diff options
| author | Mica White <botahamec@outlook.com> | 2026-06-20 09:04:33 -0400 |
|---|---|---|
| committer | Mica White <botahamec@outlook.com> | 2026-06-20 09:04:33 -0400 |
| commit | 1897aa4c604a0d9ab81f84dbff687b7f42bc1f0f (patch) | |
| tree | 8ed0db5fc0342dc221bb63e431d4012ec7c27c3b /src | |
| parent | 230a1e6987a322077f4b7ed16392ef4372285307 (diff) | |
Diffstat (limited to 'src')
| -rw-r--r-- | src/authenticate.rs | 2 | ||||
| -rw-r--r-- | src/bin/git-autosave-daemon.rs | 2 | ||||
| -rw-r--r-- | src/inquire.rs | 13 | ||||
| -rw-r--r-- | src/lib.rs | 39 | ||||
| -rw-r--r-- | src/utils.rs | 4 |
5 files changed, 19 insertions, 41 deletions
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() }; @@ -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, |
