git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 20/20] refs.c: make delete_ref use a transaction

From
Ronnie Sahlberg <sahlberg@google.com>
Date
Jul 15, 2014, 23:34 UTC
Message-ID
<1405467258-24102-21-git-send-email-sahlberg@google.com>
In-Reply-To
<1405467258-24102-1-git-send-email-sahlberg@google.com>

Change delete_ref to use a ref transaction for the deletion. At the same time since we no longer have any callers of repack_without_ref we can now delete this function.

Change delete_ref to return 0 on success and 1 on failure instead of the previous 0 on success either 1 or -1 on failure.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
---
 refs.c | 34 +++++++++++++---------------------
 1 file changed, 13 insertions(+), 21 deletions(-)
diff --git a/refs.c b/refs.c
index 186df37..0017d9c 100644
--- a/refs.c
+++ b/refs.c
@@ -2544,11 +2544,6 @@ int repack_without_refs(const char **refnames, int n, struct strbuf *err)
 	return ret;
 }
 
-static int repack_without_ref(const char *refname)
-{
-	return repack_without_refs(&refname, 1, NULL);
-}
-
 static int delete_ref_loose(struct ref_lock *lock, int flag)
 {
 	if (!(flag & REF_ISPACKED) || flag & REF_ISSYMREF) {
@@ -2566,24 +2561,21 @@ static int delete_ref_loose(struct ref_lock *lock, int flag)
 
 int delete_ref(const char *refname, const unsigned char *sha1, int delopt)
 {
-	struct ref_lock *lock;
-	int ret = 0, flag = 0;
+	struct ref_transaction *transaction;
+	struct strbuf err = STRBUF_INIT;
 
-	lock = lock_ref_sha1_basic(refname, sha1, delopt, &flag);
-	if (!lock)
+	transaction = ref_transaction_begin(&err);
+	if (!transaction ||
+	    ref_transaction_delete(transaction, refname, sha1, delopt,
+				   sha1 && !is_null_sha1(sha1), &err) ||
+	    ref_transaction_commit(transaction, NULL, &err)) {
+		error("%s", err.buf);
+		ref_transaction_free(transaction);
+		strbuf_release(&err);
 		return 1;
-	ret |= delete_ref_loose(lock, flag);
-
-	/* removing the loose one could have resurrected an earlier
-	 * packed one.  Also, if it was not loose we need to repack
-	 * without it.
-	 */
-	ret |= repack_without_ref(lock->ref_name);
-
-	unlink_or_warn(git_path("logs/%s", lock->ref_name));
-	clear_loose_ref_cache(&ref_cache);
-	unlock_ref(lock);
-	return ret;
+	}
+	ref_transaction_free(transaction);
+	return 0;
 }
 
 /*
-- 
2.0.1.442.g7fe6834.dirty
Previous: Ronnie SahlbergNext: Ronnie Sahlberg
Message 21 of 24 in “ref transactions part 2”
  1. 00/20 ref transactions part 2Ronnie Sahlberg, Jul 15, 2014
  2. 01/20 refs.c: change ref_transaction_create to do error checking and return statusRonnie Sahlberg, Jul 15, 2014
  3. 02/20 refs.c: update ref_transaction_delete to check for error and return statusRonnie Sahlberg, Jul 15, 2014
  4. 03/20 refs.c: make ref_transaction_begin take an err argumentRonnie Sahlberg, Jul 15, 2014
  5. 04/20 refs.c: add transaction.status and track OPEN/CLOSED/ERRORRonnie Sahlberg, Jul 15, 2014
  6. 05/20 tag.c: use ref transactions when doing updatesRonnie Sahlberg, Jul 15, 2014
  7. 06/20 replace.c: use the ref transaction functions for updatesRonnie Sahlberg, Jul 15, 2014
  8. 07/20 commit.c: use ref transactions for updatesRonnie Sahlberg, Jul 15, 2014
  9. 08/20 sequencer.c: use ref transactions for all ref updatesRonnie Sahlberg, Jul 15, 2014
  10. 09/20 fast-import.c: change update_branch to use ref transactionsRonnie Sahlberg, Jul 15, 2014
  11. 10/20 branch.c: use ref transaction for all ref updatesRonnie Sahlberg, Jul 15, 2014
  12. 11/20 refs.c: change update_ref to use a transactionRonnie Sahlberg, Jul 15, 2014
  13. 12/20 receive-pack.c: use a reference transaction for updating the refsRonnie Sahlberg, Jul 15, 2014
  14. 13/20 fast-import.c: use a ref transaction when dumping tagsRonnie Sahlberg, Jul 15, 2014
  15. 14/20 walker.c: use ref transaction for ref updatesRonnie Sahlberg, Jul 15, 2014
  16. 15/20 refs.c: make lock_ref_sha1 staticRonnie Sahlberg, Jul 15, 2014
  17. 16/20 refs.c: remove the update_ref_lock functionRonnie Sahlberg, Jul 15, 2014
  18. 17/20 refs.c: remove the update_ref_write functionRonnie Sahlberg, Jul 15, 2014
  19. 18/20 refs.c: remove lock_ref_sha1Ronnie Sahlberg, Jul 15, 2014
  20. 19/20 refs.c: make prune_ref use a transaction to delete the refRonnie Sahlberg, Jul 15, 2014
  21. 20/20 refs.c: make delete_ref use a transactionRonnie Sahlberg, Jul 15, 2014
  22. Ronnie SahlbergJul 15, 2014
  23. Junio C HamanoJul 16, 2014
  24. Ronnie SahlbergJul 16, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.