Skip to content

Commit 3bfa8a1

Browse files
derrickstoleedscho
authored andcommitted
pack-objects: add --path-walk option
In order to more easily compute delta bases among objects that appear at the exact same path, add a --path-walk option to 'git pack-objects'. This option will use the path-walk API instead of the object walk given by the revision machinery. Since objects will be provided in batches representing a common path, those objects can be tested for delta bases immediately instead of waiting for a sort of the full object list by name-hash. This has multiple benefits, including avoiding collisions by name-hash. The objects marked as UNINTERESTING are included in these batches, so we are guaranteeing some locality to find good delta bases. After the individual passes are done on a per-path basis, the default name-hash is used to find other opportunistic delta bases that did not match exactly by the full path name. RFC TODO: It is important to note that this option is inherently incompatible with using a bitmap index. This walk probably also does not work with other advanced features, such as delta islands. Getting ahead of myself, this option compares well with --full-name-hash when the packfile is large enough, but also performs at least as well as the default in all cases that I've seen. RFC TODO: this should probably be recording the batch locations to another list so they could be processed in a second phase using threads. RFC TODO: list some examples of how this outperforms previous pack-objects strategies. (This is coming in later commits that include performance test changes.) Signed-off-by: Derrick Stolee <[email protected]>
1 parent a9f9573 commit 3bfa8a1

File tree

4 files changed

+168
-11
lines changed

4 files changed

+168
-11
lines changed

Documentation/git-pack-objects.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ SYNOPSIS
1616
[--cruft] [--cruft-expiration=<time>]
1717
[--stdout [--filter=<filter-spec>] | <base-name>]
1818
[--shallow] [--keep-true-parents] [--[no-]sparse]
19-
[--full-name-hash] < <object-list>
19+
[--full-name-hash] [--path-walk] < <object-list>
2020

2121

2222
DESCRIPTION
@@ -346,6 +346,16 @@ raise an error.
346346
Restrict delta matches based on "islands". See DELTA ISLANDS
347347
below.
348348

349+
--path-walk::
350+
By default, `git pack-objects` walks objects in an order that
351+
presents trees and blobs in an order unrelated to the path they
352+
appear relative to a commit's root tree. The `--path-walk` option
353+
enables a different walking algorithm that organizes trees and
354+
blobs by path. This has the potential to improve delta compression
355+
especially in the presence of filenames that cause collisions in
356+
Git's default name-hash algorithm. Due to changing how the objects
357+
are walked, this option is not compatible with `--delta-islands`,
358+
`--shallow`, or `--filter`.
349359

350360
DELTA ISLANDS
351361
-------------

Documentation/technical/api-path-walk.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,5 @@ Examples
6969
--------
7070

7171
See example usages in:
72-
`t/helper/test-path-walk.c`
72+
`t/helper/test-path-walk.c`,
73+
`builtin/pack-objects.c`

builtin/pack-objects.c

Lines changed: 138 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
#include "promisor-remote.h"
4040
#include "pack-mtimes.h"
4141
#include "parse-options.h"
42+
#include "blob.h"
43+
#include "tree.h"
44+
#include "path-walk.h"
4245

4346
/*
4447
* Objects we are going to pack are collected in the `to_pack` structure.
@@ -215,6 +218,7 @@ static int delta_search_threads;
215218
static int pack_to_stdout;
216219
static int sparse;
217220
static int thin;
221+
static int path_walk;
218222
static int num_preferred_base;
219223
static struct progress *progress_state;
220224

@@ -4140,6 +4144,105 @@ static void mark_bitmap_preferred_tips(void)
41404144
}
41414145
}
41424146

4147+
static inline int is_oid_interesting(struct repository *repo,
4148+
struct object_id *oid)
4149+
{
4150+
struct object *o = lookup_object(repo, oid);
4151+
return o && !(o->flags & UNINTERESTING);
4152+
}
4153+
4154+
static int add_objects_by_path(const char *path,
4155+
struct oid_array *oids,
4156+
enum object_type type,
4157+
void *data)
4158+
{
4159+
struct object_entry **delta_list;
4160+
size_t oe_start = to_pack.nr_objects;
4161+
size_t oe_end;
4162+
unsigned int sub_list_size;
4163+
unsigned int *processed = data;
4164+
4165+
/*
4166+
* First, add all objects to the packing data, including the ones
4167+
* marked UNINTERESTING (translated to 'exclude') as they can be
4168+
* used as delta bases.
4169+
*/
4170+
for (size_t i = 0; i < oids->nr; i++) {
4171+
int exclude;
4172+
struct object_info oi = OBJECT_INFO_INIT;
4173+
struct object_id *oid = &oids->oid[i];
4174+
4175+
/* Skip objects that do not exist locally. */
4176+
if (exclude_promisor_objects &&
4177+
oid_object_info_extended(the_repository, oid, &oi,
4178+
OBJECT_INFO_FOR_PREFETCH) < 0)
4179+
continue;
4180+
4181+
exclude = !is_oid_interesting(the_repository, oid);
4182+
4183+
if (exclude && !thin)
4184+
continue;
4185+
4186+
add_object_entry(oid, type, path, exclude);
4187+
}
4188+
4189+
oe_end = to_pack.nr_objects;
4190+
4191+
/* We can skip delta calculations if it is a no-op. */
4192+
if (oe_end == oe_start || !window)
4193+
return 0;
4194+
4195+
sub_list_size = 0;
4196+
ALLOC_ARRAY(delta_list, oe_end - oe_start);
4197+
4198+
for (size_t i = 0; i < oe_end - oe_start; i++) {
4199+
struct object_entry *entry = to_pack.objects + oe_start + i;
4200+
4201+
if (!should_attempt_deltas(entry))
4202+
continue;
4203+
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);
4221+
return 0;
4222+
}
4223+
4224+
static void get_object_list_path_walk(struct rev_info *revs)
4225+
{
4226+
struct path_walk_info info = PATH_WALK_INFO_INIT;
4227+
unsigned int processed = 0;
4228+
4229+
info.revs = revs;
4230+
info.path_fn = add_objects_by_path;
4231+
info.path_fn_data = &processed;
4232+
revs->tag_objects = 1;
4233+
4234+
/*
4235+
* Allow the --[no-]sparse option to be interesting here, if only
4236+
* for testing purposes. Paths with no interesting objects will not
4237+
* contribute to the resulting pack, but only create noisy preferred
4238+
* base objects.
4239+
*/
4240+
info.prune_all_uninteresting = sparse;
4241+
4242+
if (walk_objects_by_path(&info))
4243+
die(_("failed to pack objects via path-walk"));
4244+
}
4245+
41434246
static void get_object_list(struct rev_info *revs, int ac, const char **av)
41444247
{
41454248
struct setup_revision_opt s_r_opt = {
@@ -4186,7 +4289,7 @@ static void get_object_list(struct rev_info *revs, int ac, const char **av)
41864289

41874290
warn_on_object_refname_ambiguity = save_warning;
41884291

4189-
if (use_bitmap_index && !get_object_list_from_bitmap(revs))
4292+
if (use_bitmap_index && !path_walk && !get_object_list_from_bitmap(revs))
41904293
return;
41914294

41924295
if (use_delta_islands)
@@ -4195,15 +4298,19 @@ static void get_object_list(struct rev_info *revs, int ac, const char **av)
41954298
if (write_bitmap_index)
41964299
mark_bitmap_preferred_tips();
41974300

4198-
if (prepare_revision_walk(revs))
4199-
die(_("revision walk setup failed"));
4200-
mark_edges_uninteresting(revs, show_edge, sparse);
4201-
42024301
if (!fn_show_object)
42034302
fn_show_object = show_object;
4204-
traverse_commit_list(revs,
4205-
show_commit, fn_show_object,
4206-
NULL);
4303+
4304+
if (path_walk) {
4305+
get_object_list_path_walk(revs);
4306+
} else {
4307+
if (prepare_revision_walk(revs))
4308+
die(_("revision walk setup failed"));
4309+
mark_edges_uninteresting(revs, show_edge, sparse);
4310+
traverse_commit_list(revs,
4311+
show_commit, fn_show_object,
4312+
NULL);
4313+
}
42074314

42084315
if (unpack_unreachable_expiration) {
42094316
revs->ignore_missing_links = 1;
@@ -4413,6 +4520,8 @@ int cmd_pack_objects(int argc,
44134520
N_("use the sparse reachability algorithm")),
44144521
OPT_BOOL(0, "thin", &thin,
44154522
N_("create thin packs")),
4523+
OPT_BOOL(0, "path-walk", &path_walk,
4524+
N_("use the path-walk API to walk objects when possible")),
44164525
OPT_BOOL(0, "shallow", &shallow,
44174526
N_("create packs suitable for shallow fetches")),
44184527
OPT_BOOL(0, "honor-pack-keep", &ignore_packed_keep_on_disk,
@@ -4498,7 +4607,27 @@ int cmd_pack_objects(int argc,
44984607
window = 0;
44994608

45004609
strvec_push(&rp, "pack-objects");
4501-
if (thin) {
4610+
4611+
if (path_walk && filter_options.choice) {
4612+
warning(_("cannot use --filter with --path-walk"));
4613+
path_walk = 0;
4614+
}
4615+
if (path_walk && use_delta_islands) {
4616+
warning(_("cannot use delta islands with --path-walk"));
4617+
path_walk = 0;
4618+
}
4619+
if (path_walk && shallow) {
4620+
warning(_("cannot use --shallow with --path-walk"));
4621+
path_walk = 0;
4622+
}
4623+
if (path_walk) {
4624+
strvec_push(&rp, "--boundary");
4625+
/*
4626+
* We must disable the bitmaps because we are removing
4627+
* the --objects / --objects-edge[-aggressive] options.
4628+
*/
4629+
use_bitmap_index = 0;
4630+
} else if (thin) {
45024631
use_internal_rev_list = 1;
45034632
strvec_push(&rp, shallow
45044633
? "--objects-edge-aggressive"

t/t5300-pack-object.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,4 +686,21 @@ test_expect_success '--full-name-hash and --write-bitmap-index are incompatible'
686686
git pack-objects --stdout --all --full-name-hash --write-bitmap-index >out
687687
'
688688

689+
# Basic "repack everything" test
690+
test_expect_success '--path-walk pack everything' '
691+
git -C server rev-parse HEAD >in &&
692+
git -C server pack-objects --stdout --revs --path-walk <in >out.pack &&
693+
git -C server index-pack --stdin <out.pack
694+
'
695+
696+
# Basic "thin pack" test
697+
test_expect_success '--path-walk thin pack' '
698+
cat >in <<-EOF &&
699+
$(git -C server rev-parse HEAD)
700+
^$(git -C server rev-parse HEAD~2)
701+
EOF
702+
git -C server pack-objects --thin --stdout --revs --path-walk <in >out.pack &&
703+
git -C server index-pack --fix-thin --stdin <out.pack
704+
'
705+
689706
test_done

0 commit comments

Comments
 (0)