git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Martin Ågren" <martin.agren@gmail.com>
To: git@vger.kernel.org
Cc: Alban Gruin <alban.gruin@gmail.com>, Derrick Stolee <stolee@gmail.com>
Subject: [PATCH 3/5] midx: don't peek into `struct lock_file`
Date: Tue,  5 Jan 2021 20:23:48 +0100	[thread overview]
Message-ID: <6dfb457b2a3187546eb4b4d90679348f2051a57d.1609874026.git.martin.agren@gmail.com> (raw)
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.

The two functions we're calling here double-check that the tempfile is
indeed "active", which is arguably overkill considering how we took the
lock on the line immediately above. More importantly, this future-proofs
us against, e.g., other code appearing between these two lines or the
lock file and/or tempfile internals changing.

Signed-off-by: Martin Ågren <martin.agren@gmail.com>
---
 midx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/midx.c b/midx.c
index 79c282b070..9d41b9c271 100644
--- a/midx.c
+++ b/midx.c
@@ -918,7 +918,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
 					(pack_name_concat_len % MIDX_CHUNK_ALIGNMENT);
 
 	hold_lock_file_for_update(&lk, midx_name, LOCK_DIE_ON_ERROR);
-	f = hashfd(lk.tempfile->fd, lk.tempfile->filename.buf);
+	f = hashfd(get_lock_file_fd(&lk), get_lock_file_path(&lk));
 	FREE_AND_NULL(midx_name);
 
 	if (packs.m)
-- 
2.30.0


  parent reply	other threads:[~2021-01-05 19:26 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-05 19:23 [PATCH 0/5] avoid peeking into `struct lock_file` Martin Ågren
2021-01-05 19:23 ` [PATCH 1/5] builtin/gc: don't peek " Martin Ågren
2021-01-05 19:23 ` [PATCH 2/5] commit-graph: " Martin Ågren
2021-01-05 19:23 ` Martin Ågren [this message]
2021-01-05 19:23 ` [PATCH 4/5] refs/files-backend: " Martin Ågren
2021-01-05 19:23 ` [PATCH 5/5] read-cache: try not to peek into `struct {lock_,temp}file` Martin Ågren
2021-01-06  2:16 ` [PATCH 0/5] avoid peeking into `struct lock_file` Derrick Stolee
2021-01-06 11:55   ` Junio C Hamano
2021-01-06 22:36     ` Junio C Hamano
2021-01-07  2:08       ` Derrick Stolee
2021-01-07  7:55         ` Martin Ågren
2021-01-07  8:19           ` Junio C Hamano
2021-01-07 18:17             ` Martin Ågren

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6dfb457b2a3187546eb4b4d90679348f2051a57d.1609874026.git.martin.agren@gmail.com \
    --to=martin.agren@gmail.com \
    --cc=alban.gruin@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=stolee@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).