@matheusbsbs / matheus-bagliano / commits / 1cb303872a
Fork 0

fmt-merge-msg: show summary of what is merged.

In addition to the branch names, populate the log message with one-line description from actual commits that are being merged. This was prompted by Len's 12-way octopus. You need to have 'merge.summary' in the configuration file to enable it: $ git repo-config merge.summary yes Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Feb 3, 2006 at 19:20 UTC 1cb303872ab1ba73fcc52167c61fc4211c843cf5
1 file changed +77 -2
git-fmt-merge-msg.perl
+77 -2
@@ -27,10 +27,47 @@ sub andjoin {
27 return ($m);
28 }
29
30 +sub repoconfig {
31 + my $fh;
32 + my $val;
33 + eval {
34 + open $fh, '-|', 'git-repo-config', '--get', 'merge.summary'
35 + or die "$!";
36 + ($val) = <$fh>;
37 + close $fh;
38 + };
39 + return $val;
40 +}
41 +
42 +sub mergebase {
43 + my ($other) = @_;
44 + my $fh;
45 + open $fh, '-|', 'git-merge-base', '--all', 'HEAD', $other or die "$!";
46 + my (@mb) = map { chomp; $_ } <$fh>;
47 + close $fh or die "$!";
48 + return @mb;
49 +}
50 +
51 +sub shortlog {
52 + my ($tip, $limit, @base) = @_;
53 + my ($fh, @result);
54 + open $fh, '-|', ('git-log', "--max-count=$limit", '--topo-order',
55 + '--pretty=oneline', $tip, map { "^$_" } @base)
56 + or die "$!";
57 + while (<$fh>) {
58 + s/^[0-9a-f]{40}\s+//;
59 + push @result, $_;
60 + }
61 + close $fh or die "$!";
62 + return @result;
63 +}
64 +
65 +my @origin = ();
66 while (<>) {
31 - my ($bname, $tname, $gname, $src);
67 + my ($bname, $tname, $gname, $src, $sha1, $origin);
68 chomp;
33 - s/^[0-9a-f]* //;
69 + s/^([0-9a-f]*) //;
70 + $sha1 = $1;
71 next if (/^not-for-merge/);
72 s/^ //;
73 if (s/ of (.*)$//) {
@@ -52,19 +89,30 @@ while (<>) {
89 };
90 }
91 if (/^branch (.*)$/) {
92 + $origin = $1;
93 push @{$src{$src}{BRANCH}}, $1;
94 $src{$src}{HEAD_STATUS} |= 2;
95 }
96 elsif (/^tag (.*)$/) {
97 + $origin = $_;
98 push @{$src{$src}{TAG}}, $1;
99 $src{$src}{HEAD_STATUS} |= 2;
100 }
101 elsif (/^HEAD$/) {
102 + $origin = $src;
103 $src{$src}{HEAD_STATUS} |= 1;
104 }
105 else {
106 push @{$src{$src}{GENERIC}}, $_;
107 $src{$src}{HEAD_STATUS} |= 2;
108 + $origin = $src;
109 + }
110 + if ($src eq '.' || $src eq $origin) {
111 + $origin =~ s/^'(.*)'$/$1/;
112 + push @origin, [$sha1, "$origin"];
113 + }
114 + else {
115 + push @origin, [$sha1, "$origin of $src"];
116 }
117 }
118
@@ -93,3 +141,30 @@ for my $src (@src) {
141 push @msg, $this;
142 }
143 print "Merge ", join("; ", @msg), "\n";
144 +
145 +if (!repoconfig) {
146 + exit(0);
147 +}
148 +
149 +# We limit the merge message to the latst 20 or so per each branch.
150 +my $limit = 20;
151 +
152 +for (@origin) {
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";
158 + }
159 + else {
160 + print "\n* $name:\n";
161 + }
162 + my $cnt = 0;
163 + for my $log (@log) {
164 + if ($limit < ++$cnt) {
165 + print " ...\n";
166 + last;
167 + }
168 + print " $log";
169 + }
170 +}