@@ -134,9 +134,9 @@ impl From<Reinstall> for Refresh {
134134    } 
135135} 
136136
137- /// An upgrade selection as specified by a user on the command line or in a configuration file . 
137+ /// Whether to allow package upgrades . 
138138#[ derive( Debug ,  Default ,  Clone ) ]  
139- pub  enum  UpgradeSelection  { 
139+ pub  enum  Upgrade  { 
140140    /// Prefer pinned versions from the existing lockfile, if possible. 
141141#[ default]  
142142    None , 
@@ -145,10 +145,10 @@ pub enum UpgradeSelection {
145145All , 
146146
147147    /// Allow package upgrades, but only for the specified packages. 
148- Packages ( Vec < Requirement > ) , 
148+ Packages ( FxHashMap < PackageName ,   Vec < Requirement > > ) , 
149149} 
150150
151- impl  UpgradeSelection  { 
151+ impl  Upgrade  { 
152152    /// Determine the upgrade selection strategy from the command-line arguments. 
153153pub  fn  from_args ( upgrade :  Option < bool > ,  upgrade_package :  Vec < Requirement > )  -> Option < Self >  { 
154154        match  upgrade { 
@@ -157,68 +157,18 @@ impl UpgradeSelection {
157157            // packages to be upgraded. Right now, `--upgrade-package` is silently ignored. 
158158            Some ( false )  => Some ( Self :: None ) , 
159159            None  if  upgrade_package. is_empty ( )  => None , 
160-             None  => Some ( Self :: Packages ( upgrade_package) ) , 
161-         } 
162-     } 
163- 
164-     /// Combine a set of [`UpgradeSelection`] values. 
165- #[ must_use]  
166-     pub  fn  combine ( self ,  other :  Self )  -> Self  { 
167-         match  self  { 
168-             // Setting `--upgrade` or `--no-upgrade` should clear previous `--upgrade-package` selections. 
169-             Self :: All  | Self :: None  => self , 
170-             Self :: Packages ( self_packages)  => match  other { 
171-                 // If `--upgrade` was enabled previously, `--upgrade-package` is subsumed by upgrading all packages. 
172-                 Self :: All  => other, 
173-                 // If `--no-upgrade` was enabled previously, then `--upgrade-package` enables an explicit upgrade of those packages. 
174-                 Self :: None  => Self :: Packages ( self_packages) , 
175-                 // If `--upgrade-package` was included twice, combine the requirements. 
176-                 Self :: Packages ( other_packages)  => { 
177-                     let  mut  combined = self_packages; 
178-                     combined. extend ( other_packages) ; 
179-                     Self :: Packages ( combined) 
180-                 } 
181-             } , 
160+             None  => Some ( Self :: Packages ( upgrade_package. into_iter ( ) . fold ( 
161+                 FxHashMap :: default ( ) , 
162+                 |mut  map,  requirement| { 
163+                     map. entry ( requirement. name . clone ( ) ) 
164+                         . or_default ( ) 
165+                         . push ( requirement) ; 
166+                     map
167+                 } , 
168+             ) ) ) , 
182169        } 
183170    } 
184- } 
185- 
186- /// Whether to allow package upgrades. 
187- #[ derive( Debug ,  Default ,  Clone ) ]  
188- pub  enum  Upgrade  { 
189-     /// Prefer pinned versions from the existing lockfile, if possible. 
190- #[ default]  
191-     None , 
192- 
193-     /// Allow package upgrades for all packages, ignoring the existing lockfile. 
194- All , 
195171
196-     /// Allow package upgrades, but only for the specified packages. 
197- Packages ( FxHashMap < PackageName ,  Vec < Requirement > > ) , 
198- } 
199- 
200- /// Determine the [`Upgrade`] strategy from the command-line arguments. 
201- impl  From < Option < UpgradeSelection > >  for  Upgrade  { 
202-     fn  from ( value :  Option < UpgradeSelection > )  -> Self  { 
203-         match  value { 
204-             None  => Self :: None , 
205-             Some ( UpgradeSelection :: None )  => Self :: None , 
206-             Some ( UpgradeSelection :: All )  => Self :: All , 
207-             Some ( UpgradeSelection :: Packages ( requirements) )  => Self :: Packages ( 
208-                 requirements
209-                     . into_iter ( ) 
210-                     . fold ( FxHashMap :: default ( ) ,  |mut  map,  requirement| { 
211-                         map. entry ( requirement. name . clone ( ) ) 
212-                             . or_default ( ) 
213-                             . push ( requirement) ; 
214-                         map
215-                     } ) , 
216-             ) , 
217-         } 
218-     } 
219- } 
220- 
221- impl  Upgrade  { 
222172    /// Create an [`Upgrade`] strategy to upgrade a single package. 
223173pub  fn  package ( package_name :  PackageName )  -> Self  { 
224174        Self :: Packages ( { 
@@ -265,19 +215,23 @@ impl Upgrade {
265215    /// Combine a set of [`Upgrade`] values. 
266216#[ must_use]  
267217    pub  fn  combine ( self ,  other :  Self )  -> Self  { 
268-         match  ( self ,  other)  { 
269-             // If both are `None`, the result is `None`. 
270-             ( Self :: None ,  Self :: None )  => Self :: None , 
271-             // If either is `All`, the result is `All`. 
272-             ( Self :: All ,  _)  | ( _,  Self :: All )  => Self :: All , 
273-             // If one is `None`, the result is the other. 
274-             ( Self :: Packages ( a) ,  Self :: None )  => Self :: Packages ( a) , 
275-             ( Self :: None ,  Self :: Packages ( b) )  => Self :: Packages ( b) , 
276-             // If both are `Packages`, the result is the union of the two. 
277-             ( Self :: Packages ( mut  a) ,  Self :: Packages ( b) )  => { 
278-                 a. extend ( b) ; 
279-                 Self :: Packages ( a) 
280-             } 
218+         match  self  { 
219+             // Setting `--upgrade` or `--no-upgrade` should clear previous `--upgrade-package` selections. 
220+             Self :: All  | Self :: None  => self , 
221+             Self :: Packages ( self_packages)  => match  other { 
222+                 // If `--upgrade` was enabled previously, `--upgrade-package` is subsumed by upgrading all packages. 
223+                 Self :: All  => other, 
224+                 // If `--no-upgrade` was enabled previously, then `--upgrade-package` enables an explicit upgrade of those packages. 
225+                 Self :: None  => Self :: Packages ( self_packages) , 
226+                 // If `--upgrade-package` was included twice, combine the requirements. 
227+                 Self :: Packages ( other_packages)  => { 
228+                     let  mut  combined = self_packages; 
229+                     for  ( package,  requirements)  in  other_packages { 
230+                         combined. entry ( package) . or_default ( ) . extend ( requirements) ; 
231+                     } 
232+                     Self :: Packages ( combined) 
233+                 } 
234+             } , 
281235        } 
282236    } 
283237} 
0 commit comments