3 # Copyright (c) 2005 Junio C Hamano
5 # Read .git/FETCH_HEAD and make a human readable merge message
6 # by grouping branches and tags together to form a single line.
8 unshift @INC, '@@INSTLIBDIR@@';
13 my $repo = Git
->repository();
18 my ($label, $labels, $stuff) = @_;
19 my $l = scalar @
$stuff;
25 $m = "$label$stuff->[0]";
29 join (', ', @
{$stuff}[0..$l-2]) .
38 $val = $repo->command_oneline('repo-config', '--get', 'merge.summary');
39 } catch Git
::Error
::Command with
{
41 if ($E->value() == 1) {
51 my ($bra) = $repo->command_oneline('symbolic-ref', 'HEAD');
52 $bra =~ s
|^refs
/heads/||;
53 if ($bra ne 'master') {
64 foreach ($repo->command('log', '--no-merges', '--topo-order', '--pretty=oneline', $tip, '^HEAD')) {
73 my ($bname, $tname, $gname, $src, $sha1, $origin);
77 next if (/^not-for-merge/);
86 if (! exists $src{$src}) {
98 if (/^branch (.*)$/) {
100 push @
{$src{$src}{BRANCH
}}, $1;
101 $src{$src}{HEAD_STATUS
} |= 2;
103 elsif (/^tag (.*)$/) {
105 push @
{$src{$src}{TAG
}}, $1;
106 $src{$src}{HEAD_STATUS
} |= 2;
108 elsif (/^remote branch (.*)$/) {
110 push @
{$src{$src}{R_BRANCH
}}, $1;
111 $src{$src}{HEAD_STATUS
} |= 2;
115 $src{$src}{HEAD_STATUS
} |= 1;
118 push @
{$src{$src}{GENERIC
}}, $_;
119 $src{$src}{HEAD_STATUS
} |= 2;
122 if ($src eq '.' || $src eq $origin) {
123 $origin =~ s/^'(.*)'$/$1/;
124 push @origin, [$sha1, "$origin"];
127 push @origin, [$sha1, "$origin of $src"];
133 if ($src{$src}{HEAD_STATUS
} == 1) {
134 # Only HEAD is fetched, nothing else.
139 if ($src{$src}{HEAD_STATUS
} == 3) {
140 # HEAD is fetched among others.
141 push @this, andjoin
('', '', ['HEAD']);
143 push @this, andjoin
("branch ", "branches ",
145 push @this, andjoin
("remote branch ", "remote branches ",
146 $src{$src}{R_BRANCH
});
147 push @this, andjoin
("tag ", "tags ",
149 push @this, andjoin
("commit ", "commits ",
150 $src{$src}{GENERIC
});
151 my $this = join(', ', @this);
158 my $into = current_branch
();
160 print "Merge ", join("; ", @msg), $into, "\n";
166 # We limit the merge message to the latst 20 or so per each branch.
170 my ($sha1, $name) = @
$_;
171 my @log = shortlog
($sha1);
172 if ($limit + 1 <= @log) {
173 print "\n* $name: (" . scalar(@log) . " commits)\n";
176 print "\n* $name:\n";
180 if ($limit < ++$cnt) {