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

obslog: reverse order of predecessors in topo traversal #4086

Merged
merged 2 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion cli/src/commands/obslog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,21 @@ pub(crate) fn cmd_obslog(
let mut commits = topo_order_reverse_ok(
vec![Ok(start_commit)],
|commit: &Commit| commit.id().clone(),
|commit: &Commit| commit.predecessors().collect_vec(),
|commit: &Commit| {
let mut predecessors = commit.predecessors().collect_vec();
scott2000 marked this conversation as resolved.
Show resolved Hide resolved
// Predecessors don't need to follow any defined order. However in
// practice, if there are multiple predecessors, then usually the
// first predecessor is the previous version of the same change, and
// the other predecessors are commits that were squashed into it. If
// multiple commits are squashed at once, then they are usually
// recorded in chronological order. We want to show squashed commits
// in reverse chronological order, and we also want to show squashed
// commits before the squash destination (since the destination's
// subgraph may contain earlier squashed commits as well), so we
// visit the predecessors in reverse order.
predecessors.reverse();
predecessors
},
)?;
if args.deprecated_limit.is_some() {
writeln!(
Expand Down
58 changes: 40 additions & 18 deletions cli/tests/test_obslog_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,31 +235,53 @@ fn test_obslog_squash() {
std::fs::write(repo_path.join("file1"), "foo\nbar\n").unwrap();

let edit_script = test_env.set_up_fake_editor();
std::fs::write(edit_script, "write\nsquashed").unwrap();
std::fs::write(&edit_script, "write\nsquashed 1").unwrap();
test_env.jj_cmd_ok(&repo_path, &["squash"]);

test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "third"]);
std::fs::write(repo_path.join("file1"), "foo\nbar\nbaz\n").unwrap();

std::fs::write(&edit_script, "write\nsquashed 2").unwrap();
test_env.jj_cmd_ok(&repo_path, &["squash"]);

let stdout = test_env.jj_cmd_success(&repo_path, &["obslog", "-p", "-r", "@-"]);
insta::assert_snapshot!(stdout, @r###"
◉ qpvuntsm [email protected] 2001-02-03 08:05:10 68647e34
├─╮ squashed
◉ qpvuntsm [email protected] 2001-02-03 08:05:12 1408a0a7
├─╮ squashed 2
│ │ Modified regular file file1:
│ │ 1 1: foo
│ │ 2 2: bar
│ │ 3: baz
│ ◉ zsuskuln hidden [email protected] 2001-02-03 08:05:12 7015a42c
│ │ third
│ │ Modified regular file file1:
│ │ 1 1: foo
│ │ 2 2: bar
│ │ 3: baz
│ ◉ zsuskuln hidden [email protected] 2001-02-03 08:05:11 66645763
│ │ (empty) third
│ ◉ zsuskuln hidden [email protected] 2001-02-03 08:05:10 1c7afcb4
│ (empty) (no description set)
◉ qpvuntsm hidden [email protected] 2001-02-03 08:05:10 e3c2a446
├─╮ squashed 1
│ │ Modified regular file file1:
│ │ 1 1: foo
│ │ 2: bar
◉ │ qpvuntsm hidden [email protected] 2001-02-03 08:05:09 766420db
│ │ first
│ │ Added regular file file1:
│ │ 1: foo
qpvuntsm hidden [email protected] 2001-02-03 08:05:08 fa15625b
│ (empty) first
qpvuntsm hidden [email protected] 2001-02-03 08:05:07 230dd059
│ (empty) (no description set)
◉ kkmpptxz hidden [email protected] 2001-02-03 08:05:10 46acd22a
│ second
│ Modified regular file file1:
│ 1 1: foo
2: bar
kkmpptxz hidden [email protected] 2001-02-03 08:05:09 cba41deb
(empty) second
│ ◉ kkmpptxz hidden [email protected] 2001-02-03 08:05:10 46acd22a
│ │ second
│ │ Modified regular file file1:
│ │ 1 1: foo
2: bar
◉ kkmpptxz hidden [email protected] 2001-02-03 08:05:09 cba41deb
(empty) second
◉ qpvuntsm hidden [email protected] 2001-02-03 08:05:09 766420db
│ first
│ Added regular file file1:
│ 1: foo
◉ qpvuntsm hidden [email protected] 2001-02-03 08:05:08 fa15625b
(empty) first
qpvuntsm hidden [email protected] 2001-02-03 08:05:07 230dd059
(empty) (no description set)
"###);
}

Expand Down
8 changes: 4 additions & 4 deletions cli/tests/test_squash_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -972,10 +972,10 @@ fn test_squash_from_multiple_partial_no_op() {
insta::assert_snapshot!(stdout, @r###"
@ e178068add8c d
├─╮
◉ │ b37ca1ee3306 d
◉ │ 1d9eb34614c9 d
b73077b08c59 b
a786561e909f b
│ ◉ b73077b08c59 b
│ ◉ a786561e909f b
b37ca1ee3306 d
1d9eb34614c9 d
"###);

// If no source commits match the paths, then the whole operation is a no-op
Expand Down