Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 899beb7

Browse files
committed
Still more tweaking of git_changelog.
1. Don't assume there's only one candidate match; check them all and use the one with the closest timestamp. Avoids funny output when someone makes several successive commits with the same log message, as certain people have been known to do. 2. When the same commit (with the same SHA1) is reachable from multiple branch tips, don't report it for all the branches; instead report it only for the first such branch. Given our development practices, this case arises only for commits that occurred before a given branch split off from master. The original coding blamed old commits on *all* the branches, which isn't terribly useful; the new coding blames such a commit only on master.
1 parent 30d2e10 commit 899beb7

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/tools/git_changelog

+19-5
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ for my $branch (@BRANCHES) {
4747
my $pid =
4848
IPC::Open2::open2(my $git_out, my $git_in, @git, "origin/$branch")
4949
|| die "can't run @git origin/$branch: $!";
50-
my $commitnum = 0;
5150
my %commit;
5251
while (my $line = <$git_out>) {
5352
if ($line =~ /^commit\s+(.*)/) {
@@ -56,7 +55,6 @@ for my $branch (@BRANCHES) {
5655
'branch' => $branch,
5756
'commit' => $1,
5857
'message' => '',
59-
'commitnum' => $commitnum++,
6058
);
6159
}
6260
elsif ($line =~ /^Author:\s+(.*)/) {
@@ -127,21 +125,37 @@ sub push_commit {
127125
my $ht = hash_commit($c);
128126
my $ts = parse_datetime($c->{'date'});
129127
my $cc;
128+
# Note that this code will never merge two commits on the same branch,
129+
# even if they have the same hash (author/message) and nearby
130+
# timestamps. This means that there could be multiple potential
131+
# matches when we come to add a commit from another branch. Prefer
132+
# the closest-in-time one.
130133
for my $candidate (@{$all_commits{$ht}}) {
131-
if (abs($ts - $candidate->{'timestamp'}) < $timestamp_slop
132-
&& !exists $candidate->{'branch_position'}{$c->{'branch'}})
134+
my $diff = abs($ts - $candidate->{'timestamp'});
135+
if ($diff < $timestamp_slop &&
136+
!exists $candidate->{'branch_position'}{$c->{'branch'}})
133137
{
138+
if (!defined $cc ||
139+
$diff < abs($ts - $cc->{'timestamp'})) {
134140
$cc = $candidate;
135-
last;
141+
}
136142
}
137143
}
138144
if (!defined $cc) {
139145
$cc = {
140146
'header' => sprintf("Author: %s\n", $c->{'author'}),
141147
'message' => $c->{'message'},
148+
'commit' => $c->{'commit'},
142149
'timestamp' => $ts
143150
};
144151
push @{$all_commits{$ht}}, $cc;
152+
} elsif ($cc->{'commit'} eq $c->{'commit'}) {
153+
# If this is exactly the same commit we saw before on another
154+
# branch, ignore it. Hence, a commit that's reachable from more
155+
# than one branch head will be reported only for the first
156+
# head it's reachable from. This will give the desired results
157+
# so long as @BRANCHES is ordered with master first.
158+
return;
145159
}
146160
$cc->{'header'} .= sprintf "Branch: %s [%s] %s\n",
147161
$c->{'branch'}, substr($c->{'commit'}, 0, 9), $c->{'date'};

0 commit comments

Comments
 (0)