Unify appending signoff in format-patch, commit and sequencer
There are two implementations of append_signoff in log-tree.c and sequencer.c, which do more or less the same thing. Unify on top of the sequencer.c implementation. Add a test in t4014 to demonstrate support for non-s-o-b elements in the commit footer provided by sequence.c:append_sob. Mark tests fixed as appropriate. [Commit message mostly stolen from Nguyễn Thái Ngọc Duy's original unification patch] Signed-off-by: Brandon Casey <bcasey@nvidia.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
5289c56a72
commit
959a26231f
91
log-tree.c
91
log-tree.c
|
@ -9,8 +9,7 @@
|
||||||
#include "string-list.h"
|
#include "string-list.h"
|
||||||
#include "color.h"
|
#include "color.h"
|
||||||
#include "gpg-interface.h"
|
#include "gpg-interface.h"
|
||||||
|
#include "sequencer.h"
|
||||||
#define APPEND_SIGNOFF_DEDUP (1u <<0)
|
|
||||||
|
|
||||||
struct decoration name_decoration = { "object names" };
|
struct decoration name_decoration = { "object names" };
|
||||||
|
|
||||||
|
@ -208,94 +207,6 @@ void show_decorations(struct rev_info *opt, struct commit *commit)
|
||||||
putchar(')');
|
putchar(')');
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Search for "^[-A-Za-z]+: [^@]+@" pattern. It usually matches
|
|
||||||
* Signed-off-by: and Acked-by: lines.
|
|
||||||
*/
|
|
||||||
static int detect_any_signoff(char *letter, int size)
|
|
||||||
{
|
|
||||||
char *cp;
|
|
||||||
int seen_colon = 0;
|
|
||||||
int seen_at = 0;
|
|
||||||
int seen_name = 0;
|
|
||||||
int seen_head = 0;
|
|
||||||
|
|
||||||
cp = letter + size;
|
|
||||||
while (letter <= --cp && *cp == '\n')
|
|
||||||
continue;
|
|
||||||
|
|
||||||
while (letter <= cp) {
|
|
||||||
char ch = *cp--;
|
|
||||||
if (ch == '\n')
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (!seen_at) {
|
|
||||||
if (ch == '@')
|
|
||||||
seen_at = 1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!seen_colon) {
|
|
||||||
if (ch == '@')
|
|
||||||
return 0;
|
|
||||||
else if (ch == ':')
|
|
||||||
seen_colon = 1;
|
|
||||||
else
|
|
||||||
seen_name = 1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (('A' <= ch && ch <= 'Z') ||
|
|
||||||
('a' <= ch && ch <= 'z') ||
|
|
||||||
ch == '-') {
|
|
||||||
seen_head = 1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
/* no empty last line doesn't match */
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return seen_head && seen_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void append_signoff(struct strbuf *sb, int ignore_footer, unsigned flag)
|
|
||||||
{
|
|
||||||
unsigned no_dup_sob = flag & APPEND_SIGNOFF_DEDUP;
|
|
||||||
static const char signed_off_by[] = "Signed-off-by: ";
|
|
||||||
char *signoff = xstrdup(fmt_name(getenv("GIT_COMMITTER_NAME"),
|
|
||||||
getenv("GIT_COMMITTER_EMAIL")));
|
|
||||||
size_t signoff_len = strlen(signoff);
|
|
||||||
int has_signoff = 0;
|
|
||||||
char *cp;
|
|
||||||
|
|
||||||
cp = sb->buf;
|
|
||||||
|
|
||||||
/* First see if we already have the sign-off by the signer */
|
|
||||||
while ((cp = strstr(cp, signed_off_by))) {
|
|
||||||
|
|
||||||
has_signoff = 1;
|
|
||||||
|
|
||||||
cp += strlen(signed_off_by);
|
|
||||||
if (cp + signoff_len >= sb->buf + sb->len)
|
|
||||||
break;
|
|
||||||
if (strncmp(cp, signoff, signoff_len))
|
|
||||||
continue;
|
|
||||||
if (!isspace(cp[signoff_len]))
|
|
||||||
continue;
|
|
||||||
/* we already have him */
|
|
||||||
free(signoff);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!has_signoff)
|
|
||||||
has_signoff = detect_any_signoff(sb->buf, sb->len);
|
|
||||||
|
|
||||||
if (!has_signoff)
|
|
||||||
strbuf_addch(sb, '\n');
|
|
||||||
|
|
||||||
strbuf_addstr(sb, signed_off_by);
|
|
||||||
strbuf_add(sb, signoff, signoff_len);
|
|
||||||
strbuf_addch(sb, '\n');
|
|
||||||
free(signoff);
|
|
||||||
}
|
|
||||||
|
|
||||||
static unsigned int digits_in_number(unsigned int number)
|
static unsigned int digits_in_number(unsigned int number)
|
||||||
{
|
{
|
||||||
unsigned int i = 10, result = 1;
|
unsigned int i = 10, result = 1;
|
||||||
|
|
|
@ -1045,7 +1045,28 @@ EOF
|
||||||
test_cmp expected actual
|
test_cmp expected actual
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_failure 'signoff: some random signoff-alike' '
|
test_expect_success 'signoff: misc conforming footer elements' '
|
||||||
|
append_signoff <<\EOF >actual &&
|
||||||
|
subject
|
||||||
|
|
||||||
|
body
|
||||||
|
|
||||||
|
Signed-off-by: my@house
|
||||||
|
(cherry picked from commit da39a3ee5e6b4b0d3255bfef95601890afd80709)
|
||||||
|
Tested-by: Some One <someone@example.com>
|
||||||
|
Bug: 1234
|
||||||
|
EOF
|
||||||
|
cat >expected <<\EOF &&
|
||||||
|
4:Subject: [PATCH] subject
|
||||||
|
8:
|
||||||
|
10:
|
||||||
|
11:Signed-off-by: my@house
|
||||||
|
15:Signed-off-by: C O Mitter <committer@example.com>
|
||||||
|
EOF
|
||||||
|
test_cmp expected actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'signoff: some random signoff-alike' '
|
||||||
append_signoff <<\EOF >actual &&
|
append_signoff <<\EOF >actual &&
|
||||||
subject
|
subject
|
||||||
|
|
||||||
|
@ -1061,7 +1082,7 @@ EOF
|
||||||
test_cmp expected actual
|
test_cmp expected actual
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_failure 'signoff: not really a signoff' '
|
test_expect_success 'signoff: not really a signoff' '
|
||||||
append_signoff <<\EOF >actual &&
|
append_signoff <<\EOF >actual &&
|
||||||
subject
|
subject
|
||||||
|
|
||||||
|
@ -1077,7 +1098,7 @@ EOF
|
||||||
test_cmp expected actual
|
test_cmp expected actual
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_failure 'signoff: not really a signoff (2)' '
|
test_expect_success 'signoff: not really a signoff (2)' '
|
||||||
append_signoff <<\EOF >actual &&
|
append_signoff <<\EOF >actual &&
|
||||||
subject
|
subject
|
||||||
|
|
||||||
|
@ -1094,7 +1115,7 @@ EOF
|
||||||
test_cmp expected actual
|
test_cmp expected actual
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_failure 'signoff: valid S-o-b paragraph in the middle' '
|
test_expect_success 'signoff: valid S-o-b paragraph in the middle' '
|
||||||
append_signoff <<\EOF >actual &&
|
append_signoff <<\EOF >actual &&
|
||||||
subject
|
subject
|
||||||
|
|
||||||
|
@ -1162,7 +1183,7 @@ EOF
|
||||||
test_cmp expected actual
|
test_cmp expected actual
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_failure 'signoff: detect garbage in non-conforming footer' '
|
test_expect_success 'signoff: detect garbage in non-conforming footer' '
|
||||||
append_signoff <<\EOF >actual &&
|
append_signoff <<\EOF >actual &&
|
||||||
subject
|
subject
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue