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 <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Sep 23, 2017 at 11:41 UTC
54fad6614fc6b61ee6eb4a5b3daa7a2239019b49
2 files changed
+8
-4
refs.c
+3
@@ -1396,9 +1396,12 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
1396
unsigned char *sha1, int *flags)
1397
{
1398
static struct strbuf sb_refname = STRBUF_INIT;
1399
+ struct object_id unused_oid;
1400
int unused_flags;
1401
int symref_count;
1402
1403
+ if (!sha1)
1404
+ sha1 = unused_oid.hash;
1405
if (!flags)
1406
flags = &unused_flags;
1407
refs.h
+5
-4
@@ -10,10 +10,11 @@ struct worktree;
10
/*
11
* Resolve a reference, recursively following symbolic refererences.
12
*
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.
18
*
19
* If the reference cannot be resolved to an object, the behavior
20
* depends on the RESOLVE_REF_READING flag: