@@ -1338,18 +1338,25 @@ static int write_loose_object_to_stdin(const struct object_id *oid,
1338
1338
return ++ (d -> count ) > d -> batch_size ;
1339
1339
}
1340
1340
1341
+ static const char * shared_object_dir = NULL ;
1342
+
1341
1343
static int pack_loose (struct maintenance_run_opts * opts )
1342
1344
{
1343
1345
struct repository * r = the_repository ;
1344
1346
int result = 0 ;
1345
1347
struct write_loose_object_data data ;
1346
1348
struct child_process pack_proc = CHILD_PROCESS_INIT ;
1349
+ const char * object_dir = r -> objects -> sources -> path ;
1350
+
1351
+ /* If set, use the shared object directory. */
1352
+ if (shared_object_dir )
1353
+ object_dir = shared_object_dir ;
1347
1354
1348
1355
/*
1349
1356
* Do not start pack-objects process
1350
1357
* if there are no loose objects.
1351
1358
*/
1352
- if (!for_each_loose_file_in_objdir (r -> objects -> sources -> path ,
1359
+ if (!for_each_loose_file_in_objdir (object_dir ,
1353
1360
bail_on_loose ,
1354
1361
NULL , NULL , NULL ))
1355
1362
return 0 ;
@@ -1361,7 +1368,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
1361
1368
strvec_push (& pack_proc .args , "--quiet" );
1362
1369
else
1363
1370
strvec_push (& pack_proc .args , "--no-quiet" );
1364
- strvec_pushf (& pack_proc .args , "%s/pack/loose" , r -> objects -> sources -> path );
1371
+ strvec_pushf (& pack_proc .args , "%s/pack/loose" , object_dir );
1365
1372
1366
1373
pack_proc .in = -1 ;
1367
1374
@@ -1389,7 +1396,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
1389
1396
else if (data .batch_size > 0 )
1390
1397
data .batch_size -- ; /* Decrease for equality on limit. */
1391
1398
1392
- for_each_loose_file_in_objdir (r -> objects -> sources -> path ,
1399
+ for_each_loose_file_in_objdir (object_dir ,
1393
1400
write_loose_object_to_stdin ,
1394
1401
NULL ,
1395
1402
NULL ,
@@ -1834,11 +1841,12 @@ static int task_option_parse(const struct option *opt,
1834
1841
}
1835
1842
1836
1843
static int maintenance_run (int argc , const char * * argv , const char * prefix ,
1837
- struct repository * repo UNUSED )
1844
+ struct repository * repo )
1838
1845
{
1839
1846
struct maintenance_run_opts opts = MAINTENANCE_RUN_OPTS_INIT ;
1840
1847
struct string_list selected_tasks = STRING_LIST_INIT_DUP ;
1841
1848
struct gc_config cfg = GC_CONFIG_INIT ;
1849
+ const char * tmp_obj_dir = NULL ;
1842
1850
struct option builtin_maintenance_run_options [] = {
1843
1851
OPT_BOOL (0 , "auto" , & opts .auto_flag ,
1844
1852
N_ ("run tasks based on the state of the repository" )),
@@ -1875,6 +1883,17 @@ static int maintenance_run(int argc, const char **argv, const char *prefix,
1875
1883
usage_with_options (builtin_maintenance_run_usage ,
1876
1884
builtin_maintenance_run_options );
1877
1885
1886
+ /*
1887
+ * To enable the VFS for Git/Scalar shared object cache, use
1888
+ * the gvfs.sharedcache config option to redirect the
1889
+ * maintenance to that location.
1890
+ */
1891
+ if (!repo_config_get_value (repo , "gvfs.sharedcache" , & tmp_obj_dir ) &&
1892
+ tmp_obj_dir ) {
1893
+ shared_object_dir = xstrdup (tmp_obj_dir );
1894
+ setenv (DB_ENVIRONMENT , shared_object_dir , 1 );
1895
+ }
1896
+
1878
1897
ret = maintenance_run_tasks (& opts , & cfg );
1879
1898
1880
1899
string_list_clear (& selected_tasks , 0 );
0 commit comments