{"thread":{"id":"32769","subject":"[PATCH] branch: show (rebasing) or (bisecting) instead of (no branch) when possible","startedAt":"2013-01-29T12:12:54Z","lastAt":"2013-02-14T09:46:21Z","messageCount":14,"participants":["Nguyễn Thái Ngọc Duy","Jonathan Nieder","Matthieu Moy","Junio C Hamano","Duy Nguyen"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"208182","messageId":"1359461574-24529-1-git-send-email-pclouds@gmail.com","threadId":"32769","inReplyTo":null,"subject":"[PATCH] branch: show (rebasing) or (bisecting) instead of (no branch) when possible","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2013-01-29T12:12:54Z","receivedAt":"2013-01-29T12:12:54Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n In the spirit of status' in-progress info. I think showing this is\n more useful than \"(no branch)\". I tend to do \"git br\" more often than\n \"git st\" and this catches my eyes.\n\n builtin/branch.c            | 10 +++++++++-\n t/t6030-bisect-porcelain.sh |  2 +-\n 2 files changed, 10 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex 873f624..b0c5a20 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -557,7 +557,15 @@ static void show_detached(struct ref_list *ref_list)\n \n \tif (head_commit && is_descendant_of(head_commit, ref_list->with_commit)) {\n \t\tstruct ref_item item;\n-\t\titem.name = xstrdup(_(\"(no branch)\"));\n+\t\tstruct stat st;\n+\t\tif ((!stat(git_path(\"rebase-apply\"), &st) &&\n+\t\t     stat(git_path(\"rebase-apply/applying\"), &st)) ||\n+\t\t    !stat(git_path(\"rebase-merge\"), &st))\n+\t\t\titem.name = xstrdup(_(\"(rebasing)\"));\n+\t\telse if (!stat(git_path(\"BISECT_LOG\"), &st))\n+\t\t\titem.name = xstrdup(_(\"(bisecting)\"));\n+\t\telse\n+\t\t\titem.name = xstrdup(_(\"(no branch)\"));\n \t\titem.width = utf8_strwidth(item.name);\n \t\titem.kind = REF_LOCAL_BRANCH;\n \t\titem.dest = NULL;\ndiff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh\nindex 3e0e15f..bc21bc9 100755\n--- a/t/t6030-bisect-porcelain.sh\n+++ b/t/t6030-bisect-porcelain.sh\n@@ -164,7 +164,7 @@ test_expect_success 'bisect start: existing \".git/BISECT_START\" not modified if\n \tcp .git/BISECT_START saved &&\n \ttest_must_fail git bisect start $HASH4 foo -- &&\n \tgit branch > branch.output &&\n-\ttest_i18ngrep \"* (no branch)\" branch.output > /dev/null &&\n+\ttest_i18ngrep \"* (bisecting)\" branch.output > /dev/null &&\n \ttest_cmp saved .git/BISECT_START\n '\n test_expect_success 'bisect start: no \".git/BISECT_START\" if mistaken rev' '\n-- \n1.8.1.1.459.g5970e58\n"},{"id":"208206","messageId":"20130129191321.GB18266@google.com","threadId":"32769","inReplyTo":"1359461574-24529-1-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH] branch: show (rebasing) or (bisecting) instead of (no branch) when possible","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2013-01-29T19:13:21Z","receivedAt":"2013-01-29T19:13:21Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Nguyễn Thái Ngọc Duy wrote:\n\n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> ---\n>  In the spirit of status' in-progress info. I think showing this is\n>  more useful than \"(no branch)\". I tend to do \"git br\" more often than\n>  \"git st\" and this catches my eyes.\n\nVery nice idea.  This would also have been a nice way to avoid\nconfusion when my officemate used bisect for the first time.\n\nAny particular reason the above explanation is after the triple-dash\ninstead of before it?\n\n[...]\n> --- a/builtin/branch.c\n> +++ b/builtin/branch.c\n> @@ -557,7 +557,15 @@ static void show_detached(struct ref_list *ref_list)\n>  \n>  \tif (head_commit && is_descendant_of(head_commit, ref_list->with_commit)) {\n>  \t\tstruct ref_item item;\n> -\t\titem.name = xstrdup(_(\"(no branch)\"));\n> +\t\tstruct stat st;\n> +\t\tif ((!stat(git_path(\"rebase-apply\"), &st) &&\n> +\t\t     stat(git_path(\"rebase-apply/applying\"), &st)) ||\n> +\t\t    !stat(git_path(\"rebase-merge\"), &st))\n\nHere's a straight translation of contrib/completion/prompt.sh for\ncomparison, skipping the cases that don't involve automatically\ndetaching HEAD:\n\n\tif (!stat(git_path(\"rebase-merge\"), &st) && S_ISDIR(st.st_mode))\n\t\titem.name = xstrdup(_(\"(rebasing)\"));\n\telse if (!access(git_path(\"rebase-apply/rebasing\"), F_OK))\n\t\titem.name = xstrdup(_(\"(rebasing)\"));\n\telse if (!access(git_path(\"BISECT_LOG\"), F_OK))\n\t\titem.name = xstrdup(_(\"(bisecting)\"));\n\telse\n\t\titem.name = xstrdup(_(\"(no branch)\"));\n\nThat would mean:\n\n * using access() instead of stat() to avoid unnecessary work\n * relying on rebase--am to write .git/rebase-apply/rebasing when\n   appropriate instead of guessing\n\nNot important, though. :)\n\nJonathan\n"},{"id":"208533","messageId":"1359870520-22644-1-git-send-email-pclouds@gmail.com","threadId":"32769","inReplyTo":"1359461574-24529-1-git-send-email-pclouds@gmail.com","subject":"[PATCH v2] branch: show rebase/bisect info when possible instead of \"(no branch)\"","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2013-02-03T05:48:40Z","receivedAt":"2013-02-03T05:48:40Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"This prints more helpful info when HEAD is detached: is it detached\nbecause of bisect or rebase? What is the original branch name in those\ncases?\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n  - Incorporate Jonathan's version of checking\n  - Show original branch name, e.g. \"(rebasing foo)\", when possible\n\n builtin/branch.c            | 40 +++++++++++++++++++++++++++++++++++++++-\n t/t6030-bisect-porcelain.sh |  2 +-\n 2 files changed, 40 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex ea6498b..40f20ad 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -550,6 +550,44 @@ static int calc_maxwidth(struct ref_list *refs)\n \treturn w;\n }\n \n+static char *get_head_description()\n+{\n+\tstruct stat st;\n+\tstruct strbuf sb = STRBUF_INIT;\n+\tstruct strbuf result = STRBUF_INIT;\n+\tint bisect = 0;\n+\tint ret;\n+\tif (!stat(git_path(\"rebase-merge\"), &st) && S_ISDIR(st.st_mode))\n+\t\tret = strbuf_read_file(&sb, git_path(\"rebase-merge/head-name\"), 0);\n+\telse if (!access(git_path(\"rebase-apply/rebasing\"), F_OK))\n+\t\tret = strbuf_read_file(&sb, git_path(\"rebase-apply/head-name\"), 0);\n+\telse if (!access(git_path(\"BISECT_LOG\"), F_OK)) {\n+\t\tret = strbuf_read_file(&sb, git_path(\"BISECT_START\"), 0);\n+\t\tbisect = 1;\n+\t} else\n+\t\treturn xstrdup(_(\"(no branch)\"));\n+\n+\tif (ret <= 0)\n+\t\treturn xstrdup(bisect ? _(\"(bisecting)\") : _(\"_(rebasing)\"));\n+\n+\twhile (sb.len && sb.buf[sb.len - 1] == '\\n')\n+\t\tstrbuf_setlen(&sb, sb.len - 1);\n+\n+\tif (bisect) {\n+\t\tunsigned char sha1[20];\n+\t\tif (!get_sha1_hex(sb.buf, sha1))\n+\t\t\tstrbuf_addstr(&result, _(\"(bisecting)\"));\n+\t\telse\n+\t\t\tstrbuf_addf(&result, _(\"(bisecting %s)\"), sb.buf);\n+\t} else {\n+\t\tif (!prefixcmp(sb.buf, \"refs/heads/\"))\n+\t\t\tstrbuf_addf(&result, _(\"(rebasing %s)\"), sb.buf + 11);\n+\t\telse\n+\t\t\tstrbuf_addstr(&result, _(\"(rebasing)\"));\n+\t}\n+\tstrbuf_release(&sb);\n+\treturn strbuf_detach(&result, NULL);\n+}\n \n static void show_detached(struct ref_list *ref_list)\n {\n@@ -557,7 +595,7 @@ static void show_detached(struct ref_list *ref_list)\n \n \tif (head_commit && is_descendant_of(head_commit, ref_list->with_commit)) {\n \t\tstruct ref_item item;\n-\t\titem.name = xstrdup(_(\"(no branch)\"));\n+\t\titem.name = get_head_description();\n \t\titem.width = utf8_strwidth(item.name);\n \t\titem.kind = REF_LOCAL_BRANCH;\n \t\titem.dest = NULL;\ndiff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh\nindex 3e0e15f..90968d5 100755\n--- a/t/t6030-bisect-porcelain.sh\n+++ b/t/t6030-bisect-porcelain.sh\n@@ -164,7 +164,7 @@ test_expect_success 'bisect start: existing \".git/BISECT_START\" not modified if\n \tcp .git/BISECT_START saved &&\n \ttest_must_fail git bisect start $HASH4 foo -- &&\n \tgit branch > branch.output &&\n-\ttest_i18ngrep \"* (no branch)\" branch.output > /dev/null &&\n+\ttest_i18ngrep \"* (bisecting other)\" branch.output > /dev/null &&\n \ttest_cmp saved .git/BISECT_START\n '\n test_expect_success 'bisect start: no \".git/BISECT_START\" if mistaken rev' '\n-- \n1.8.1.1.459.g5970e58\n"},{"id":"208568","messageId":"vpqpq0hnlb1.fsf@grenoble-inp.fr","threadId":"32769","inReplyTo":"1359870520-22644-1-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH v2] branch: show rebase/bisect info when possible instead of \"(no branch)\"","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2013-02-03T21:23:46Z","receivedAt":"2013-02-03T21:23:46Z","isPatch":true,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:\n\n> --- a/t/t6030-bisect-porcelain.sh\n> +++ b/t/t6030-bisect-porcelain.sh\n> @@ -164,7 +164,7 @@ test_expect_success 'bisect start: existing \".git/BISECT_START\" not modified if\n>  \tcp .git/BISECT_START saved &&\n>  \ttest_must_fail git bisect start $HASH4 foo -- &&\n>  \tgit branch > branch.output &&\n> -\ttest_i18ngrep \"* (no branch)\" branch.output > /dev/null &&\n> +\ttest_i18ngrep \"* (bisecting other)\" branch.output > /dev/null &&\n\nI'd have spelled it (no branch, bisecting other) to make it clear that\nwe're on detached HEAD, and avoid confusing old-timers. But maybe your\nversion is enough, I'm not sure.\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"208569","messageId":"7v1ucx83fz.fsf@alter.siamese.dyndns.org","threadId":"32769","inReplyTo":"vpqpq0hnlb1.fsf@grenoble-inp.fr","subject":"Re: [PATCH v2] branch: show rebase/bisect info when possible instead of \"(no branch)\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-02-03T21:58:40Z","receivedAt":"2013-02-03T21:58:40Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:\n\n> Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:\n>\n>> --- a/t/t6030-bisect-porcelain.sh\n>> +++ b/t/t6030-bisect-porcelain.sh\n>> @@ -164,7 +164,7 @@ test_expect_success 'bisect start: existing \".git/BISECT_START\" not modified if\n>>  \tcp .git/BISECT_START saved &&\n>>  \ttest_must_fail git bisect start $HASH4 foo -- &&\n>>  \tgit branch > branch.output &&\n>> -\ttest_i18ngrep \"* (no branch)\" branch.output > /dev/null &&\n>> +\ttest_i18ngrep \"* (bisecting other)\" branch.output > /dev/null &&\n>\n> I'd have spelled it (no branch, bisecting other) to make it clear that\n> we're on detached HEAD, and avoid confusing old-timers. But maybe your\n> version is enough, I'm not sure.\n\nYeah, I do not think \"bisecting other\" alone makes much sense.\n\nWhat does \"other\" refer to when you start your bisection at a\ndetached head?  I personally think \"other\" has _any_ value in that\nmessage, because \"(no branch, bisecting)\" gives the same amount of\ninformation, especially because \"other\" does not say which branch it\nrefers to at all.\n"},{"id":"208570","messageId":"7vwqup6ot8.fsf@alter.siamese.dyndns.org","threadId":"32769","inReplyTo":"7v1ucx83fz.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH v2] branch: show rebase/bisect info when possible instead of \"(no branch)\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-02-03T22:00:03Z","receivedAt":"2013-02-03T22:00:03Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Yeah, I do not think \"bisecting other\" alone makes much sense.\n>\n> What does \"other\" refer to when you start your bisection at a\n> detached head?  I personally think \"other\" has _any_ value in that\n\ns/_any_/_no_/; obviously ;-)\n\n> message, because \"(no branch, bisecting)\" gives the same amount of\n> information, especially because \"other\" does not say which branch it\n> refers to at all.\n"},{"id":"208591","messageId":"CACsJy8CGqiahw3y42KRt61gChtfOucFHqZqn_uvLrj7j7KrQbg@mail.gmail.com","threadId":"32769","inReplyTo":"vpqpq0hnlb1.fsf@grenoble-inp.fr","subject":"Re: [PATCH v2] branch: show rebase/bisect info when possible instead of \"(no branch)\"","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2013-02-04T07:14:34Z","receivedAt":"2013-02-04T07:14:34Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Mon, Feb 4, 2013 at 4:23 AM, Matthieu Moy\n<Matthieu.Moy@grenoble-inp.fr> wrote:\n> Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:\n>\n>> --- a/t/t6030-bisect-porcelain.sh\n>> +++ b/t/t6030-bisect-porcelain.sh\n>> @@ -164,7 +164,7 @@ test_expect_success 'bisect start: existing \".git/BISECT_START\" not modified if\n>>       cp .git/BISECT_START saved &&\n>>       test_must_fail git bisect start $HASH4 foo -- &&\n>>       git branch > branch.output &&\n>> -     test_i18ngrep \"* (no branch)\" branch.output > /dev/null &&\n>> +     test_i18ngrep \"* (bisecting other)\" branch.output > /dev/null &&\n>\n> I'd have spelled it (no branch, bisecting other) to make it clear that\n> we're on detached HEAD, and avoid confusing old-timers. But maybe your\n> version is enough, I'm not sure.\n\nIf we want to make it clear, I think the standard \"* (no branch)\" should become\n\n* HEAD (detached)\n\nor non-detached case:\n\n* HEAD -> foo\n\nThen we could present rebase/bisect information as\n\n* HEAD (detached, bisecting)\n* HEAD (detached, rebasing)\n* foo (rebasing)\n\nI don't want to make this line too long because it would break (well,\nwaste space in) column layout. So if we do this, no branch name added\nfor rebase/bisect.\n-- \nDuy\n"},{"id":"208593","messageId":"CACsJy8C4MippsxZMdp0ZLmzQyJkAMe_2caFi3hbEDt4P+wNp6w@mail.gmail.com","threadId":"32769","inReplyTo":"CACsJy8CGqiahw3y42KRt61gChtfOucFHqZqn_uvLrj7j7KrQbg@mail.gmail.com","subject":"Re: [PATCH v2] branch: show rebase/bisect info when possible instead of \"(no branch)\"","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2013-02-04T07:17:27Z","receivedAt":"2013-02-04T07:17:27Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Mon, Feb 4, 2013 at 2:14 PM, Duy Nguyen <pclouds@gmail.com> wrote:\n> * foo (rebasing)\n\nWell, this one does not make sense (or causes more confusion).\n-- \nDuy\n"},{"id":"208608","messageId":"vpqr4kwmdcs.fsf@grenoble-inp.fr","threadId":"32769","inReplyTo":"7v1ucx83fz.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH v2] branch: show rebase/bisect info when possible instead of \"(no branch)\"","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2013-02-04T13:13:07Z","receivedAt":"2013-02-04T13:13:07Z","isPatch":true,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:\n>\n>> Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:\n>>\n>>> --- a/t/t6030-bisect-porcelain.sh\n>>> +++ b/t/t6030-bisect-porcelain.sh\n>>> @@ -164,7 +164,7 @@ test_expect_success 'bisect start: existing \".git/BISECT_START\" not modified if\n>>>  \tcp .git/BISECT_START saved &&\n>>>  \ttest_must_fail git bisect start $HASH4 foo -- &&\n>>>  \tgit branch > branch.output &&\n>>> -\ttest_i18ngrep \"* (no branch)\" branch.output > /dev/null &&\n>>> +\ttest_i18ngrep \"* (bisecting other)\" branch.output > /dev/null &&\n[...]\n> What does \"other\" refer to when you start your bisection at a\n> detached head?\n\nIf I read correctly, the branch name is shown only when the bisection\nwas not started on a detached HEAD:\n\n+\t\tif (!get_sha1_hex(sb.buf, sha1))\n+\t\t\tstrbuf_addstr(&result, _(\"(bisecting)\"));\n+\t\telse\n+\t\t\tstrbuf_addf(&result, _(\"(bisecting %s)\"), sb.buf);\n\n> I personally think \"other\" has _no_ value in that message, because\n> \"(no branch, bisecting)\" gives the same amount of information,\n> especially because \"other\" does not say which branch it refers to at\n> all.\n\nJust to be sure: \"other\" here is not a hardcoded message \"bisecting\nother\", but an instance of \"bisecting <branch-name>\" with the branch\nbeing called \"other\".\n\nI think this is very valuable information, and most likely the\ninformation you'd be looking for when running \"git branch\". You're\ntechnically on detached HEAD, but morally on some branch, the HEAD being\ndetached only because a bisect is in progress.\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"208613","messageId":"7vk3qo3ved.fsf@alter.siamese.dyndns.org","threadId":"32769","inReplyTo":"vpqr4kwmdcs.fsf@grenoble-inp.fr","subject":"Re: [PATCH v2] branch: show rebase/bisect info when possible instead of \"(no branch)\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-02-04T16:18:18Z","receivedAt":"2013-02-04T16:18:18Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:\n\n> Just to be sure: \"other\" here is not a hardcoded message \"bisecting\n> other\", but an instance of \"bisecting <branch-name>\" with the branch\n> being called \"other\".\n\nOK, then I do not have any objection.  Thanks.\n"},{"id":"208991","messageId":"1360318171-17614-1-git-send-email-pclouds@gmail.com","threadId":"32769","inReplyTo":"1359870520-22644-1-git-send-email-pclouds@gmail.com","subject":"[PATCH v3] branch: show rebase/bisect info when possible instead of \"(no branch)\"","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2013-02-08T10:09:31Z","receivedAt":"2013-02-08T10:09:31Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"This prints more helpful info when HEAD is detached: is it detached\nbecause of bisect or rebase? What is the original branch name in those\ncases?\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n Keep \"no branch\" in all cases. Just append \"rebasing/bisecting [%s]\"\n when applicable.\n\n builtin/branch.c            | 44 +++++++++++++++++++++++++++++++++++++++++++-\n t/t6030-bisect-porcelain.sh |  2 +-\n 2 files changed, 44 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex 6371bf9..26c0c3d 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -550,6 +550,48 @@ static int calc_maxwidth(struct ref_list *refs)\n \treturn w;\n }\n \n+static char *get_head_description()\n+{\n+\tstruct stat st;\n+\tstruct strbuf sb = STRBUF_INIT;\n+\tstruct strbuf result = STRBUF_INIT;\n+\tint bisect = 0;\n+\tint ret;\n+\tif (!stat(git_path(\"rebase-merge\"), &st) && S_ISDIR(st.st_mode))\n+\t\tret = strbuf_read_file(&sb, git_path(\"rebase-merge/head-name\"), 0);\n+\telse if (!access(git_path(\"rebase-apply/rebasing\"), F_OK))\n+\t\tret = strbuf_read_file(&sb, git_path(\"rebase-apply/head-name\"), 0);\n+\telse if (!access(git_path(\"BISECT_LOG\"), F_OK)) {\n+\t\tret = strbuf_read_file(&sb, git_path(\"BISECT_START\"), 0);\n+\t\tbisect = 1;\n+\t} else\n+\t\treturn xstrdup(_(\"(no branch)\"));\n+\n+\tif (ret <= 0) {\n+\t\tif (bisect)\n+\t\t\treturn xstrdup(_(\"(no branch, bisecting)\"));\n+\t\telse\n+\t\t\treturn xstrdup(_(\"_(no branch, rebasing)\"));\n+\t}\n+\n+\twhile (sb.len && sb.buf[sb.len - 1] == '\\n')\n+\t\tstrbuf_setlen(&sb, sb.len - 1);\n+\n+\tif (bisect) {\n+\t\tunsigned char sha1[20];\n+\t\tif (!get_sha1_hex(sb.buf, sha1))\n+\t\t\tstrbuf_addstr(&result, _(\"(no branch, bisecting)\"));\n+\t\telse\n+\t\t\tstrbuf_addf(&result, _(\"(no branch, bisecting %s)\"), sb.buf);\n+\t} else {\n+\t\tif (!prefixcmp(sb.buf, \"refs/heads/\"))\n+\t\t\tstrbuf_addf(&result, _(\"(no branch, rebasing %s)\"), sb.buf + 11);\n+\t\telse\n+\t\t\tstrbuf_addstr(&result, _(\"(no branch, rebasing)\"));\n+\t}\n+\tstrbuf_release(&sb);\n+\treturn strbuf_detach(&result, NULL);\n+}\n \n static void show_detached(struct ref_list *ref_list)\n {\n@@ -557,7 +599,7 @@ static void show_detached(struct ref_list *ref_list)\n \n \tif (head_commit && is_descendant_of(head_commit, ref_list->with_commit)) {\n \t\tstruct ref_item item;\n-\t\titem.name = xstrdup(_(\"(no branch)\"));\n+\t\titem.name = get_head_description();\n \t\titem.width = utf8_strwidth(item.name);\n \t\titem.kind = REF_LOCAL_BRANCH;\n \t\titem.dest = NULL;\ndiff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh\nindex 3e0e15f..9b6f0d0 100755\n--- a/t/t6030-bisect-porcelain.sh\n+++ b/t/t6030-bisect-porcelain.sh\n@@ -164,7 +164,7 @@ test_expect_success 'bisect start: existing \".git/BISECT_START\" not modified if\n \tcp .git/BISECT_START saved &&\n \ttest_must_fail git bisect start $HASH4 foo -- &&\n \tgit branch > branch.output &&\n-\ttest_i18ngrep \"* (no branch)\" branch.output > /dev/null &&\n+\ttest_i18ngrep \"* (no branch, bisecting other)\" branch.output > /dev/null &&\n \ttest_cmp saved .git/BISECT_START\n '\n test_expect_success 'bisect start: no \".git/BISECT_START\" if mistaken rev' '\n-- \n1.8.1.2.536.gf441e6d\n"},{"id":"209017","messageId":"7v1ucq3b7e.fsf@alter.siamese.dyndns.org","threadId":"32769","inReplyTo":"1360318171-17614-1-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH v3] branch: show rebase/bisect info when possible instead of \"(no branch)\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-02-08T18:35:49Z","receivedAt":"2013-02-08T18:35:49Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:\n\n> This prints more helpful info when HEAD is detached: is it detached\n> because of bisect or rebase? What is the original branch name in those\n> cases?\n>\n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> ---\n>  Keep \"no branch\" in all cases. Just append \"rebasing/bisecting [%s]\"\n>  when applicable.\n>\n>  builtin/branch.c            | 44 +++++++++++++++++++++++++++++++++++++++++++-\n>  t/t6030-bisect-porcelain.sh |  2 +-\n>  2 files changed, 44 insertions(+), 2 deletions(-)\n>\n> diff --git a/builtin/branch.c b/builtin/branch.c\n> index 6371bf9..26c0c3d 100644\n> --- a/builtin/branch.c\n> +++ b/builtin/branch.c\n> @@ -550,6 +550,48 @@ static int calc_maxwidth(struct ref_list *refs)\n>  \treturn w;\n>  }\n>  \n> +static char *get_head_description()\n> +{\n> +\tstruct stat st;\n> +\tstruct strbuf sb = STRBUF_INIT;\n> +\tstruct strbuf result = STRBUF_INIT;\n> +\tint bisect = 0;\n> +\tint ret;\n> +\tif (!stat(git_path(\"rebase-merge\"), &st) && S_ISDIR(st.st_mode))\n> +\t\tret = strbuf_read_file(&sb, git_path(\"rebase-merge/head-name\"), 0);\n> +\telse if (!access(git_path(\"rebase-apply/rebasing\"), F_OK))\n> +\t\tret = strbuf_read_file(&sb, git_path(\"rebase-apply/head-name\"), 0);\n> +\telse if (!access(git_path(\"BISECT_LOG\"), F_OK)) {\n> +\t\tret = strbuf_read_file(&sb, git_path(\"BISECT_START\"), 0);\n> +\t\tbisect = 1;\n> +\t} else\n> +\t\treturn xstrdup(_(\"(no branch)\"));\n> +\n> +\tif (ret <= 0) {\n\nDoesn't the general \"negative signals an error\" apply here?\n\nThe end result may be the same, as the later part of this function\nthat uses sb with len==0 ends up showing the same \"bisecting\" (or\n\"rebasing\") without any other information, but the logic to reach\nthat outcome looks wrong.\n\n> +\t\tif (bisect)\n> +\t\t\treturn xstrdup(_(\"(no branch, bisecting)\"));\n> +\t\telse\n> +\t\t\treturn xstrdup(_(\"_(no branch, rebasing)\"));\n> +\t}\n> +\n> +\twhile (sb.len && sb.buf[sb.len - 1] == '\\n')\n> +\t\tstrbuf_setlen(&sb, sb.len - 1);\n> +\n> +\tif (bisect) {\n> +\t\tunsigned char sha1[20];\n> +\t\tif (!get_sha1_hex(sb.buf, sha1))\n> +\t\t\tstrbuf_addstr(&result, _(\"(no branch, bisecting)\"));\n> +\t\telse\n> +\t\t\tstrbuf_addf(&result, _(\"(no branch, bisecting %s)\"), sb.buf);\n> +\t} else {\n> +\t\tif (!prefixcmp(sb.buf, \"refs/heads/\"))\n> +\t\t\tstrbuf_addf(&result, _(\"(no branch, rebasing %s)\"), sb.buf + 11);\n> +\t\telse\n> +\t\t\tstrbuf_addstr(&result, _(\"(no branch, rebasing)\"));\n> +\t}\n> +\tstrbuf_release(&sb);\n> +\treturn strbuf_detach(&result, NULL);\n> +}\n\nWe may want to refactor wt_status_print_state() and its callee a bit\nso that it and this part can share the logic without duplication and\nrisk implementing subtly different decision.  wt_status used to have\nclean separation between collection phase and presentation phase,\nbut the wall between the phases seems deteriorated over time as more\n\"in progress\" crufts have been piled on top.\n\nSuch a refactoring may look larger than necessary, but on the other\nhand, I do not see this feature very useful if it can over time\ndrift away from what we will see in \"git status\", so...\n\n>  \n>  static void show_detached(struct ref_list *ref_list)\n>  {\n> @@ -557,7 +599,7 @@ static void show_detached(struct ref_list *ref_list)\n>  \n>  \tif (head_commit && is_descendant_of(head_commit, ref_list->with_commit)) {\n>  \t\tstruct ref_item item;\n> -\t\titem.name = xstrdup(_(\"(no branch)\"));\n> +\t\titem.name = get_head_description();\n>  \t\titem.width = utf8_strwidth(item.name);\n>  \t\titem.kind = REF_LOCAL_BRANCH;\n>  \t\titem.dest = NULL;\n> diff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh\n> index 3e0e15f..9b6f0d0 100755\n> --- a/t/t6030-bisect-porcelain.sh\n> +++ b/t/t6030-bisect-porcelain.sh\n> @@ -164,7 +164,7 @@ test_expect_success 'bisect start: existing \".git/BISECT_START\" not modified if\n>  \tcp .git/BISECT_START saved &&\n>  \ttest_must_fail git bisect start $HASH4 foo -- &&\n>  \tgit branch > branch.output &&\n> -\ttest_i18ngrep \"* (no branch)\" branch.output > /dev/null &&\n> +\ttest_i18ngrep \"* (no branch, bisecting other)\" branch.output > /dev/null &&\n>  \ttest_cmp saved .git/BISECT_START\n>  '\n>  test_expect_success 'bisect start: no \".git/BISECT_START\" if mistaken rev' '\n"},{"id":"209292","messageId":"7vehgmmzop.fsf@alter.siamese.dyndns.org","threadId":"32769","inReplyTo":"1360318171-17614-1-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH v3] branch: show rebase/bisect info when possible instead of \"(no branch)\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-02-11T19:13:26Z","receivedAt":"2013-02-11T19:13:26Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:\n\n> +static char *get_head_description()\n> +{\n> +\tstruct stat st;\n> +\tstruct strbuf sb = STRBUF_INIT;\n> +\tstruct strbuf result = STRBUF_INIT;\n> +\tint bisect = 0;\n> +\tint ret;\n> +\tif (!stat(git_path(\"rebase-merge\"), &st) && S_ISDIR(st.st_mode))\n> +\t\tret = strbuf_read_file(&sb, git_path(\"rebase-merge/head-name\"), 0);\n\nHrmph.  Why isn't this checking if the file exists and then read it,\ni.e.\n\n\tif (access(git_path(\"rebase-merge/head-name\"), F_OK))\n\t\tret = strbuf_read_file(&sb, git_path(\"rebase-merge/head-name\"), 0);\n\nIt is not like you are creating this file and making sure leading\ndirectories exist, so the sequence looks a bit strange.\n\n> +\telse if (!access(git_path(\"rebase-apply/rebasing\"), F_OK))\n> +\t\tret = strbuf_read_file(&sb, git_path(\"rebase-apply/head-name\"), 0);\n> +\telse if (!access(git_path(\"BISECT_LOG\"), F_OK)) {\n> +\t\tret = strbuf_read_file(&sb, git_path(\"BISECT_START\"), 0);\n> +\t\tbisect = 1;\n\nAnd if the answer to the above question is \"because if rebase-merge/\nexists, with or without head-name, we know we are not bisecting\",\nthen that may suggest that the structure of if/elseif cascade is\nmisdesigned.  Shouldn't the \"bisect\" boolean be an enum \"what are we\ndoing\" that is initialized to \"I do not know\" and each of these\nif/elseif cascade set the state to it when they know what we are\ndoing, in order for this function to be longer-term maintainable?\n"},{"id":"209511","messageId":"CACsJy8Ah5PvtD_AXL+tiZp-eQvzfcmvciUEK=yyOPKv-Es9YCA@mail.gmail.com","threadId":"32769","inReplyTo":"7v1ucq3b7e.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH v3] branch: show rebase/bisect info when possible instead of \"(no branch)\"","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2013-02-14T09:46:21Z","receivedAt":"2013-02-14T09:46:21Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Sat, Feb 9, 2013 at 1:35 AM, Junio C Hamano <gitster@pobox.com> wrote:\n> We may want to refactor wt_status_print_state() and its callee a bit\n> so that it and this part can share the logic without duplication and\n> risk implementing subtly different decision.  wt_status used to have\n> clean separation between collection phase and presentation phase,\n> but the wall between the phases seems deteriorated over time as more\n> \"in progress\" crufts have been piled on top.\n>\n> Such a refactoring may look larger than necessary, but on the other\n> hand, I do not see this feature very useful if it can over time\n> drift away from what we will see in \"git status\", so...\n\nOK. I'll wait until nd/status-show-in-progress is merged to master,\nthen rework this patch on top.\n-- \nDuy\n"}]}