support fetchsvn

This commit is contained in:
figsoda 2023-01-02 14:19:41 -05:00
parent 87f7c3c7bf
commit 2f0e9a71ed
5 changed files with 41 additions and 6 deletions

View File

@ -84,4 +84,5 @@ pub enum FetcherFunction {
FetchFromSourcehut,
Fetchgit,
Fetchhg,
Fetchsvn,
}

View File

@ -7,6 +7,7 @@ mod gitlab;
mod hg;
mod repo_or_cz;
mod sourcehut;
mod svn;
pub use bitbucket::FetchFromBitbucket;
pub use git::Fetchgit;
@ -17,6 +18,7 @@ pub use gitlab::FetchFromGitLab;
pub use hg::Fetchhg;
pub use repo_or_cz::FetchFromRepoOrCz;
pub use sourcehut::FetchFromSourcehut;
pub use svn::Fetchsvn;
use anyhow::Result;
use enum_dispatch::enum_dispatch;
@ -61,6 +63,7 @@ pub enum FetcherDispatch<'a> {
FetchFromSourcehut(FetchFromSourcehut<'a>),
Fetchgit(Fetchgit),
Fetchhg(Fetchhg),
Fetchsvn(Fetchsvn),
}
#[macro_export]

21
src/fetcher/svn.rs Normal file
View File

@ -0,0 +1,21 @@
use url::Url;
use crate::{
impl_fetcher,
simple::{SimpleFetcher, SimpleFodFetcher},
};
pub struct Fetchsvn;
impl_fetcher!(Fetchsvn);
impl<'a> SimpleFetcher<'a, 1> for Fetchsvn {
const HASH_KEY: &'static str = "sha256";
const KEYS: [&'static str; 1] = ["url"];
const NAME: &'static str = "fetchsvn";
fn get_values(&self, url: &'a Url) -> Option<[&'a str; 1]> {
Some([url.as_ref()])
}
}
impl<'a> SimpleFodFetcher<'a, 1> for Fetchsvn {}

View File

@ -15,6 +15,7 @@ use crate::{
fetcher::{
FetchFromBitbucket, FetchFromGitHub, FetchFromGitLab, FetchFromGitea, FetchFromGitiles,
FetchFromRepoOrCz, FetchFromSourcehut, Fetcher, FetcherDispatch, Fetchgit, Fetchhg,
Fetchsvn,
},
};
@ -26,7 +27,12 @@ fn main() -> Result<()> {
if opts.list_fetchers || opts.list_possible_fetchers {
let mut out = stdout().lock();
for fetcher in FetcherFunction::value_variants() {
if matches!(fetcher, FetcherFunction::Fetchhg) && opts.list_possible_fetchers {
if opts.list_possible_fetchers
&& matches!(
fetcher,
FetcherFunction::Fetchhg | FetcherFunction::Fetchsvn
)
{
continue;
}
if let Some(fetcher) = fetcher.to_possible_value() {
@ -100,6 +106,8 @@ fn main() -> Result<()> {
(None | Some(FetcherFunction::Fetchgit), _) => Fetchgit.into(),
(Some(FetcherFunction::Fetchhg), _) => Fetchhg.into(),
(Some(FetcherFunction::Fetchsvn), _) => Fetchsvn.into(),
};
let out = &mut stdout().lock();

View File

@ -10,6 +10,7 @@ use crate::prefetch::{flake_prefetch, fod_prefetch, url_prefetch};
pub trait SimpleFetcher<'a, const N: usize> {
const HOST_KEY: &'static str = "domain";
const HASH_KEY: &'static str = "hash";
const KEYS: [&'static str; N];
const NAME: &'static str;
@ -61,7 +62,8 @@ pub trait SimpleFetcher<'a, const N: usize> {
write!(
expr,
r#"rev="{rev}";hash="sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";"#
r#"rev="{rev}";{}="sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";"#,
Self::HASH_KEY,
)?;
for (key, value) in args {
@ -118,10 +120,10 @@ pub trait SimpleFetcher<'a, const N: usize> {
} else {
writeln!(out, r#"{indent} rev = "{rev}";"#)?;
}
if let Some(hash) = overwrites.remove("hash") {
writeln!(out, "{indent} hash = {hash};")?;
if let Some(hash) = overwrites.remove(Self::HASH_KEY) {
writeln!(out, "{indent} {} = {hash};", Self::HASH_KEY)?;
} else {
writeln!(out, r#"{indent} hash = "{hash}";"#)?;
writeln!(out, r#"{indent} {} = "{hash}";"#, Self::HASH_KEY)?;
}
for (key, value) in args {
@ -158,7 +160,7 @@ pub trait SimpleFetcher<'a, const N: usize> {
) -> Result<()> {
let mut fetcher_args = json!({
"rev": rev,
"hash": hash,
Self::HASH_KEY: hash,
});
if let Some(host) = self.host() {