Skip to content

Commit 556f025

Browse files
committed
Merge branch 'ew/packfile-syscall-optim'
Code cleanup. * ew/packfile-syscall-optim: packfile: replace lseek+read with pread packfile: remove redundant fcntl F_GETFD/F_SETFD
2 parents 8679ef2 + 4e61b22 commit 556f025

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

packfile.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,6 @@ static int open_packed_git_1(struct packed_git *p)
510510
struct pack_header hdr;
511511
unsigned char hash[GIT_MAX_RAWSZ];
512512
unsigned char *idx_hash;
513-
long fd_flag;
514513
ssize_t read_result;
515514
const unsigned hashsz = the_hash_algo->rawsz;
516515

@@ -554,16 +553,6 @@ static int open_packed_git_1(struct packed_git *p)
554553
} else if (p->pack_size != st.st_size)
555554
return error("packfile %s size changed", p->pack_name);
556555

557-
/* We leave these file descriptors open with sliding mmap;
558-
* there is no point keeping them open across exec(), though.
559-
*/
560-
fd_flag = fcntl(p->pack_fd, F_GETFD, 0);
561-
if (fd_flag < 0)
562-
return error("cannot determine file descriptor flags");
563-
fd_flag |= FD_CLOEXEC;
564-
if (fcntl(p->pack_fd, F_SETFD, fd_flag) == -1)
565-
return error("cannot set FD_CLOEXEC");
566-
567556
/* Verify we recognize this pack file format. */
568557
read_result = read_in_full(p->pack_fd, &hdr, sizeof(hdr));
569558
if (read_result < 0)
@@ -587,9 +576,8 @@ static int open_packed_git_1(struct packed_git *p)
587576
" while index indicates %"PRIu32" objects",
588577
p->pack_name, ntohl(hdr.hdr_entries),
589578
p->num_objects);
590-
if (lseek(p->pack_fd, p->pack_size - hashsz, SEEK_SET) == -1)
591-
return error("end of packfile %s is unavailable", p->pack_name);
592-
read_result = read_in_full(p->pack_fd, hash, hashsz);
579+
read_result = pread_in_full(p->pack_fd, hash, hashsz,
580+
p->pack_size - hashsz);
593581
if (read_result < 0)
594582
return error_errno("error reading from %s", p->pack_name);
595583
if (read_result != hashsz)

0 commit comments

Comments
 (0)