From c856c23aef3db0537af382a5499c400ca81c6c30 Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Sun, 28 Jun 2020 21:43:11 +0200 Subject: [PATCH] remove outdated commit method --- asyncgit/src/revlog.rs | 18 +++++++++++------- asyncgit/src/sync/commit.rs | 4 ++-- asyncgit/src/sync/commit_details.rs | 5 ++--- asyncgit/src/sync/commit_files.rs | 4 +--- asyncgit/src/sync/commits_info.rs | 10 ++++++++-- asyncgit/src/sync/diff.rs | 9 ++------- asyncgit/src/sync/logwalker.rs | 11 ++++++----- asyncgit/src/sync/mod.rs | 4 ++-- asyncgit/src/sync/stash.rs | 6 +++--- asyncgit/src/sync/utils.rs | 29 +++++++++++++---------------- src/components/commit.rs | 2 +- 11 files changed, 51 insertions(+), 51 deletions(-) diff --git a/asyncgit/src/revlog.rs b/asyncgit/src/revlog.rs index 715b4792..6fde2e93 100644 --- a/asyncgit/src/revlog.rs +++ b/asyncgit/src/revlog.rs @@ -1,6 +1,6 @@ use crate::{ error::Result, - sync::{utils::repo, LogWalker}, + sync::{utils::repo, CommitId, LogWalker}, AsyncNotification, CWD, }; use crossbeam_channel::Sender; @@ -29,7 +29,7 @@ pub enum FetchStatus { /// pub struct AsyncLog { - current: Arc>>, + current: Arc>>, sender: Sender, pending: Arc, background: Arc, @@ -60,7 +60,7 @@ impl AsyncLog { &self, start_index: usize, amount: usize, - ) -> Result> { + ) -> Result> { let list = self.current.lock()?; let list_len = list.len(); let min = start_index.min(list_len); @@ -80,15 +80,19 @@ impl AsyncLog { } /// - fn current_head(&self) -> Result { - Ok(self.current.lock()?.first().map_or(Oid::zero(), |f| *f)) + fn current_head(&self) -> Result { + Ok(self + .current + .lock()? + .first() + .map_or(Oid::zero().into(), |f| *f)) } /// fn head_changed(&self) -> Result { if let Ok(head) = repo(CWD)?.head() { if let Some(head) = head.target() { - return Ok(head != self.current_head()?); + return Ok(head != self.current_head()?.into()); } } Ok(false) @@ -131,7 +135,7 @@ impl AsyncLog { } fn fetch_helper( - arc_current: Arc>>, + arc_current: Arc>>, arc_background: Arc, sender: &Sender, ) -> Result<()> { diff --git a/asyncgit/src/sync/commit.rs b/asyncgit/src/sync/commit.rs index d5cf49f4..171b375e 100644 --- a/asyncgit/src/sync/commit.rs +++ b/asyncgit/src/sync/commit.rs @@ -35,7 +35,7 @@ mod tests { use crate::error::Result; use crate::sync::{ commit, get_commit_details, get_commit_files, stage_add_file, - tests::repo_init_empty, utils::get_head, CommitId, LogWalker, + tests::repo_init_empty, utils::get_head, LogWalker, }; use commit::amend; use git2::Repository; @@ -67,7 +67,7 @@ mod tests { stage_add_file(repo_path, file_path2)?; - let new_id = amend(repo_path, CommitId::new(id), "amended")?; + let new_id = amend(repo_path, id, "amended")?; assert_eq!(count_commits(&repo, 10), 1); diff --git a/asyncgit/src/sync/commit_details.rs b/asyncgit/src/sync/commit_details.rs index 9591200a..da194147 100644 --- a/asyncgit/src/sync/commit_details.rs +++ b/asyncgit/src/sync/commit_details.rs @@ -114,7 +114,7 @@ mod tests { use super::get_commit_details; use crate::error::Result; use crate::sync::{ - commit, stage_add_file, tests::repo_init_empty, CommitId, + commit, stage_add_file, tests::repo_init_empty, }; use std::{fs::File, io::Write, path::Path}; @@ -131,8 +131,7 @@ mod tests { let msg = invalidstring::invalid_utf8("test msg"); let id = commit(repo_path, msg.as_str()).unwrap(); - let res = - get_commit_details(repo_path, CommitId::new(id)).unwrap(); + let res = get_commit_details(repo_path, id).unwrap(); dbg!(&res.message.as_ref().unwrap().subject); assert_eq!( diff --git a/asyncgit/src/sync/commit_files.rs b/asyncgit/src/sync/commit_files.rs index 0b96f83f..a9cae476 100644 --- a/asyncgit/src/sync/commit_files.rs +++ b/asyncgit/src/sync/commit_files.rs @@ -75,7 +75,6 @@ mod tests { error::Result, sync::{ commit, stage_add_file, stash_save, tests::repo_init, - CommitId, }, StatusItemType, }; @@ -97,8 +96,7 @@ mod tests { let id = commit(repo_path, "commit msg").unwrap(); - let diff = - get_commit_files(repo_path, CommitId::new(id)).unwrap(); + let diff = get_commit_files(repo_path, id).unwrap(); assert_eq!(diff.len(), 1); assert_eq!(diff[0].status, StatusItemType::New); diff --git a/asyncgit/src/sync/commits_info.rs b/asyncgit/src/sync/commits_info.rs index 268fb0e7..9ff860d2 100644 --- a/asyncgit/src/sync/commits_info.rs +++ b/asyncgit/src/sync/commits_info.rs @@ -32,6 +32,12 @@ impl Into for CommitId { } } +impl From for CommitId { + fn from(id: Oid) -> Self { + Self::new(id) + } +} + /// #[derive(Debug)] pub struct CommitInfo { @@ -48,7 +54,7 @@ pub struct CommitInfo { /// pub fn get_commits_info( repo_path: &str, - ids: &[Oid], + ids: &[CommitId], message_length_limit: usize, ) -> Result> { scope_time!("get_commits_info"); @@ -57,7 +63,7 @@ pub fn get_commits_info( let commits = ids .iter() - .map(|id| repo.find_commit(*id)) + .map(|id| repo.find_commit((*id).into())) .collect::, Error>>()? .into_iter(); diff --git a/asyncgit/src/sync/diff.rs b/asyncgit/src/sync/diff.rs index e265d40b..9bdb6370 100644 --- a/asyncgit/src/sync/diff.rs +++ b/asyncgit/src/sync/diff.rs @@ -304,7 +304,6 @@ mod tests { commit, stage_add_file, status::{get_status, StatusType}, tests::{get_statuses, repo_init, repo_init_empty}, - CommitId, }; use std::{ fs::{self, File}, @@ -529,12 +528,8 @@ mod tests { let id = commit(repo_path, "").unwrap(); - let diff = get_diff_commit( - repo_path, - CommitId::new(id), - String::new(), - ) - .unwrap(); + let diff = + get_diff_commit(repo_path, id, String::new()).unwrap(); dbg!(&diff); assert_eq!(diff.sizes, (1, 2)); diff --git a/asyncgit/src/sync/logwalker.rs b/asyncgit/src/sync/logwalker.rs index 9202227e..bd259655 100644 --- a/asyncgit/src/sync/logwalker.rs +++ b/asyncgit/src/sync/logwalker.rs @@ -1,5 +1,6 @@ +use super::CommitId; use crate::error::Result; -use git2::{Oid, Repository, Revwalk}; +use git2::{Repository, Revwalk}; /// pub struct LogWalker<'a> { @@ -19,7 +20,7 @@ impl<'a> LogWalker<'a> { /// pub fn read( &mut self, - out: &mut Vec, + out: &mut Vec, limit: usize, ) -> Result { let mut count = 0_usize; @@ -33,7 +34,7 @@ impl<'a> LogWalker<'a> { if let Some(ref mut walk) = self.revwalk { for id in walk { if let Ok(id) = id { - out.push(id); + out.push(id.into()); count += 1; if count == limit { @@ -75,7 +76,7 @@ mod tests { walk.read(&mut items, 1).unwrap(); assert_eq!(items.len(), 1); - assert_eq!(items[0], oid2); + assert_eq!(items[0], oid2.into()); Ok(()) } @@ -102,7 +103,7 @@ mod tests { dbg!(&info); assert_eq!(items.len(), 2); - assert_eq!(items[0], oid2); + assert_eq!(items[0], oid2.into()); let mut items = Vec::new(); walk.read(&mut items, 100).unwrap(); diff --git a/asyncgit/src/sync/mod.rs b/asyncgit/src/sync/mod.rs index 55147459..58b7f5f9 100644 --- a/asyncgit/src/sync/mod.rs +++ b/asyncgit/src/sync/mod.rs @@ -30,8 +30,8 @@ pub use reset::{reset_stage, reset_workdir}; pub use stash::{get_stashes, stash_apply, stash_drop, stash_save}; pub use tags::{get_tags, Tags}; pub use utils::{ - commit, commit_new, get_head, is_bare_repo, is_repo, - stage_add_all, stage_add_file, stage_addremoved, + commit, get_head, is_bare_repo, is_repo, stage_add_all, + stage_add_file, stage_addremoved, }; #[cfg(test)] diff --git a/asyncgit/src/sync/stash.rs b/asyncgit/src/sync/stash.rs index 431f4a62..da67dc82 100644 --- a/asyncgit/src/sync/stash.rs +++ b/asyncgit/src/sync/stash.rs @@ -4,7 +4,7 @@ use git2::{Oid, Repository, StashFlags}; use scopetime::scope_time; /// -pub fn get_stashes(repo_path: &str) -> Result> { +pub fn get_stashes(repo_path: &str) -> Result> { scope_time!("get_stashes"); let mut repo = repo(repo_path)?; @@ -12,7 +12,7 @@ pub fn get_stashes(repo_path: &str) -> Result> { let mut list = Vec::new(); repo.stash_foreach(|_index, _msg, id| { - list.push(*id); + list.push((*id).into()); true })?; @@ -25,7 +25,7 @@ pub fn stash_drop(repo_path: &str, stash_id: CommitId) -> Result<()> { let mut repo = repo(repo_path)?; - let index = get_stash_index(&mut repo, stash_id.get_oid())?; + let index = get_stash_index(&mut repo, stash_id.into())?; repo.stash_drop(index)?; diff --git a/asyncgit/src/sync/utils.rs b/asyncgit/src/sync/utils.rs index e68636f9..fae81f97 100644 --- a/asyncgit/src/sync/utils.rs +++ b/asyncgit/src/sync/utils.rs @@ -2,7 +2,7 @@ use super::CommitId; use crate::error::{Error, Result}; -use git2::{IndexAddOption, Oid, Repository, RepositoryOpenFlags}; +use git2::{IndexAddOption, Repository, RepositoryOpenFlags}; use scopetime::scope_time; use std::path::Path; @@ -60,19 +60,14 @@ pub fn get_head_repo(repo: &Repository) -> Result { let head = repo.head()?.target(); if let Some(head_id) = head { - Ok(CommitId::new(head_id)) + Ok(head_id.into()) } else { Err(Error::NoHead) } } -/// ditto -pub fn commit_new(repo_path: &str, msg: &str) -> Result { - commit(repo_path, msg).map(CommitId::new) -} - /// this does not run any git hooks -pub fn commit(repo_path: &str, msg: &str) -> Result { +pub fn commit(repo_path: &str, msg: &str) -> Result { scope_time!("commit"); let repo = repo(repo_path)?; @@ -90,14 +85,16 @@ pub fn commit(repo_path: &str, msg: &str) -> Result { let parents = parents.iter().collect::>(); - Ok(repo.commit( - Some("HEAD"), - &signature, - &signature, - msg, - &tree, - parents.as_slice(), - )?) + Ok(repo + .commit( + Some("HEAD"), + &signature, + &signature, + msg, + &tree, + parents.as_slice(), + )? + .into()) } /// add a file diff from workingdir to stage (will not add removed files see `stage_addremoved`) diff --git a/src/components/commit.rs b/src/components/commit.rs index ea1e610a..3640015a 100644 --- a/src/components/commit.rs +++ b/src/components/commit.rs @@ -202,7 +202,7 @@ impl CommitComponent { let res = if let Some(amend) = self.amend { sync::amend(CWD, amend, &msg) } else { - sync::commit_new(CWD, &msg) + sync::commit(CWD, &msg) }; if let Err(e) = res { log::error!("commit error: {}", &e);