[PATCH 33/43] refs.c: make struct ref_transaction generic

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Alternate ref backends might need different data for transactions.  Make
struct ref_transaction an empty struct, and let backends define their
own structs which extend it.

Signed-off-by: David Turner <dturner@xxxxxxxxxxx>
---
 refs-be-files.c | 20 +++++++++++++-------
 refs.h          |  8 ++++++--
 2 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/refs-be-files.c b/refs-be-files.c
index acf35b5..af99666 100644
--- a/refs-be-files.c
+++ b/refs-be-files.c
@@ -3202,7 +3202,8 @@ enum ref_transaction_state {
  * consist of checks and updates to multiple references, carried out
  * as atomically as possible.  This structure is opaque to callers.
  */
-struct ref_transaction {
+struct files_ref_transaction {
+	struct ref_transaction base;
 	struct ref_update **updates;
 	size_t alloc;
 	size_t nr;
@@ -3213,13 +3214,15 @@ static struct ref_transaction *files_transaction_begin(struct strbuf *err)
 {
 	assert(err);
 
-	return xcalloc(1, sizeof(struct ref_transaction));
+	return xcalloc(1, sizeof(struct files_ref_transaction));
 }
 
-static void files_transaction_free(struct ref_transaction *transaction)
+static void files_transaction_free(struct ref_transaction *trans)
 {
 	int i;
 
+	struct files_ref_transaction *transaction = (struct files_ref_transaction *)trans;
+
 	if (!transaction)
 		return;
 
@@ -3231,7 +3234,7 @@ static void files_transaction_free(struct ref_transaction *transaction)
 	free(transaction);
 }
 
-static struct ref_update *add_update(struct ref_transaction *transaction,
+static struct ref_update *add_update(struct files_ref_transaction *transaction,
 				     const char *refname)
 {
 	size_t len = strlen(refname);
@@ -3243,7 +3246,7 @@ static struct ref_update *add_update(struct ref_transaction *transaction,
 	return update;
 }
 
-static int files_transaction_update(struct ref_transaction *transaction,
+static int files_transaction_update(struct ref_transaction *trans,
 				  const char *refname,
 				  const unsigned char *new_sha1,
 				  const unsigned char *old_sha1,
@@ -3251,6 +3254,7 @@ static int files_transaction_update(struct ref_transaction *transaction,
 				  struct strbuf *err)
 {
 	struct ref_update *update;
+	struct files_ref_transaction *transaction = (struct files_ref_transaction *)trans;
 
 	assert(err);
 
@@ -3334,10 +3338,11 @@ static int ref_update_reject_duplicates(struct string_list *refnames,
 	return 0;
 }
 
-static int files_transaction_commit(struct ref_transaction *transaction,
+static int files_transaction_commit(struct ref_transaction *trans,
 				  struct strbuf *err)
 {
 	int ret = 0, i;
+	struct files_ref_transaction *transaction = (struct files_ref_transaction *)trans;
 	int n = transaction->nr;
 	struct ref_update **updates = transaction->updates;
 	struct string_list refs_to_delete = STRING_LIST_INIT_NODUP;
@@ -3501,10 +3506,11 @@ static int ref_present(const char *refname,
 	return string_list_has_string(affected_refnames, refname);
 }
 
-static int files_initial_transaction_commit(struct ref_transaction *transaction,
+static int files_initial_transaction_commit(struct ref_transaction *trans,
 					    struct strbuf *err)
 {
 	int ret = 0, i;
+	struct files_ref_transaction *transaction = (struct files_ref_transaction *)trans;
 	int n = transaction->nr;
 	struct ref_update **updates = transaction->updates;
 	struct string_list affected_refnames = STRING_LIST_INIT_NODUP;
diff --git a/refs.h b/refs.h
index 3134a28..e64d3c4 100644
--- a/refs.h
+++ b/refs.h
@@ -130,7 +130,7 @@ extern int dwim_log(const char *str, int len, unsigned char *sha1, char **ref);
  *
  * Calling sequence
  * ----------------
- * - Allocate and initialize a `struct ref_transaction` by calling
+ * - Allocate and initialize a transaction by calling
  *   `ref_transaction_begin()`.
  *
  * - List intended ref updates by calling functions like
@@ -156,7 +156,10 @@ extern int dwim_log(const char *str, int len, unsigned char *sha1, char **ref);
  * The message is appended to err without first clearing err.
  * err will not be '\n' terminated.
  */
-struct ref_transaction;
+
+struct ref_transaction {
+	/* ref backends should extend this */
+};
 
 /*
  * Bit values set in the flags argument passed to each_ref_fn():
@@ -622,6 +625,7 @@ typedef int (*create_reflog_fn)(const char *refname, int force_create, struct st
 typedef int (*delete_reflog_fn)(const char *refname);
 
 /* resolution functions */
+typedef void (*ref_transaction_free_fn)(struct ref_transaction *transaction);
 typedef const char *(*resolve_ref_unsafe_fn)(const char *ref,
 					     int resolve_flags,
 					     unsigned char *sha1, int *flags);
-- 
2.0.4.315.gad8727a-twtrsrc

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]