MCPcopy Index your code
hub / github.com/emwalker/digraph / parse_path

Function parse_path

backend/src/git/client.rs:31–61  ·  view source on GitHub ↗
(input: &str)

Source from the content-addressed store, hash-verified

29}
30
31pub fn parse_path(input: &str) -> Result<(DataRoot, RepoId, ExternalId)> {
32 lazy_static! {
33 static ref RE: Regex =
34 Regex::new(r"^(.+?)/([\w-]+)/objects/([\w_-]{2})/([\w_-]{2})/([\w_-]+)/object.yaml$")
35 .unwrap();
36 }
37
38 let cap = RE
39 .captures(input)
40 .ok_or_else(|| Error::Repo(format!("bad path: {input}")))?;
41 if cap.len() != 6 {
42 return Err(Error::Command(format!("bad path: {cap:?}")));
43 }
44
45 let (root, repo_id, part1, part2, part3) =
46 match (cap.get(1), cap.get(2), cap.get(3), cap.get(4), cap.get(5)) {
47 (Some(root), Some(repo_id), Some(part1), Some(part2), Some(part3)) => (
48 root.as_str(),
49 RepoId::try_from(repo_id.as_str())?,
50 part1.as_str(),
51 part2.as_str(),
52 part3.as_str(),
53 ),
54 _ => return Err(Error::Repo(format!("bad path: {input}"))),
55 };
56
57 let oid: ExternalId = format!("{part1}{part2}{part3}").try_into()?;
58 let root = PathBuf::from(root);
59
60 Ok((DataRoot::new(root), repo_id, oid))
61}
62
63impl DataRoot {
64 pub fn new(root: PathBuf) -> Self {

Callers 2

parse_path_worksFunction · 0.85
mainFunction · 0.85

Calls 5

RepoClass · 0.85
as_strMethod · 0.80
lenMethod · 0.45
getMethod · 0.45
try_intoMethod · 0.45

Tested by 1

parse_path_worksFunction · 0.68