commit: More generous accepting of RFC-2822 footer lines.
'git commit -s' will insert a blank line before the Signed-off-by line at the end of the message, unless this last line is a Signed-off-by line itself. Common use has other trailing lines at the ends of commit text, in the style of RFC2822 headers. Be more generous in considering lines to be part of this footer. If the last paragraph of the commit message reasonably resembles RFC-2822 formatted lines, don't insert that blank line. The new Signed-off-by line is still only suppressed when the author's existing Signed-off-by is the last line of the message. Signed-off-by: David Brown <davidb@quicinc.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
David Brown committed
Oct 28, 2009 at 10:13 UTC
c1e01b0c5106451770ae77a62f52acfe814c3326
2 files changed
+83
-1
builtin-commit.c
+42
-1
@@ -414,6 +414,47 @@ static void determine_author_info(void)
414
author_date = date;
415
}
416
417
+static int ends_rfc2822_footer(struct strbuf *sb)
418
+{
419
+ int ch;
420
+ int hit = 0;
421
+ int i, j, k;
422
+ int len = sb->len;
423
+ int first = 1;
424
+ const char *buf = sb->buf;
425
+
426
+ for (i = len - 1; i > 0; i--) {
427
+ if (hit && buf[i] == '\n')
428
+ break;
429
+ hit = (buf[i] == '\n');
430
+ }
431
+
432
+ while (i < len - 1 && buf[i] == '\n')
433
+ i++;
434
+
435
+ for (; i < len; i = k) {
436
+ for (k = i; k < len && buf[k] != '\n'; k++)
437
+ ; /* do nothing */
438
+ k++;
439
+
440
+ if ((buf[k] == ' ' || buf[k] == '\t') && !first)
441
+ continue;
442
+
443
+ first = 0;
444
+
445
+ for (j = 0; i + j < len; j++) {
446
+ ch = buf[i + j];
447
+ if (ch == ':')
448
+ break;
449
+ if (isalnum(ch) ||
450
+ (ch == '-'))
451
+ continue;
452
+ return 0;
453
+ }
454
+ }
455
+ return 1;
456
+}
457
+
458
static int prepare_to_commit(const char *index_file, const char *prefix,
459
struct wt_status *s)
460
{
@@ -489,7 +530,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
530
for (i = sb.len - 1; i > 0 && sb.buf[i - 1] != '\n'; i--)
531
; /* do nothing */
532
if (prefixcmp(sb.buf + i, sob.buf)) {
492
- if (prefixcmp(sb.buf + i, sign_off_header))
533
+ if (!ends_rfc2822_footer(&sb))
534
strbuf_addch(&sb, '\n');
535
strbuf_addbuf(&sb, &sob);
536
}
t/t7501-commit.sh
+41
@@ -247,6 +247,47 @@ $existing" &&
247
248
'
249
250
+test_expect_success 'signoff gap' '
251
+
252
+ echo 3 >positive &&
253
+ git add positive &&
254
+ alt="Alt-RFC-822-Header: Value" &&
255
+ git commit -s -m "welcome
256
+
257
+$alt" &&
258
+ git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
259
+ (
260
+ echo welcome
261
+ echo
262
+ echo $alt
263
+ git var GIT_COMMITTER_IDENT |
264
+ sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
265
+ ) >expected &&
266
+ test_cmp expected actual
267
+'
268
+
269
+test_expect_success 'signoff gap 2' '
270
+
271
+ echo 4 >positive &&
272
+ git add positive &&
273
+ alt="fixed: 34" &&
274
+ git commit -s -m "welcome
275
+
276
+We have now
277
+$alt" &&
278
+ git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
279
+ (
280
+ echo welcome
281
+ echo
282
+ echo We have now
283
+ echo $alt
284
+ echo
285
+ git var GIT_COMMITTER_IDENT |
286
+ sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
287
+ ) >expected &&
288
+ test_cmp expected actual
289
+'
290
+
291
test_expect_success 'multiple -m' '
292
293
>negative &&