Skip to content

Commit 66a6b1f

Browse files
psluacescursoragent
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 35c929c commit 66a6b1f

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
/**
@@ -3917,7 +3918,8 @@ static int stdin_packs_include_check(struct commit *commit, void *data)
39173918
}
39183919

39193920
static void stdin_packs_add_pack_entries(struct strmap *packs,
3920-
struct rev_info *revs)
3921+
struct rev_info *revs,
3922+
enum stdin_packs_mode mode)
39213923
{
39223924
struct string_list keys = STRING_LIST_INIT_NODUP;
39233925
struct string_list_item *item;
@@ -3958,7 +3960,8 @@ static void stdin_packs_add_pack_entries(struct strmap *packs,
39583960
for_each_object_in_pack(info->p,
39593961
add_object_entry_from_pack,
39603962
revs,
3961-
ODB_FOR_EACH_OBJECT_PACK_ORDER);
3963+
mode == STDIN_PACKS_MODE_DAMAGE_CONTROL ?
3964+
0 : ODB_FOR_EACH_OBJECT_PACK_ORDER);
39623965
}
39633966

39643967
string_list_clear(&keys, 0);
@@ -4045,7 +4048,7 @@ static void stdin_packs_read_input(struct rev_info *revs,
40454048
info->p = p;
40464049
}
40474050

4048-
stdin_packs_add_pack_entries(&packs, revs);
4051+
stdin_packs_add_pack_entries(&packs, revs, mode);
40494052

40504053
strbuf_release(&buf);
40514054
strmap_clear(&packs, 1);
@@ -4097,12 +4100,14 @@ static void read_stdin_packs(enum stdin_packs_mode mode, int rev_list_unpacked)
40974100
if (rev_list_unpacked)
40984101
add_unreachable_loose_objects(&revs);
40994102

4100-
if (prepare_revision_walk(&revs))
4101-
die(_("revision walk setup failed"));
4102-
traverse_commit_list(&revs,
4103-
show_commit_pack_hint,
4104-
show_object_pack_hint,
4105-
&mode);
4103+
if (mode != STDIN_PACKS_MODE_DAMAGE_CONTROL) {
4104+
if (prepare_revision_walk(&revs))
4105+
die(_("revision walk setup failed"));
4106+
traverse_commit_list(&revs,
4107+
show_commit_pack_hint,
4108+
show_object_pack_hint,
4109+
&mode);
4110+
}
41064111

41074112
release_revisions(&revs);
41084113

@@ -4993,6 +4998,8 @@ static int parse_stdin_packs_mode(const struct option *opt, const char *arg,
49934998
*mode = STDIN_PACKS_MODE_STANDARD;
49944999
else if (!strcmp(arg, "follow"))
49955000
*mode = STDIN_PACKS_MODE_FOLLOW;
5001+
else if (!strcmp(arg, "damage-control"))
5002+
*mode = STDIN_PACKS_MODE_DAMAGE_CONTROL;
49965003
else
49975004
die(_("invalid value for '%s': '%s'"), opt->long_name, arg);
49985005

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)