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

[PATCH 17/20] refs.c: remove the update_ref_write function

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

Since we only call update_ref_write from a single place and we only call it with onerr==QUIET_ON_ERR we can just as well get rid of it and just call write_ref_sha1 directly. This changes the return status for _commit from 1 to -1 on failures when writing to the ref. Eventually we will want _commit to start returning more detailed error conditions than the current simple success/failure. For example if the commit failed due to name conflicts etc.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
---
 refs.c | 35 +++++++++--------------------------
 1 file changed, 9 insertions(+), 26 deletions(-)
diff --git a/refs.c b/refs.c
index 091c343..27c629f 100644
--- a/refs.c
+++ b/refs.c
@@ -3333,25 +3333,6 @@ int for_each_reflog(each_ref_fn fn, void *cb_data)
 	return retval;
 }
 
-static int update_ref_write(const char *action, const char *refname,
-			    const unsigned char *sha1, struct ref_lock *lock,
-			    struct strbuf *err, enum action_on_err onerr)
-{
-	if (write_ref_sha1(lock, sha1, action) < 0) {
-		const char *str = "Cannot update the ref '%s'.";
-		if (err)
-			strbuf_addf(err, str, refname);
-
-		switch (onerr) {
-		case UPDATE_REFS_MSG_ON_ERR: error(str, refname); break;
-		case UPDATE_REFS_DIE_ON_ERR: die(str, refname); break;
-		case UPDATE_REFS_QUIET_ON_ERR: break;
-		}
-		return 1;
-	}
-	return 0;
-}
-
 /**
  * Information needed for a single ref update.  Set new_sha1 to the
  * new value or to zero to delete the ref.  To check the old value
@@ -3604,14 +3585,16 @@ int ref_transaction_commit(struct ref_transaction *transaction,
 		struct ref_update *update = updates[i];
 
 		if (!is_null_sha1(update->new_sha1)) {
-			ret = update_ref_write(msg,
-					       update->refname,
-					       update->new_sha1,
-					       update->lock, err,
-					       UPDATE_REFS_QUIET_ON_ERR);
-			update->lock = NULL; /* freed by update_ref_write */
-			if (ret)
+			ret = write_ref_sha1(update->lock, update->new_sha1,
+					     msg);
+			update->lock = NULL; /* freed by write_ref_sha1 */
+			if (ret) {
+				const char *str = "Cannot update the ref '%s'.";
+
+				if (err)
+					strbuf_addf(err, str, update->refname);
 				goto cleanup;
+			}
 		}
 	}
 
-- 
2.0.1.442.g7fe6834.dirty
Previous: Ronnie SahlbergNext: Ronnie Sahlberg
Message 18 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.