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

commands: Implement next and prev #1200

Merged
merged 2 commits into from
Sep 5, 2023
Merged

Conversation

PhilipMetzger
Copy link
Collaborator

@PhilipMetzger PhilipMetzger commented Feb 5, 2023

This is a naive implementation, which cannot deal with multiple children or parents stemming from merges.

For now I'll create a follow-up bug, which someone else can solve.

Note: I currently gave each command separate a separate argument struct for extensibility.

Fixes #878

Checklist

  • I have updated CHANGELOG.md
  • [n/a ] I have updated the documentation (README.md, docs/, demos/)
  • I have added tests to cover my changes

src/commands/mod.rs Outdated Show resolved Hide resolved
src/commands/mod.rs Outdated Show resolved Hide resolved
src/commands/mod.rs Outdated Show resolved Hide resolved
@PhilipMetzger PhilipMetzger force-pushed the prev-next branch 3 times, most recently from f1a62b9 to 8bc732c Compare February 16, 2023 20:47
@PhilipMetzger
Copy link
Collaborator Author

Sorry that I haven't progressed that much. While I have some local changes, I'm also in the progress of moving to neovim as my main $EDITOR for non-work concerned things, which hampers my process. Hopefully after finishing the base of next and prev I have the time for run as described in the Design Doc.

@martinvonz
Copy link
Member

Sorry that I haven't progressed that much.

No worries! Take your time.

@PhilipMetzger
Copy link
Collaborator Author

PTAL, @martinvonz if I'm on the correct path.

@martinvonz
Copy link
Member

PTAL, @martinvonz if I'm on the correct path.

Yes, looks like it. Do you need help with anything or is it going pretty well?

@PhilipMetzger PhilipMetzger force-pushed the prev-next branch 2 times, most recently from fecd27d to ed0cf1b Compare May 25, 2023 22:17
@PhilipMetzger
Copy link
Collaborator Author

PhilipMetzger commented May 25, 2023

This is almost ready, only the tests are missing now. Here's a screenshot with the Arcanist repo as an example:
image

I'll need some help to turn the jj next/prev --edit true into just jj next 10 --edit though.

@martinvonz
Copy link
Member

I'll need some help to turn the jj next/prev --edit true into just jj next 10 --edit though.

Try replacing Option<bool> by just bool (it still won't mean that the user has to pass the flag).

src/commands/mod.rs Outdated Show resolved Hide resolved
src/commands/mod.rs Outdated Show resolved Hide resolved
src/commands/mod.rs Outdated Show resolved Hide resolved
src/commands/mod.rs Outdated Show resolved Hide resolved
@PhilipMetzger PhilipMetzger changed the title WIP: commands: Implement next and prev commands: Implement next and prev Jul 3, 2023
@PhilipMetzger PhilipMetzger marked this pull request as ready for review July 3, 2023 21:47
@PhilipMetzger
Copy link
Collaborator Author

This is now ready for review. A testcase is missing and four are failing but can be fixed during the review.

@yuja
Copy link
Collaborator

yuja commented Jul 4, 2023

(Github somehow failed to load the review UI, so commented in old style.)

// Get the N'th child.
for _ in 0..amount {
    // Does the revset optimizer turn this into a `descendants(id)`?
    children_revset = children_revset.children();
}

Perhaps, you can build a single query like this.

    let current = RevsetExpression::commit(current_wc_id.clone());
    let next = current.parents().children().minus(&current); // @-+ & ~@
    Rc::new(RevsetExpression::Descendants {
        roots: next,
        generation: (amount - 1)..amount,
    });

We'll probably need a helper method for the last part. I can't think of a good name, but maybe .descendants_at(n) or .descendants_within(range)?

/// Instead of moving the empty commit from `jj new`, edit the child
/// revision directly. This mirrors the behavior of Mercurial and
/// Sapling.

I think Mercurial's behavior is not --edit. JJ's graph is close to -r 'wdir() + all()' in Mercurial.

FWIW, the query @-+ & ~@ implies that we're not "editing" the @ revision. If we're editing, the next revision would be just @+. I'm not sure if --edit should affect the handling of the current revision.

@PhilipMetzger
Copy link
Collaborator Author

Perhaps, you can build a single query like this.

    let current = RevsetExpression::commit(current_wc_id.clone());
    let next = current.parents().children().minus(&current); // @-+ & ~@
    Rc::new(RevsetExpression::Descendants {
        roots: next,
        generation: (amount - 1)..amount,
    });

We'll probably need a helper method for the last part. I can't think of a good name, but maybe .descendants_at(n) or .descendants_within(range)?

Thanks, this suggestion is simpler than my previous attempts. My initial attempt is still available as commented code, e.g a direct lookup via RevsetExpression::descendants(id), this implementation is based on this comment from martin in Discord.

/// Instead of moving the empty commit from `jj new`, edit the child
/// revision directly. This mirrors the behavior of Mercurial and
/// Sapling.

I think Mercurial's behavior is not --edit. JJ's graph is close to -r 'wdir() + all()' in Mercurial.

FWIW, the query @-+ & ~@ implies that we're not "editing" the @ revision. If we're editing, the next revision would be just @+. I'm not sure if --edit should affect the handling of the current revision.

Thanks for the clarification. What would be a more appropriate description? This is purely based on my assumptions from sl next.

@yuja
Copy link
Collaborator

yuja commented Jul 4, 2023

I think Mercurial's behavior is not --edit. JJ's graph is close to -r 'wdir() + all()' in Mercurial.
FWIW, the query @-+ & ~@ implies that we're not "editing" the @ revision. If we're editing, the next revision would be just @+. I'm not sure if --edit should affect the handling of the current revision.

Thanks for the clarification. What would be a more appropriate description? This is purely based on my assumptions from sl next.

My feeling is that jj edit is close to hg update && hg uncommit (without losing commit metadata.)
I don't know if people would want to use --edit while walking stacked commits by jj next/prev, but maybe I'm biased. I rarely use jj edit.

@necauqua
Copy link
Collaborator

necauqua commented Jul 4, 2023

From my perspective (I did not look too deep into this), for jj next/prev it would not be too useful if it did edits, it would be better if it did "checkouts" aka making/dropping empty working copy children

And something like jj next/prev --edit is not needed bc that's just jj edit @+/@-

@PhilipMetzger
Copy link
Collaborator Author

I don't know if people would want to use --edit while walking stacked commits by jj next/prev, but maybe I'm biased. I rarely use jj edit.

I'm one of the people which generally use edit instead of the new + squash workflow. And @talpr also has jj next aliased to edit @+. Which means that we generally should support both workflows.

And something like jj next/prev --edit is not needed bc that's just jj edit @+/@-

I respectfully disagree, see the initial conversation with Martin on Discord here.

@martinvonz
Copy link
Member

FYI, 2164b7e somehow fails to load for me, so I can't review this.

I agree that this comment is misleading:

/// Instead of moving the empty commit from `jj new`, edit the child
/// revision directly. This mirrors the behavior of Mercurial and
/// Sapling.

Maybe something like this?

/// Instead of creating a new working-copy commit on top of the
/// target commit (like `jj new`), edit the target commit directly
/// (like `jj edit`).

@PhilipMetzger PhilipMetzger force-pushed the prev-next branch 2 times, most recently from cbbb91d to 7969fed Compare July 5, 2023 20:57
src/commands/mod.rs Outdated Show resolved Hide resolved
src/commands/mod.rs Outdated Show resolved Hide resolved
src/commands/mod.rs Outdated Show resolved Hide resolved
src/commands/mod.rs Outdated Show resolved Hide resolved
src/commands/mod.rs Outdated Show resolved Hide resolved
src/commands/mod.rs Outdated Show resolved Hide resolved
src/commands/mod.rs Outdated Show resolved Hide resolved
src/commands/mod.rs Outdated Show resolved Hide resolved
lib/src/revset.rs Outdated Show resolved Hide resolved
src/commands/mod.rs Outdated Show resolved Hide resolved
src/commands/mod.rs Outdated Show resolved Hide resolved
src/commands/mod.rs Outdated Show resolved Hide resolved
src/commands/mod.rs Outdated Show resolved Hide resolved
src/commands/mod.rs Outdated Show resolved Hide resolved
@PhilipMetzger PhilipMetzger marked this pull request as ready for review August 4, 2023 18:21
lib/src/revset.rs Outdated Show resolved Hide resolved
lib/src/revset.rs Show resolved Hide resolved
cli/src/commands/mod.rs Show resolved Hide resolved
cli/src/commands/mod.rs Outdated Show resolved Hide resolved
cli/src/commands/mod.rs Outdated Show resolved Hide resolved
cli/src/commands/mod.rs Outdated Show resolved Hide resolved
cli/src/commands/mod.rs Outdated Show resolved Hide resolved
cli/src/commands/mod.rs Outdated Show resolved Hide resolved
cli/src/commands/mod.rs Outdated Show resolved Hide resolved
cli/src/commands/mod.rs Outdated Show resolved Hide resolved
cli/src/commands/mod.rs Outdated Show resolved Hide resolved
cli/src/commands/mod.rs Outdated Show resolved Hide resolved
cli/src/commands/mod.rs Outdated Show resolved Hide resolved
cli/src/commands/mod.rs Show resolved Hide resolved
cli/src/commands/mod.rs Outdated Show resolved Hide resolved
cli/src/commands/mod.rs Outdated Show resolved Hide resolved
cli/src/commands/mod.rs Outdated Show resolved Hide resolved
cli/src/commands/mod.rs Outdated Show resolved Hide resolved
@PhilipMetzger PhilipMetzger force-pushed the prev-next branch 2 times, most recently from 863ff22 to a6aecca Compare August 24, 2023 15:35
@martinvonz
Copy link
Member

Is this PR ready to be merged?

@PhilipMetzger
Copy link
Collaborator Author

Sorry for no activity here, as I had some personal obligations. I'm fine to commit as is and add the next creating a commit part later.

@martinvonz
Copy link
Member

Sorry for no activity here, as I had some personal obligations. I'm fine to commit as is and add the next creating a commit part later.

Sounds good! Do you have time to rebase it so it can be merged?

@PhilipMetzger
Copy link
Collaborator Author

Sounds good! Do you have time to rebase it so it can be merged?

Yeah, I'll do it after creating a issue with the missing feature and splitting my local changes into a later commit.

They are needed for `next` and `prev`.
They behave symmetrically for parents and children.
This is a naive implementation, which cannot deal with multiple children
or parents stemming from merges.

Note: I gave each command separate a separate argument struct
for extensibility. 

Fixes jj-vcs#878
@PhilipMetzger
Copy link
Collaborator Author

Should be good now.

Copy link
Member

@martinvonz martinvonz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Looking forward to using this.

@PhilipMetzger PhilipMetzger merged commit f131dc9 into jj-vcs:main Sep 5, 2023
15 checks passed
@PhilipMetzger PhilipMetzger deleted the prev-next branch September 5, 2023 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement jj next/prev
5 participants