@@ -1357,21 +1357,37 @@ static int write_loose_object_to_stdin(const struct object_id *oid,
13571357 return ++ (d -> count ) > d -> batch_size ;
13581358}
13591359
1360+ static const char * shared_object_dir = NULL ;
1361+
13601362static int pack_loose (struct maintenance_run_opts * opts )
13611363{
13621364 struct repository * r = the_repository ;
13631365 int result = 0 ;
13641366 struct write_loose_object_data data ;
13651367 struct child_process pack_proc = CHILD_PROCESS_INIT ;
1368+ struct odb_source * prev_source = NULL ;
1369+ const char * object_dir = r -> objects -> sources -> path ;
1370+
1371+ /* If set, use the shared object directory. */
1372+ if (shared_object_dir ) {
1373+ prev_source =
1374+ odb_set_temporary_primary_source (r -> objects ,
1375+ shared_object_dir , 0 );
1376+ object_dir = shared_object_dir ;
1377+ }
13661378
13671379 /*
13681380 * Do not start pack-objects process
13691381 * if there are no loose objects.
13701382 */
13711383 if (!for_each_loose_file_in_source (r -> objects -> sources ,
13721384 bail_on_loose ,
1373- NULL , NULL , NULL ))
1385+ NULL , NULL , NULL )) {
1386+ if (shared_object_dir )
1387+ odb_restore_primary_source (r -> objects , prev_source ,
1388+ shared_object_dir );
13741389 return 0 ;
1390+ }
13751391
13761392 pack_proc .git_cmd = 1 ;
13771393
@@ -1380,7 +1396,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
13801396 strvec_push (& pack_proc .args , "--quiet" );
13811397 else
13821398 strvec_push (& pack_proc .args , "--no-quiet" );
1383- strvec_pushf (& pack_proc .args , "%s/pack/loose" , r -> objects -> sources -> path );
1399+ strvec_pushf (& pack_proc .args , "%s/pack/loose" , object_dir );
13841400
13851401 pack_proc .in = -1 ;
13861402
@@ -1392,6 +1408,9 @@ static int pack_loose(struct maintenance_run_opts *opts)
13921408
13931409 if (start_command (& pack_proc )) {
13941410 error (_ ("failed to start 'git pack-objects' process" ));
1411+ if (shared_object_dir )
1412+ odb_restore_primary_source (r -> objects , prev_source ,
1413+ shared_object_dir );
13951414 return 1 ;
13961415 }
13971416
@@ -1419,6 +1438,10 @@ static int pack_loose(struct maintenance_run_opts *opts)
14191438 result = 1 ;
14201439 }
14211440
1441+ if (shared_object_dir )
1442+ odb_restore_primary_source (r -> objects , prev_source ,
1443+ shared_object_dir );
1444+
14221445 return result ;
14231446}
14241447
@@ -2036,11 +2059,12 @@ static int task_option_parse(const struct option *opt,
20362059}
20372060
20382061static int maintenance_run (int argc , const char * * argv , const char * prefix ,
2039- struct repository * repo UNUSED )
2062+ struct repository * repo )
20402063{
20412064 struct maintenance_run_opts opts = MAINTENANCE_RUN_OPTS_INIT ;
20422065 struct string_list selected_tasks = STRING_LIST_INIT_DUP ;
20432066 struct gc_config cfg = GC_CONFIG_INIT ;
2067+ const char * tmp_obj_dir = NULL ;
20442068 struct option builtin_maintenance_run_options [] = {
20452069 OPT_BOOL (0 , "auto" , & opts .auto_flag ,
20462070 N_ ("run tasks based on the state of the repository" )),
@@ -2077,6 +2101,17 @@ static int maintenance_run(int argc, const char **argv, const char *prefix,
20772101 usage_with_options (builtin_maintenance_run_usage ,
20782102 builtin_maintenance_run_options );
20792103
2104+ /*
2105+ * To enable the VFS for Git/Scalar shared object cache, use
2106+ * the gvfs.sharedcache config option to redirect the
2107+ * maintenance to that location.
2108+ */
2109+ if (!repo_config_get_value (repo , "gvfs.sharedcache" , & tmp_obj_dir ) &&
2110+ tmp_obj_dir ) {
2111+ shared_object_dir = xstrdup (tmp_obj_dir );
2112+ setenv (DB_ENVIRONMENT , shared_object_dir , 1 );
2113+ }
2114+
20802115 ret = maintenance_run_tasks (& opts , & cfg );
20812116
20822117 string_list_clear (& selected_tasks , 0 );
0 commit comments