ident: don't consider '.' a crud

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>

brian m. carlson committed Aug 2, 2023 at 09:49 UTC 1c04cb0744d2acdcaebc77b0e78c47efbba67fd5
3 files changed +12 -4
ident.c
-1
@@ -203,7 +203,6 @@ void reset_ident_date(void)
203 static int crud(unsigned char c)
204 {
205 return c <= 32 ||
206 - c == '.' ||
206 c == ',' ||
207 c == ':' ||
208 c == ';' ||
t/t4203-mailmap.sh
+2 -2
@@ -466,7 +466,7 @@ test_expect_success 'gitmailmap(5) example output: example #1' '
466 Author Jane Doe <jane@laptop.(none)> maps to Jane Doe <jane@laptop.(none)>
467 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
468
469 - Author Jane D <jane@desktop.(none)> maps to Jane Doe <jane@desktop.(none)>
469 + Author Jane D. <jane@desktop.(none)> maps to Jane Doe <jane@desktop.(none)>
470 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
471 EOF
472 git -C doc log --reverse --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
@@ -494,7 +494,7 @@ test_expect_success 'gitmailmap(5) example output: example #2' '
494 Author Jane Doe <jane@laptop.(none)> maps to Jane Doe <jane@example.com>
495 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
496
497 - Author Jane D <jane@desktop.(none)> maps to Jane Doe <jane@example.com>
497 + Author Jane D. <jane@desktop.(none)> maps to Jane Doe <jane@example.com>
498 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
499 EOF
500 git -C doc log --reverse --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
t/t7518-ident-corner-cases.sh
+10 -1
@@ -20,10 +20,19 @@ test_expect_success 'empty name and missing email' '
20 '
21
22 test_expect_success 'commit rejects all-crud name' '
23 - test_must_fail env GIT_AUTHOR_NAME=" .;<>" \
23 + test_must_fail env GIT_AUTHOR_NAME=" ,;<>" \
24 git commit --allow-empty -m foo
25 '
26
27 +test_expect_success 'commit does not strip trailing dot' '
28 + author_name="Pat Doe Jr." &&
29 + env GIT_AUTHOR_NAME="$author_name" \
30 + git commit --allow-empty -m foo &&
31 + git log -1 --format=%an >actual &&
32 + echo "$author_name" >expected &&
33 + test_cmp actual expected
34 +'
35 +
36 # We must test the actual error message here, as an unwanted
37 # auto-detection could fail for other reasons.
38 test_expect_success 'empty configured name does not auto-detect' '