Skip to content

Commit

Permalink
log: emit working-copy branch first if included in the revset
Browse files Browse the repository at this point in the history
The working-copy revision is usually the latest commit, but it's not always
true. This patch ensures that the wc branch is emitted first so the graph node
order is less dependent on rewrites.
  • Loading branch information
yuja committed Nov 19, 2024
1 parent c175dca commit 7526217
Show file tree
Hide file tree
Showing 17 changed files with 1,309 additions and 988 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
* New `fork_point()` revset function can be used to obtain the fork point
of multiple commits.

* `jj log` now displays the working-copy branch first.

### Fixed bugs

* `jj config unset <TABLE-NAME>` no longer removes a table (such as `[ui]`.)
Expand Down
20 changes: 15 additions & 5 deletions cli/src/commands/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,21 @@ pub(crate) fn cmd_log(
if !args.no_graph {
let mut raw_output = formatter.raw()?;
let mut graph = get_graphlog(graph_style, raw_output.as_mut());
let forward_iter = TopoGroupedGraphIterator::new(revset.iter_graph());
let iter: Box<dyn Iterator<Item = _>> = if args.reversed {
Box::new(ReverseGraphIterator::new(forward_iter)?)
} else {
Box::new(forward_iter)
let iter: Box<dyn Iterator<Item = _>> = {
let mut forward_iter = TopoGroupedGraphIterator::new(revset.iter_graph());
// Emit the working-copy branch first, which is usually most
// interesting. This also helps stabilize output order.
if let Some(id) = workspace_command.get_wc_commit_id() {
let has_commit = revset.containing_fn();
if has_commit(id)? {
forward_iter.prioritize_branch(id.clone());
}
}
if args.reversed {
Box::new(ReverseGraphIterator::new(forward_iter)?)
} else {
Box::new(forward_iter)
}
};
for node in iter.take(limit) {
let (commit_id, edges) = node?;
Expand Down
44 changes: 22 additions & 22 deletions cli/tests/test_bookmark_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -940,12 +940,12 @@ fn test_bookmark_track_untrack() {
feature2@origin: sptzoqmo 7b33f629 commit 1
main@origin: sptzoqmo 7b33f629 commit 1
"###);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
◆ feature1@origin feature2@origin main@origin 7b33f6295eda
@ 230dd059e1b0
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r#"
@ 230dd059e1b0
◆ feature1@origin feature2@origin main@origin 7b33f6295eda
├─╯
◆ 000000000000
"###);
"#);

// Track new bookmark. Local bookmark should be created.
test_env.jj_cmd_ok(
Expand Down Expand Up @@ -988,12 +988,12 @@ fn test_bookmark_track_untrack() {
main: sptzoqmo 7b33f629 commit 1
@origin: sptzoqmo 7b33f629 commit 1
"###);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
◆ feature1 feature1@origin feature2@origin main 7b33f6295eda
@ 230dd059e1b0
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r#"
@ 230dd059e1b0
◆ feature1 feature1@origin feature2@origin main 7b33f6295eda
├─╯
◆ 000000000000
"###);
"#);

// Fetch new commit. Only tracking bookmark "main" should be merged.
create_remote_commit(
Expand All @@ -1018,14 +1018,14 @@ fn test_bookmark_track_untrack() {
main: mmqqkyyt 40dabdaf commit 2
@origin: mmqqkyyt 40dabdaf commit 2
"###);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
◆ feature1@origin feature2@origin main 40dabdaf4abe
feature1 7b33f6295eda
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r#"
@ 230dd059e1b0
feature1@origin feature2@origin main 40dabdaf4abe
├─╯
@ 230dd059e1b0
○ feature1 7b33f6295eda
├─╯
◆ 000000000000
"###);
"#);

// Fetch new commit with auto tracking. Tracking bookmark "main" and new
// bookmark "feature3" should be merged.
Expand Down Expand Up @@ -1057,14 +1057,14 @@ fn test_bookmark_track_untrack() {
main: wwnpyzpo 3f0f86fa commit 3
@origin: wwnpyzpo 3f0f86fa commit 3
"###);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
◆ feature1@origin feature2@origin feature3 main 3f0f86fa0e57
feature1 7b33f6295eda
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r#"
@ 230dd059e1b0
feature1@origin feature2@origin feature3 main 3f0f86fa0e57
├─╯
@ 230dd059e1b0
○ feature1 7b33f6295eda
├─╯
◆ 000000000000
"###);
"#);
}

#[test]
Expand Down Expand Up @@ -1447,9 +1447,9 @@ fn test_bookmark_list_filtered() {
&local_path,
&["log", "-r::(bookmarks() | remote_bookmarks())", "-T", template],
),
@r###"
○ e31634b64294 remote-rewrite*
@ c7b4c09cd77c local-keep
@r#"
@ c7b4c09cd77c local-keep
○ e31634b64294 remote-rewrite*
├─╯
│ ○ 3e9a5af6ef15 remote-rewrite@origin (hidden)
├─╯
Expand All @@ -1458,7 +1458,7 @@ fn test_bookmark_list_filtered() {
│ ○ 911e912015fb remote-keep
├─╯
◆ 000000000000
"###);
"#);

// All bookmarks are listed by default.
let (stdout, stderr) = test_env.jj_cmd_ok(&local_path, &["bookmark", "list"]);
Expand Down
60 changes: 30 additions & 30 deletions cli/tests/test_commit_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,26 +503,26 @@ fn test_log_evolog_divergence() {
&["describe", "-m", "description 2", "--at-operation", "@-"],
);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["log"]);
insta::assert_snapshot!(stdout, @r###"
qpvuntsm?? [email protected] 2001-02-03 08:05:10 6ba70e00
│ description 2
@ qpvuntsm?? [email protected] 2001-02-03 08:05:08 ff309c29
├─╯ description 1
insta::assert_snapshot!(stdout, @r#"
@ qpvuntsm?? [email protected] 2001-02-03 08:05:08 ff309c29
│ description 1
qpvuntsm?? [email protected] 2001-02-03 08:05:10 6ba70e00
├─╯ description 2
◆ zzzzzzzz root() 00000000
"###);
"#);
insta::assert_snapshot!(stderr, @r###"
Concurrent modification detected, resolving automatically.
"###);

// Color
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "--color=always"]);
insta::assert_snapshot!(stdout, @r###"
[1m[4m[38;5;1mq[0m[38;5;1mpvuntsm??[39m [38;5;[email protected][39m [38;5;6m2001-02-03 08:05:10[39m [1m[38;5;4m6[0m[38;5;8mba70e00[39m
description 2
[1m[38;5;2m@[0m [1m[4m[38;5;1mq[24mpvuntsm[38;5;9m??[39m [38;5;[email protected][39m [38;5;14m2001-02-03 08:05:08[39m [38;5;12mf[38;5;8mf309c29[39m[0m
├─╯ [1mdescription 1[0m
insta::assert_snapshot!(stdout, @r#"
[1m[38;5;2m@[0m [1m[4m[38;5;1mq[24mpvuntsm[38;5;9m??[39m [38;5;[email protected][39m [38;5;14m2001-02-03 08:05:08[39m [38;5;12mf[38;5;8mf309c29[39m[0m
[1mdescription 1[0m
[1m[4m[38;5;1mq[0m[38;5;1mpvuntsm??[39m [38;5;[email protected][39m [38;5;6m2001-02-03 08:05:10[39m [1m[38;5;4m6[0m[38;5;8mba70e00[39m
├─╯ description 2
◆ zzzzzzzz root() 00000000
"###);
"#);

// Evolog and hidden divergent
let stdout = test_env.jj_cmd_success(&repo_path, &["evolog"]);
Expand Down Expand Up @@ -599,45 +599,45 @@ fn test_log_bookmarks() {

let template = r#"commit_id.short() ++ " " ++ if(bookmarks, bookmarks, "(no bookmarks)")"#;
let output = test_env.jj_cmd_success(&workspace_root, &["log", "-T", template]);
insta::assert_snapshot!(output, @r###"
○ fed794e2ba44 bookmark3?? bookmark3@origin
insta::assert_snapshot!(output, @r#"
@ a5b4d15489cc bookmark2* new-bookmark
○ 8476341eb395 bookmark2@origin unchanged
│ ○ fed794e2ba44 bookmark3?? bookmark3@origin
├─╯
│ ○ b1bb3766d584 bookmark3??
├─╯
│ ○ 4a7e4246fc4d bookmark1*
├─╯
│ @ a5b4d15489cc bookmark2* new-bookmark
│ ○ 8476341eb395 bookmark2@origin unchanged
├─╯
◆ 000000000000 (no bookmarks)
"###);
"#);

let template = r#"bookmarks.map(|b| separate("/", b.remote(), b.name())).join(", ")"#;
let output = test_env.jj_cmd_success(&workspace_root, &["log", "-T", template]);
insta::assert_snapshot!(output, @r###"
○ bookmark3, origin/bookmark3
insta::assert_snapshot!(output, @r#"
@ bookmark2, new-bookmark
○ origin/bookmark2, unchanged
│ ○ bookmark3, origin/bookmark3
├─╯
│ ○ bookmark3
├─╯
│ ○ bookmark1
├─╯
│ @ bookmark2, new-bookmark
│ ○ origin/bookmark2, unchanged
├─╯
"###);
"#);

let template = r#"separate(" ", "L:", local_bookmarks, "R:", remote_bookmarks)"#;
let output = test_env.jj_cmd_success(&workspace_root, &["log", "-T", template]);
insta::assert_snapshot!(output, @r###"
○ L: bookmark3?? R: bookmark3@origin
insta::assert_snapshot!(output, @r#"
@ L: bookmark2* new-bookmark R:
○ L: unchanged R: bookmark2@origin unchanged@origin
│ ○ L: bookmark3?? R: bookmark3@origin
├─╯
│ ○ L: bookmark3?? R:
├─╯
│ ○ L: bookmark1* R:
├─╯
│ @ L: bookmark2* new-bookmark R:
│ ○ L: unchanged R: bookmark2@origin unchanged@origin
├─╯
◆ L: R:
"###);
"#);

let template = r#"
remote_bookmarks.map(|ref| concat(
Expand Down
8 changes: 4 additions & 4 deletions cli/tests/test_concurrent_operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ fn test_concurrent_operation_divergence() {

// We should be informed about the concurrent modification
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["log", "-T", "description"]);
insta::assert_snapshot!(stdout, @r###"
message 2
@ message 1
insta::assert_snapshot!(stdout, @r#"
@ message 1
message 2
├─╯
"###);
"#);
insta::assert_snapshot!(stderr, @r###"
Concurrent modification detected, resolving automatically.
"###);
Expand Down
Loading

0 comments on commit 7526217

Please sign in to comment.