{"thread":{"id":"18012","subject":"Re: [PATCH 0/3] git-branch-head: recognize all refs pointing to the current branch head as such (Ah! topic is supposed to be git-show-branch:)","startedAt":"2009-02-25T10:17:17Z","lastAt":"2009-02-25T10:29:30Z","messageCount":5,"participants":["Halsmit","Dirk Wallenstein"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"106203","messageId":"cover.1235499771.git.halsmit@t-online.de","threadId":"18012","inReplyTo":null,"subject":"[PATCH 0/3] git-branch-head: recognize all refs pointing to the current branch head as such","fromName":"Dirk Wallenstein","fromEmail":"halsmit@t-online.de","sentAt":"2009-02-25T10:17:17Z","receivedAt":"2009-02-25T10:17:17Z","isPatch":true,"sender":{"key":"halsmit@t-online.de","avatar":null},"body":"With git-show-branch I would like to specify \"HEAD\" or \"<branchname>\" on \nthe command line and have it flagged with '*'. A prerequisite for this \nis that multiple columns can be flagged with '*'. \nThat is what the first patch does.\n\nCurrently the following is true:\n* if you have a detached head and specify \"HEAD\" it is flagged with '*'\n* on a branch, the only ref argument that is flagged with '*' is the \n  name of the branch (like \"master\"), and not 'HEAD' nor `git rev-parse HEAD`.\n* no arguments (neither heads nor non-heads) are reduced to only one ref if \n  they point to the same object (except for identical refs)\n\nThe only problem of a sha1-only based solution for branch head determination \n(comparing the sha1 of the current head and the specified ref) that I can \nthink about is that, if some other branch head shares the sha1 of the current\nbranch head (immediately after creation), one could name the other branch and\nit would be flagged as current branch head.\n\nIf that is too much of a problem, I propose an exceptions for the case when\nexactly \"HEAD\" is specified, and optionally if a sha1 is specified and matches\nhead (`git rev-parse HEAD`). To not mix up different solutions in the \nposted patches I go with the sha1-only based proposal. \nThat is the second patch.\n\nMaybe, with a detached head, nothing should be flagged as branch head. \nIf that is the case, the problem seems to be the retval from resolve_ref(), \nwhich returns its argument unmodified if called with \"HEAD\" (and not NULL). \nA local fix for that is in the third patch, which simply checks for that case.\n\nThe switch '--current' uses rev_is_head() to find out if the branchname has \nbeen specified on the command line, and adds such a column if not. That seems\nalright, as with this patch, you can now easily spot all columns that refer to\nthe branch head.\n\nSome example calls of rev_is_head() while being on branch \"callDemo\":\nNormal:\n\thead=refs/heads/callDemo ; headlen=19 ; name=HEAD     ; head_sha1=968d629 ; sha1=968d629\n\thead=refs/heads/callDemo ; headlen=19 ; name=callDemo ; head_sha1=968d629 ; sha1=968d629\nWith '--current' (this adds a \"<branchname>\" column if it is not specified on the command line) :\n\thead=refs/heads/callDemo ; headlen=19 ; name=HEAD ; head_sha1=968d629 ; sha1=<none>\n\thead=refs/heads/callDemo ; headlen=19 ; name=callDemo ; head_sha1=968d629 ; sha1=<none>\nWith a detached head, with and without '--current' (without the third patch of \nthis thread. With that patch, head is a pointer to an empty string):\n\thead=HEAD ; headlen=4 ; name=HEAD ; head_sha1=14706b5 ; sha1=<none>\n\thead=HEAD ; headlen=4 ; name=HEAD ; head_sha1=14706b5 ; sha1=14706b5\n\thead=HEAD ; headlen=4 ; name=callDemo ; head_sha1=14706b5 ; sha1=968d629\n\n\nAnd an example of what would be the outcome of these patches while being on \nbranch \"sha1BasedOnly\":\n    git (sha1BasedOnly) $ ./git-show-branch --current HEAD^^ HEAD HEAD^ `git rev-parse HEAD` master\n\t! [HEAD^^] git-show-branch: allow for multiple branch head columns\n\t * [HEAD] git-show-branch: avoid any column to be flagged as branch head if head is detached\n\t  ! [HEAD^] git-show-branch: sha1 based branch head determination\n\t   * [8e3c6fcd00a6a809bf1cca383a09c8d077c945d6] git-show-branch: avoid any column to be flagged as branch head if head is detached\n\t    ! [master] Merge branch 'for-junio' of git://source.winehq.org/~julliard/git/git\n\t     * [sha1BasedOnly] git-show-branch: avoid any column to be flagged as branch head if head is detached\n\t------\n\t * * * [HEAD] git-show-branch: avoid any column to be flagged as branch head if head is detached\n\t *+* * [HEAD^] git-show-branch: sha1 based branch head determination\n\t+*+* * [HEAD^^] git-show-branch: allow for multiple branch head columns\n\t------ [master] Merge branch 'for-junio' of git://source.winehq.org/~julliard/git/git\n\n\n\n\nDirk Wallenstein (3):\n  git-show-branch: allow for multiple branch head columns\n  git-show-branch: sha1 based branch head determination\n  git-show-branch: avoid any column to be flagged as branch head if\n    head is detached\n\n builtin-show-branch.c |   24 ++++++++++++++++++------\n 1 files changed, 18 insertions(+), 6 deletions(-)\n"},{"id":"106205","messageId":"fa82452302afa700e7cbbacbf2d58a8c188a0c62.1235499771.git.halsmit@t-online.de","threadId":"18012","inReplyTo":"cover.1235499771.git.halsmit@t-online.de","subject":"[PATCH 1/3] git-show-branch: allow for multiple branch head columns","fromName":"Dirk Wallenstein","fromEmail":"halsmit@t-online.de","sentAt":"2009-02-25T10:17:18Z","receivedAt":"2009-02-25T10:17:18Z","isPatch":true,"sender":{"key":"halsmit@t-online.de","avatar":null},"body":"If multiple refs point to the current branch head, each of them\nshould show a '*' in the corresponding column. This commit changes\nthis information about columns from an absolute index to a bitmask.\n---\n builtin-show-branch.c |   10 ++++++----\n 1 files changed, 6 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin-show-branch.c b/builtin-show-branch.c\nindex 306b850..df83491 100644\n--- a/builtin-show-branch.c\n+++ b/builtin-show-branch.c\n@@ -604,7 +604,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)\n \tint sha1_name = 0;\n \tint shown_merge_point = 0;\n \tint with_current_branch = 0;\n-\tint head_at = -1;\n+\tunsigned int head_at = 0;\n \tint topics = 0;\n \tint dense = 1;\n \tint reflog = 0;\n@@ -855,8 +855,10 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)\n \t\t\telse\n \t\t\t\tputs(reflog_msg[i]);\n \n-\t\t\tif (is_head)\n-\t\t\t\thead_at = i;\n+\t\t\tif (is_head) {\n+\t\t\t\tassert(MAX_REVS <= (sizeof(head_at) * 8));\n+\t\t\t\thead_at |= (1UL << i);\n+\t\t\t}\n \t\t}\n \t\tif (0 <= extra) {\n \t\t\tfor (i = 0; i < num_rev; i++)\n@@ -900,7 +902,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)\n \t\t\t\t\tmark = ' ';\n \t\t\t\telse if (is_merge)\n \t\t\t\t\tmark = '-';\n-\t\t\t\telse if (i == head_at)\n+\t\t\t\telse if (head_at & (1UL << i))\n \t\t\t\t\tmark = '*';\n \t\t\t\telse\n \t\t\t\t\tmark = '+';\n-- \n1.6.1\n"},{"id":"106204","messageId":"14706b525c71ab0628e54f7bd24b3303bf422698.1235499771.git.halsmit@t-online.de","threadId":"18012","inReplyTo":"cover.1235499771.git.halsmit@t-online.de","subject":"[PATCH 2/3] git-show-branch: sha1 based branch head determination","fromName":"Dirk Wallenstein","fromEmail":"halsmit@t-online.de","sentAt":"2009-02-25T10:17:19Z","receivedAt":"2009-02-25T10:17:19Z","isPatch":true,"sender":{"key":"halsmit@t-online.de","avatar":null},"body":"Any ref that points to the same object as the one that is\ncurrently pointed at by HEAD, is recognized as head, which is\nthen marked with a '*' in the corresponding column.\n---\n builtin-show-branch.c |   11 +++++++++--\n 1 files changed, 9 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin-show-branch.c b/builtin-show-branch.c\nindex df83491..96ae3cb 100644\n--- a/builtin-show-branch.c\n+++ b/builtin-show-branch.c\n@@ -460,9 +460,16 @@ static void snarf_refs(int head, int remotes)\n static int rev_is_head(char *head, int headlen, char *name,\n \t\t       unsigned char *head_sha1, unsigned char *sha1)\n {\n-\tif ((!head[0]) ||\n-\t    (head_sha1 && sha1 && hashcmp(head_sha1, sha1)))\n+\tif (!head[0])\n \t\treturn 0;\n+\tif (head_sha1 && sha1) {\n+\t\tif (hashcmp(head_sha1, sha1)) {\n+\t\t\treturn 0;\n+\t\t} else {\n+\t\t\treturn 1;\n+\t\t}\n+\t}\n+\n \tif (!prefixcmp(head, \"refs/heads/\"))\n \t\thead += 11;\n \tif (!prefixcmp(name, \"refs/heads/\"))\n-- \n1.6.1\n"},{"id":"106206","messageId":"8e3c6fcd00a6a809bf1cca383a09c8d077c945d6.1235499771.git.halsmit@t-online.de","threadId":"18012","inReplyTo":"cover.1235499771.git.halsmit@t-online.de","subject":"[PATCH 3/3] git-show-branch: avoid any column to be flagged as branch head if head is detached","fromName":"Dirk Wallenstein","fromEmail":"halsmit@t-online.de","sentAt":"2009-02-25T10:17:20Z","receivedAt":"2009-02-25T10:17:20Z","isPatch":true,"sender":{"key":"halsmit@t-online.de","avatar":null},"body":"For a detached head, resolve_ref() returns the argument \"HEAD\"\nunmodified. That case is checked for and pretended to be NULL,\nwhich consequently avoids any column to be flagged as branch head.\n---\n builtin-show-branch.c |    3 +++\n 1 files changed, 3 insertions(+), 0 deletions(-)\n\ndiff --git a/builtin-show-branch.c b/builtin-show-branch.c\nindex 96ae3cb..b073a31 100644\n--- a/builtin-show-branch.c\n+++ b/builtin-show-branch.c\n@@ -766,6 +766,9 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)\n \t}\n \n \thead_p = resolve_ref(\"HEAD\", head_sha1, 1, NULL);\n+\tif (head_p && !strcmp(head_p, \"HEAD\")) {\n+\t\thead_p = NULL;\n+\t}\n \tif (head_p) {\n \t\thead_len = strlen(head_p);\n \t\tmemcpy(head, head_p, head_len + 1);\n-- \n1.6.1\n"},{"id":"106202","messageId":"200902251129.30588.halsmit@t-online.de","threadId":"18012","inReplyTo":"cover.1235499771.git.halsmit@t-online.de","subject":"Re: [PATCH 0/3] git-branch-head: recognize all refs pointing to the current branch head as such (Ah! topic is supposed to be git-show-branch:)","fromName":"Halsmit","fromEmail":"halsmit@t-online.de","sentAt":"2009-02-25T10:29:30Z","receivedAt":"2009-02-25T10:29:30Z","isPatch":true,"sender":{"key":"halsmit@t-online.de","avatar":null},"body":"Topic is supposed to be git-show-branch:\n"}]}