Skip to content

Commit 01a9bb1

Browse files
derrickstoleeGit for Windows Build Agent
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 79f283f commit 01a9bb1

File tree

4 files changed

+75
-33
lines changed

4 files changed

+75
-33
lines changed

builtin/pack-objects.c

Lines changed: 57 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3198,6 +3198,51 @@ static int should_attempt_deltas(struct object_entry *entry)
31983198
return 1;
31993199
}
32003200

3201+
static void find_deltas_for_region(struct object_entry *list UNUSED,
3202+
struct packing_region *region,
3203+
unsigned int *processed)
3204+
{
3205+
struct object_entry **delta_list;
3206+
uint32_t delta_list_nr = 0;
3207+
3208+
ALLOC_ARRAY(delta_list, region->nr);
3209+
for (uint32_t i = 0; i < region->nr; i++) {
3210+
struct object_entry *entry = to_pack.objects + region->start + i;
3211+
if (should_attempt_deltas(entry))
3212+
delta_list[delta_list_nr++] = entry;
3213+
}
3214+
3215+
QSORT(delta_list, delta_list_nr, type_size_sort);
3216+
find_deltas(delta_list, &delta_list_nr, window, depth, processed);
3217+
free(delta_list);
3218+
}
3219+
3220+
static void find_deltas_by_region(struct object_entry *list,
3221+
struct packing_region *regions,
3222+
uint32_t start, uint32_t nr)
3223+
{
3224+
unsigned int processed = 0;
3225+
uint32_t progress_nr;
3226+
3227+
if (!nr)
3228+
return;
3229+
3230+
progress_nr = regions[nr - 1].start + regions[nr - 1].nr;
3231+
3232+
if (progress)
3233+
progress_state = start_progress(the_repository,
3234+
_("Compressing objects by path"),
3235+
progress_nr);
3236+
3237+
while (nr--)
3238+
find_deltas_for_region(list,
3239+
&regions[start++],
3240+
&processed);
3241+
3242+
display_progress(progress_state, progress_nr);
3243+
stop_progress(&progress_state);
3244+
}
3245+
32013246
static void prepare_pack(int window, int depth)
32023247
{
32033248
struct object_entry **delta_list;
@@ -3222,6 +3267,10 @@ static void prepare_pack(int window, int depth)
32223267
if (!to_pack.nr_objects || !window || !depth)
32233268
return;
32243269

3270+
if (path_walk)
3271+
find_deltas_by_region(to_pack.objects, to_pack.regions,
3272+
0, to_pack.nr_regions);
3273+
32253274
ALLOC_ARRAY(delta_list, to_pack.nr_objects);
32263275
nr_deltas = n = 0;
32273276

@@ -4166,10 +4215,8 @@ static int add_objects_by_path(const char *path,
41664215
enum object_type type,
41674216
void *data)
41684217
{
4169-
struct object_entry **delta_list;
41704218
size_t oe_start = to_pack.nr_objects;
41714219
size_t oe_end;
4172-
unsigned int sub_list_size;
41734220
unsigned int *processed = data;
41744221

41754222
/*
@@ -4202,32 +4249,17 @@ static int add_objects_by_path(const char *path,
42024249
if (oe_end == oe_start || !window)
42034250
return 0;
42044251

4205-
sub_list_size = 0;
4206-
ALLOC_ARRAY(delta_list, oe_end - oe_start);
4207-
4208-
for (size_t i = 0; i < oe_end - oe_start; i++) {
4209-
struct object_entry *entry = to_pack.objects + oe_start + i;
4252+
ALLOC_GROW(to_pack.regions,
4253+
to_pack.nr_regions + 1,
4254+
to_pack.nr_regions_alloc);
42104255

4211-
if (!should_attempt_deltas(entry))
4212-
continue;
4213-
4214-
delta_list[sub_list_size++] = entry;
4215-
}
4256+
to_pack.regions[to_pack.nr_regions].start = oe_start;
4257+
to_pack.regions[to_pack.nr_regions].nr = oe_end - oe_start;
4258+
to_pack.nr_regions++;
42164259

4217-
/*
4218-
* Find delta bases among this list of objects that all match the same
4219-
* path. This causes the delta compression to be interleaved in the
4220-
* object walk, which can lead to confusing progress indicators. This is
4221-
* also incompatible with threaded delta calculations. In the future,
4222-
* consider creating a list of regions in the full to_pack.objects array
4223-
* that could be picked up by the threaded delta computation.
4224-
*/
4225-
if (sub_list_size && window) {
4226-
QSORT(delta_list, sub_list_size, type_size_sort);
4227-
find_deltas(delta_list, &sub_list_size, window, depth, processed);
4228-
}
4260+
*processed += oids->nr;
4261+
display_progress(progress_state, *processed);
42294262

4230-
free(delta_list);
42314263
return 0;
42324264
}
42334265

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
@@ -707,7 +707,9 @@ test_expect_success '--full-name-hash and --write-bitmap-index are incompatible'
707707
# Basic "repack everything" test
708708
test_expect_success '--path-walk pack everything' '
709709
git -C server rev-parse HEAD >in &&
710-
git -C server pack-objects --stdout --revs --path-walk <in >out.pack &&
710+
GIT_PROGRESS_DELAY=0 git -C server pack-objects \
711+
--stdout --revs --path-walk --progress <in >out.pack 2>err &&
712+
grep "Compressing objects by path" err &&
711713
git -C server index-pack --stdin <out.pack
712714
'
713715

@@ -717,7 +719,9 @@ test_expect_success '--path-walk thin pack' '
717719
$(git -C server rev-parse HEAD)
718720
^$(git -C server rev-parse HEAD~2)
719721
EOF
720-
git -C server pack-objects --thin --stdout --revs --path-walk <in >out.pack &&
722+
GIT_PROGRESS_DELAY=0 git -C server pack-objects \
723+
--thin --stdout --revs --path-walk --progress <in >out.pack 2>err &&
724+
grep "Compressing objects by path" err &&
721725
git -C server index-pack --fix-thin --stdin <out.pack
722726
'
723727

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)