Skip to content

Commit 97ec432

Browse files
ttaylorrgitster
authored andcommitted
pack-objects: declare 'rev_info' for '--stdin-packs' earlier
Once 'read_packs_list_from_stdin()' has called for_each_object_in_pack() on each of the input packs, we do a reachability traversal to discover names for any objects we picked up so we can generate name hash values and hopefully get higher quality deltas as a result. A future commit will change the purpose of this reachability traversal to find and pack objects which are reachable from commits in the input packs, but are packed in an unknown (not included nor excluded) pack. Extract the code which initializes and performs the reachability traversal to take place in the caller, not the callee, which prepares us to share this code for the '--unpacked' case (see the function add_unreachable_loose_objects() for more details). Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 67e1a78 commit 97ec432

File tree

1 file changed

+34
-33
lines changed

1 file changed

+34
-33
lines changed

builtin/pack-objects.c

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3793,32 +3793,14 @@ static int pack_mtime_cmp(const void *_a, const void *_b)
37933793
return 0;
37943794
}
37953795

3796-
static void read_packs_list_from_stdin(void)
3796+
static void read_packs_list_from_stdin(struct rev_info *revs)
37973797
{
37983798
struct strbuf buf = STRBUF_INIT;
37993799
struct string_list include_packs = STRING_LIST_INIT_DUP;
38003800
struct string_list exclude_packs = STRING_LIST_INIT_DUP;
38013801
struct string_list_item *item = NULL;
38023802

38033803
struct packed_git *p;
3804-
struct rev_info revs;
3805-
3806-
repo_init_revisions(the_repository, &revs, NULL);
3807-
/*
3808-
* Use a revision walk to fill in the namehash of objects in the include
3809-
* packs. To save time, we'll avoid traversing through objects that are
3810-
* in excluded packs.
3811-
*
3812-
* That may cause us to avoid populating all of the namehash fields of
3813-
* all included objects, but our goal is best-effort, since this is only
3814-
* an optimization during delta selection.
3815-
*/
3816-
revs.no_kept_objects = 1;
3817-
revs.keep_pack_cache_flags |= IN_CORE_KEEP_PACKS;
3818-
revs.blob_objects = 1;
3819-
revs.tree_objects = 1;
3820-
revs.tag_objects = 1;
3821-
revs.ignore_missing_links = 1;
38223804

38233805
while (strbuf_getline(&buf, stdin) != EOF) {
38243806
if (!buf.len)
@@ -3888,22 +3870,10 @@ static void read_packs_list_from_stdin(void)
38883870
struct packed_git *p = item->util;
38893871
for_each_object_in_pack(p,
38903872
add_object_entry_from_pack,
3891-
&revs,
3873+
revs,
38923874
FOR_EACH_OBJECT_PACK_ORDER);
38933875
}
38943876

3895-
if (prepare_revision_walk(&revs))
3896-
die(_("revision walk setup failed"));
3897-
traverse_commit_list(&revs,
3898-
show_commit_pack_hint,
3899-
show_object_pack_hint,
3900-
NULL);
3901-
3902-
trace2_data_intmax("pack-objects", the_repository, "stdin_packs_found",
3903-
stdin_packs_found_nr);
3904-
trace2_data_intmax("pack-objects", the_repository, "stdin_packs_hints",
3905-
stdin_packs_hints_nr);
3906-
39073877
strbuf_release(&buf);
39083878
string_list_clear(&include_packs, 0);
39093879
string_list_clear(&exclude_packs, 0);
@@ -3913,11 +3883,42 @@ static void add_unreachable_loose_objects(void);
39133883

39143884
static void read_stdin_packs(int rev_list_unpacked)
39153885
{
3886+
struct rev_info revs;
3887+
3888+
repo_init_revisions(the_repository, &revs, NULL);
3889+
/*
3890+
* Use a revision walk to fill in the namehash of objects in the include
3891+
* packs. To save time, we'll avoid traversing through objects that are
3892+
* in excluded packs.
3893+
*
3894+
* That may cause us to avoid populating all of the namehash fields of
3895+
* all included objects, but our goal is best-effort, since this is only
3896+
* an optimization during delta selection.
3897+
*/
3898+
revs.no_kept_objects = 1;
3899+
revs.keep_pack_cache_flags |= IN_CORE_KEEP_PACKS;
3900+
revs.blob_objects = 1;
3901+
revs.tree_objects = 1;
3902+
revs.tag_objects = 1;
3903+
revs.ignore_missing_links = 1;
3904+
39163905
/* avoids adding objects in excluded packs */
39173906
ignore_packed_keep_in_core = 1;
3918-
read_packs_list_from_stdin();
3907+
read_packs_list_from_stdin(&revs);
39193908
if (rev_list_unpacked)
39203909
add_unreachable_loose_objects();
3910+
3911+
if (prepare_revision_walk(&revs))
3912+
die(_("revision walk setup failed"));
3913+
traverse_commit_list(&revs,
3914+
show_commit_pack_hint,
3915+
show_object_pack_hint,
3916+
NULL);
3917+
3918+
trace2_data_intmax("pack-objects", the_repository, "stdin_packs_found",
3919+
stdin_packs_found_nr);
3920+
trace2_data_intmax("pack-objects", the_repository, "stdin_packs_hints",
3921+
stdin_packs_hints_nr);
39213922
}
39223923

39233924
static void add_cruft_object_entry(const struct object_id *oid, enum object_type type,

0 commit comments

Comments
 (0)