mirror of https://github.com/stelzo/typst.git
migrating from git2 to gitoxide crate for git downloads
This commit is contained in:
parent
a295495dc5
commit
3962be8ebf
File diff suppressed because it is too large
Load Diff
|
|
@ -34,7 +34,6 @@ typst-timing = { path = "crates/typst-timing", version = "0.12.0" }
|
||||||
typst-utils = { path = "crates/typst-utils", version = "0.12.0" }
|
typst-utils = { path = "crates/typst-utils", version = "0.12.0" }
|
||||||
typst-assets = { git = "https://github.com/typst/typst-assets", rev = "8cccef9" }
|
typst-assets = { git = "https://github.com/typst/typst-assets", rev = "8cccef9" }
|
||||||
typst-dev-assets = { git = "https://github.com/typst/typst-dev-assets", rev = "b07d156" }
|
typst-dev-assets = { git = "https://github.com/typst/typst-dev-assets", rev = "b07d156" }
|
||||||
auth-git2 = "0.5.5"
|
|
||||||
arrayvec = "0.7.4"
|
arrayvec = "0.7.4"
|
||||||
az = "1.2"
|
az = "1.2"
|
||||||
base64 = "0.22"
|
base64 = "0.22"
|
||||||
|
|
@ -59,7 +58,7 @@ env_proxy = "0.4"
|
||||||
flate2 = "1"
|
flate2 = "1"
|
||||||
fontdb = { version = "0.21", default-features = false }
|
fontdb = { version = "0.21", default-features = false }
|
||||||
fs_extra = "1.3"
|
fs_extra = "1.3"
|
||||||
git2 = "0.19.0"
|
gix = "0.68.0"
|
||||||
hayagriva = "0.8"
|
hayagriva = "0.8"
|
||||||
heck = "0.5"
|
heck = "0.5"
|
||||||
hypher = "0.1.4"
|
hypher = "0.1.4"
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,7 @@ native-tls = { workspace = true, optional = true }
|
||||||
once_cell = { workspace = true }
|
once_cell = { workspace = true }
|
||||||
tar = { workspace = true, optional = true }
|
tar = { workspace = true, optional = true }
|
||||||
ureq = { workspace = true, optional = true }
|
ureq = { workspace = true, optional = true }
|
||||||
git2 = { workspace = true, optional = true }
|
gix = { workspace = true, optional = true, features = ["worktree-mutation", "blocking-network-client"] }
|
||||||
auth-git2 = { workspace = true, optional = true }
|
|
||||||
|
|
||||||
# Explicitly depend on OpenSSL if applicable, so that we can add the
|
# Explicitly depend on OpenSSL if applicable, so that we can add the
|
||||||
# `openssl/vendored` feature to it if `vendor-openssl` is enabled.
|
# `openssl/vendored` feature to it if `vendor-openssl` is enabled.
|
||||||
|
|
@ -42,7 +41,7 @@ fonts = ["dep:fontdb", "fontdb/memmap", "fontdb/fontconfig"]
|
||||||
# Add generic downloading utilities
|
# Add generic downloading utilities
|
||||||
downloads = ["downloads_http", "downloads_git"]
|
downloads = ["downloads_http", "downloads_git"]
|
||||||
downloads_http = ["dep:env_proxy", "dep:native-tls", "dep:ureq", "dep:openssl"]
|
downloads_http = ["dep:env_proxy", "dep:native-tls", "dep:ureq", "dep:openssl"]
|
||||||
downloads_git = ["git2", "auth-git2"]
|
downloads_git = ["gix"]
|
||||||
|
|
||||||
# Add package downloading utilities, implies `downloads`
|
# Add package downloading utilities, implies `downloads`
|
||||||
packages = ["downloads", "dep:dirs", "dep:flate2", "dep:tar"]
|
packages = ["downloads", "dep:dirs", "dep:flate2", "dep:tar"]
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,8 @@
|
||||||
use crate::package_downloads::{DownloadState, PackageDownloader, Progress};
|
use crate::package_downloads::{DownloadState, PackageDownloader, Progress};
|
||||||
use auth_git2::GitAuthenticator;
|
|
||||||
use ecow::{eco_format, EcoString};
|
use ecow::{eco_format, EcoString};
|
||||||
use git2::build::RepoBuilder;
|
use gix::remote::fetch::Shallow;
|
||||||
use git2::{FetchOptions, RemoteCallbacks};
|
|
||||||
use std::collections::VecDeque;
|
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
use std::num::NonZero;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use typst_library::diag::{PackageError, PackageResult};
|
use typst_library::diag::{PackageError, PackageResult};
|
||||||
|
|
@ -32,45 +30,34 @@ impl GitDownloader {
|
||||||
progress: &mut dyn Progress,
|
progress: &mut dyn Progress,
|
||||||
) -> Result<(), EcoString> {
|
) -> Result<(), EcoString> {
|
||||||
progress.print_start();
|
progress.print_start();
|
||||||
|
|
||||||
eprintln!("{} {} {}", repo, tag, dest.display());
|
|
||||||
|
|
||||||
let state = DownloadState {
|
let state = DownloadState {
|
||||||
content_len: None,
|
content_len: None,
|
||||||
total_downloaded: 0,
|
total_downloaded: 0,
|
||||||
bytes_per_second: VecDeque::from(vec![0; 5]),
|
bytes_per_second: Default::default(),
|
||||||
start_time: Instant::now(),
|
start_time: Instant::now(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let auth = GitAuthenticator::default();
|
std::fs::create_dir_all(dest).map_err(|x| eco_format!("{x}"))?;
|
||||||
let git_config = git2::Config::open_default()
|
let url = gix::url::parse(repo.into()).map_err(|x| eco_format!("{x}"))?;
|
||||||
.map_err(|err| EcoString::from(format!("{err}")))?;
|
let mut prepare_fetch =
|
||||||
|
gix::prepare_clone(url, dest).map_err(|x| eco_format!("{x}"))?;
|
||||||
|
prepare_fetch = prepare_fetch
|
||||||
|
.with_shallow(Shallow::DepthAtRemote(NonZero::new(1).unwrap()))
|
||||||
|
.with_ref_name(Some(tag))
|
||||||
|
.map_err(|x| eco_format!("{x}"))?;
|
||||||
|
|
||||||
let mut fetch_options = FetchOptions::new();
|
let (mut prepare_checkout, _) = prepare_fetch
|
||||||
let mut remote_callbacks = RemoteCallbacks::new();
|
.fetch_then_checkout(gix::progress::Discard, &gix::interrupt::IS_INTERRUPTED)
|
||||||
|
.map_err(|x| eco_format!("{x}"))?;
|
||||||
remote_callbacks.credentials(auth.credentials(&git_config));
|
if prepare_checkout.repo().work_dir().is_none() {
|
||||||
fetch_options.remote_callbacks(remote_callbacks);
|
return Err(eco_format!(
|
||||||
|
"Cloned git repository but files are not available."
|
||||||
let repo = RepoBuilder::new()
|
))?;
|
||||||
.fetch_options(fetch_options)
|
|
||||||
.clone(repo, dest)
|
|
||||||
.map_err(|err| EcoString::from(format!("{err}")))?;
|
|
||||||
|
|
||||||
let (object, reference) = repo
|
|
||||||
.revparse_ext(tag)
|
|
||||||
.map_err(|err| EcoString::from(format!("{err}")))?;
|
|
||||||
repo.checkout_tree(&object, None)
|
|
||||||
.map_err(|err| EcoString::from(format!("{err}")))?;
|
|
||||||
|
|
||||||
match reference {
|
|
||||||
// gref is an actual reference like branches or tags
|
|
||||||
Some(gref) => repo.set_head(gref.name().unwrap()),
|
|
||||||
// this is a commit, not a reference
|
|
||||||
None => repo.set_head_detached(object.id()),
|
|
||||||
}
|
}
|
||||||
.map_err(|err| EcoString::from(format!("{err}")))?;
|
|
||||||
|
|
||||||
|
prepare_checkout
|
||||||
|
.main_worktree(gix::progress::Discard, &gix::interrupt::IS_INTERRUPTED)
|
||||||
|
.map_err(|x| eco_format!("{x}"))?;
|
||||||
progress.print_finish(&state);
|
progress.print_finish(&state);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
@ -122,7 +109,7 @@ impl PackageDownloader for GitDownloader {
|
||||||
) -> PackageResult<()> {
|
) -> PackageResult<()> {
|
||||||
let repo = Self::parse_namespace(spec.namespace.as_str(), spec.name.as_str())
|
let repo = Self::parse_namespace(spec.namespace.as_str(), spec.name.as_str())
|
||||||
.map_err(|x| PackageError::Other(Some(x)))?;
|
.map_err(|x| PackageError::Other(Some(x)))?;
|
||||||
let tag = format!("v{}", spec.version);
|
let tag = format!("refs/tags/v{}", spec.version);
|
||||||
self.download_with_progress(repo.as_str(), tag.as_str(), package_dir, progress)
|
self.download_with_progress(repo.as_str(), tag.as_str(), package_dir, progress)
|
||||||
.map_err(|x| PackageError::Other(Some(x)))
|
.map_err(|x| PackageError::Other(Some(x)))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue