mirror of
https://github.com/git/git.git
synced 2024-12-14 20:33:46 +08:00
03818a4a94
Split_ident currently parses left to right. Given this input: Your Name <email@example.com> 123456789 -0500\n We assume the name starts the line and runs until the first "<". That starts the email address, which runs until the first ">". Everything after that is assumed to be the timestamp. This works fine in the normal case, but is easily broken by corrupted ident lines that contain an extra ">". Some examples seen in the wild are: 1. Name <email>-<> 123456789 -0500\n 2. Name <email> <Name<email>> 123456789 -0500\n 3. Name1 <email1>, Name2 <email2> 123456789 -0500\n Currently each of these produces some email address (which is not necessarily the one the user intended) and end up with a NULL date (which is generally interpreted as the epoch by "git log" and friends). But in each case we could get the correct timestamp simply by parsing from the right-hand side, looking backwards for the final ">", and then reading the timestamp from there. In general, it's a losing battle to try to automatically guess what the user meant with their broken crud. But this particular workaround is probably worth doing. One, it's dirt simple, and can't impact non-broken cases. Two, it doesn't catch a single breakage we've seen, but rather a large class of errors (i.e., any breakage inside the email angle brackets may affect the email, but won't spill over into the timestamp parsing). And three, the timestamp is arguably more valuable to get right, because it can affect correctness (e.g., in --until cutoffs). This patch implements the right-to-left scheme described above. We adjust the tests in t4212, which generate a commit with such a broken ident, and now gets the timestamp right. We also add a test that fsck continues to detect the breakage. For reference, here are pointers to the breakages seen (as numbered above): [1] http://article.gmane.org/gmane.comp.version-control.git/221441 [2] http://article.gmane.org/gmane.comp.version-control.git/222362 [3] http://perl5.git.perl.org/perl.git/commit/13b79730adea97e660de84bbe67f9d7cbe344302 Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
48 lines
1.1 KiB
Bash
Executable File
48 lines
1.1 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
test_description='git log with invalid commit headers'
|
|
|
|
. ./test-lib.sh
|
|
|
|
test_expect_success 'setup' '
|
|
test_commit foo &&
|
|
|
|
git cat-file commit HEAD |
|
|
sed "/^author /s/>/>-<>/" >broken_email.commit &&
|
|
git hash-object -w -t commit broken_email.commit >broken_email.hash &&
|
|
git update-ref refs/heads/broken_email $(cat broken_email.hash)
|
|
'
|
|
|
|
test_expect_success 'fsck notices broken commit' '
|
|
git fsck 2>actual &&
|
|
test_i18ngrep invalid.author actual
|
|
'
|
|
|
|
test_expect_success 'git log with broken author email' '
|
|
{
|
|
echo commit $(cat broken_email.hash)
|
|
echo "Author: A U Thor <author@example.com>"
|
|
echo "Date: Thu Apr 7 15:13:13 2005 -0700"
|
|
echo
|
|
echo " foo"
|
|
} >expect.out &&
|
|
: >expect.err &&
|
|
|
|
git log broken_email >actual.out 2>actual.err &&
|
|
|
|
test_cmp expect.out actual.out &&
|
|
test_cmp expect.err actual.err
|
|
'
|
|
|
|
test_expect_success 'git log --format with broken author email' '
|
|
echo "A U Thor+author@example.com+Thu Apr 7 15:13:13 2005 -0700" >expect.out &&
|
|
: >expect.err &&
|
|
|
|
git log --format="%an+%ae+%ad" broken_email >actual.out 2>actual.err &&
|
|
|
|
test_cmp expect.out actual.out &&
|
|
test_cmp expect.err actual.err
|
|
'
|
|
|
|
test_done
|