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

[PATCH v2 5/8] rename_ref(): inline calls to write_ref_sha1() from this function

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
May 10, 2015, 02:45 UTC
Message-ID
<1431225937-10456-6-git-send-email-mhagger@alum.mit.edu>
In-Reply-To
<1431225937-10456-1-git-send-email-mhagger@alum.mit.edu>
Most of what it does is unneeded from these call sites.
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
 refs.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/refs.c b/refs.c
index 7661db9..18ce8e6 100644
--- a/refs.c
+++ b/refs.c
@@ -2799,8 +2799,9 @@ static int rename_ref_available(const char *oldname, const char *newname)
 	return ret;
 }
 
-static int write_ref_sha1(struct ref_lock *lock, const unsigned char *sha1,
-			  const char *logmsg);
+static int write_ref_to_lockfile(struct ref_lock *lock, const unsigned char *sha1);
+static int commit_ref_update(struct ref_lock *lock,
+			     const unsigned char *sha1, const char *logmsg);
 
 int rename_ref(const char *oldrefname, const char *newrefname, const char *logmsg)
 {
@@ -2859,7 +2860,9 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms
 	}
 	lock->force_write = 1;
 	hashcpy(lock->old_sha1, orig_sha1);
-	if (write_ref_sha1(lock, orig_sha1, logmsg)) {
+
+	if (write_ref_to_lockfile(lock, orig_sha1) ||
+	    commit_ref_update(lock, orig_sha1, logmsg)) {
 		error("unable to write current sha1 into %s", newrefname);
 		goto rollback;
 	}
@@ -2876,7 +2879,8 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms
 	lock->force_write = 1;
 	flag = log_all_ref_updates;
 	log_all_ref_updates = 0;
-	if (write_ref_sha1(lock, orig_sha1, NULL))
+	if (write_ref_to_lockfile(lock, orig_sha1) ||
+	    commit_ref_update(lock, orig_sha1, NULL))
 		error("unable to write current sha1 into %s", oldrefname);
 	log_all_ref_updates = flag;
 
-- 
2.1.4
Previous: Michael HaggertyNext: Michael Haggerty
Message 8 of 16 in “Fix atomicity and avoid fd exhaustion in ref transactions”
  1. 0/8 Fix atomicity and avoid fd exhaustion in ref transactionsMichael Haggerty, May 10, 2015
  2. 1/8 update-ref: test handling large transactions properlyMichael Haggerty, May 10, 2015
  3. 2/8 t7004: rename ULIMIT test prerequisite to ULIMIT_STACK_SIZEMichael Haggerty, May 10, 2015
  4. Stefan BellerMay 11, 2015
  5. Junio C HamanoMay 12, 2015
  6. 3/8 write_ref_to_lockfile(): new function, extracted from write_ref_sha1()Michael Haggerty, May 10, 2015
  7. 4/8 commit_ref_update(): new function, extracted from write_ref_sha1()Michael Haggerty, May 10, 2015
  8. 5/8 rename_ref(): inline calls to write_ref_sha1() from this functionMichael Haggerty, May 10, 2015
  9. 6/8 ref_transaction_commit(): inline call to write_ref_sha1()Michael Haggerty, May 10, 2015
  10. 7/8 ref_transaction_commit(): remove the local flags variableMichael Haggerty, May 10, 2015
  11. 8/8 ref_transaction_commit(): fix atomicity and avoid fd exhaustionMichael Haggerty, May 10, 2015
  12. Junio C HamanoMay 11, 2015
  13. Michael HaggertyMay 11, 2015
  14. Stefan BellerMay 11, 2015
  15. Christian CouderMay 12, 2015
  16. Stefan BellerMay 11, 2015

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.