From: Junio C Hamano <gitster@pobox.com>
To: Eric Wong <e@80x24.org>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 2/2] packfile: replace lseek+read with pread
Date: Thu, 26 Dec 2019 10:23:01 -0800 [thread overview]
Message-ID: <xmqqzhffkku2.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <20191226104220.27325-3-e@80x24.org> (Eric Wong's message of "Thu, 26 Dec 2019 10:42:20 +0000")
Eric Wong <e@80x24.org> writes:
> We already have pread emulation for portability, so there's
> there's no reason to make two syscalls where one suffices.
>
> Furthermore, readers of the packfile will be using mmap
> (or pread to emulate mmap), anyways, so the file description
> offset does not matter in this case.
s/description/descriptor/ probably.
After seeking to the packfile trailer and reading the pack id hash
using lseek+read, this helper function does not read from the file
descriptor, and the sole caller of it closes the file descriptor
immediately after it returns, which means the read file offset after
reading the packfile trailer does not matter.
So this conversion is correct. Thanks for a careful analysis.
Will queue both patches.
> Signed-off-by: Eric Wong <e@80x24.org>
> ---
> packfile.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/packfile.c b/packfile.c
> index 1821cb7a3d..7e7c04e4d8 100644
> --- a/packfile.c
> +++ b/packfile.c
> @@ -576,9 +576,8 @@ static int open_packed_git_1(struct packed_git *p)
> " while index indicates %"PRIu32" objects",
> p->pack_name, ntohl(hdr.hdr_entries),
> p->num_objects);
> - if (lseek(p->pack_fd, p->pack_size - hashsz, SEEK_SET) == -1)
> - return error("end of packfile %s is unavailable", p->pack_name);
> - read_result = read_in_full(p->pack_fd, hash, hashsz);
> + read_result = pread_in_full(p->pack_fd, hash, hashsz,
> + p->pack_size - hashsz);
> if (read_result < 0)
> return error_errno("error reading from %s", p->pack_name);
> if (read_result != hashsz)
next prev parent reply other threads:[~2019-12-26 18:23 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-26 10:42 [PATCH 0/2] packfile: small syscall reductions Eric Wong
2019-12-26 10:42 ` [PATCH 1/2] packfile: remove redundant fcntl F_GETFD/F_SETFD Eric Wong
2019-12-26 10:42 ` [PATCH 2/2] packfile: replace lseek+read with pread Eric Wong
2019-12-26 18:23 ` Junio C Hamano [this message]
2019-12-26 18:32 ` Junio C Hamano
2019-12-26 18:59 ` Eric Wong
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=xmqqzhffkku2.fsf@gitster-ct.c.googlers.com \
--to=gitster@pobox.com \
--cc=e@80x24.org \
--cc=git@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.