]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Fix merge name generation in "merge in C"
authorJunio C Hamano <gitster@pobox.com>
Wed, 30 Jul 2008 08:12:19 +0000 (01:12 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 30 Jul 2008 08:13:26 +0000 (01:13 -0700)
When merging an early part of a branch, e.g. "git merge xyzzy~20", we were
supposed to say "branch 'xyzzy' (early part)", but it incorrectly said
"branch 'refs/heads/xy' (early part)" instead.

The logic was supposed to first strip away "~20" part to make sure that
what follows "~" is a non-zero posint, prefix it with "refs/heads/" and
ask resolve_ref() if it is a ref.  If it is, then we know xyzzy was a
branch, and we can give the correct message.

However, there were a few bugs.  First of all, the logic to build this
"true branch refname" did not count the characters correctly.  At this
point of the code, "len" is the number of trailing, non-name part of the
given extended SHA-1 expression given by the user, i.e. number of bytes in
"~20" in the above example.

In addition, the message forgot to skip "refs/heads/" it prefixed from the
output.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-merge.c

index e78fa18b3a68e2b7f041beab0524ce1a2b7e9365..dde0c7ed33118ff8d0cc421e8a0366e342c6d011 100644 (file)
@@ -396,12 +396,12 @@ static void merge_name(const char *remote, struct strbuf *msg)
                struct strbuf truname = STRBUF_INIT;
                strbuf_addstr(&truname, "refs/heads/");
                strbuf_addstr(&truname, remote);
-               strbuf_setlen(&truname, len+11);
+               strbuf_setlen(&truname, truname.len - len);
                if (resolve_ref(truname.buf, buf_sha, 0, 0)) {
                        strbuf_addf(msg,
                                    "%s\t\tbranch '%s'%s of .\n",
                                    sha1_to_hex(remote_head->sha1),
-                                   truname.buf,
+                                   truname.buf + 11,
                                    (early ? " (early part)" : ""));
                        return;
                }