@@ -3,12 +3,9 @@ use crate::util::errors::{CargoResult, CargoResultExt};
33use crate :: util:: { existing_vcs_repo, FossilRepo , GitRepo , HgRepo , PijulRepo } ;
44use crate :: util:: { restricted_names, Config } ;
55use cargo_util:: paths;
6- use git2:: Config as GitConfig ;
7- use git2:: Repository as GitRepository ;
86use serde:: de;
97use serde:: Deserialize ;
108use std:: collections:: BTreeMap ;
11- use std:: env;
129use std:: fmt;
1310use std:: io:: { BufRead , BufReader , ErrorKind } ;
1411use std:: path:: { Path , PathBuf } ;
@@ -129,8 +126,14 @@ impl NewOptions {
129126
130127#[ derive( Deserialize ) ]
131128struct CargoNewConfig {
129+ #[ deprecated = "cargo-new no longer supports adding the authors field" ]
130+ #[ allow( dead_code) ]
132131 name : Option < String > ,
132+
133+ #[ deprecated = "cargo-new no longer supports adding the authors field" ]
134+ #[ allow( dead_code) ]
133135 email : Option < String > ,
136+
134137 #[ serde( rename = "vcs" ) ]
135138 version_control : Option < VersionControl > ,
136139}
@@ -666,32 +669,6 @@ fn mk(config: &Config, opts: &MkOptions<'_>) -> CargoResult<()> {
666669 init_vcs ( path, vcs, config) ?;
667670 write_ignore_file ( path, & ignore, vcs) ?;
668671
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-
695672 let mut cargotoml_path_specifier = String :: new ( ) ;
696673
697674 // Calculate what `[lib]` and `[[bin]]`s we need to append to `Cargo.toml`.
@@ -730,18 +707,13 @@ path = {}
730707 r#"[package]
731708name = "{}"
732709version = "0.1.0"
733- authors = [{}]
734710edition = {}
735711{}
736712# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
737713
738714[dependencies]
739715{}"# ,
740716 name,
741- match author {
742- Some ( value) => format!( "{}" , toml:: Value :: String ( value) ) ,
743- None => format!( "" ) ,
744- } ,
745717 match opts. edition {
746718 Some ( edition) => toml:: Value :: String ( edition. to_string( ) ) ,
747719 None => toml:: Value :: String ( Edition :: LATEST_STABLE . to_string( ) ) ,
@@ -811,76 +783,3 @@ mod tests {
811783
812784 Ok ( ( ) )
813785}
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