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

[PATCHv5 1/4] Fix prefix handling in ref iteration functions

From
Jamey Sharp <jamey@minilop.net>
Date
Jun 3, 2011, 21:29 UTC
Message-ID
<1307136593-16306-2-git-send-email-jamey@minilop.net>
In-Reply-To
<1307136593-16306-1-git-send-email-jamey@minilop.net>
From: Josh Triplett <josh@joshtriplett.org>

The do_for_each_ref iteration function accepts a prefix and a trim, and checks for the prefix on each ref before passing in that ref; it also supports trimming off part of the ref before passing it. Several callers passed a prefix of "refs/" to filter out everything outside of refs/, but a trim of 0 to avoid trimming off the "refs/". However, do_for_each_ref used trim as the length of the prefix to check, so it ignored the "refs/" prefix entirely. Switch to using prefixcmp, checking the entire length of the prefix string, to properly support a trim value different than the length of the prefix.

This fixes a bug where the ref iteration functions did not properly ignore refs outside of "refs/". The loose ref functions can never supply such refs, and packed-refs would not normally include such refs, but nothing prevents a packed-refs file from including refs outside of "refs/". (Confirmed by manually editing a packed-refs file.)

Commit by Josh Triplett and Jamey Sharp.
Signed-off-by: Josh Triplett <josh@joshtriplett.org>
Signed-off-by: Jamey Sharp <jamey@minilop.net>
---
 refs.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/refs.c b/refs.c
index e3c0511..003680f 100644
--- a/refs.c
+++ b/refs.c
@@ -584,7 +584,7 @@ int read_ref(const char *ref, unsigned char *sha1)
 static int do_one_ref(const char *base, each_ref_fn fn, int trim,
 		      int flags, void *cb_data, struct ref_list *entry)
 {
-	if (strncmp(base, entry->name, trim))
+	if (prefixcmp(entry->name, base))
 		return 0;
 
 	if (!(flags & DO_FOR_EACH_INCLUDE_BROKEN)) {
-- 
1.7.5.3
Previous: Jamey SharpNext: Jamey Sharp
Message 2 of 9 in “[PATCHv5 0/4] Support ref namespaces”
  1. Jamey SharpJun 3, 2011
  2. 1/4 Fix prefix handling in ref iteration functionsJamey Sharp, Jun 3, 2011
  3. 2/4 Add infrastructure for ref namespacesJamey Sharp, Jun 3, 2011
  4. Junio C HamanoJun 3, 2011
  5. Josh TriplettJun 3, 2011
  6. 3/4 Support ref namespaces for remote repositories via upload-pack and receive-packJamey Sharp, Jun 3, 2011
  7. 4/4 Add documentation for ref namespacesJamey Sharp, Jun 3, 2011
  8. Junio C HamanoJun 3, 2011
  9. Josh TriplettJun 3, 2011

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.