t/helper: stop using `the_index`
[git.git] / t / helper / test-delete-gpgsig.c
blobe36831af03f6a39414ef9e58804cfba8f11cf299
1 #include "test-tool.h"
2 #include "gpg-interface.h"
3 #include "strbuf.h"
6 int cmd__delete_gpgsig(int argc, const char **argv)
8 struct strbuf buf = STRBUF_INIT;
9 const char *pattern = "gpgsig";
10 const char *bufptr, *tail, *eol;
11 int deleting = 0;
12 size_t plen;
14 if (argc >= 2) {
15 pattern = argv[1];
16 argv++;
17 argc--;
20 plen = strlen(pattern);
21 strbuf_read(&buf, 0, 0);
23 if (!strcmp(pattern, "trailer")) {
24 size_t payload_size = parse_signed_buffer(buf.buf, buf.len);
25 fwrite(buf.buf, 1, payload_size, stdout);
26 fflush(stdout);
27 return 0;
30 bufptr = buf.buf;
31 tail = bufptr + buf.len;
33 while (bufptr < tail) {
34 /* Find the end of the line */
35 eol = memchr(bufptr, '\n', tail - bufptr);
36 if (!eol)
37 eol = tail;
39 /* Drop continuation lines */
40 if (deleting && (bufptr < eol) && (bufptr[0] == ' ')) {
41 bufptr = eol + 1;
42 continue;
44 deleting = 0;
46 /* Does the line match the prefix? */
47 if (((bufptr + plen) < eol) &&
48 !memcmp(bufptr, pattern, plen) &&
49 (bufptr[plen] == ' ')) {
50 deleting = 1;
51 bufptr = eol + 1;
52 continue;
55 /* Print all other lines */
56 fwrite(bufptr, 1, (eol - bufptr) + 1, stdout);
57 bufptr = eol + 1;
59 fflush(stdout);
61 return 0;