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

[PATCH 4/5] refs/files-backend: don't peek into `struct lock_file`

From
MÅMartin Ågren <martin.agren@gmail.com>
Date
Jan 5, 2021, 19:23 UTC
Message-ID
<a3510f3969d26d26ade136b27a7b9dd1d9cc2976.1609874026.git.martin.agren@gmail.com>
In-Reply-To
<cover.1609874026.git.martin.agren@gmail.com>

Similar to the previous commits, avoid peeking into the `struct lock_file`. Use the lock file API instead. Note how we obtain the path to the lock file if `fdopen_lock_file()` failed and that this is not a problem: as documented in lockfile.h, failure to "fdopen" does not roll back the lock file and we're free to, e.g., query it for its path.

Signed-off-by: Martin Ågren <martin.agren@gmail.com>
---
 refs/files-backend.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 04e85e7002..4fdc68810b 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -1824,12 +1824,12 @@ static int create_symref_locked(struct files_ref_store *refs,
 
 	if (!fdopen_lock_file(&lock->lk, "w"))
 		return error("unable to fdopen %s: %s",
-			     lock->lk.tempfile->filename.buf, strerror(errno));
+			     get_lock_file_path(&lock->lk), strerror(errno));
 
 	update_symref_reflog(refs, lock, refname, target, logmsg);
 
 	/* no error check; commit_ref will check ferror */
-	fprintf(lock->lk.tempfile->fp, "ref: %s\n", target);
+	fprintf(get_lock_file_fp(&lock->lk), "ref: %s\n", target);
 	if (commit_ref(lock) < 0)
 		return error("unable to write symref for %s: %s", refname,
 			     strerror(errno));
-- 
2.30.0
Previous: Martin ÅgrenNext: Martin Ågren
Message 2 of 13 in “avoid peeking into `struct lock_file`”
  1. 0/5 avoid peeking into `struct lock_file`Martin Ågren, Jan 5, 2021
  2. 4/5 refs/files-backend: don't peek into `struct lock_file`Martin Ågren, Jan 5, 2021
  3. 3/5 midx: don't peek into `struct lock_file`Martin Ågren, Jan 5, 2021
  4. 2/5 commit-graph: don't peek into `struct lock_file`Martin Ågren, Jan 5, 2021
  5. 1/5 builtin/gc: don't peek into `struct lock_file`Martin Ågren, Jan 5, 2021
  6. 5/5 read-cache: try not to peek into `struct {lock_,temp}file`Martin Ågren, Jan 5, 2021
  7. Derrick StoleeJan 6, 2021
  8. Junio C HamanoJan 6, 2021
  9. Junio C HamanoJan 6, 2021
  10. Derrick StoleeJan 7, 2021
  11. Martin ÅgrenJan 7, 2021
  12. Junio C HamanoJan 7, 2021
  13. Martin ÅgrenJan 7, 2021

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.