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

[PATCH v2 7/8] ref_transaction_commit(): remove the local flags variable

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
May 10, 2015, 02:45 UTC
Message-ID
<1431225937-10456-8-git-send-email-mhagger@alum.mit.edu>
In-Reply-To
<1431225937-10456-1-git-send-email-mhagger@alum.mit.edu>

Instead, work directly with update->flags. This has the advantage that the REF_DELETING bit, set in the first loop, can be read in the second loop instead of having to be recomputed. Plus, it was potentially confusing having both update->flags and flags, which sometimes had different values.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
 refs.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/refs.c b/refs.c
index 76609bf..58b1182 100644
--- a/refs.c
+++ b/refs.c
@@ -3802,16 +3802,15 @@ int ref_transaction_commit(struct ref_transaction *transaction,
 	/* Acquire all locks while verifying old values */
 	for (i = 0; i < n; i++) {
 		struct ref_update *update = updates[i];
-		int flags = update->flags;
 
 		if (is_null_sha1(update->new_sha1))
-			flags |= REF_DELETING;
+			update->flags |= REF_DELETING;
 		update->lock = lock_ref_sha1_basic(update->refname,
 						   (update->have_old ?
 						    update->old_sha1 :
 						    NULL),
 						   NULL,
-						   flags,
+						   update->flags,
 						   &update->type);
 		if (!update->lock) {
 			ret = (errno == ENOTDIR)
@@ -3827,7 +3826,7 @@ int ref_transaction_commit(struct ref_transaction *transaction,
 	for (i = 0; i < n; i++) {
 		struct ref_update *update = updates[i];
 
-		if (!is_null_sha1(update->new_sha1)) {
+		if (!(update->flags & REF_DELETING)) {
 			if (!update->lock->force_write &&
 			    !hashcmp(update->lock->old_sha1, update->new_sha1)) {
 				unlock_ref(update->lock);
-- 
2.1.4
Previous: Michael HaggertyNext: Michael Haggerty
Message 10 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.