Skip to content

Commit 2828d72

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 89f64f7 commit 2828d72

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
@@ -3561,32 +3561,14 @@ static int pack_mtime_cmp(const void *_a, const void *_b)
35613561
return 0;
35623562
}
35633563

3564-
static void read_packs_list_from_stdin(void)
3564+
static void read_packs_list_from_stdin(struct rev_info *revs)
35653565
{
35663566
struct strbuf buf = STRBUF_INIT;
35673567
struct string_list include_packs = STRING_LIST_INIT_DUP;
35683568
struct string_list exclude_packs = STRING_LIST_INIT_DUP;
35693569
struct string_list_item *item = NULL;
35703570

35713571
struct packed_git *p;
3572-
struct rev_info revs;
3573-
3574-
repo_init_revisions(the_repository, &revs, NULL);
3575-
/*
3576-
* Use a revision walk to fill in the namehash of objects in the include
3577-
* packs. To save time, we'll avoid traversing through objects that are
3578-
* in excluded packs.
3579-
*
3580-
* That may cause us to avoid populating all of the namehash fields of
3581-
* all included objects, but our goal is best-effort, since this is only
3582-
* an optimization during delta selection.
3583-
*/
3584-
revs.no_kept_objects = 1;
3585-
revs.keep_pack_cache_flags |= IN_CORE_KEEP_PACKS;
3586-
revs.blob_objects = 1;
3587-
revs.tree_objects = 1;
3588-
revs.tag_objects = 1;
3589-
revs.ignore_missing_links = 1;
35903572

35913573
while (strbuf_getline(&buf, stdin) != EOF) {
35923574
if (!buf.len)
@@ -3656,22 +3638,10 @@ static void read_packs_list_from_stdin(void)
36563638
struct packed_git *p = item->util;
36573639
for_each_object_in_pack(p,
36583640
add_object_entry_from_pack,
3659-
&revs,
3641+
revs,
36603642
FOR_EACH_OBJECT_PACK_ORDER);
36613643
}
36623644

3663-
if (prepare_revision_walk(&revs))
3664-
die(_("revision walk setup failed"));
3665-
traverse_commit_list(&revs,
3666-
show_commit_pack_hint,
3667-
show_object_pack_hint,
3668-
NULL);
3669-
3670-
trace2_data_intmax("pack-objects", the_repository, "stdin_packs_found",
3671-
stdin_packs_found_nr);
3672-
trace2_data_intmax("pack-objects", the_repository, "stdin_packs_hints",
3673-
stdin_packs_hints_nr);
3674-
36753645
strbuf_release(&buf);
36763646
string_list_clear(&include_packs, 0);
36773647
string_list_clear(&exclude_packs, 0);
@@ -3681,11 +3651,42 @@ static void add_unreachable_loose_objects(void);
36813651

36823652
static void read_stdin_packs(int rev_list_unpacked)
36833653
{
3654+
struct rev_info revs;
3655+
3656+
repo_init_revisions(the_repository, &revs, NULL);
3657+
/*
3658+
* Use a revision walk to fill in the namehash of objects in the include
3659+
* packs. To save time, we'll avoid traversing through objects that are
3660+
* in excluded packs.
3661+
*
3662+
* That may cause us to avoid populating all of the namehash fields of
3663+
* all included objects, but our goal is best-effort, since this is only
3664+
* an optimization during delta selection.
3665+
*/
3666+
revs.no_kept_objects = 1;
3667+
revs.keep_pack_cache_flags |= IN_CORE_KEEP_PACKS;
3668+
revs.blob_objects = 1;
3669+
revs.tree_objects = 1;
3670+
revs.tag_objects = 1;
3671+
revs.ignore_missing_links = 1;
3672+
36843673
/* avoids adding objects in excluded packs */
36853674
ignore_packed_keep_in_core = 1;
3686-
read_packs_list_from_stdin();
3675+
read_packs_list_from_stdin(&revs);
36873676
if (rev_list_unpacked)
36883677
add_unreachable_loose_objects();
3678+
3679+
if (prepare_revision_walk(&revs))
3680+
die(_("revision walk setup failed"));
3681+
traverse_commit_list(&revs,
3682+
show_commit_pack_hint,
3683+
show_object_pack_hint,
3684+
NULL);
3685+
3686+
trace2_data_intmax("pack-objects", the_repository, "stdin_packs_found",
3687+
stdin_packs_found_nr);
3688+
trace2_data_intmax("pack-objects", the_repository, "stdin_packs_hints",
3689+
stdin_packs_hints_nr);
36893690
}
36903691

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

0 commit comments

Comments
 (0)