Skip to content

Commit 54fad66

Browse files
rscharfegitster
authored andcommitted
refs: make sha1 output parameter of refs_resolve_ref_unsafe() optional
Allow callers of refs_resolve_ref_unsafe() to pass NULL if they don't need the resolved hash value. We already allow the same for the flags parameter. This new leniency is inherited by the various wrappers like resolve_ref_unsafe(). Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 59c0ea1 commit 54fad66

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

refs.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,9 +1396,12 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
13961396
unsigned char *sha1, int *flags)
13971397
{
13981398
static struct strbuf sb_refname = STRBUF_INIT;
1399+
struct object_id unused_oid;
13991400
int unused_flags;
14001401
int symref_count;
14011402

1403+
if (!sha1)
1404+
sha1 = unused_oid.hash;
14021405
if (!flags)
14031406
flags = &unused_flags;
14041407

refs.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ struct worktree;
1010
/*
1111
* Resolve a reference, recursively following symbolic refererences.
1212
*
13-
* Store the referred-to object's name in sha1 and return the name of
14-
* the non-symbolic reference that ultimately pointed at it. The
15-
* return value, if not NULL, is a pointer into either a static buffer
16-
* or the input ref.
13+
* Return the name of the non-symbolic reference that ultimately pointed
14+
* at the resolved object name. The return value, if not NULL, is a
15+
* pointer into either a static buffer or the input ref.
16+
*
17+
* If sha1 is non-NULL, store the referred-to object's name in it.
1718
*
1819
* If the reference cannot be resolved to an object, the behavior
1920
* depends on the RESOLVE_REF_READING flag:

0 commit comments

Comments
 (0)