@matheusbsbs / matheus-bagliano / commits / c8b48ba476
Fork 0

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>

Junio C Hamano committed Sep 22, 2005 at 00:55 UTC c8b48ba4767ff9da19ef4f41f8d870f11742d833
4 files changed +99 -24
Makefile
+1 -1
@@ -87,7 +87,7 @@ SCRIPT_SH = \
87
88 SCRIPT_PERL = \
89 git-archimport.perl git-cvsimport.perl git-relink.perl \
90 - git-rename.perl git-shortlog.perl
90 + git-rename.perl git-shortlog.perl git-fmt-merge-msg.perl
91
92 SCRIPT_PYTHON = \
93 git-merge-recursive.py
git-fmt-merge-msg.perl new
+93
@@ -0,0 +1,93 @@
1 +#!/usr/bin/perl -w
2 +#
3 +# Copyright (c) 2005 Junio C Hamano
4 +#
5 +# Read .git/FETCH_HEAD and make a human readable merge message
6 +# by grouping branches and tags together to form a single line.
7 +
8 +use strict;
9 +
10 +my @src;
11 +my %src;
12 +sub andjoin {
13 + my ($label, $labels, $stuff) = @_;
14 + my $l = scalar @$stuff;
15 + my $m = '';
16 + if ($l == 0) {
17 + return ();
18 + }
19 + if ($l == 1) {
20 + $m = "$label$stuff->[0]";
21 + }
22 + else {
23 + $m = ("$labels" .
24 + join (', ', @{$stuff}[0..$l-2]) .
25 + " and $stuff->[-1]");
26 + }
27 + return ($m);
28 +}
29 +
30 +while (<>) {
31 + my ($bname, $tname, $gname, $src);
32 + chomp;
33 + s/^[0-9a-f]* //;
34 + if (s/ of (.*)$//) {
35 + $src = $1;
36 + } else {
37 + # Pulling HEAD
38 + $src = $_;
39 + $_ = 'HEAD';
40 + }
41 + if (! exists $src{$src}) {
42 + push @src, $src;
43 + $src{$src} = {
44 + BRANCH => [],
45 + TAG => [],
46 + GENERIC => [],
47 + # &1 == has HEAD.
48 + # &2 == has others.
49 + HEAD_STATUS => 0,
50 + };
51 + }
52 + if (/^branch (.*)$/) {
53 + push @{$src{$src}{BRANCH}}, $1;
54 + $src{$src}{HEAD_STATUS} |= 2;
55 + }
56 + elsif (/^tag (.*)$/) {
57 + push @{$src{$src}{TAG}}, $1;
58 + $src{$src}{HEAD_STATUS} |= 2;
59 + }
60 + elsif (/^HEAD$/) {
61 + $src{$src}{HEAD_STATUS} |= 1;
62 + }
63 + else {
64 + push @{$src{$src}{GENERIC}}, $_;
65 + $src{$src}{HEAD_STATUS} |= 2;
66 + }
67 +}
68 +
69 +my @msg;
70 +for my $src (@src) {
71 + if ($src{$src}{HEAD_STATUS} == 1) {
72 + # Only HEAD is fetched, nothing else.
73 + push @msg, $src;
74 + next;
75 + }
76 + my @this;
77 + if ($src{$src}{HEAD_STATUS} == 3) {
78 + # HEAD is fetched among others.
79 + push @this, andjoin('', '', ['HEAD']);
80 + }
81 + push @this, andjoin("branch ", "branches ",
82 + $src{$src}{BRANCH});
83 + push @this, andjoin("tag ", "tags ",
84 + $src{$src}{TAG});
85 + push @this, andjoin("commit ", "commits ",
86 + $src{$src}{GENERIC});
87 + my $this = join(', ', @this);
88 + if ($src ne '.') {
89 + $this .= " from $src";
90 + }
91 + push @msg, $this;
92 +}
93 +print "Merge ", join("; ", @msg), "\n";
git-octopus.sh
+3 -16
@@ -27,7 +27,7 @@ test "$(git-diff-index --cached "$head")" = "" ||
27 # MRC is the current "merge reference commit"
28 # MRT is the current "merge result tree"
29
30 -MRC=$head MSG= PARENT="-p $head"
30 +MRC=$head PARENT="-p $head"
31 MRT=$(git-write-tree)
32 CNT=1 ;# counting our head
33 NON_FF_MERGE=0
@@ -44,8 +44,6 @@ do
44
45 CNT=`expr $CNT + 1`
46 PARENT="$PARENT -p $SHA1"
47 - MSG="$MSG
48 - $REPO"
47
48 if test "$common,$NON_FF_MERGE" = "$MRC,0"
49 then
@@ -84,20 +82,9 @@ case "$CNT" in
82 1)
83 echo "No changes."
84 exit 0 ;;
87 -2)
88 - echo "Not an Octopus; making an ordinary commit."
89 - MSG="Merge "`expr "$MSG" : '. \(.*\)'` ; # remove LF and TAB
90 - ;;
91 -*)
92 - # In an octopus, the original head is just one of the equals,
93 - # so we should list it as such.
94 - HEAD_LINK=`readlink "$GIT_DIR/HEAD"`
95 - MSG="Octopus merge of the following:
96 -
97 - $HEAD_LINK from .$MSG"
98 - ;;
85 esac
100 -result_commit=$(echo "$MSG" | git-commit-tree $MRT $PARENT)
86 +result_commit=$(git-fmt-merge-msg <"$GIT_DIR/FETCH_HEAD" |
87 + git-commit-tree $MRT $PARENT)
88 echo "Committed merge $result_commit"
89 echo $result_commit >"$GIT_DIR"/HEAD
90 git-diff-tree -p $head $result_commit | git-apply --stat
git-pull.sh
+2 -7
@@ -25,10 +25,6 @@ then
25 fi
26
27 merge_head=$(sed -e 's/ .*//' "$GIT_DIR"/FETCH_HEAD | tr '\012' ' ')
28 -merge_name=$(
29 - perl -e 'print join("; ", map { chomp; s/^[0-9a-f]* //; $_ } <>)' \
30 - "$GIT_DIR"/FETCH_HEAD
31 -)
28
29 case "$merge_head" in
30 '')
@@ -41,6 +37,5 @@ case "$merge_head" in
37 ;;
38 esac
39
44 -git-resolve \
45 - "$(cat "$GIT_DIR"/HEAD)" \
46 - $merge_head "Merge $merge_name"
40 +merge_name=$(git-fmt-merge-msg <"$GIT_DIR/FETCH_HEAD")
41 +git-resolve "$(cat "$GIT_DIR"/HEAD)" $merge_head "$merge_name"