Keep '*' in pattern refspecs
In order to do anything more capable with refspecs, the first step is to keep the entire input. Additionally, validate patterns by checking for the ref matching the rules for a pattern as given by check_ref_format(). This requires a slight change to check_ref_format() to make it enforce the requirement that the '*' immediately follow a '/'. Signed-off-by: Daniel Barkalow <barkalow@iabervon.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Daniel Barkalow committed
Mar 7, 2009 at 01:11 UTC
08fbdb30438fd7087c5abe15840a22fe21094515
2 files changed
+19
-18
refs.c
+1
-3
@@ -718,9 +718,7 @@ int check_ref_format(const char *ref)
718
while ((ch = *cp++) != 0) {
719
bad_type = bad_ref_char(ch);
720
if (bad_type) {
721
- return (bad_type == 2 && !*cp)
722
- ? CHECK_REF_FORMAT_WILDCARD
723
- : CHECK_REF_FORMAT_ERROR;
721
+ return CHECK_REF_FORMAT_ERROR;
722
}
723
if (ch == '/')
724
break;
remote.c
+18
-15
@@ -10,8 +10,8 @@ static struct refspec s_tag_refspec = {
10
0,
11
1,
12
0,
13
- "refs/tags/",
14
- "refs/tags/"
13
+ "refs/tags/*",
14
+ "refs/tags/*"
15
};
16
17
const struct refspec *tag_refspec = &s_tag_refspec;
@@ -451,16 +451,11 @@ static void read_config(void)
451
*/
452
static int verify_refname(char *name, int is_glob)
453
{
454
- int result, len = -1;
454
+ int result;
455
456
- if (is_glob) {
457
- len = strlen(name);
458
- assert(name[len - 1] == '/');
459
- name[len - 1] = '\0';
460
- }
456
result = check_ref_format(name);
462
- if (is_glob)
463
- name[len - 1] = '/';
457
+ if (is_glob && result == CHECK_REF_FORMAT_WILDCARD)
458
+ result = CHECK_REF_FORMAT_OK;
459
return result;
460
}
461
@@ -517,7 +512,7 @@ static struct refspec *parse_refspec_internal(int nr_refspec, const char **refsp
512
if (rhs) {
513
size_t rlen = strlen(++rhs);
514
is_glob = (2 <= rlen && !strcmp(rhs + rlen - 2, "/*"));
520
- rs[i].dst = xstrndup(rhs, rlen - is_glob);
515
+ rs[i].dst = xstrndup(rhs, rlen);
516
}
517
518
llen = (rhs ? (rhs - lhs - 1) : strlen(lhs));
@@ -525,7 +520,6 @@ static struct refspec *parse_refspec_internal(int nr_refspec, const char **refsp
520
if ((rhs && !is_glob) || (!rhs && fetch))
521
goto invalid;
522
is_glob = 1;
528
- llen--;
523
} else if (rhs && is_glob) {
524
goto invalid;
525
}
@@ -722,10 +716,19 @@ int remote_has_url(struct remote *remote, const char *url)
716
static int match_name_with_pattern(const char *key, const char *name,
717
const char *value, char **result)
718
{
725
- size_t klen = strlen(key);
726
- int ret = !strncmp(key, name, klen);
719
+ const char *kstar = strchr(key, '*');
720
+ size_t klen;
721
+ int ret;
722
+ if (!kstar)
723
+ die("Key '%s' of pattern had no '*'", key);
724
+ klen = kstar - key;
725
+ ret = !strncmp(key, name, klen);
726
if (ret && value) {
728
- size_t vlen = strlen(value);
727
+ const char *vstar = strchr(value, '*');
728
+ size_t vlen;
729
+ if (!vstar)
730
+ die("Value '%s' of pattern has no '*'", value);
731
+ vlen = vstar - value;
732
*result = xmalloc(vlen +
733
strlen(name) -
734
klen + 1);