Skip to content

Commit 95c41db

Browse files
author
Stephan Dilly
authored
limit log message to first line of commit msg (#662)
1 parent 97985bf commit 95c41db

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212

1313
### Fixed
1414
- debug print when adding a file to ignore
15+
- limit log messages in log tab ([#652](https://github.com/extrawurst/gitui/issues/652))
1516
- fetch crashed when no upstream of branch is set ([#637](https://github.com/extrawurst/gitui/issues/637))
1617
- `enter` key panics in empty remote branch list ([#643](https://github.com/extrawurst/gitui/issues/643))
1718

asyncgit/src/sync/commits_info.rs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,21 @@ pub fn get_commit_info(
115115
})
116116
}
117117

118-
///
118+
/// if `message_limit` is set the message will be
119+
/// limited to the first line and truncated to fit
119120
pub fn get_message(
120121
c: &Commit,
121-
message_length_limit: Option<usize>,
122+
message_limit: Option<usize>,
122123
) -> String {
123124
let msg = String::from_utf8_lossy(c.message_bytes());
124125
let msg = msg.trim();
125126

126-
message_length_limit.map_or_else(
127+
message_limit.map_or_else(
127128
|| msg.to_string(),
128-
|limit| msg.unicode_truncate(limit).0.to_string(),
129+
|limit| {
130+
let msg = msg.lines().next().unwrap_or_default();
131+
msg.unicode_truncate(limit).0.to_string()
132+
},
129133
)
130134
}
131135

@@ -164,6 +168,25 @@ mod tests {
164168
Ok(())
165169
}
166170

171+
#[test]
172+
fn test_log_first_msg_line() -> Result<()> {
173+
let file_path = Path::new("foo");
174+
let (_td, repo) = repo_init_empty().unwrap();
175+
let root = repo.path().parent().unwrap();
176+
let repo_path = root.as_os_str().to_str().unwrap();
177+
178+
File::create(&root.join(file_path))?.write_all(b"a")?;
179+
stage_add_file(repo_path, file_path).unwrap();
180+
let c1 = commit(repo_path, "subject\nbody").unwrap();
181+
182+
let res = get_commits_info(repo_path, &vec![c1], 50).unwrap();
183+
184+
assert_eq!(res.len(), 1);
185+
assert_eq!(res[0].message.as_str(), "subject");
186+
187+
Ok(())
188+
}
189+
167190
#[test]
168191
fn test_invalid_utf8() -> Result<()> {
169192
let file_path = Path::new("foo");

0 commit comments

Comments
 (0)