9
9
//!
10
10
//! This module impl that cache in all the gory details
11
11
12
- use std:: cmp:: Ordering ;
13
- use std:: collections:: { BTreeSet , HashMap , HashSet } ;
14
- use std:: rc:: Rc ;
15
-
16
- use log:: debug;
17
-
18
12
use crate :: core:: resolver:: context:: Context ;
19
13
use crate :: core:: resolver:: errors:: describe_path;
14
+ use crate :: core:: resolver:: types:: { ConflictReason , DepInfo , FeaturesSet } ;
15
+ use crate :: core:: resolver:: { ActivateResult , ResolveOpts } ;
20
16
use crate :: core:: { Dependency , FeatureValue , PackageId , PackageIdSpec , Registry , Summary } ;
17
+ use crate :: core:: { GitReference , SourceId } ;
21
18
use crate :: util:: errors:: { CargoResult , CargoResultExt } ;
22
19
use crate :: util:: interning:: InternedString ;
23
-
24
- use crate :: core:: resolver:: types:: { ConflictReason , DepInfo , FeaturesSet } ;
25
- use crate :: core:: resolver:: { ActivateResult , ResolveOpts } ;
20
+ use crate :: util:: Config ;
21
+ use log:: debug;
22
+ use std:: cmp:: Ordering ;
23
+ use std:: collections:: { BTreeSet , HashMap , HashSet } ;
24
+ use std:: rc:: Rc ;
26
25
27
26
pub struct RegistryQueryer < ' a > {
28
27
pub registry : & ' a mut ( dyn Registry + ' a ) ,
@@ -41,6 +40,10 @@ pub struct RegistryQueryer<'a> {
41
40
> ,
42
41
/// all the cases we ended up using a supplied replacement
43
42
used_replacements : HashMap < PackageId , Summary > ,
43
+ /// Where to print warnings, if configured.
44
+ config : Option < & ' a Config > ,
45
+ /// Sources that we've already wared about possibly colliding in the future.
46
+ warned_git_collisions : HashSet < SourceId > ,
44
47
}
45
48
46
49
impl < ' a > RegistryQueryer < ' a > {
@@ -49,6 +52,7 @@ impl<'a> RegistryQueryer<'a> {
49
52
replacements : & ' a [ ( PackageIdSpec , Dependency ) ] ,
50
53
try_to_use : & ' a HashSet < PackageId > ,
51
54
minimal_versions : bool ,
55
+ config : Option < & ' a Config > ,
52
56
) -> Self {
53
57
RegistryQueryer {
54
58
registry,
@@ -58,6 +62,8 @@ impl<'a> RegistryQueryer<'a> {
58
62
registry_cache : HashMap :: new ( ) ,
59
63
summary_cache : HashMap :: new ( ) ,
60
64
used_replacements : HashMap :: new ( ) ,
65
+ config,
66
+ warned_git_collisions : HashSet :: new ( ) ,
61
67
}
62
68
}
63
69
@@ -69,13 +75,52 @@ impl<'a> RegistryQueryer<'a> {
69
75
self . used_replacements . get ( & p)
70
76
}
71
77
78
+ /// Issues a future-compatible warning targeted at removing reliance on
79
+ /// unifying behavior between these two dependency directives:
80
+ ///
81
+ /// ```toml
82
+ /// [dependencies]
83
+ /// a = { git = 'https://example.org/foo' }
84
+ /// a = { git = 'https://example.org/foo', branch = 'master }
85
+ /// ```
86
+ ///
87
+ /// Historical versions of Cargo considered these equivalent but going
88
+ /// forward we'd like to fix this. For more details see the comments in
89
+ /// src/cargo/sources/git/utils.rs
90
+ fn warn_colliding_git_sources ( & mut self , id : SourceId ) -> CargoResult < ( ) > {
91
+ let config = match self . config {
92
+ Some ( config) => config,
93
+ None => return Ok ( ( ) ) ,
94
+ } ;
95
+ let prev = match self . warned_git_collisions . replace ( id) {
96
+ Some ( prev) => prev,
97
+ None => return Ok ( ( ) ) ,
98
+ } ;
99
+ match ( id. git_reference ( ) , prev. git_reference ( ) ) {
100
+ ( Some ( GitReference :: DefaultBranch ) , Some ( GitReference :: Branch ( b) ) )
101
+ | ( Some ( GitReference :: Branch ( b) ) , Some ( GitReference :: DefaultBranch ) )
102
+ if b == "master" => { }
103
+ _ => return Ok ( ( ) ) ,
104
+ }
105
+
106
+ config. shell ( ) . warn ( & format ! (
107
+ "two git dependencies found for `{}` \
108
+ where one uses `branch = \" master\" ` and the other doesn't; \
109
+ this will break in a future version of Cargo, so please \
110
+ ensure the dependency forms are consistent",
111
+ id. url( ) ,
112
+ ) ) ?;
113
+ Ok ( ( ) )
114
+ }
115
+
72
116
/// Queries the `registry` to return a list of candidates for `dep`.
73
117
///
74
118
/// This method is the location where overrides are taken into account. If
75
119
/// any candidates are returned which match an override then the override is
76
120
/// applied by performing a second query for what the override should
77
121
/// return.
78
122
pub fn query ( & mut self , dep : & Dependency ) -> CargoResult < Rc < Vec < Summary > > > {
123
+ self . warn_colliding_git_sources ( dep. source_id ( ) ) ?;
79
124
if let Some ( out) = self . registry_cache . get ( dep) . cloned ( ) {
80
125
return Ok ( out) ;
81
126
}
0 commit comments