Skip to content

Commit ac651c4

Browse files
Merge af/codex/pack-bytes into codex
Integrate the current af/codex/pack-bytes topic into the internally distributed codex branch. Codex-Integration: af/codex/pack-bytes@9abdcdc650f32a4b03c31d0595e0b29892749574
2 parents 0797db5 + 9abdcdc commit ac651c4

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

builtin/pack-objects.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,7 @@ static void write_pack_file(void)
13371337
uint32_t nr_remaining = nr_result;
13381338
time_t last_mtime = 0;
13391339
struct object_entry **write_order;
1340+
off_t bytes_written = 0;
13401341

13411342
if (progress > pack_to_stdout)
13421343
progress_state = start_progress(the_repository,
@@ -1347,6 +1348,7 @@ static void write_pack_file(void)
13471348
do {
13481349
unsigned char hash[GIT_MAX_RAWSZ];
13491350
char *pack_tmp_name = NULL;
1351+
off_t pack_bytes;
13501352

13511353
if (pack_to_stdout) {
13521354
/*
@@ -1389,6 +1391,8 @@ static void write_pack_file(void)
13891391
display_progress(progress_state, written);
13901392
}
13911393

1394+
pack_bytes = hashfile_total(f) +
1395+
the_repository->hash_algo->rawsz;
13921396
if (pack_to_stdout) {
13931397
/*
13941398
* We never fsync when writing to stdout since we may
@@ -1419,6 +1423,7 @@ static void write_pack_file(void)
14191423
write_bitmap_index = 0;
14201424
}
14211425
}
1426+
bytes_written += pack_bytes;
14221427

14231428
if (!pack_to_stdout) {
14241429
struct stat st;
@@ -1510,6 +1515,8 @@ static void write_pack_file(void)
15101515
written, nr_result);
15111516
trace2_data_intmax("pack-objects", the_repository,
15121517
"write_pack_file/wrote", nr_result);
1518+
trace2_data_intmax("pack-objects", the_repository,
1519+
"write_pack_file/wrote_bytes", bytes_written);
15131520
}
15141521

15151522
static int no_try_delta(const char *path)

t/t5300-pack-object.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,30 @@ test_expect_success 'setup' '
3333
} >expect
3434
'
3535

36+
test_expect_success 'pack-object traces bytes written to stdout' '
37+
test_when_finished "rm -f pack.trace pack.pack" &&
38+
GIT_TRACE2_EVENT="$PWD/pack.trace" \
39+
git pack-objects --quiet --revs --stdout >pack.pack <<-EOF &&
40+
$commit
41+
EOF
42+
bytes=$(test_file_size pack.pack) &&
43+
test_grep "\"key\":\"write_pack_file/wrote_bytes\",\"value\":\"$bytes\"" pack.trace
44+
'
45+
46+
test_expect_success 'pack-object traces bytes written to split pack files' '
47+
test_when_finished "rm -f split.trace traced-pack-*" &&
48+
GIT_TRACE2_EVENT="$PWD/split.trace" \
49+
git -c pack.packSizeLimit=3m pack-objects --quiet traced-pack <obj-list &&
50+
test 2 = $(ls traced-pack-*.pack | wc -l) &&
51+
bytes=0 &&
52+
for pack in traced-pack-*.pack
53+
do
54+
pack_size=$(test_file_size "$pack") &&
55+
bytes=$((bytes + pack_size)) || return 1
56+
done &&
57+
test_grep "\"key\":\"write_pack_file/wrote_bytes\",\"value\":\"$bytes\"" split.trace
58+
'
59+
3660
test_expect_success 'setup pack-object <stdin' '
3761
git init pack-object-stdin &&
3862
test_commit -C pack-object-stdin one &&

0 commit comments

Comments
 (0)