From a74d159cdadd0a3ebed57c30ee2ad71f1ce922cd Mon Sep 17 00:00:00 2001 From: Friel Date: Sat, 15 Aug 2026 07:15:37 +0000 Subject: [PATCH 1/3] pack-objects: trace bytes written to stdout --- builtin/pack-objects.c | 6 ++++++ t/t5300-pack-object.sh | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 1ec5b6f206366e..f96ad42174fb2f 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -1337,6 +1337,7 @@ static void write_pack_file(void) uint32_t nr_remaining = nr_result; time_t last_mtime = 0; struct object_entry **write_order; + off_t bytes_written = 0; if (progress > pack_to_stdout) progress_state = start_progress(the_repository, @@ -1390,6 +1391,8 @@ static void write_pack_file(void) } if (pack_to_stdout) { + bytes_written += hashfile_total(f) + + the_repository->hash_algo->rawsz; /* * We never fsync when writing to stdout since we may * not be writing to an actual pack file. For instance, @@ -1510,6 +1513,9 @@ static void write_pack_file(void) written, nr_result); trace2_data_intmax("pack-objects", the_repository, "write_pack_file/wrote", nr_result); + if (pack_to_stdout) + trace2_data_intmax("pack-objects", the_repository, + "written/bytes", bytes_written); } static int no_try_delta(const char *path) diff --git a/t/t5300-pack-object.sh b/t/t5300-pack-object.sh index 9dabb3615aff56..101729f1f6a2a7 100755 --- a/t/t5300-pack-object.sh +++ b/t/t5300-pack-object.sh @@ -33,6 +33,16 @@ test_expect_success 'setup' ' } >expect ' +test_expect_success 'pack-object traces bytes written to stdout' ' + test_when_finished "rm -f pack.trace pack.pack" && + GIT_TRACE2_EVENT="$PWD/pack.trace" \ + git pack-objects --quiet --revs --stdout >pack.pack <<-EOF && + $commit + EOF + bytes=$(test_file_size pack.pack) && + test_grep "\"key\":\"written/bytes\",\"value\":\"$bytes\"" pack.trace +' + test_expect_success 'setup pack-object Date: Mon, 17 Aug 2026 03:54:18 +0000 Subject: [PATCH 2/3] pack-objects: trace bytes for all pack output --- builtin/pack-objects.c | 10 +++++----- t/t5300-pack-object.sh | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index f96ad42174fb2f..01a11da860c01b 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -1390,9 +1390,10 @@ static void write_pack_file(void) display_progress(progress_state, written); } + /* Every finalization path appends the pack checksum. */ + bytes_written += hashfile_total(f) + + the_repository->hash_algo->rawsz; if (pack_to_stdout) { - bytes_written += hashfile_total(f) + - the_repository->hash_algo->rawsz; /* * We never fsync when writing to stdout since we may * not be writing to an actual pack file. For instance, @@ -1513,9 +1514,8 @@ static void write_pack_file(void) written, nr_result); trace2_data_intmax("pack-objects", the_repository, "write_pack_file/wrote", nr_result); - if (pack_to_stdout) - trace2_data_intmax("pack-objects", the_repository, - "written/bytes", bytes_written); + trace2_data_intmax("pack-objects", the_repository, + "write_pack_file/wrote_bytes", bytes_written); } static int no_try_delta(const char *path) diff --git a/t/t5300-pack-object.sh b/t/t5300-pack-object.sh index 101729f1f6a2a7..aac139e6a096eb 100755 --- a/t/t5300-pack-object.sh +++ b/t/t5300-pack-object.sh @@ -40,7 +40,21 @@ test_expect_success 'pack-object traces bytes written to stdout' ' $commit EOF bytes=$(test_file_size pack.pack) && - test_grep "\"key\":\"written/bytes\",\"value\":\"$bytes\"" pack.trace + test_grep "\"key\":\"write_pack_file/wrote_bytes\",\"value\":\"$bytes\"" pack.trace +' + +test_expect_success 'pack-object traces bytes written to split pack files' ' + test_when_finished "rm -f split.trace traced-pack-*" && + GIT_TRACE2_EVENT="$PWD/split.trace" \ + git -c pack.packSizeLimit=3m pack-objects --quiet traced-pack Date: Mon, 17 Aug 2026 03:57:02 +0000 Subject: [PATCH 3/3] pack-objects: accumulate bytes after finalization --- builtin/pack-objects.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 01a11da860c01b..bbf1adb437dd8d 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -1348,6 +1348,7 @@ static void write_pack_file(void) do { unsigned char hash[GIT_MAX_RAWSZ]; char *pack_tmp_name = NULL; + off_t pack_bytes; if (pack_to_stdout) { /* @@ -1390,8 +1391,7 @@ static void write_pack_file(void) display_progress(progress_state, written); } - /* Every finalization path appends the pack checksum. */ - bytes_written += hashfile_total(f) + + pack_bytes = hashfile_total(f) + the_repository->hash_algo->rawsz; if (pack_to_stdout) { /* @@ -1423,6 +1423,7 @@ static void write_pack_file(void) write_bitmap_index = 0; } } + bytes_written += pack_bytes; if (!pack_to_stdout) { struct stat st;