Skip to content

Commit

Permalink
show tags in commit details popup (closes #193)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan Dilly committed Jul 12, 2020
1 parent f4e2b7c commit 1afa91b
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion asyncgit/src/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion asyncgit/src/sync/tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>;
/// hashmap of tag target commit hash to tag names
pub type Tags = BTreeMap<CommitId, Vec<String>>;
pub type Tags = BTreeMap<CommitId, CommitTags>;

/// returns `Tags` type filled with all tags found in repo
pub fn get_tags(repo_path: &str) -> Result<Tags> {
Expand Down
4 changes: 2 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
13 changes: 5 additions & 8 deletions src/components/commit_details/details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -40,7 +41,7 @@ impl DetailsComponent {
pub fn set_commit(
&mut self,
id: Option<CommitId>,
tags: Option<&Tags>,
tags: Option<CommitTags>,
) -> Result<()> {
self.tags.clear();

Expand All @@ -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(())
Expand Down
4 changes: 2 additions & 2 deletions src/components/commit_details/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
};
use anyhow::Result;
use asyncgit::{
sync::{CommitId, Tags},
sync::{CommitId, CommitTags},
AsyncCommitFiles, AsyncNotification,
};
use crossbeam_channel::Sender;
Expand Down Expand Up @@ -68,7 +68,7 @@ impl CommitDetailsComponent {
pub fn set_commit(
&mut self,
id: Option<CommitId>,
tags: Option<&Tags>,
tags: Option<CommitTags>,
) -> Result<()> {
self.details.set_commit(id, tags)?;

Expand Down
15 changes: 11 additions & 4 deletions src/components/inspect_commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,6 +23,7 @@ use tui::{

pub struct InspectCommitComponent {
commit_id: Option<CommitId>,
tags: Option<CommitTags>,
diff: DiffComponent,
details: CommitDetailsComponent,
git_diff: AsyncDiff,
Expand Down Expand Up @@ -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<CommitTags>,
) -> Result<()> {
self.commit_id = Some(id);
self.tags = tags;
self.show()?;

Ok(())
Expand Down Expand Up @@ -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(())
Expand Down
4 changes: 2 additions & 2 deletions src/queue.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -47,7 +47,7 @@ pub enum InternalEvent {
///
TabSwitch,
///
InspectCommit(CommitId),
InspectCommit(CommitId, Option<CommitTags>),
///
OpenExternalEditor(Option<String>),
}
Expand Down
35 changes: 30 additions & 5 deletions src/tabs/revlog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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)?;
}
}

Expand Down Expand Up @@ -141,6 +142,25 @@ impl Revlog {
fn selected_commit(&self) -> Option<CommitId> {
self.list.selected_entry().map(|e| e.id)
}

fn selected_commit_tags(
&self,
commit: &Option<CommitId>,
) -> Option<CommitTags> {
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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/tabs/stashlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down

0 comments on commit 1afa91b

Please sign in to comment.