Skip to content

Commit 7be97e4

Browse files
derrickstoleedscho
authored andcommitted
pack-objects: refactor path-walk delta phase
Previously, the --path-walk option to 'git pack-objects' would compute deltas inline with the path-walk logic. This would make the progress indicator look like it is taking a long time to enumerate objects, and then very quickly computed deltas. Instead of computing deltas on each region of objects organized by tree, store a list of regions corresponding to these groups. These can later be pulled from the list for delta compression before doing the "global" delta search. This presents a new progress indicator that can be used in tests to verify that this stage is happening. The current implementation is not integrated with threads, but could be done in a future update. Since we do not attempt to sort objects by size until after exploring all trees, we can remove the previous change to t5530 due to a different error message appearing first. Signed-off-by: Derrick Stolee <[email protected]>
1 parent 99a82ac commit 7be97e4

File tree

4 files changed

+74
-33
lines changed

4 files changed

+74
-33
lines changed

builtin/pack-objects.c

Lines changed: 56 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3192,6 +3192,50 @@ static int should_attempt_deltas(struct object_entry *entry)
31923192
return 1;
31933193
}
31943194

3195+
static void find_deltas_for_region(struct object_entry *list UNUSED,
3196+
struct packing_region *region,
3197+
unsigned int *processed)
3198+
{
3199+
struct object_entry **delta_list;
3200+
uint32_t delta_list_nr = 0;
3201+
3202+
ALLOC_ARRAY(delta_list, region->nr);
3203+
for (uint32_t i = 0; i < region->nr; i++) {
3204+
struct object_entry *entry = to_pack.objects + region->start + i;
3205+
if (should_attempt_deltas(entry))
3206+
delta_list[delta_list_nr++] = entry;
3207+
}
3208+
3209+
QSORT(delta_list, delta_list_nr, type_size_sort);
3210+
find_deltas(delta_list, &delta_list_nr, window, depth, processed);
3211+
free(delta_list);
3212+
}
3213+
3214+
static void find_deltas_by_region(struct object_entry *list,
3215+
struct packing_region *regions,
3216+
uint32_t start, uint32_t nr)
3217+
{
3218+
unsigned int processed = 0;
3219+
uint32_t progress_nr;
3220+
3221+
if (!nr)
3222+
return;
3223+
3224+
progress_nr = regions[nr - 1].start + regions[nr - 1].nr;
3225+
3226+
if (progress)
3227+
progress_state = start_progress(_("Compressing objects by path"),
3228+
progress_nr);
3229+
3230+
while (nr--)
3231+
find_deltas_for_region(list,
3232+
&regions[start++],
3233+
&processed);
3234+
3235+
display_progress(progress_state, progress_nr);
3236+
stop_progress(&progress_state);
3237+
}
3238+
31953239
static void prepare_pack(int window, int depth)
31963240
{
31973241
struct object_entry **delta_list;
@@ -3216,6 +3260,10 @@ static void prepare_pack(int window, int depth)
32163260
if (!to_pack.nr_objects || !window || !depth)
32173261
return;
32183262

3263+
if (path_walk)
3264+
find_deltas_by_region(to_pack.objects, to_pack.regions,
3265+
0, to_pack.nr_regions);
3266+
32193267
ALLOC_ARRAY(delta_list, to_pack.nr_objects);
32203268
nr_deltas = n = 0;
32213269

@@ -4156,10 +4204,8 @@ static int add_objects_by_path(const char *path,
41564204
enum object_type type,
41574205
void *data)
41584206
{
4159-
struct object_entry **delta_list;
41604207
size_t oe_start = to_pack.nr_objects;
41614208
size_t oe_end;
4162-
unsigned int sub_list_size;
41634209
unsigned int *processed = data;
41644210

41654211
/*
@@ -4192,32 +4238,17 @@ static int add_objects_by_path(const char *path,
41924238
if (oe_end == oe_start || !window)
41934239
return 0;
41944240

4195-
sub_list_size = 0;
4196-
ALLOC_ARRAY(delta_list, oe_end - oe_start);
4241+
ALLOC_GROW(to_pack.regions,
4242+
to_pack.nr_regions + 1,
4243+
to_pack.nr_regions_alloc);
41974244

4198-
for (size_t i = 0; i < oe_end - oe_start; i++) {
4199-
struct object_entry *entry = to_pack.objects + oe_start + i;
4245+
to_pack.regions[to_pack.nr_regions].start = oe_start;
4246+
to_pack.regions[to_pack.nr_regions].nr = oe_end - oe_start;
4247+
to_pack.nr_regions++;
42004248

4201-
if (!should_attempt_deltas(entry))
4202-
continue;
4249+
*processed += oids->nr;
4250+
display_progress(progress_state, *processed);
42034251

4204-
delta_list[sub_list_size++] = entry;
4205-
}
4206-
4207-
/*
4208-
* Find delta bases among this list of objects that all match the same
4209-
* path. This causes the delta compression to be interleaved in the
4210-
* object walk, which can lead to confusing progress indicators. This is
4211-
* also incompatible with threaded delta calculations. In the future,
4212-
* consider creating a list of regions in the full to_pack.objects array
4213-
* that could be picked up by the threaded delta computation.
4214-
*/
4215-
if (sub_list_size && window) {
4216-
QSORT(delta_list, sub_list_size, type_size_sort);
4217-
find_deltas(delta_list, &sub_list_size, window, depth, processed);
4218-
}
4219-
4220-
free(delta_list);
42214252
return 0;
42224253
}
42234254

pack-objects.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,23 @@ struct object_entry {
119119
unsigned ext_base:1; /* delta_idx points outside packlist */
120120
};
121121

122+
/**
123+
* A packing region is a section of the packing_data.objects array
124+
* as given by a starting index and a number of elements.
125+
*/
126+
struct packing_region {
127+
uint32_t start;
128+
uint32_t nr;
129+
};
130+
122131
struct packing_data {
123132
struct repository *repo;
124133
struct object_entry *objects;
125134
uint32_t nr_objects, nr_alloc;
126135

136+
struct packing_region *regions;
137+
uint32_t nr_regions, nr_regions_alloc;
138+
127139
int32_t *index;
128140
uint32_t index_size;
129141

t/t5300-pack-object.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,9 @@ test_expect_success '--full-name-hash and --write-bitmap-index are incompatible'
689689
# Basic "repack everything" test
690690
test_expect_success '--path-walk pack everything' '
691691
git -C server rev-parse HEAD >in &&
692-
git -C server pack-objects --stdout --revs --path-walk <in >out.pack &&
692+
GIT_PROGRESS_DELAY=0 git -C server pack-objects \
693+
--stdout --revs --path-walk --progress <in >out.pack 2>err &&
694+
grep "Compressing objects by path" err &&
693695
git -C server index-pack --stdin <out.pack
694696
'
695697

@@ -699,7 +701,9 @@ test_expect_success '--path-walk thin pack' '
699701
$(git -C server rev-parse HEAD)
700702
^$(git -C server rev-parse HEAD~2)
701703
EOF
702-
git -C server pack-objects --thin --stdout --revs --path-walk <in >out.pack &&
704+
GIT_PROGRESS_DELAY=0 git -C server pack-objects \
705+
--thin --stdout --revs --path-walk --progress <in >out.pack 2>err &&
706+
grep "Compressing objects by path" err &&
703707
git -C server index-pack --fix-thin --stdin <out.pack
704708
'
705709

t/t5530-upload-pack-error.sh

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ test_expect_success 'upload-pack fails due to error in pack-objects packing' '
3434
hexsz=$(test_oid hexsz) &&
3535
printf "%04xwant %s\n00000009done\n0000" \
3636
$(($hexsz + 10)) $head >input &&
37-
38-
# The current implementation of path-walk causes a different
39-
# error message. This will be changed by a future refactoring.
40-
GIT_TEST_PACK_PATH_WALK=0 &&
41-
export GIT_TEST_PACK_PATH_WALK &&
42-
4337
test_must_fail git upload-pack . <input >/dev/null 2>output.err &&
4438
test_grep "unable to read" output.err &&
4539
test_grep "pack-objects died" output.err

0 commit comments

Comments
 (0)