Skip to content

Commit 2a9d10d

Browse files
author
Stephan Dilly
committed
show tags in commit details popup (closes #193)
1 parent 819472f commit 2a9d10d

File tree

10 files changed

+58
-26
lines changed

10 files changed

+58
-26
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
- crashes in revlog with utf8 commit messages ([#188](https://github.com/extrawurst/gitui/issues/188))
1616
- `add_to_ignore` failed on files without a newline at EOF ([#191](https://github.com/extrawurst/gitui/issues/191))
1717
- new tags were not picked up in revlog view ([#190](https://github.com/extrawurst/gitui/issues/190))
18+
- tags not shown in commit details popup ([#193](https://github.com/extrawurst/gitui/issues/193))
1819

1920
## [0.8.1] - 2020-07-07
2021

Diff for: asyncgit/src/sync/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub use ignore::add_to_ignore;
2929
pub use logwalker::LogWalker;
3030
pub use reset::{reset_stage, reset_workdir};
3131
pub use stash::{get_stashes, stash_apply, stash_drop, stash_save};
32-
pub use tags::{get_tags, Tags};
32+
pub use tags::{get_tags, CommitTags, Tags};
3333
pub use utils::{
3434
get_head, is_bare_repo, is_repo, stage_add_all, stage_add_file,
3535
stage_addremoved,

Diff for: asyncgit/src/sync/tags.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ use crate::error::Result;
33
use scopetime::scope_time;
44
use std::collections::BTreeMap;
55

6+
/// all tags pointing to a single commit
7+
pub type CommitTags = Vec<String>;
68
/// hashmap of tag target commit hash to tag names
7-
pub type Tags = BTreeMap<CommitId, Vec<String>>;
9+
pub type Tags = BTreeMap<CommitId, CommitTags>;
810

911
/// returns `Tags` type filled with all tags found in repo
1012
pub fn get_tags(repo_path: &str) -> Result<Tags> {

Diff for: src/app.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,8 @@ impl App {
420420
self.stashmsg_popup.show()?
421421
}
422422
InternalEvent::TabSwitch => self.set_tab(0)?,
423-
InternalEvent::InspectCommit(id) => {
424-
self.inspect_commit_popup.open(id)?;
423+
InternalEvent::InspectCommit(id, tags) => {
424+
self.inspect_commit_popup.open(id, tags)?;
425425
flags.insert(NeedsUpdate::ALL | NeedsUpdate::COMMANDS)
426426
}
427427
InternalEvent::OpenExternalEditor(path) => {

Diff for: src/components/commit_details/details.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ use crate::{
88
};
99
use anyhow::Result;
1010
use asyncgit::{
11-
sync::{self, CommitDetails, CommitId, Tags},
11+
sync::{self, CommitDetails, CommitId},
1212
CWD,
1313
};
1414
use crossterm::event::Event;
1515
use std::borrow::Cow;
16+
use sync::CommitTags;
1617
use tui::{
1718
backend::Backend,
1819
layout::{Constraint, Direction, Layout, Rect},
@@ -40,7 +41,7 @@ impl DetailsComponent {
4041
pub fn set_commit(
4142
&mut self,
4243
id: Option<CommitId>,
43-
tags: Option<&Tags>,
44+
tags: Option<CommitTags>,
4445
) -> Result<()> {
4546
self.tags.clear();
4647

@@ -50,12 +51,8 @@ impl DetailsComponent {
5051
None
5152
};
5253

53-
if let Some(id) = id {
54-
if let Some(tags) = tags {
55-
if let Some(tags) = tags.get(&id) {
56-
self.tags.extend(tags.clone());
57-
}
58-
}
54+
if let Some(tags) = tags {
55+
self.tags.extend(tags)
5956
}
6057

6158
Ok(())

Diff for: src/components/commit_details/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{
99
};
1010
use anyhow::Result;
1111
use asyncgit::{
12-
sync::{CommitId, Tags},
12+
sync::{CommitId, CommitTags},
1313
AsyncCommitFiles, AsyncNotification,
1414
};
1515
use crossbeam_channel::Sender;
@@ -68,7 +68,7 @@ impl CommitDetailsComponent {
6868
pub fn set_commit(
6969
&mut self,
7070
id: Option<CommitId>,
71-
tags: Option<&Tags>,
71+
tags: Option<CommitTags>,
7272
) -> Result<()> {
7373
self.details.set_commit(id, tags)?;
7474

Diff for: src/components/inspect_commit.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use crate::{
99
};
1010
use anyhow::Result;
1111
use asyncgit::{
12-
sync::CommitId, AsyncDiff, AsyncNotification, DiffParams,
13-
DiffType,
12+
sync::{CommitId, CommitTags},
13+
AsyncDiff, AsyncNotification, DiffParams, DiffType,
1414
};
1515
use crossbeam_channel::Sender;
1616
use crossterm::event::Event;
@@ -23,6 +23,7 @@ use tui::{
2323

2424
pub struct InspectCommitComponent {
2525
commit_id: Option<CommitId>,
26+
tags: Option<CommitTags>,
2627
diff: DiffComponent,
2728
details: CommitDetailsComponent,
2829
git_diff: AsyncDiff,
@@ -160,14 +161,20 @@ impl InspectCommitComponent {
160161
),
161162
diff: DiffComponent::new(None, theme),
162163
commit_id: None,
164+
tags: None,
163165
git_diff: AsyncDiff::new(sender.clone()),
164166
visible: false,
165167
}
166168
}
167169

168170
///
169-
pub fn open(&mut self, id: CommitId) -> Result<()> {
171+
pub fn open(
172+
&mut self,
173+
id: CommitId,
174+
tags: Option<CommitTags>,
175+
) -> Result<()> {
170176
self.commit_id = Some(id);
177+
self.tags = tags;
171178
self.show()?;
172179

173180
Ok(())
@@ -225,7 +232,7 @@ impl InspectCommitComponent {
225232
}
226233

227234
fn update(&mut self) -> Result<()> {
228-
self.details.set_commit(self.commit_id, None)?;
235+
self.details.set_commit(self.commit_id, self.tags.clone())?;
229236
self.update_diff()?;
230237

231238
Ok(())

Diff for: src/queue.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::tabs::StashingOptions;
2-
use asyncgit::sync::CommitId;
2+
use asyncgit::sync::{CommitId, CommitTags};
33
use bitflags::bitflags;
44
use std::{cell::RefCell, collections::VecDeque, rc::Rc};
55

@@ -47,7 +47,7 @@ pub enum InternalEvent {
4747
///
4848
TabSwitch,
4949
///
50-
InspectCommit(CommitId),
50+
InspectCommit(CommitId, Option<CommitTags>),
5151
///
5252
OpenExternalEditor(Option<String>),
5353
}

Diff for: src/tabs/revlog.rs

+30-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use asyncgit::{
1818
use crossbeam_channel::Sender;
1919
use crossterm::event::Event;
2020
use std::time::Duration;
21+
use sync::CommitTags;
2122
use tui::{
2223
backend::Backend,
2324
layout::{Constraint, Direction, Layout, Rect},
@@ -89,10 +90,10 @@ impl Revlog {
8990
);
9091

9192
if self.commit_details.is_visible() {
92-
self.commit_details.set_commit(
93-
self.selected_commit(),
94-
self.list.tags(),
95-
)?;
93+
let commit = self.selected_commit();
94+
let tags = self.selected_commit_tags(&commit);
95+
96+
self.commit_details.set_commit(commit, tags)?;
9697
}
9798
}
9899

@@ -141,6 +142,25 @@ impl Revlog {
141142
fn selected_commit(&self) -> Option<CommitId> {
142143
self.list.selected_entry().map(|e| e.id)
143144
}
145+
146+
fn selected_commit_tags(
147+
&self,
148+
commit: &Option<CommitId>,
149+
) -> Option<CommitTags> {
150+
let tags = self.list.tags();
151+
152+
commit.and_then(|commit| {
153+
if let Some(tags) = tags {
154+
if let Some(tags) = tags.get(&commit) {
155+
Some(tags.clone())
156+
} else {
157+
None
158+
}
159+
} else {
160+
None
161+
}
162+
})
163+
}
144164
}
145165

146166
impl DrawableComponent for Revlog {
@@ -194,7 +214,12 @@ impl Component for Revlog {
194214
self.selected_commit()
195215
{
196216
self.queue.borrow_mut().push_back(
197-
InternalEvent::InspectCommit(id),
217+
InternalEvent::InspectCommit(
218+
id,
219+
self.selected_commit_tags(&Some(
220+
id,
221+
)),
222+
),
198223
);
199224
Ok(true)
200225
} else {

Diff for: src/tabs/stashlist.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl StashList {
7777
if let Some(e) = self.list.selected_entry() {
7878
self.queue
7979
.borrow_mut()
80-
.push_back(InternalEvent::InspectCommit(e.id));
80+
.push_back(InternalEvent::InspectCommit(e.id, None));
8181
}
8282
}
8383

0 commit comments

Comments
 (0)