{"thread":{"id":"56388","subject":"[PATCH] show-branch: simplify rev_is_head()","startedAt":"2021-08-27T19:25:37Z","lastAt":"2021-08-27T19:25:37Z","messageCount":1,"participants":["René Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"433950","messageId":"a5800c55-0147-214e-fb75-968476d9d1fe@web.de","threadId":"56388","inReplyTo":null,"subject":"[PATCH] show-branch: simplify rev_is_head()","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2021-08-27T19:20:27Z","receivedAt":"2021-08-27T19:25:37Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Only one of the callers of rev_is_head() provides two hashes to compare.\nMove that check there and convert it to struct object_id.\n\nSigned-off-by: René Scharfe <l.s.r@web.de>\n---\n builtin/show-branch.c | 15 +++++----------\n 1 file changed, 5 insertions(+), 10 deletions(-)\n\ndiff --git a/builtin/show-branch.c b/builtin/show-branch.c\nindex d77ce7aeb3..bea4bbf468 100644\n--- a/builtin/show-branch.c\n+++ b/builtin/show-branch.c\n@@ -482,10 +482,9 @@ static void snarf_refs(int head, int remotes)\n \t}\n }\n\n-static int rev_is_head(const char *head, const char *name,\n-\t\t       unsigned char *head_sha1, unsigned char *sha1)\n+static int rev_is_head(const char *head, const char *name)\n {\n-\tif (!head || (head_sha1 && sha1 && !hasheq(head_sha1, sha1)))\n+\tif (!head)\n \t\treturn 0;\n \tskip_prefix(head, \"refs/heads/\", &head);\n \tif (!skip_prefix(name, \"refs/heads/\", &name))\n@@ -806,9 +805,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)\n \t\t\t/* We are only interested in adding the branch\n \t\t\t * HEAD points at.\n \t\t\t */\n-\t\t\tif (rev_is_head(head,\n-\t\t\t\t\tref_name[i],\n-\t\t\t\t\thead_oid.hash, NULL))\n+\t\t\tif (rev_is_head(head, ref_name[i]))\n \t\t\t\thas_head++;\n \t\t}\n \t\tif (!has_head) {\n@@ -867,10 +864,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)\n \tif (1 < num_rev || extra < 0) {\n \t\tfor (i = 0; i < num_rev; i++) {\n \t\t\tint j;\n-\t\t\tint is_head = rev_is_head(head,\n-\t\t\t\t\t\t  ref_name[i],\n-\t\t\t\t\t\t  head_oid.hash,\n-\t\t\t\t\t\t  rev[i]->object.oid.hash);\n+\t\t\tint is_head = rev_is_head(head, ref_name[i]) &&\n+\t\t\t\t      oideq(&head_oid, &rev[i]->object.oid);\n \t\t\tif (extra < 0)\n \t\t\t\tprintf(\"%c [%s] \",\n \t\t\t\t       is_head ? '*' : ' ', ref_name[i]);\n--\n2.33.0\n"}]}