Readme, Box leak, async mutex, repo URL parsing
This commit is contained in:
parent
da6fb1c3c8
commit
44c310ac11
8 changed files with 103 additions and 32 deletions
|
|
@ -107,6 +107,7 @@ pub enum FetchRepoError {
|
|||
CannotCreateDir(std::io::Error),
|
||||
TooManyEntries,
|
||||
Client(ClientError),
|
||||
UrlParsing,
|
||||
}
|
||||
|
||||
impl From<ClientError> for FetchRepoError {
|
||||
|
|
@ -133,6 +134,12 @@ impl From<trillium_client::ClientSerdeError> for FetchRepoError {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<url::ParseError> for FetchRepoError {
|
||||
fn from(_value: url::ParseError) -> Self {
|
||||
Self::UrlParsing
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct RepoIndex {
|
||||
files: Vec<RepoIndexFile>,
|
||||
|
|
@ -145,17 +152,25 @@ pub struct RepoIndexFile {
|
|||
|
||||
pub async fn fetch_repo_tree_index_at_commit(
|
||||
client: &mut Client,
|
||||
url: &str,
|
||||
owner: &str,
|
||||
repo: &str,
|
||||
repo_url: &str,
|
||||
commit_hash: &str,
|
||||
token: Option<&str>,
|
||||
) -> Result<RepoIndex, FetchRepoError> {
|
||||
let parsed = url::Url::parse(repo_url)?;
|
||||
let mut base = parsed.clone();
|
||||
base.set_fragment(None);
|
||||
let base_url = base.as_str();
|
||||
// Is the URL always /owner/repo?
|
||||
let mut segments = parsed.path_segments().ok_or(FetchRepoError::UrlParsing)?;
|
||||
let owner = segments.next().ok_or(FetchRepoError::UrlParsing)?;
|
||||
let repo = segments.next().ok_or(FetchRepoError::UrlParsing)?;
|
||||
let repo = repo.strip_suffix(".git").unwrap_or(repo);
|
||||
|
||||
let mut repo_index = RepoIndex::default();
|
||||
let mut count: u32 = 0;
|
||||
for page in 1..MAX_PAGE {
|
||||
let res =
|
||||
fetch_repo_tree_at_commit_page(client, url, owner, repo, commit_hash, token, page)
|
||||
fetch_repo_tree_at_commit_page(client, base_url, owner, repo, commit_hash, token, page)
|
||||
.await?;
|
||||
count = count.saturating_add(res.total_count);
|
||||
if count > MAX_ENTRIES || res.total_count > MAX_ENTRIES {
|
||||
|
|
|
|||
Loading…
Reference in a new issue