}
}
-sub scan_branches($$) {
+sub get_source($$) {
my ($ref, $new) = @_;
- # Is there any branch pointing to $new (other than $ref)?
- for (`git branch -v --no-abbrev`) {
+ # Get branch (different from $ref) whose tip is $new
+ my @branches = ();
+ for (`git for-each-ref refs/heads`) {
chomp;
- my ($name, $sha) = /^..(\S+)\s+(\S+)/ or die;
- if ((!defined($ref) || $name ne $ref) && $sha eq $new) {
- return $name;
+ my ($sha, $type, $name) = m{^(\S+) (\S+)\trefs/heads/(\S+)$} or die;
+ if ((!defined($ref) || $name ne $ref) && $sha eq $new && $type eq 'commit') {
+ push @branches, $name;
}
}
- return;
+ if (@branches == 1) {
+ return $branches[0];
+ } elsif (@branches) {
+ return sprintf("%s [and %d other]", $branches[0], @branches-1);
+ } else {
+ return;
+ }
}
sub scan_commits($$) {
if ($old =~ /^0+$/) {
# Creation of a branch
$subj .= ' Created branch';
- my $copy_of = scan_branches($branch, $new);
+ my $copy_of = get_source($branch, $new);
if (defined $copy_of) {
$subj .= " as a copy of $copy_of";
print $out "Created branch $branch as a copy of $copy_of ($new).\n";
my $c0 = $commits[0];
my $n0 = $nonmerges[0];
my $c0p = $c0->{parents};
+
if (@{$c0p} == 2 &&
($c0p->[0] eq $old || $c0p->[1] eq $old) &&
- $c0->{subject} =~ m{^\s*Merge branch '([^']*)' into (\S+)} &&
- (($1 eq $branch) != ($2 eq $branch))) {
+ (
+ $c0->{subject} =~ m{^\s*Merge branch '([^']*)' into (\S+)} &&
+ ($1 eq $branch) != ($2 eq $branch)
+ ) || (
+ $c0->{subject} =~ m{^\s*Merge branch '([^']*)'( of |$)}
+ )) {
# Pushed a merge of the current branch with another local branch
$subj .= ' ' . $c0->{subject};
} elsif ($n0) {
$subj .= ' ' . $c0->{subject};
}
- print $out "Push to branch $branch ($old -> $new)\n\n";
+ print $out "Push to branch $branch ($old..$new)\n\n";
# If there are multiple commits, mention that
if (@nonmerges > 1) {
} elsif ($lca eq $new) {
# Rewind
$subj .= ' Branch rewound';
- print $out "Rewound branch $branch ($old -> $new).\n\n";
+ print $out "Rewound branch $branch ($old..$new).\n\n";
most_recent($new);
} else {
# Otherwise it is a rebase
$subj .= ' Branch rebased';
- print $out "Rebased branch $branch ($old -> $new).\n\n";
+ print $out "Rebased branch $branch ($old..$new).\n\n";
print $out "Commits from common ancestor:\n\n";
system 'git', 'rev-list', @rev_list_options, $new, "^$old";
}
$subj .= " Deleted tag $tag";
print $out "Deleted tag $tag ($old).\n";
} else {
- my $copy_of = scan_branches(undef, $new);
+ my $copy_of = get_source(undef, $new);
my $cp = defined($copy_of) ? " to branch $copy_of" : "";
if ($old =~ /^0+/) {
$subj .= " Created tag $tag$cp";
print $out "Created tag $tag$cp ($new).\n\n";
} else {
$subj .= " Changed tag $tag$cp";
- print $out "Changed tag $tag$cp ($old -> $new).\n\n";
+ print $out "Changed tag $tag$cp ($old..$new).\n\n";
}
most_recent($new);
}
'-x',
'-e', 'set charset="utf-8"',
'-e', 'set send_charset="us-ascii:iso-8859-2:utf-8"',
+ '-e', 'set record=',
'-s', $headers->{'Subject'},
);
delete $headers->{'Subject'};