From: David Turner <dturner@twopensource.com>
To: git@vger.kernel.org, mhagger@alum.mit.edu
Cc: David Turner <dturner@twopensource.com>
Subject: [PATCH v2 09/21] refs: add method to rename refs
Date: Mon, 11 Jan 2016 20:22:08 -0500 [thread overview]
Message-ID: <1452561740-8668-10-git-send-email-dturner@twopensource.com> (raw)
In-Reply-To: <1452561740-8668-1-git-send-email-dturner@twopensource.com>
Signed-off-by: David Turner <dturner@twopensource.com>
---
refs.c | 37 +++++++++++++++++++++----------------
refs/files-backend.c | 4 +++-
refs/refs-internal.h | 9 +++++++++
3 files changed, 33 insertions(+), 17 deletions(-)
diff --git a/refs.c b/refs.c
index af5f7a7..0b29b25 100644
--- a/refs.c
+++ b/refs.c
@@ -1089,22 +1089,6 @@ const char *find_descendant_ref(const char *dirname,
return NULL;
}
-int rename_ref_available(const char *oldname, const char *newname)
-{
- struct string_list skip = STRING_LIST_INIT_NODUP;
- struct strbuf err = STRBUF_INIT;
- int ret;
-
- string_list_insert(&skip, oldname);
- ret = !verify_refname_available(newname, NULL, &skip, &err);
- if (!ret)
- error("%s", err.buf);
-
- string_list_clear(&skip, 0);
- strbuf_release(&err);
- return ret;
-}
-
/* backend functions */
int refs_init_db(struct strbuf *err, int shared)
{
@@ -1122,6 +1106,11 @@ int delete_refs(struct string_list *refnames)
return the_refs_backend->delete_refs(refnames);
}
+int rename_ref(const char *oldref, const char *newref, const char *logmsg)
+{
+ return the_refs_backend->rename_ref(oldref, newref, logmsg);
+}
+
const char *resolve_ref_unsafe(const char *ref, int resolve_flags,
unsigned char *sha1, int *flags)
{
@@ -1135,6 +1124,22 @@ int verify_refname_available(const char *refname, struct string_list *extra,
return the_refs_backend->verify_refname_available(refname, extra, skip, err);
}
+int rename_ref_available(const char *oldname, const char *newname)
+{
+ struct string_list skip = STRING_LIST_INIT_NODUP;
+ struct strbuf err = STRBUF_INIT;
+ int ret;
+
+ string_list_insert(&skip, oldname);
+ ret = !verify_refname_available(newname, NULL, &skip, &err);
+ if (!ret)
+ error("%s", err.buf);
+
+ string_list_clear(&skip, 0);
+ strbuf_release(&err);
+ return ret;
+}
+
int pack_refs(unsigned int flags)
{
return the_refs_backend->pack_refs(flags);
diff --git a/refs/files-backend.c b/refs/files-backend.c
index e8e112c..fd4b530 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -2478,7 +2478,8 @@ static int commit_ref_update(struct ref_lock *lock,
const unsigned char *sha1, const char *logmsg,
int flags, struct strbuf *err);
-int rename_ref(const char *oldrefname, const char *newrefname, const char *logmsg)
+static int files_rename_ref(const char *oldrefname, const char *newrefname,
+ const char *logmsg)
{
unsigned char sha1[20], orig_sha1[20];
int flag = 0, logmoved = 0;
@@ -3569,6 +3570,7 @@ struct ref_storage_be refs_be_files = {
files_peel_ref,
files_create_symref,
files_delete_refs,
+ files_rename_ref,
files_resolve_ref_unsafe,
files_verify_refname_available,
diff --git a/refs/refs-internal.h b/refs/refs-internal.h
index f3c2632..64c3092 100644
--- a/refs/refs-internal.h
+++ b/refs/refs-internal.h
@@ -53,6 +53,13 @@ int do_for_each_per_worktree_ref(const char *submodule, const char *base,
void *cb_data);
/*
+ * Check if the new name does not conflict with any existing refs
+ * (other than possibly the old ref). Return 0 if the ref can be
+ * renamed to the new name.
+ */
+int rename_ref_available(const char *oldname, const char *newname);
+
+/*
* Return true iff refname is minimally safe. "Safe" here means that
* deleting a loose reference by this name will not do any damage, for
* example by causing a file that is not a reference to be deleted.
@@ -246,6 +253,7 @@ typedef const char *resolve_ref_unsafe_fn(const char *ref,
typedef int verify_refname_available_fn(const char *refname, struct string_list *extra, struct string_list *skip, struct strbuf *err);
typedef int resolve_gitlink_ref_fn(const char *path, const char *refname,
unsigned char *sha1);
+typedef int rename_ref_fn(const char *oldref, const char *newref, const char *logmsg);
/* iteration methods */
typedef int head_ref_fn(each_ref_fn fn, void *cb_data);
@@ -284,6 +292,7 @@ struct ref_storage_be {
peel_ref_fn *peel_ref;
create_symref_fn *create_symref;
delete_refs_fn *delete_refs;
+ rename_ref_fn *rename_ref;
resolve_ref_unsafe_fn *resolve_ref_unsafe;
verify_refname_available_fn *verify_refname_available;
--
2.4.2.749.g730654d-twtrsrc
next prev parent reply other threads:[~2016-01-12 1:22 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-12 1:21 [PATCH v2 00/21] refs backend reroll David Turner
2016-01-12 1:22 ` [PATCH v2 01/21] refs: add a backend method structure with transaction functions David Turner
2016-01-12 1:22 ` [PATCH v2 02/21] refs: add methods for misc ref operations David Turner
2016-01-12 1:22 ` [PATCH v2 03/21] refs: add methods for the ref iterators David Turner
2016-01-12 1:22 ` [PATCH v2 04/21] refs: add do_for_each_per_worktree_ref David Turner
2016-01-12 1:22 ` [PATCH v2 05/21] refs: add methods for reflog David Turner
2016-01-12 1:22 ` [PATCH v2 06/21] refs: add method for initial ref transaction commit David Turner
2016-01-12 1:22 ` [PATCH v2 07/21] refs: add method for delete_refs David Turner
2016-01-12 1:22 ` [PATCH v2 08/21] refs: add methods to init refs db David Turner
2016-01-12 1:22 ` David Turner [this message]
2016-01-12 1:22 ` [PATCH v2 10/21] refs: make lock generic David Turner
2016-01-12 1:22 ` [PATCH v2 11/21] refs: move duplicate check to common code David Turner
2016-01-12 1:22 ` [PATCH v2 12/21] refs: allow log-only updates David Turner
2016-01-12 1:22 ` [PATCH v2 13/21] refs: resolve symbolic refs first David Turner
2016-01-13 0:19 ` Junio C Hamano
2016-01-13 16:33 ` David Turner
2016-01-12 1:22 ` [PATCH v2 14/21] refs: always handle non-normal refs in files backend David Turner
2016-01-13 0:19 ` Junio C Hamano
2016-01-13 16:34 ` David Turner
2016-01-12 1:22 ` [PATCH v2 15/21] init: allow alternate backends to be set for new repos David Turner
2016-01-12 1:22 ` [PATCH v2 16/21] refs: check submodules ref storage config David Turner
2016-01-13 0:19 ` Junio C Hamano
2016-01-13 16:32 ` David Turner
2016-01-13 17:02 ` Junio C Hamano
2016-01-12 1:22 ` [PATCH v2 17/21] clone: use child_process for recursive checkouts David Turner
2016-01-12 1:22 ` [PATCH v2 18/21] refs: allow ref backend to be set for clone David Turner
2016-01-12 1:22 ` [PATCH v2 19/21] svn: learn ref-storage argument David Turner
2016-01-12 1:22 ` [PATCH v2 20/21] refs: add LMDB refs backend David Turner
2016-01-14 20:52 ` Jeff King
2016-01-14 22:30 ` David Turner
2016-01-12 1:22 ` [PATCH v2 21/21] refs: tests for lmdb backend David Turner
2016-01-13 0:22 ` [PATCH v2 00/21] refs backend reroll Junio C Hamano
2016-01-14 9:26 ` Jeff King
2016-01-14 16:25 ` David Turner
2016-01-14 20:12 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1452561740-8668-10-git-send-email-dturner@twopensource.com \
--to=dturner@twopensource.com \
--cc=git@vger.kernel.org \
--cc=mhagger@alum.mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).