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

[PATCH 1/3] Clean-up lock-ref implementation

From
Junio C Hamano <junkio@cox.net>
Date
Sep 26, 2006, 04:13 UTC
Message-ID
<7vlko7uuxp.fsf_-_@assigned-by-dhcp.cox.net>
In-Reply-To
<7vmz8o1em0.fsf_-_@assigned-by-dhcp.cox.net>

This drops "mustexist" parameter lock_ref_sha1() and lock_any_ref_forupdate() functions take. Existing callers were always passing 0.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 * A bit of clean-up before the real changes...
 builtin-update-ref.c |    2 +-
 fetch.c              |    2 +-
 refs.c               |   20 +++++++++-----------
 refs.h               |    4 ++--
 4 files changed, 13 insertions(+), 15 deletions(-)
diff --git a/builtin-update-ref.c b/builtin-update-ref.c
index 90a3da5..ab52833 100644
--- a/builtin-update-ref.c
+++ b/builtin-update-ref.c
@@ -48,7 +48,7 @@ int cmd_update_ref(int argc, const char 
 	if (oldval && get_sha1(oldval, oldsha1))
 		die("%s: not a valid old SHA1", oldval);
 
-	lock = lock_any_ref_for_update(refname, oldval ? oldsha1 : NULL, 0);
+	lock = lock_any_ref_for_update(refname, oldval ? oldsha1 : NULL);
 	if (!lock)
 		return 1;
 	if (write_ref_sha1(lock, sha1, msg) < 0)
diff --git a/fetch.c b/fetch.c
index 34df8d3..74585c4 100644
--- a/fetch.c
+++ b/fetch.c
@@ -266,7 +266,7 @@ int pull(int targets, char **target, con
 		if (!write_ref || !write_ref[i])
 			continue;
 
-		lock[i] = lock_ref_sha1(write_ref[i], NULL, 0);
+		lock[i] = lock_ref_sha1(write_ref[i], NULL);
 		if (!lock[i]) {
 			error("Can't lock ref %s", write_ref[i]);
 			goto unlock_and_fail;
diff --git a/refs.c b/refs.c
index 5e65314..b4f6d4f 100644
--- a/refs.c
+++ b/refs.c
@@ -264,12 +264,11 @@ int check_ref_format(const char *ref)
 	}
 }
 
-static struct ref_lock *verify_lock(struct ref_lock *lock,
-	const unsigned char *old_sha1, int mustexist)
+static struct ref_lock *verify_lock(struct ref_lock *lock, const unsigned char *old_sha1)
 {
 	char buf[40];
 	int nr, fd = open(lock->ref_file, O_RDONLY);
-	if (fd < 0 && (mustexist || errno != ENOENT)) {
+	if (fd < 0 && errno != ENOENT) {
 		error("Can't verify ref %s", lock->ref_file);
 		unlock_ref(lock);
 		return NULL;
@@ -292,11 +291,12 @@ static struct ref_lock *verify_lock(stru
 
 static struct ref_lock *lock_ref_sha1_basic(const char *path,
 	int plen,
-	const unsigned char *old_sha1, int mustexist)
+	const unsigned char *old_sha1)
 {
 	const char *orig_path = path;
 	struct ref_lock *lock;
 	struct stat st;
+	int mustexist = 0;
 
 	lock = xcalloc(1, sizeof(struct ref_lock));
 	lock->lock_fd = -1;
@@ -321,23 +321,21 @@ static struct ref_lock *lock_ref_sha1_ba
 		die("unable to create directory for %s", lock->ref_file);
 	lock->lock_fd = hold_lock_file_for_update(lock->lk, lock->ref_file, 1);
 
-	return old_sha1 ? verify_lock(lock, old_sha1, mustexist) : lock;
+	return old_sha1 ? verify_lock(lock, old_sha1) : lock;
 }
 
-struct ref_lock *lock_ref_sha1(const char *ref,
-	const unsigned char *old_sha1, int mustexist)
+struct ref_lock *lock_ref_sha1(const char *ref, const unsigned char *old_sha1)
 {
 	if (check_ref_format(ref))
 		return NULL;
 	return lock_ref_sha1_basic(git_path("refs/%s", ref),
-		5 + strlen(ref), old_sha1, mustexist);
+		5 + strlen(ref), old_sha1);
 }
 
-struct ref_lock *lock_any_ref_for_update(const char *ref,
-	const unsigned char *old_sha1, int mustexist)
+struct ref_lock *lock_any_ref_for_update(const char *ref, const unsigned char *old_sha1)
 {
 	return lock_ref_sha1_basic(git_path("%s", ref),
-		strlen(ref), old_sha1, mustexist);
+		strlen(ref), old_sha1);
 }
 
 void unlock_ref(struct ref_lock *lock)
diff --git a/refs.h b/refs.h
index 553155c..d3bc295 100644
--- a/refs.h
+++ b/refs.h
@@ -24,10 +24,10 @@ extern int for_each_remote_ref(int (*fn)
 extern int get_ref_sha1(const char *ref, unsigned char *sha1);
 
 /** Locks a "refs/" ref returning the lock on success and NULL on failure. **/
-extern struct ref_lock *lock_ref_sha1(const char *ref, const unsigned char *old_sha1, int mustexist);
+extern struct ref_lock *lock_ref_sha1(const char *ref, const unsigned char *old_sha1);
 
 /** Locks any ref (for 'HEAD' type refs). */
-extern struct ref_lock *lock_any_ref_for_update(const char *ref, const unsigned char *old_sha1, int mustexist);
+extern struct ref_lock *lock_any_ref_for_update(const char *ref, const unsigned char *old_sha1);
 
 /** Release any lock taken but not written. **/
 extern void unlock_ref(struct ref_lock *lock);
-- 
1.4.2.1.g7a39b
Previous: Junio C HamanoNext: Junio C Hamano
Message 15 of 19 in “Remove branch by putting a null sha1 into the ref file.”
  1. Remove branch by putting a null sha1 into the ref file.Christian Couder, Sep 18, 2006
  2. Junio C HamanoSep 18, 2006
  3. Linus TorvaldsSep 18, 2006
  4. Junio C HamanoSep 18, 2006
  5. Christian CouderSep 20, 2006
  6. Junio C HamanoSep 22, 2006
  7. Christian CouderSep 23, 2006
  8. Junio C HamanoSep 23, 2006
  9. Christian CouderSep 23, 2006
  10. Junio C HamanoSep 23, 2006
  11. Christian CouderSep 24, 2006
  12. On ref lockingJunio C Hamano, Sep 25, 2006
  13. Daniel BarkalowSep 25, 2006
  14. Junio C HamanoSep 26, 2006
  15. 1/3 Clean-up lock-ref implementationJunio C Hamano, Sep 26, 2006
  16. 2/3 update-ref: -d flag and ref creation safety.Junio C Hamano, Sep 26, 2006
  17. 3/3 update a few Porcelain-ish for ref lock safety.Junio C Hamano, Sep 26, 2006
  18. Andy WhitcroftSep 26, 2006
  19. Junio C HamanoSep 27, 2006

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.