diff --git a/CHANGELOG.md b/CHANGELOG.md index d06bd376932..9e777b1f8a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - crashes in revlog with utf8 commit messages ([#188](https://github.com/extrawurst/gitui/issues/188)) - `add_to_ignore` failed on files without a newline at EOF ([#191](https://github.com/extrawurst/gitui/issues/191)) - new tags were not picked up in revlog view ([#190](https://github.com/extrawurst/gitui/issues/190)) +- tags not shown in commit details popup ([#193](https://github.com/extrawurst/gitui/issues/193)) ## [0.8.1] - 2020-07-07 diff --git a/asyncgit/src/sync/mod.rs b/asyncgit/src/sync/mod.rs index acf6f08f379..2c0e782fc11 100644 --- a/asyncgit/src/sync/mod.rs +++ b/asyncgit/src/sync/mod.rs @@ -29,7 +29,7 @@ pub use ignore::add_to_ignore; pub use logwalker::LogWalker; 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 tags::{get_tags, CommitTags, Tags}; pub use utils::{ get_head, is_bare_repo, is_repo, stage_add_all, stage_add_file, stage_addremoved, diff --git a/asyncgit/src/sync/tags.rs b/asyncgit/src/sync/tags.rs index 5e6c7cc31c4..63f4f60457e 100644 --- a/asyncgit/src/sync/tags.rs +++ b/asyncgit/src/sync/tags.rs @@ -3,8 +3,10 @@ use crate::error::Result; use scopetime::scope_time; use std::collections::BTreeMap; +/// all tags pointing to a single commit +pub type CommitTags = Vec; /// hashmap of tag target commit hash to tag names -pub type Tags = BTreeMap>; +pub type Tags = BTreeMap; /// returns `Tags` type filled with all tags found in repo pub fn get_tags(repo_path: &str) -> Result { diff --git a/src/app.rs b/src/app.rs index 0de0e8b9c0b..fa028467676 100644 --- a/src/app.rs +++ b/src/app.rs @@ -420,8 +420,8 @@ impl App { self.stashmsg_popup.show()? } InternalEvent::TabSwitch => self.set_tab(0)?, - InternalEvent::InspectCommit(id) => { - self.inspect_commit_popup.open(id)?; + InternalEvent::InspectCommit(id, tags) => { + self.inspect_commit_popup.open(id, tags)?; flags.insert(NeedsUpdate::ALL | NeedsUpdate::COMMANDS) } InternalEvent::OpenExternalEditor(path) => { diff --git a/src/components/commit_details/details.rs b/src/components/commit_details/details.rs index ef4e01d7f87..655bb98d542 100644 --- a/src/components/commit_details/details.rs +++ b/src/components/commit_details/details.rs @@ -8,11 +8,12 @@ use crate::{ }; use anyhow::Result; use asyncgit::{ - sync::{self, CommitDetails, CommitId, Tags}, + sync::{self, CommitDetails, CommitId}, CWD, }; use crossterm::event::Event; use std::borrow::Cow; +use sync::CommitTags; use tui::{ backend::Backend, layout::{Constraint, Direction, Layout, Rect}, @@ -40,7 +41,7 @@ impl DetailsComponent { pub fn set_commit( &mut self, id: Option, - tags: Option<&Tags>, + tags: Option, ) -> Result<()> { self.tags.clear(); @@ -50,12 +51,8 @@ impl DetailsComponent { None }; - if let Some(id) = id { - if let Some(tags) = tags { - if let Some(tags) = tags.get(&id) { - self.tags.extend(tags.clone()); - } - } + if let Some(tags) = tags { + self.tags.extend(tags) } Ok(()) diff --git a/src/components/commit_details/mod.rs b/src/components/commit_details/mod.rs index b706ffc0720..aa8347a0eb5 100644 --- a/src/components/commit_details/mod.rs +++ b/src/components/commit_details/mod.rs @@ -9,7 +9,7 @@ use crate::{ }; use anyhow::Result; use asyncgit::{ - sync::{CommitId, Tags}, + sync::{CommitId, CommitTags}, AsyncCommitFiles, AsyncNotification, }; use crossbeam_channel::Sender; @@ -68,7 +68,7 @@ impl CommitDetailsComponent { pub fn set_commit( &mut self, id: Option, - tags: Option<&Tags>, + tags: Option, ) -> Result<()> { self.details.set_commit(id, tags)?; diff --git a/src/components/inspect_commit.rs b/src/components/inspect_commit.rs index 158b863a2c4..a2201d742fd 100644 --- a/src/components/inspect_commit.rs +++ b/src/components/inspect_commit.rs @@ -9,8 +9,8 @@ use crate::{ }; use anyhow::Result; use asyncgit::{ - sync::CommitId, AsyncDiff, AsyncNotification, DiffParams, - DiffType, + sync::{CommitId, CommitTags}, + AsyncDiff, AsyncNotification, DiffParams, DiffType, }; use crossbeam_channel::Sender; use crossterm::event::Event; @@ -23,6 +23,7 @@ use tui::{ pub struct InspectCommitComponent { commit_id: Option, + tags: Option, diff: DiffComponent, details: CommitDetailsComponent, git_diff: AsyncDiff, @@ -160,14 +161,20 @@ impl InspectCommitComponent { ), diff: DiffComponent::new(None, theme), commit_id: None, + tags: None, git_diff: AsyncDiff::new(sender.clone()), visible: false, } } /// - pub fn open(&mut self, id: CommitId) -> Result<()> { + pub fn open( + &mut self, + id: CommitId, + tags: Option, + ) -> Result<()> { self.commit_id = Some(id); + self.tags = tags; self.show()?; Ok(()) @@ -225,7 +232,7 @@ impl InspectCommitComponent { } fn update(&mut self) -> Result<()> { - self.details.set_commit(self.commit_id, None)?; + self.details.set_commit(self.commit_id, self.tags.clone())?; self.update_diff()?; Ok(()) diff --git a/src/queue.rs b/src/queue.rs index 6d1d2d462b0..bed396ae53f 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -1,5 +1,5 @@ use crate::tabs::StashingOptions; -use asyncgit::sync::CommitId; +use asyncgit::sync::{CommitId, CommitTags}; use bitflags::bitflags; use std::{cell::RefCell, collections::VecDeque, rc::Rc}; @@ -47,7 +47,7 @@ pub enum InternalEvent { /// TabSwitch, /// - InspectCommit(CommitId), + InspectCommit(CommitId, Option), /// OpenExternalEditor(Option), } diff --git a/src/tabs/revlog.rs b/src/tabs/revlog.rs index d6f9cf0859b..fbe0cc9968f 100644 --- a/src/tabs/revlog.rs +++ b/src/tabs/revlog.rs @@ -18,6 +18,7 @@ use asyncgit::{ use crossbeam_channel::Sender; use crossterm::event::Event; use std::time::Duration; +use sync::CommitTags; use tui::{ backend::Backend, layout::{Constraint, Direction, Layout, Rect}, @@ -89,10 +90,10 @@ impl Revlog { ); if self.commit_details.is_visible() { - self.commit_details.set_commit( - self.selected_commit(), - self.list.tags(), - )?; + let commit = self.selected_commit(); + let tags = self.selected_commit_tags(&commit); + + self.commit_details.set_commit(commit, tags)?; } } @@ -141,6 +142,25 @@ impl Revlog { fn selected_commit(&self) -> Option { self.list.selected_entry().map(|e| e.id) } + + fn selected_commit_tags( + &self, + commit: &Option, + ) -> Option { + let tags = self.list.tags(); + + commit.and_then(|commit| { + if let Some(tags) = tags { + if let Some(tags) = tags.get(&commit) { + Some(tags.clone()) + } else { + None + } + } else { + None + } + }) + } } impl DrawableComponent for Revlog { @@ -194,7 +214,12 @@ impl Component for Revlog { self.selected_commit() { self.queue.borrow_mut().push_back( - InternalEvent::InspectCommit(id), + InternalEvent::InspectCommit( + id, + self.selected_commit_tags(&Some( + id, + )), + ), ); Ok(true) } else { diff --git a/src/tabs/stashlist.rs b/src/tabs/stashlist.rs index 0d20930dc66..521c2fa6b32 100644 --- a/src/tabs/stashlist.rs +++ b/src/tabs/stashlist.rs @@ -77,7 +77,7 @@ impl StashList { if let Some(e) = self.list.selected_entry() { self.queue .borrow_mut() - .push_back(InternalEvent::InspectCommit(e.id)); + .push_back(InternalEvent::InspectCommit(e.id, None)); } }