Skip to content

Commit 061687f

Browse files
committed
WIP
1 parent def26e1 commit 061687f

File tree

4 files changed

+54
-2
lines changed

4 files changed

+54
-2
lines changed

builtin/multi-pack-index.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ static char const * const builtin_multi_pack_index_usage[] = {
6161
static struct opts_multi_pack_index {
6262
char *object_dir;
6363
const char *preferred_pack;
64+
const char *incremental_base;
6465
char *refs_snapshot;
6566
unsigned long batch_size;
6667
unsigned flags;
@@ -214,6 +215,8 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,
214215

215216
struct option *options;
216217
static struct option builtin_multi_pack_index_compact_options[] = {
218+
OPT_STRING(0, "base", &opts.incremental_base, N_("checksum"),
219+
N_("base MIDX for incremental writes")),
217220
OPT_BIT(0, "bitmap", &opts.flags, N_("write multi-pack bitmap"),
218221
MIDX_WRITE_BITMAP | MIDX_WRITE_REV_INDEX),
219222
OPT_BIT(0, "incremental", &opts.flags,
@@ -258,7 +261,8 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,
258261
if (!to_midx)
259262
die(_("could not find MIDX 'to': %s"), argv[1]);
260263

261-
return write_midx_file_compact(source, from_midx, to_midx, opts.flags);
264+
return write_midx_file_compact(source, from_midx, to_midx,
265+
opts.incremental_base, opts.flags);
262266
}
263267

264268
static int cmd_multi_pack_index_verify(int argc, const char **argv,

midx-write.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,7 @@ struct write_midx_opts {
11571157

11581158
const char *preferred_pack_name;
11591159
const char *refs_snapshot;
1160+
const char *incremental_base;
11601161
unsigned flags;
11611162
};
11621163

@@ -1196,6 +1197,9 @@ static int write_midx_internal(struct write_midx_opts *opts)
11961197

11971198
ctx.compact_from = opts->compact_from;
11981199
ctx.compact_to = opts->compact_to;
1200+
} else if (opts->incremental_base) {
1201+
error(_("custom bases are only supported during compaction"));
1202+
goto cleanup;
11991203
}
12001204

12011205
if (ctx.incremental)
@@ -1231,11 +1235,28 @@ static int write_midx_internal(struct write_midx_opts *opts)
12311235

12321236
/*
12331237
* If compacting MIDX layer(s) in the range [from, to], then the
1234-
* compacted MIDX will share the same base MIDX as 'from'.
1238+
* compacted MIDX will share the same base MIDX as 'from',
1239+
* unless a custom --base is specified (see below).
12351240
*/
12361241
if (ctx.compact)
12371242
ctx.base_midx = ctx.compact_from->base_midx;
12381243

1244+
if (opts->incremental_base) {
1245+
while (ctx.base_midx) {
1246+
if (!strcmp(opts->incremental_base,
1247+
get_midx_checksum(ctx.base_midx)))
1248+
break;
1249+
1250+
ctx.base_midx = ctx.base_midx->base_midx;
1251+
}
1252+
1253+
if (!ctx.base_midx) {
1254+
error(_("could not find base MIDX '%s'"),
1255+
opts->incremental_base);
1256+
goto cleanup;
1257+
}
1258+
}
1259+
12391260
ctx.nr = 0;
12401261
ctx.alloc = ctx.m ? ctx.m->num_packs + ctx.m->num_packs_in_base : 16;
12411262
ctx.info = NULL;
@@ -1757,12 +1778,14 @@ int write_midx_file_only(struct odb_source *source,
17571778
int write_midx_file_compact(struct odb_source *source,
17581779
struct multi_pack_index *from,
17591780
struct multi_pack_index *to,
1781+
const char *incremental_base,
17601782
unsigned flags)
17611783
{
17621784
struct write_midx_opts opts = {
17631785
.source = source,
17641786
.compact_from = from,
17651787
.compact_to = to,
1788+
.incremental_base = incremental_base,
17661789
.flags = flags | MIDX_WRITE_COMPACT,
17671790
};
17681791

midx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ int write_midx_file_only(struct odb_source *source,
134134
int write_midx_file_compact(struct odb_source *source,
135135
struct multi_pack_index *from,
136136
struct multi_pack_index *to,
137+
const char *incremental_base,
137138
unsigned flags);
138139
void clear_midx_file(struct repository *r);
139140
int verify_midx_file(struct odb_source *source, unsigned flags);

t/t5335-compact-multi-pack-index.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,28 @@ test_expect_success 'MIDX compaction with bitmaps (non-trivial)' '
197197
)
198198
'
199199

200+
test_expect_success 'MIDX compaction with --base' '
201+
git init midx-compact-with--base &&
202+
(
203+
cd midx-compact-with--base &&
204+
205+
write_packs A B C D &&
206+
207+
test_line_count = 4 $midx_chain &&
208+
209+
cp "$midx_chain" "$midx_chain".bak &&
210+
211+
git multi-pack-index compact --incremental \
212+
--base="$(nth_line 1 "$midx_chain")" \
213+
"$(nth_line 3 "$midx_chain")" \
214+
"$(nth_line 4 "$midx_chain")" &&
215+
test_line_count = 2 $midx_chain &&
216+
217+
head -n1 "$midx_chain.bak" >actual &&
218+
head -n1 "$midx_chain" >expect &&
219+
220+
test_cmp expect actual
221+
)
222+
'
223+
200224
test_done

0 commit comments

Comments
 (0)