Skip to content

Commit d1bab04

Browse files
committed
Update to git-url-parse 0.5.x
Version 0.5.2 includes tjtelan/git-url-parse-rs#66 which we need. Pinning to 0.5.x for now since there might be other breaking/structural changes coming soon. GUS-W-19637481
1 parent 5841610 commit d1bab04

File tree

3 files changed

+66
-49
lines changed

3 files changed

+66
-49
lines changed

Cargo.lock

Lines changed: 47 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

composer/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ workspace = true
88

99
[dependencies]
1010
derive_more = { version = "2", features = ["deref", "from"] }
11-
git-url-parse = "0.4"
11+
git-url-parse = "0.5.2"
1212
monostate = "0.1"
1313
serde = { version = "1", features = ["derive"] }
1414
serde_json = "1"

composer/src/lib.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use derive_more::{Deref, From};
2-
use git_url_parse::{GitUrl, Scheme as GitUrlScheme};
2+
use git_url_parse::GitUrl;
33
use monostate::MustBe;
44
use serde::de::{Error, MapAccess, SeqAccess, Visitor};
55
use serde::ser::{SerializeMap, Serializer};
@@ -627,25 +627,23 @@ impl From<String> for ComposerUrlOrPathUrl {
627627
}
628628
}
629629

630-
// for some sources (and their mirrors) such as 'git', three kinds of URLs are allowed:
630+
// For some sources (and their mirrors) such as 'git', three kinds of URLs are allowed:
631631
// 1) URL style (e.g. https://github.com/foo/bar)
632632
// 2) SSH style (e.g. [email protected]:foo/bar.git)
633633
// 3) local filesystem path
634-
// so the URL type has to permit all of these
634+
// Style 2 is normalized into style 1 during parsing
635635
#[derive(Clone, Debug, Deserialize, Serialize)]
636636
#[serde(try_from = "String")]
637637
#[serde(into = "String")]
638638
pub enum ComposerUrlOrSshOrPathUrl {
639639
Url(Url),
640-
GitUrl(GitUrl),
641640
Path(PathBuf),
642641
}
643642

644643
impl From<ComposerUrlOrSshOrPathUrl> for String {
645644
fn from(val: ComposerUrlOrSshOrPathUrl) -> Self {
646645
match val {
647646
ComposerUrlOrSshOrPathUrl::Url(v) => v.into(),
648-
ComposerUrlOrSshOrPathUrl::GitUrl(v) => v.to_string(),
649647
ComposerUrlOrSshOrPathUrl::Path(v) => format!("{}", v.display()),
650648
}
651649
}
@@ -657,20 +655,22 @@ impl TryFrom<String> for ComposerUrlOrSshOrPathUrl {
657655
// try and parse as a regular Url first
658656
// reason is that Url handles e.g. 'svn+ssh://...' correctly
659657
// GitUrl really is only for the '[email protected]:foo/bar.git' cases
660-
match Url::parse(&value) {
661-
Ok(url) => Ok(Self::Url(url)),
662-
Err(_) => match GitUrl::parse(&value) {
663-
Ok(url) => {
664-
match url.scheme {
665-
// GitUrl will parse "local" URLs like "./foo", "foo/bar", "../test"
666-
// in that case we want to return a Path variant instead
667-
GitUrlScheme::File => Ok(Self::Path(PathBuf::from(&value))),
668-
_ => Ok(Self::GitUrl(url)),
658+
// (and even then, we convert back to a regular Url)
659+
Url::parse(&value)
660+
.map(Self::Url)
661+
.or_else(|_| {
662+
GitUrl::parse(&value).and_then(|git_url| {
663+
match &git_url.scheme() {
664+
// it's a file, but url::Url did not parse it as such, since it was relative
665+
// git-url-parse, however, accepts those
666+
// in that case, we return a PathBuf instead of a Url
667+
Some("file") => Ok(Self::Path(PathBuf::from(&value))),
668+
// it's an SSH style URL, "normalize" it to url::Url
669+
_ => Ok(Self::Url(git_url.try_into()?)),
669670
}
670-
}
671-
Err(e) => Err(format!("Invalid GitUrl {value}: {e}")),
672-
},
673-
}
671+
})
672+
})
673+
.map_err(|e| format!("Invalid GitUrl {value}: {e}"))
674674
}
675675
}
676676

0 commit comments

Comments
 (0)