Skip to content

Commit 5a2e058

Browse files
committed
fixup! pack-objects: refactor path-walk delta phase
1 parent a7e0520 commit 5a2e058

File tree

4 files changed

+33
-74
lines changed

4 files changed

+33
-74
lines changed

builtin/pack-objects.c

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

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

3385-
if (path_walk)
3386-
find_deltas_by_region(to_pack.objects, to_pack.regions,
3387-
0, to_pack.nr_regions);
3388-
33893341
ALLOC_ARRAY(delta_list, to_pack.nr_objects);
33903342
nr_deltas = n = 0;
33913343

@@ -4341,8 +4293,10 @@ static int add_objects_by_path(const char *path,
43414293
enum object_type type,
43424294
void *data)
43434295
{
4296+
struct object_entry **delta_list;
43444297
size_t oe_start = to_pack.nr_objects;
43454298
size_t oe_end;
4299+
unsigned int sub_list_size;
43464300
unsigned int *processed = data;
43474301

43484302
/*
@@ -4375,17 +4329,32 @@ static int add_objects_by_path(const char *path,
43754329
if (oe_end == oe_start || !window)
43764330
return 0;
43774331

4378-
ALLOC_GROW(to_pack.regions,
4379-
to_pack.nr_regions + 1,
4380-
to_pack.nr_regions_alloc);
4332+
sub_list_size = 0;
4333+
ALLOC_ARRAY(delta_list, oe_end - oe_start);
43814334

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

4386-
*processed += oids->nr;
4387-
display_progress(progress_state, *processed);
4338+
if (!should_attempt_deltas(entry))
4339+
continue;
43884340

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

pack-objects.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,23 +120,11 @@ 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-
132123
struct packing_data {
133124
struct repository *repo;
134125
struct object_entry *objects;
135126
uint32_t nr_objects, nr_alloc;
136127

137-
struct packing_region *regions;
138-
uint32_t nr_regions, nr_regions_alloc;
139-
140128
int32_t *index;
141129
uint32_t index_size;
142130

t/t5300-pack-object.sh

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -726,9 +726,7 @@ 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_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 &&
729+
git -C server pack-objects --stdout --revs --path-walk <in >out.pack &&
732730
git -C server index-pack --stdin <out.pack
733731
'
734732

@@ -738,9 +736,7 @@ test_expect_success '--path-walk thin pack' '
738736
$(git -C server rev-parse HEAD)
739737
^$(git -C server rev-parse HEAD~2)
740738
EOF
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 &&
739+
git -C server pack-objects --thin --stdout --revs --path-walk <in >out.pack &&
744740
git -C server index-pack --fix-thin --stdin <out.pack
745741
'
746742

t/t5530-upload-pack-error.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ 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+
3743
test_must_fail git upload-pack . <input >/dev/null 2>output.err &&
3844
test_grep "unable to read" output.err &&
3945
test_grep "pack-objects died" output.err

0 commit comments

Comments
 (0)