Skip to content

Commit 149022b

Browse files
authored
Merge pull request #8503 from alexcrichton/revert-beta
[beta] Revert "Improve support for non-`master` main branches"
2 parents 4481ef5 + 374a0b2 commit 149022b

File tree

11 files changed

+18
-79
lines changed

11 files changed

+18
-79
lines changed

src/bin/cargo/commands/install.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
140140
} else if let Some(rev) = args.value_of("rev") {
141141
GitReference::Rev(rev.to_string())
142142
} else {
143-
GitReference::DefaultBranch
143+
GitReference::Branch("master".to_string())
144144
};
145145
SourceId::for_git(&url, gitref)?
146146
} else if let Some(path) = args.value_of_path("path", config) {

src/cargo/core/source/source_id.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,10 @@ enum SourceKind {
6363
pub enum GitReference {
6464
/// From a tag.
6565
Tag(String),
66-
/// From a branch.
66+
/// From the HEAD of a branch.
6767
Branch(String),
6868
/// From a specific revision.
6969
Rev(String),
70-
/// The default branch of the repository, the reference named `HEAD`.
71-
DefaultBranch,
7270
}
7371

7472
impl SourceId {
@@ -116,7 +114,7 @@ impl SourceId {
116114
match kind {
117115
"git" => {
118116
let mut url = url.into_url()?;
119-
let mut reference = GitReference::DefaultBranch;
117+
let mut reference = GitReference::Branch("master".to_string());
120118
for (k, v) in url.query_pairs() {
121119
match &k[..] {
122120
// Map older 'ref' to branch.
@@ -551,10 +549,10 @@ impl<'a> fmt::Display for SourceIdIntoUrl<'a> {
551549

552550
impl GitReference {
553551
/// Returns a `Display`able view of this git reference, or None if using
554-
/// the head of the default branch
552+
/// the head of the "master" branch
555553
pub fn pretty_ref(&self) -> Option<PrettyRef<'_>> {
556554
match *self {
557-
GitReference::DefaultBranch => None,
555+
GitReference::Branch(ref s) if *s == "master" => None,
558556
_ => Some(PrettyRef { inner: self }),
559557
}
560558
}
@@ -571,7 +569,6 @@ impl<'a> fmt::Display for PrettyRef<'a> {
571569
GitReference::Branch(ref b) => write!(f, "branch={}", b),
572570
GitReference::Tag(ref s) => write!(f, "tag={}", s),
573571
GitReference::Rev(ref s) => write!(f, "rev={}", s),
574-
GitReference::DefaultBranch => unreachable!(),
575572
}
576573
}
577574
}
@@ -584,11 +581,11 @@ mod tests {
584581
#[test]
585582
fn github_sources_equal() {
586583
let loc = "https://github.com/foo/bar".into_url().unwrap();
587-
let default = SourceKind::Git(GitReference::DefaultBranch);
588-
let s1 = SourceId::new(default.clone(), loc).unwrap();
584+
let master = SourceKind::Git(GitReference::Branch("master".to_string()));
585+
let s1 = SourceId::new(master.clone(), loc).unwrap();
589586

590587
let loc = "git://github.com/foo/bar".into_url().unwrap();
591-
let s2 = SourceId::new(default, loc.clone()).unwrap();
588+
let s2 = SourceId::new(master, loc.clone()).unwrap();
592589

593590
assert_eq!(s1, s2);
594591

src/cargo/ops/vendor.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ fn sync(
275275
GitReference::Branch(ref b) => branch = Some(b.clone()),
276276
GitReference::Tag(ref t) => tag = Some(t.clone()),
277277
GitReference::Rev(ref r) => rev = Some(r.clone()),
278-
GitReference::DefaultBranch => {}
279278
}
280279
}
281280
VendorSource::Git {

src/cargo/sources/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ restore the source replacement configuration to continue the build
225225
Some(b) => GitReference::Tag(b.val),
226226
None => match def.rev {
227227
Some(b) => GitReference::Rev(b.val),
228-
None => GitReference::DefaultBranch,
228+
None => GitReference::Branch("master".to_string()),
229229
},
230230
},
231231
};

src/cargo/sources/git/source.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,10 @@ mod test {
261261
}
262262

263263
fn src(s: &str) -> SourceId {
264-
SourceId::for_git(&s.into_url().unwrap(), GitReference::DefaultBranch).unwrap()
264+
SourceId::for_git(
265+
&s.into_url().unwrap(),
266+
GitReference::Branch("master".to_string()),
267+
)
268+
.unwrap()
265269
}
266270
}

src/cargo/sources/git/utils.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,6 @@ impl GitReference {
217217
.target()
218218
.ok_or_else(|| anyhow::format_err!("branch `{}` did not have a target", s))?
219219
}
220-
GitReference::DefaultBranch => {
221-
let refname = "refs/remotes/origin/HEAD";
222-
let id = repo.refname_to_id(refname)?;
223-
let obj = repo.find_object(id, None)?;
224-
let obj = obj.peel(ObjectType::Commit)?;
225-
obj.id()
226-
}
227-
228220
GitReference::Rev(s) => {
229221
let obj = repo.revparse_single(s)?;
230222
match obj.as_tag() {
@@ -750,16 +742,11 @@ pub fn fetch(
750742
refspecs.push(format!("refs/tags/{0}:refs/remotes/origin/tags/{0}", t));
751743
}
752744

753-
GitReference::DefaultBranch => {
754-
refspecs.push(format!("HEAD:refs/remotes/origin/HEAD"));
755-
}
756-
757745
// For `rev` dependencies we don't know what the rev will point to. To
758746
// handle this situation we fetch all branches and tags, and then we
759747
// pray it's somewhere in there.
760748
GitReference::Rev(_) => {
761749
refspecs.push(format!("refs/heads/*:refs/remotes/origin/*"));
762-
refspecs.push(format!("HEAD:refs/remotes/origin/HEAD"));
763750
tags = true;
764751
}
765752
}
@@ -978,7 +965,6 @@ fn github_up_to_date(
978965
let github_branch_name = match reference {
979966
GitReference::Branch(branch) => branch,
980967
GitReference::Tag(tag) => tag,
981-
GitReference::DefaultBranch => "HEAD",
982968
GitReference::Rev(_) => {
983969
debug!("can't use github fast path with `rev`");
984970
return Ok(false);

src/cargo/sources/registry/remote.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl<'cfg> RemoteRegistry<'cfg> {
4949
source_id,
5050
config,
5151
// TODO: we should probably make this configurable
52-
index_git_ref: GitReference::DefaultBranch,
52+
index_git_ref: GitReference::Branch("master".to_string()),
5353
tree: RefCell::new(None),
5454
repo: LazyCell::new(),
5555
head: Cell::new(None),

src/cargo/util/toml/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1690,7 +1690,7 @@ impl DetailedTomlDependency {
16901690
.map(GitReference::Branch)
16911691
.or_else(|| self.tag.clone().map(GitReference::Tag))
16921692
.or_else(|| self.rev.clone().map(GitReference::Rev))
1693-
.unwrap_or_else(|| GitReference::DefaultBranch);
1693+
.unwrap_or_else(|| GitReference::Branch("master".to_string()));
16941694
let loc = git.into_url()?;
16951695

16961696
if let Some(fragment) = loc.fragment() {

src/doc/src/reference/specifying-dependencies.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ Cargo will fetch the `git` repository at this location then look for a
137137
of a workspace and setting `git` to the repository containing the workspace).
138138

139139
Since we haven’t specified any other information, Cargo assumes that
140-
we intend to use the latest commit on the main branch to build our package.
140+
we intend to use the latest commit on the `master` branch to build our package.
141141
You can combine the `git` key with the `rev`, `tag`, or `branch` keys to
142142
specify something else. Here's an example of specifying that you want to use
143143
the latest commit on a branch named `next`:

tests/build-std/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use std::path::Path;
2525
fn enable_build_std(e: &mut Execs, arg: Option<&str>) {
2626
e.env_remove("CARGO_HOME");
2727
e.env_remove("HOME");
28+
e.arg("-Zno-index-update");
2829

2930
// And finally actually enable `build-std` for now
3031
let arg = match arg {

tests/testsuite/git.rs

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2784,51 +2784,3 @@ to proceed despite [..]
27842784
git::commit(&repo);
27852785
git_project.cargo("package --no-verify").run();
27862786
}
2787-
2788-
#[cargo_test]
2789-
fn default_not_master() {
2790-
let project = project();
2791-
2792-
// Create a repository with a `master` branch ...
2793-
let (git_project, repo) = git::new_repo("dep1", |project| {
2794-
project.file("Cargo.toml", &basic_lib_manifest("dep1"))
2795-
});
2796-
2797-
// Then create a `main` branch with actual code, and set the head of the
2798-
// repository (default branch) to `main`.
2799-
git_project.change_file("src/lib.rs", "pub fn foo() {}");
2800-
git::add(&repo);
2801-
let rev = git::commit(&repo);
2802-
let commit = repo.find_commit(rev).unwrap();
2803-
repo.branch("main", &commit, false).unwrap();
2804-
repo.set_head("refs/heads/main").unwrap();
2805-
2806-
let project = project
2807-
.file(
2808-
"Cargo.toml",
2809-
&format!(
2810-
r#"
2811-
[project]
2812-
name = "foo"
2813-
version = "0.5.0"
2814-
2815-
[dependencies]
2816-
dep1 = {{ git = '{}' }}
2817-
"#,
2818-
git_project.url()
2819-
),
2820-
)
2821-
.file("src/lib.rs", "pub fn foo() { dep1::foo() }")
2822-
.build();
2823-
2824-
project
2825-
.cargo("build")
2826-
.with_stderr(
2827-
"\
2828-
[UPDATING] git repository `[..]`
2829-
[COMPILING] dep1 v0.5.0 ([..])
2830-
[COMPILING] foo v0.5.0 ([..])
2831-
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]",
2832-
)
2833-
.run();
2834-
}

0 commit comments

Comments
 (0)