diff options
author | Joshix-1 <57299889+Joshix-1@users.noreply.github.com> | 2024-02-12 19:33:46 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-12 20:33:46 +0100 |
commit | 7335cd1c5ddafa0daf32a7dd3d85cb703458157f (patch) | |
tree | 2dc178a533aa31f3aff012d76e50dbe2fb91c2f1 /src | |
parent | 1fa6f9b725a51d041b13977e55b15c383f0d07df (diff) |
fix sorting of commits in diff view (#1747)
Diffstat (limited to 'src')
-rw-r--r-- | src/components/commit_details/compare_details.rs | 44 | ||||
-rw-r--r-- | src/components/commit_details/mod.rs | 9 | ||||
-rw-r--r-- | src/components/compare_commits.rs | 15 |
3 files changed, 36 insertions, 32 deletions
diff --git a/src/components/commit_details/compare_details.rs b/src/components/commit_details/compare_details.rs index 2f184a25..2e908b2b 100644 --- a/src/components/commit_details/compare_details.rs +++ b/src/components/commit_details/compare_details.rs @@ -13,7 +13,9 @@ use crate::{ ui::style::SharedTheme, }; use anyhow::Result; -use asyncgit::sync::{self, CommitDetails, CommitId, RepoPathRef}; +use asyncgit::sync::{ + self, commit_files::OldNew, CommitDetails, CommitId, RepoPathRef, +}; use crossterm::event::Event; use ratatui::{ backend::Backend, @@ -24,7 +26,7 @@ use ratatui::{ pub struct CompareDetailsComponent { repo: RepoPathRef, - data: Option<(CommitDetails, CommitDetails)>, + data: Option<OldNew<CommitDetails>>, theme: SharedTheme, focused: bool, } @@ -40,24 +42,20 @@ impl CompareDetailsComponent { } } - pub fn set_commits(&mut self, ids: Option<(CommitId, CommitId)>) { + pub fn set_commits(&mut self, ids: Option<OldNew<CommitId>>) { self.data = ids.and_then(|ids| { - let c1 = - sync::get_commit_details(&self.repo.borrow(), ids.0) - .ok(); - let c2 = - sync::get_commit_details(&self.repo.borrow(), ids.1) - .ok(); - - c1.and_then(|c1| { - c2.map(|c2| { - if c1.author.time < c2.author.time { - (c1, c2) - } else { - (c2, c1) - } - }) - }) + let old = sync::get_commit_details( + &self.repo.borrow(), + ids.old, + ) + .ok()?; + let new = sync::get_commit_details( + &self.repo.borrow(), + ids.new, + ) + .ok()?; + + Some(OldNew { old, new }) }); } @@ -122,9 +120,9 @@ impl DrawableComponent for CompareDetailsComponent { dialog_paragraph( &strings::commit::compare_details_info_title( true, - data.0.short_hash(), + data.old.short_hash(), ), - Text::from(self.get_commit_text(&data.0)), + Text::from(self.get_commit_text(&data.old)), &self.theme, false, ), @@ -135,9 +133,9 @@ impl DrawableComponent for CompareDetailsComponent { dialog_paragraph( &strings::commit::compare_details_info_title( false, - data.1.short_hash(), + data.new.short_hash(), ), - Text::from(self.get_commit_text(&data.1)), + Text::from(self.get_commit_text(&data.new)), &self.theme, false, ), diff --git a/src/components/commit_details/mod.rs b/src/components/commit_details/mod.rs index 2e14aeca..e9cfd6b9 100644 --- a/src/components/commit_details/mod.rs +++ b/src/components/commit_details/mod.rs @@ -14,7 +14,8 @@ use crate::{ }; use anyhow::Result; use asyncgit::{ - sync::CommitTags, AsyncCommitFiles, CommitFilesParams, + sync::{commit_files::OldNew, CommitTags}, + AsyncCommitFiles, CommitFilesParams, }; use compare_details::CompareDetailsComponent; use crossterm::event::Event; @@ -81,8 +82,10 @@ impl CommitDetailsComponent { self.file_tree.set_commit(Some(id.id)); if let Some(other) = id.other { - self.compare_details - .set_commits(Some((id.id, other))); + self.compare_details.set_commits(Some(OldNew { + new: id.id, + old: other, + })); } else { self.single_details .set_commit(Some(id.id), tags.clone()); diff --git a/src/components/compare_commits.rs b/src/components/compare_commits.rs index 49937c58..19de2539 100644 --- a/src/components/compare_commits.rs +++ b/src/components/compare_commits.rs @@ -13,7 +13,7 @@ use crate::{ }; use anyhow::Result; use asyncgit::{ - sync::{self, CommitId, RepoPathRef}, + sync::{self, commit_files::OldNew, CommitId, RepoPathRef}, AsyncDiff, AsyncGitNotification, CommitFilesParams, DiffParams, DiffType, }; @@ -222,16 +222,19 @@ impl CompareCommitsComponent { Ok(()) } - fn get_ids(&self) -> Option<(CommitId, CommitId)> { + fn get_ids(&self) -> Option<OldNew<CommitId>> { let other = self .open_request .as_ref() .and_then(|open| open.compare_id); - self.open_request - .as_ref() - .map(|open| open.commit_id) - .zip(other) + let this = + self.open_request.as_ref().map(|open| open.commit_id); + + Some(OldNew { + old: other?, + new: this?, + }) } /// called when any tree component changed selection |