custom pretty format: tolerate empty e-mail address
When e-mail address is empty (e.g. "A U Thor <>"), --pretty=format misparsed the commit header and did not pick up the date field correctly. Noticed by Marco, fixed slightly differently with additional sanity check and with a test. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Jan 6, 2008 at 04:21 UTC
f7ab5c793707082d41e19093f536cdc0d45d8830
2 files changed
+22
-4
pretty.c
+12
-4
@@ -292,7 +292,18 @@ static void format_person_part(struct strbuf *sb, char part,
292
/* parse name */
293
for (end = 0; end < len && msg[end] != '<'; end++)
294
; /* do nothing */
295
+ /*
296
+ * If it does not even have a '<' and '>', that is
297
+ * quite a bogus commit author and we discard it;
298
+ * this is in line with add_user_info() that is used
299
+ * in the normal codepath. When end points at the '<'
300
+ * that we found, it should have matching '>' later,
301
+ * which means start (beginning of email address) must
302
+ * be strictly below len.
303
+ */
304
start = end + 1;
305
+ if (start >= len - 1)
306
+ return;
307
while (end > 0 && isspace(msg[end - 1]))
308
end--;
309
if (part == 'n') { /* name */
@@ -300,11 +311,8 @@ static void format_person_part(struct strbuf *sb, char part,
311
return;
312
}
313
303
- if (start >= len)
304
- return;
305
-
314
/* parse email */
307
- for (end = start + 1; end < len && msg[end] != '>'; end++)
315
+ for (end = start; end < len && msg[end] != '>'; end++)
316
; /* do nothing */
317
318
if (end >= len)
t/t6006-rev-list-format.sh
+10
@@ -139,4 +139,14 @@ commit 131a310eb913d107dd3c09a65d1651175898735d
139
commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
140
EOF
141
142
+test_expect_success 'empty email' '
143
+ test_tick &&
144
+ C=$(GIT_AUTHOR_EMAIL= git commit-tree HEAD^{tree} </dev/null) &&
145
+ A=$(git show --pretty=format:%an,%ae,%ad%n -s $C) &&
146
+ test "$A" = "A U Thor,,Thu Apr 7 15:14:13 2005 -0700" || {
147
+ echo "Eh? $A" >failure
148
+ false
149
+ }
150
+'
151
+
152
test_done