Your one-stop-cake-shop for everything Freshly Baked has to offer

fix(jujutsu): correct back/fwd distances

previously, back(@, 1) == @. That feels very weird, so instead now
back(@, 0) == @. Since as back(@, n) was used in the rangediff script,
I also had to update that script to cope with this (it had the correct
behavior already...)

We've had to do some interesting finagling to get this to happen, since
as AFAICT there is no way to do maths in the revset language (so no
way to add 1). Instead, we've done revision- to go back 1 already, so
our argument operates on a revision already 1 in the past.

Of course, 0 isn't going to bring us forward again so we instead have
to coalesce and return the current revision if we have no changes. Again
the revset language gets in our way since as there isn't a way to tell
if we have 0 as a quantity directly. Fortunately, for 0 we can make
a set that is always guarenteed to have the whole repo as members if
and only if our number was 0, and logically-and that with our current
revision to conditionally return it.

We also replaced our heads call with `ancestors(foo-) & ~ancestors(foo)`
- normally equivalent, but better if we've reached the end of our
commits, for example if we do `fwd(5)` when in reality we only have 2
more commits ontop of us. Previously that would return the last commit,
now it returns nothing

Finally, we've added some aliases to `fwd(n)` which default to using `@`
since as that seems to be a very common case.

Changed files
+9 -4
packetmix
homes
development
+9 -4
packetmix/homes/development/jujutsu.nix
··· 127 127 fi 128 128 129 129 BEFORE_TOP=$(${config.programs.jujutsu.package}/bin/jj show -T "self.commit_id()" --no-patch --quiet $BEFORE_REVSET) 130 - BEFORE_BOTTOM=$(${config.programs.jujutsu.package}/bin/jj show -T "self.commit_id()" --no-patch --quiet "back($BEFORE_REVSET, $BEFORE_LENGTH)") 130 + BEFORE_BOTTOM=$(${config.programs.jujutsu.package}/bin/jj show -T "self.commit_id()" --no-patch --quiet "back($BEFORE_REVSET, $(($BEFORE_LENGTH - 1)))") 131 131 132 132 AFTER_TOP=$(${config.programs.jujutsu.package}/bin/jj show -T "self.commit_id()" --no-patch --quiet $AFTER_REVSET) 133 - AFTER_BOTTOM=$(${config.programs.jujutsu.package}/bin/jj show -T "self.commit_id()" --no-patch --quiet "back($AFTER_REVSET, $AFTER_LENGTH)") 133 + AFTER_BOTTOM=$(${config.programs.jujutsu.package}/bin/jj show -T "self.commit_id()" --no-patch --quiet "back($AFTER_REVSET, $(($AFTER_LENGTH - 1)))") 134 134 135 135 ${pkgs.git}/bin/git range-diff $BEFORE_BOTTOM~..$BEFORE_TOP $AFTER_BOTTOM~..$AFTER_TOP "$@" 136 136 ''; ··· 358 358 "here" = "reachable(@, trunk()..)"; 359 359 "in(branch, matching)" = "matching & ::branch"; 360 360 361 - "back(revision, distance)" = "roots(ancestors(revision, distance))"; 362 - "fwd(revision, distance)" = "heads(decendants(revision, distance))"; 361 + "valued(n)" = "latest(root(), n)::"; # Returns all() if n >= 1 or none() if n == 0 362 + "back(revision, distance)" = 363 + "coalesce(~valued(distance) & revision, ancestors(revision-, distance) & ~ancestors(revision, distance))"; 364 + "fwd(revision, distance)" = 365 + "coalesce(~valued(distance) & revision, descendants(revision+, distance) & ~descendants(revision, distance))"; 366 + "back(distance)" = "back(@, distance)"; 367 + "fwd(distance)" = "fwd(@, distance)"; 363 368 364 369 "closest_bookmark(to)" = "heads(::to & bookmarks())"; 365 370 "closest_pushable_allow_empty_desc(to)" = "heads(::to & mutable() & (~empty() | merges()))";