diff options
author | Junio C Hamano <junkio@cox.net> | 2005-09-22 00:55:22 -0700 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2005-09-22 18:09:07 -0700 |
commit | c8b48ba4767ff9da19ef4f41f8d870f11742d833 (patch) | |
tree | 3d0e6f09fd3189d9b684d064529eb81c5128a517 /git-fmt-merge-msg.perl | |
parent | f8ff0c0641a14770a2214fffbd4271b1ea3a0d61 (diff) | |
download | git-c8b48ba4767ff9da19ef4f41f8d870f11742d833.tar.gz |
Prettyprint octopus merge message.
Including the current branch in the list of heads being merged
was not a good idea, so drop it. And shorten the message by
grouping branches and tags together to form a single line.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'git-fmt-merge-msg.perl')
-rwxr-xr-x | git-fmt-merge-msg.perl | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/git-fmt-merge-msg.perl b/git-fmt-merge-msg.perl new file mode 100755 index 0000000000..f0f3100eb1 --- /dev/null +++ b/git-fmt-merge-msg.perl @@ -0,0 +1,93 @@ +#!/usr/bin/perl -w +# +# Copyright (c) 2005 Junio C Hamano +# +# Read .git/FETCH_HEAD and make a human readable merge message +# by grouping branches and tags together to form a single line. + +use strict; + +my @src; +my %src; +sub andjoin { + my ($label, $labels, $stuff) = @_; + my $l = scalar @$stuff; + my $m = ''; + if ($l == 0) { + return (); + } + if ($l == 1) { + $m = "$label$stuff->[0]"; + } + else { + $m = ("$labels" . + join (', ', @{$stuff}[0..$l-2]) . + " and $stuff->[-1]"); + } + return ($m); +} + +while (<>) { + my ($bname, $tname, $gname, $src); + chomp; + s/^[0-9a-f]* //; + if (s/ of (.*)$//) { + $src = $1; + } else { + # Pulling HEAD + $src = $_; + $_ = 'HEAD'; + } + if (! exists $src{$src}) { + push @src, $src; + $src{$src} = { + BRANCH => [], + TAG => [], + GENERIC => [], + # &1 == has HEAD. + # &2 == has others. + HEAD_STATUS => 0, + }; + } + if (/^branch (.*)$/) { + push @{$src{$src}{BRANCH}}, $1; + $src{$src}{HEAD_STATUS} |= 2; + } + elsif (/^tag (.*)$/) { + push @{$src{$src}{TAG}}, $1; + $src{$src}{HEAD_STATUS} |= 2; + } + elsif (/^HEAD$/) { + $src{$src}{HEAD_STATUS} |= 1; + } + else { + push @{$src{$src}{GENERIC}}, $_; + $src{$src}{HEAD_STATUS} |= 2; + } +} + +my @msg; +for my $src (@src) { + if ($src{$src}{HEAD_STATUS} == 1) { + # Only HEAD is fetched, nothing else. + push @msg, $src; + next; + } + my @this; + if ($src{$src}{HEAD_STATUS} == 3) { + # HEAD is fetched among others. + push @this, andjoin('', '', ['HEAD']); + } + push @this, andjoin("branch ", "branches ", + $src{$src}{BRANCH}); + push @this, andjoin("tag ", "tags ", + $src{$src}{TAG}); + push @this, andjoin("commit ", "commits ", + $src{$src}{GENERIC}); + my $this = join(', ', @this); + if ($src ne '.') { + $this .= " from $src"; + } + push @msg, $this; +} +print "Merge ", join("; ", @msg), "\n"; |