Skip to content

Commit 5baf37d

Browse files
mhaggergitster
authored andcommitted
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 <[email protected]>
1 parent e911104 commit 5baf37d

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

refs.c

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ struct ref_dir {
263263
* presence of an empty subdirectory does not block the creation of a
264264
* similarly-named reference. (The fact that reference names with the
265265
* 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().)
267267
*
268268
* Please note that the name field contains the fully-qualified
269269
* 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)
858858
}
859859

860860
/*
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.
868869
*
869870
* Two reference names conflict if one of them exactly matches the
870871
* 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)
873874
*
874875
* extras and skip must be sorted.
875876
*/
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)
880881
{
881882
const char *slash;
882883
int pos;
883884
struct strbuf dirname = STRBUF_INIT;
884-
int ret = 0;
885+
int ret = -1;
885886

886887
/*
887888
* For the sake of comments in this function, suppose that
@@ -1007,7 +1008,7 @@ static int is_refname_available(const char *refname,
10071008
}
10081009

10091010
/* No conflicts were found */
1010-
ret = 1;
1011+
ret = 0;
10111012

10121013
cleanup:
10131014
strbuf_release(&dirname);
@@ -2383,7 +2384,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
23832384
* our refname.
23842385
*/
23852386
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))) {
23872388
last_errno = ENOTDIR;
23882389
goto error_return;
23892390
}
@@ -2824,8 +2825,10 @@ static int rename_ref_available(const char *oldname, const char *newname)
28242825
int ret;
28252826

28262827
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));
28292832
string_list_clear(&skip, 0);
28302833
return ret;
28312834
}

0 commit comments

Comments
 (0)