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 15, 2024
1 parent 8daf045 commit be15efb
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 35 deletions.
25 changes: 24 additions & 1 deletion cli/src/commands/obslog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,30 @@ 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();
// Generally the first predecessor is the "original" version of the
// commit, and the other predecessors are different commits that
// were squashed into it. For instance, if you have a commit A, and
// then you squash commit B into it to create commit X, and then you
// squash commit C into X to make commit Y, then the predecessor
// graph of Y will look like this:
//
// Y
// / \
// X C
// / \
// A B
//
// Visiting the predecessors from left to right would give a
// reverse-topo order of [Y, X, A, B, C], which puts the most
// recently squashed commit C at the bottom of the log. We want more
// recently squashed commits to appear earlier in the log, so we
// reverse the predecessors and visit them from right to left
// instead, giving an order of [Y, C, X, B, A].
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 be15efb

Please sign in to comment.