From 7299778a958112b0339ab29365ba0d654bd5d21c Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 23 Oct 2011 14:34:36 -0400 Subject: [PATCH] Improve git_changelog's handling of inconsistent commit orderings. Use the CommitDate not the AuthorDate, as the former is representative of the order in which things went into the main repository, and the latter isn't very; we now have instances where the AuthorDate is as much as a month before the patch really went in. Also, get rid of the "commit order inversions" heuristic, which turns out not to do anything very desirable. Instead we just print commits in strict timestamp order, interpreting the "timestamp" of a merged commit as its timestamp on the newest branch it appears in. This fixes some cases where very ancient commits were being printed relatively early in the report. --- src/tools/git_changelog | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/src/tools/git_changelog b/src/tools/git_changelog index fcf78f5202..7276c11a5f 100755 --- a/src/tools/git_changelog +++ b/src/tools/git_changelog @@ -17,14 +17,9 @@ # Most of the time, matchable commits occur in the same order on all branches, # and we print them out in that order. However, if commit A occurs before # commit B on branch X and commit B occurs before commit A on branch Y, then -# there's no ordering which is consistent with both branches. -# -# When we encounter a situation where there's no single "best" commit to -# print next, we print the one that involves the least distortion of the -# commit order, summed across all branches. In the event of a tie on the -# distortion measure (which is actually the common case: normally, the -# distortion is zero), we choose the commit with latest timestamp. If -# that's a tie too, the commit from the newer branch prints first. +# there's no ordering which is consistent with both branches. In such cases +# we sort a merged commit according to its timestamp on the newest branch +# it appears in. # use strict; @@ -51,7 +46,7 @@ Getopt::Long::GetOptions('post-date' => \$post_date, 'since=s' => \$since) || usage(); usage() if @ARGV; -my @git = qw(git log --date=iso); +my @git = qw(git log --format=fuller --date=iso); push @git, '--since=' . $since if defined $since; # Collect the release tag data @@ -117,7 +112,7 @@ for my $branch (@BRANCHES) { elsif ($line =~ /^Author:\s+(.*)/) { $commit{'author'} = $1; } - elsif ($line =~ /^Date:\s+(.*)/) { + elsif ($line =~ /^CommitDate:\s+(.*)/) { $commit{'date'} = $1; } elsif ($line =~ /^\s\s/) { @@ -171,24 +166,13 @@ for my $branch (@BRANCHES) { while (1) { my $best_branch; - my $best_inversions; my $best_timestamp; for my $branch (@BRANCHES) { my $leader = $all_commits_by_branch{$branch}->[$position{$branch}]; next if !defined $leader; - my $inversions = 0; - for my $branch2 (@BRANCHES) { - if (defined $leader->{'branch_position'}{$branch2}) { - $inversions += $leader->{'branch_position'}{$branch2} - - $position{$branch2}; - } - } - if (!defined $best_inversions || - $inversions < $best_inversions || - ($inversions == $best_inversions && - $leader->{'timestamp'} > $best_timestamp)) { + if (!defined $best_branch || + $leader->{'timestamp'} > $best_timestamp) { $best_branch = $branch; - $best_inversions = $inversions; $best_timestamp = $leader->{'timestamp'}; } } @@ -203,8 +187,6 @@ while (1) { } printf " [%s] %s\n", substr($c->{'commit'}, 0, 9), $c->{'date'}; } - print "Commit-Order-Inversions: $best_inversions\n" - if $best_inversions != 0; print "\n"; print $winner->{'message'}; print "\n";