Skip to content

Commit

Permalink
ident: don't consider '.' a crud
Browse files Browse the repository at this point in the history
When we process a user's name (as in user.name), we strip all
leading and trailing crud from it.  Right now, we consider a dot
a crud character, and strip it off.

However, this is unsuitable for many personal names because humans
frequently have abbreviated suffixes, such as "Jr." or "Sr." at the end
of their names, and this corrupts them.  Some other users may wish to
use an abbreviated name or initial, which will pose a problem especially
in cultures that write the family name first, followed by the personal
name.

Since the current approach causes lots of practical problems, let's
avoid it by no longer considering a dot to be crud.

Note that "." in the name forces the entire name to be quoted to
please mailers, but stripping "." only at the beginning and the end
does not help a name with "." in the middle (like "brian m. carlson")
so this change will not make it much worse.  A name like "Given
Family, Jr." that did not have to be quoted now would need to be, in
order to be placed on the e-mail headers, though.

This is based on a weather-balloon patch by Jeff King sent in Aug 2021
https://lore.kernel.org/git/YSKm8Q8nyTavQaox@coredump.intra.peff.net/

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
bk2204 authored and gitster committed Aug 2, 2023
1 parent fb7d80e commit 1c04cb0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
1 change: 0 additions & 1 deletion ident.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ void reset_ident_date(void)
static int crud(unsigned char c)
{
return c <= 32 ||
c == '.' ||
c == ',' ||
c == ':' ||
c == ';' ||
Expand Down
4 changes: 2 additions & 2 deletions t/t4203-mailmap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ test_expect_success 'gitmailmap(5) example output: example #1' '
Author Jane Doe <jane@laptop.(none)> maps to Jane Doe <jane@laptop.(none)>
Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
Author Jane D <jane@desktop.(none)> maps to Jane Doe <jane@desktop.(none)>
Author Jane D. <jane@desktop.(none)> maps to Jane Doe <jane@desktop.(none)>
Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
EOF
git -C doc log --reverse --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
Expand Down Expand Up @@ -494,7 +494,7 @@ test_expect_success 'gitmailmap(5) example output: example #2' '
Author Jane Doe <jane@laptop.(none)> maps to Jane Doe <jane@example.com>
Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
Author Jane D <jane@desktop.(none)> maps to Jane Doe <jane@example.com>
Author Jane D. <jane@desktop.(none)> maps to Jane Doe <jane@example.com>
Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
EOF
git -C doc log --reverse --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
Expand Down
11 changes: 10 additions & 1 deletion t/t7518-ident-corner-cases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,19 @@ test_expect_success 'empty name and missing email' '
'

test_expect_success 'commit rejects all-crud name' '
test_must_fail env GIT_AUTHOR_NAME=" .;<>" \
test_must_fail env GIT_AUTHOR_NAME=" ,;<>" \
git commit --allow-empty -m foo
'

test_expect_success 'commit does not strip trailing dot' '
author_name="Pat Doe Jr." &&
env GIT_AUTHOR_NAME="$author_name" \
git commit --allow-empty -m foo &&
git log -1 --format=%an >actual &&
echo "$author_name" >expected &&
test_cmp actual expected
'

# We must test the actual error message here, as an unwanted
# auto-detection could fail for other reasons.
test_expect_success 'empty configured name does not auto-detect' '
Expand Down

0 comments on commit 1c04cb0

Please sign in to comment.