Skip to content

Commit 73bdebc

Browse files
committed
Add a hack to make github urls case-insensitive. Fixes rust-lang#84
1 parent 541a060 commit 73bdebc

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

src/cargo/sources/git/source.rs

+21-5
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,8 @@ fn ident(location: &Location) -> String {
6868
str::from_utf8(last).unwrap().to_str()
6969
}
7070
Remote(ref url) => {
71-
// Remove the trailing '/' so that 'split' doesn't give us
72-
// an empty string, making '../foo/' and '../foo' both
73-
// result in the name 'foo' (#84)
7471
let path = strip_trailing_slash(url.path.as_slice());
75-
path.split('/').last().unwrap().to_str()
72+
path.as_slice().split('/').last().unwrap().to_str()
7673
}
7774
};
7875

@@ -82,17 +79,36 @@ fn ident(location: &Location) -> String {
8279
ident
8380
};
8481

85-
format!("{}-{}", ident, to_hex(hasher.hash(&location.to_str())))
82+
let location = canonicalize_url(location.to_str().as_slice());
83+
84+
format!("{}-{}", ident, to_hex(hasher.hash(&location.as_slice())))
8685
}
8786

8887
fn strip_trailing_slash<'a>(path: &'a str) -> &'a str {
88+
// Remove the trailing '/' so that 'split' doesn't give us
89+
// an empty string, making '../foo/' and '../foo' both
90+
// result in the name 'foo' (#84)
8991
if path.as_bytes().last() != Some(&('/' as u8)) {
9092
path.clone()
9193
} else {
9294
path.slice(0, path.len() - 1)
9395
}
9496
}
9597

98+
fn canonicalize_url(url: &str) -> String {
99+
// HACKHACK: For github URL's specifically just lowercase
100+
// everything. GitHub traits both the same, but they hash
101+
// differently, and we're gonna be hashing them. This wants a more
102+
// general solution, and also we're almost certainly not using the
103+
// same case conversion rules that GitHub does. (#84)
104+
let lower_url = url.chars().map(|c|c.to_lowercase()).collect::<String>();
105+
if lower_url.as_slice().contains("github.com") {
106+
lower_url
107+
} else {
108+
url.to_string()
109+
}
110+
}
111+
96112
impl<'a, 'b> Show for GitSource<'a, 'b> {
97113
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
98114
try!(write!(f, "git repo at {}", self.remote.get_location()));

0 commit comments

Comments
 (0)