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

[PATCH v3 3/7] lock_ref_sha1_basic(): do not set force_write for missing references

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Mar 3, 2015, 11:43 UTC
Message-ID
<1425382997-24984-4-git-send-email-mhagger@alum.mit.edu>
In-Reply-To
<1425382997-24984-1-git-send-email-mhagger@alum.mit.edu>

If a reference is missing, its SHA-1 will be null_sha1, which can't possibly match a new value that ref_transaction_commit() is trying to update it to. So there is no need to set force_write in this scenario.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
 refs.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/refs.c b/refs.c
index dd30bfa..3ed9ea6 100644
--- a/refs.c
+++ b/refs.c
@@ -2258,7 +2258,6 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
 	int type, lflags;
 	int mustexist = (old_sha1 && !is_null_sha1(old_sha1));
 	int resolve_flags = 0;
-	int missing = 0;
 	int attempts_remaining = 3;
 
 	lock = xcalloc(1, sizeof(struct ref_lock));
@@ -2297,13 +2296,13 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
 			orig_refname, strerror(errno));
 		goto error_return;
 	}
-	missing = is_null_sha1(lock->old_sha1);
-	/* When the ref did not exist and we are creating it,
-	 * make sure there is no existing ref that is packed
-	 * whose name begins with our refname, nor a ref whose
-	 * name is a proper prefix of our refname.
+	/*
+	 * If the ref did not exist and we are creating it, make sure
+	 * there is no existing packed ref whose name begins with our
+	 * refname, nor a packed ref whose name is a proper prefix of
+	 * our refname.
 	 */
-	if (missing &&
+	if (is_null_sha1(lock->old_sha1) &&
 	     !is_refname_available(refname, skip, get_packed_refs(&ref_cache))) {
 		last_errno = ENOTDIR;
 		goto error_return;
@@ -2319,8 +2318,6 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
 	lock->ref_name = xstrdup(refname);
 	lock->orig_ref_name = xstrdup(orig_refname);
 	ref_file = git_path("%s", refname);
-	if (missing)
-		lock->force_write = 1;
 	if ((flags & REF_NODEREF) && (type & REF_ISSYMREF))
 		lock->force_write = 1;
 
-- 
2.1.4
Previous: Michael HaggertyNext: Michael Haggerty
Message 4 of 9 in “Fix some problems with reflog expiration”
  1. 0/7 Fix some problems with reflog expirationMichael Haggerty, Mar 3, 2015
  2. 1/7 write_ref_sha1(): remove check for lock == NULLMichael Haggerty, Mar 3, 2015
  3. 2/7 write_ref_sha1(): Move write elision test to callersMichael Haggerty, Mar 3, 2015
  4. 3/7 lock_ref_sha1_basic(): do not set force_write for missing referencesMichael Haggerty, Mar 3, 2015
  5. 4/7 struct ref_lock: delete the force_write memberMichael Haggerty, Mar 3, 2015
  6. 5/7 reflog: improve and update documentationMichael Haggerty, Mar 3, 2015
  7. 6/7 reflog_expire(): ignore --updateref for symbolic referencesMichael Haggerty, Mar 3, 2015
  8. 7/7 reflog_expire(): never update a reference to null_sha1Michael Haggerty, Mar 3, 2015
  9. Stefan BellerMar 5, 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.