summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs39
1 files changed, 9 insertions, 30 deletions
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!(
"{}:{}/{}",