Skip to content

Commit 980e78f

Browse files
committed
tag support for fetchgit and friends
1 parent 16ab26c commit 980e78f

63 files changed

Lines changed: 188 additions & 66 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/fetcher/bitbucket.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
22
impl_fetcher,
3-
simple::{SimpleFetcher, SimpleUrlFetcher},
3+
simple::{RevKey, SimpleFetcher, SimpleUrlFetcher},
44
};
55

66
pub struct FetchFromBitbucket;
@@ -9,6 +9,7 @@ impl_fetcher!(FetchFromBitbucket);
99
impl SimpleFetcher<'_, 2> for FetchFromBitbucket {
1010
const KEYS: [&'static str; 2] = ["owner", "repo"];
1111
const NAME: &'static str = "fetchFromBitbucket";
12+
const REV_KEY: RevKey = RevKey::RevOrTag;
1213
}
1314

1415
impl SimpleUrlFetcher<'_, 2> for FetchFromBitbucket {

src/fetcher/crates_io.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
22
Url, impl_fetcher,
3-
simple::{SimpleFetcher, SimpleUrlFetcher},
3+
simple::{RevKey, SimpleFetcher, SimpleUrlFetcher},
44
};
55

66
pub struct FetchCrate(pub bool);
@@ -9,7 +9,7 @@ impl_fetcher!(FetchCrate);
99
impl SimpleFetcher<'_, 1> for FetchCrate {
1010
const KEYS: [&'static str; 1] = ["pname"];
1111
const NAME: &'static str = "fetchCrate";
12-
const REV_KEY: &'static str = "version";
12+
const REV_KEY: RevKey = RevKey::Const("version");
1313

1414
fn get_values<'a>(&self, url: &'a Url) -> Option<[&'a str; 1]> {
1515
let mut xs = url.path_segments();

src/fetcher/git.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
use anyhow::Result;
22

3-
use crate::{GitScheme, Url, impl_fetcher, prefetch::git_prefetch, simple::SimpleFetcher};
3+
use crate::{
4+
GitScheme, Url, impl_fetcher,
5+
prefetch::git_prefetch,
6+
simple::{RevKey, SimpleFetcher},
7+
};
48

59
pub struct Fetchgit(pub GitScheme);
610
impl_fetcher!(Fetchgit);
711

812
impl<'a> SimpleFetcher<'a, 1> for Fetchgit {
913
const KEYS: [&'static str; 1] = ["url"];
1014
const NAME: &'static str = "fetchgit";
15+
const REV_KEY: RevKey = RevKey::RevOrTag;
1116
const SUBMODULES_DEFAULT: bool = true;
1217
const SUBMODULES_KEY: Option<&'static str> = Some("fetchSubmodules");
1318

@@ -24,6 +29,7 @@ impl Fetchgit {
2429
fn fetch(
2530
&self,
2631
values @ [url]: &[&str; 1],
32+
rev_key: &'static str,
2733
rev: &str,
2834
submodules: bool,
2935
args: &[(String, String)],
@@ -33,7 +39,7 @@ impl Fetchgit {
3339
if args.is_empty() && args_str.is_empty() {
3440
git_prefetch(matches!(self.0, GitScheme::Yes), url, rev, !submodules)
3541
} else {
36-
self.fetch_fod(values, rev, submodules, args, args_str, nixpkgs)
42+
self.fetch_fod(values, rev_key, rev, submodules, args, args_str, nixpkgs)
3743
}
3844
}
3945
}

src/fetcher/gitea.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use serde::Deserialize;
44
use crate::{
55
impl_fetcher,
66
prefetch::{git_prefetch, url_prefetch},
7-
simple::SimpleFetcher,
7+
simple::{RevKey, SimpleFetcher},
88
};
99

1010
pub struct FetchFromGitea<'a>(pub &'a str);
@@ -18,6 +18,7 @@ struct Commit {
1818
impl SimpleFetcher<'_, 2> for FetchFromGitea<'_> {
1919
const KEYS: [&'static str; 2] = ["owner", "repo"];
2020
const NAME: &'static str = "fetchFromGitea";
21+
const REV_KEY: RevKey = RevKey::RevOrTag;
2122
const SUBMODULES_KEY: Option<&'static str> = Some("fetchSubmodules");
2223

2324
fn host(&self) -> Option<&str> {
@@ -44,6 +45,7 @@ impl FetchFromGitea<'_> {
4445
fn fetch(
4546
&self,
4647
values @ [owner, repo]: &[&str; 2],
48+
rev_key: &'static str,
4749
rev: &str,
4850
submodules: bool,
4951
args: &[(String, String)],
@@ -65,7 +67,7 @@ impl FetchFromGitea<'_> {
6567
)
6668
}
6769
} else {
68-
self.fetch_fod(values, rev, submodules, args, args_str, nixpkgs)
70+
self.fetch_fod(values, rev_key, rev, submodules, args, args_str, nixpkgs)
6971
}
7072
}
7173
}

src/fetcher/github.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use serde::Deserialize;
33

44
use crate::{
55
impl_fetcher,
6-
simple::{SimpleFetcher, SimpleGitFetcher},
6+
simple::{RevKey, SimpleFetcher, SimpleGitFetcher},
77
};
88

99
pub struct FetchFromGitHub<'a>(pub Option<&'a str>);
@@ -24,6 +24,7 @@ impl SimpleFetcher<'_, 2> for FetchFromGitHub<'_> {
2424
const HOST_KEY: &'static str = "githubBase";
2525
const KEYS: [&'static str; 2] = ["owner", "repo"];
2626
const NAME: &'static str = "fetchFromGitHub";
27+
const REV_KEY: RevKey = RevKey::RevOrTag;
2728
const SUBMODULES_KEY: Option<&'static str> = Some("fetchSubmodules");
2829

2930
fn host(&self) -> Option<&str> {

src/fetcher/gitiles.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
22
Url, impl_fetcher,
3-
simple::{SimpleFetcher, SimpleUrlFetcher},
3+
simple::{RevKey, SimpleFetcher, SimpleUrlFetcher},
44
};
55

66
pub struct FetchFromGitiles;
@@ -9,6 +9,7 @@ impl_fetcher!(FetchFromGitiles);
99
impl<'a> SimpleFetcher<'a, 1> for FetchFromGitiles {
1010
const KEYS: [&'static str; 1] = ["url"];
1111
const NAME: &'static str = "fetchFromGitiles";
12+
const REV_KEY: RevKey = RevKey::RevOrTag;
1213

1314
fn get_values(&self, url: &'a Url) -> Option<[&'a str; 1]> {
1415
Some([url.as_str()])

src/fetcher/gitlab.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use serde::Deserialize;
55

66
use crate::{
77
Url, impl_fetcher,
8-
simple::{SimpleFetcher, SimpleGitFetcher},
8+
simple::{RevKey, SimpleFetcher, SimpleGitFetcher},
99
};
1010

1111
pub struct FetchFromGitLab<'a> {
@@ -31,6 +31,7 @@ struct Commit {
3131
impl<'a> SimpleFetcher<'a, 2> for FetchFromGitLab<'a> {
3232
const KEYS: [&'static str; 2] = ["owner", "repo"];
3333
const NAME: &'static str = "fetchFromGitLab";
34+
const REV_KEY: RevKey = RevKey::RevOrTag;
3435
const SUBMODULES_KEY: Option<&'static str> = Some("fetchSubmodules");
3536

3637
fn host(&self) -> Option<&str> {

src/fetcher/hex.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
22
Url, impl_fetcher,
3-
simple::{SimpleFetcher, SimpleUrlFetcher},
3+
simple::{RevKey, SimpleFetcher, SimpleUrlFetcher},
44
};
55

66
pub struct FetchHex;
@@ -10,7 +10,7 @@ impl<'a> SimpleFetcher<'a, 1> for FetchHex {
1010
const HASH_KEY: &'static str = "sha256";
1111
const KEYS: [&'static str; 1] = ["pkg"];
1212
const NAME: &'static str = "fetchHex";
13-
const REV_KEY: &'static str = "version";
13+
const REV_KEY: RevKey = RevKey::Const("version");
1414

1515
fn get_values(&self, url: &'a Url) -> Option<[&'a str; 1]> {
1616
Some([url.path_segments().nth(1)?])

src/fetcher/hg.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ impl Fetchhg {
2424
fn fetch(
2525
&self,
2626
values @ [url]: &[&str; 1],
27+
rev_key: &'static str,
2728
rev: &str,
2829
submodules: bool,
2930
args: &[(String, String)],
@@ -36,7 +37,7 @@ impl Fetchhg {
3637
if rev.len() == 40 { "rev" } else { "ref" },
3738
))
3839
} else {
39-
self.fetch_fod(values, rev, submodules, args, args_str, nixpkgs)
40+
self.fetch_fod(values, rev_key, rev, submodules, args, args_str, nixpkgs)
4041
}
4142
}
4243
}

src/fetcher/mod.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,12 @@ macro_rules! impl_fetcher {
113113
Some(rev) => rev,
114114
None => self.fetch_rev(values)?,
115115
};
116+
let (rev_key, rev) = self.rev_entry(&rev);
116117

117118
let submodules = self.resolve_submodules(submodules);
118-
let hash = self.fetch(values, &rev, submodules, &args, &args_str, nixpkgs)?;
119+
let hash = self.fetch(values, rev_key, rev, submodules, &args, &args_str, nixpkgs)?;
119120

120-
self.write_nix(out, values, rev, hash, submodules, args, args_str, overwrites, indent)
121+
self.write_nix(out, values, rev_key, rev, hash, submodules, args, args_str, overwrites, indent)
121122
}
122123

123124
fn fetch_hash(
@@ -140,9 +141,10 @@ macro_rules! impl_fetcher {
140141
Some(rev) => rev,
141142
None => self.fetch_rev(values)?,
142143
};
144+
let (rev_key, rev) = self.rev_entry(&rev);
143145

144146
let submodules = self.resolve_submodules(submodules);
145-
let hash = self.fetch(values, &rev, submodules, &args, &args_str, nixpkgs)?;
147+
let hash = self.fetch(values, rev_key, rev, submodules, &args, &args_str, nixpkgs)?;
146148
write!(out, "{}", hash)?;
147149

148150
Ok(())
@@ -170,13 +172,15 @@ macro_rules! impl_fetcher {
170172
Some(rev) => rev,
171173
None => self.fetch_rev(values)?,
172174
};
175+
let (rev_key, rev) = self.rev_entry(&rev);
173176

174177
let submodules = self.resolve_submodules(submodules);
175-
let hash = self.fetch(values, &rev, submodules, &args, &args_str, nixpkgs)?;
178+
let hash = self.fetch(values, rev_key, rev, submodules, &args, &args_str, nixpkgs)?;
176179

177180
self.write_json(
178181
out,
179182
values,
183+
rev_key,
180184
rev,
181185
hash,
182186
submodules,
@@ -209,7 +213,8 @@ macro_rules! impl_fetcher {
209213
fetcher_args["group"] = json!(group);
210214
}
211215
if let Some(rev) = rev {
212-
fetcher_args[Self::REV_KEY] = json!(rev);
216+
let (rev_key, rev) = self.rev_entry(&rev);
217+
fetcher_args[rev_key] = json!(rev);
213218
}
214219

215220
serde_json::to_writer(

0 commit comments

Comments
 (0)