描述
Problem
Revsets are very cool. They provide a way to select a set of changes, without having to run jj log and manually copy the change IDs. Unfortunately, they only provide functions for moving between the most recent commits that changes point to. To select a previous version of a change, the user must first open the obslog, and then copy the commit ID for the version they're after.
Solution
Introduce a set of functions for traversing the obslog. Much like parents(x) gives the parent change(s) of change x that can be found with jj log -r ..x, previously(x) would give the parent commit(s) of the change x that could be found with jj obslog -r x.
I'm proposing this set of functions where previously is the most useful and simple.
| Obslog function suggestion | Analogous changelog function | Alias of |
|---|---|---|
| past(x) | ancestors(x) | |
| future(x) | x.. | |
| previously(x) | parents(x) | oldest(past(x, 2))1 |
Operators would also be really nice to have, especially in cases like previously(previously(x)) but I'm not sure what symbol would be best.
Use cases
Verbatim "ours" rebase/merge https://github.com/martinvonz/jj/issues/1027
I initially wanted this feature to carry out verbatim rebases. This is based on an idea from @ilyagr.
jj rebase -r a -d b
jj restore --to a --from 'previously(a)'
Unlike adding a --verbatim flag to rebase, this also allows restoring into a child of a so that the conflict resolution can be viewed before squashing into a.
Note that this is only equivalent to one type of git "ours" merge strategy. There are two subtly different types.
Restoring from a previous snapshot
Take this example
touch important # create an important file
jj debug snapshot # snapshot @
rm important # unintentionally remove an important file
jj restore --from 'previously(@)' important # bring the file back from the last snapshot
Footnotes
-
oldestdoesn't exist but should be too hard to add since we havelatest↩