{"thread":{"id":"14753","subject":"[PATCH] Fix merge name generation in \"merge in C\"","startedAt":"2008-07-30T08:12:19Z","lastAt":"2008-10-13T21:03:48Z","messageCount":4,"participants":["Junio C Hamano","Miklos Vajna","Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"85589","messageId":"7vabfz7puk.fsf@gitster.siamese.dyndns.org","threadId":"14753","inReplyTo":null,"subject":"[PATCH] Fix merge name generation in \"merge in C\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-07-30T08:12:19Z","receivedAt":"2008-07-30T08:12:19Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"When merging an early part of a branch, e.g. \"git merge xyzzy~20\", we were\nsupposed to say \"branch 'xyzzy' (early part)\", but it incorrectly said\n\"branch 'refs/heads/xy' (early part)\" instead.\n\nThe logic was supposed to first strip away \"~20\" part to make sure that\nwhat follows \"~\" is a non-zero posint, prefix it with \"refs/heads/\" and\nask resolve_ref() if it is a ref.  If it is, then we know xyzzy was a\nbranch, and we can give the correct message.\n\nHowever, there were a few bugs.  First of all, the logic to build this\n\"true branch refname\" did not count the characters correctly.  At this\npoint of the code, \"len\" is the number of trailing, non-name part of the\ngiven extended SHA-1 expression given by the user, i.e. number of bytes in\n\"~20\" in the above example.\n\nIn addition, the message forgot to skip \"refs/heads/\" it prefixed from the\noutput.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n * It is a bit surprising that after beating merge-in-C to death, we\n   still find a minor breakage like this.\n\n builtin-merge.c |    4 ++--\n 1 files changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin-merge.c b/builtin-merge.c\nindex e78fa18..dde0c7e 100644\n--- a/builtin-merge.c\n+++ b/builtin-merge.c\n@@ -396,12 +396,12 @@ static void merge_name(const char *remote, struct strbuf *msg)\n \t\tstruct strbuf truname = STRBUF_INIT;\n \t\tstrbuf_addstr(&truname, \"refs/heads/\");\n \t\tstrbuf_addstr(&truname, remote);\n-\t\tstrbuf_setlen(&truname, len+11);\n+\t\tstrbuf_setlen(&truname, truname.len - len);\n \t\tif (resolve_ref(truname.buf, buf_sha, 0, 0)) {\n \t\t\tstrbuf_addf(msg,\n \t\t\t\t    \"%s\\t\\tbranch '%s'%s of .\\n\",\n \t\t\t\t    sha1_to_hex(remote_head->sha1),\n-\t\t\t\t    truname.buf,\n+\t\t\t\t    truname.buf + 11,\n \t\t\t\t    (early ? \" (early part)\" : \"\"));\n \t\t\treturn;\n \t\t}\n"},{"id":"85652","messageId":"1217438608-28855-1-git-send-email-vmiklos@frugalware.org","threadId":"14753","inReplyTo":"7vabfz7puk.fsf@gitster.siamese.dyndns.org","subject":"[PATCH] Add testcase to ensure merging an early part of a branch is done properly","fromName":"Miklos Vajna","fromEmail":"vmiklos@frugalware.org","sentAt":"2008-07-30T17:23:28Z","receivedAt":"2008-07-30T17:23:28Z","isPatch":true,"sender":{"key":"vmiklos@frugalware.org","avatar":"https://gravatar.com/avatar/401c1cbbb3a5d13e650c691a2c71d6fd0b80df1a01bc74d9f1972675dd58f2bd?d=mp&s=160"},"body":"Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>\n---\n\nOn Wed, Jul 30, 2008 at 01:12:19AM -0700, Junio C Hamano <gitster@pobox.com> wrote:\n> In addition, the message forgot to skip \"refs/heads/\" it prefixed from\n> the\n> output.\n>\n> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n> ---\n>  * It is a bit surprising that after beating merge-in-C to death, we\n>    still find a minor breakage like this.\n\nUh-oh. Here is a testcase that fails with master, but passes with your\npatch.\n\nThanks for catching this.\n\n t/t7607-merge-early.sh |   39 +++++++++++++++++++++++++++++++++++++++\n 1 files changed, 39 insertions(+), 0 deletions(-)\n create mode 100755 t/t7607-merge-early.sh\n\ndiff --git a/t/t7607-merge-early.sh b/t/t7607-merge-early.sh\nnew file mode 100755\nindex 0000000..9dd3ac5\n--- /dev/null\n+++ b/t/t7607-merge-early.sh\n@@ -0,0 +1,39 @@\n+#!/bin/sh\n+\n+test_description='git-merge\n+\n+Testing merging an early part of a branch.'\n+\n+. ./test-lib.sh\n+\n+test_expect_success 'setup' '\n+\techo c0 > c0.c &&\n+\tgit add c0.c &&\n+\tgit commit -m c0 &&\n+\tgit tag c0 &&\n+\techo c1 > c1.c &&\n+\tgit add c1.c &&\n+\tgit commit -m c1 &&\n+\tgit tag c1 &&\n+\techo c2 > c2.c &&\n+\tgit add c2.c &&\n+\tgit commit -m c2 &&\n+\tgit tag c2 &&\n+\tgit reset --hard c0 &&\n+\techo c3 > c3.c &&\n+\tgit add c3.c &&\n+\tgit commit -m c3 &&\n+\tgit tag c3\n+'\n+\n+cat >expected <<EOF\n+Merge branch 'c2' (early part)\n+EOF\n+\n+test_expect_success 'merge early part of c2' '\n+\tgit merge c2~1 &&\n+\tgit show -s --pretty=format:%s HEAD > actual &&\n+\ttest_cmp actual expected\n+'\n+\n+test_done\n-- \n1.6.0.rc0.14.g95f8.dirty\n"},{"id":"92962","messageId":"1223931265-8862-1-git-send-email-vmiklos@frugalware.org","threadId":"14753","inReplyTo":"1217438608-28855-1-git-send-email-vmiklos@frugalware.org","subject":"[PATCH] Add testcase to ensure merging an early part of a branch is done properly","fromName":"Miklos Vajna","fromEmail":"vmiklos@frugalware.org","sentAt":"2008-10-13T20:54:25Z","receivedAt":"2008-10-13T20:54:25Z","isPatch":true,"sender":{"key":"vmiklos@frugalware.org","avatar":"https://gravatar.com/avatar/401c1cbbb3a5d13e650c691a2c71d6fd0b80df1a01bc74d9f1972675dd58f2bd?d=mp&s=160"},"body":"Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>\n---\n\n[ Adding Shawn to CC as the interim maintainer. ]\n\nOn Wed, Jul 30, 2008 at 07:23:28PM +0200, Miklos Vajna <vmiklos@frugalware.org> wrote:\n> Uh-oh. Here is a testcase that fails with master, but passes with your\n> patch.\n\nI remember you had a note about it's a bad habit to write a new test for\nevery bug, so here is an updated version that just improves\nt7600-merge.sh and does not adds a new one.\n\n t/t7600-merge.sh |   26 ++++++++++++++++++++++++++\n 1 files changed, 26 insertions(+), 0 deletions(-)\n\ndiff --git a/t/t7600-merge.sh b/t/t7600-merge.sh\nindex 7313ac2..a4443a7 100755\n--- a/t/t7600-merge.sh\n+++ b/t/t7600-merge.sh\n@@ -520,4 +520,30 @@ test_expect_success 'refresh the index before merging' '\n \n test_debug 'gitk --all'\n \n+cat >expected <<EOF\n+Merge branch 'c5' (early part)\n+EOF\n+\n+test_expect_success 'merge early part of c2' '\n+\tgit reset --hard c3 &&\n+\techo c4 > c4.c &&\n+\tgit add c4.c &&\n+\tgit commit -m c4 &&\n+\tgit tag c4 &&\n+\techo c5 > c5.c &&\n+\tgit add c5.c &&\n+\tgit commit -m c5 &&\n+\tgit tag c5 &&\n+\tgit reset --hard c3 &&\n+\techo c6 > c6.c &&\n+\tgit add c6.c &&\n+\tgit commit -m c6 &&\n+\tgit tag c6 &&\n+\tgit merge c5~1 &&\n+\tgit show -s --pretty=format:%s HEAD > actual &&\n+\ttest_cmp actual expected\n+'\n+\n+test_debug 'gitk --all'\n+\n test_done\n-- \n1.6.0.2\n"},{"id":"92964","messageId":"20081013210348.GU4856@spearce.org","threadId":"14753","inReplyTo":"1223931265-8862-1-git-send-email-vmiklos@frugalware.org","subject":"Re: [PATCH] Add testcase to ensure merging an early part of a branch is done properly","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-10-13T21:03:48Z","receivedAt":"2008-10-13T21:03:48Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Miklos Vajna <vmiklos@frugalware.org> wrote:\n> Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>\n> ---\n> \n> [ Adding Shawn to CC as the interim maintainer. ]\n\nIn case you missed it, Junio has the pumpkin now.  (He's picked up\nmy topics, merged my tree, and has freed me from the time sink that\nis known as maintainership.)\n \n-- \nShawn.\n"}]}