Auto detect pkg_fmt (#310)

* Refactor: Extract `GhCrateMeta::find_baseline`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Update `Cargo.lock`: Update dep `compact_str`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Fix use of `fetchers`: Set `meta.pkg_fmt` using `fetcher.pkg_fmt()`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Derive `strum_macors::{Display, EnumIter}` for `PkgFmt`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Set typeof field `PkgMeta::pkg_fmt` to be `Option<PkgFmt>`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Optimize `Fetcher::new` to take `&Arc<Data>` instead of `&Data`

To avoid unnecessary `Data::clone` call in `GhCrateMeta`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Optimize `GhCrateMeta::find_baseline`: Avoid unnecessary spawning

for `let Err(_) = url`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Optimize spawning in `GhCrateMeta::find_baseline`

Ret `Option<Url>` instead of `(Url, bool)`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Add new method `target_meta` to trait `Fetcher`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Simplify `resolve_inner` using `Fetcher::target_meta`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Optimize loop in `resolve_inner`: Avoid cloning `PkgOverride`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Impl `PkgMeta::clone_without_overrides`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Optimize `resolve_inner` loop: Use `PkgMeta::clone_without_overrides`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Refactor: Simplify `Context::from_data` impl

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Refactor: Extract `launch_baseline_find_tasks`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Refactor: Simplify `<GhCrateMeta as Fetcher>::find`

Instead of launching tasks in an opaque manner in `Self::find_baseline`,
the new design returns an iterator which launches the tasks and thus
have a unified `.await` point for all these tasks.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Add `warn!`ing to report failure of `Context::render_url`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-08-22 22:28:36 +10:00 committed by GitHub
parent b5ea9a2293
commit 6b5e8f6875
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 106 additions and 66 deletions

4
Cargo.lock generated
View file

@ -288,9 +288,9 @@ dependencies = [
[[package]]
name = "compact_str"
version = "0.5.2"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5857fc4f27cd0fa2cd7c4a4fa780c0da3d898ae27e66bf6a719343e219e9a559"
checksum = "bbe793f2e4f8b2b8295ea7dfd141260c0a5c9f6d25c91bde42efed76a47e0bfe"
dependencies = [
"castaway",
"itoa",