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

[PATCH 1/2] Move code resolving packed refs into its own function.

From
Christian Couder <chriscool@tuxfamily.org>
Date
Sep 30, 2006, 20:01 UTC
Message-ID
<20060930220158.d331bb7c.chriscool@tuxfamily.org>

This patch move Linus' packed refs resolving code from "resolve_ref" into a new "resolve_packed_ref" extern function so that it can be reused when needed.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 cache.h |    2 ++
 refs.c  |   34 ++++++++++++++++++++--------------
 2 files changed, 22 insertions(+), 14 deletions(-)
diff --git a/cache.h b/cache.h
index 4e01a74..f37bc18 100644
--- a/cache.h
+++ b/cache.h
@@ -296,6 +296,8 @@ extern int get_sha1_hex(const char *hex,
 extern char *sha1_to_hex(const unsigned char *sha1);	/* static buffer result! */
 extern int read_ref(const char *filename, unsigned char *sha1);
 extern const char *resolve_ref(const char *path, unsigned char *sha1, int, int *);
+extern const char *resolve_packed_ref(const char *ref, unsigned char *sha1, int, int *);
+
 extern int create_symref(const char *ref, const char *refs_heads_master);
 extern int validate_symref(const char *ref);
 
diff --git a/refs.c b/refs.c
index 3d4cdd1..5e3988b 100644
--- a/refs.c
+++ b/refs.c
@@ -148,6 +148,25 @@ static struct ref_list *get_loose_refs(v
 	return refs;
 }
 
+const char *resolve_packed_ref(const char *ref, unsigned char *sha1,
+			       int reading, int *flag)
+{
+	struct ref_list *list = get_packed_refs();
+	while (list) {
+		if (!strcmp(ref, list->name)) {
+			hashcpy(sha1, list->sha1);
+			if (flag)
+				*flag |= REF_ISPACKED;
+			return ref;
+		}
+		list = list->next;
+	}
+	if (reading || errno != ENOENT)
+		return NULL;
+	hashclr(sha1);
+	return ref;
+}
+
 /* We allow "recursive" symbolic refs. Only within reason, though */
 #define MAXDEPTH 5
 
@@ -177,20 +196,7 @@ const char *resolve_ref(const char *ref,
 		 * reading.
 		 */
 		if (lstat(path, &st) < 0) {
-			struct ref_list *list = get_packed_refs();
-			while (list) {
-				if (!strcmp(ref, list->name)) {
-					hashcpy(sha1, list->sha1);
-					if (flag)
-						*flag |= REF_ISPACKED;
-					return ref;
-				}
-				list = list->next;
-			}
-			if (reading || errno != ENOENT)
-				return NULL;
-			hashclr(sha1);
-			return ref;
+			return resolve_packed_ref(ref, sha1, reading, flag);
 		}
 
 		/* Follow "normalized" - ie "refs/.." symlinks by hand */
-- 
1.4.2.1.g7cf04
Next: Junio C Hamano
Message 1 of 14 in “Move code resolving packed refs into its own function.”
  1. 1/2 Move code resolving packed refs into its own function.Christian Couder, Sep 30, 2006
  2. Junio C HamanoSep 30, 2006
  3. 0/6 ref deletion and D/F conflict avoidance with packed-refs.Junio C Hamano, Sep 30, 2006
  4. 1/6 ref locking: allow 'foo' when 'foo/bar' used to exist but not anymore.Junio C Hamano, Sep 30, 2006
  5. 2/6 refs: minor restructuring of cached refs data.Junio C Hamano, Sep 30, 2006
  6. 3/6 lock_ref_sha1(): do not sometimes error() and sometimes die().Junio C Hamano, Sep 30, 2006
  7. 4/6 lock_ref_sha1(): check D/F conflict with packed ref when creating.Junio C Hamano, Sep 30, 2006
  8. 5/6 delete_ref(): delete packed refJunio C Hamano, Sep 30, 2006
  9. 6/6 git-branch: remove D/F check done by hand.Junio C Hamano, Sep 30, 2006
  10. Jeff KingSep 30, 2006
  11. Christian CouderOct 1, 2006
  12. Junio C HamanoOct 1, 2006
  13. Jakub NarebskiOct 3, 2006
  14. Junio C HamanoOct 3, 2006

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.