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

[PATCH v2 10/11] resove_gitlink_packed_ref(): inline function

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Oct 15, 2014, 15:06 UTC
Message-ID
<1413385583-4872-11-git-send-email-mhagger@alum.mit.edu>
In-Reply-To
<1413385583-4872-1-git-send-email-mhagger@alum.mit.edu>
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
 refs.c | 31 +++++++++++--------------------
 1 file changed, 11 insertions(+), 20 deletions(-)
diff --git a/refs.c b/refs.c
index a7c8abd..8edcc3b 100644
--- a/refs.c
+++ b/refs.c
@@ -1280,25 +1280,6 @@ static struct ref_dir *get_loose_refs(struct ref_cache *refs)
 /* We allow "recursive" symbolic refs. Only within reason, though */
 #define MAXDEPTH 5
 
-/*
- * Called by resolve_gitlink_ref_recursive() after it failed to read
- * from the loose refs in ref_cache refs. Find <refname> in the
- * packed-refs file for the submodule.
- */
-static int resolve_gitlink_packed_ref(struct ref_cache *refs,
-				      const char *refname, unsigned char *sha1)
-{
-	struct ref_entry *ref;
-	struct ref_dir *dir = get_packed_refs(refs);
-
-	ref = find_ref(dir, refname);
-	if (ref == NULL)
-		return -1;
-
-	hashcpy(sha1, ref->u.value.sha1);
-	return 0;
-}
-
 int resolve_gitlink_ref(const char *path, const char *refname, unsigned char *sha1)
 {
 	struct strbuf result = STRBUF_INIT;
@@ -1331,7 +1312,17 @@ int resolve_gitlink_ref(const char *path, const char *refname, unsigned char *sh
 	if (parseval == 1) {
 		ret = 0;
 	} else if (parseval == -2) {
-		ret = resolve_gitlink_packed_ref(refs, result.buf, sha1) ? -1 : 0;
+		/* Loose ref doesn't exist; check for a packed ref */
+		struct ref_entry *entry;
+		struct ref_dir *dir = get_packed_refs(refs);
+
+		entry = find_ref(dir, result.buf);
+		if (entry) {
+			hashcpy(sha1, entry->u.value.sha1);
+			ret = 0;
+		} else {
+			ret = -1;
+		}
 	} else {
 		ret = -1;
 	}
-- 
2.1.1
Previous: Michael HaggertyNext: Michael Haggerty
Message 11 of 16 in “Consolidate ref parsing code”
  1. 00/11 Consolidate ref parsing codeMichael Haggerty, Oct 15, 2014
  2. 01/11 strbuf_read_file(): preserve errno on failureMichael Haggerty, Oct 15, 2014
  3. 02/11 handle_missing_loose_ref(): return an intMichael Haggerty, Oct 15, 2014
  4. 03/11 resolve_ref_unsafe(): reverse the logic of the symref conditionalMichael Haggerty, Oct 15, 2014
  5. 04/11 resolve_ref_unsafe(): use skip_prefix() to skip over "ref:"Michael Haggerty, Oct 15, 2014
  6. 05/11 refs.c: refactor resolve_ref_unsafe() to use strbuf internallyMichael Haggerty, Oct 15, 2014
  7. 06/11 refs.c: move ref parsing code out of resolve_ref()Michael Haggerty, Oct 15, 2014
  8. 07/11 handle_missing_loose_ref(): inline functionMichael Haggerty, Oct 15, 2014
  9. 08/11 resolve_gitlink_ref_recursive(): drop arbitrary refname length limitMichael Haggerty, Oct 15, 2014
  10. 09/11 refs.c: rewrite resolve_gitlink_ref() to use parse_ref()Michael Haggerty, Oct 15, 2014
  11. 10/11 resove_gitlink_packed_ref(): inline functionMichael Haggerty, Oct 15, 2014
  12. 11/11 resolve_gitlink_ref(): remove redundant testMichael Haggerty, Oct 15, 2014
  13. Junio C HamanoOct 16, 2014
  14. Junio C HamanoOct 16, 2014
  15. Michael HaggertyOct 16, 2014
  16. Duy NguyenOct 16, 2014

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.