Skip to content

Commit 5b14e6e

Browse files
committed
refactor(package): add comments
1 parent b033b97 commit 5b14e6e

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

src/cargo/ops/cargo_package/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ enum GeneratedFile {
7979
Manifest,
8080
/// Generates `Cargo.lock` in some cases (like if there is a binary).
8181
Lockfile,
82-
/// Adds a `.cargo_vcs_info.json` file if in a (clean) git repo.
82+
/// Adds a `.cargo_vcs_info.json` file if in a git repo.
8383
VcsInfo(vcs::VcsInfo),
8484
}
8585

src/cargo/ops/cargo_package/vcs.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Helpers to gather the VCS information for `cargo package`.
2+
13
use std::path::Path;
24
use std::path::PathBuf;
35

@@ -12,13 +14,15 @@ use crate::GlobalContext;
1214

1315
use super::PackageOpts;
1416

17+
/// Represents the VCS information when packaging.
1518
#[derive(Serialize)]
1619
pub struct VcsInfo {
1720
git: GitVcsInfo,
18-
/// Path to the package within repo (empty string if root). / not \
21+
/// Path to the package within repo (empty string if root).
1922
path_in_vcs: String,
2023
}
2124

25+
/// Represents the Git VCS information when packaging.
2226
#[derive(Serialize)]
2327
pub struct GitVcsInfo {
2428
sha1: String,
@@ -27,11 +31,13 @@ pub struct GitVcsInfo {
2731
dirty: bool,
2832
}
2933

30-
/// Checks if the package source is in a *git* DVCS repository. If *git*, and
31-
/// the source is *dirty* (e.g., has uncommitted changes), and `--allow-dirty`
32-
/// has not been passed, then `bail!` with an informative message. Otherwise
33-
/// return the sha1 hash of the current *HEAD* commit, or `None` if no repo is
34-
/// found.
34+
/// Checks if the package source is in a *git* DVCS repository.
35+
///
36+
/// If *git*, and the source is *dirty* (e.g., has uncommitted changes),
37+
/// and `--allow-dirty` has not been passed,
38+
/// then `bail!` with an informative message.
39+
/// Otherwise return the sha1 hash of the current *HEAD* commit,
40+
/// or `None` if no repo is found.
3541
#[tracing::instrument(skip_all)]
3642
pub fn check_repo_state(
3743
p: &Package,
@@ -104,6 +110,7 @@ pub fn check_repo_state(
104110
return Ok(Some(VcsInfo { git, path_in_vcs }));
105111
}
106112

113+
/// The real git status check starts from here.
107114
fn git(
108115
pkg: &Package,
109116
gctx: &GlobalContext,

src/cargo/ops/cargo_package/verify.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Helpers to verify a packaged `.crate` file.
2+
13
use std::collections::HashMap;
24
use std::fs;
35
use std::fs::File;
@@ -29,6 +31,7 @@ use crate::CargoResult;
2931
use super::PackageOpts;
3032
use super::TmpRegistry;
3133

34+
/// Verifies whether a `.crate` file is able to compile.
3235
pub fn run_verify(
3336
ws: &Workspace<'_>,
3437
pkg: &Package,
@@ -123,6 +126,11 @@ pub fn run_verify(
123126
Ok(())
124127
}
125128

129+
/// Hashes everything under a given directory.
130+
///
131+
/// This is for checking if any source file inside a `.crate` file has changed
132+
/// durint the compilation. It is usually caused by bad build scripts or proc
133+
/// macros trying to modify source files. Cargo disallows that.
126134
fn hash_all(path: &Path) -> CargoResult<HashMap<PathBuf, u64>> {
127135
fn wrap(path: &Path) -> CargoResult<HashMap<PathBuf, u64>> {
128136
let mut result = HashMap::new();
@@ -148,6 +156,7 @@ fn hash_all(path: &Path) -> CargoResult<HashMap<PathBuf, u64>> {
148156
Ok(result)
149157
}
150158

159+
/// Reports the hash difference before and after the compilation computed by [`hash_all`].
151160
fn report_hash_difference(orig: &HashMap<PathBuf, u64>, after: &HashMap<PathBuf, u64>) -> String {
152161
let mut changed = Vec::new();
153162
let mut removed = Vec::new();

0 commit comments

Comments
 (0)