mirror of
https://github.com/pesde-pkg/pesde.git
synced 2024-12-12 11:00:36 +00:00
refactor: use gix urls in more places
This commit is contained in:
parent
b10e7667f0
commit
986196ac67
11 changed files with 87 additions and 52 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -2702,7 +2702,6 @@ name = "pesde"
|
||||||
version = "0.5.0-dev.0"
|
version = "0.5.0-dev.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"cfg-if",
|
|
||||||
"chrono",
|
"chrono",
|
||||||
"clap",
|
"clap",
|
||||||
"colored",
|
"colored",
|
||||||
|
|
|
@ -10,8 +10,8 @@ repository = "https://github.com/daimond113/pesde"
|
||||||
include = ["src/**/*", "Cargo.toml", "Cargo.lock", "README.md", "LICENSE", "CHANGELOG.md"]
|
include = ["src/**/*", "Cargo.toml", "Cargo.lock", "README.md", "LICENSE", "CHANGELOG.md"]
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
bin = ["clap", "directories", "pretty_env_logger", "reqwest/json", "reqwest/multipart", "indicatif", "indicatif-log-bridge", "inquire", "toml_edit", "colored", "anyhow", "keyring", "open", "gix/worktree-mutation"]
|
bin = ["clap", "directories", "pretty_env_logger", "reqwest/json", "reqwest/multipart", "indicatif", "indicatif-log-bridge", "inquire", "toml_edit", "colored", "anyhow", "keyring", "open", "gix/worktree-mutation", "serde_json"]
|
||||||
wally-compat = ["zip", "roblox"]
|
wally-compat = ["zip", "serde_json", "roblox"]
|
||||||
roblox = []
|
roblox = []
|
||||||
lune = []
|
lune = []
|
||||||
luau = []
|
luau = []
|
||||||
|
@ -28,7 +28,6 @@ uninlined_format_args = "warn"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = { version = "1.0.204", features = ["derive"] }
|
serde = { version = "1.0.204", features = ["derive"] }
|
||||||
toml = "0.8.15"
|
toml = "0.8.15"
|
||||||
serde_json = "1.0.120"
|
|
||||||
serde_with = "3.9.0"
|
serde_with = "3.9.0"
|
||||||
gix = { version = "0.64.0", default-features = false, features = ["blocking-http-transport-reqwest-rust-tls", "revparse-regex", "credentials"] }
|
gix = { version = "0.64.0", default-features = false, features = ["blocking-http-transport-reqwest-rust-tls", "revparse-regex", "credentials"] }
|
||||||
semver = { version = "1.0.23", features = ["serde"] }
|
semver = { version = "1.0.23", features = ["serde"] }
|
||||||
|
@ -42,7 +41,6 @@ thiserror = "1.0.63"
|
||||||
threadpool = "1.8.1"
|
threadpool = "1.8.1"
|
||||||
full_moon = { version = "1.0.0-rc.5", features = ["luau"] }
|
full_moon = { version = "1.0.0-rc.5", features = ["luau"] }
|
||||||
url = { version = "2.5.2", features = ["serde"] }
|
url = { version = "2.5.2", features = ["serde"] }
|
||||||
cfg-if = "1.0.0"
|
|
||||||
# TODO: reevaluate whether to use this
|
# TODO: reevaluate whether to use this
|
||||||
# secrecy = "0.8.0"
|
# secrecy = "0.8.0"
|
||||||
chrono = { version = "0.4.38", features = ["serde"] }
|
chrono = { version = "0.4.38", features = ["serde"] }
|
||||||
|
@ -51,6 +49,7 @@ chrono = { version = "0.4.38", features = ["serde"] }
|
||||||
git2 = { version = "0.19.0", optional = true }
|
git2 = { version = "0.19.0", optional = true }
|
||||||
|
|
||||||
zip = { version = "2.1.5", optional = true }
|
zip = { version = "2.1.5", optional = true }
|
||||||
|
serde_json = { version = "1.0.120", optional = true }
|
||||||
|
|
||||||
anyhow = { version = "1.0.86", optional = true }
|
anyhow = { version = "1.0.86", optional = true }
|
||||||
open = { version = "5.3.0", optional = true }
|
open = { version = "5.3.0", optional = true }
|
||||||
|
|
|
@ -61,8 +61,8 @@ impl LoginCommand {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let index_url = match &self.index {
|
let index_url = match self.index.as_deref() {
|
||||||
Some(index) => match index.parse() {
|
Some(index) => match index.try_into() {
|
||||||
Ok(url) => Some(url),
|
Ok(url) => Some(url),
|
||||||
Err(_) => None,
|
Err(_) => None,
|
||||||
},
|
},
|
||||||
|
@ -84,12 +84,7 @@ impl LoginCommand {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let source = PesdePackageSource::new(
|
let source = PesdePackageSource::new(index_url);
|
||||||
index_url
|
|
||||||
.as_str()
|
|
||||||
.try_into()
|
|
||||||
.context("cannot parse URL to git URL")?,
|
|
||||||
);
|
|
||||||
source.refresh(project).context("failed to refresh index")?;
|
source.refresh(project).context("failed to refresh index")?;
|
||||||
|
|
||||||
let config = source
|
let config = source
|
||||||
|
|
|
@ -5,8 +5,8 @@ use pesde::Project;
|
||||||
#[derive(Debug, Args)]
|
#[derive(Debug, Args)]
|
||||||
pub struct DefaultIndexCommand {
|
pub struct DefaultIndexCommand {
|
||||||
/// The new index URL to set as default, don't pass any value to check the current default index
|
/// The new index URL to set as default, don't pass any value to check the current default index
|
||||||
#[arg(index = 1)]
|
#[arg(index = 1, value_parser = crate::cli::parse_gix_url)]
|
||||||
index: Option<url::Url>,
|
index: Option<gix::Url>,
|
||||||
|
|
||||||
/// Resets the default index to the default value
|
/// Resets the default index to the default value
|
||||||
#[arg(short, long, conflicts_with = "index")]
|
#[arg(short, long, conflicts_with = "index")]
|
||||||
|
|
|
@ -5,8 +5,8 @@ use pesde::Project;
|
||||||
#[derive(Debug, Args)]
|
#[derive(Debug, Args)]
|
||||||
pub struct ScriptsRepoCommand {
|
pub struct ScriptsRepoCommand {
|
||||||
/// The new repo URL to set as default, don't pass any value to check the current default repo
|
/// The new repo URL to set as default, don't pass any value to check the current default repo
|
||||||
#[arg(index = 1)]
|
#[arg(index = 1, value_parser = crate::cli::parse_gix_url)]
|
||||||
repo: Option<url::Url>,
|
repo: Option<gix::Url>,
|
||||||
|
|
||||||
/// Resets the default repo to the default value
|
/// Resets the default repo to the default value
|
||||||
#[arg(short, long, conflicts_with = "repo")]
|
#[arg(short, long, conflicts_with = "repo")]
|
||||||
|
|
|
@ -144,8 +144,12 @@ impl InitCommand {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
manifest["indices"][DEFAULT_INDEX_NAME] =
|
manifest["indices"][DEFAULT_INDEX_NAME] = toml_edit::value(
|
||||||
toml_edit::value(read_config(project.data_dir())?.default_index.as_str());
|
read_config(project.data_dir())?
|
||||||
|
.default_index
|
||||||
|
.to_bstring()
|
||||||
|
.to_string(),
|
||||||
|
);
|
||||||
|
|
||||||
project.write_manifest(manifest.to_string())?;
|
project.write_manifest(manifest.to_string())?;
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,9 @@ use std::{collections::HashSet, sync::Arc, time::Duration};
|
||||||
|
|
||||||
#[derive(Debug, Args)]
|
#[derive(Debug, Args)]
|
||||||
pub struct InstallCommand {
|
pub struct InstallCommand {
|
||||||
/// The amount of threads to use for downloading, defaults to 6
|
/// The amount of threads to use for downloading
|
||||||
#[arg(short, long)]
|
#[arg(short, long, default_value_t = 6, value_parser = clap::value_parser!(u64).range(1..=128))]
|
||||||
threads: Option<usize>,
|
threads: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InstallCommand {
|
impl InstallCommand {
|
||||||
|
@ -92,7 +92,7 @@ impl InstallCommand {
|
||||||
&graph,
|
&graph,
|
||||||
&mut refreshed_sources,
|
&mut refreshed_sources,
|
||||||
&reqwest_client(project.data_dir())?,
|
&reqwest_client(project.data_dir())?,
|
||||||
self.threads.unwrap_or(6).max(1),
|
self.threads as usize,
|
||||||
)
|
)
|
||||||
.context("failed to download dependencies")?;
|
.context("failed to download dependencies")?;
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,16 @@ mod self_install;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct CliConfig {
|
pub struct CliConfig {
|
||||||
pub default_index: url::Url,
|
#[serde(
|
||||||
pub scripts_repo: url::Url,
|
serialize_with = "crate::util::serialize_gix_url",
|
||||||
|
deserialize_with = "crate::util::deserialize_gix_url"
|
||||||
|
)]
|
||||||
|
pub default_index: gix::Url,
|
||||||
|
#[serde(
|
||||||
|
serialize_with = "crate::util::serialize_gix_url",
|
||||||
|
deserialize_with = "crate::util::deserialize_gix_url"
|
||||||
|
)]
|
||||||
|
pub scripts_repo: gix::Url,
|
||||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||||
pub token: Option<String>,
|
pub token: Option<String>,
|
||||||
}
|
}
|
||||||
|
@ -30,9 +38,11 @@ pub struct CliConfig {
|
||||||
impl Default for CliConfig {
|
impl Default for CliConfig {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
default_index: "https://github.com/daimond113/pesde-index".parse().unwrap(),
|
default_index: "https://github.com/daimond113/pesde-index"
|
||||||
|
.try_into()
|
||||||
|
.unwrap(),
|
||||||
scripts_repo: "https://github.com/daimond113/pesde-scripts"
|
scripts_repo: "https://github.com/daimond113/pesde-scripts"
|
||||||
.parse()
|
.try_into()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
token: None,
|
token: None,
|
||||||
}
|
}
|
||||||
|
@ -221,7 +231,7 @@ pub fn update_scripts_folder(project: &Project) -> anyhow::Result<()> {
|
||||||
|
|
||||||
let cli_config = read_config(project.data_dir())?;
|
let cli_config = read_config(project.data_dir())?;
|
||||||
|
|
||||||
gix::prepare_clone(cli_config.scripts_repo.as_str(), &scripts_dir)
|
gix::prepare_clone(cli_config.scripts_repo, &scripts_dir)
|
||||||
.context("failed to prepare scripts repository clone")?
|
.context("failed to prepare scripts repository clone")?
|
||||||
.fetch_then_checkout(gix::progress::Discard, &false.into())
|
.fetch_then_checkout(gix::progress::Discard, &false.into())
|
||||||
.context("failed to fetch and checkout scripts repository")?
|
.context("failed to fetch and checkout scripts repository")?
|
||||||
|
@ -333,6 +343,10 @@ impl VersionedPackageName {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn parse_gix_url(s: &str) -> Result<gix::Url, gix::url::parse::Error> {
|
||||||
|
s.try_into()
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, clap::Subcommand)]
|
#[derive(Debug, clap::Subcommand)]
|
||||||
pub enum Subcommand {
|
pub enum Subcommand {
|
||||||
/// Authentication-related commands
|
/// Authentication-related commands
|
||||||
|
|
|
@ -30,11 +30,20 @@ pub struct Manifest {
|
||||||
pub private: bool,
|
pub private: bool,
|
||||||
#[serde(default, skip_serializing)]
|
#[serde(default, skip_serializing)]
|
||||||
pub scripts: BTreeMap<String, RelativePathBuf>,
|
pub scripts: BTreeMap<String, RelativePathBuf>,
|
||||||
#[serde(default)]
|
#[serde(
|
||||||
pub indices: BTreeMap<String, url::Url>,
|
default,
|
||||||
|
serialize_with = "crate::util::serialize_gix_url_map",
|
||||||
|
deserialize_with = "crate::util::deserialize_gix_url_map"
|
||||||
|
)]
|
||||||
|
pub indices: BTreeMap<String, gix::Url>,
|
||||||
#[cfg(feature = "wally-compat")]
|
#[cfg(feature = "wally-compat")]
|
||||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
#[serde(
|
||||||
pub wally_indices: BTreeMap<String, url::Url>,
|
default,
|
||||||
|
skip_serializing_if = "BTreeMap::is_empty",
|
||||||
|
serialize_with = "crate::util::serialize_gix_url_map",
|
||||||
|
deserialize_with = "crate::util::deserialize_gix_url_map"
|
||||||
|
)]
|
||||||
|
pub wally_indices: BTreeMap<String, gix::Url>,
|
||||||
#[serde(default, skip_serializing)]
|
#[serde(default, skip_serializing)]
|
||||||
pub overrides: BTreeMap<OverrideKey, DependencySpecifiers>,
|
pub overrides: BTreeMap<OverrideKey, DependencySpecifiers>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
|
|
|
@ -128,26 +128,22 @@ impl Project {
|
||||||
DependencySpecifiers::Pesde(specifier) => {
|
DependencySpecifiers::Pesde(specifier) => {
|
||||||
let index_url = if depth == 0 || overridden {
|
let index_url = if depth == 0 || overridden {
|
||||||
let index_name = specifier.index.as_deref().unwrap_or(DEFAULT_INDEX_NAME);
|
let index_name = specifier.index.as_deref().unwrap_or(DEFAULT_INDEX_NAME);
|
||||||
let index_url = manifest.indices.get(index_name).ok_or(
|
|
||||||
errors::DependencyGraphError::IndexNotFound(index_name.to_string()),
|
|
||||||
)?;
|
|
||||||
|
|
||||||
match index_url.as_str().try_into() {
|
manifest
|
||||||
Ok(url) => url,
|
.indices
|
||||||
Err(e) => {
|
.get(index_name)
|
||||||
return Err(Box::new(errors::DependencyGraphError::UrlParse(
|
.ok_or(errors::DependencyGraphError::IndexNotFound(
|
||||||
index_url.clone(),
|
index_name.to_string(),
|
||||||
e,
|
))?
|
||||||
)))
|
.clone()
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
let index_url = specifier.index.clone().unwrap();
|
let index_url = specifier.index.clone().unwrap();
|
||||||
|
|
||||||
index_url
|
index_url
|
||||||
.clone()
|
.clone()
|
||||||
.try_into()
|
.try_into()
|
||||||
.map_err(|e| errors::DependencyGraphError::InvalidIndex(index_url, e))?
|
// specifiers in indices store the index url in this field
|
||||||
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
PackageSources::Pesde(PesdePackageSource::new(index_url))
|
PackageSources::Pesde(PesdePackageSource::new(index_url))
|
||||||
|
@ -309,12 +305,6 @@ pub mod errors {
|
||||||
#[error("index named {0} not found in manifest")]
|
#[error("index named {0} not found in manifest")]
|
||||||
IndexNotFound(String),
|
IndexNotFound(String),
|
||||||
|
|
||||||
#[error("error parsing url {0} into git url")]
|
|
||||||
UrlParse(url::Url, #[source] gix::url::parse::Error),
|
|
||||||
|
|
||||||
#[error("index {0} cannot be parsed as a git url")]
|
|
||||||
InvalidIndex(String, #[source] gix::url::parse::Error),
|
|
||||||
|
|
||||||
#[error("error refreshing package source")]
|
#[error("error refreshing package source")]
|
||||||
Refresh(#[from] crate::source::errors::RefreshError),
|
Refresh(#[from] crate::source::errors::RefreshError),
|
||||||
|
|
||||||
|
|
27
src/util.rs
27
src/util.rs
|
@ -1,6 +1,7 @@
|
||||||
use crate::AuthConfig;
|
use crate::AuthConfig;
|
||||||
use gix::bstr::BStr;
|
use gix::bstr::BStr;
|
||||||
use serde::{Deserialize, Deserializer, Serializer};
|
use serde::{ser::SerializeMap, Deserialize, Deserializer, Serializer};
|
||||||
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
pub fn authenticate_conn(
|
pub fn authenticate_conn(
|
||||||
conn: &mut gix::remote::Connection<
|
conn: &mut gix::remote::Connection<
|
||||||
|
@ -28,9 +29,33 @@ pub fn serialize_gix_url<S: Serializer>(url: &gix::Url, serializer: S) -> Result
|
||||||
serializer.serialize_str(&url.to_bstring().to_string())
|
serializer.serialize_str(&url.to_bstring().to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn serialize_gix_url_map<S: Serializer>(
|
||||||
|
url: &BTreeMap<String, gix::Url>,
|
||||||
|
serializer: S,
|
||||||
|
) -> Result<S::Ok, S::Error> {
|
||||||
|
let mut map = serializer.serialize_map(Some(url.len()))?;
|
||||||
|
for (k, v) in url {
|
||||||
|
map.serialize_entry(k, &v.to_bstring().to_string())?;
|
||||||
|
}
|
||||||
|
map.end()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn deserialize_gix_url<'de, D: Deserializer<'de>>(
|
pub fn deserialize_gix_url<'de, D: Deserializer<'de>>(
|
||||||
deserializer: D,
|
deserializer: D,
|
||||||
) -> Result<gix::Url, D::Error> {
|
) -> Result<gix::Url, D::Error> {
|
||||||
let s = String::deserialize(deserializer)?;
|
let s = String::deserialize(deserializer)?;
|
||||||
gix::Url::from_bytes(BStr::new(&s)).map_err(serde::de::Error::custom)
|
gix::Url::from_bytes(BStr::new(&s)).map_err(serde::de::Error::custom)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn deserialize_gix_url_map<'de, D: Deserializer<'de>>(
|
||||||
|
deserializer: D,
|
||||||
|
) -> Result<BTreeMap<String, gix::Url>, D::Error> {
|
||||||
|
BTreeMap::<String, String>::deserialize(deserializer)?
|
||||||
|
.into_iter()
|
||||||
|
.map(|(k, v)| {
|
||||||
|
gix::Url::from_bytes(BStr::new(&v))
|
||||||
|
.map(|v| (k, v))
|
||||||
|
.map_err(serde::de::Error::custom)
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue