Skip to content

Commit 3d3a5ce

Browse files
change for_path to accept author_display_replace to change author name on demand
1 parent 13b5c1d commit 3d3a5ce

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

crates/git/src/blame.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,19 @@ impl Blame {
3131
content: &Rope,
3232
remote_url: Option<String>,
3333
provider_registry: Arc<GitHostingProviderRegistry>,
34+
author_display_replace: Option<&str>
3435
) -> Result<Self> {
3536
let output = run_git_blame(git_binary, working_directory, path, content)?;
3637
let mut entries = parse_git_blame(&output)?;
3738
entries.sort_unstable_by(|a, b| a.range.start.cmp(&b.range.start));
3839

39-
let current_user = get_git_user_name(git_binary, working_directory)?;
40-
41-
if let Some(username) = current_user {
42-
for entry in &mut entries {
43-
if let Some(ref author) = entry.author {
44-
if author == &username {
45-
entry.author = Some(format!("{} (You)", author));
46-
}
47-
}
40+
if let Some(replacement) = author_display_replace {
41+
if let Some(username) = get_git_user_name(git_binary, working_directory)? {
42+
let new_author = replacement.replace("{}", &username);
43+
entries
44+
.iter_mut()
45+
.filter(|e| e.author.as_deref() == Some(&username))
46+
.for_each(|e| e.author = Some(new_author.clone()));
4847
}
4948
}
5049

0 commit comments

Comments
 (0)