@@ -30,7 +30,7 @@ use uv_python::{Interpreter, PythonDownloads, PythonEnvironment, PythonPreferenc
30
30
use uv_requirements:: ExtrasResolver ;
31
31
use uv_requirements:: upgrade:: { LockedRequirements , read_lock_requirements} ;
32
32
use uv_resolver:: {
33
- FlatIndex , InMemoryIndex , Lock , Options , OptionsBuilder , PythonRequirement ,
33
+ FlatIndex , InMemoryIndex , Lock , Options , OptionsBuilder , Package , PythonRequirement ,
34
34
ResolverEnvironment , ResolverManifest , SatisfiesResult , UniversalMarker ,
35
35
} ;
36
36
use uv_scripts:: Pep723Script ;
@@ -1355,28 +1355,56 @@ impl ValidatedLock {
1355
1355
}
1356
1356
}
1357
1357
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
+
1358
1386
/// A modification to a lockfile.
1359
1387
#[ derive( Debug , Clone ) ]
1360
- pub ( crate ) enum LockEvent < ' lock > {
1388
+ enum LockEvent < ' lock > {
1361
1389
Update (
1362
1390
DryRun ,
1363
1391
PackageName ,
1364
- BTreeSet < Option < & ' lock Version > > ,
1365
- BTreeSet < Option < & ' lock Version > > ,
1392
+ BTreeSet < LockEventVersion < ' lock > > ,
1393
+ BTreeSet < LockEventVersion < ' lock > > ,
1366
1394
) ,
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 > > ) ,
1369
1397
}
1370
1398
1371
1399
impl < ' lock > LockEvent < ' lock > {
1372
1400
/// Detect the change events between an (optional) existing and updated lockfile.
1373
- pub ( crate ) fn detect_changes (
1401
+ fn detect_changes (
1374
1402
existing_lock : Option < & ' lock Lock > ,
1375
1403
new_lock : & ' lock Lock ,
1376
1404
dry_run : DryRun ,
1377
1405
) -> impl Iterator < Item = Self > {
1378
1406
// 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 > > =
1380
1408
if let Some ( existing_lock) = existing_lock {
1381
1409
existing_lock. packages ( ) . iter ( ) . fold (
1382
1410
FxHashMap :: with_capacity_and_hasher (
@@ -1386,7 +1414,7 @@ impl<'lock> LockEvent<'lock> {
1386
1414
|mut acc, package| {
1387
1415
acc. entry ( package. name ( ) )
1388
1416
. or_default ( )
1389
- . insert ( package . version ( ) ) ;
1417
+ . insert ( LockEventVersion :: from ( package ) ) ;
1390
1418
acc
1391
1419
} ,
1392
1420
)
@@ -1395,13 +1423,13 @@ impl<'lock> LockEvent<'lock> {
1395
1423
} ;
1396
1424
1397
1425
// 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 > > =
1399
1427
new_lock. packages ( ) . iter ( ) . fold (
1400
1428
FxHashMap :: with_capacity_and_hasher ( new_lock. packages ( ) . len ( ) , FxBuildHasher ) ,
1401
1429
|mut acc, package| {
1402
1430
acc. entry ( package. name ( ) )
1403
1431
. or_default ( )
1404
- . insert ( package . version ( ) ) ;
1432
+ . insert ( LockEventVersion :: from ( package ) ) ;
1405
1433
acc
1406
1434
} ,
1407
1435
) ;
@@ -1435,23 +1463,16 @@ impl<'lock> LockEvent<'lock> {
1435
1463
1436
1464
impl std:: fmt:: Display for LockEvent < ' _ > {
1437
1465
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
-
1445
1466
match self {
1446
1467
Self :: Update ( dry_run, name, existing_versions, new_versions) => {
1447
1468
let existing_versions = existing_versions
1448
1469
. iter ( )
1449
- . map ( |version| format_version ( * version ) )
1470
+ . map ( std :: string :: ToString :: to_string )
1450
1471
. collect :: < Vec < _ > > ( )
1451
1472
. join ( ", " ) ;
1452
1473
let new_versions = new_versions
1453
1474
. iter ( )
1454
- . map ( |version| format_version ( * version ) )
1475
+ . map ( std :: string :: ToString :: to_string )
1455
1476
. collect :: < Vec < _ > > ( )
1456
1477
. join ( ", " ) ;
1457
1478
@@ -1470,7 +1491,7 @@ impl std::fmt::Display for LockEvent<'_> {
1470
1491
Self :: Add ( dry_run, name, new_versions) => {
1471
1492
let new_versions = new_versions
1472
1493
. iter ( )
1473
- . map ( |version| format_version ( * version ) )
1494
+ . map ( std :: string :: ToString :: to_string )
1474
1495
. collect :: < Vec < _ > > ( )
1475
1496
. join ( ", " ) ;
1476
1497
@@ -1485,7 +1506,7 @@ impl std::fmt::Display for LockEvent<'_> {
1485
1506
Self :: Remove ( dry_run, name, existing_versions) => {
1486
1507
let existing_versions = existing_versions
1487
1508
. iter ( )
1488
- . map ( |version| format_version ( * version ) )
1509
+ . map ( std :: string :: ToString :: to_string )
1489
1510
. collect :: < Vec < _ > > ( )
1490
1511
. join ( ", " ) ;
1491
1512
0 commit comments