Skip to content

Commit 363a2d1

Browse files
committed
Auto merge of #13187 - weihanglo:git-paths, r=ehuss
refactor: centralize git checkouts and db paths
2 parents 53eb9a2 + 0a4ce46 commit 363a2d1

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

src/cargo/core/global_cache_tracker.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -560,11 +560,10 @@ impl GlobalCacheTracker {
560560
) -> CargoResult<()> {
561561
let _p = crate::util::profile::start("cleaning global cache files");
562562
let config = clean_ctx.config;
563-
let base_git_path = config.git_path().into_path_unlocked();
564563
let base = BasePaths {
565564
index: config.registry_index_path().into_path_unlocked(),
566-
git_db: base_git_path.join("db"),
567-
git_co: base_git_path.join("checkouts"),
565+
git_db: config.git_db_path().into_path_unlocked(),
566+
git_co: config.git_checkouts_path().into_path_unlocked(),
568567
crate_dir: config.registry_cache_path().into_path_unlocked(),
569568
src: config.registry_source_path().into_path_unlocked(),
570569
};

src/cargo/sources/git/source.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@ impl<'cfg> Source for GitSource<'cfg> {
248248
// exists.
249249
exclude_from_backups_and_indexing(&git_path);
250250

251-
let db_path = git_path.join("db").join(&self.ident);
251+
let db_path = self.config.git_db_path().join(&self.ident);
252+
let db_path = db_path.into_path_unlocked();
252253

253254
let db = self.remote.db_at(&db_path).ok();
254255
let (db, actual_rev) = match (self.locked_rev, db) {
@@ -305,10 +306,12 @@ impl<'cfg> Source for GitSource<'cfg> {
305306
// Check out `actual_rev` from the database to a scoped location on the
306307
// filesystem. This will use hard links and such to ideally make the
307308
// checkout operation here pretty fast.
308-
let checkout_path = git_path
309-
.join("checkouts")
309+
let checkout_path = self
310+
.config
311+
.git_checkouts_path()
310312
.join(&self.ident)
311313
.join(short_id.as_str());
314+
let checkout_path = checkout_path.into_path_unlocked();
312315
db.copy_to(actual_rev, &checkout_path, self.config)?;
313316

314317
let source_id = self

src/cargo/util/config/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,18 @@ impl Config {
368368
self.home_path.join("git")
369369
}
370370

371+
/// Gets the directory of code sources Cargo checkouts from Git bare repos
372+
/// (`<cargo_home>/git/checkouts`).
373+
pub fn git_checkouts_path(&self) -> Filesystem {
374+
self.git_path().join("checkouts")
375+
}
376+
377+
/// Gets the directory for all Git bare repos Cargo clones
378+
/// (`<cargo_home>/git/db`).
379+
pub fn git_db_path(&self) -> Filesystem {
380+
self.git_path().join("db")
381+
}
382+
371383
/// Gets the Cargo base directory for all registry information (`<cargo_home>/registry`).
372384
pub fn registry_base_path(&self) -> Filesystem {
373385
self.home_path.join("registry")

0 commit comments

Comments
 (0)