Skip to content

Commit

Permalink
obslog: reverse order of predecessors in topo traversal
Browse files Browse the repository at this point in the history
Currently, when there is a commit with two predecessors, the graph
splits into two branches, and all of the predecessors on the first
branch are printed before all of the predecessors on the second branch.
This causes the graph to grow wider with each squashed commit, since the
second branch must always get indented one level farther each time a
commit is squashed. I have some commits where the graph is indented more
than 10 levels due to squashing more than 10 times, making it very
difficult to read.

Reversing the order and printing the second branch before the first
branch prevents this unnecessary indentation and makes the graph easier
to read. This does not change the order of the edges in the graph (i.e.
the first predecessor is still the first edge and the second predecessor
is still the second edge in the graph).
  • Loading branch information
scott2000 committed Jul 14, 2024
1 parent 8daf045 commit 54bd4f3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 35 deletions.
6 changes: 5 additions & 1 deletion cli/src/commands/obslog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ 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();
predecessors.reverse();
predecessors
},
)?;
if args.deprecated_limit.is_some() {
writeln!(
Expand Down
60 changes: 30 additions & 30 deletions cli/tests/test_obslog_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,36 +252,36 @@ fn test_obslog_squash() {
│ │ 1 1: foo
│ │ 2 2: bar
│ │ 3: baz
◉ │ 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
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)
│ ◉ 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
│ ◉ 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

0 comments on commit 54bd4f3

Please sign in to comment.