From e7bfed103cdb31f2b65b2f8ba576405e268e9b98 Mon Sep 17 00:00:00 2001 From: Tor Hovland <55164+torhovland@users.noreply.github.com> Date: Mon, 3 Jun 2024 10:09:33 +0200 Subject: [PATCH] Skip serializing the dirty flag if false. --- src/cargo/ops/cargo_package.rs | 1 + src/doc/man/cargo-package.md | 4 ++-- src/doc/man/generated_txt/cargo-package.txt | 8 ++++---- src/doc/src/commands/cargo-package.md | 4 ++-- src/etc/man/cargo-package.1 | 4 ++-- tests/testsuite/package.rs | 9 +++------ 6 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/cargo/ops/cargo_package.rs b/src/cargo/ops/cargo_package.rs index 26934de509f..e5821867f8a 100644 --- a/src/cargo/ops/cargo_package.rs +++ b/src/cargo/ops/cargo_package.rs @@ -82,6 +82,7 @@ struct VcsInfo { struct GitVcsInfo { sha1: String, /// Indicate whether or not the Git worktree is dirty. + #[serde(skip_serializing_if = "std::ops::Not::not")] dirty: bool, } diff --git a/src/doc/man/cargo-package.md b/src/doc/man/cargo-package.md index 20bbda9396f..42fa2366b83 100644 --- a/src/doc/man/cargo-package.md +++ b/src/doc/man/cargo-package.md @@ -31,7 +31,7 @@ steps: executable binary or example target. {{man "cargo-install" 1}} will use the packaged lock file if the `--locked` flag is used. - A `.cargo_vcs_info.json` file is included that contains information - about the current VCS checkout hash if available, and whether or not the + about the current VCS checkout hash if available, as well as a flag if the worktree is dirty. 3. Extract the `.crate` file and build it to verify it can build. - This will rebuild your package from scratch to ensure that it can be @@ -59,7 +59,7 @@ Will generate a `.cargo_vcs_info.json` in the following format } ``` -`dirty` indicates whether or not the Git worktree was dirty when the package +`dirty` indicates that the Git worktree was dirty when the package was built. `path_in_vcs` will be set to a repo-relative path for packages diff --git a/src/doc/man/generated_txt/cargo-package.txt b/src/doc/man/generated_txt/cargo-package.txt index 174bf1e5b05..0e474d17ff8 100644 --- a/src/doc/man/generated_txt/cargo-package.txt +++ b/src/doc/man/generated_txt/cargo-package.txt @@ -29,8 +29,8 @@ DESCRIPTION packaged lock file if the --locked flag is used. o A .cargo_vcs_info.json file is included that contains information - about the current VCS checkout hash if available, and whether or - not the worktree is dirty. + about the current VCS checkout hash if available, as well as a + flag if the worktree is dirty. 3. Extract the .crate file and build it to verify it can build. o This will rebuild your package from scratch to ensure that it can @@ -57,8 +57,8 @@ DESCRIPTION "path_in_vcs": "" } - dirty indicates whether or not the Git worktree was dirty when the - package was built. + dirty indicates that the Git worktree was dirty when the package was + built. path_in_vcs will be set to a repo-relative path for packages in subdirectories of the version control repository. diff --git a/src/doc/src/commands/cargo-package.md b/src/doc/src/commands/cargo-package.md index cebb550dc26..bb3324fdb74 100644 --- a/src/doc/src/commands/cargo-package.md +++ b/src/doc/src/commands/cargo-package.md @@ -26,7 +26,7 @@ steps: executable binary or example target. [cargo-install(1)](cargo-install.html) will use the packaged lock file if the `--locked` flag is used. - A `.cargo_vcs_info.json` file is included that contains information - about the current VCS checkout hash if available, and whether or not the + about the current VCS checkout hash if available, as well as a flag if the worktree is dirty. 3. Extract the `.crate` file and build it to verify it can build. - This will rebuild your package from scratch to ensure that it can be @@ -54,7 +54,7 @@ Will generate a `.cargo_vcs_info.json` in the following format } ``` -`dirty` indicates whether or not the Git worktree was dirty when the package +`dirty` indicates that the Git worktree was dirty when the package was built. `path_in_vcs` will be set to a repo-relative path for packages diff --git a/src/etc/man/cargo-package.1 b/src/etc/man/cargo-package.1 index f715c1e9de1..9a7986014a4 100644 --- a/src/etc/man/cargo-package.1 +++ b/src/etc/man/cargo-package.1 @@ -43,7 +43,7 @@ packaged lock file if the \fB\-\-locked\fR flag is used. .sp .RS 4 \h'-04'\(bu\h'+02'A \fB\&.cargo_vcs_info.json\fR file is included that contains information -about the current VCS checkout hash if available, and whether or not the +about the current VCS checkout hash if available, as well as a flag if the worktree is dirty. .RE .RE @@ -82,7 +82,7 @@ Will generate a \fB\&.cargo_vcs_info.json\fR in the following format .fi .RE .sp -\fBdirty\fR indicates whether or not the Git worktree was dirty when the package +\fBdirty\fR indicates that the Git worktree was dirty when the package was built. .sp \fBpath_in_vcs\fR will be set to a repo\-relative path for packages diff --git a/tests/testsuite/package.rs b/tests/testsuite/package.rs index 163ce018885..91179535acb 100644 --- a/tests/testsuite/package.rs +++ b/tests/testsuite/package.rs @@ -189,8 +189,7 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for let vcs_contents = format!( r#"{{ "git": {{ - "sha1": "{}", - "dirty": false + "sha1": "{}" }}, "path_in_vcs": "" }} @@ -231,8 +230,7 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for let vcs_contents = format!( r#"{{ "git": {{ - "sha1": "{}", - "dirty": false + "sha1": "{}" }}, "path_in_vcs": "a/a" }} @@ -1272,8 +1270,7 @@ fn issue_13695_allowing_dirty_vcs_info_but_clean() { ".cargo_vcs_info.json", r#"{ "git": { - "sha1": "[..]", - "dirty": false + "sha1": "[..]" }, "path_in_vcs": "" }"#,