rust 1.80 clippy fixes

This commit is contained in:
extrawurst 2024-07-26 12:49:18 +07:00 committed by extrawurst
parent ce923e6fe4
commit b89672b134
38 changed files with 158 additions and 205 deletions

View File

@ -92,7 +92,7 @@ impl<J: 'static + AsyncJob> AsyncSingleJob<J> {
} }
/// makes sure `next` is cleared and returns `true` if it actually canceled something /// makes sure `next` is cleared and returns `true` if it actually canceled something
pub fn cancel(&mut self) -> bool { pub fn cancel(&self) -> bool {
if let Ok(mut next) = self.next.lock() { if let Ok(mut next) = self.next.lock() {
if next.is_some() { if next.is_some() {
*next = None; *next = None;
@ -111,7 +111,7 @@ impl<J: 'static + AsyncJob> AsyncSingleJob<J> {
/// spawns `task` if nothing is running currently, /// spawns `task` if nothing is running currently,
/// otherwise schedules as `next` overwriting if `next` was set before. /// otherwise schedules as `next` overwriting if `next` was set before.
/// return `true` if the new task gets started right away. /// return `true` if the new task gets started right away.
pub fn spawn(&mut self, task: J) -> bool { pub fn spawn(&self, task: J) -> bool {
self.schedule_next(task); self.schedule_next(task);
self.check_for_job() self.check_for_job()
} }
@ -162,7 +162,7 @@ impl<J: 'static + AsyncJob> AsyncSingleJob<J> {
Ok(()) Ok(())
} }
fn schedule_next(&mut self, task: J) { fn schedule_next(&self, task: J) {
if let Ok(mut next) = self.next.lock() { if let Ok(mut next) = self.next.lock() {
*next = Some(task); *next = Some(task);
} }
@ -226,7 +226,7 @@ mod test {
fn test_overwrite() { fn test_overwrite() {
let (sender, receiver) = unbounded(); let (sender, receiver) = unbounded();
let mut job: AsyncSingleJob<TestJob> = let job: AsyncSingleJob<TestJob> =
AsyncSingleJob::new(sender); AsyncSingleJob::new(sender);
let task = TestJob { let task = TestJob {
@ -265,7 +265,7 @@ mod test {
fn test_cancel() { fn test_cancel() {
let (sender, receiver) = unbounded(); let (sender, receiver) = unbounded();
let mut job: AsyncSingleJob<TestJob> = let job: AsyncSingleJob<TestJob> =
AsyncSingleJob::new(sender); AsyncSingleJob::new(sender);
let task = TestJob { let task = TestJob {

View File

@ -55,9 +55,7 @@ impl AsyncBlame {
} }
/// ///
pub fn last( pub fn last(&self) -> Result<Option<(BlameParams, FileBlame)>> {
&mut self,
) -> Result<Option<(BlameParams, FileBlame)>> {
let last = self.last.lock()?; let last = self.last.lock()?;
Ok(last.clone().map(|last_result| { Ok(last.clone().map(|last_result| {
@ -66,7 +64,7 @@ impl AsyncBlame {
} }
/// ///
pub fn refresh(&mut self) -> Result<()> { pub fn refresh(&self) -> Result<()> {
if let Ok(Some(param)) = self.get_last_param() { if let Ok(Some(param)) = self.get_last_param() {
self.clear_current()?; self.clear_current()?;
self.request(param)?; self.request(param)?;
@ -81,7 +79,7 @@ impl AsyncBlame {
/// ///
pub fn request( pub fn request(
&mut self, &self,
params: BlameParams, params: BlameParams,
) -> Result<Option<FileBlame>> { ) -> Result<Option<FileBlame>> {
log::trace!("request"); log::trace!("request");
@ -181,7 +179,7 @@ impl AsyncBlame {
.map(|last_result| last_result.params)) .map(|last_result| last_result.params))
} }
fn clear_current(&mut self) -> Result<()> { fn clear_current(&self) -> Result<()> {
let mut current = self.current.lock()?; let mut current = self.current.lock()?;
current.0 = 0; current.0 = 0;
current.1 = None; current.1 = None;

View File

@ -70,7 +70,7 @@ impl AsyncCommitFiles {
/// ///
pub fn current( pub fn current(
&mut self, &self,
) -> Result<Option<(CommitFilesParams, ResultType)>> { ) -> Result<Option<(CommitFilesParams, ResultType)>> {
let c = self.current.lock()?; let c = self.current.lock()?;
@ -84,7 +84,7 @@ impl AsyncCommitFiles {
} }
/// ///
pub fn fetch(&mut self, params: CommitFilesParams) -> Result<()> { pub fn fetch(&self, params: CommitFilesParams) -> Result<()> {
if self.is_pending() { if self.is_pending() {
return Ok(()); return Ok(());
} }

View File

@ -73,14 +73,14 @@ impl AsyncDiff {
} }
/// ///
pub fn last(&mut self) -> Result<Option<(DiffParams, FileDiff)>> { pub fn last(&self) -> Result<Option<(DiffParams, FileDiff)>> {
let last = self.last.lock()?; let last = self.last.lock()?;
Ok(last.clone().map(|res| (res.params, res.result))) Ok(last.clone().map(|res| (res.params, res.result)))
} }
/// ///
pub fn refresh(&mut self) -> Result<()> { pub fn refresh(&self) -> Result<()> {
if let Ok(Some(param)) = self.get_last_param() { if let Ok(Some(param)) = self.get_last_param() {
self.clear_current()?; self.clear_current()?;
self.request(param)?; self.request(param)?;
@ -95,7 +95,7 @@ impl AsyncDiff {
/// ///
pub fn request( pub fn request(
&mut self, &self,
params: DiffParams, params: DiffParams,
) -> Result<Option<FileDiff>> { ) -> Result<Option<FileDiff>> {
log::trace!("request {:?}", params); log::trace!("request {:?}", params);
@ -212,7 +212,7 @@ impl AsyncDiff {
Ok(self.last.lock()?.clone().map(|e| e.params)) Ok(self.last.lock()?.clone().map(|e| e.params))
} }
fn clear_current(&mut self) -> Result<()> { fn clear_current(&self) -> Result<()> {
let mut current = self.current.lock()?; let mut current = self.current.lock()?;
current.0 = 0; current.0 = 0;
current.1 = None; current.1 = None;

View File

@ -71,7 +71,7 @@ impl AsyncPull {
} }
/// ///
pub fn request(&mut self, params: FetchRequest) -> Result<()> { pub fn request(&self, params: FetchRequest) -> Result<()> {
log::trace!("request"); log::trace!("request");
if self.is_pending()? { if self.is_pending()? {

View File

@ -78,7 +78,7 @@ impl AsyncPush {
} }
/// ///
pub fn request(&mut self, params: PushRequest) -> Result<()> { pub fn request(&self, params: PushRequest) -> Result<()> {
log::trace!("request"); log::trace!("request");
if self.is_pending()? { if self.is_pending()? {

View File

@ -69,7 +69,7 @@ impl AsyncPushTags {
} }
/// ///
pub fn request(&mut self, params: PushTagsRequest) -> Result<()> { pub fn request(&self, params: PushTagsRequest) -> Result<()> {
log::trace!("request"); log::trace!("request");
if self.is_pending()? { if self.is_pending()? {

View File

@ -126,7 +126,7 @@ impl AsyncLog {
} }
/// ///
pub fn set_background(&mut self) { pub fn set_background(&self) {
self.background.store(true, Ordering::Relaxed); self.background.store(true, Ordering::Relaxed);
} }
@ -146,7 +146,7 @@ impl AsyncLog {
} }
/// ///
pub fn fetch(&mut self) -> Result<FetchStatus> { pub fn fetch(&self) -> Result<FetchStatus> {
self.background.store(false, Ordering::Relaxed); self.background.store(false, Ordering::Relaxed);
if self.is_pending() { if self.is_pending() {
@ -308,7 +308,7 @@ impl AsyncLog {
Ok(()) Ok(())
} }
fn clear(&mut self) -> Result<()> { fn clear(&self) -> Result<()> {
self.current.lock()?.commits.clear(); self.current.lock()?.commits.clear();
*self.current_head.lock()? = None; *self.current_head.lock()? = None;
self.partial_extract.store(false, Ordering::Relaxed); self.partial_extract.store(false, Ordering::Relaxed);

View File

@ -77,7 +77,7 @@ impl AsyncStatus {
} }
/// ///
pub fn last(&mut self) -> Result<Status> { pub fn last(&self) -> Result<Status> {
let last = self.last.lock()?; let last = self.last.lock()?;
Ok(last.clone()) Ok(last.clone())
} }
@ -89,7 +89,7 @@ impl AsyncStatus {
/// ///
pub fn fetch( pub fn fetch(
&mut self, &self,
params: &StatusParams, params: &StatusParams,
) -> Result<Option<Status>> { ) -> Result<Option<Status>> {
if self.is_pending() { if self.is_pending() {

View File

@ -167,7 +167,7 @@ mod tests {
let repo_path: &RepoPath = let repo_path: &RepoPath =
&root.as_os_str().to_str().unwrap().into(); &root.as_os_str().to_str().unwrap().into();
assert!(matches!(blame_file(repo_path, "foo", None), Err(_))); assert!(blame_file(repo_path, "foo", None).is_err());
File::create(root.join(file_path))?.write_all(b"line 1\n")?; File::create(root.join(file_path))?.write_all(b"line 1\n")?;

View File

@ -79,7 +79,7 @@ mod test {
git2::Time::new(0, 0), git2::Time::new(0, 0),
); );
assert_eq!(clone1.head_detached().unwrap(), false); assert!(!clone1.head_detached().unwrap());
push_branch( push_branch(
&clone1_dir.into(), &clone1_dir.into(),
@ -92,7 +92,7 @@ mod test {
) )
.unwrap(); .unwrap();
assert_eq!(clone1.head_detached().unwrap(), false); assert!(!clone1.head_detached().unwrap());
// clone2 // clone2
@ -109,7 +109,7 @@ mod test {
git2::Time::new(1, 0), git2::Time::new(1, 0),
); );
assert_eq!(clone2.head_detached().unwrap(), false); assert!(!clone2.head_detached().unwrap());
push_branch( push_branch(
&clone2_dir.into(), &clone2_dir.into(),
@ -122,7 +122,7 @@ mod test {
) )
.unwrap(); .unwrap();
assert_eq!(clone2.head_detached().unwrap(), false); assert!(!clone2.head_detached().unwrap());
// clone1 // clone1
@ -134,7 +134,7 @@ mod test {
git2::Time::new(2, 0), git2::Time::new(2, 0),
); );
assert_eq!(clone1.head_detached().unwrap(), false); assert!(!clone1.head_detached().unwrap());
//lets fetch from origin //lets fetch from origin
let bytes = let bytes =
@ -151,7 +151,7 @@ mod test {
// debug_cmd_print(clone1_dir, "git status"); // debug_cmd_print(clone1_dir, "git status");
assert_eq!(clone1.head_detached().unwrap(), false); assert!(!clone1.head_detached().unwrap());
merge_upstream_rebase(&clone1_dir.into(), "master").unwrap(); merge_upstream_rebase(&clone1_dir.into(), "master").unwrap();
@ -171,7 +171,7 @@ mod test {
] ]
); );
assert_eq!(clone1.head_detached().unwrap(), false); assert!(!clone1.head_detached().unwrap());
} }
#[test] #[test]
@ -270,7 +270,7 @@ mod test {
] ]
); );
assert_eq!(clone1.head_detached().unwrap(), false); assert!(!clone1.head_detached().unwrap());
} }
#[test] #[test]

View File

@ -497,7 +497,7 @@ mod tests_branch_compare {
let res = branch_compare_upstream(repo_path, "test"); let res = branch_compare_upstream(repo_path, "test");
assert_eq!(res.is_err(), true); assert!(res.is_err());
} }
} }
@ -730,7 +730,7 @@ mod tests_checkout {
let file = root.join(filename); let file = root.join(filename);
File::create(&file).unwrap(); File::create(&file).unwrap();
stage_add_file(&repo_path, &Path::new(filename)).unwrap(); stage_add_file(repo_path, Path::new(filename)).unwrap();
assert!(checkout_branch(repo_path, "test").is_ok()); assert!(checkout_branch(repo_path, "test").is_ok());
} }

View File

@ -330,10 +330,7 @@ mod tests {
vec![Tag::new("tag")] vec![Tag::new("tag")]
); );
assert!(matches!( assert!(tag_commit(repo_path, &new_id, "tag", None).is_err());
tag_commit(repo_path, &new_id, "tag", None),
Err(_)
));
assert_eq!( assert_eq!(
get_tags(repo_path).unwrap()[&new_id], get_tags(repo_path).unwrap()[&new_id],
@ -401,13 +398,13 @@ mod tests {
let error = commit(repo_path, "commit msg"); let error = commit(repo_path, "commit msg");
assert!(matches!(error, Err(_))); assert!(error.is_err());
repo.config()?.set_str("user.email", "email")?; repo.config()?.set_str("user.email", "email")?;
let success = commit(repo_path, "commit msg"); let success = commit(repo_path, "commit msg");
assert!(matches!(success, Ok(_))); assert!(success.is_ok());
assert_eq!(count_commits(&repo, 10), 1); assert_eq!(count_commits(&repo, 10), 1);
let details = let details =
@ -437,7 +434,7 @@ mod tests {
let mut success = commit(repo_path, "commit msg"); let mut success = commit(repo_path, "commit msg");
assert!(matches!(success, Ok(_))); assert!(success.is_ok());
assert_eq!(count_commits(&repo, 10), 1); assert_eq!(count_commits(&repo, 10), 1);
let mut details = let mut details =
@ -450,7 +447,7 @@ mod tests {
success = commit(repo_path, "commit msg"); success = commit(repo_path, "commit msg");
assert!(matches!(success, Ok(_))); assert!(success.is_ok());
assert_eq!(count_commits(&repo, 10), 2); assert_eq!(count_commits(&repo, 10), 2);
details = details =

View File

@ -146,14 +146,12 @@ mod tests {
let res = get_commit_details(repo_path, id).unwrap(); let res = get_commit_details(repo_path, id).unwrap();
assert_eq!( assert!(res
res.message .message
.as_ref() .as_ref()
.unwrap() .unwrap()
.subject .subject
.starts_with("test msg"), .starts_with("test msg"));
true
);
Ok(()) Ok(())
} }

View File

@ -235,7 +235,7 @@ mod tests {
assert_eq!(res.len(), 1); assert_eq!(res.len(), 1);
dbg!(&res[0].message); dbg!(&res[0].message);
assert_eq!(res[0].message.starts_with("test msg"), true); assert!(res[0].message.starts_with("test msg"));
Ok(()) Ok(())
} }

View File

@ -203,38 +203,26 @@ mod tests {
#[test] #[test]
fn test_credential_complete() { fn test_credential_complete() {
assert_eq!( assert!(BasicAuthCredential::new(
BasicAuthCredential::new( Some("username".to_owned()),
Some("username".to_owned()), Some("password".to_owned())
Some("password".to_owned()) )
) .is_complete());
.is_complete(),
true
);
} }
#[test] #[test]
fn test_credential_not_complete() { fn test_credential_not_complete() {
assert_eq!( assert!(!BasicAuthCredential::new(
BasicAuthCredential::new( None,
None, Some("password".to_owned())
Some("password".to_owned()) )
) .is_complete());
.is_complete(), assert!(!BasicAuthCredential::new(
false Some("username".to_owned()),
); None
assert_eq!( )
BasicAuthCredential::new( .is_complete());
Some("username".to_owned()), assert!(!BasicAuthCredential::new(None, None).is_complete());
None
)
.is_complete(),
false
);
assert_eq!(
BasicAuthCredential::new(None, None).is_complete(),
false
);
} }
#[test] #[test]
@ -275,7 +263,7 @@ mod tests {
repo.remote(DEFAULT_REMOTE_NAME, "http://user@github.com") repo.remote(DEFAULT_REMOTE_NAME, "http://user@github.com")
.unwrap(); .unwrap();
assert_eq!(need_username_password(repo_path).unwrap(), true); assert!(need_username_password(repo_path).unwrap());
} }
#[test] #[test]
@ -289,7 +277,7 @@ mod tests {
repo.remote(DEFAULT_REMOTE_NAME, "git@github.com:user/repo") repo.remote(DEFAULT_REMOTE_NAME, "git@github.com:user/repo")
.unwrap(); .unwrap();
assert_eq!(need_username_password(repo_path).unwrap(), false); assert!(!need_username_password(repo_path).unwrap());
} }
#[test] #[test]
@ -308,7 +296,7 @@ mod tests {
) )
.unwrap(); .unwrap();
assert_eq!(need_username_password(repo_path).unwrap(), false); assert!(!need_username_password(repo_path).unwrap());
} }
#[test] #[test]

View File

@ -557,7 +557,7 @@ mod tests {
let res = let res =
get_diff(repo_path, "bar.txt", false, None).unwrap(); get_diff(repo_path, "bar.txt", false, None).unwrap();
assert_eq!(res.hunks.len(), 2) assert_eq!(res.hunks.len(), 2);
} }
#[test] #[test]

View File

@ -254,35 +254,29 @@ mod tests {
// Attempt a normal push, // Attempt a normal push,
// should fail as branches diverged // should fail as branches diverged
assert_eq!( assert!(push_branch(
push_branch( &tmp_other_repo_dir.path().to_str().unwrap().into(),
&tmp_other_repo_dir.path().to_str().unwrap().into(), "origin",
"origin", "master",
"master", false,
false, false,
false, None,
None, None,
None, )
) .is_err());
.is_err(),
true
);
// Attempt force push, // Attempt force push,
// should work as it forces the push through // should work as it forces the push through
assert_eq!( assert!(!push_branch(
push_branch( &tmp_other_repo_dir.path().to_str().unwrap().into(),
&tmp_other_repo_dir.path().to_str().unwrap().into(), "origin",
"origin", "master",
"master", true,
true, false,
false, None,
None, None,
None, )
) .is_err());
.is_err(),
false
);
} }
#[test] #[test]
@ -383,19 +377,16 @@ mod tests {
// Attempt a normal push, // Attempt a normal push,
// should fail as branches diverged // should fail as branches diverged
assert_eq!( assert!(push_branch(
push_branch( &tmp_other_repo_dir.path().to_str().unwrap().into(),
&tmp_other_repo_dir.path().to_str().unwrap().into(), "origin",
"origin", "master",
"master", false,
false, false,
false, None,
None, None,
None, )
) .is_err());
.is_err(),
true
);
// Check that the other commit is not in upstream, // Check that the other commit is not in upstream,
// a normal push would not rewrite history // a normal push would not rewrite history
@ -483,40 +474,31 @@ mod tests {
.unwrap(); .unwrap();
// Test if the branch exits on the remote // Test if the branch exits on the remote
assert_eq!( assert!(upstream_repo
upstream_repo .branches(None)
.branches(None) .unwrap()
.unwrap() .map(std::result::Result::unwrap)
.map(std::result::Result::unwrap) .map(|(i, _)| i.name().unwrap().unwrap().to_string())
.map(|(i, _)| i.name().unwrap().unwrap().to_string()) .any(|i| &i == "test_branch"));
.any(|i| &i == "test_branch"),
true
);
// Delete the remote branch // Delete the remote branch
assert_eq!( assert!(push_branch(
push_branch( &tmp_repo_dir.path().to_str().unwrap().into(),
&tmp_repo_dir.path().to_str().unwrap().into(), "origin",
"origin", "test_branch",
"test_branch", false,
false, true,
true, None,
None, None,
None, )
) .is_ok());
.is_ok(),
true
);
// Test that the branch has be remove from the remote // Test that the branch has be remove from the remote
assert_eq!( assert!(!upstream_repo
upstream_repo .branches(None)
.branches(None) .unwrap()
.unwrap() .map(std::result::Result::unwrap)
.map(std::result::Result::unwrap) .map(|(i, _)| i.name().unwrap().unwrap().to_string())
.map(|(i, _)| i.name().unwrap().unwrap().to_string()) .any(|i| &i == "test_branch"));
.any(|i| &i == "test_branch"),
false
);
} }
} }

View File

@ -177,8 +177,7 @@ mod tests {
assert_eq!(message, "commit2"); assert_eq!(message, "commit2");
let reworded = let reworded =
reword(repo_path, oid2.into(), "NewCommitMessage") reword(repo_path, oid2, "NewCommitMessage").unwrap();
.unwrap();
// Need to get the branch again as top oid has changed // Need to get the branch again as top oid has changed
let branch = let branch =

View File

@ -144,12 +144,9 @@ mod tests {
let repo_path: &RepoPath = let repo_path: &RepoPath =
&root.as_os_str().to_str().unwrap().into(); &root.as_os_str().to_str().unwrap().into();
assert_eq!( assert!(!stash_save(repo_path, None, true, false).is_ok());
stash_save(repo_path, None, true, false).is_ok(),
false
);
assert_eq!(get_stashes(repo_path).unwrap().is_empty(), true); assert!(get_stashes(repo_path).unwrap().is_empty());
} }
#[test] #[test]

View File

@ -200,7 +200,7 @@ mod tests {
let repo_path: &RepoPath = let repo_path: &RepoPath =
&root.as_os_str().to_str().unwrap().into(); &root.as_os_str().to_str().unwrap().into();
assert_eq!(get_tags(repo_path).unwrap().is_empty(), true); assert!(get_tags(repo_path).unwrap().is_empty());
} }
#[test] #[test]

View File

@ -156,7 +156,7 @@ mod tests {
#[test] #[test]
fn test_sorting() { fn test_sorting() {
let mut list = vec!["file", "folder/file", "folder/afile"] let mut list = ["file", "folder/file", "folder/afile"]
.iter() .iter()
.map(|f| TreeFile { .map(|f| TreeFile {
path: PathBuf::from(f), path: PathBuf::from(f),
@ -181,7 +181,7 @@ mod tests {
#[test] #[test]
fn test_sorting_folders() { fn test_sorting_folders() {
let mut list = vec!["bfolder/file", "afolder/file"] let mut list = ["bfolder/file", "afolder/file"]
.iter() .iter()
.map(|f| TreeFile { .map(|f| TreeFile {
path: PathBuf::from(f), path: PathBuf::from(f),
@ -205,7 +205,7 @@ mod tests {
#[test] #[test]
fn test_sorting_folders2() { fn test_sorting_folders2() {
let mut list = vec!["bfolder/sub/file", "afolder/file"] let mut list = ["bfolder/sub/file", "afolder/file"]
.iter() .iter()
.map(|f| TreeFile { .map(|f| TreeFile {
path: PathBuf::from(f), path: PathBuf::from(f),

View File

@ -242,10 +242,7 @@ mod tests {
let root = repo.path().parent().unwrap(); let root = repo.path().parent().unwrap();
let repo_path = root.as_os_str().to_str().unwrap(); let repo_path = root.as_os_str().to_str().unwrap();
assert_eq!( assert!(!stage_add_file(&repo_path.into(), file_path).is_ok());
stage_add_file(&repo_path.into(), file_path).is_ok(),
false
);
} }
#[test] #[test]
@ -391,7 +388,7 @@ mod tests {
commit(repo_path, "commit msg").unwrap(); commit(repo_path, "commit msg").unwrap();
// delete the file now // delete the file now
assert_eq!(remove_file(full_path).is_ok(), true); assert!(remove_file(full_path).is_ok());
// deleted file in diff now // deleted file in diff now
assert_eq!(status_count(StatusType::WorkingDir), 1); assert_eq!(status_count(StatusType::WorkingDir), 1);
@ -443,7 +440,7 @@ mod tests {
let repo_path: &RepoPath = let repo_path: &RepoPath =
&root.as_os_str().to_str().unwrap().into(); &root.as_os_str().to_str().unwrap().into();
assert_eq!(get_head(repo_path).is_ok(), false); assert!(!get_head(repo_path).is_ok());
Ok(()) Ok(())
} }
@ -455,7 +452,7 @@ mod tests {
let repo_path: &RepoPath = let repo_path: &RepoPath =
&root.as_os_str().to_str().unwrap().into(); &root.as_os_str().to_str().unwrap().into();
assert_eq!(get_head(repo_path).is_ok(), true); assert!(get_head(repo_path).is_ok());
Ok(()) Ok(())
} }

View File

@ -275,10 +275,7 @@ impl FileTree {
} }
} }
fn select_parent( fn select_parent(&self, current_index: usize) -> Option<usize> {
&mut self,
current_index: usize,
) -> Option<usize> {
let indent = let indent =
self.items.tree_items[current_index].info().indent(); self.items.tree_items[current_index].info().indent();

View File

@ -76,7 +76,7 @@ impl ChangesComponent {
self.files.is_file_selected() self.files.is_file_selected()
} }
fn index_add_remove(&mut self) -> Result<bool> { fn index_add_remove(&self) -> Result<bool> {
if let Some(tree_item) = self.selection() { if let Some(tree_item) = self.selection() {
if self.is_working_dir { if self.is_working_dir {
if let FileTreeItemKind::File(i) = tree_item.kind { if let FileTreeItemKind::File(i) = tree_item.kind {
@ -128,7 +128,7 @@ impl ChangesComponent {
Ok(false) Ok(false)
} }
fn index_add_all(&mut self) -> Result<()> { fn index_add_all(&self) -> Result<()> {
let config = self.options.borrow().status_show_untracked(); let config = self.options.borrow().status_show_untracked();
sync::stage_add_all(&self.repo.borrow(), "*", config)?; sync::stage_add_all(&self.repo.borrow(), "*", config)?;
@ -138,7 +138,7 @@ impl ChangesComponent {
Ok(()) Ok(())
} }
fn stage_remove_all(&mut self) -> Result<()> { fn stage_remove_all(&self) -> Result<()> {
sync::reset_stage(&self.repo.borrow(), "*")?; sync::reset_stage(&self.repo.borrow(), "*")?;
self.queue.push(InternalEvent::Update(NeedsUpdate::ALL)); self.queue.push(InternalEvent::Update(NeedsUpdate::ALL));
@ -146,7 +146,7 @@ impl ChangesComponent {
Ok(()) Ok(())
} }
fn dispatch_reset_workdir(&mut self) -> bool { fn dispatch_reset_workdir(&self) -> bool {
if let Some(tree_item) = self.selection() { if let Some(tree_item) = self.selection() {
self.queue.push(InternalEvent::ConfirmAction( self.queue.push(InternalEvent::ConfirmAction(
Action::Reset(ResetItem { Action::Reset(ResetItem {
@ -159,7 +159,7 @@ impl ChangesComponent {
false false
} }
fn add_to_ignore(&mut self) -> bool { fn add_to_ignore(&self) -> bool {
if let Some(tree_item) = self.selection() { if let Some(tree_item) = self.selection() {
if let Err(e) = sync::add_to_ignore( if let Err(e) = sync::add_to_ignore(
&self.repo.borrow(), &self.repo.borrow(),

View File

@ -244,7 +244,7 @@ impl DetailsComponent {
}) })
} }
fn move_scroll_top(&mut self, move_type: ScrollType) -> bool { fn move_scroll_top(&self, move_type: ScrollType) -> bool {
if self.data.is_some() { if self.data.is_some() {
self.scroll.move_top(move_type) self.scroll.move_top(move_type)
} else { } else {

View File

@ -171,7 +171,7 @@ impl CommitList {
} }
/// ///
pub fn checkout(&mut self) { pub fn checkout(&self) {
if let Some(commit_hash) = if let Some(commit_hash) =
self.selected_entry().map(|entry| entry.id) self.selected_entry().map(|entry| entry.id)
{ {
@ -705,7 +705,7 @@ impl CommitList {
} }
} }
fn selection_highlighted(&mut self) -> bool { fn selection_highlighted(&self) -> bool {
let commit = self.commits[self.selection]; let commit = self.commits[self.selection];
self.highlights self.highlights

View File

@ -496,7 +496,7 @@ impl DiffComponent {
false false
} }
fn unstage_hunk(&mut self) -> Result<()> { fn unstage_hunk(&self) -> Result<()> {
if let Some(diff) = &self.diff { if let Some(diff) = &self.diff {
if let Some(hunk) = self.selected_hunk { if let Some(hunk) = self.selected_hunk {
let hash = diff.hunks[hunk].header_hash; let hash = diff.hunks[hunk].header_hash;
@ -513,7 +513,7 @@ impl DiffComponent {
Ok(()) Ok(())
} }
fn stage_hunk(&mut self) -> Result<()> { fn stage_hunk(&self) -> Result<()> {
if let Some(diff) = &self.diff { if let Some(diff) = &self.diff {
if let Some(hunk) = self.selected_hunk { if let Some(hunk) = self.selected_hunk {
if diff.untracked { if diff.untracked {
@ -621,7 +621,7 @@ impl DiffComponent {
))); )));
} }
fn stage_unstage_hunk(&mut self) -> Result<()> { fn stage_unstage_hunk(&self) -> Result<()> {
if self.current.is_stage { if self.current.is_stage {
self.unstage_hunk()?; self.unstage_hunk()?;
} else { } else {

View File

@ -370,7 +370,7 @@ impl RevisionFilesComponent {
Ok(title) Ok(title)
} }
fn request_files(&mut self, commit: CommitId) { fn request_files(&self, commit: CommitId) {
self.async_treefiles.spawn(AsyncTreeFilesJob::new( self.async_treefiles.spawn(AsyncTreeFilesJob::new(
self.repo.borrow().clone(), self.repo.borrow().clone(),
commit, commit,

View File

@ -73,7 +73,7 @@ impl Input {
} }
/// ///
pub fn set_polling(&mut self, enabled: bool) { pub fn set_polling(&self, enabled: bool) {
self.desired_state.set_and_notify(enabled); self.desired_state.set_and_notify(enabled);
} }

View File

@ -685,7 +685,7 @@ impl BlameFilePopup {
number_of_digits(max_line_number) number_of_digits(max_line_number)
} }
fn move_selection(&mut self, scroll_type: ScrollType) -> bool { fn move_selection(&self, scroll_type: ScrollType) -> bool {
let mut table_state = self.table_state.take(); let mut table_state = self.table_state.take();
let old_selection = table_state.selected().unwrap_or(0); let old_selection = table_state.selected().unwrap_or(0);
@ -716,7 +716,7 @@ impl BlameFilePopup {
needs_update needs_update
} }
fn set_open_selection(&mut self) { fn set_open_selection(&self) {
if let Some(selection) = if let Some(selection) =
self.open_request.as_ref().and_then(|req| req.selection) self.open_request.as_ref().and_then(|req| req.selection)
{ {

View File

@ -756,7 +756,7 @@ impl BranchListPopup {
Ok(()) Ok(())
} }
fn rename_branch(&mut self) { fn rename_branch(&self) {
let cur_branch = &self.branches[self.selection as usize]; let cur_branch = &self.branches[self.selection as usize];
self.queue.push(InternalEvent::RenameBranch( self.queue.push(InternalEvent::RenameBranch(
cur_branch.reference.clone(), cur_branch.reference.clone(),
@ -764,7 +764,7 @@ impl BranchListPopup {
)); ));
} }
fn delete_branch(&mut self) { fn delete_branch(&self) {
let reference = let reference =
self.branches[self.selection as usize].reference.clone(); self.branches[self.selection as usize].reference.clone();

View File

@ -168,7 +168,7 @@ impl OptionsPopup {
} }
} }
fn switch_option(&mut self, right: bool) { fn switch_option(&self, right: bool) {
if right { if right {
match self.selection { match self.selection {
AppOption::StatusShowUntracked => { AppOption::StatusShowUntracked => {

View File

@ -374,7 +374,7 @@ impl TagListPopup {
Ok(()) Ok(())
} }
pub fn update_missing_remote_tags(&mut self) { pub fn update_missing_remote_tags(&self) {
if self.has_remotes { if self.has_remotes {
self.async_remote_tags.spawn(AsyncRemoteTagsJob::new( self.async_remote_tags.spawn(AsyncRemoteTagsJob::new(
self.repo.borrow().clone(), self.repo.borrow().clone(),
@ -384,7 +384,7 @@ impl TagListPopup {
} }
/// ///
fn move_selection(&mut self, scroll_type: ScrollType) -> bool { fn move_selection(&self, scroll_type: ScrollType) -> bool {
let mut table_state = self.table_state.take(); let mut table_state = self.table_state.take();
let old_selection = table_state.selected().unwrap_or(0); let old_selection = table_state.selected().unwrap_or(0);

View File

@ -257,7 +257,7 @@ impl Revlog {
let cancellation_flag = Arc::new(AtomicBool::new(false)); let cancellation_flag = Arc::new(AtomicBool::new(false));
let mut job = AsyncSingleJob::new(self.sender.clone()); let job = AsyncSingleJob::new(self.sender.clone());
job.spawn(AsyncCommitFilterJob::new( job.spawn(AsyncCommitFilterJob::new(
self.repo.borrow().clone(), self.repo.borrow().clone(),
self.list.copy_items(), self.list.copy_items(),

View File

@ -69,7 +69,7 @@ impl Stashing {
} }
/// ///
pub fn update(&mut self) -> Result<()> { pub fn update(&self) -> Result<()> {
if self.is_visible() { if self.is_visible() {
self.git_status self.git_status
//TODO: support options //TODO: support options

View File

@ -46,7 +46,7 @@ impl StashList {
Ok(()) Ok(())
} }
fn apply_stash(&mut self) { fn apply_stash(&self) {
if let Some(e) = self.list.selected_entry() { if let Some(e) = self.list.selected_entry() {
match sync::stash_apply(&self.repo.borrow(), e.id, false) match sync::stash_apply(&self.repo.borrow(), e.id, false)
{ {
@ -62,7 +62,7 @@ impl StashList {
} }
} }
fn drop_stash(&mut self) { fn drop_stash(&self) {
if self.list.marked_count() > 0 { if self.list.marked_count() > 0 {
self.queue.push(InternalEvent::ConfirmAction( self.queue.push(InternalEvent::ConfirmAction(
Action::StashDrop(self.list.marked_commits()), Action::StashDrop(self.list.marked_commits()),
@ -74,7 +74,7 @@ impl StashList {
} }
} }
fn pop_stash(&mut self) { fn pop_stash(&self) {
if let Some(e) = self.list.selected_entry() { if let Some(e) = self.list.selected_entry() {
self.queue.push(InternalEvent::ConfirmAction( self.queue.push(InternalEvent::ConfirmAction(
Action::StashPop(e.id), Action::StashPop(e.id),
@ -82,7 +82,7 @@ impl StashList {
} }
} }
fn inspect(&mut self) { fn inspect(&self) {
if let Some(e) = self.list.selected_entry() { if let Some(e) = self.list.selected_entry() {
self.queue.push(InternalEvent::OpenPopup( self.queue.push(InternalEvent::OpenPopup(
StackablePopupOpen::InspectCommit( StackablePopupOpen::InspectCommit(

View File

@ -451,7 +451,7 @@ impl Status {
Ok(()) Ok(())
} }
pub fn get_files_changes(&mut self) -> Result<Vec<StatusItem>> { pub fn get_files_changes(&self) -> Result<Vec<StatusItem>> {
Ok(self.git_status_stage.last()?.items) Ok(self.git_status_stage.last()?.items)
} }
@ -540,7 +540,7 @@ impl Status {
} }
/// called after confirmation /// called after confirmation
pub fn reset(&mut self, item: &ResetItem) -> bool { pub fn reset(&self, item: &ResetItem) -> bool {
if let Err(e) = sync::reset_workdir( if let Err(e) = sync::reset_workdir(
&self.repo.borrow(), &self.repo.borrow(),
item.path.as_str(), item.path.as_str(),