summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock48
-rw-r--r--Cargo.toml4
-rw-r--r--src/authenticate.rs2
-rw-r--r--src/bin/git-autosave-daemon.rs2
-rw-r--r--src/inquire.rs13
-rw-r--r--src/lib.rs39
-rw-r--r--src/utils.rs4
7 files changed, 27 insertions, 85 deletions
diff --git a/Cargo.lock b/Cargo.lock
index ecdfdfa..8382921 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -78,9 +78,9 @@ checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c"
[[package]]
name = "auth-git2"
-version = "0.5.8"
+version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4888bf91cce63baf1670512d0f12b5d636179a4abbad6504812ac8ab124b3efe"
+checksum = "aec364a6ee335b23a7e77703100f5103965810f91a9ef6319a004a7e7b8e2b66"
dependencies = [
"dirs",
"git2",
@@ -451,16 +451,14 @@ dependencies = [
[[package]]
name = "git2"
-version = "0.20.4"
+version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7b88256088d75a56f8ecfa070513a775dd9107f6530ef14919dac831af9cfe2b"
+checksum = "ddddbf932745a6be37109b6112d3ee09696106f848449069d3a57bba937ab82e"
dependencies = [
"bitflags 2.11.0",
"libc",
"libgit2-sys",
"log",
- "openssl-probe",
- "openssl-sys",
"url",
]
@@ -799,15 +797,13 @@ checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d"
[[package]]
name = "libgit2-sys"
-version = "0.18.3+1.9.2"
+version = "0.18.5+1.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c9b3acc4b91781bb0b3386669d325163746af5f6e4f73e6d2d630e09a35f3487"
+checksum = "005d6ae6eac1912906073e069f7db60b1fa98e052a68227824afe3e3a1c59ca2"
dependencies = [
"cc",
"libc",
- "libssh2-sys",
"libz-sys",
- "openssl-sys",
"pkg-config",
]
@@ -821,20 +817,6 @@ dependencies = [
]
[[package]]
-name = "libssh2-sys"
-version = "0.3.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "220e4f05ad4a218192533b300327f5150e809b54c4ec83b5a1d91833601811b9"
-dependencies = [
- "cc",
- "libc",
- "libz-sys",
- "openssl-sys",
- "pkg-config",
- "vcpkg",
-]
-
-[[package]]
name = "libz-sys"
version = "1.1.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -965,24 +947,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
[[package]]
-name = "openssl-probe"
-version = "0.1.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e"
-
-[[package]]
-name = "openssl-sys"
-version = "0.9.112"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "57d55af3b3e226502be1526dfdba67ab0e9c96fc293004e79576b2b9edb0dbdb"
-dependencies = [
- "cc",
- "libc",
- "pkg-config",
- "vcpkg",
-]
-
-[[package]]
name = "option-ext"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 95a7808..eba9476 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2024"
[dependencies]
-git2 = "0.20"
+git2 = "0.21"
serde = { version = "1.0.152", features = ["derive"] }
uuid = { version = "1", features = ["v4"] }
thiserror = "2"
@@ -19,5 +19,5 @@ log = "0.4"
colog = "1"
hostname = "0.4"
inquire = "0.9"
-auth-git2 = "0.5"
+auth-git2 = "0.6"
ping = "0.7"
diff --git a/src/authenticate.rs b/src/authenticate.rs
index fab33a2..66bfded 100644
--- a/src/authenticate.rs
+++ b/src/authenticate.rs
@@ -11,8 +11,8 @@ pub struct Inquirer<'a>(pub &'a Config);
fn config_value(git_config: &git2::Config, name: &str) -> Option<String> {
git_config
.get_entry(name)
- .ok()
.and_then(|entry| entry.value().map(|entry| entry.to_string()))
+ .ok()
}
fn prompt_secret(message: &str) -> Result<String, InquireError> {
diff --git a/src/bin/git-autosave-daemon.rs b/src/bin/git-autosave-daemon.rs
index d8c23fc..d9af1e5 100644
--- a/src/bin/git-autosave-daemon.rs
+++ b/src/bin/git-autosave-daemon.rs
@@ -288,6 +288,6 @@ fn main() -> Result<(), anyhow::Error> {
log::info!("Initializing complete. Parking...");
loop {
- std::thread::yield_now();
+ std::thread::park();
}
}
diff --git a/src/inquire.rs b/src/inquire.rs
index 6dd2e3c..a914061 100644
--- a/src/inquire.rs
+++ b/src/inquire.rs
@@ -47,11 +47,13 @@ pub fn filter_autosaves(
all_users
|| signature
.name()
- .zip(autosave.author.clone())
+ .ok()
+ .zip(Some(autosave.author.clone()))
.is_some_and(|(a, b)| a == b)
|| signature
.email()
- .zip(autosave.email.clone())
+ .ok()
+ .zip(Some(autosave.email.clone()))
.is_some_and(|(a, b)| a == b)
})
.filter(move |autosave| all_branches || autosave.branch_name == branch)
@@ -78,11 +80,8 @@ pub fn select_autosave(
} else {
String::new()
};
- let author = if let Some(author) =
- autosave.author.as_ref().or(autosave.email.as_ref())
- && all_users
- {
- format!(" by {author}")
+ let author = if all_users {
+ format!(" by {}", autosave.author)
} else {
String::new()
};
diff --git a/src/lib.rs b/src/lib.rs
index 2662948..f44cf57 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -12,12 +12,6 @@
* - allow --no-commit
* - display available autosaves if there is more than one
*
- * git undo-restore-autosave:
- * - check for differences between workdir and restored save
- * - error if there are unsaved changes
- * - apply `refs/autosave/undo` to tree
- * - allow force
- *
* git repair-autosave
*/
@@ -47,8 +41,8 @@ pub struct Autosave {
pub repo_id: String,
pub branch_name: String,
pub commit_id: Oid,
- pub author: Option<String>,
- pub email: Option<String>,
+ pub author: String,
+ pub email: String,
pub host_name: Option<String>,
pub time: Time,
}
@@ -65,11 +59,7 @@ impl TryFrom<&Reference<'_>> for Autosave {
type Error = git2::Error;
fn try_from(reference: &Reference<'_>) -> Result<Self, Self::Error> {
- let reference_name = reference.name().ok_or(git2::Error::new(
- git2::ErrorCode::Invalid,
- git2::ErrorClass::Reference,
- "Reference is not valid UTF-8",
- ))?;
+ let reference_name = reference.name()?;
let reference_name = reference_name
.strip_prefix(AUTOSAVE_ENTRIES_NAMESPACE)
.unwrap_or(reference_name);
@@ -81,8 +71,8 @@ impl TryFrom<&Reference<'_>> for Autosave {
));
};
let commit = reference.peel_to_commit()?;
- let message = commit.message();
- let host_name = message.and_then(|m| m.strip_prefix("Autosave: "));
+ let message = commit.message()?;
+ let host_name = message.strip_prefix("Autosave: ");
let author = commit.author();
let author_name = author.name();
let author_email = author.email();
@@ -92,8 +82,8 @@ impl TryFrom<&Reference<'_>> for Autosave {
repo_id: id.to_string(),
branch_name: branch.to_string(),
commit_id: commit.id(),
- author: author_name.map(|s| s.to_string()),
- email: author_email.map(|s| s.to_string()),
+ author: author_name.map(|s| s.to_string())?,
+ email: author_email.map(|s| s.to_string())?,
host_name: host_name.map(|s| s.to_string()),
time,
})
@@ -106,11 +96,6 @@ pub fn repository_id(repository: &Repository) -> Result<String, git2::Error> {
.get_entry(AUTOSAVE_ID_CONFIG_KEY)?
.value()
.map(|s| s.to_string())
- .ok_or(git2::Error::new(
- git2::ErrorCode::Invalid,
- git2::ErrorClass::Config,
- "Repository ID is not valid UTF-8",
- ))
}
pub fn init(repository: &Repository, config: Option<&mut Config>) -> Result<Uuid, git2::Error> {
@@ -164,7 +149,7 @@ pub fn push_autosaves(
.name_bytes()
.starts_with(format!("{AUTOSAVE_ENTRIES_NAMESPACE}{id}").as_bytes())
})
- .filter_map(|reference| reference.name().map(|n| n.to_string()))
+ .filter_map(|reference| reference.name().map(|n| n.to_string()).ok())
.map(|reference| format!("+{reference}:{reference}"))
.collect::<Vec<_>>();
remote.push(&refs, Some(PushOptions::new().remote_callbacks(callbacks)))?;
@@ -224,13 +209,7 @@ pub fn saved_restored_autosave(
repository: &Repository,
autosave: &Autosave,
) -> Result<(), git2::Error> {
- let author = if let Some(author) = &autosave.author
- && let Some(email) = &autosave.email
- {
- Signature::new(author, email, &autosave.time)?
- } else {
- repository.signature()?
- };
+ let author = Signature::new(&autosave.author, &autosave.email, &autosave.time)?;
let committer = repository.signature()?;
let message = format!(
"{}:{}/{}",
diff --git a/src/utils.rs b/src/utils.rs
index dc0c082..9b868eb 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -15,8 +15,8 @@ pub enum TreeError {
pub fn current_branch_ref(repository: &Repository) -> Result<String, git2::Error> {
let head = repository.head()?;
let ref_name = match head.kind() {
- Some(git2::ReferenceType::Symbolic) => head.symbolic_target(),
- _ => head.name(),
+ Some(git2::ReferenceType::Symbolic) => head.symbolic_target()?,
+ _ => Some(head.name()?),
}
.ok_or(git2::Error::new(
git2::ErrorCode::Invalid,