git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: David Turner <dturner@twopensource.com>
To: git@vger.kernel.org, mhagger@alum.mit.edu
Cc: Ronnie Sahlberg <sahlberg@google.com>,
	David Turner <dturner@twopensource.com>
Subject: [PATCH v2 01/21] refs: add a backend method structure with transaction functions
Date: Mon, 11 Jan 2016 20:22:00 -0500	[thread overview]
Message-ID: <1452561740-8668-2-git-send-email-dturner@twopensource.com> (raw)
In-Reply-To: <1452561740-8668-1-git-send-email-dturner@twopensource.com>

From: Ronnie Sahlberg <sahlberg@google.com>

Add a ref structure for storage backend methods. Start by adding a
method pointer for the transaction commit function.

Add a function set_refs_backend to switch between storage
backends. The files based storage backend is the default.

Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
Signed-off-by: David Turner <dturner@twopensource.com>
---
 refs.c               | 29 +++++++++++++++++++++++++++++
 refs.h               |  5 +++++
 refs/files-backend.c | 10 ++++++++--
 refs/refs-internal.h | 10 ++++++++++
 4 files changed, 52 insertions(+), 2 deletions(-)

diff --git a/refs.c b/refs.c
index 0f7628d..831ee12 100644
--- a/refs.c
+++ b/refs.c
@@ -10,6 +10,28 @@
 #include "tag.h"
 
 /*
+ * We always have a files backend and it is the default.
+ */
+struct ref_storage_be refs_be_files;
+static struct ref_storage_be *the_refs_backend = &refs_be_files;
+/*
+ * List of all available backends
+ */
+static struct ref_storage_be *refs_backends = &refs_be_files;
+
+int set_ref_storage_backend(const char *name)
+{
+	struct ref_storage_be *be;
+
+	for (be = refs_backends; be; be = be->next)
+		if (!strcmp(be->name, name)) {
+			the_refs_backend = be;
+			return 0;
+		}
+	return 1;
+}
+
+/*
  * How to handle various characters in refnames:
  * 0: An acceptable character for refs
  * 1: End-of-component
@@ -1082,3 +1104,10 @@ int rename_ref_available(const char *oldname, const char *newname)
 	strbuf_release(&err);
 	return ret;
 }
+
+/* backend functions */
+int ref_transaction_commit(struct ref_transaction *transaction,
+			   struct strbuf *err)
+{
+	return the_refs_backend->transaction_commit(transaction, err);
+}
diff --git a/refs.h b/refs.h
index 7a04077..3464a79 100644
--- a/refs.h
+++ b/refs.h
@@ -508,4 +508,9 @@ extern int reflog_expire(const char *refname, const unsigned char *sha1,
 			 reflog_expiry_cleanup_fn cleanup_fn,
 			 void *policy_cb_data);
 
+/*
+ * Switch to an alternate ref storage backend.
+ */
+int set_ref_storage_backend(const char *name);
+
 #endif /* REFS_H */
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 4db3e36..684a517 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -3123,8 +3123,8 @@ static int ref_update_reject_duplicates(struct string_list *refnames,
 	return 0;
 }
 
-int ref_transaction_commit(struct ref_transaction *transaction,
-			   struct strbuf *err)
+static int files_transaction_commit(struct ref_transaction *transaction,
+				    struct strbuf *err)
 {
 	int ret = 0, i;
 	int n = transaction->nr;
@@ -3510,3 +3510,9 @@ int reflog_expire(const char *refname, const unsigned char *sha1,
 	unlock_ref(lock);
 	return -1;
 }
+
+struct ref_storage_be refs_be_files = {
+	NULL,
+	"files",
+	files_transaction_commit,
+};
diff --git a/refs/refs-internal.h b/refs/refs-internal.h
index c7dded3..b110c77 100644
--- a/refs/refs-internal.h
+++ b/refs/refs-internal.h
@@ -197,4 +197,14 @@ const char *find_descendant_ref(const char *dirname,
 
 int rename_ref_available(const char *oldname, const char *newname);
 
+/* refs backends */
+typedef int ref_transaction_commit_fn(struct ref_transaction *transaction,
+				      struct strbuf *err);
+
+struct ref_storage_be {
+	struct ref_storage_be *next;
+	const char *name;
+	ref_transaction_commit_fn *transaction_commit;
+};
+
 #endif /* REFS_REFS_INTERNAL_H */
-- 
2.4.2.749.g730654d-twtrsrc

  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 ` David Turner [this message]
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 ` [PATCH v2 09/21] refs: add method to rename refs David Turner
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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1452561740-8668-2-git-send-email-dturner@twopensource.com \
    --to=dturner@twopensource.com \
    --cc=git@vger.kernel.org \
    --cc=mhagger@alum.mit.edu \
    --cc=sahlberg@google.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).