{"thread":{"id":"34201","subject":"[PATCH 0/5] Fix describe --contains --all","startedAt":"2013-06-18T17:13:23Z","lastAt":"2013-06-18T17:13:28Z","messageCount":6,"participants":["Ramkumar Ramachandra"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"221266","messageId":"1371575608-9980-1-git-send-email-artagnon@gmail.com","threadId":"34201","inReplyTo":null,"subject":"[PATCH 0/5] Fix describe --contains --all","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-06-18T17:13:23Z","receivedAt":"2013-06-18T17:13:23Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi,\n\nI discovered --contains --all in describe, and found out that it\ndoesn't work as advertised for a deep historical reason.  [3/5] is\nsuper-important and addresses this issue; everything else is\ndecoration.\n\nThanks.\n\nRamkumar Ramachandra (5):\n  prompt: clean up describe logic\n  prompt: do not double-discriminate detached HEAD\n  name-rev: fix assumption about --name-only usage\n  name-rev: strip trailing ^0 in when --name-only\n  name-rev doc: rewrite --stdin paragraph\n\n Documentation/git-name-rev.txt       | 12 +++++++-----\n builtin/name-rev.c                   | 13 ++++++++++---\n contrib/completion/git-prompt.sh     | 20 +++++++++++---------\n t/t4202-log.sh                       |  8 ++++----\n t/t6007-rev-list-cherry-pick-file.sh | 32 ++++++++++++++++----------------\n t/t9903-bash-prompt.sh               |  2 +-\n 6 files changed, 49 insertions(+), 38 deletions(-)\n\n-- \n1.8.3.1.456.gb7f4cb6.dirty\n"},{"id":"221267","messageId":"1371575608-9980-2-git-send-email-artagnon@gmail.com","threadId":"34201","inReplyTo":"1371575608-9980-1-git-send-email-artagnon@gmail.com","subject":"[PATCH 1/5] prompt: clean up describe logic","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-06-18T17:13:24Z","receivedAt":"2013-06-18T17:13:24Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"The describe logic is convoluted and unclean:\n\n1. Reading .git/HEAD by hand and using the first 7 characters, of the\n   SHA-1 does not guarantee an unambiguous output; we can use rev-parse\n   --short in its place to get a unique SHA-1.\n\n2. Use the --always option of describe to automatically output the short\n   SHA-1 when everything else fails.\n\nThe patch introduces one small change: since we are not checking the\nreturn value of describe (with --always, it always returns something\nvalid), we cannot discriminate a raw SHA-1 from everything else and\nsuffix it with a \"...\".\n\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n contrib/completion/git-prompt.sh | 16 +++++++---------\n t/t9903-bash-prompt.sh           |  2 +-\n 2 files changed, 8 insertions(+), 10 deletions(-)\n\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nindex 86a4f3f..9ed6ff1 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh\n@@ -380,20 +380,18 @@ __git_ps1 ()\n \t\t\ttest -n \"$b\" ||\n \t\t\tb=\"$(git symbolic-ref HEAD 2>/dev/null)\" || {\n \t\t\t\tdetached=yes\n-\t\t\t\tb=\"$(\n \t\t\t\tcase \"${GIT_PS1_DESCRIBE_STYLE-}\" in\n \t\t\t\t(contains)\n-\t\t\t\t\tgit describe --contains HEAD ;;\n+\t\t\t\t\tb=$(git describe --always --contains HEAD) ;;\n \t\t\t\t(branch)\n-\t\t\t\t\tgit describe --contains --all HEAD ;;\n+\t\t\t\t\tb=$(git describe --always --contains --all HEAD) ;;\n \t\t\t\t(describe)\n-\t\t\t\t\tgit describe HEAD ;;\n+\t\t\t\t\tb=$(git describe --always HEAD) ;;\n \t\t\t\t(* | default)\n-\t\t\t\t\tgit describe --tags --exact-match HEAD ;;\n-\t\t\t\tesac 2>/dev/null)\" ||\n-\n-\t\t\t\tb=\"$(cut -c1-7 \"$g/HEAD\" 2>/dev/null)...\" ||\n-\t\t\t\tb=\"unknown\"\n+\t\t\t\t\tb=$(git describe --tags --exact-match HEAD 2>/dev/null)\n+\t\t\t\t\ttest -z $b && b=\"$(git rev-parse --short HEAD)\"\n+\t\t\t\t\t;;\n+\t\t\t\tesac\n \t\t\t\tb=\"($b)\"\n \t\t\t}\n \t\tfi\ndiff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\nindex 15521cc..b0ad477 100755\n--- a/t/t9903-bash-prompt.sh\n+++ b/t/t9903-bash-prompt.sh\n@@ -169,7 +169,7 @@ test_expect_success 'prompt - branch name' '\n '\n \n test_expect_success 'prompt - detached head' '\n-\tprintf \" ((%s...))\" $(git log -1 --format=\"%h\" b1^) > expected &&\n+\tprintf \" ((%s))\" $(git log -1 --format=\"%h\" b1^) > expected &&\n \tgit checkout b1^ &&\n \ttest_when_finished \"git checkout master\" &&\n \t__git_ps1 > \"$actual\" &&\n-- \n1.8.3.1.456.gb7f4cb6.dirty\n"},{"id":"221270","messageId":"1371575608-9980-3-git-send-email-artagnon@gmail.com","threadId":"34201","inReplyTo":"1371575608-9980-1-git-send-email-artagnon@gmail.com","subject":"[PATCH 2/5] prompt: do not double-discriminate detached HEAD","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-06-18T17:13:25Z","receivedAt":"2013-06-18T17:13:25Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"When GIT_PS1_SHOWCOLORHINTS is turned on, there is no need to put a\ndetached HEAD within parenthesis: the color can be used to discriminate\nthe detached HEAD.\n\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n contrib/completion/git-prompt.sh | 6 +++++-\n 1 file changed, 5 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nindex 9ed6ff1..a127d3b 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh\n@@ -392,7 +392,11 @@ __git_ps1 ()\n \t\t\t\t\ttest -z $b && b=\"$(git rev-parse --short HEAD)\"\n \t\t\t\t\t;;\n \t\t\t\tesac\n-\t\t\t\tb=\"($b)\"\n+\n+\t\t\t\t# if there is no color, use\n+\t\t\t\t# parenthesis to indicate that the\n+\t\t\t\t# HEAD is detached\n+\t\t\t\ttest -n \"${GIT_PS1_SHOWCOLORHINTS-}\" || b=\"($b)\"\n \t\t\t}\n \t\tfi\n \n-- \n1.8.3.1.456.gb7f4cb6.dirty\n"},{"id":"221269","messageId":"1371575608-9980-4-git-send-email-artagnon@gmail.com","threadId":"34201","inReplyTo":"1371575608-9980-1-git-send-email-artagnon@gmail.com","subject":"[PATCH 3/5] name-rev: fix assumption about --name-only usage","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-06-18T17:13:26Z","receivedAt":"2013-06-18T17:13:26Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"236157 (Teach git-describe how to run name-rev, 2007-05-21) introduced\n`git name-rev --name-only`, with the intent of using it to implement\n`git describe --contains`.  According to the message, users wanted to\nuse describe to figure out which tags contains a specific commit.\nname-rev already did this, but didn't print out in the same format as\ndescribe:\n\n  $ git describe v1.8.3~1\n  v1.8.3-rc3-8-g5e49f30\n\n  $ git name-rev v1.8.3~1\n  v1.8.3~1 tags/v1.8.3~1\n\nThere are two problems with using the output of name-rev in describe:\nfirst, it prints out the given argument before describing it.  Second,\nit prefixes \"tags/\" to the tag description.  To eliminate these two\nproblems, 236157 proposed that the --name-rev option would strip these\nthings when used with --tags, to match the describe output more closely:\n\n  $ git name-rev --name-only --tags v1.8.3~1\n  v1.8.3~1\n\n236157 did not anticipate a problem with always combining --name-rev\nwith --tags, because it was primarily intended to be used from describe,\nwhere it hard-coded these two arguments in the execv() of name-rev.\n\nLater, 3f7701 (make 'git describe --all --contains' work, 2007-12-19)\nnoticed that describe didn't work with --contains and --all.  This is\nbecause --contains implied a call to --name-rev (in with --tags was\nhard-coded), but --all implied that any ref should be used to describe\nthe given argument (not just tags).  3f7701 took the band-aid approach,\nand made --all disable --tags when calling name-rev.  As a result, while\n\n  $ git describe --contains v1.8.3~1\n  v1.8.3~1\n\nwould get name-rev to print output in the same format as describe,\n\n  $ git describe --contains --all v1.8.3~1\n  tags/v1.8.3~1\n\nwould not strip the leading \"tags/\".\n\nThe bug exists in git to this day.  Fix it by removing the assumption\nthat name-rev --name-only is only intended to be used with --tags.  Also\nupdate some tests.\n\nUsers and scripts have learnt to live with 3f7701, and it will continue\nto be a small quirk.  Even after this patch, notice\n\n  $ git checkout -b foom v1.8.3\n  $ git describe --contains @~1\n  v1.8.3~1\n  $ git describe --contains --all @~1\n  foom~1\n\nIn other words, --contains implies --tags in name-rev, which gives\nprecedence to tags; --all cancels that effect thereby giving precedence\nto branches in the case of a tie.\n\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n Documentation/git-name-rev.txt       |  6 +++---\n builtin/name-rev.c                   |  3 +--\n t/t4202-log.sh                       |  8 ++++----\n t/t6007-rev-list-cherry-pick-file.sh | 32 ++++++++++++++++----------------\n 4 files changed, 24 insertions(+), 25 deletions(-)\n\ndiff --git a/Documentation/git-name-rev.txt b/Documentation/git-name-rev.txt\nindex ad1d146..5cd0d0d 100644\n--- a/Documentation/git-name-rev.txt\n+++ b/Documentation/git-name-rev.txt\n@@ -36,9 +36,9 @@ OPTIONS\n \n --name-only::\n \tInstead of printing both the SHA-1 and the name, print only\n-\tthe name.  If given with --tags the usual tag prefix of\n-\t\"tags/\" is also omitted from the name, matching the output\n-\tof `git-describe` more closely.\n+\tthe name.  The usual tag prefix of \"tags/\" is also omitted\n+\tfrom the name, matching the output of `git-describe` more\n+\tclosely.\n \n --no-undefined::\n \tDie with error code != 0 when a reference is undefined,\ndiff --git a/builtin/name-rev.c b/builtin/name-rev.c\nindex 6238247..524d790 100644\n--- a/builtin/name-rev.c\n+++ b/builtin/name-rev.c\n@@ -112,8 +112,7 @@ static int name_ref(const char *path, const unsigned char *sha1, int flags, void\n \n \t\tif (!prefixcmp(path, \"refs/heads/\"))\n \t\t\tpath = path + 11;\n-\t\telse if (data->tags_only\n-\t\t    && data->name_only\n+\t\telse if (data->name_only\n \t\t    && !prefixcmp(path, \"refs/tags/\"))\n \t\t\tpath = path + 10;\n \t\telse if (!prefixcmp(path, \"refs/\"))\ndiff --git a/t/t4202-log.sh b/t/t4202-log.sh\nindex cb03d28..9bec360 100755\n--- a/t/t4202-log.sh\n+++ b/t/t4202-log.sh\n@@ -302,7 +302,7 @@ cat > expect <<\\EOF\n | |\n | |     side-2\n | |\n-| * commit tags/side-1\n+| * commit side-1\n | | Author: A U Thor <author@example.com>\n | |\n | |     side-1\n@@ -327,17 +327,17 @@ cat > expect <<\\EOF\n |\n |       fourth\n |\n-* commit tags/side-1~1\n+* commit side-1~1\n | Author: A U Thor <author@example.com>\n |\n |     third\n |\n-* commit tags/side-1~2\n+* commit side-1~2\n | Author: A U Thor <author@example.com>\n |\n |     second\n |\n-* commit tags/side-1~3\n+* commit side-1~3\n   Author: A U Thor <author@example.com>\n \n       initial\ndiff --git a/t/t6007-rev-list-cherry-pick-file.sh b/t/t6007-rev-list-cherry-pick-file.sh\nindex 28d4f6b..5a8175e 100755\n--- a/t/t6007-rev-list-cherry-pick-file.sh\n+++ b/t/t6007-rev-list-cherry-pick-file.sh\n@@ -49,8 +49,8 @@ test_expect_success setup '\n '\n \n cat >expect <<EOF\n-<tags/B\n->tags/C\n+<B\n+>C\n EOF\n \n test_expect_success '--left-right' '\n@@ -70,7 +70,7 @@ test_expect_success '--cherry-pick foo comes up empty' '\n '\n \n cat >expect <<EOF\n->tags/C\n+>C\n EOF\n \n test_expect_success '--cherry-pick bar does not come up empty' '\n@@ -88,8 +88,8 @@ test_expect_success 'bar does not come up empty' '\n '\n \n cat >expect <<EOF\n-<tags/F\n->tags/E\n+<F\n+>E\n EOF\n \n test_expect_success '--cherry-pick bar does not come up empty (II)' '\n@@ -100,10 +100,10 @@ test_expect_success '--cherry-pick bar does not come up empty (II)' '\n '\n \n cat >expect <<EOF\n-+tags/F\n-=tags/D\n-+tags/E\n-=tags/C\n++F\n+=D\n++E\n+=C\n EOF\n \n test_expect_success '--cherry-mark' '\n@@ -114,10 +114,10 @@ test_expect_success '--cherry-mark' '\n '\n \n cat >expect <<EOF\n-<tags/F\n-=tags/D\n->tags/E\n-=tags/C\n+<F\n+=D\n+>E\n+=C\n EOF\n \n test_expect_success '--cherry-mark --left-right' '\n@@ -128,7 +128,7 @@ test_expect_success '--cherry-mark --left-right' '\n '\n \n cat >expect <<EOF\n-tags/E\n+E\n EOF\n \n test_expect_success '--cherry-pick --right-only' '\n@@ -146,8 +146,8 @@ test_expect_success '--cherry-pick --left-only' '\n '\n \n cat >expect <<EOF\n-+tags/E\n-=tags/C\n++E\n+=C\n EOF\n \n test_expect_success '--cherry' '\n-- \n1.8.3.1.456.gb7f4cb6.dirty\n"},{"id":"221268","messageId":"1371575608-9980-5-git-send-email-artagnon@gmail.com","threadId":"34201","inReplyTo":"1371575608-9980-1-git-send-email-artagnon@gmail.com","subject":"[PATCH 4/5] name-rev: strip trailing ^0 in when --name-only","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-06-18T17:13:27Z","receivedAt":"2013-06-18T17:13:27Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"236157 (Teach git-describe how to run name-rev, 2007-05-21) introduced\n`git name-rev --name-only`, with the intent of using it to implement\n`git describe --contains`.  According to the message, one of the primary\nobjectives of --name-only was to make the output of name-rev match that\nof describe.\n\n  $ git describe --contains --all master\n  master\n\n  $ git describe --contains --all master~1\n  master~1\n\n  $ git describe --contains --all v1.8.3~1\n  v1.8.3~1\n\n  $ git describe --contains --all v1.8.3\n  v1.8.3^0\n\nThe last invocation unnecessarily prints a trailing \"^0\" (--stdin does\nnot suffer from this defect).  Fix this.\n\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n builtin/name-rev.c | 10 +++++++++-\n 1 file changed, 9 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/name-rev.c b/builtin/name-rev.c\nindex 524d790..4b17209 100644\n--- a/builtin/name-rev.c\n+++ b/builtin/name-rev.c\n@@ -160,7 +160,15 @@ static void show_name(const struct object *obj,\n \tif (!name_only)\n \t\tprintf(\"%s \", caller_name ? caller_name : sha1_to_hex(sha1));\n \tname = get_rev_name(obj);\n-\tif (name)\n+\n+\tif (name && name_only) {\n+\t\t/* strip possible trailing ^0 from name */\n+\t\tint len = strlen(name);\n+\t\tif (len > 2 && !strcmp(name + len - 2, \"^0\"))\n+\t\t\tlen -= 2;\n+\t\tprintf(\"%.*s\\n\", len, name);\n+\t}\n+\telse if (name)\n \t\tprintf(\"%s\\n\", name);\n \telse if (allow_undefined)\n \t\tprintf(\"undefined\\n\");\n-- \n1.8.3.1.456.gb7f4cb6.dirty\n"},{"id":"221271","messageId":"1371575608-9980-6-git-send-email-artagnon@gmail.com","threadId":"34201","inReplyTo":"1371575608-9980-1-git-send-email-artagnon@gmail.com","subject":"[PATCH 5/5] name-rev doc: rewrite --stdin paragraph","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-06-18T17:13:28Z","receivedAt":"2013-06-18T17:13:28Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n Documentation/git-name-rev.txt | 6 ++++--\n 1 file changed, 4 insertions(+), 2 deletions(-)\n\ndiff --git a/Documentation/git-name-rev.txt b/Documentation/git-name-rev.txt\nindex 5cd0d0d..67f0487 100644\n--- a/Documentation/git-name-rev.txt\n+++ b/Documentation/git-name-rev.txt\n@@ -31,8 +31,10 @@ OPTIONS\n \tList all commits reachable from all refs\n \n --stdin::\n-\tRead from stdin, append \"(<rev_name>)\" to all sha1's of nameable\n-\tcommits, and pass to stdout\n+\tTransform stdin by substituting all the 40-character SHA-1\n+\thexes (say $hex) with \"$hex ($rev_name)\".  When used with\n+\t--name-only, substitute with \"$rev_name\", omitting $hex\n+\taltogether.  Intended for the scripter's use.\n \n --name-only::\n \tInstead of printing both the SHA-1 and the name, print only\n-- \n1.8.3.1.456.gb7f4cb6.dirty\n"}]}