@@ -65,12 +65,20 @@ static int parse_object_dir(const struct option *opt, const char *arg,
6565 char * * value = opt -> value ;
6666 free (* value );
6767 if (unset )
68- * value = xstrdup (repo_get_object_directory ( the_repository ) );
68+ * value = xstrdup (the_repository -> objects -> sources -> path );
6969 else
7070 * value = real_pathdup (arg , 1 );
7171 return 0 ;
7272}
7373
74+ static struct odb_source * handle_object_dir_option (struct repository * repo )
75+ {
76+ struct odb_source * source = odb_find_source (repo -> objects , opts .object_dir );
77+ if (!source )
78+ source = odb_add_to_alternates_memory (repo -> objects , opts .object_dir );
79+ return source ;
80+ }
81+
7482static struct option common_opts [] = {
7583 OPT_CALLBACK (0 , "object-dir" , & opts .object_dir ,
7684 N_ ("directory" ),
@@ -140,6 +148,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
140148 N_ ("refs snapshot for selecting bitmap commits" )),
141149 OPT_END (),
142150 };
151+ struct odb_source * source ;
143152 int ret ;
144153
145154 opts .flags |= MIDX_WRITE_BITMAP_HASH_CACHE ;
@@ -158,6 +167,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
158167 if (argc )
159168 usage_with_options (builtin_multi_pack_index_write_usage ,
160169 options );
170+ source = handle_object_dir_option (repo );
161171
162172 FREE_AND_NULL (options );
163173
@@ -166,7 +176,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
166176
167177 read_packs_from_stdin (& packs );
168178
169- ret = write_midx_file_only (repo , opts . object_dir , & packs ,
179+ ret = write_midx_file_only (source , & packs ,
170180 opts .preferred_pack ,
171181 opts .refs_snapshot , opts .flags );
172182
@@ -177,7 +187,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
177187
178188 }
179189
180- ret = write_midx_file (repo , opts . object_dir , opts .preferred_pack ,
190+ ret = write_midx_file (source , opts .preferred_pack ,
181191 opts .refs_snapshot , opts .flags );
182192
183193 free (opts .refs_snapshot );
@@ -194,6 +204,8 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv,
194204 N_ ("force progress reporting" ), MIDX_PROGRESS ),
195205 OPT_END (),
196206 };
207+ struct odb_source * source ;
208+
197209 options = add_common_options (builtin_multi_pack_index_verify_options );
198210
199211 trace2_cmd_mode (argv [0 ]);
@@ -206,10 +218,11 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv,
206218 if (argc )
207219 usage_with_options (builtin_multi_pack_index_verify_usage ,
208220 options );
221+ source = handle_object_dir_option (the_repository );
209222
210223 FREE_AND_NULL (options );
211224
212- return verify_midx_file (the_repository , opts . object_dir , opts .flags );
225+ return verify_midx_file (source , opts .flags );
213226}
214227
215228static int cmd_multi_pack_index_expire (int argc , const char * * argv ,
@@ -222,6 +235,8 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv,
222235 N_ ("force progress reporting" ), MIDX_PROGRESS ),
223236 OPT_END (),
224237 };
238+ struct odb_source * source ;
239+
225240 options = add_common_options (builtin_multi_pack_index_expire_options );
226241
227242 trace2_cmd_mode (argv [0 ]);
@@ -234,10 +249,11 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv,
234249 if (argc )
235250 usage_with_options (builtin_multi_pack_index_expire_usage ,
236251 options );
252+ source = handle_object_dir_option (the_repository );
237253
238254 FREE_AND_NULL (options );
239255
240- return expire_midx_packs (the_repository , opts . object_dir , opts .flags );
256+ return expire_midx_packs (source , opts .flags );
241257}
242258
243259static int cmd_multi_pack_index_repack (int argc , const char * * argv ,
@@ -252,6 +268,7 @@ static int cmd_multi_pack_index_repack(int argc, const char **argv,
252268 N_ ("force progress reporting" ), MIDX_PROGRESS ),
253269 OPT_END (),
254270 };
271+ struct odb_source * source ;
255272
256273 options = add_common_options (builtin_multi_pack_index_repack_options );
257274
@@ -266,11 +283,11 @@ static int cmd_multi_pack_index_repack(int argc, const char **argv,
266283 if (argc )
267284 usage_with_options (builtin_multi_pack_index_repack_usage ,
268285 options );
286+ source = handle_object_dir_option (the_repository );
269287
270288 FREE_AND_NULL (options );
271289
272- return midx_repack (the_repository , opts .object_dir ,
273- (size_t )opts .batch_size , opts .flags );
290+ return midx_repack (source , (size_t )opts .batch_size , opts .flags );
274291}
275292
276293int cmd_multi_pack_index (int argc ,
0 commit comments