remote.c: refactor creation of new dst ref
This refactors open-coded sequence to create a new "struct ref" and link it to the tail of dst list into a new function. Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
54a8ad925c
commit
163f0ee5ad
35
remote.c
35
remote.c
@ -406,6 +406,18 @@ static struct ref *try_explicit_object_name(const char *name)
|
|||||||
return ref;
|
return ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct ref *make_dst(const char *name, struct ref ***dst_tail)
|
||||||
|
{
|
||||||
|
struct ref *dst;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
len = strlen(name) + 1;
|
||||||
|
dst = xcalloc(1, sizeof(*dst) + len);
|
||||||
|
memcpy(dst->name, name, len);
|
||||||
|
link_dst_tail(dst, dst_tail);
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
|
||||||
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,
|
||||||
@ -447,23 +459,13 @@ static int match_explicit(struct ref *src, struct ref *dst,
|
|||||||
case 1:
|
case 1:
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
if (!memcmp(dst_value, "refs/", 5)) {
|
if (!memcmp(dst_value, "refs/", 5))
|
||||||
int len = strlen(dst_value) + 1;
|
matched_dst = make_dst(dst_value, dst_tail);
|
||||||
matched_dst = xcalloc(1, sizeof(*dst) + len);
|
else if (!strcmp(rs->src, dst_value) && matched_src)
|
||||||
memcpy(matched_dst->name, dst_value, len);
|
|
||||||
link_dst_tail(matched_dst, dst_tail);
|
|
||||||
}
|
|
||||||
else if (!strcmp(rs->src, dst_value) &&
|
|
||||||
matched_src) {
|
|
||||||
/* pushing "master:master" when
|
/* pushing "master:master" when
|
||||||
* remote does not have master yet.
|
* remote does not have master yet.
|
||||||
*/
|
*/
|
||||||
int len = strlen(matched_src->name) + 1;
|
matched_dst = make_dst(matched_src->name, dst_tail);
|
||||||
matched_dst = xcalloc(1, sizeof(*dst) + len);
|
|
||||||
memcpy(matched_dst->name, matched_src->name,
|
|
||||||
len);
|
|
||||||
link_dst_tail(matched_dst, dst_tail);
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
errs = 1;
|
errs = 1;
|
||||||
error("dst refspec %s does not match any "
|
error("dst refspec %s does not match any "
|
||||||
@ -567,11 +569,8 @@ int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail,
|
|||||||
goto free_name;
|
goto free_name;
|
||||||
if (!dst_peer) {
|
if (!dst_peer) {
|
||||||
/* Create a new one and link it */
|
/* Create a new one and link it */
|
||||||
int len = strlen(dst_name) + 1;
|
dst_peer = make_dst(dst_name, dst_tail);
|
||||||
dst_peer = xcalloc(1, sizeof(*dst_peer) + len);
|
|
||||||
memcpy(dst_peer->name, dst_name, len);
|
|
||||||
hashcpy(dst_peer->new_sha1, src->new_sha1);
|
hashcpy(dst_peer->new_sha1, src->new_sha1);
|
||||||
link_dst_tail(dst_peer, dst_tail);
|
|
||||||
}
|
}
|
||||||
dst_peer->peer_ref = src;
|
dst_peer->peer_ref = src;
|
||||||
free_name:
|
free_name:
|
||||||
|
Loading…
Reference in New Issue
Block a user