Skip to content

Commit

Permalink
Improve git_changelog's handling of inconsistent commit orderings.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tglsfdc committed Oct 23, 2011
1 parent 0f39d50 commit 7299778
Showing 1 changed file with 7 additions and 25 deletions.
32 changes: 7 additions & 25 deletions src/tools/git_changelog
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -17,14 +17,9 @@
# Most of the time, matchable commits occur in the same order on all branches, # 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 # 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 # 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. # 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
# When we encounter a situation where there's no single "best" commit to # it appears in.
# 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.
# #


use strict; use strict;
Expand All @@ -51,7 +46,7 @@ Getopt::Long::GetOptions('post-date' => \$post_date,
'since=s' => \$since) || usage(); 'since=s' => \$since) || usage();
usage() if @ARGV; 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; push @git, '--since=' . $since if defined $since;


# Collect the release tag data # Collect the release tag data
Expand Down Expand Up @@ -117,7 +112,7 @@ for my $branch (@BRANCHES) {
elsif ($line =~ /^Author:\s+(.*)/) { elsif ($line =~ /^Author:\s+(.*)/) {
$commit{'author'} = $1; $commit{'author'} = $1;
} }
elsif ($line =~ /^Date:\s+(.*)/) { elsif ($line =~ /^CommitDate:\s+(.*)/) {
$commit{'date'} = $1; $commit{'date'} = $1;
} }
elsif ($line =~ /^\s\s/) { elsif ($line =~ /^\s\s/) {
Expand Down Expand Up @@ -171,24 +166,13 @@ for my $branch (@BRANCHES) {


while (1) { while (1) {
my $best_branch; my $best_branch;
my $best_inversions;
my $best_timestamp; my $best_timestamp;
for my $branch (@BRANCHES) { for my $branch (@BRANCHES) {
my $leader = $all_commits_by_branch{$branch}->[$position{$branch}]; my $leader = $all_commits_by_branch{$branch}->[$position{$branch}];
next if !defined $leader; next if !defined $leader;
my $inversions = 0; if (!defined $best_branch ||
for my $branch2 (@BRANCHES) { $leader->{'timestamp'} > $best_timestamp) {
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)) {
$best_branch = $branch; $best_branch = $branch;
$best_inversions = $inversions;
$best_timestamp = $leader->{'timestamp'}; $best_timestamp = $leader->{'timestamp'};
} }
} }
Expand All @@ -203,8 +187,6 @@ while (1) {
} }
printf " [%s] %s\n", substr($c->{'commit'}, 0, 9), $c->{'date'}; 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 "\n";
print $winner->{'message'}; print $winner->{'message'};
print "\n"; print "\n";
Expand Down

0 comments on commit 7299778

Please sign in to comment.