verify_refname_available(): rename function

Rename is_refname_available() to verify_refname_available() and change its return value from 1 for success to 0 for success, to be consistent with our error-handling convention. In a moment it will also get a "struct strbuf *err" parameter. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>

Michael Haggerty committed May 11, 2015 at 17:25 UTC 5baf37d383ff80e913da1cc99a325a9baadc844c
1 file changed +20 -17
refs.c
+20 -17
@@ -263,7 +263,7 @@ struct ref_dir {
263 * presence of an empty subdirectory does not block the creation of a
264 * similarly-named reference. (The fact that reference names with the
265 * same leading components can conflict *with each other* is a
266 - * separate issue that is regulated by is_refname_available().)
266 + * separate issue that is regulated by verify_refname_available().)
267 *
268 * Please note that the name field contains the fully-qualified
269 * reference (or subdirectory) name. Space could be saved by only
@@ -858,13 +858,14 @@ static int nonmatching_ref_fn(struct ref_entry *entry, void *vdata)
858 }
859
860 /*
861 - * Return true iff a reference named refname could be created without
862 - * conflicting with the name of an existing reference in dir. If
863 - * extras is non-NULL, it is a list of additional refnames with which
864 - * refname is not allowed to conflict. If skip is non-NULL, ignore
865 - * potential conflicts with refs in skip (e.g., because they are
866 - * scheduled for deletion in the same operation). Behavior is
867 - * undefined if the same name is listed in both extras and skip.
861 + * Return 0 if a reference named refname could be created without
862 + * conflicting with the name of an existing reference in dir.
863 + * Otherwise, return a negative value. If extras is non-NULL, it is a
864 + * list of additional refnames with which refname is not allowed to
865 + * conflict. If skip is non-NULL, ignore potential conflicts with refs
866 + * in skip (e.g., because they are scheduled for deletion in the same
867 + * operation). Behavior is undefined if the same name is listed in
868 + * both extras and skip.
869 *
870 * Two reference names conflict if one of them exactly matches the
871 * leading components of the other; e.g., "refs/foo/bar" conflicts
@@ -873,15 +874,15 @@ static int nonmatching_ref_fn(struct ref_entry *entry, void *vdata)
874 *
875 * extras and skip must be sorted.
876 */
876 -static int is_refname_available(const char *refname,
877 - const struct string_list *extras,
878 - const struct string_list *skip,
879 - struct ref_dir *dir)
877 +static int verify_refname_available(const char *refname,
878 + const struct string_list *extras,
879 + const struct string_list *skip,
880 + struct ref_dir *dir)
881 {
882 const char *slash;
883 int pos;
884 struct strbuf dirname = STRBUF_INIT;
884 - int ret = 0;
885 + int ret = -1;
886
887 /*
888 * For the sake of comments in this function, suppose that
@@ -1007,7 +1008,7 @@ static int is_refname_available(const char *refname,
1008 }
1009
1010 /* No conflicts were found */
1010 - ret = 1;
1011 + ret = 0;
1012
1013 cleanup:
1014 strbuf_release(&dirname);
@@ -2383,7 +2384,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
2384 * our refname.
2385 */
2386 if (is_null_sha1(lock->old_sha1) &&
2386 - !is_refname_available(refname, extras, skip, get_packed_refs(&ref_cache))) {
2387 + verify_refname_available(refname, extras, skip, get_packed_refs(&ref_cache))) {
2388 last_errno = ENOTDIR;
2389 goto error_return;
2390 }
@@ -2824,8 +2825,10 @@ static int rename_ref_available(const char *oldname, const char *newname)
2825 int ret;
2826
2827 string_list_insert(&skip, oldname);
2827 - ret = is_refname_available(newname, NULL, &skip, get_packed_refs(&ref_cache))
2828 - && is_refname_available(newname, NULL, &skip, get_loose_refs(&ref_cache));
2828 + ret = !verify_refname_available(newname, NULL, &skip,
2829 + get_packed_refs(&ref_cache))
2830 + && !verify_refname_available(newname, NULL, &skip,
2831 + get_loose_refs(&ref_cache));
2832 string_list_clear(&skip, 0);
2833 return ret;
2834 }