@@ -1338,21 +1338,37 @@ 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
+ struct odb_source * prev_source = NULL ;
1350
+ const char * object_dir = r -> objects -> sources -> path ;
1351
+
1352
+ /* If set, use the shared object directory. */
1353
+ if (shared_object_dir ) {
1354
+ prev_source =
1355
+ odb_set_temporary_primary_source (r -> objects ,
1356
+ shared_object_dir , 0 );
1357
+ object_dir = shared_object_dir ;
1358
+ }
1347
1359
1348
1360
/*
1349
1361
* Do not start pack-objects process
1350
1362
* if there are no loose objects.
1351
1363
*/
1352
1364
if (!for_each_loose_file_in_source (r -> objects -> sources ,
1353
1365
bail_on_loose ,
1354
- NULL , NULL , NULL ))
1366
+ NULL , NULL , NULL )) {
1367
+ if (shared_object_dir )
1368
+ odb_restore_primary_source (r -> objects , prev_source ,
1369
+ shared_object_dir );
1355
1370
return 0 ;
1371
+ }
1356
1372
1357
1373
pack_proc .git_cmd = 1 ;
1358
1374
@@ -1361,7 +1377,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
1361
1377
strvec_push (& pack_proc .args , "--quiet" );
1362
1378
else
1363
1379
strvec_push (& pack_proc .args , "--no-quiet" );
1364
- strvec_pushf (& pack_proc .args , "%s/pack/loose" , r -> objects -> sources -> path );
1380
+ strvec_pushf (& pack_proc .args , "%s/pack/loose" , object_dir );
1365
1381
1366
1382
pack_proc .in = -1 ;
1367
1383
@@ -1373,6 +1389,9 @@ static int pack_loose(struct maintenance_run_opts *opts)
1373
1389
1374
1390
if (start_command (& pack_proc )) {
1375
1391
error (_ ("failed to start 'git pack-objects' process" ));
1392
+ if (shared_object_dir )
1393
+ odb_restore_primary_source (r -> objects , prev_source ,
1394
+ shared_object_dir );
1376
1395
return 1 ;
1377
1396
}
1378
1397
@@ -1400,6 +1419,10 @@ static int pack_loose(struct maintenance_run_opts *opts)
1400
1419
result = 1 ;
1401
1420
}
1402
1421
1422
+ if (shared_object_dir )
1423
+ odb_restore_primary_source (r -> objects , prev_source ,
1424
+ shared_object_dir );
1425
+
1403
1426
return result ;
1404
1427
}
1405
1428
@@ -1832,11 +1855,12 @@ static int task_option_parse(const struct option *opt,
1832
1855
}
1833
1856
1834
1857
static int maintenance_run (int argc , const char * * argv , const char * prefix ,
1835
- struct repository * repo UNUSED )
1858
+ struct repository * repo )
1836
1859
{
1837
1860
struct maintenance_run_opts opts = MAINTENANCE_RUN_OPTS_INIT ;
1838
1861
struct string_list selected_tasks = STRING_LIST_INIT_DUP ;
1839
1862
struct gc_config cfg = GC_CONFIG_INIT ;
1863
+ const char * tmp_obj_dir = NULL ;
1840
1864
struct option builtin_maintenance_run_options [] = {
1841
1865
OPT_BOOL (0 , "auto" , & opts .auto_flag ,
1842
1866
N_ ("run tasks based on the state of the repository" )),
@@ -1873,6 +1897,17 @@ static int maintenance_run(int argc, const char **argv, const char *prefix,
1873
1897
usage_with_options (builtin_maintenance_run_usage ,
1874
1898
builtin_maintenance_run_options );
1875
1899
1900
+ /*
1901
+ * To enable the VFS for Git/Scalar shared object cache, use
1902
+ * the gvfs.sharedcache config option to redirect the
1903
+ * maintenance to that location.
1904
+ */
1905
+ if (!repo_config_get_value (repo , "gvfs.sharedcache" , & tmp_obj_dir ) &&
1906
+ tmp_obj_dir ) {
1907
+ shared_object_dir = xstrdup (tmp_obj_dir );
1908
+ setenv (DB_ENVIRONMENT , shared_object_dir , 1 );
1909
+ }
1910
+
1876
1911
ret = maintenance_run_tasks (& opts , & cfg );
1877
1912
1878
1913
string_list_clear (& selected_tasks , 0 );
0 commit comments