From 7d2df051d05bc65a0a540ba080f07b421b4d99d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 26 Mar 2017 09:42:34 +0700 Subject: refs: add new ref-store api MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Junio C Hamano --- refs/files-backend.c | 13 +++++++------ refs/refs-internal.h | 31 +++---------------------------- 2 files changed, 10 insertions(+), 34 deletions(-) (limited to 'refs') diff --git a/refs/files-backend.c b/refs/files-backend.c index c90b47232e..f3ebdb279d 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -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; } diff --git a/refs/refs-internal.h b/refs/refs-internal.h index f20dde39ee..5f26208c2c 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -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 */ -- cgit v1.2.3