git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/3] refs: make sha1 output parameter of refs_resolve_ref_unsafe() optional

From
René Scharfe <l.s.r@web.de>
Date
Sep 23, 2017, 09:41 UTC
Message-ID
<b89d36b5-0996-829b-a267-7ee4da9673dc@web.de>

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>
---
 refs.c | 3 +++
 refs.h | 9 +++++----
 2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/refs.c b/refs.c
index c30f4c36be..36439fdb54 100644
--- a/refs.c
+++ b/refs.c
@@ -1396,9 +1396,12 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
 				    unsigned char *sha1, int *flags)
 {
 	static struct strbuf sb_refname = STRBUF_INIT;
+	struct object_id unused_oid;
 	int unused_flags;
 	int symref_count;
 
+	if (!sha1)
+		sha1 = unused_oid.hash;
 	if (!flags)
 		flags = &unused_flags;
 
diff --git a/refs.h b/refs.h
index 78a26400b6..996d4ea54d 100644
--- a/refs.h
+++ b/refs.h
@@ -10,10 +10,11 @@ struct worktree;
 /*
  * Resolve a reference, recursively following symbolic refererences.
  *
- * Store the referred-to object's name in sha1 and return the name of
- * the non-symbolic reference that ultimately pointed at it.  The
- * return value, if not NULL, is a pointer into either a static buffer
- * or the input ref.
+ * Return the name of the non-symbolic reference that ultimately pointed
+ * at the resolved object name.  The return value, if not NULL, is a
+ * pointer into either a static buffer or the input ref.
+ *
+ * If sha1 is non-NULL, store the referred-to object's name in it.
  *
  * If the reference cannot be resolved to an object, the behavior
  * depends on the RESOLVE_REF_READING flag:
-- 
2.14.1
Next: René Scharfe
Message 1 of 8 in “refs: make sha1 output parameter of refs_resolve_ref_unsafe() optional”
  1. 1/3 refs: make sha1 output parameter of refs_resolve_ref_unsafe() optionalRené Scharfe, Sep 23, 2017
  2. 2/3 refs: pass NULL to refs_resolve_ref_unsafe() if hash is not neededRené Scharfe, Sep 23, 2017
  3. 3/3 refs: pass NULL to resolve_ref_unsafe() if hash is not neededRené Scharfe, Sep 23, 2017
  4. Junio C HamanoSep 24, 2017
  5. René ScharfeSep 24, 2017
  6. 4/3 refs: pass NULL to refs_resolve_refdup() if hash is not neededRené Scharfe, Oct 1, 2017
  7. 5/3 refs: pass NULL to resolve_refdup() if hash is not neededRené Scharfe, Oct 1, 2017
  8. Junio C HamanoOct 1, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.