From 37817ba08681c085d383238b13000d37ad3dd93d Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 16 Nov 2011 16:54:32 -0800 Subject: [PATCH] refs: loosen over-strict "format" check The add_extra_ref() interface is used to add an extra-ref that is _not_ our ref for the purpose of helping auto-following of tags and reducing object transfer from remote repository, and they are typically formatted as a tagname followed by ^{} to make sure no valid refs match that pattern. In other words, these entries are deliberately formatted not to pass check-refname-format test. A recent series however added a test unconditionally to the add_ref() function that is called from add_extra_ref(). The check may be sensible for other two callsites of the add_ref() interface, but definitely is a wrong thing to do in add_extra_ref(). Disable it. Signed-off-by: Junio C Hamano --- refs.c | 12 +++++++----- t/t5700-clone-reference.sh | 7 +++++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/refs.c b/refs.c index 59f1db2952..739b226ff3 100644 --- a/refs.c +++ b/refs.c @@ -58,12 +58,14 @@ static const char *parse_ref_line(char *line, unsigned char *sha1) } static struct ref_entry *create_ref_entry(const char *refname, - const unsigned char *sha1, int flag) + const unsigned char *sha1, int flag, + int check_name) { int len; struct ref_entry *ref; - if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL|REFNAME_DOT_COMPONENT)) + if (check_name && + check_refname_format(refname, REFNAME_ALLOW_ONELEVEL|REFNAME_DOT_COMPONENT)) die("Reference has invalid format: '%s'", refname); len = strlen(refname) + 1; ref = xmalloc(sizeof(struct ref_entry) + len); @@ -261,7 +263,7 @@ static void read_packed_refs(FILE *f, struct ref_array *array) refname = parse_ref_line(refline, sha1); if (refname) { - last = create_ref_entry(refname, sha1, flag); + last = create_ref_entry(refname, sha1, flag, 1); add_ref(array, last); continue; } @@ -277,7 +279,7 @@ static void read_packed_refs(FILE *f, struct ref_array *array) void add_extra_ref(const char *refname, const unsigned char *sha1, int flag) { - add_ref(&extra_refs, create_ref_entry(refname, sha1, flag)); + add_ref(&extra_refs, create_ref_entry(refname, sha1, flag, 0)); } void clear_extra_refs(void) @@ -364,7 +366,7 @@ static void get_ref_dir(struct ref_cache *refs, const char *base, hashclr(sha1); flag |= REF_BROKEN; } - add_ref(array, create_ref_entry(refname, sha1, flag)); + add_ref(array, create_ref_entry(refname, sha1, flag, 1)); } free(refname); closedir(dir); diff --git a/t/t5700-clone-reference.sh b/t/t5700-clone-reference.sh index 895f5595ae..c4c375ac04 100755 --- a/t/t5700-clone-reference.sh +++ b/t/t5700-clone-reference.sh @@ -146,4 +146,11 @@ test_expect_success 'cloning with reference being subset of source (-l -s)' \ cd "$base_dir" +test_expect_success 'clone with reference from a tagged repository' ' + ( + cd A && git tag -a -m 'tagged' HEAD + ) && + git clone --reference=A A I +' + test_done