зеркало из https://github.com/microsoft/git.git
remote: separate out the remote_find_tracking logic into query_refspecs
Move the body of remote_find_tracking() to a new helper query_refspecs() that finds a refspec that matches and applies the transformation, but explicitly takes the list of refspecs, and make remote_find_tracking() a thin wrapper of it. Make apply_refspecs() also use query_refspecs(). Signed-off-by: Carlos Martín Nieto <cmn@elego.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
43a8a04a11
Коммит
c500352e0d
69
remote.c
69
remote.c
|
@ -828,59 +828,56 @@ static int match_name_with_pattern(const char *key, const char *name,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *apply_refspecs(struct refspec *refspecs, int nr_refspec,
|
static int query_refspecs(struct refspec *refs, int ref_count, struct refspec *query)
|
||||||
const char *name)
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char *ret = NULL;
|
int find_src = !query->src;
|
||||||
for (i = 0; i < nr_refspec; i++) {
|
|
||||||
struct refspec *refspec = refspecs + i;
|
|
||||||
if (refspec->pattern) {
|
|
||||||
if (match_name_with_pattern(refspec->src, name,
|
|
||||||
refspec->dst, &ret))
|
|
||||||
return ret;
|
|
||||||
} else if (!strcmp(refspec->src, name))
|
|
||||||
return strdup(refspec->dst);
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
int remote_find_tracking(struct remote *remote, struct refspec *refspec)
|
if (find_src && !query->dst)
|
||||||
{
|
return error("query_refspecs: need either src or dst");
|
||||||
int find_src = refspec->src == NULL;
|
|
||||||
char *needle, **result;
|
for (i = 0; i < ref_count; i++) {
|
||||||
int i;
|
struct refspec *refspec = &refs[i];
|
||||||
|
const char *key = find_src ? refspec->dst : refspec->src;
|
||||||
|
const char *value = find_src ? refspec->src : refspec->dst;
|
||||||
|
const char *needle = find_src ? query->dst : query->src;
|
||||||
|
char **result = find_src ? &query->src : &query->dst;
|
||||||
|
|
||||||
if (find_src) {
|
|
||||||
if (!refspec->dst)
|
if (!refspec->dst)
|
||||||
return error("find_tracking: need either src or dst");
|
|
||||||
needle = refspec->dst;
|
|
||||||
result = &refspec->src;
|
|
||||||
} else {
|
|
||||||
needle = refspec->src;
|
|
||||||
result = &refspec->dst;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < remote->fetch_refspec_nr; i++) {
|
|
||||||
struct refspec *fetch = &remote->fetch[i];
|
|
||||||
const char *key = find_src ? fetch->dst : fetch->src;
|
|
||||||
const char *value = find_src ? fetch->src : fetch->dst;
|
|
||||||
if (!fetch->dst)
|
|
||||||
continue;
|
continue;
|
||||||
if (fetch->pattern) {
|
if (refspec->pattern) {
|
||||||
if (match_name_with_pattern(key, needle, value, result)) {
|
if (match_name_with_pattern(key, needle, value, result)) {
|
||||||
refspec->force = fetch->force;
|
query->force = refspec->force;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} else if (!strcmp(needle, key)) {
|
} else if (!strcmp(needle, key)) {
|
||||||
*result = xstrdup(value);
|
*result = xstrdup(value);
|
||||||
refspec->force = fetch->force;
|
query->force = refspec->force;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *apply_refspecs(struct refspec *refspecs, int nr_refspec,
|
||||||
|
const char *name)
|
||||||
|
{
|
||||||
|
struct refspec query;
|
||||||
|
|
||||||
|
memset(&query, 0, sizeof(struct refspec));
|
||||||
|
query.src = (char *)name;
|
||||||
|
|
||||||
|
if (query_refspecs(refspecs, nr_refspec, &query))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return query.dst;
|
||||||
|
}
|
||||||
|
|
||||||
|
int remote_find_tracking(struct remote *remote, struct refspec *refspec)
|
||||||
|
{
|
||||||
|
return query_refspecs(remote->fetch, remote->fetch_refspec_nr, refspec);
|
||||||
|
}
|
||||||
|
|
||||||
static struct ref *alloc_ref_with_prefix(const char *prefix, size_t prefixlen,
|
static struct ref *alloc_ref_with_prefix(const char *prefix, size_t prefixlen,
|
||||||
const char *name)
|
const char *name)
|
||||||
{
|
{
|
||||||
|
|
Загрузка…
Ссылка в новой задаче