@@ -126,26 +126,7 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
126126 }
127127
128128 let just_pkgs: Vec < _ > = pkgs. iter ( ) . map ( |p| p. 0 ) . collect ( ) ;
129- let reg_or_index = match opts. reg_or_index . clone ( ) {
130- Some ( r) => {
131- validate_registry ( & just_pkgs, Some ( & r) ) ?;
132- Some ( r)
133- }
134- None => {
135- let reg = super :: infer_registry ( & just_pkgs) ?;
136- validate_registry ( & just_pkgs, reg. as_ref ( ) ) ?;
137- if let Some ( RegistryOrIndex :: Registry ( registry) ) = & reg {
138- if registry != CRATES_IO_REGISTRY {
139- // Don't warn for crates.io.
140- opts. gctx . shell ( ) . note ( & format ! (
141- "found `{}` as only allowed registry. Publishing to it automatically." ,
142- registry
143- ) ) ?;
144- }
145- }
146- reg
147- }
148- } ;
129+ let reg_or_index = resolve_registry_or_index ( opts, & just_pkgs) ?;
149130
150131 // This is only used to confirm that we can create a token before we build the package.
151132 // This causes the credential provider to be called an extra time, but keeps the same order of errors.
@@ -814,6 +795,32 @@ fn package_list(pkgs: impl IntoIterator<Item = PackageId>, final_sep: &str) -> S
814795 }
815796}
816797
798+ fn resolve_registry_or_index (
799+ opts : & PublishOpts < ' _ > ,
800+ just_pkgs : & [ & Package ] ,
801+ ) -> CargoResult < Option < RegistryOrIndex > > {
802+ Ok ( match opts. reg_or_index . clone ( ) {
803+ Some ( r) => {
804+ validate_registry ( & just_pkgs, Some ( & r) ) ?;
805+ Some ( r)
806+ }
807+ None => {
808+ let reg = super :: infer_registry ( & just_pkgs) ?;
809+ validate_registry ( & just_pkgs, reg. as_ref ( ) ) ?;
810+ if let Some ( RegistryOrIndex :: Registry ( registry) ) = & reg {
811+ if registry != CRATES_IO_REGISTRY {
812+ // Don't warn for crates.io.
813+ opts. gctx . shell ( ) . note ( & format ! (
814+ "found `{}` as only allowed registry. Publishing to it automatically." ,
815+ registry
816+ ) ) ?;
817+ }
818+ }
819+ reg
820+ }
821+ } )
822+ }
823+
817824fn validate_registry ( pkgs : & [ & Package ] , reg_or_index : Option < & RegistryOrIndex > ) -> CargoResult < ( ) > {
818825 let reg_name = match reg_or_index {
819826 Some ( RegistryOrIndex :: Registry ( r) ) => Some ( r. as_str ( ) ) ,
0 commit comments