From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Turner Subject: [PATCH v3 35/44] refs: make lock generic Date: Mon, 12 Oct 2015 17:51:56 -0400 Message-ID: <1444686725-27660-37-git-send-email-dturner@twopensource.com> References: <1444686725-27660-1-git-send-email-dturner@twopensource.com> Cc: David Turner To: git@vger.kernel.org, mhagger@alum.mit.edu X-From: git-owner@vger.kernel.org Mon Oct 12 23:52:59 2015 Return-path: Envelope-to: gcvg-git-2@plane.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Zll1e-0004jW-4k for gcvg-git-2@plane.gmane.org; Mon, 12 Oct 2015 23:52:58 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752610AbbJLVwz (ORCPT ); Mon, 12 Oct 2015 17:52:55 -0400 Received: from mail-qk0-f173.google.com ([209.85.220.173]:36453 "EHLO mail-qk0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752566AbbJLVww (ORCPT ); Mon, 12 Oct 2015 17:52:52 -0400 Received: by qkht68 with SMTP id t68so63044925qkh.3 for ; Mon, 12 Oct 2015 14:52:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6d5jfr9hiJlP966dJGpjE5lD0Zk4wB39NcqPtZ2LDhY=; b=DjHvhdcN4X6aCTgNZBB1ln6PUBBwcJDYAJVVIFwTXUfWp8tIdyLoetwrfXLHoXz+oB aGIAhVZHz9kjKTVZndg4Dri882LLB5DWhKbhQuluWxQa30SAZ91+7kajiu5sLGli0fnq LrOcuBumUjxhntnJlECi3BFG2nbyMYnX09Kus4N/F63yqnmroFHoI6U6neblrQbodfT2 kRa5kJCGFIxgXcg9xAH0elo+uZwqVcfJZFUiKf+CliJat7j+qrnb8GnE8OCBY5tcHZb8 PopaHT6CDuNk1honytkV9Ovqw4aVShREtCE9DpXCQ+busVXKlATwz9oHV7ynb/ipkfbZ wqGQ== X-Gm-Message-State: ALoCoQmvTGx2c7s4UhnB1CS8G+rG8Qby5JclVk9OidkC4lmUODAfzDeGFaHw4VU6V6TkuhqxRklF X-Received: by 10.55.33.35 with SMTP id h35mr34885252qkh.71.1444686772146; Mon, 12 Oct 2015 14:52:52 -0700 (PDT) Received: from ubuntu.jfk4.office.twttr.net ([192.133.79.147]) by smtp.gmail.com with ESMTPSA id q140sm7865647qha.5.2015.10.12.14.52.51 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 12 Oct 2015 14:52:51 -0700 (PDT) X-Mailer: git-send-email 2.4.2.644.g97b850b-twtrsrc In-Reply-To: <1444686725-27660-1-git-send-email-dturner@twopensource.com> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: Instead of using a files-backend-specific struct ref_lock, the generic ref_transaction struct should provide a void pointer that backends can use for their own lock data. Signed-off-by: David Turner --- refs-be-files.c | 29 ++++++++++++++++------------- refs.h | 2 +- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/refs-be-files.c b/refs-be-files.c index 4e6f032..798a995 100644 --- a/refs-be-files.c +++ b/refs-be-files.c @@ -3167,11 +3167,12 @@ static int files_transaction_commit(struct ref_transaction *transaction, */ for (i = 0; i < n; i++) { struct ref_update *update = updates[i]; + struct ref_lock *lock; if ((update->flags & REF_HAVE_NEW) && is_null_sha1(update->new_sha1)) update->flags |= REF_DELETING; - update->lock = lock_ref_sha1_basic( + lock = lock_ref_sha1_basic( update->refname, ((update->flags & REF_HAVE_OLD) ? update->old_sha1 : NULL), @@ -3179,7 +3180,8 @@ static int files_transaction_commit(struct ref_transaction *transaction, update->flags, &update->type, err); - if (!update->lock) { + update->backend_data = lock; + if (!lock) { char *reason; ret = (errno == ENOTDIR) @@ -3197,12 +3199,12 @@ static int files_transaction_commit(struct ref_transaction *transaction, (update->flags & REF_NODEREF)); if (!overwriting_symref && - !hashcmp(update->lock->old_oid.hash, update->new_sha1)) { + !hashcmp(lock->old_oid.hash, update->new_sha1)) { /* * The reference already has the desired * value, so we don't need to write it. */ - } else if (write_ref_to_lockfile(update->lock, + } else if (write_ref_to_lockfile(lock, update->new_sha1, err)) { char *write_err = strbuf_detach(err, NULL); @@ -3211,7 +3213,7 @@ static int files_transaction_commit(struct ref_transaction *transaction, * The lock was freed upon failure of * write_ref_to_lockfile(): */ - update->lock = NULL; + update->backend_data = NULL; strbuf_addf(err, "cannot update the ref '%s': %s", update->refname, write_err); @@ -3227,7 +3229,7 @@ static int files_transaction_commit(struct ref_transaction *transaction, * We didn't have to write anything to the lockfile. * Close it to free up the file descriptor: */ - if (close_ref(update->lock)) { + if (close_ref(lock)) { strbuf_addf(err, "Couldn't close %s.lock", update->refname); goto cleanup; @@ -3240,16 +3242,16 @@ static int files_transaction_commit(struct ref_transaction *transaction, struct ref_update *update = updates[i]; if (update->flags & REF_NEEDS_COMMIT) { - if (commit_ref_update(update->lock, + if (commit_ref_update(update->backend_data, update->new_sha1, update->msg, update->flags, err)) { /* freed by commit_ref_update(): */ - update->lock = NULL; + update->backend_data = NULL; ret = TRANSACTION_GENERIC_ERROR; goto cleanup; } else { /* freed by commit_ref_update(): */ - update->lock = NULL; + update->backend_data = NULL; } } } @@ -3257,16 +3259,17 @@ static int files_transaction_commit(struct ref_transaction *transaction, /* Perform deletes now that updates are safely completed */ for (i = 0; i < n; i++) { struct ref_update *update = updates[i]; + struct ref_lock *lock = update->backend_data; if (update->flags & REF_DELETING) { - 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); } } @@ -3282,8 +3285,8 @@ cleanup: transaction->state = REF_TRANSACTION_CLOSED; for (i = 0; i < n; i++) - if (updates[i]->lock) - unlock_ref(updates[i]->lock); + if (updates[i]->backend_data) + unlock_ref(updates[i]->backend_data); string_list_clear(&refs_to_delete, 0); string_list_clear(&affected_refnames, 0); return ret; diff --git a/refs.h b/refs.h index 87d5801..4d8b3bb 100644 --- a/refs.h +++ b/refs.h @@ -196,7 +196,7 @@ struct ref_update { * REF_DELETING, and REF_ISPRUNING: */ unsigned int flags; - struct ref_lock *lock; + void *backend_data; int type; char *msg; const char refname[FLEX_ARRAY]; -- 2.4.2.644.g97b850b-twtrsrc