git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jamey Sharp <jamey@minilop.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: "Shawn O. Pearce" <spearce@spearce.org>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	Jeff King <peff@peff.net>, Jakub Narebski <jnareb@gmail.com>,
	git@vger.kernel.org, Josh Triplett <josh@joshtriplett.org>
Subject: [PATCHv6 1/4] Fix prefix handling in ref iteration functions
Date: Fri,  3 Jun 2011 17:11:40 -0700	[thread overview]
Message-ID: <1307146303-4524-2-git-send-email-jamey@minilop.net> (raw)
In-Reply-To: <1307146303-4524-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

  reply	other threads:[~2011-06-04  0:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-04  0:11 [PATCHv6 0/4] Support ref namespaces Jamey Sharp
2011-06-04  0:11 ` Jamey Sharp [this message]
2011-06-04  0:11 ` [PATCHv6 2/4] Add infrastructure for " Jamey Sharp
2011-06-04  0:11 ` [PATCHv6 3/4] Support ref namespaces for remote repositories via upload-pack and receive-pack Jamey Sharp
2011-06-04  0:11 ` [PATCHv6 4/4] Add documentation for ref namespaces Jamey Sharp

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1307146303-4524-2-git-send-email-jamey@minilop.net \
    --to=jamey@minilop.net \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jnareb@gmail.com \
    --cc=josh@joshtriplett.org \
    --cc=peff@peff.net \
    --cc=spearce@spearce.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).