Skip to content

Commit 87e7307

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 3cc3722 commit 87e7307

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
@@ -3315,6 +3315,50 @@ static int should_attempt_deltas(struct object_entry *entry)
33153315
return 1;
33163316
}
33173317

3318+
static void find_deltas_for_region(struct object_entry *list UNUSED,
3319+
struct packing_region *region,
3320+
unsigned int *processed)
3321+
{
3322+
struct object_entry **delta_list;
3323+
uint32_t delta_list_nr = 0;
3324+
3325+
ALLOC_ARRAY(delta_list, region->nr);
3326+
for (uint32_t i = 0; i < region->nr; i++) {
3327+
struct object_entry *entry = to_pack.objects + region->start + i;
3328+
if (should_attempt_deltas(entry))
3329+
delta_list[delta_list_nr++] = entry;
3330+
}
3331+
3332+
QSORT(delta_list, delta_list_nr, type_size_sort);
3333+
find_deltas(delta_list, &delta_list_nr, window, depth, processed);
3334+
free(delta_list);
3335+
}
3336+
3337+
static void find_deltas_by_region(struct object_entry *list,
3338+
struct packing_region *regions,
3339+
uint32_t start, uint32_t nr)
3340+
{
3341+
unsigned int processed = 0;
3342+
uint32_t progress_nr;
3343+
3344+
if (!nr)
3345+
return;
3346+
3347+
progress_nr = regions[nr - 1].start + regions[nr - 1].nr;
3348+
3349+
if (progress)
3350+
progress_state = start_progress(_("Compressing objects by path"),
3351+
progress_nr);
3352+
3353+
while (nr--)
3354+
find_deltas_for_region(list,
3355+
&regions[start++],
3356+
&processed);
3357+
3358+
display_progress(progress_state, progress_nr);
3359+
stop_progress(&progress_state);
3360+
}
3361+
33183362
static void prepare_pack(int window, int depth)
33193363
{
33203364
struct object_entry **delta_list;
@@ -3339,6 +3383,10 @@ static void prepare_pack(int window, int depth)
33393383
if (!to_pack.nr_objects || !window || !depth)
33403384
return;
33413385

3386+
if (path_walk)
3387+
find_deltas_by_region(to_pack.objects, to_pack.regions,
3388+
0, to_pack.nr_regions);
3389+
33423390
ALLOC_ARRAY(delta_list, to_pack.nr_objects);
33433391
nr_deltas = n = 0;
33443392

@@ -4294,10 +4342,8 @@ static int add_objects_by_path(const char *path,
42944342
enum object_type type,
42954343
void *data)
42964344
{
4297-
struct object_entry **delta_list;
42984345
size_t oe_start = to_pack.nr_objects;
42994346
size_t oe_end;
4300-
unsigned int sub_list_size;
43014347
unsigned int *processed = data;
43024348

43034349
/*
@@ -4330,32 +4376,17 @@ static int add_objects_by_path(const char *path,
43304376
if (oe_end == oe_start || !window)
43314377
return 0;
43324378

4333-
sub_list_size = 0;
4334-
ALLOC_ARRAY(delta_list, oe_end - oe_start);
4379+
ALLOC_GROW(to_pack.regions,
4380+
to_pack.nr_regions + 1,
4381+
to_pack.nr_regions_alloc);
43354382

4336-
for (size_t i = 0; i < oe_end - oe_start; i++) {
4337-
struct object_entry *entry = to_pack.objects + oe_start + i;
4383+
to_pack.regions[to_pack.nr_regions].start = oe_start;
4384+
to_pack.regions[to_pack.nr_regions].nr = oe_end - oe_start;
4385+
to_pack.nr_regions++;
43384386

4339-
if (!should_attempt_deltas(entry))
4340-
continue;
4387+
*processed += oids->nr;
4388+
display_progress(progress_state, *processed);
43414389

4342-
delta_list[sub_list_size++] = entry;
4343-
}
4344-
4345-
/*
4346-
* Find delta bases among this list of objects that all match the same
4347-
* path. This causes the delta compression to be interleaved in the
4348-
* object walk, which can lead to confusing progress indicators. This is
4349-
* also incompatible with threaded delta calculations. In the future,
4350-
* consider creating a list of regions in the full to_pack.objects array
4351-
* that could be picked up by the threaded delta computation.
4352-
*/
4353-
if (sub_list_size && window) {
4354-
QSORT(delta_list, sub_list_size, type_size_sort);
4355-
find_deltas(delta_list, &sub_list_size, window, depth, processed);
4356-
}
4357-
4358-
free(delta_list);
43594390
return 0;
43604391
}
43614392

pack-objects.h

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

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

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

t/t5300-pack-object.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,9 @@ test_expect_success '--name-hash-version=2 and --write-bitmap-index are incompat
726726
# Basic "repack everything" test
727727
test_expect_success '--path-walk pack everything' '
728728
git -C server rev-parse HEAD >in &&
729-
git -C server pack-objects --stdout --revs --path-walk <in >out.pack &&
729+
GIT_PROGRESS_DELAY=0 git -C server pack-objects \
730+
--stdout --revs --path-walk --progress <in >out.pack 2>err &&
731+
grep "Compressing objects by path" err &&
730732
git -C server index-pack --stdin <out.pack
731733
'
732734

@@ -736,7 +738,9 @@ test_expect_success '--path-walk thin pack' '
736738
$(git -C server rev-parse HEAD)
737739
^$(git -C server rev-parse HEAD~2)
738740
EOF
739-
git -C server pack-objects --thin --stdout --revs --path-walk <in >out.pack &&
741+
GIT_PROGRESS_DELAY=0 git -C server pack-objects \
742+
--thin --stdout --revs --path-walk --progress <in >out.pack 2>err &&
743+
grep "Compressing objects by path" err &&
740744
git -C server index-pack --fix-thin --stdin <out.pack
741745
'
742746

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)