remove outdated commit method

This commit is contained in:
Stephan Dilly 2020-06-28 21:43:11 +02:00
parent 90587bc6ae
commit 6d88a678eb
11 changed files with 51 additions and 51 deletions

View file

@ -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<Mutex<Vec<Oid>>>,
current: Arc<Mutex<Vec<CommitId>>>,
sender: Sender<AsyncNotification>,
pending: Arc<AtomicBool>,
background: Arc<AtomicBool>,
@ -60,7 +60,7 @@ impl AsyncLog {
&self,
start_index: usize,
amount: usize,
) -> Result<Vec<Oid>> {
) -> Result<Vec<CommitId>> {
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<Oid> {
Ok(self.current.lock()?.first().map_or(Oid::zero(), |f| *f))
fn current_head(&self) -> Result<CommitId> {
Ok(self
.current
.lock()?
.first()
.map_or(Oid::zero().into(), |f| *f))
}
///
fn head_changed(&self) -> Result<bool> {
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<Mutex<Vec<Oid>>>,
arc_current: Arc<Mutex<Vec<CommitId>>>,
arc_background: Arc<AtomicBool>,
sender: &Sender<AsyncNotification>,
) -> Result<()> {

View file

@ -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);

View file

@ -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!(

View file

@ -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);

View file

@ -32,6 +32,12 @@ impl Into<Oid> for CommitId {
}
}
impl From<Oid> 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<Vec<CommitInfo>> {
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::<std::result::Result<Vec<Commit>, Error>>()?
.into_iter();

View file

@ -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));

View file

@ -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<Oid>,
out: &mut Vec<CommitId>,
limit: usize,
) -> Result<usize> {
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();

View file

@ -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)]

View file

@ -4,7 +4,7 @@ use git2::{Oid, Repository, StashFlags};
use scopetime::scope_time;
///
pub fn get_stashes(repo_path: &str) -> Result<Vec<Oid>> {
pub fn get_stashes(repo_path: &str) -> Result<Vec<CommitId>> {
scope_time!("get_stashes");
let mut repo = repo(repo_path)?;
@ -12,7 +12,7 @@ pub fn get_stashes(repo_path: &str) -> Result<Vec<Oid>> {
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)?;

View file

@ -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<CommitId> {
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<CommitId> {
commit(repo_path, msg).map(CommitId::new)
}
/// this does not run any git hooks
pub fn commit(repo_path: &str, msg: &str) -> Result<Oid> {
pub fn commit(repo_path: &str, msg: &str) -> Result<CommitId> {
scope_time!("commit");
let repo = repo(repo_path)?;
@ -90,14 +85,16 @@ pub fn commit(repo_path: &str, msg: &str) -> Result<Oid> {
let parents = parents.iter().collect::<Vec<_>>();
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`)

View file

@ -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);