Skip to content

Commit 0ceb753

Browse files
committed
Merge branch 'jk/split-broken-ident' into maint
The fall-back parsing of commit objects with broken author or committer lines were less robust than ideal in picking up the timestamps. * jk/split-broken-ident: split_ident: parse timestamp from end of line
2 parents 0faff47 + 03818a4 commit 0ceb753

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

ident.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,21 @@ int split_ident_line(struct ident_split *split, const char *line, int len)
233233
if (!split->mail_end)
234234
return status;
235235

236-
for (cp = split->mail_end + 1; cp < line + len && isspace(*cp); cp++)
236+
/*
237+
* Look from the end-of-line to find the trailing ">" of the mail
238+
* address, even though we should already know it as split->mail_end.
239+
* This can help in cases of broken idents with an extra ">" somewhere
240+
* in the email address. Note that we are assuming the timestamp will
241+
* never have a ">" in it.
242+
*
243+
* Note that we will always find some ">" before going off the front of
244+
* the string, because will always hit the split->mail_end closing
245+
* bracket.
246+
*/
247+
for (cp = line + len - 1; *cp != '>'; cp--)
248+
;
249+
250+
for (cp = cp + 1; cp < line + len && isspace(*cp); cp++)
237251
;
238252
if (line + len <= cp)
239253
goto person_only;

t/t4212-log-corrupt.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@ test_expect_success 'setup' '
1313
git update-ref refs/heads/broken_email $(cat broken_email.hash)
1414
'
1515

16+
test_expect_success 'fsck notices broken commit' '
17+
git fsck 2>actual &&
18+
test_i18ngrep invalid.author actual
19+
'
20+
1621
test_expect_success 'git log with broken author email' '
1722
{
1823
echo commit $(cat broken_email.hash)
1924
echo "Author: A U Thor <[email protected]>"
20-
echo "Date: Thu Jan 1 00:00:00 1970 +0000"
25+
echo "Date: Thu Apr 7 15:13:13 2005 -0700"
2126
echo
2227
echo " foo"
2328
} >expect.out &&
@@ -30,7 +35,7 @@ test_expect_success 'git log with broken author email' '
3035
'
3136

3237
test_expect_success 'git log --format with broken author email' '
33-
echo "A U [email protected]+" >expect.out &&
38+
echo "A U [email protected]+Thu Apr 7 15:13:13 2005 -0700" >expect.out &&
3439
: >expect.err &&
3540
3641
git log --format="%an+%ae+%ad" broken_email >actual.out 2>actual.err &&

0 commit comments

Comments
 (0)