summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e928213)
raw | patch | inline | side by side (parent: e928213)
author | Daniel Barkalow <barkalow@iabervon.org> | |
Sat, 7 Mar 2009 06:11:36 +0000 (01:11 -0500) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sat, 7 Mar 2009 20:19:24 +0000 (12:19 -0800) |
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>
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>
refs.c | patch | blob | history | |
remote.c | patch | blob | history |
index 6eb5f5384611bb5d159d892a1bfd120d72e54b9b..a50ba79270d897d2f5c75bfc189ee3d1fd7f2b9b 100644 (file)
--- a/refs.c
+++ b/refs.c
while ((ch = *cp++) != 0) {
bad_type = bad_ref_char(ch);
if (bad_type) {
- return (bad_type == 2 && !*cp)
- ? CHECK_REF_FORMAT_WILDCARD
- : CHECK_REF_FORMAT_ERROR;
+ return CHECK_REF_FORMAT_ERROR;
}
if (ch == '/')
break;
diff --git a/remote.c b/remote.c
index 01b8f91c5b3f493eb1ade0d08e6f9f962f7ff992..d596a4865189c1219692ed2181d629ca838c2961 100644 (file)
--- a/remote.c
+++ b/remote.c
0,
1,
0,
- "refs/tags/",
- "refs/tags/"
+ "refs/tags/*",
+ "refs/tags/*"
};
const struct refspec *tag_refspec = &s_tag_refspec;
*/
static int verify_refname(char *name, int is_glob)
{
- int result, len = -1;
+ int result;
- if (is_glob) {
- len = strlen(name);
- assert(name[len - 1] == '/');
- name[len - 1] = '\0';
- }
result = check_ref_format(name);
- if (is_glob)
- name[len - 1] = '/';
+ if (is_glob && result == CHECK_REF_FORMAT_WILDCARD)
+ result = CHECK_REF_FORMAT_OK;
return result;
}
@@ -517,7 +512,7 @@ static struct refspec *parse_refspec_internal(int nr_refspec, const char **refsp
if (rhs) {
size_t rlen = strlen(++rhs);
is_glob = (2 <= rlen && !strcmp(rhs + rlen - 2, "/*"));
- rs[i].dst = xstrndup(rhs, rlen - is_glob);
+ rs[i].dst = xstrndup(rhs, rlen);
}
llen = (rhs ? (rhs - lhs - 1) : strlen(lhs));
@@ -525,7 +520,6 @@ static struct refspec *parse_refspec_internal(int nr_refspec, const char **refsp
if ((rhs && !is_glob) || (!rhs && fetch))
goto invalid;
is_glob = 1;
- llen--;
} else if (rhs && is_glob) {
goto invalid;
}
static int match_name_with_pattern(const char *key, const char *name,
const char *value, char **result)
{
- size_t klen = strlen(key);
- int ret = !strncmp(key, name, klen);
+ const char *kstar = strchr(key, '*');
+ size_t klen;
+ int ret;
+ if (!kstar)
+ die("Key '%s' of pattern had no '*'", key);
+ klen = kstar - key;
+ ret = !strncmp(key, name, klen);
if (ret && value) {
- size_t vlen = strlen(value);
+ const char *vstar = strchr(value, '*');
+ size_t vlen;
+ if (!vstar)
+ die("Value '%s' of pattern has no '*'", value);
+ vlen = vstar - value;
*result = xmalloc(vlen +
strlen(name) -
klen + 1);