Skip to content

Commit 81924fb

Browse files
author
Stephan Dilly
committed
show subject line of commits compared
1 parent 3db3b95 commit 81924fb

File tree

6 files changed

+47
-102
lines changed

6 files changed

+47
-102
lines changed

asyncgit/src/sync/commit_details.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ pub struct CommitDetails {
8080
pub hash: String,
8181
}
8282

83+
impl CommitDetails {
84+
///
85+
pub fn short_hash(&self) -> &str {
86+
&self.hash[0..7]
87+
}
88+
}
89+
8390
///
8491
pub fn get_commit_details(
8592
repo_path: &str,

src/components/commit_details/compare_details.rs

Lines changed: 12 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use crate::{
88
CommandBlocking, CommandInfo, Component, DrawableComponent,
99
EventState,
1010
},
11-
keys::SharedKeyConfig,
1211
strings::{self},
1312
ui::style::SharedTheme,
1413
};
@@ -29,21 +28,15 @@ pub struct CompareDetailsComponent {
2928
data: Option<(CommitDetails, CommitDetails)>,
3029
theme: SharedTheme,
3130
focused: bool,
32-
key_config: SharedKeyConfig,
3331
}
3432

3533
impl CompareDetailsComponent {
3634
///
37-
pub const fn new(
38-
theme: SharedTheme,
39-
key_config: SharedKeyConfig,
40-
focused: bool,
41-
) -> Self {
35+
pub const fn new(theme: SharedTheme, focused: bool) -> Self {
4236
Self {
4337
data: None,
4438
theme,
4539
focused,
46-
key_config,
4740
}
4841
}
4942

@@ -68,11 +61,7 @@ impl CompareDetailsComponent {
6861
fn get_commit_text(&self, data: &CommitDetails) -> Vec<Spans> {
6962
let mut res = vec![
7063
Spans::from(vec![
71-
style_detail(
72-
&self.theme,
73-
&self.key_config,
74-
&Detail::Author,
75-
),
64+
style_detail(&self.theme, &Detail::Author),
7665
Span::styled(
7766
Cow::from(format!(
7867
"{} <{}>",
@@ -82,11 +71,7 @@ impl CompareDetailsComponent {
8271
),
8372
]),
8473
Spans::from(vec![
85-
style_detail(
86-
&self.theme,
87-
&self.key_config,
88-
&Detail::Date,
89-
),
74+
style_detail(&self.theme, &Detail::Date),
9075
Span::styled(
9176
Cow::from(time_to_string(
9277
data.author.time,
@@ -97,48 +82,15 @@ impl CompareDetailsComponent {
9782
]),
9883
];
9984

100-
if let Some(ref committer) = data.committer {
101-
res.extend(vec![
102-
Spans::from(vec![
103-
style_detail(
104-
&self.theme,
105-
&self.key_config,
106-
&Detail::Commiter,
107-
),
108-
Span::styled(
109-
Cow::from(format!(
110-
"{} <{}>",
111-
committer.name, committer.email
112-
)),
113-
self.theme.text(true, false),
114-
),
115-
]),
116-
Spans::from(vec![
117-
style_detail(
118-
&self.theme,
119-
&self.key_config,
120-
&Detail::Date,
121-
),
122-
Span::styled(
123-
Cow::from(time_to_string(
124-
committer.time,
125-
false,
126-
)),
127-
self.theme.text(true, false),
128-
),
129-
]),
130-
]);
131-
}
132-
13385
res.push(Spans::from(vec![
86+
style_detail(&self.theme, &Detail::Message),
13487
Span::styled(
135-
Cow::from(strings::commit::details_sha(
136-
&self.key_config,
137-
)),
138-
self.theme.text(false, false),
139-
),
140-
Span::styled(
141-
Cow::from(data.hash.clone()),
88+
Cow::from(
89+
data.message
90+
.as_ref()
91+
.map(|msg| msg.subject.clone())
92+
.unwrap_or_default(),
93+
),
14294
self.theme.text(true, false),
14395
),
14496
]));
@@ -166,6 +118,7 @@ impl DrawableComponent for CompareDetailsComponent {
166118
dialog_paragraph(
167119
&strings::commit::compare_details_info_title(
168120
true,
121+
data.0.short_hash(),
169122
),
170123
Text::from(self.get_commit_text(&data.0)),
171124
&self.theme,
@@ -178,6 +131,7 @@ impl DrawableComponent for CompareDetailsComponent {
178131
dialog_paragraph(
179132
&strings::commit::compare_details_info_title(
180133
false,
134+
data.1.short_hash(),
181135
),
182136
Text::from(self.get_commit_text(&data.1)),
183137
&self.theme,

src/components/commit_details/details.rs

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,7 @@ impl DetailsComponent {
155155
if let Some(ref data) = self.data {
156156
let mut res = vec![
157157
Spans::from(vec![
158-
style_detail(
159-
&self.theme,
160-
&self.key_config,
161-
&Detail::Author,
162-
),
158+
style_detail(&self.theme, &Detail::Author),
163159
Span::styled(
164160
Cow::from(format!(
165161
"{} <{}>",
@@ -169,11 +165,7 @@ impl DetailsComponent {
169165
),
170166
]),
171167
Spans::from(vec![
172-
style_detail(
173-
&self.theme,
174-
&self.key_config,
175-
&Detail::Date,
176-
),
168+
style_detail(&self.theme, &Detail::Date),
177169
Span::styled(
178170
Cow::from(time_to_string(
179171
data.author.time,
@@ -187,11 +179,7 @@ impl DetailsComponent {
187179
if let Some(ref committer) = data.committer {
188180
res.extend(vec![
189181
Spans::from(vec![
190-
style_detail(
191-
&self.theme,
192-
&self.key_config,
193-
&Detail::Commiter,
194-
),
182+
style_detail(&self.theme, &Detail::Commiter),
195183
Span::styled(
196184
Cow::from(format!(
197185
"{} <{}>",
@@ -201,11 +189,7 @@ impl DetailsComponent {
201189
),
202190
]),
203191
Spans::from(vec![
204-
style_detail(
205-
&self.theme,
206-
&self.key_config,
207-
&Detail::Date,
208-
),
192+
style_detail(&self.theme, &Detail::Date),
209193
Span::styled(
210194
Cow::from(time_to_string(
211195
committer.time,
@@ -219,9 +203,7 @@ impl DetailsComponent {
219203

220204
res.push(Spans::from(vec![
221205
Span::styled(
222-
Cow::from(strings::commit::details_sha(
223-
&self.key_config,
224-
)),
206+
Cow::from(strings::commit::details_sha()),
225207
self.theme.text(false, false),
226208
),
227209
Span::styled(
@@ -233,7 +215,6 @@ impl DetailsComponent {
233215
if !self.tags.is_empty() {
234216
res.push(Spans::from(style_detail(
235217
&self.theme,
236-
&self.key_config,
237218
&Detail::Sha,
238219
)));
239220

src/components/commit_details/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ impl CommitDetailsComponent {
5353
),
5454
compare_details: CompareDetailsComponent::new(
5555
theme.clone(),
56-
key_config.clone(),
5756
false,
5857
),
5958
git_commit_files: AsyncCommitFiles::new(sender),

src/components/commit_details/style.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{keys::SharedKeyConfig, strings, ui::style::SharedTheme};
1+
use crate::{strings, ui::style::SharedTheme};
22
use std::borrow::Cow;
33
use tui::text::Span;
44

@@ -7,28 +7,32 @@ pub enum Detail {
77
Date,
88
Commiter,
99
Sha,
10+
Message,
1011
}
1112

1213
pub fn style_detail<'a>(
1314
theme: &'a SharedTheme,
14-
keys: &'a SharedKeyConfig,
1515
field: &Detail,
1616
) -> Span<'a> {
1717
match field {
1818
Detail::Author => Span::styled(
19-
Cow::from(strings::commit::details_author(keys)),
19+
Cow::from(strings::commit::details_author()),
2020
theme.text(false, false),
2121
),
2222
Detail::Date => Span::styled(
23-
Cow::from(strings::commit::details_date(keys)),
23+
Cow::from(strings::commit::details_date()),
2424
theme.text(false, false),
2525
),
2626
Detail::Commiter => Span::styled(
27-
Cow::from(strings::commit::details_committer(keys)),
27+
Cow::from(strings::commit::details_committer()),
2828
theme.text(false, false),
2929
),
3030
Detail::Sha => Span::styled(
31-
Cow::from(strings::commit::details_tags(keys)),
31+
Cow::from(strings::commit::details_tags()),
32+
theme.text(false, false),
33+
),
34+
Detail::Message => Span::styled(
35+
Cow::from(strings::commit::details_message()),
3236
theme.text(false, false),
3337
),
3438
}

src/strings.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -300,34 +300,34 @@ pub fn rename_branch_popup_msg(
300300

301301
pub mod commit {
302302
use crate::keys::SharedKeyConfig;
303-
pub fn details_author(_key_config: &SharedKeyConfig) -> String {
303+
pub fn details_author() -> String {
304304
"Author: ".to_string()
305305
}
306-
pub fn details_committer(
307-
_key_config: &SharedKeyConfig,
308-
) -> String {
306+
pub fn details_committer() -> String {
309307
"Committer: ".to_string()
310308
}
311-
pub fn details_sha(_key_config: &SharedKeyConfig) -> String {
309+
pub fn details_sha() -> String {
312310
"Sha: ".to_string()
313311
}
314-
pub fn details_date(_key_config: &SharedKeyConfig) -> String {
312+
pub fn details_date() -> String {
315313
"Date: ".to_string()
316314
}
317-
pub fn details_tags(_key_config: &SharedKeyConfig) -> String {
315+
pub fn details_tags() -> String {
318316
"Tags: ".to_string()
319317
}
318+
pub fn details_message() -> String {
319+
"Subject: ".to_string()
320+
}
320321
pub fn details_info_title(
321322
_key_config: &SharedKeyConfig,
322323
) -> String {
323324
"Info".to_string()
324325
}
325-
pub fn compare_details_info_title(old: bool) -> String {
326-
if old {
327-
"Old".to_string()
328-
} else {
329-
"New".to_string()
330-
}
326+
pub fn compare_details_info_title(
327+
old: bool,
328+
hash: &str,
329+
) -> String {
330+
format!("{}: {}", if old { "Old" } else { "New" }, hash)
331331
}
332332
pub fn details_message_title(
333333
_key_config: &SharedKeyConfig,

0 commit comments

Comments
 (0)