show-branch: simplify rev_is_head()

Only one of the callers of rev_is_head() provides two hashes to compare. Move that check there and convert it to struct object_id. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Aug 27, 2021 at 21:20 UTC e4f8d27585c6884dab26ded734cab7d8c08370a1
1 file changed +5 -10
builtin/show-branch.c
+5 -10
@@ -482,10 +482,9 @@ static void snarf_refs(int head, int remotes)
482 }
483 }
484
485 -static int rev_is_head(const char *head, const char *name,
486 - unsigned char *head_sha1, unsigned char *sha1)
485 +static int rev_is_head(const char *head, const char *name)
486 {
488 - if (!head || (head_sha1 && sha1 && !hasheq(head_sha1, sha1)))
487 + if (!head)
488 return 0;
489 skip_prefix(head, "refs/heads/", &head);
490 if (!skip_prefix(name, "refs/heads/", &name))
@@ -806,9 +805,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
805 /* We are only interested in adding the branch
806 * HEAD points at.
807 */
809 - if (rev_is_head(head,
810 - ref_name[i],
811 - head_oid.hash, NULL))
808 + if (rev_is_head(head, ref_name[i]))
809 has_head++;
810 }
811 if (!has_head) {
@@ -867,10 +864,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
864 if (1 < num_rev || extra < 0) {
865 for (i = 0; i < num_rev; i++) {
866 int j;
870 - int is_head = rev_is_head(head,
871 - ref_name[i],
872 - head_oid.hash,
873 - rev[i]->object.oid.hash);
867 + int is_head = rev_is_head(head, ref_name[i]) &&
868 + oideq(&head_oid, &rev[i]->object.oid);
869 if (extra < 0)
870 printf("%c [%s] ",
871 is_head ? '*' : ' ', ref_name[i]);