1use super::super::{context::*, errors::*, url::*, util::*};
2
3use {
4 relative_path::*,
5 std::{fmt, sync::*},
6};
7
8#[derive(Clone, Debug)]
22pub struct GitUrl {
23 pub repository_url: Arc<UrlRef>,
25
26 pub repository_gix_url: gix::Url,
28
29 pub path: RelativePathBuf,
31
32 pub(crate) context: UrlContextRef,
33}
34
35impl GitUrl {
36 pub fn parse(url_representation: &str) -> Result<(String, String), UrlError> {
38 parse_archive_entry_url_representation(url_representation, "git")
39 }
40
41 pub fn new(
43 context: &UrlContextRef,
44 repository_url: Arc<UrlRef>,
45 repository_gix_url: gix::Url,
46 path: RelativePathBuf,
47 ) -> Self {
48 Self { repository_url, repository_gix_url, path, context: context.clone() }
49 }
50
51 pub fn new_with(&self, path: RelativePathBuf) -> Self {
53 Self::new(&self.context, self.repository_url.clone(), self.repository_gix_url.clone(), path)
54 }
55}
56
57impl fmt::Display for GitUrl {
58 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
59 write!(formatter, "git:{}!{}", self.repository_url, self.path)
60 }
61}
62
63impl Into<UrlRef> for GitUrl {
66 fn into(self) -> UrlRef {
67 Box::new(self)
68 }
69}