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>
This commit is contained in:

committed by
Junio C Hamano

parent
e911104c84
commit
5baf37d383
37
refs.c
37
refs.c
@ -263,7 +263,7 @@ struct ref_dir {
|
|||||||
* presence of an empty subdirectory does not block the creation of a
|
* presence of an empty subdirectory does not block the creation of a
|
||||||
* similarly-named reference. (The fact that reference names with the
|
* similarly-named reference. (The fact that reference names with the
|
||||||
* same leading components can conflict *with each other* is a
|
* same leading components can conflict *with each other* is a
|
||||||
* separate issue that is regulated by is_refname_available().)
|
* separate issue that is regulated by verify_refname_available().)
|
||||||
*
|
*
|
||||||
* Please note that the name field contains the fully-qualified
|
* Please note that the name field contains the fully-qualified
|
||||||
* reference (or subdirectory) name. Space could be saved by only
|
* 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)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return true iff a reference named refname could be created without
|
* Return 0 if a reference named refname could be created without
|
||||||
* conflicting with the name of an existing reference in dir. If
|
* conflicting with the name of an existing reference in dir.
|
||||||
* extras is non-NULL, it is a list of additional refnames with which
|
* Otherwise, return a negative value. If extras is non-NULL, it is a
|
||||||
* refname is not allowed to conflict. If skip is non-NULL, ignore
|
* list of additional refnames with which refname is not allowed to
|
||||||
* potential conflicts with refs in skip (e.g., because they are
|
* conflict. If skip is non-NULL, ignore potential conflicts with refs
|
||||||
* scheduled for deletion in the same operation). Behavior is
|
* in skip (e.g., because they are scheduled for deletion in the same
|
||||||
* undefined if the same name is listed in both extras and skip.
|
* operation). Behavior is undefined if the same name is listed in
|
||||||
|
* both extras and skip.
|
||||||
*
|
*
|
||||||
* Two reference names conflict if one of them exactly matches the
|
* Two reference names conflict if one of them exactly matches the
|
||||||
* leading components of the other; e.g., "refs/foo/bar" conflicts
|
* 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)
|
|||||||
*
|
*
|
||||||
* extras and skip must be sorted.
|
* extras and skip must be sorted.
|
||||||
*/
|
*/
|
||||||
static int is_refname_available(const char *refname,
|
static int verify_refname_available(const char *refname,
|
||||||
const struct string_list *extras,
|
const struct string_list *extras,
|
||||||
const struct string_list *skip,
|
const struct string_list *skip,
|
||||||
struct ref_dir *dir)
|
struct ref_dir *dir)
|
||||||
{
|
{
|
||||||
const char *slash;
|
const char *slash;
|
||||||
int pos;
|
int pos;
|
||||||
struct strbuf dirname = STRBUF_INIT;
|
struct strbuf dirname = STRBUF_INIT;
|
||||||
int ret = 0;
|
int ret = -1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* For the sake of comments in this function, suppose that
|
* For the sake of comments in this function, suppose that
|
||||||
@ -1007,7 +1008,7 @@ static int is_refname_available(const char *refname,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* No conflicts were found */
|
/* No conflicts were found */
|
||||||
ret = 1;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
strbuf_release(&dirname);
|
strbuf_release(&dirname);
|
||||||
@ -2383,7 +2384,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
|
|||||||
* our refname.
|
* our refname.
|
||||||
*/
|
*/
|
||||||
if (is_null_sha1(lock->old_sha1) &&
|
if (is_null_sha1(lock->old_sha1) &&
|
||||||
!is_refname_available(refname, extras, skip, get_packed_refs(&ref_cache))) {
|
verify_refname_available(refname, extras, skip, get_packed_refs(&ref_cache))) {
|
||||||
last_errno = ENOTDIR;
|
last_errno = ENOTDIR;
|
||||||
goto error_return;
|
goto error_return;
|
||||||
}
|
}
|
||||||
@ -2824,8 +2825,10 @@ static int rename_ref_available(const char *oldname, const char *newname)
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
string_list_insert(&skip, oldname);
|
string_list_insert(&skip, oldname);
|
||||||
ret = is_refname_available(newname, NULL, &skip, get_packed_refs(&ref_cache))
|
ret = !verify_refname_available(newname, NULL, &skip,
|
||||||
&& is_refname_available(newname, NULL, &skip, get_loose_refs(&ref_cache));
|
get_packed_refs(&ref_cache))
|
||||||
|
&& !verify_refname_available(newname, NULL, &skip,
|
||||||
|
get_loose_refs(&ref_cache));
|
||||||
string_list_clear(&skip, 0);
|
string_list_clear(&skip, 0);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user