remote.c: minor clean-up of match_explicit()
When checking what ref the source refspec matches, we have no business setting the default for the destination, so move that code lower. Also simplify the result from the code block that matches the source side by making it set matched_src only upon unambiguous match. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Jun 9, 2007 at 00:14 UTC
3c8b7df1ba6dd2093672afc460fd5de0e755f162
1 file changed
+12
-11
remote.c
+12
-11
@@ -430,9 +430,6 @@ static int match_explicit(struct ref *src, struct ref *dst,
430
if (rs->pattern)
431
return errs;
432
433
- if (dst_value == NULL)
434
- dst_value = rs->src;
435
-
433
matched_src = matched_dst = NULL;
434
switch (count_refspec_match(rs->src, src, &matched_src)) {
435
case 1:
@@ -445,16 +442,22 @@ static int match_explicit(struct ref *src, struct ref *dst,
442
matched_src = try_explicit_object_name(rs->src);
443
if (matched_src)
444
break;
448
- errs = 1;
445
error("src refspec %s does not match any.",
446
rs->src);
447
break;
448
default:
453
- errs = 1;
449
+ matched_src = NULL;
450
error("src refspec %s matches more than one.",
451
rs->src);
452
break;
453
}
454
+
455
+ if (!matched_src)
456
+ errs = 1;
457
+
458
+ if (dst_value == NULL)
459
+ dst_value = rs->src;
460
+
461
switch (count_refspec_match(dst_value, dst, &matched_dst)) {
462
case 1:
463
break;
@@ -466,21 +469,19 @@ static int match_explicit(struct ref *src, struct ref *dst,
469
* remote does not have master yet.
470
*/
471
matched_dst = make_dst(matched_src->name, dst_tail);
469
- else {
470
- errs = 1;
472
+ else
473
error("dst refspec %s does not match any "
474
"existing ref on the remote and does "
475
"not start with refs/.", dst_value);
474
- }
476
break;
477
default:
477
- errs = 1;
478
+ matched_dst = NULL;
479
error("dst refspec %s matches more than one.",
480
dst_value);
481
break;
482
}
482
- if (errs)
483
- return errs;
483
+ if (errs || matched_dst == NULL)
484
+ return 1;
485
if (matched_dst->peer_ref) {
486
errs = 1;
487
error("dst ref %s receives from more than one src.",