Skip to content

Commit 6f81818

Browse files
Ubuntucursoragent
authored andcommitted
pack-objects: add damage-control stdin packs mode
Add a storm-oriented stdin-packs mode that skips best-effort namehash traversal and pack-order reverse-index enumeration when callers only need a valid low-latency roll-up. This keeps damage-control repacks write-bound while preserving the normal stdin-packs behavior for quality repacks. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 6f7ced8 commit 6f81818

2 files changed

Lines changed: 41 additions & 9 deletions

File tree

builtin/pack-objects.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ enum stdin_packs_mode {
290290
STDIN_PACKS_MODE_NONE,
291291
STDIN_PACKS_MODE_STANDARD,
292292
STDIN_PACKS_MODE_FOLLOW,
293+
STDIN_PACKS_MODE_DAMAGE_CONTROL,
293294
};
294295

295296
/**
@@ -3907,7 +3908,8 @@ static int stdin_packs_include_check(struct commit *commit, void *data)
39073908
}
39083909

39093910
static void stdin_packs_add_pack_entries(struct strmap *packs,
3910-
struct rev_info *revs)
3911+
struct rev_info *revs,
3912+
enum stdin_packs_mode mode)
39113913
{
39123914
struct string_list keys = STRING_LIST_INIT_NODUP;
39133915
struct string_list_item *item;
@@ -3948,7 +3950,8 @@ static void stdin_packs_add_pack_entries(struct strmap *packs,
39483950
for_each_object_in_pack(info->p,
39493951
add_object_entry_from_pack,
39503952
revs,
3951-
ODB_FOR_EACH_OBJECT_PACK_ORDER);
3953+
mode == STDIN_PACKS_MODE_DAMAGE_CONTROL ?
3954+
0 : ODB_FOR_EACH_OBJECT_PACK_ORDER);
39523955
}
39533956

39543957
string_list_clear(&keys, 0);
@@ -4035,7 +4038,7 @@ static void stdin_packs_read_input(struct rev_info *revs,
40354038
info->p = p;
40364039
}
40374040

4038-
stdin_packs_add_pack_entries(&packs, revs);
4041+
stdin_packs_add_pack_entries(&packs, revs, mode);
40394042

40404043
strbuf_release(&buf);
40414044
strmap_clear(&packs, 1);
@@ -4087,12 +4090,14 @@ static void read_stdin_packs(enum stdin_packs_mode mode, int rev_list_unpacked)
40874090
if (rev_list_unpacked)
40884091
add_unreachable_loose_objects(&revs);
40894092

4090-
if (prepare_revision_walk(&revs))
4091-
die(_("revision walk setup failed"));
4092-
traverse_commit_list(&revs,
4093-
show_commit_pack_hint,
4094-
show_object_pack_hint,
4095-
&mode);
4093+
if (mode != STDIN_PACKS_MODE_DAMAGE_CONTROL) {
4094+
if (prepare_revision_walk(&revs))
4095+
die(_("revision walk setup failed"));
4096+
traverse_commit_list(&revs,
4097+
show_commit_pack_hint,
4098+
show_object_pack_hint,
4099+
&mode);
4100+
}
40964101

40974102
release_revisions(&revs);
40984103

@@ -4983,6 +4988,8 @@ static int parse_stdin_packs_mode(const struct option *opt, const char *arg,
49834988
*mode = STDIN_PACKS_MODE_STANDARD;
49844989
else if (!strcmp(arg, "follow"))
49854990
*mode = STDIN_PACKS_MODE_FOLLOW;
4991+
else if (!strcmp(arg, "damage-control"))
4992+
*mode = STDIN_PACKS_MODE_DAMAGE_CONTROL;
49864993
else
49874994
die(_("invalid value for '%s': '%s'"), opt->long_name, arg);
49884995

t/t5331-pack-objects-stdin.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,31 @@ test_expect_success '--stdin-packs with excluded packs' '
6060
)
6161
'
6262

63+
test_expect_success '--stdin-packs=damage-control includes listed packs' '
64+
(
65+
cd stdin-packs &&
66+
67+
PACK_A="$(basename .git/objects/pack/pack-A-*.pack)" &&
68+
PACK_C="$(basename .git/objects/pack/pack-C-*.pack)" &&
69+
70+
git pack-objects test-dc --stdin-packs=damage-control \
71+
--window=0 --depth=0 <<-EOF &&
72+
$PACK_A
73+
$PACK_C
74+
EOF
75+
76+
(
77+
git show-index <$(ls .git/objects/pack/pack-A-*.idx) &&
78+
git show-index <$(ls .git/objects/pack/pack-C-*.idx)
79+
) >expect.raw &&
80+
git show-index <$(ls test-dc-*.idx) >actual.raw &&
81+
82+
cut -d" " -f2 <expect.raw | sort >expect &&
83+
cut -d" " -f2 <actual.raw | sort >actual &&
84+
test_cmp expect actual
85+
)
86+
'
87+
6388
test_expect_success '--stdin-packs is incompatible with --filter' '
6489
(
6590
cd stdin-packs &&

0 commit comments

Comments
 (0)