refs: add new ref-store api

This is not meant to cover all existing API. It adds enough to test ref
stores with the new test program test-ref-store, coming soon and to be
used by files-backend.c.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Nguyễn Thái Ngọc Duy
2017-03-26 09:42:34 +07:00
committed by Junio C Hamano
parent 18d0002d6d
commit 7d2df051d0
4 changed files with 270 additions and 99 deletions

View File

@ -1313,7 +1313,7 @@ static void read_loose_refs(const char *dirname, struct ref_dir *dir)
create_dir_entry(refs, refname.buf,
refname.len, 1));
} else {
if (!resolve_ref_recursively(&refs->base,
if (!refs_resolve_ref_unsafe(&refs->base,
refname.buf,
RESOLVE_REF_READING,
sha1, &flag)) {
@ -1622,7 +1622,8 @@ retry:
* another reference such as "refs/foo". There is no
* reason to expect this error to be transitory.
*/
if (verify_refname_available(refname, extras, skip, err)) {
if (refs_verify_refname_available(&refs->base, refname,
extras, skip, err)) {
if (mustexist) {
/*
* To the user the relevant error is
@ -2670,7 +2671,7 @@ static int files_rename_ref(struct ref_store *ref_store,
oldrefname);
goto out;
}
if (!rename_ref_available(oldrefname, newrefname)) {
if (!refs_rename_ref_available(&refs->base, oldrefname, newrefname)) {
ret = 1;
goto out;
}
@ -4054,9 +4055,9 @@ static int files_initial_transaction_commit(struct ref_store *ref_store,
if ((update->flags & REF_HAVE_OLD) &&
!is_null_sha1(update->old_sha1))
die("BUG: initial ref transaction with old_sha1 set");
if (verify_refname_available(update->refname,
&affected_refnames, NULL,
err)) {
if (refs_verify_refname_available(&refs->base, update->refname,
&affected_refnames, NULL,
err)) {
ret = TRANSACTION_NAME_CONFLICT;
goto cleanup;
}

View File

@ -111,28 +111,6 @@ enum peel_status {
*/
enum peel_status peel_object(const unsigned char *name, unsigned char *sha1);
/*
* Return 0 if a reference named refname could be created without
* conflicting with the name of an existing reference. Otherwise,
* return a negative value and write an explanation to err. If extras
* is non-NULL, it is a list of additional refnames with which refname
* is not allowed to conflict. If skip is non-NULL, ignore potential
* conflicts with refs in skip (e.g., because they are scheduled for
* deletion in the same 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
* leading components of the other; e.g., "foo/bar" conflicts with
* both "foo" and with "foo/bar/baz" but not with "foo/bar" or
* "foo/barbados".
*
* extras and skip must be sorted.
*/
int verify_refname_available(const char *newname,
const struct string_list *extras,
const struct string_list *skip,
struct strbuf *err);
/*
* Copy the reflog message msg to buf, which has been allocated sufficiently
* large, while cleaning up the whitespaces. Especially, convert LF to space,
@ -252,7 +230,9 @@ const char *find_descendant_ref(const char *dirname,
* processes (though rename_ref() catches some races that might get by
* this check).
*/
int rename_ref_available(const char *old_refname, const char *new_refname);
int refs_rename_ref_available(struct ref_store *refs,
const char *old_refname,
const char *new_refname);
/* We allow "recursive" symbolic refs. Only within reason, though */
#define SYMREF_MAXDEPTH 5
@ -646,9 +626,4 @@ struct ref_store {
void base_ref_store_init(struct ref_store *refs,
const struct ref_storage_be *be);
const char *resolve_ref_recursively(struct ref_store *refs,
const char *refname,
int resolve_flags,
unsigned char *sha1, int *flags);
#endif /* REFS_REFS_INTERNAL_H */