{"thread":{"id":"6090","subject":"[PATCH 2/2] Display 'theirs' branch name when possible in merge.","startedAt":"2006-12-23T08:44:47Z","lastAt":"2006-12-23T09:11:28Z","messageCount":2,"participants":["Shawn O. Pearce","Jakub Narebski"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"30185","messageId":"20061223084447.GB10203@spearce.org","threadId":"6090","inReplyTo":"6115ec06459724c7c37c355805462cb61715e9c5.1166863413.git.spearce@spearce.org","subject":"[PATCH 2/2] Display 'theirs' branch name when possible in merge.","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-12-23T08:44:47Z","receivedAt":"2006-12-23T08:44:47Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Displaying the SHA1 of 'their' branch (the branch being merged into\nthe current branch) is not nearly as friendly as just displaying\nthe name of that branch, especially if that branch is already local\nto this repository.\n\ngit-merge now sets the environment variable 'GITHEAD_%(sha1)=%(name)'\nfor each argument it gets passed, making the actual input name that\nresolved to the commit '%(sha1)' easily available to the invoked\nmerge strategy.\n\ngit-merge-recursive makes use of these environment variables when\nthey are available by using '%(name)' whenever it outputs the commit\nidentification rather than '%(sha1)'.  This is most obvious in the\nconflict hunks created by xdl_merge:\n\n  $ git mege sideb~1\n  <<<<<<< HEAD:INSTALL\n     Good!\n  =======\n     Oops.\n  >>>>>>> sideb~1:INSTALL\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n git-merge.sh      |    2 ++\n merge-recursive.c |   17 ++++++++++++++++-\n 2 files changed, 18 insertions(+), 1 deletions(-)\n\ndiff --git a/git-merge.sh b/git-merge.sh\nindex a17aa2c..5c2d03b 100755\n--- a/git-merge.sh\n+++ b/git-merge.sh\n@@ -266,6 +266,8 @@ do\n \tremotehead=$(git-rev-parse --verify \"$remote\"^0 2>/dev/null) ||\n \t    die \"$remote - not something we can merge\"\n \tremoteheads=\"${remoteheads}$remotehead \"\n+\teval GITHEAD_$remotehead='\"$remote\"'\n+\texport GITHEAD_$remotehead\n done\n set x $remoteheads ; shift\n \ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex abebb95..a96821c 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -1263,6 +1263,18 @@ static struct commit *get_ref(const char *ref)\n \treturn (struct commit *)object;\n }\n \n+static char* better_branch_name(const char *branch)\n+{\n+\tstatic char githead_env[8 + 40 + 1];\n+\tchar* name;\n+\n+\tif (strlen(branch) != 40)\n+\t\treturn branch;\n+\tsprintf(githead_env, \"GITHEAD_%s\", branch);\n+\tname = getenv(githead_env);\n+\treturn name ? name : branch;\n+}\n+\n int main(int argc, char *argv[])\n {\n \tstatic const char *bases[2];\n@@ -1293,11 +1305,14 @@ int main(int argc, char *argv[])\n \n \tbranch1 = argv[++i];\n \tbranch2 = argv[++i];\n-\tprintf(\"Merging %s with %s\\n\", branch1, branch2);\n \n \th1 = get_ref(branch1);\n \th2 = get_ref(branch2);\n \n+\tbranch1 = better_branch_name(branch1);\n+\tbranch2 = better_branch_name(branch2);\n+\tprintf(\"Merging %s with %s\\n\", branch1, branch2);\n+\n \tif (bases_count == 1) {\n \t\tstruct commit *ancestor = get_ref(bases[0]);\n \t\tclean = merge(h1, h2, branch1, branch2, 0, ancestor, &result);\n-- \n1.4.4.3.g87d8\n"},{"id":"30187","messageId":"emirms$kh3$1@sea.gmane.org","threadId":"6090","inReplyTo":"20061223084447.GB10203@spearce.org","subject":"Re: [PATCH 2/2] Display 'theirs' branch name when possible in merge.","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2006-12-23T09:11:28Z","receivedAt":"2006-12-23T09:11:28Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Shawn O. Pearce wrote:\n\n> Displaying the SHA1 of 'their' branch (the branch being merged into\n> the current branch) is not nearly as friendly as just displaying\n> the name of that branch, especially if that branch is already local\n> to this repository.\n> \n> git-merge now sets the environment variable 'GITHEAD_%(sha1)=%(name)'\n> for each argument it gets passed, making the actual input name that\n> resolved to the commit '%(sha1)' easily available to the invoked\n> merge strategy.\n> \n> git-merge-recursive makes use of these environment variables when\n> they are available by using '%(name)' whenever it outputs the commit\n> identification rather than '%(sha1)'.  This is most obvious in the\n> conflict hunks created by xdl_merge:\n> \n>   $ git mege sideb~1\n      git merge sideb~1\n>   <<<<<<< HEAD:INSTALL\n>      Good!\n>   =======\n>      Oops.\n>   >>>>>>> sideb~1:INSTALL\n\nVery nice. Thanks.\n-- \nJakub Narebski\nWarsaw, Poland\nShadeHawk on #git\n"}]}