Skip to content

Commit e4f8d27

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 225bc32 commit e4f8d27

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

builtin/show-branch.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,9 @@ static void snarf_refs(int head, int remotes)
482482
}
483483
}
484484

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)
487486
{
488-
if (!head || (head_sha1 && sha1 && !hasheq(head_sha1, sha1)))
487+
if (!head)
489488
return 0;
490489
skip_prefix(head, "refs/heads/", &head);
491490
if (!skip_prefix(name, "refs/heads/", &name))
@@ -806,9 +805,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
806805
/* We are only interested in adding the branch
807806
* HEAD points at.
808807
*/
809-
if (rev_is_head(head,
810-
ref_name[i],
811-
head_oid.hash, NULL))
808+
if (rev_is_head(head, ref_name[i]))
812809
has_head++;
813810
}
814811
if (!has_head) {
@@ -867,10 +864,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
867864
if (1 < num_rev || extra < 0) {
868865
for (i = 0; i < num_rev; i++) {
869866
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);
874869
if (extra < 0)
875870
printf("%c [%s] ",
876871
is_head ? '*' : ' ', ref_name[i]);

0 commit comments

Comments
 (0)