@@ -468,34 +468,51 @@ impl SourceId {
468
468
469
469
/// Creates a new `SourceId` from this source with the given `precise`.
470
470
pub fn with_git_precise ( self , fragment : Option < String > ) -> SourceId {
471
- SourceId :: wrap ( SourceIdInner {
472
- precise : fragment. map ( |f| Precise :: GitUrlFragment ( f) ) ,
473
- ..( * self . inner ) . clone ( )
474
- } )
471
+ let precise = fragment. map ( |f| Precise :: GitUrlFragment ( f) ) ;
472
+ if self . inner . precise == precise {
473
+ self
474
+ } else {
475
+ SourceId :: wrap ( SourceIdInner {
476
+ precise,
477
+ ..( * self . inner ) . clone ( )
478
+ } )
479
+ }
475
480
}
476
481
477
482
/// Creates a new `SourceId` from this source without a `precise`.
478
483
pub fn without_precise ( self ) -> SourceId {
479
- SourceId :: wrap ( SourceIdInner {
480
- precise : None ,
481
- ..( * self . inner ) . clone ( )
482
- } )
484
+ if self . inner . precise . is_none ( ) {
485
+ self
486
+ } else {
487
+ SourceId :: wrap ( SourceIdInner {
488
+ precise : None ,
489
+ ..( * self . inner ) . clone ( )
490
+ } )
491
+ }
483
492
}
484
493
485
494
/// Creates a new `SourceId` from this source without a `precise`.
486
495
pub fn with_locked_precise ( self ) -> SourceId {
487
- SourceId :: wrap ( SourceIdInner {
488
- precise : Some ( Precise :: Locked ) ,
489
- ..( * self . inner ) . clone ( )
490
- } )
496
+ if self . inner . precise == Some ( Precise :: Locked ) {
497
+ self
498
+ } else {
499
+ SourceId :: wrap ( SourceIdInner {
500
+ precise : Some ( Precise :: Locked ) ,
501
+ ..( * self . inner ) . clone ( )
502
+ } )
503
+ }
491
504
}
492
505
493
506
/// Creates a new `SourceId` from this source with the `precise` from some other `SourceId`.
494
507
pub fn with_precise_from ( self , v : Self ) -> SourceId {
495
- SourceId :: wrap ( SourceIdInner {
496
- precise : v. inner . precise . clone ( ) ,
497
- ..( * self . inner ) . clone ( )
498
- } )
508
+ if self . inner . precise == v. inner . precise {
509
+ self
510
+ } else {
511
+ SourceId :: wrap ( SourceIdInner {
512
+ precise : v. inner . precise . clone ( ) ,
513
+ ..( * self . inner ) . clone ( )
514
+ } )
515
+ }
499
516
}
500
517
501
518
/// When updating a lock file on a version using `cargo update --precise`
0 commit comments