Skip to content

Instantly share code, notes, and snippets.

@strega-nil
Last active May 21, 2025 08:02
Show Gist options
  • Save strega-nil/b1bdc5ac4dead395358f3dd3bd82cd96 to your computer and use it in GitHub Desktop.
Save strega-nil/b1bdc5ac4dead395358f3dd3bd82cd96 to your computer and use it in GitHub Desktop.
Better range-diff for GitHub
[aliases]
range-diff = ["util", "exec", "--", "sh", "-c", '''
if [ "x$1" = "x" ]; then
echo "jj range-diff requires at least one argument" 1>&2
exit 1
fi
old_commit="$1"
trunk=`jj log -r "trunk()" -T commit_id --no-graph`
current=`jj log -r HEAD -T commit_id --no-graph`
git range-diff "$trunk..$old_commit" "$trunk..$current" | awk -f "$HOME/projects/dotfiles/scripts/range-diff.awk"
''', ""]
BEGIN {
in_diff = 0
}
# -: --------- > 1: 3ab9e098d cli config edit: Rollback to previous config when invalid TOML is saved
# 1 2 3 4 5 ...
/^(-|[1-9]): (--*|[a-f0-9][a-f0-9]*) [<>=!]/ {
if (in_diff) {
print "```"
}
print "* " $0
if ($3 ~ /!/) {
print "```diff"
in_diff = 1
} else {
in_diff = 0
}
}
in_diff && /^ / {
sub(/^ /, "")
print $0
}
END {
if (in_diff) {
print "```"
}
}
  • 1: bcd366b54 ! 1: f4a73faf0 config: change how config paths are represented
@@ Metadata
  ## Commit message ##
     config: change how config paths are represented
 
+    This change, from an enum to a struct, is a more accurate representation
+    of the actual way that a ConfigPath works; additionally, it lets us add
+    different information without modifying every single enumeration field.
+
+    The change to `config_paths()`, to return a `ConfigPath` instead of a
+    `Path`, is less interesting, but in my opinion results in slightly more
+    obvious code. It also makes the test code significantly easier.
+
  ## cli/src/commands/config/mod.rs ##
 @@ cli/src/commands/config/mod.rs: mod path;
  mod set;
  • 2: 8a31c0b81 ! 2: f82fac4ea config: switch to etcetera from dirs
@@ cli/Cargo.toml: clap_complete_nushell = { workspace = true }
  gix = { workspace = true, optional = true }
 
  ## cli/src/config.rs ##
+@@ cli/src/config.rs: impl UnresolvedConfigEnv {
+ 
+         // theoretically this should be an `if let Some(...) = ... && ..., but that
+         // isn't stable
+-        let get_existing = |opt: Option<ConfigPath>| match opt {
+-            Some(path) if path.exists() => Some(path),
+-            _ => None,
+-        };
+-        if let Some(path) = get_existing(platform_config_dir) {
+-            paths.push(path);
++        if let Some(path) = platform_config_dir {
++            if path.exists() {
++                paths.push(path);
++            }
+         }
+         paths
+     }
 @@ cli/src/config.rs: pub struct ConfigEnv {
  impl ConfigEnv {
      /// Initializes configuration loader based on environment variables.
  • 3: a4a790ea3 ! 3: 57b4cd795 config: default to XDG config files on macOS
@@ cli/src/config.rs: impl UnresolvedConfigEnv {
              }
          }
 @@ cli/src/config.rs: impl UnresolvedConfigEnv {
-         if let Some(path) = get_existing(platform_config_dir) {
              paths.push(path);
          }
+ 
+-        // theoretically this should be an `if let Some(...) = ... && ..., but that
++        // theoretically these should be an `if let Some(...) = ... && ..., but that
+         // isn't stable
+         if let Some(path) = platform_config_dir {
+             if path.exists() {
+                 paths.push(path);
+             }
+         }
 +
-+        if let Some(path) = get_existing(legacy_platform_config_path) {
-+            paths.push(path);
++        if let Some(path) = legacy_platform_config_path {
++            if path.exists() {
++                paths.push(path);
++            }
 +        }
-+        if let Some(path) = get_existing(legacy_platform_config_dir) {
-+            paths.push(path);
++        if let Some(path) = legacy_platform_config_dir {
++            if path.exists() {
++                paths.push(path);
++            }
 +        }
 +
          paths
  • 4: b6c814370 = 4: d1110e1b0 config: deprecate macOS legacy platform configs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment