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>
Brandon Casey committed
Feb 12, 2013 at 02:17 UTC
959a26231f53b9cc7da40d36c550aef193647731
2 files changed
+27
-95
log-tree.c
+1
-90
@@ -9,8 +9,7 @@
9
#include "string-list.h"
10
#include "color.h"
11
#include "gpg-interface.h"
12
-
13
-#define APPEND_SIGNOFF_DEDUP (1u <<0)
12
+#include "sequencer.h"
13
14
struct decoration name_decoration = { "object names" };
15
@@ -208,94 +207,6 @@ void show_decorations(struct rev_info *opt, struct commit *commit)
207
putchar(')');
208
}
209
211
-/*
212
- * Search for "^[-A-Za-z]+: [^@]+@" pattern. It usually matches
213
- * Signed-off-by: and Acked-by: lines.
214
- */
215
-static int detect_any_signoff(char *letter, int size)
216
-{
217
- char *cp;
218
- int seen_colon = 0;
219
- int seen_at = 0;
220
- int seen_name = 0;
221
- int seen_head = 0;
222
-
223
- cp = letter + size;
224
- while (letter <= --cp && *cp == '\n')
225
- continue;
226
-
227
- while (letter <= cp) {
228
- char ch = *cp--;
229
- if (ch == '\n')
230
- break;
231
-
232
- if (!seen_at) {
233
- if (ch == '@')
234
- seen_at = 1;
235
- continue;
236
- }
237
- if (!seen_colon) {
238
- if (ch == '@')
239
- return 0;
240
- else if (ch == ':')
241
- seen_colon = 1;
242
- else
243
- seen_name = 1;
244
- continue;
245
- }
246
- if (('A' <= ch && ch <= 'Z') ||
247
- ('a' <= ch && ch <= 'z') ||
248
- ch == '-') {
249
- seen_head = 1;
250
- continue;
251
- }
252
- /* no empty last line doesn't match */
253
- return 0;
254
- }
255
- return seen_head && seen_name;
256
-}
257
-
258
-static void append_signoff(struct strbuf *sb, int ignore_footer, unsigned flag)
259
-{
260
- unsigned no_dup_sob = flag & APPEND_SIGNOFF_DEDUP;
261
- static const char signed_off_by[] = "Signed-off-by: ";
262
- char *signoff = xstrdup(fmt_name(getenv("GIT_COMMITTER_NAME"),
263
- getenv("GIT_COMMITTER_EMAIL")));
264
- size_t signoff_len = strlen(signoff);
265
- int has_signoff = 0;
266
- char *cp;
267
-
268
- cp = sb->buf;
269
-
270
- /* First see if we already have the sign-off by the signer */
271
- while ((cp = strstr(cp, signed_off_by))) {
272
-
273
- has_signoff = 1;
274
-
275
- cp += strlen(signed_off_by);
276
- if (cp + signoff_len >= sb->buf + sb->len)
277
- break;
278
- if (strncmp(cp, signoff, signoff_len))
279
- continue;
280
- if (!isspace(cp[signoff_len]))
281
- continue;
282
- /* we already have him */
283
- free(signoff);
284
- return;
285
- }
286
-
287
- if (!has_signoff)
288
- has_signoff = detect_any_signoff(sb->buf, sb->len);
289
-
290
- if (!has_signoff)
291
- strbuf_addch(sb, '\n');
292
-
293
- strbuf_addstr(sb, signed_off_by);
294
- strbuf_add(sb, signoff, signoff_len);
295
- strbuf_addch(sb, '\n');
296
- free(signoff);
297
-}
298
-
210
static unsigned int digits_in_number(unsigned int number)
211
{
212
unsigned int i = 10, result = 1;
t/t4014-format-patch.sh
+26
-5
@@ -1045,7 +1045,28 @@ EOF
1045
test_cmp expected actual
1046
'
1047
1048
-test_expect_failure 'signoff: some random signoff-alike' '
1048
+test_expect_success 'signoff: misc conforming footer elements' '
1049
+ append_signoff <<\EOF >actual &&
1050
+subject
1051
+
1052
+body
1053
+
1054
+Signed-off-by: my@house
1055
+(cherry picked from commit da39a3ee5e6b4b0d3255bfef95601890afd80709)
1056
+Tested-by: Some One <someone@example.com>
1057
+Bug: 1234
1058
+EOF
1059
+ cat >expected <<\EOF &&
1060
+4:Subject: [PATCH] subject
1061
+8:
1062
+10:
1063
+11:Signed-off-by: my@house
1064
+15:Signed-off-by: C O Mitter <committer@example.com>
1065
+EOF
1066
+ test_cmp expected actual
1067
+'
1068
+
1069
+test_expect_success 'signoff: some random signoff-alike' '
1070
append_signoff <<\EOF >actual &&
1071
subject
1072
@@ -1061,7 +1082,7 @@ EOF
1082
test_cmp expected actual
1083
'
1084
1064
-test_expect_failure 'signoff: not really a signoff' '
1085
+test_expect_success 'signoff: not really a signoff' '
1086
append_signoff <<\EOF >actual &&
1087
subject
1088
@@ -1077,7 +1098,7 @@ EOF
1098
test_cmp expected actual
1099
'
1100
1080
-test_expect_failure 'signoff: not really a signoff (2)' '
1101
+test_expect_success 'signoff: not really a signoff (2)' '
1102
append_signoff <<\EOF >actual &&
1103
subject
1104
@@ -1094,7 +1115,7 @@ EOF
1115
test_cmp expected actual
1116
'
1117
1097
-test_expect_failure 'signoff: valid S-o-b paragraph in the middle' '
1118
+test_expect_success 'signoff: valid S-o-b paragraph in the middle' '
1119
append_signoff <<\EOF >actual &&
1120
subject
1121
@@ -1162,7 +1183,7 @@ EOF
1183
test_cmp expected actual
1184
'
1185
1165
-test_expect_failure 'signoff: detect garbage in non-conforming footer' '
1186
+test_expect_success 'signoff: detect garbage in non-conforming footer' '
1187
append_signoff <<\EOF >actual &&
1188
subject
1189