@@ -30,7 +30,7 @@ use uv_python::{Interpreter, PythonDownloads, PythonEnvironment, PythonPreferenc
3030use uv_requirements:: ExtrasResolver ;
3131use uv_requirements:: upgrade:: { LockedRequirements , read_lock_requirements} ;
3232use uv_resolver:: {
33- FlatIndex , InMemoryIndex , Lock , Options , OptionsBuilder , PythonRequirement ,
33+ FlatIndex , InMemoryIndex , Lock , Options , OptionsBuilder , Package , PythonRequirement ,
3434 ResolverEnvironment , ResolverManifest , SatisfiesResult , UniversalMarker ,
3535} ;
3636use uv_scripts:: Pep723Script ;
@@ -1355,28 +1355,56 @@ impl ValidatedLock {
13551355 }
13561356}
13571357
1358+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
1359+ struct LockEventVersion < ' lock > {
1360+ /// The version of the package, or `None` if the package has a dynamic version.
1361+ version : Option < & ' lock Version > ,
1362+ /// The short Git SHA of the package, if it was installed from a Git repository.
1363+ sha : Option < & ' lock str > ,
1364+ }
1365+
1366+ impl < ' lock > From < & ' lock Package > for LockEventVersion < ' lock > {
1367+ fn from ( value : & ' lock Package ) -> Self {
1368+ Self {
1369+ version : value. version ( ) ,
1370+ sha : value. short_git_sha ( ) ,
1371+ }
1372+ }
1373+ }
1374+
1375+ impl std:: fmt:: Display for LockEventVersion < ' _ > {
1376+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
1377+ match ( self . version , self . sha ) {
1378+ ( Some ( version) , Some ( sha) ) => write ! ( f, "v{version} ({sha})" ) ,
1379+ ( Some ( version) , None ) => write ! ( f, "v{version}" ) ,
1380+ ( None , Some ( sha) ) => write ! ( f, "(dynamic) ({sha})" ) ,
1381+ ( None , None ) => write ! ( f, "(dynamic)" ) ,
1382+ }
1383+ }
1384+ }
1385+
13581386/// A modification to a lockfile.
13591387#[ derive( Debug , Clone ) ]
1360- pub ( crate ) enum LockEvent < ' lock > {
1388+ enum LockEvent < ' lock > {
13611389 Update (
13621390 DryRun ,
13631391 PackageName ,
1364- BTreeSet < Option < & ' lock Version > > ,
1365- BTreeSet < Option < & ' lock Version > > ,
1392+ BTreeSet < LockEventVersion < ' lock > > ,
1393+ BTreeSet < LockEventVersion < ' lock > > ,
13661394 ) ,
1367- Add ( DryRun , PackageName , BTreeSet < Option < & ' lock Version > > ) ,
1368- Remove ( DryRun , PackageName , BTreeSet < Option < & ' lock Version > > ) ,
1395+ Add ( DryRun , PackageName , BTreeSet < LockEventVersion < ' lock > > ) ,
1396+ Remove ( DryRun , PackageName , BTreeSet < LockEventVersion < ' lock > > ) ,
13691397}
13701398
13711399impl < ' lock > LockEvent < ' lock > {
13721400 /// Detect the change events between an (optional) existing and updated lockfile.
1373- pub ( crate ) fn detect_changes (
1401+ fn detect_changes (
13741402 existing_lock : Option < & ' lock Lock > ,
13751403 new_lock : & ' lock Lock ,
13761404 dry_run : DryRun ,
13771405 ) -> impl Iterator < Item = Self > {
13781406 // Identify the package-versions in the existing lockfile.
1379- let mut existing_packages: FxHashMap < & PackageName , BTreeSet < Option < & Version > > > =
1407+ let mut existing_packages: FxHashMap < & PackageName , BTreeSet < LockEventVersion > > =
13801408 if let Some ( existing_lock) = existing_lock {
13811409 existing_lock. packages ( ) . iter ( ) . fold (
13821410 FxHashMap :: with_capacity_and_hasher (
@@ -1386,7 +1414,7 @@ impl<'lock> LockEvent<'lock> {
13861414 |mut acc, package| {
13871415 acc. entry ( package. name ( ) )
13881416 . or_default ( )
1389- . insert ( package . version ( ) ) ;
1417+ . insert ( LockEventVersion :: from ( package ) ) ;
13901418 acc
13911419 } ,
13921420 )
@@ -1395,13 +1423,13 @@ impl<'lock> LockEvent<'lock> {
13951423 } ;
13961424
13971425 // Identify the package-versions in the updated lockfile.
1398- let mut new_packages: FxHashMap < & PackageName , BTreeSet < Option < & Version > > > =
1426+ let mut new_packages: FxHashMap < & PackageName , BTreeSet < LockEventVersion > > =
13991427 new_lock. packages ( ) . iter ( ) . fold (
14001428 FxHashMap :: with_capacity_and_hasher ( new_lock. packages ( ) . len ( ) , FxBuildHasher ) ,
14011429 |mut acc, package| {
14021430 acc. entry ( package. name ( ) )
14031431 . or_default ( )
1404- . insert ( package . version ( ) ) ;
1432+ . insert ( LockEventVersion :: from ( package ) ) ;
14051433 acc
14061434 } ,
14071435 ) ;
@@ -1435,23 +1463,16 @@ impl<'lock> LockEvent<'lock> {
14351463
14361464impl std:: fmt:: Display for LockEvent < ' _ > {
14371465 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
1438- /// Format a version for inclusion in the upgrade report.
1439- fn format_version ( version : Option < & Version > ) -> String {
1440- version
1441- . map ( |version| format ! ( "v{version}" ) )
1442- . unwrap_or_else ( || "(dynamic)" . to_string ( ) )
1443- }
1444-
14451466 match self {
14461467 Self :: Update ( dry_run, name, existing_versions, new_versions) => {
14471468 let existing_versions = existing_versions
14481469 . iter ( )
1449- . map ( |version| format_version ( * version ) )
1470+ . map ( std :: string :: ToString :: to_string )
14501471 . collect :: < Vec < _ > > ( )
14511472 . join ( ", " ) ;
14521473 let new_versions = new_versions
14531474 . iter ( )
1454- . map ( |version| format_version ( * version ) )
1475+ . map ( std :: string :: ToString :: to_string )
14551476 . collect :: < Vec < _ > > ( )
14561477 . join ( ", " ) ;
14571478
@@ -1470,7 +1491,7 @@ impl std::fmt::Display for LockEvent<'_> {
14701491 Self :: Add ( dry_run, name, new_versions) => {
14711492 let new_versions = new_versions
14721493 . iter ( )
1473- . map ( |version| format_version ( * version ) )
1494+ . map ( std :: string :: ToString :: to_string )
14741495 . collect :: < Vec < _ > > ( )
14751496 . join ( ", " ) ;
14761497
@@ -1485,7 +1506,7 @@ impl std::fmt::Display for LockEvent<'_> {
14851506 Self :: Remove ( dry_run, name, existing_versions) => {
14861507 let existing_versions = existing_versions
14871508 . iter ( )
1488- . map ( |version| format_version ( * version ) )
1509+ . map ( std :: string :: ToString :: to_string )
14891510 . collect :: < Vec < _ > > ( )
14901511 . join ( ", " ) ;
14911512
0 commit comments