-
-
Notifications
You must be signed in to change notification settings - Fork 584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Respect .mailmap
#2485
Open
acuteenvy
wants to merge
4
commits into
extrawurst:master
Choose a base branch
from
acuteenvy:respect-mailmap
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Respect .mailmap
#2485
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is mostly pretty good. But it fails if there is a commit with an empty email: I would fallback to the original name if getting the name with the mailmap fails. diff --git a/asyncgit/src/sync/commit_details.rs b/asyncgit/src/sync/commit_details.rs
index 85b7250..2203c7f 100644
--- a/asyncgit/src/sync/commit_details.rs
+++ b/asyncgit/src/sync/commit_details.rs
@@ -87,6 +87,24 @@ impl CommitDetails {
}
}
+/// Get the author of a commit
+pub fn get_author_of_commit<'a>(
+ commit: &'a git2::Commit<'a>,
+ mailmap: &git2::Mailmap,
+) -> git2::Signature<'a> {
+ match commit.author_with_mailmap(mailmap) {
+ Ok(author) => author,
+ Err(err) => {
+ log::error!(
+ "Couldn't get author with mailmap for {} {:?}: {err}",
+ commit.id(),
+ commit.message(),
+ );
+ commit.author()
+ }
+ }
+}
+
///
pub fn get_commit_details(
repo_path: &RepoPath,
@@ -99,8 +117,9 @@ pub fn get_commit_details(
let commit = repo.find_commit(id.into())?;
- let author =
- CommitSignature::from(&commit.author_with_mailmap(&mailmap)?);
+ let author = CommitSignature::from(&get_author_of_commit(
+ &commit, &mailmap,
+ ));
let committer = CommitSignature::from(
&commit.committer_with_mailmap(&mailmap)?,
);
diff --git a/asyncgit/src/sync/commit_filter.rs b/asyncgit/src/sync/commit_filter.rs
index 10b02fc..b1f2f26 100644
--- a/asyncgit/src/sync/commit_filter.rs
+++ b/asyncgit/src/sync/commit_filter.rs
@@ -1,4 +1,7 @@
-use super::{commit_files::get_commit_diff, CommitId};
+use super::{
+ commit_details::get_author_of_commit,
+ commit_files::get_commit_diff, CommitId,
+};
use crate::error::Result;
use bitflags::bitflags;
use fuzzy_matcher::FuzzyMatcher;
@@ -200,14 +203,18 @@ pub fn filter_commit_by_search(
.fields
.contains(SearchFields::AUTHORS)
.then(|| -> Result<bool> {
- let name_match = commit
- .author_with_mailmap(&mailmap)?
- .name()
- .is_some_and(|name| filter.match_text(name));
- let mail_match = commit
- .author_with_mailmap(&mailmap)?
- .email()
- .is_some_and(|name| filter.match_text(name));
+ let name_match =
+ get_author_of_commit(&commit, &mailmap)
+ .name()
+ .is_some_and(|name| {
+ filter.match_text(name)
+ });
+ let mail_match =
+ get_author_of_commit(&commit, &mailmap)
+ .email()
+ .is_some_and(|name| {
+ filter.match_text(name)
+ });
Ok(name_match || mail_match)
})
diff --git a/asyncgit/src/sync/commits_info.rs b/asyncgit/src/sync/commits_info.rs
index 9ee891a..4d1f490 100644
--- a/asyncgit/src/sync/commits_info.rs
+++ b/asyncgit/src/sync/commits_info.rs
@@ -1,7 +1,10 @@
use std::fmt::Display;
use super::RepoPath;
-use crate::{error::Result, sync::repository::repo};
+use crate::{
+ error::Result,
+ sync::{commit_details::get_author_of_commit, repository::repo},
+};
use git2::{Commit, Error, Oid};
use scopetime::scope_time;
use unicode_truncate::UnicodeTruncateStr;
@@ -102,8 +105,9 @@ pub fn get_commits_info(
let res = commits
.map(|c: Commit| {
let message = get_message(&c, Some(message_length_limit));
- let author =
- c.author_with_mailmap(&mailmap)?.name().map_or_else(
+ let author = get_author_of_commit(&c, &mailmap)
+ .name()
+ .map_or_else(
|| String::from("<unknown>"),
String::from,
);
@@ -130,7 +134,7 @@ pub fn get_commit_info(
let mailmap = repo.mailmap()?;
let commit = repo.find_commit((*commit_id).into())?;
- let author = commit.author_with_mailmap(&mailmap)?;
+ let author = get_author_of_commit(&commit, &mailmap);
Ok(CommitInfo {
message: commit.message().unwrap_or("").into(), |
Fall back to the original author when get_author_with_mailmap() fails.
Thanks, it also failed when the committer email was empty, now I made it so that it also falls back to the original. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This Pull Request fixes/closes #2406.
It changes the following:
gitui
respect.mailmap
, just like the Git CLII followed the checklist:
make check
without errors