Update callers of check_ref_format()
This updates send-pack and fast-import to use symbolic constants for checking the return values from check_ref_format(), and also futureproof the logic in lock_any_ref_for_update() to explicitly name the case that is usually considered an error but is Ok for this particular use. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Jan 2, 2008 at 11:14 UTC
257f3020f69f3222cdefc1d84b148fb35b2c4f5b
3 files changed
+12
-9
builtin-send-pack.c
+6
-4
@@ -541,10 +541,12 @@ static void verify_remote_names(int nr_heads, const char **heads)
541
remote = remote ? (remote + 1) : heads[i];
542
switch (check_ref_format(remote)) {
543
case 0: /* ok */
544
- case -2: /* ok but a single level -- that is fine for
545
- * a match pattern.
546
- */
547
- case -3: /* ok but ends with a pattern-match character */
544
+ case CHECK_REF_FORMAT_ONELEVEL:
545
+ /* ok but a single level -- that is fine for
546
+ * a match pattern.
547
+ */
548
+ case CHECK_REF_FORMAT_WILDCARD:
549
+ /* ok but ends with a pattern-match character */
550
continue;
551
}
552
die("remote part of refspec is not a valid name in %s",
fast-import.c
+3
-2
@@ -642,8 +642,9 @@ static struct branch *new_branch(const char *name)
642
if (b)
643
die("Invalid attempt to create duplicate branch: %s", name);
644
switch (check_ref_format(name)) {
645
- case 0: break; /* its valid */
646
- case -2: break; /* valid, but too few '/', allow anyway */
645
+ case 0: break; /* its valid */
646
+ case CHECK_REF_FORMAT_ONELEVEL:
647
+ break; /* valid, but too few '/', allow anyway */
648
default:
649
die("Branch name doesn't conform to GIT standards: %s", name);
650
}
refs.c
+3
-3
@@ -822,10 +822,10 @@ struct ref_lock *lock_ref_sha1(const char *ref, const unsigned char *old_sha1)
822
struct ref_lock *lock_any_ref_for_update(const char *ref, const unsigned char *old_sha1, int flags)
823
{
824
switch (check_ref_format(ref)) {
825
- case CHECK_REF_FORMAT_ERROR:
826
- case CHECK_REF_FORMAT_WILDCARD:
827
- return NULL;
825
default:
826
+ return NULL;
827
+ case 0:
828
+ case CHECK_REF_FORMAT_ONELEVEL:
829
return lock_ref_sha1_basic(ref, old_sha1, flags, NULL);
830
}
831
}