git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Michael Haggerty <mhagger@alum.mit.edu>
To: Junio C Hamano <gitster@pobox.com>
Cc: "David Turner" <novalis@novalis.org>,
	"Ramsay Jones" <ramsay@ramsayjones.plus.com>,
	"Eric Sunshine" <sunshine@sunshineco.com>,
	"Jeff King" <peff@peff.net>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
	git@vger.kernel.org, "David Turner" <dturner@twopensource.com>,
	"Michael Haggerty" <mhagger@alum.mit.edu>
Subject: [PATCH v2 37/38] refs: make lock generic
Date: Sun,  4 Sep 2016 18:08:43 +0200	[thread overview]
Message-ID: <21555b1c09974a58972940745c5778a119b0a0fa.1473003903.git.mhagger@alum.mit.edu> (raw)
In-Reply-To: <cover.1473003902.git.mhagger@alum.mit.edu>

From: David Turner <dturner@twopensource.com>

Instead of including a files-backend-specific struct ref_lock, change
the generic ref_update struct to include a void pointer that backends
can use for their own arbitrary data.

Signed-off-by: David Turner <dturner@twopensource.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 refs/files-backend.c | 25 +++++++++++++------------
 refs/refs-internal.h |  2 +-
 2 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/refs/files-backend.c b/refs/files-backend.c
index 7cc4191..0714c3f 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -3552,9 +3552,8 @@ static int lock_ref_for_update(struct files_ref_store *refs,
 
 	ret = lock_raw_ref(refs, update->refname, mustexist,
 			   affected_refnames, NULL,
-			   &update->lock, &referent,
+			   &lock, &referent,
 			   &update->type, err);
-
 	if (ret) {
 		char *reason;
 
@@ -3565,7 +3564,7 @@ static int lock_ref_for_update(struct files_ref_store *refs,
 		return ret;
 	}
 
-	lock = update->lock;
+	update->backend_data = lock;
 
 	if (update->type & REF_ISSYMREF) {
 		if (update->flags & REF_NODEREF) {
@@ -3613,7 +3612,8 @@ static int lock_ref_for_update(struct files_ref_store *refs,
 		for (parent_update = update->parent_update;
 		     parent_update;
 		     parent_update = parent_update->parent_update) {
-			oidcpy(&parent_update->lock->old_oid, &lock->old_oid);
+			struct ref_lock *parent_lock = parent_update->backend_data;
+			oidcpy(&parent_lock->old_oid, &lock->old_oid);
 		}
 	}
 
@@ -3634,7 +3634,7 @@ static int lock_ref_for_update(struct files_ref_store *refs,
 			 * The lock was freed upon failure of
 			 * write_ref_to_lockfile():
 			 */
-			update->lock = NULL;
+			update->backend_data = NULL;
 			strbuf_addf(err,
 				    "cannot update ref '%s': %s",
 				    update->refname, write_err);
@@ -3752,7 +3752,7 @@ static int files_transaction_commit(struct ref_store *ref_store,
 	/* Perform updates first so live commits remain referenced */
 	for (i = 0; i < transaction->nr; i++) {
 		struct ref_update *update = transaction->updates[i];
-		struct ref_lock *lock = update->lock;
+		struct ref_lock *lock = update->backend_data;
 
 		if (update->flags & REF_NEEDS_COMMIT ||
 		    update->flags & REF_LOG_ONLY) {
@@ -3765,7 +3765,7 @@ static int files_transaction_commit(struct ref_store *ref_store,
 					    lock->ref_name, old_msg);
 				free(old_msg);
 				unlock_ref(lock);
-				update->lock = NULL;
+				update->backend_data = NULL;
 				ret = TRANSACTION_GENERIC_ERROR;
 				goto cleanup;
 			}
@@ -3775,7 +3775,7 @@ static int files_transaction_commit(struct ref_store *ref_store,
 			if (commit_ref(lock)) {
 				strbuf_addf(err, "couldn't set '%s'", lock->ref_name);
 				unlock_ref(lock);
-				update->lock = NULL;
+				update->backend_data = NULL;
 				ret = TRANSACTION_GENERIC_ERROR;
 				goto cleanup;
 			}
@@ -3784,17 +3784,18 @@ static int files_transaction_commit(struct ref_store *ref_store,
 	/* Perform deletes now that updates are safely completed */
 	for (i = 0; i < transaction->nr; i++) {
 		struct ref_update *update = transaction->updates[i];
+		struct ref_lock *lock = update->backend_data;
 
 		if (update->flags & REF_DELETING &&
 		    !(update->flags & REF_LOG_ONLY)) {
-			if (delete_ref_loose(update->lock, update->type, err)) {
+			if (delete_ref_loose(lock, update->type, err)) {
 				ret = TRANSACTION_GENERIC_ERROR;
 				goto cleanup;
 			}
 
 			if (!(update->flags & REF_ISPRUNING))
 				string_list_append(&refs_to_delete,
-						   update->lock->ref_name);
+						   lock->ref_name);
 		}
 	}
 
@@ -3810,8 +3811,8 @@ static int files_transaction_commit(struct ref_store *ref_store,
 	transaction->state = REF_TRANSACTION_CLOSED;
 
 	for (i = 0; i < transaction->nr; i++)
-		if (transaction->updates[i]->lock)
-			unlock_ref(transaction->updates[i]->lock);
+		if (transaction->updates[i]->backend_data)
+			unlock_ref(transaction->updates[i]->backend_data);
 	string_list_clear(&refs_to_delete, 0);
 	free(head_ref);
 	string_list_clear(&affected_refnames, 0);
diff --git a/refs/refs-internal.h b/refs/refs-internal.h
index c598cb1..681982b 100644
--- a/refs/refs-internal.h
+++ b/refs/refs-internal.h
@@ -162,7 +162,7 @@ struct ref_update {
 	 */
 	unsigned int flags;
 
-	struct ref_lock *lock;
+	void *backend_data;
 	unsigned int type;
 	char *msg;
 
-- 
2.9.3


  parent reply	other threads:[~2016-09-04 16:12 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-04 16:08 [PATCH v2 00/38] Virtualization of the refs API Michael Haggerty
2016-09-04 16:08 ` [PATCH v2 01/38] resolve_gitlink_ref(): eliminate temporary variable Michael Haggerty
2016-09-04 16:08 ` [PATCH v2 02/38] rename_ref_available(): add docstring Michael Haggerty
2016-09-06 14:25   ` Jakub Narębski
2016-09-07  4:32     ` Michael Haggerty
2016-09-04 16:08 ` [PATCH v2 03/38] refs: rename struct ref_cache to files_ref_store Michael Haggerty
2016-09-04 16:08 ` [PATCH v2 04/38] refs: add a backend method structure Michael Haggerty
2016-09-04 19:43   ` David Turner
2016-09-04 16:08 ` [PATCH v2 05/38] refs: create a base class "ref_store" for files_ref_store Michael Haggerty
2016-09-04 20:40   ` David Turner
2016-09-05  3:53     ` Michael Haggerty
2016-09-05  5:17       ` Stefan Beller
2016-09-05 16:16       ` David Turner
2016-09-04 16:08 ` [PATCH v2 06/38] add_packed_ref(): add a files_ref_store argument Michael Haggerty
2016-09-04 16:08 ` [PATCH v2 07/38] get_packed_ref(): " Michael Haggerty
2016-09-04 16:08 ` [PATCH v2 08/38] resolve_missing_loose_ref(): " Michael Haggerty
2016-09-04 16:08 ` [PATCH v2 09/38] {lock,commit,rollback}_packed_refs(): add files_ref_store arguments Michael Haggerty
2016-09-04 16:08 ` [PATCH v2 10/38] refs: add a transaction_commit() method Michael Haggerty
2016-09-04 16:08 ` [PATCH v2 11/38] refs: reorder definitions Michael Haggerty
2016-09-04 16:08 ` [PATCH v2 12/38] resolve_packed_ref(): rename function from resolve_missing_loose_ref() Michael Haggerty
2016-09-04 16:08 ` [PATCH v2 13/38] resolve_gitlink_packed_ref(): remove function Michael Haggerty
2016-09-04 16:08 ` [PATCH v2 14/38] read_raw_ref(): take a (struct ref_store *) argument Michael Haggerty
2016-09-04 16:08 ` [PATCH v2 15/38] resolve_ref_recursively(): new function Michael Haggerty
2016-09-04 16:08 ` [PATCH v2 16/38] resolve_gitlink_ref(): implement using resolve_ref_recursively() Michael Haggerty
2016-09-04 16:08 ` [PATCH v2 17/38] resolve_gitlink_ref(): avoid memory allocation in many cases Michael Haggerty
2016-09-04 16:08 ` [PATCH v2 18/38] resolve_gitlink_ref(): rename path parameter to submodule Michael Haggerty
2016-09-04 16:08 ` [PATCH v2 19/38] refs: make read_raw_ref() virtual Michael Haggerty
2016-09-04 16:08 ` [PATCH v2 20/38] refs: make verify_refname_available() virtual Michael Haggerty
2016-09-04 16:08 ` [PATCH v2 21/38] refs: make pack_refs() virtual Michael Haggerty
2016-09-04 16:08 ` [PATCH v2 22/38] refs: make create_symref() virtual Michael Haggerty
2016-09-04 16:08 ` [PATCH v2 23/38] refs: make peel_ref() virtual Michael Haggerty
2016-09-04 16:08 ` [PATCH v2 24/38] repack_without_refs(): add a files_ref_store argument Michael Haggerty
2016-09-04 16:08 ` [PATCH v2 25/38] lock_raw_ref(): " Michael Haggerty
2016-09-04 16:08 ` [PATCH v2 26/38] commit_ref_update(): " Michael Haggerty
2016-09-04 16:08 ` [PATCH v2 27/38] lock_ref_for_update(): " Michael Haggerty
2016-09-04 16:08 ` [PATCH v2 28/38] lock_ref_sha1_basic(): " Michael Haggerty
2016-09-04 16:08 ` [PATCH v2 29/38] split_symref_update(): " Michael Haggerty
2016-09-04 16:08 ` [PATCH v2 30/38] files_ref_iterator_begin(): take a ref_store argument Michael Haggerty
2016-09-04 16:08 ` [PATCH v2 31/38] refs: add method iterator_begin Michael Haggerty
2016-09-04 16:08 ` [PATCH v2 32/38] refs: add methods for reflog Michael Haggerty
2016-09-04 16:08 ` [PATCH v2 33/38] refs: add method for initial ref transaction commit Michael Haggerty
2016-09-04 16:08 ` [PATCH v2 34/38] refs: make delete_refs() virtual Michael Haggerty
2016-09-04 16:08 ` [PATCH v2 35/38] refs: add methods to init refs db Michael Haggerty
2016-09-04 16:08 ` [PATCH v2 36/38] refs: add method to rename refs Michael Haggerty
2016-09-04 16:08 ` Michael Haggerty [this message]
2016-09-04 16:08 ` [PATCH v2 38/38] refs: implement iteration over only per-worktree refs Michael Haggerty
2016-09-08 21:45   ` David Turner
2016-09-07 19:20 ` [PATCH v2 00/38] Virtualization of the refs API Junio C Hamano
2016-09-08  6:42   ` Michael Haggerty

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=21555b1c09974a58972940745c5778a119b0a0fa.1473003903.git.mhagger@alum.mit.edu \
    --to=mhagger@alum.mit.edu \
    --cc=dturner@twopensource.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=novalis@novalis.org \
    --cc=pclouds@gmail.com \
    --cc=peff@peff.net \
    --cc=ramsay@ramsayjones.plus.com \
    --cc=sunshine@sunshineco.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).