1313#include "repository.h"
1414
1515#define BUILTIN_MIDX_WRITE_USAGE \
16- N_("git multi-pack-index [<options>] write [--preferred-pack=<pack>]" \
17- "[--refs-snapshot=<path>]")
16+ N_("git multi-pack-index [<options>] write [--preferred-pack=<pack>]\n" \
17+ " [--[no-]bitmap] [--[no-]incremental] [--[no-]stdin-packs]\n" \
18+ " [--refs-snapshot=<path>]")
19+
20+ #define BUILTIN_MIDX_COMPACT_USAGE \
21+ N_("git multi-pack-index [<options>] compact [--[no-]incremental]\n" \
22+ " [--[no-]bitmap] <from> <to>")
1823
1924#define BUILTIN_MIDX_VERIFY_USAGE \
2025 N_("git multi-pack-index [<options>] verify")
@@ -29,6 +34,10 @@ static char const * const builtin_multi_pack_index_write_usage[] = {
2934 BUILTIN_MIDX_WRITE_USAGE ,
3035 NULL
3136};
37+ static char const * const builtin_multi_pack_index_compact_usage [] = {
38+ BUILTIN_MIDX_COMPACT_USAGE ,
39+ NULL
40+ };
3241static char const * const builtin_multi_pack_index_verify_usage [] = {
3342 BUILTIN_MIDX_VERIFY_USAGE ,
3443 NULL
@@ -43,6 +52,7 @@ static char const * const builtin_multi_pack_index_repack_usage[] = {
4352};
4453static char const * const builtin_multi_pack_index_usage [] = {
4554 BUILTIN_MIDX_WRITE_USAGE ,
55+ BUILTIN_MIDX_COMPACT_USAGE ,
4656 BUILTIN_MIDX_VERIFY_USAGE ,
4757 BUILTIN_MIDX_EXPIRE_USAGE ,
4858 BUILTIN_MIDX_REPACK_USAGE ,
@@ -84,6 +94,8 @@ static struct option common_opts[] = {
8494 N_ ("directory" ),
8595 N_ ("object directory containing set of packfile and pack-index pairs" ),
8696 parse_object_dir ),
97+ OPT_BIT (0 , "progress" , & opts .flags , N_ ("force progress reporting" ),
98+ MIDX_PROGRESS ),
8799 OPT_END (),
88100};
89101
@@ -138,8 +150,6 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
138150 N_ ("pack for reuse when computing a multi-pack bitmap" )),
139151 OPT_BIT (0 , "bitmap" , & opts .flags , N_ ("write multi-pack bitmap" ),
140152 MIDX_WRITE_BITMAP | MIDX_WRITE_REV_INDEX ),
141- OPT_BIT (0 , "progress" , & opts .flags ,
142- N_ ("force progress reporting" ), MIDX_PROGRESS ),
143153 OPT_BIT (0 , "incremental" , & opts .flags ,
144154 N_ ("write a new incremental MIDX" ), MIDX_WRITE_INCREMENTAL ),
145155 OPT_BOOL (0 , "stdin-packs" , & opts .stdin_packs ,
@@ -194,14 +204,78 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
194204 return ret ;
195205}
196206
207+ static int cmd_multi_pack_index_compact (int argc , const char * * argv ,
208+ const char * prefix ,
209+ struct repository * repo )
210+ {
211+ struct multi_pack_index * m , * cur ;
212+ struct multi_pack_index * from_midx = NULL ;
213+ struct multi_pack_index * to_midx = NULL ;
214+ struct odb_source * source ;
215+ int ret ;
216+
217+ struct option * options ;
218+ static struct option builtin_multi_pack_index_compact_options [] = {
219+ OPT_BIT (0 , "bitmap" , & opts .flags , N_ ("write multi-pack bitmap" ),
220+ MIDX_WRITE_BITMAP | MIDX_WRITE_REV_INDEX ),
221+ OPT_BIT (0 , "incremental" , & opts .flags ,
222+ N_ ("write a new incremental MIDX" ), MIDX_WRITE_INCREMENTAL ),
223+ OPT_END (),
224+ };
225+
226+ repo_config (repo , git_multi_pack_index_write_config , NULL );
227+
228+ options = add_common_options (builtin_multi_pack_index_compact_options );
229+
230+ trace2_cmd_mode (argv [0 ]);
231+
232+ if (isatty (2 ))
233+ opts .flags |= MIDX_PROGRESS ;
234+ argc = parse_options (argc , argv , prefix ,
235+ options , builtin_multi_pack_index_compact_usage ,
236+ 0 );
237+
238+ if (argc != 2 )
239+ usage_with_options (builtin_multi_pack_index_compact_usage ,
240+ options );
241+ source = handle_object_dir_option (the_repository );
242+
243+ FREE_AND_NULL (options );
244+
245+ m = get_multi_pack_index (source );
246+
247+ for (cur = m ; cur && !(from_midx && to_midx ); cur = cur -> base_midx ) {
248+ const char * midx_csum = midx_get_checksum_hex (cur );
249+
250+ if (!from_midx && !strcmp (midx_csum , argv [0 ]))
251+ from_midx = cur ;
252+ if (!to_midx && !strcmp (midx_csum , argv [1 ]))
253+ to_midx = cur ;
254+ }
255+
256+ if (!from_midx )
257+ die (_ ("could not find MIDX: %s" ), argv [0 ]);
258+ if (!to_midx )
259+ die (_ ("could not find MIDX: %s" ), argv [1 ]);
260+ if (from_midx == to_midx )
261+ die (_ ("MIDX compaction endpoints must be unique" ));
262+
263+ for (m = from_midx ; m ; m = m -> base_midx ) {
264+ if (m == to_midx )
265+ die (_ ("MIDX %s must be an ancestor of %s" ), argv [0 ], argv [1 ]);
266+ }
267+
268+ ret = write_midx_file_compact (source , from_midx , to_midx , opts .flags );
269+
270+ return ret ;
271+ }
272+
197273static int cmd_multi_pack_index_verify (int argc , const char * * argv ,
198274 const char * prefix ,
199275 struct repository * repo UNUSED )
200276{
201277 struct option * options ;
202278 static struct option builtin_multi_pack_index_verify_options [] = {
203- OPT_BIT (0 , "progress" , & opts .flags ,
204- N_ ("force progress reporting" ), MIDX_PROGRESS ),
205279 OPT_END (),
206280 };
207281 struct odb_source * source ;
@@ -231,8 +305,6 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv,
231305{
232306 struct option * options ;
233307 static struct option builtin_multi_pack_index_expire_options [] = {
234- OPT_BIT (0 , "progress" , & opts .flags ,
235- N_ ("force progress reporting" ), MIDX_PROGRESS ),
236308 OPT_END (),
237309 };
238310 struct odb_source * source ;
@@ -264,8 +336,6 @@ static int cmd_multi_pack_index_repack(int argc, const char **argv,
264336 static struct option builtin_multi_pack_index_repack_options [] = {
265337 OPT_UNSIGNED (0 , "batch-size" , & opts .batch_size ,
266338 N_ ("during repack, collect pack-files of smaller size into a batch that is larger than this size" )),
267- OPT_BIT (0 , "progress" , & opts .flags ,
268- N_ ("force progress reporting" ), MIDX_PROGRESS ),
269339 OPT_END (),
270340 };
271341 struct odb_source * source ;
@@ -300,6 +370,7 @@ int cmd_multi_pack_index(int argc,
300370 struct option builtin_multi_pack_index_options [] = {
301371 OPT_SUBCOMMAND ("repack" , & fn , cmd_multi_pack_index_repack ),
302372 OPT_SUBCOMMAND ("write" , & fn , cmd_multi_pack_index_write ),
373+ OPT_SUBCOMMAND ("compact" , & fn , cmd_multi_pack_index_compact ),
303374 OPT_SUBCOMMAND ("verify" , & fn , cmd_multi_pack_index_verify ),
304375 OPT_SUBCOMMAND ("expire" , & fn , cmd_multi_pack_index_expire ),
305376 OPT_END (),
0 commit comments