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.
13 my ($label, $labels, $stuff) = @_;
14 my $l = scalar @$stuff;
20 $m = "$label$stuff->[0]";
24 join (', ', @{$stuff}[0..$l-2]) .
34 open $fh, '-|', 'git-repo-config', '--get', 'merge.summary'
45 open $fh, '-|', 'git-merge-base', '--all', 'HEAD', $other or die "$!";
46 my (@mb) = map { chomp; $_ } <$fh>;
47 close $fh or die "$!";
52 my ($tip, $limit, @base) = @_;
54 open $fh, '-|', ('git-log', "--max-count=$limit", '--topo-order',
55 '--pretty=oneline', $tip, map { "^$_" } @base)
61 close $fh or die "$!";
67 my ($bname, $tname, $gname, $src, $sha1, $origin);
71 next if (/^not-for-merge/);
80 if (! exists $src{$src}) {
91 if (/^branch (.*)$/) {
93 push @{$src{$src}{BRANCH}}, $1;
94 $src{$src}{HEAD_STATUS} |= 2;
96 elsif (/^tag (.*)$/) {
98 push @{$src{$src}{TAG}}, $1;
99 $src{$src}{HEAD_STATUS} |= 2;
103 $src{$src}{HEAD_STATUS} |= 1;
106 push @{$src{$src}{GENERIC}}, $_;
107 $src{$src}{HEAD_STATUS} |= 2;
110 if ($src eq '.' || $src eq $origin) {
111 $origin =~ s/^'(.*)'$/$1/;
112 push @origin, [$sha1, "$origin"];
115 push @origin, [$sha1, "$origin of $src"];
121 if ($src{$src}{HEAD_STATUS} == 1) {
122 # Only HEAD is fetched, nothing else.
127 if ($src{$src}{HEAD_STATUS} == 3) {
128 # HEAD is fetched among others.
129 push @this, andjoin('', '', ['HEAD']);
131 push @this, andjoin("branch ", "branches ",
133 push @this, andjoin("tag ", "tags ",
135 push @this, andjoin("commit ", "commits ",
136 $src{$src}{GENERIC});
137 my $this = join(', ', @this);
143 print "Merge ", join("; ", @msg), "\n";
149 # We limit the merge message to the latst 20 or so per each branch.
153 my ($sha1, $name) = @$_;
154 my @mb = mergebase($sha1);
155 my @log = shortlog($sha1, $limit + 1, @mb);
156 if ($limit + 1 <= @log) {
157 print "\n* $name: (" . scalar(@log) . " commits)\n";
160 print "\n* $name:\n";
164 if ($limit < ++$cnt) {