Skip to content

Commit c685eb3

Browse files
lf-ehuss
authored andcommitted
RFC 3052: Stop including authors field in manifests made by cargo new
See rust-lang/rust#83227
1 parent 39d9413 commit c685eb3

File tree

2 files changed

+2
-372
lines changed

2 files changed

+2
-372
lines changed

src/cargo/ops/cargo_new.rs

Lines changed: 0 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@ use crate::util::errors::{CargoResult, CargoResultExt};
33
use crate::util::{existing_vcs_repo, FossilRepo, GitRepo, HgRepo, PijulRepo};
44
use crate::util::{restricted_names, Config};
55
use cargo_util::paths;
6-
use git2::Config as GitConfig;
7-
use git2::Repository as GitRepository;
86
use serde::de;
97
use serde::Deserialize;
108
use std::collections::BTreeMap;
11-
use std::env;
129
use std::fmt;
1310
use std::io::{BufRead, BufReader, ErrorKind};
1411
use std::path::{Path, PathBuf};
@@ -129,8 +126,6 @@ impl NewOptions {
129126

130127
#[derive(Deserialize)]
131128
struct CargoNewConfig {
132-
name: Option<String>,
133-
email: Option<String>,
134129
#[serde(rename = "vcs")]
135130
version_control: Option<VersionControl>,
136131
}
@@ -666,32 +661,6 @@ fn mk(config: &Config, opts: &MkOptions<'_>) -> CargoResult<()> {
666661
init_vcs(path, vcs, config)?;
667662
write_ignore_file(path, &ignore, vcs)?;
668663

669-
let (discovered_name, discovered_email) = discover_author(path);
670-
671-
// "Name <email>" or "Name" or "<email>" or None if neither name nor email is obtained
672-
// cfg takes priority over the discovered ones
673-
let author_name = cfg.name.or(discovered_name);
674-
let author_email = cfg.email.or(discovered_email);
675-
676-
let author = match (author_name, author_email) {
677-
(Some(name), Some(email)) => {
678-
if email.is_empty() {
679-
Some(name)
680-
} else {
681-
Some(format!("{} <{}>", name, email))
682-
}
683-
}
684-
(Some(name), None) => Some(name),
685-
(None, Some(email)) => {
686-
if email.is_empty() {
687-
None
688-
} else {
689-
Some(format!("<{}>", email))
690-
}
691-
}
692-
(None, None) => None,
693-
};
694-
695664
let mut cargotoml_path_specifier = String::new();
696665

697666
// Calculate what `[lib]` and `[[bin]]`s we need to append to `Cargo.toml`.
@@ -730,18 +699,13 @@ path = {}
730699
r#"[package]
731700
name = "{}"
732701
version = "0.1.0"
733-
authors = [{}]
734702
edition = {}
735703
{}
736704
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
737705
738706
[dependencies]
739707
{}"#,
740708
name,
741-
match author {
742-
Some(value) => format!("{}", toml::Value::String(value)),
743-
None => format!(""),
744-
},
745709
match opts.edition {
746710
Some(edition) => toml::Value::String(edition.to_string()),
747711
None => toml::Value::String(Edition::LATEST_STABLE.to_string()),
@@ -811,76 +775,3 @@ mod tests {
811775

812776
Ok(())
813777
}
814-
815-
fn get_environment_variable(variables: &[&str]) -> Option<String> {
816-
variables.iter().filter_map(|var| env::var(var).ok()).next()
817-
}
818-
819-
fn discover_author(path: &Path) -> (Option<String>, Option<String>) {
820-
let git_config = find_git_config(path);
821-
let git_config = git_config.as_ref();
822-
823-
let name_variables = [
824-
"CARGO_NAME",
825-
"GIT_AUTHOR_NAME",
826-
"GIT_COMMITTER_NAME",
827-
"USER",
828-
"USERNAME",
829-
"NAME",
830-
];
831-
let name = get_environment_variable(&name_variables[0..3])
832-
.or_else(|| git_config.and_then(|g| g.get_string("user.name").ok()))
833-
.or_else(|| get_environment_variable(&name_variables[3..]));
834-
835-
let name = name.map(|namestr| namestr.trim().to_string());
836-
837-
let email_variables = [
838-
"CARGO_EMAIL",
839-
"GIT_AUTHOR_EMAIL",
840-
"GIT_COMMITTER_EMAIL",
841-
"EMAIL",
842-
];
843-
let email = get_environment_variable(&email_variables[0..3])
844-
.or_else(|| git_config.and_then(|g| g.get_string("user.email").ok()))
845-
.or_else(|| get_environment_variable(&email_variables[3..]));
846-
847-
let email = email.map(|s| {
848-
let mut s = s.trim();
849-
850-
// In some cases emails will already have <> remove them since they
851-
// are already added when needed.
852-
if s.starts_with('<') && s.ends_with('>') {
853-
s = &s[1..s.len() - 1];
854-
}
855-
856-
s.to_string()
857-
});
858-
859-
(name, email)
860-
}
861-
862-
fn find_git_config(path: &Path) -> Option<GitConfig> {
863-
match env::var("__CARGO_TEST_ROOT") {
864-
Ok(_) => find_tests_git_config(path),
865-
Err(_) => find_real_git_config(path),
866-
}
867-
}
868-
869-
fn find_tests_git_config(path: &Path) -> Option<GitConfig> {
870-
// Don't escape the test sandbox when looking for a git repository.
871-
// NOTE: libgit2 has support to define the path ceiling in
872-
// git_repository_discover, but the git2 bindings do not expose that.
873-
for path in paths::ancestors(path, None) {
874-
if let Ok(repo) = GitRepository::open(path) {
875-
return Some(repo.config().expect("test repo should have valid config"));
876-
}
877-
}
878-
GitConfig::open_default().ok()
879-
}
880-
881-
fn find_real_git_config(path: &Path) -> Option<GitConfig> {
882-
GitRepository::discover(path)
883-
.and_then(|repo| repo.config())
884-
.or_else(|_| GitConfig::open_default())
885-
.ok()
886-
}

0 commit comments

Comments
 (0)