match_explicit: hoist refspec lhs checks into their own function
In preparation for being able to check the left-hand side of our push refspecs separately, this pulls the examination of them out into its own function. There should be no behavior change. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
5f95c9f850
commit
f7ade3d36b
49
remote.c
49
remote.c
@ -1096,12 +1096,36 @@ static char *guess_ref(const char *name, struct ref *peer)
|
|||||||
return strbuf_detach(&buf, NULL);
|
return strbuf_detach(&buf, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int match_explicit_lhs(struct ref *src,
|
||||||
|
struct refspec *rs,
|
||||||
|
struct ref **match,
|
||||||
|
int *allocated_match)
|
||||||
|
{
|
||||||
|
switch (count_refspec_match(rs->src, src, match)) {
|
||||||
|
case 1:
|
||||||
|
*allocated_match = 0;
|
||||||
|
return 0;
|
||||||
|
case 0:
|
||||||
|
/* The source could be in the get_sha1() format
|
||||||
|
* not a reference name. :refs/other is a
|
||||||
|
* way to delete 'other' ref at the remote end.
|
||||||
|
*/
|
||||||
|
*match = try_explicit_object_name(rs->src);
|
||||||
|
if (!*match)
|
||||||
|
return error("src refspec %s does not match any.", rs->src);
|
||||||
|
*allocated_match = 1;
|
||||||
|
return 0;
|
||||||
|
default:
|
||||||
|
return error("src refspec %s matches more than one.", rs->src);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int match_explicit(struct ref *src, struct ref *dst,
|
static int match_explicit(struct ref *src, struct ref *dst,
|
||||||
struct ref ***dst_tail,
|
struct ref ***dst_tail,
|
||||||
struct refspec *rs)
|
struct refspec *rs)
|
||||||
{
|
{
|
||||||
struct ref *matched_src, *matched_dst;
|
struct ref *matched_src, *matched_dst;
|
||||||
int copy_src;
|
int allocated_src;
|
||||||
|
|
||||||
const char *dst_value = rs->dst;
|
const char *dst_value = rs->dst;
|
||||||
char *dst_guess;
|
char *dst_guess;
|
||||||
@ -1110,23 +1134,8 @@ static int match_explicit(struct ref *src, struct ref *dst,
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
matched_src = matched_dst = NULL;
|
matched_src = matched_dst = NULL;
|
||||||
switch (count_refspec_match(rs->src, src, &matched_src)) {
|
if (match_explicit_lhs(src, rs, &matched_src, &allocated_src) < 0)
|
||||||
case 1:
|
return -1;
|
||||||
copy_src = 1;
|
|
||||||
break;
|
|
||||||
case 0:
|
|
||||||
/* The source could be in the get_sha1() format
|
|
||||||
* not a reference name. :refs/other is a
|
|
||||||
* way to delete 'other' ref at the remote end.
|
|
||||||
*/
|
|
||||||
matched_src = try_explicit_object_name(rs->src);
|
|
||||||
if (!matched_src)
|
|
||||||
return error("src refspec %s does not match any.", rs->src);
|
|
||||||
copy_src = 0;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return error("src refspec %s matches more than one.", rs->src);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!dst_value) {
|
if (!dst_value) {
|
||||||
unsigned char sha1[20];
|
unsigned char sha1[20];
|
||||||
@ -1171,7 +1180,9 @@ static int match_explicit(struct ref *src, struct ref *dst,
|
|||||||
return error("dst ref %s receives from more than one src.",
|
return error("dst ref %s receives from more than one src.",
|
||||||
matched_dst->name);
|
matched_dst->name);
|
||||||
else {
|
else {
|
||||||
matched_dst->peer_ref = copy_src ? copy_ref(matched_src) : matched_src;
|
matched_dst->peer_ref = allocated_src ?
|
||||||
|
matched_src :
|
||||||
|
copy_ref(matched_src);
|
||||||
matched_dst->force = rs->force;
|
matched_dst->force = rs->force;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user