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>
Junio C Hamano committed
Jun 9, 2007 at 00:07 UTC
163f0ee5ad0a5cb7d862431479c270ae3fef79cf
1 file changed
+17
-18
remote.c
+17
-18
@@ -406,6 +406,18 @@ static struct ref *try_explicit_object_name(const char *name)
406
return ref;
407
}
408
409
+static struct ref *make_dst(const char *name, struct ref ***dst_tail)
410
+{
411
+ struct ref *dst;
412
+ size_t len;
413
+
414
+ len = strlen(name) + 1;
415
+ dst = xcalloc(1, sizeof(*dst) + len);
416
+ memcpy(dst->name, name, len);
417
+ link_dst_tail(dst, dst_tail);
418
+ return dst;
419
+}
420
+
421
static int match_explicit(struct ref *src, struct ref *dst,
422
struct ref ***dst_tail,
423
struct refspec *rs,
@@ -447,23 +459,13 @@ static int match_explicit(struct ref *src, struct ref *dst,
459
case 1:
460
break;
461
case 0:
450
- if (!memcmp(dst_value, "refs/", 5)) {
451
- int len = strlen(dst_value) + 1;
452
- matched_dst = xcalloc(1, sizeof(*dst) + len);
453
- memcpy(matched_dst->name, dst_value, len);
454
- link_dst_tail(matched_dst, dst_tail);
455
- }
456
- else if (!strcmp(rs->src, dst_value) &&
457
- matched_src) {
462
+ if (!memcmp(dst_value, "refs/", 5))
463
+ matched_dst = make_dst(dst_value, dst_tail);
464
+ else if (!strcmp(rs->src, dst_value) && matched_src)
465
/* pushing "master:master" when
466
* remote does not have master yet.
467
*/
461
- int len = strlen(matched_src->name) + 1;
462
- matched_dst = xcalloc(1, sizeof(*dst) + len);
463
- memcpy(matched_dst->name, matched_src->name,
464
- len);
465
- link_dst_tail(matched_dst, dst_tail);
466
- }
468
+ matched_dst = make_dst(matched_src->name, dst_tail);
469
else {
470
errs = 1;
471
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,
569
goto free_name;
570
if (!dst_peer) {
571
/* Create a new one and link it */
570
- int len = strlen(dst_name) + 1;
571
- dst_peer = xcalloc(1, sizeof(*dst_peer) + len);
572
- memcpy(dst_peer->name, dst_name, len);
572
+ dst_peer = make_dst(dst_name, dst_tail);
573
hashcpy(dst_peer->new_sha1, src->new_sha1);
574
- link_dst_tail(dst_peer, dst_tail);
574
}
575
dst_peer->peer_ref = src;
576
free_name: