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

Display 'theirs' branch name when possible in merge.

Displaying the SHA1 of 'their' branch (the branch being merged into the current branch) is not nearly as friendly as just displaying the name of that branch, especially if that branch is already local to this repository. git-merge now sets the environment variable 'GITHEAD_%(sha1)=%(name)' for each argument it gets passed, making the actual input name that resolved to the commit '%(sha1)' easily available to the invoked merge strategy. git-merge-recursive makes use of these environment variables when they are available by using '%(name)' whenever it outputs the commit identification rather than '%(sha1)'. This is most obvious in the conflict hunks created by xdl_merge: $ git mege sideb~1 <<<<<<< HEAD:INSTALL Good! ======= Oops. >>>>>>> sideb~1:INSTALL [jc: adjusted a test script and a minor constness glitch.] Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Shawn O. Pearce committed Dec 23, 2006 at 03:44 UTC e0ec18192db8a5f80705a81dfaa1caa3e6c48c1a
3 files changed +21 -4
git-merge.sh
+2
@@ -221,6 +221,8 @@ do
221 remotehead=$(git-rev-parse --verify "$remote"^0 2>/dev/null) ||
222 die "$remote - not something we can merge"
223 remoteheads="${remoteheads}$remotehead "
224 + eval GITHEAD_$remotehead='"$remote"'
225 + export GITHEAD_$remotehead
226 done
227 set x $remoteheads ; shift
228
merge-recursive.c
+16 -1
@@ -1263,6 +1263,18 @@ static struct commit *get_ref(const char *ref)
1263 return (struct commit *)object;
1264 }
1265
1266 +static const char *better_branch_name(const char *branch)
1267 +{
1268 + static char githead_env[8 + 40 + 1];
1269 + char *name;
1270 +
1271 + if (strlen(branch) != 40)
1272 + return branch;
1273 + sprintf(githead_env, "GITHEAD_%s", branch);
1274 + name = getenv(githead_env);
1275 + return name ? name : branch;
1276 +}
1277 +
1278 int main(int argc, char *argv[])
1279 {
1280 static const char *bases[2];
@@ -1293,11 +1305,14 @@ int main(int argc, char *argv[])
1305
1306 branch1 = argv[++i];
1307 branch2 = argv[++i];
1296 - printf("Merging %s with %s\n", branch1, branch2);
1308
1309 h1 = get_ref(branch1);
1310 h2 = get_ref(branch2);
1311
1312 + branch1 = better_branch_name(branch1);
1313 + branch2 = better_branch_name(branch2);
1314 + printf("Merging %s with %s\n", branch1, branch2);
1315 +
1316 if (bases_count == 1) {
1317 struct commit *ancestor = get_ref(bases[0]);
1318 clean = merge(h1, h2, branch1, branch2, 0, ancestor, &result);
t/t6024-recursive-merge.sh
+3 -3
@@ -59,18 +59,18 @@ GIT_AUTHOR_DATE="2006-12-12 23:00:08" git commit -m F
59 test_expect_failure "combined merge conflicts" "git merge -m final G"
60
61 cat > expect << EOF
62 -<<<<<<< HEAD/a1
62 +<<<<<<< HEAD:a1
63 F
64 =======
65 G
66 ->>>>>>> 26f86b677eb03d4d956dbe108b29cb77061c1e73/a1
66 +>>>>>>> G:a1
67 EOF
68
69 test_expect_success "result contains a conflict" "diff -u expect a1"
70
71 git ls-files --stage > out
72 cat > expect << EOF
73 -100644 f16f906ab60483c100d1241dfc39868de9ec9fcb 1 a1
73 +100644 da056ce14a2241509897fa68bb2b3b6e6194ef9e 1 a1
74 100644 cf84443e49e1b366fac938711ddf4be2d4d1d9e9 2 a1
75 100644 fd7923529855d0b274795ae3349c5e0438333979 3 a1
76 EOF