Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR: revset functions for traversing the obslog #4129

Open
eopb opened this issue Jul 20, 2024 · 8 comments
Open

FR: revset functions for traversing the obslog #4129

eopb opened this issue Jul 20, 2024 · 8 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@eopb
Copy link
Contributor

eopb commented Jul 20, 2024

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 #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

  1. oldest doesn't exist but should be too hard to add since we have latest

@PhilipMetzger PhilipMetzger added the enhancement New feature or request label Jul 20, 2024
@emilazy
Copy link
Collaborator

emilazy commented Jul 20, 2024

I think I prefer previous()to previously(), but I suspect there’s lots of bikeshedding that could be done here.

There’s also the subtle difference between “this change ID at the previous op log version” and “this change ID at the previous obslog version” to consider.

@eopb
Copy link
Contributor Author

eopb commented Jul 20, 2024

I think I prefer previous()to previously(), but I suspect there’s lots of bikeshedding that could be done here.

That's fair. I considered previous but went for previously because I felt it conveyed better that it only goes a single layer deep, that being said, my reasoning may not work for others.

There’s also the subtle difference between “this change ID at the previous op log version” and “this change ID at the previous obslog version” to consider.

This is also related to #1283. Maybe we'll want to support both in the future. The obslog seems simpler and more useful to me, but both are interesting

@yuja
Copy link
Collaborator

yuja commented Jul 21, 2024

Mercurial calls obslog-based resolution as predecessors/allpredecessors/successors/allsuccessors (analogous to parents/ancestors/children/descendants respectively.) I'll be nice if we can find better names for all* variants.

@ilyagr
Copy link
Collaborator

ilyagr commented Jul 21, 2024

Copying from #4097, I think obsparents, obschildren, obsancestors, and obsdescendants are relatively clear. This also allows for obsroots and obsheads. We could also style them as obs_parents. Of course, these are not the prettiest names nor the shortest.

A related option would be to have parents(x, changes) for parents in the change-graph (AKA the normal graph, not sure if there is a better name) and parents(x, obs) for parents in the obsgraph. I'm not sure if this is a good idea as-is, but perhaps it'll spark other ideas.

@yuja
Copy link
Collaborator

yuja commented Jul 21, 2024

Maybe evolution is better as a prefix? I think obsolete implies the direction towards predecessors (or ancestors in rewrites log.)

A related option would be to have parents(x, changes) for parents in the change-graph (AKA the normal graph, not sure if there is a better name) and parents(x, obs) for parents in the obsgraph.

Or obs(parents(x)), obs(::x), etc. Too cryptic? It's probably similar to how "branch set" would be expressed if we had such thing.

@emilazy
Copy link
Collaborator

emilazy commented Jul 21, 2024

I would personally like something fairly short for the UX of the restore use case. In that sense obs is nice, but on the other hand the obslog name itself always stuck out to me as awkward and out of place.

@PhilipMetzger
Copy link
Collaborator

Maybe the new names should consider #3592 whenever we get around that.

Maybe evolution is better as a prefix? I think obsolete implies the direction towards predecessors (or ancestors in rewrites log.)

A related option would be to have parents(x, changes) for parents in the change-graph (AKA the normal graph, not sure if there is a better name) and parents(x, obs) for parents in the obsgraph.

I do like this idea though.

I would personally like something fairly short for the UX of the restore use case.

I don't think this should matter for the name bikeshed, as you always can add aliases.

ilyagr added a commit to ilyagr/jj that referenced this issue Aug 1, 2024
This is useful when you accidentally put some changes in the wrong commit.

In the future, we could add some shortcuts for common uses. For example, we
could define `current(X)` to be the current revision with the same change id as
`X` (which would usually be a hidden commit) and have a shortcut for `jj split
--from X -r current(X)` (only valid if `current(X)` is one commit).

Or, we could have a similar operation for `obscurrent(X)`, defined as
`obsheads(obsdescendants(X))` , based on the `jj obslog` graph (see also
martinvonz#4129 for a more focused discussion about implementing such operation).

However, let's have the basic operation first. It should be useful with the default value of `-r @`.
@yuja
Copy link
Collaborator

yuja commented Aug 6, 2024

A related option would be to have parents(x, changes) for parents in the change-graph (AKA the normal graph, not sure if there is a better name) and parents(x, obs) for parents in the obsgraph.

Or obs(parents(x)), obs(::x), etc. Too cryptic?

It'll be nice if we can filter obslog by diffs from the predecessor.

jj obslog -r@- --obs '~empty()'

In revset, it might be expressed as obs(empty()), obs_empty(), or empty(obs).

@martinvonz martinvonz added the good first issue Good for newcomers label Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

6 participants