From 7695d118e5a3c9c6fcb4cb15eb766a1c57422aed Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Tue, 15 Jul 2014 12:59:36 -0700 Subject: refs.c: change resolve_ref_unsafe reading argument to be a flags field resolve_ref_unsafe takes a boolean argument for reading (a nonexistent ref resolves successfully for writing but not for reading). Change this to be a flags field instead, and pass the new constant RESOLVE_REF_READING when we want this behaviour. While at it, swap two of the arguments in the function to put output arguments at the end. As a nice side effect, this ensures that we can catch callers that were unaware of the new API so they can be audited. Give the wrapper functions resolve_refdup and read_ref_full the same treatment for consistency. Signed-off-by: Ronnie Sahlberg Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- builtin/for-each-ref.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'builtin/for-each-ref.c') diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c index fda0f04712..492265d9f9 100644 --- a/builtin/for-each-ref.c +++ b/builtin/for-each-ref.c @@ -635,7 +635,8 @@ static void populate_value(struct refinfo *ref) if (need_symref && (ref->flag & REF_ISSYMREF) && !ref->symref) { unsigned char unused1[20]; - ref->symref = resolve_refdup(ref->refname, unused1, 1, NULL); + ref->symref = resolve_refdup(ref->refname, RESOLVE_REF_READING, + unused1, NULL); if (!ref->symref) ref->symref = ""; } @@ -693,7 +694,8 @@ static void populate_value(struct refinfo *ref) const char *head; unsigned char sha1[20]; - head = resolve_ref_unsafe("HEAD", sha1, 1, NULL); + head = resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, + sha1, NULL); if (!strcmp(ref->refname, head)) v->s = "*"; else -- cgit v1.2.1 From 971c41c71728d057115b105f427202f98565f933 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Fri, 5 Sep 2014 14:35:17 -0700 Subject: for-each-ref: skip and warn about broken ref names Print a warning message for any bad ref names we find in the repo and skip them so callers don't have to deal with parsing them. It might be useful in the future to have a flag where we would not skip these refs for those callers that want to and are prepared (for example by using a --format argument with %0 as a delimiter after the ref name). Signed-off-by: Ronnie Sahlberg Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- builtin/for-each-ref.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'builtin/for-each-ref.c') diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c index 492265d9f9..3ee22b96a5 100644 --- a/builtin/for-each-ref.c +++ b/builtin/for-each-ref.c @@ -839,6 +839,11 @@ static int grab_single_ref(const char *refname, const unsigned char *sha1, int f struct refinfo *ref; int cnt; + if (flag & REF_BAD_NAME) { + warning("ignoring ref with broken name %s", refname); + return 0; + } + if (*cb->grab_pattern) { const char **pattern; int namelen = strlen(refname); -- cgit v1.2.1