diff options
| author | shejialuo <shejialuo@gmail.com> | 2025-05-14 23:50:42 +0800 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2025-05-14 12:32:59 -0700 |
| commit | 86ddd588f24acf3960489dccb8aed82dc570796b (patch) | |
| tree | ba5495abfec8ef879652b234478004cbba58a9cc /refs | |
| parent | a0dee3f74b4f42076b7c23ca6d9aca61ed064e82 (diff) | |
| download | git-86ddd588f24acf3960489dccb8aed82dc570796b.tar.gz | |
packed-backend: mmap large "packed-refs" file during fsck
During fsck, we use "strbuf_read" to read the content of "packed-refs"
without using mmap mechanism. This is a bad practice which would consume
more memory than using mmap mechanism. Besides, as all code paths in
"packed-backend.c" use this way, we should make "fsck" align with the
current codebase.
As we have introduced the helper function "allocate_snapshot_buffer", we
can simply use this function to use mmap mechanism.
Suggested-by: Jeff King <peff@peff.net>
Suggested-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: shejialuo <shejialuo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs')
| -rw-r--r-- | refs/packed-backend.c | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/refs/packed-backend.c b/refs/packed-backend.c index 1da44a3d6d..7fd73a0e6d 100644 --- a/refs/packed-backend.c +++ b/refs/packed-backend.c @@ -2068,7 +2068,7 @@ static int packed_fsck(struct ref_store *ref_store, { struct packed_ref_store *refs = packed_downcast(ref_store, REF_STORE_READ, "fsck"); - struct strbuf packed_ref_content = STRBUF_INIT; + struct snapshot snapshot = { 0 }; unsigned int sorted = 0; struct stat st; int ret = 0; @@ -2112,7 +2112,7 @@ static int packed_fsck(struct ref_store *ref_store, goto cleanup; } - if (!st.st_size) { + if (!allocate_snapshot_buffer(&snapshot, fd, &st)) { struct fsck_ref_report report = { 0 }; report.path = "packed-refs"; ret = fsck_report_ref(o, &report, @@ -2121,21 +2121,16 @@ static int packed_fsck(struct ref_store *ref_store, goto cleanup; } - if (strbuf_read(&packed_ref_content, fd, 0) < 0) { - ret = error_errno(_("unable to read '%s'"), refs->path); - goto cleanup; - } - - ret = packed_fsck_ref_content(o, ref_store, &sorted, packed_ref_content.buf, - packed_ref_content.buf + packed_ref_content.len); + ret = packed_fsck_ref_content(o, ref_store, &sorted, snapshot.start, + snapshot.eof); if (!ret && sorted) - ret = packed_fsck_ref_sorted(o, ref_store, packed_ref_content.buf, - packed_ref_content.buf + packed_ref_content.len); + ret = packed_fsck_ref_sorted(o, ref_store, snapshot.start, + snapshot.eof); cleanup: if (fd >= 0) close(fd); - strbuf_release(&packed_ref_content); + clear_snapshot_buffer(&snapshot); return ret; } |
