Skip to content

Commit f101fa0

Browse files
committed
Auto merge of #13055 - ehuss:document-more-gc-fields, r=epage
Add more doc comments for gc changes. I missed adding these in #12634.
2 parents 2d1c64b + 6950059 commit f101fa0

File tree

6 files changed

+42
-8
lines changed

6 files changed

+42
-8
lines changed

src/cargo/core/global_cache_tracker.rs

+18-8
Original file line numberDiff line numberDiff line change
@@ -154,43 +154,53 @@ type Timestamp = u64;
154154
/// The key for a registry index entry stored in the database.
155155
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
156156
pub struct RegistryIndex {
157+
/// A unique name of the registry source.
157158
pub encoded_registry_name: InternedString,
158159
}
159160

160161
/// The key for a registry `.crate` entry stored in the database.
161162
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
162163
pub struct RegistryCrate {
164+
/// A unique name of the registry source.
163165
pub encoded_registry_name: InternedString,
166+
/// The filename of the compressed crate, like `foo-1.2.3.crate`.
164167
pub crate_filename: InternedString,
168+
/// The size of the `.crate` file.
165169
pub size: u64,
166170
}
167171

168172
/// The key for a registry src directory entry stored in the database.
169173
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
170174
pub struct RegistrySrc {
175+
/// A unique name of the registry source.
171176
pub encoded_registry_name: InternedString,
177+
/// The directory name of the extracted source, like `foo-1.2.3`.
172178
pub package_dir: InternedString,
173-
// Total size of the src directory in bytes.
174-
//
175-
// This can be None when the size is unknown. For example, when the src
176-
// directory already exists on disk, and we just want to update the
177-
// last-use timestamp. We don't want to take the expense of computing disk
178-
// usage unless necessary. `populate_untracked_src` will handle any actual
179-
// NULL values in the database, which can happen when the src directory is
180-
// created by an older version of cargo that did not track sizes.
179+
/// Total size of the src directory in bytes.
180+
///
181+
/// This can be None when the size is unknown. For example, when the src
182+
/// directory already exists on disk, and we just want to update the
183+
/// last-use timestamp. We don't want to take the expense of computing disk
184+
/// usage unless necessary. [`GlobalCacheTracker::populate_untracked`]
185+
/// will handle any actual NULL values in the database, which can happen
186+
/// when the src directory is created by an older version of cargo that
187+
/// did not track sizes.
181188
pub size: Option<u64>,
182189
}
183190

184191
/// The key for a git db entry stored in the database.
185192
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
186193
pub struct GitDb {
194+
/// A unique name of the git database.
187195
pub encoded_git_name: InternedString,
188196
}
189197

190198
/// The key for a git checkout entry stored in the database.
191199
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
192200
pub struct GitCheckout {
201+
/// A unique name of the git database.
193202
pub encoded_git_name: InternedString,
203+
/// A unique name of the checkout without the database.
194204
pub short_name: InternedString,
195205
/// Total size of the checkout directory.
196206
///

src/cargo/sources/git/source.rs

+10
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,17 @@ pub struct GitSource<'cfg> {
7676
/// The unique identifier of this source.
7777
source_id: SourceId,
7878
/// The underlying path source to discover packages inside the Git repository.
79+
///
80+
/// This gets set to `Some` after the git repo has been checked out
81+
/// (automatically handled via [`GitSource::block_until_ready`]).
7982
path_source: Option<PathSource<'cfg>>,
83+
/// A short string that uniquely identifies the version of the checkout.
84+
///
85+
/// This is typically a 7-character string of the OID hash, automatically
86+
/// increasing in size if it is ambiguous.
87+
///
88+
/// This is set to `Some` after the git repo has been checked out
89+
/// (automatically handled via [`GitSource::block_until_ready`]).
8090
short_id: Option<InternedString>,
8191
/// The identifier of this source for Cargo's Git cache directory.
8292
/// See [`ident`] for more.

src/cargo/sources/registry/http_remote.rs

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ const UNKNOWN: &'static str = "Unknown";
5454
///
5555
/// [RFC 2789]: https://github.com/rust-lang/rfcs/pull/2789
5656
pub struct HttpRegistry<'cfg> {
57+
/// The name of this source, a unique string (across all sources) used as
58+
/// the directory name where its cached content is stored.
5759
name: InternedString,
5860
/// Path to the registry index (`$CARGO_HOME/registry/index/$REG-HASH`).
5961
///

src/cargo/sources/registry/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@ struct LockMetadata {
240240
///
241241
/// For general concepts of registries, see the [module-level documentation](crate::sources::registry).
242242
pub struct RegistrySource<'cfg> {
243+
/// A unique name of the source (typically used as the directory name
244+
/// where its cached content is stored).
243245
name: InternedString,
244246
/// The unique identifier of this source.
245247
source_id: SourceId,
@@ -444,6 +446,11 @@ mod remote;
444446
/// Generates a unique name for [`SourceId`] to have a unique path to put their
445447
/// index files.
446448
fn short_name(id: SourceId, is_shallow: bool) -> String {
449+
// CAUTION: This should not change between versions. If you change how
450+
// this is computed, it will orphan previously cached data, forcing the
451+
// cache to be rebuilt and potentially wasting significant disk space. If
452+
// you change it, be cautious of the impact. See `test_cratesio_hash` for
453+
// a similar discussion.
447454
let hash = hex::short_hash(&id);
448455
let ident = id.url().host_str().unwrap_or("").to_string();
449456
let mut name = format!("{}-{}", ident, hash);

src/cargo/sources/registry/remote.rs

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ use tracing::{debug, trace};
4848
///
4949
/// [`HttpRegistry`]: super::http_remote::HttpRegistry
5050
pub struct RemoteRegistry<'cfg> {
51+
/// The name of this source, a unique string (across all sources) used as
52+
/// the directory name where its cached content is stored.
5153
name: InternedString,
5254
/// Path to the registry index (`$CARGO_HOME/registry/index/$REG-HASH`).
5355
index_path: Filesystem,

src/cargo/util/config/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,10 @@ pub struct Config {
245245
pub nightly_features_allowed: bool,
246246
/// WorkspaceRootConfigs that have been found
247247
pub ws_roots: RefCell<HashMap<PathBuf, WorkspaceRootConfig>>,
248+
/// The global cache tracker is a database used to track disk cache usage.
248249
global_cache_tracker: LazyCell<RefCell<GlobalCacheTracker>>,
250+
/// A cache of modifications to make to [`Config::global_cache_tracker`],
251+
/// saved to disk in a batch to improve performance.
249252
deferred_global_last_use: LazyCell<RefCell<DeferredGlobalLastUse>>,
250253
}
251254

0 commit comments

Comments
 (0)