Skip to content

Commit 81ca704

Browse files
committed
Auto merge of rust-lang#13696 - arlosi:gitoxide-list-files-default, r=weihanglo
Switch to using gitoxide by default for listing files ### What does this PR try to resolve? Uses gitoxide by for listing the contents of a git repository by default. Fixes rust-lang#10150 It's possible out-opt of this change with the environment variable `__CARGO_GITOXIDE_DISABLE_LIST_FILES=1`. This opt-out mechanism is temporary and will be removed before the next release. ### How should we test and review this PR? The newly added test fails with the `git2` implementation.
2 parents 6774b85 + 312e2aa commit 81ca704

File tree

4 files changed

+43
-14
lines changed

4 files changed

+43
-14
lines changed

src/cargo/core/features.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -908,8 +908,6 @@ fn parse_git(it: impl Iterator<Item = impl AsRef<str>>) -> CargoResult<Option<Gi
908908
pub struct GitoxideFeatures {
909909
/// All fetches are done with `gitoxide`, which includes git dependencies as well as the crates index.
910910
pub fetch: bool,
911-
/// Listing of files suitable for packaging with Git support.
912-
pub list_files: bool,
913911
/// Checkout git dependencies using `gitoxide` (submodules are still handled by git2 ATM, and filters
914912
/// like linefeed conversions are unsupported).
915913
pub checkout: bool,
@@ -923,7 +921,6 @@ impl GitoxideFeatures {
923921
fn all() -> Self {
924922
GitoxideFeatures {
925923
fetch: true,
926-
list_files: true,
927924
checkout: true,
928925
internal_use_git2: false,
929926
}
@@ -934,7 +931,6 @@ impl GitoxideFeatures {
934931
fn safe() -> Self {
935932
GitoxideFeatures {
936933
fetch: true,
937-
list_files: true,
938934
checkout: true,
939935
internal_use_git2: false,
940936
}
@@ -947,7 +943,6 @@ fn parse_gitoxide(
947943
let mut out = GitoxideFeatures::default();
948944
let GitoxideFeatures {
949945
fetch,
950-
list_files,
951946
checkout,
952947
internal_use_git2,
953948
} = &mut out;
@@ -956,10 +951,9 @@ fn parse_gitoxide(
956951
match e.as_ref() {
957952
"fetch" => *fetch = true,
958953
"checkout" => *checkout = true,
959-
"list-files" => *list_files = true,
960954
"internal-use-git2" => *internal_use_git2 = true,
961955
_ => {
962-
bail!("unstable 'gitoxide' only takes `fetch`, `list-files` and 'checkout' as valid input, for shallow fetches see `-Zgit=shallow-index,shallow-deps`")
956+
bail!("unstable 'gitoxide' only takes `fetch` and 'checkout' as valid input, for shallow fetches see `-Zgit=shallow-index,shallow-deps`")
963957
}
964958
}
965959
}

src/cargo/ops/cargo_package.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,9 @@ fn check_repo_state(
533533
if let Some(workdir) = repo.workdir() {
534534
debug!("found a git repo at {:?}", workdir);
535535
let path = p.manifest_path();
536-
let path = path.strip_prefix(workdir).unwrap_or(path);
537-
if let Ok(status) = repo.status_file(path) {
536+
let path =
537+
paths::strip_prefix_canonical(path, workdir).unwrap_or_else(|_| path.to_path_buf());
538+
if let Ok(status) = repo.status_file(&path) {
538539
if (status & git2::Status::IGNORED).is_empty() {
539540
debug!(
540541
"found (git) Cargo.toml at {:?} in workdir {:?}",

src/cargo/sources/path.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,14 @@ impl<'gctx> PathSource<'gctx> {
143143
let git_repo = if no_include_option {
144144
if self
145145
.gctx
146-
.cli_unstable()
147-
.gitoxide
148-
.map_or(false, |features| features.list_files)
146+
.get_env("__CARGO_GITOXIDE_DISABLE_LIST_FILES")
147+
.ok()
148+
.as_deref()
149+
== Some("1")
149150
{
150-
self.discover_gix_repo(root)?.map(Git2OrGixRepository::Gix)
151-
} else {
152151
self.discover_git_repo(root)?.map(Git2OrGixRepository::Git2)
152+
} else {
153+
self.discover_gix_repo(root)?.map(Git2OrGixRepository::Gix)
153154
}
154155
} else {
155156
None

tests/testsuite/package.rs

+33
Original file line numberDiff line numberDiff line change
@@ -3510,3 +3510,36 @@ Please update the `build` setting in the manifest at `[CWD]/Cargo.toml` and poin
35103510
.with_stderr(&expect_msg)
35113511
.run();
35123512
}
3513+
3514+
#[cargo_test]
3515+
fn symlink_manifest_path() {
3516+
// Test `cargo install --manifest-path` pointing through a symlink.
3517+
if !symlink_supported() {
3518+
return;
3519+
}
3520+
let p = git::new("foo", |p| {
3521+
p.file("Cargo.toml", &basic_manifest("foo", "1.0.0"))
3522+
.file("src/main.rs", "fn main() {}")
3523+
// Triggers discover_git_and_list_files for detecting changed files.
3524+
.file("build.rs", "fn main() {}")
3525+
});
3526+
#[cfg(unix)]
3527+
use std::os::unix::fs::symlink;
3528+
#[cfg(windows)]
3529+
use std::os::windows::fs::symlink_dir as symlink;
3530+
3531+
let foo_symlink = paths::root().join("foo-symlink");
3532+
t!(symlink(p.root(), &foo_symlink));
3533+
3534+
cargo_process("package --no-verify --manifest-path")
3535+
.arg(foo_symlink.join("Cargo.toml"))
3536+
.with_stderr(
3537+
"\
3538+
warning: manifest has no description, license, license-file, documentation, homepage or repository.
3539+
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
3540+
[PACKAGING] foo v1.0.0 ([..]foo-symlink)
3541+
[PACKAGED] 6 files[..]
3542+
",
3543+
)
3544+
.run()
3545+
}

0 commit comments

Comments
 (0)