55#
66# Display all commits on active branches, merging together commits from
77# different branches that occur close together in time and with identical
8- # log messages. Most of the time, such commits occur in the same order
9- # on all branches, and we print them out in that order. However, if commit
10- # A occurs before commit B on branch X and commit B occurs before commit A
11- # on branch Y, then there's no ordering which is consistent with both
12- # branches.
8+ # log messages.
9+ #
10+ # Most of the time, matchable commits occur in the same order on all branches,
11+ # and we print them out in that order. However, if commit A occurs before
12+ # commit B on branch X and commit B occurs before commit A on branch Y, then
13+ # there's no ordering which is consistent with both branches.
1314#
1415# When we encounter a situation where there's no single "best" commit to
1516# print next, we print the one that involves the least distortion of the
16- # commit order, summed across all branches. In the event of a further tie,
17- # the commit from the newer branch prints first. It is best not to sort
18- # based on timestamp, because git timestamps aren't necessarily in order
19- # (since the timestamp is provided by the committer's machine), even though
20- # for the portion of the history we imported from CVS, we expect that they
21- # will be.
22- #
23- # Even though we don't use timestamps to order commits, they are used to
24- # identify which commits happened at about the same time, for the purpose
25- # of matching up commits from different branches.
17+ # commit order, summed across all branches. In the event of a tie on the
18+ # distortion measure (which is actually the common case: normally, the
19+ # distortion is zero), we choose the commit with latest timestamp. If
20+ # that's a tie too, the commit from the newer branch prints first.
2621#
2722
2823use strict;
@@ -48,12 +43,12 @@ push @git, '--since=' . $since if defined $since;
4843my %all_commits ;
4944my %all_commits_by_branch ;
5045
51- my %commit ;
5246for my $branch (@BRANCHES ) {
53- my $commitnum = 0;
5447my $pid =
5548 IPC::Open2::open2(my $git_out ,my $git_in ,@git ," origin/$branch " )
5649 ||die " can't run@git origin/$branch :$! " ;
50+ my $commitnum = 0;
51+ my %commit ;
5752while (my $line = <$git_out >) {
5853if ($line =~/ ^commit\s +(.*)/ ) {
5954push_commit(\%commit )if %commit ;
@@ -74,6 +69,7 @@ for my $branch (@BRANCHES) {
7469$commit {' message' } .=$line ;
7570}
7671}
72+ push_commit(\%commit )if %commit ;
7773waitpid ($pid , 0);
7874my $child_exit_status =$? >> 8;
7975die " @git origin/$branch failed" if $child_exit_status != 0;
@@ -87,6 +83,7 @@ for my $branch (@BRANCHES) {
8783while (1) {
8884my $best_branch ;
8985my $best_inversions ;
86+ my $best_timestamp ;
9087for my $branch (@BRANCHES ) {
9188my $leader =$all_commits_by_branch {$branch }-> [$position {$branch }];
9289next if !defined $leader ;
@@ -97,9 +94,13 @@ while (1) {
9794-$position {$branch2 };
9895}
9996}
100- if (!defined $best_inversions ||$inversions <$best_inversions ) {
97+ if (!defined $best_inversions ||
98+ $inversions <$best_inversions ||
99+ ($inversions ==$best_inversions &&
100+ $leader -> {' timestamp' } >$best_timestamp )) {
101101$best_branch =$branch ;
102102$best_inversions =$inversions ;
103+ $best_timestamp =$leader -> {' timestamp' };
103104}
104105}
105106last if !defined $best_branch ;