@@ -138,6 +138,47 @@ static void remove_redundant_pack(const char *dir_name, const char *base_name)
138138 strbuf_release (& buf );
139139}
140140
141+ struct pack_objects_args {
142+ const char * window ;
143+ const char * window_memory ;
144+ const char * depth ;
145+ const char * threads ;
146+ const char * max_pack_size ;
147+ int no_reuse_delta ;
148+ int no_reuse_object ;
149+ int quiet ;
150+ int local ;
151+ };
152+
153+ static void prepare_pack_objects (struct child_process * cmd ,
154+ const struct pack_objects_args * args )
155+ {
156+ argv_array_push (& cmd -> args , "pack-objects" );
157+ if (args -> window )
158+ argv_array_pushf (& cmd -> args , "--window=%s" , args -> window );
159+ if (args -> window_memory )
160+ argv_array_pushf (& cmd -> args , "--window-memory=%s" , args -> window_memory );
161+ if (args -> depth )
162+ argv_array_pushf (& cmd -> args , "--depth=%s" , args -> depth );
163+ if (args -> threads )
164+ argv_array_pushf (& cmd -> args , "--threads=%s" , args -> threads );
165+ if (args -> max_pack_size )
166+ argv_array_pushf (& cmd -> args , "--max-pack-size=%s" , args -> max_pack_size );
167+ if (args -> no_reuse_delta )
168+ argv_array_pushf (& cmd -> args , "--no-reuse-delta" );
169+ if (args -> no_reuse_object )
170+ argv_array_pushf (& cmd -> args , "--no-reuse-object" );
171+ if (args -> local )
172+ argv_array_push (& cmd -> args , "--local" );
173+ if (args -> quiet )
174+ argv_array_push (& cmd -> args , "--quiet" );
175+ if (delta_base_offset )
176+ argv_array_push (& cmd -> args , "--delta-base-offset" );
177+ argv_array_push (& cmd -> args , packtmp );
178+ cmd -> git_cmd = 1 ;
179+ cmd -> out = -1 ;
180+ }
181+
141182#define ALL_INTO_ONE 1
142183#define LOOSEN_UNREACHABLE 2
143184
@@ -165,15 +206,9 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
165206 int delete_redundant = 0 ;
166207 const char * unpack_unreachable = NULL ;
167208 int keep_unreachable = 0 ;
168- const char * window = NULL , * window_memory = NULL ;
169- const char * depth = NULL ;
170- const char * threads = NULL ;
171- const char * max_pack_size = NULL ;
172209 struct string_list keep_pack_list = STRING_LIST_INIT_NODUP ;
173- int no_reuse_delta = 0 , no_reuse_object = 0 ;
174210 int no_update_server_info = 0 ;
175- int quiet = 0 ;
176- int local = 0 ;
211+ struct pack_objects_args po_args = {NULL };
177212
178213 struct option builtin_repack_options [] = {
179214 OPT_BIT ('a' , NULL , & pack_everything ,
@@ -183,30 +218,30 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
183218 LOOSEN_UNREACHABLE | ALL_INTO_ONE ),
184219 OPT_BOOL ('d' , NULL , & delete_redundant ,
185220 N_ ("remove redundant packs, and run git-prune-packed" )),
186- OPT_BOOL ('f' , NULL , & no_reuse_delta ,
221+ OPT_BOOL ('f' , NULL , & po_args . no_reuse_delta ,
187222 N_ ("pass --no-reuse-delta to git-pack-objects" )),
188- OPT_BOOL ('F' , NULL , & no_reuse_object ,
223+ OPT_BOOL ('F' , NULL , & po_args . no_reuse_object ,
189224 N_ ("pass --no-reuse-object to git-pack-objects" )),
190225 OPT_BOOL ('n' , NULL , & no_update_server_info ,
191226 N_ ("do not run git-update-server-info" )),
192- OPT__QUIET (& quiet , N_ ("be quiet" )),
193- OPT_BOOL ('l' , "local" , & local ,
227+ OPT__QUIET (& po_args . quiet , N_ ("be quiet" )),
228+ OPT_BOOL ('l' , "local" , & po_args . local ,
194229 N_ ("pass --local to git-pack-objects" )),
195230 OPT_BOOL ('b' , "write-bitmap-index" , & write_bitmaps ,
196231 N_ ("write bitmap index" )),
197232 OPT_STRING (0 , "unpack-unreachable" , & unpack_unreachable , N_ ("approxidate" ),
198233 N_ ("with -A, do not loosen objects older than this" )),
199234 OPT_BOOL ('k' , "keep-unreachable" , & keep_unreachable ,
200235 N_ ("with -a, repack unreachable objects" )),
201- OPT_STRING (0 , "window" , & window , N_ ("n" ),
236+ OPT_STRING (0 , "window" , & po_args . window , N_ ("n" ),
202237 N_ ("size of the window used for delta compression" )),
203- OPT_STRING (0 , "window-memory" , & window_memory , N_ ("bytes" ),
238+ OPT_STRING (0 , "window-memory" , & po_args . window_memory , N_ ("bytes" ),
204239 N_ ("same as the above, but limit memory size instead of entries count" )),
205- OPT_STRING (0 , "depth" , & depth , N_ ("n" ),
240+ OPT_STRING (0 , "depth" , & po_args . depth , N_ ("n" ),
206241 N_ ("limits the maximum delta depth" )),
207- OPT_STRING (0 , "threads" , & threads , N_ ("n" ),
242+ OPT_STRING (0 , "threads" , & po_args . threads , N_ ("n" ),
208243 N_ ("limits the maximum number of threads" )),
209- OPT_STRING (0 , "max-pack-size" , & max_pack_size , N_ ("bytes" ),
244+ OPT_STRING (0 , "max-pack-size" , & po_args . max_pack_size , N_ ("bytes" ),
210245 N_ ("maximum size of each packfile" )),
211246 OPT_BOOL (0 , "pack-kept-objects" , & pack_kept_objects ,
212247 N_ ("repack objects in packs marked with .keep" )),
@@ -238,7 +273,8 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
238273
239274 sigchain_push_common (remove_pack_on_signal );
240275
241- argv_array_push (& cmd .args , "pack-objects" );
276+ prepare_pack_objects (& cmd , & po_args );
277+
242278 argv_array_push (& cmd .args , "--keep-true-parents" );
243279 if (!pack_kept_objects )
244280 argv_array_push (& cmd .args , "--honor-pack-keep" );
@@ -251,20 +287,6 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
251287 argv_array_push (& cmd .args , "--indexed-objects" );
252288 if (repository_format_partial_clone )
253289 argv_array_push (& cmd .args , "--exclude-promisor-objects" );
254- if (window )
255- argv_array_pushf (& cmd .args , "--window=%s" , window );
256- if (window_memory )
257- argv_array_pushf (& cmd .args , "--window-memory=%s" , window_memory );
258- if (depth )
259- argv_array_pushf (& cmd .args , "--depth=%s" , depth );
260- if (threads )
261- argv_array_pushf (& cmd .args , "--threads=%s" , threads );
262- if (max_pack_size )
263- argv_array_pushf (& cmd .args , "--max-pack-size=%s" , max_pack_size );
264- if (no_reuse_delta )
265- argv_array_pushf (& cmd .args , "--no-reuse-delta" );
266- if (no_reuse_object )
267- argv_array_pushf (& cmd .args , "--no-reuse-object" );
268290 if (write_bitmaps )
269291 argv_array_push (& cmd .args , "--write-bitmap-index" );
270292
@@ -292,17 +314,6 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
292314 argv_array_push (& cmd .args , "--incremental" );
293315 }
294316
295- if (local )
296- argv_array_push (& cmd .args , "--local" );
297- if (quiet )
298- argv_array_push (& cmd .args , "--quiet" );
299- if (delta_base_offset )
300- argv_array_push (& cmd .args , "--delta-base-offset" );
301-
302- argv_array_push (& cmd .args , packtmp );
303-
304- cmd .git_cmd = 1 ;
305- cmd .out = -1 ;
306317 cmd .no_stdin = 1 ;
307318
308319 ret = start_command (& cmd );
@@ -320,7 +331,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
320331 if (ret )
321332 return ret ;
322333
323- if (!names .nr && !quiet )
334+ if (!names .nr && !po_args . quiet )
324335 printf ("Nothing new to pack.\n" );
325336
326337 /*
@@ -441,7 +452,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
441452 if (!string_list_has_string (& names , sha1 ))
442453 remove_redundant_pack (packdir , item -> string );
443454 }
444- if (!quiet && isatty (2 ))
455+ if (!po_args . quiet && isatty (2 ))
445456 opts |= PRUNE_PACKED_VERBOSE ;
446457 prune_packed_objects (opts );
447458 }
0 commit comments