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

[PATCH] Remove the close_ref function.

From
Ronnie Sahlberg <sahlberg@google.com>
Date
Apr 8, 2014, 21:17 UTC
Message-ID
<1396991830-20938-2-git-send-email-sahlberg@google.com>
In-Reply-To
<1396991830-20938-1-git-send-email-sahlberg@google.com>

close_ref() is only called from two codepaths semi-immediately before unlock_ref() is called. Since unlock_ref() will also close the file if it is still open, we can delete close_ref() and let the file become closed during unlock_ref(). This simplifies the refs.c api by removing a redundant function.

Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
---
 builtin/reflog.c |  3 +--
 refs.c           | 11 +----------
 refs.h           |  3 ---
 3 files changed, 2 insertions(+), 15 deletions(-)
diff --git a/builtin/reflog.c b/builtin/reflog.c
index c12a9784..b67fbe6 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -428,8 +428,7 @@ static int expire_reflog(const char *ref, const unsigned char *sha1, int unused,
 		} else if (cmd->updateref &&
 			(write_in_full(lock->lock_fd,
 				sha1_to_hex(cb.last_kept_sha1), 40) != 40 ||
-			 write_str_in_full(lock->lock_fd, "\n") != 1 ||
-			 close_ref(lock) < 0)) {
+			 write_str_in_full(lock->lock_fd, "\n") != 1)) {
 			status |= error("Couldn't write %s",
 				lock->lk->filename);
 			unlink(newlog_path);
diff --git a/refs.c b/refs.c
index 28d5eca..094b047 100644
--- a/refs.c
+++ b/refs.c
@@ -2665,14 +2665,6 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms
 	return 1;
 }
 
-int close_ref(struct ref_lock *lock)
-{
-	if (close_lock_file(lock->lk))
-		return -1;
-	lock->lock_fd = -1;
-	return 0;
-}
-
 int commit_ref(struct ref_lock *lock)
 {
 	if (commit_lock_file(lock->lk))
@@ -2824,8 +2816,7 @@ int write_ref_sha1(struct ref_lock *lock,
 		return -1;
 	}
 	if (write_in_full(lock->lock_fd, sha1_to_hex(sha1), 40) != 40 ||
-	    write_in_full(lock->lock_fd, &term, 1) != 1
-		|| close_ref(lock) < 0) {
+	    write_in_full(lock->lock_fd, &term, 1) != 1) {
 		error("Couldn't write %s", lock->lk->filename);
 		unlock_ref(lock);
 		return -1;
diff --git a/refs.h b/refs.h
index 87a1a79..d8732a5 100644
--- a/refs.h
+++ b/refs.h
@@ -153,9 +153,6 @@ extern struct ref_lock *lock_any_ref_for_update(const char *refname,
 						const unsigned char *old_sha1,
 						int flags, int *type_p);
 
-/** Close the file descriptor owned by a lock and return the status */
-extern int close_ref(struct ref_lock *lock);
-
 /** Close and commit the ref locked by the lock */
 extern int commit_ref(struct ref_lock *lock);
 
-- 
1.9.1.423.g4596e3a
Previous: Ronnie SahlbergNext: Junio C Hamano
Message 2 of 5 in “Remove redundant close_ref function”
  1. Remove redundant close_ref functionRonnie Sahlberg, Apr 8, 2014
  2. Remove the close_ref function.Ronnie Sahlberg, Apr 8, 2014
  3. Junio C HamanoApr 8, 2014
  4. Ronnie SahlbergApr 8, 2014
  5. Junio C HamanoApr 8, 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.