| 1247 | } |
| 1248 | |
| 1249 | int remove_signature(struct strbuf *buf) |
| 1250 | { |
| 1251 | const char *line = buf->buf; |
| 1252 | const char *tail = buf->buf + buf->len; |
| 1253 | int in_signature = 0; |
| 1254 | struct sigbuf { |
| 1255 | const char *start; |
| 1256 | const char *end; |
| 1257 | } sigs[2], *sigp = &sigs[0]; |
| 1258 | int i; |
| 1259 | const char *orig_buf = buf->buf; |
| 1260 | |
| 1261 | memset(sigs, 0, sizeof(sigs)); |
| 1262 | |
| 1263 | while (line < tail) { |
| 1264 | const char *next = memchr(line, '\n', tail - line); |
| 1265 | next = next ? next + 1 : tail; |
| 1266 | |
| 1267 | if (in_signature && line[0] == ' ') |
| 1268 | sigp->end = next; |
| 1269 | else if (starts_with(line, "gpgsig")) { |
| 1270 | int i; |
| 1271 | for (i = 1; i < GIT_HASH_NALGOS; i++) { |
| 1272 | const char *p; |
| 1273 | if (skip_prefix(line, gpg_sig_headers[i], &p) && |
| 1274 | *p == ' ') { |
| 1275 | sigp->start = line; |
| 1276 | sigp->end = next; |
| 1277 | in_signature = 1; |
| 1278 | } |
| 1279 | } |
| 1280 | } else { |
| 1281 | if (*line == '\n') |
| 1282 | /* dump the whole remainder of the buffer */ |
| 1283 | next = tail; |
| 1284 | if (in_signature && sigp - sigs != ARRAY_SIZE(sigs)) |
| 1285 | sigp++; |
| 1286 | in_signature = 0; |
| 1287 | } |
| 1288 | line = next; |
| 1289 | } |
| 1290 | |
| 1291 | for (i = ARRAY_SIZE(sigs) - 1; i >= 0; i--) |
| 1292 | if (sigs[i].start) |
| 1293 | strbuf_remove(buf, sigs[i].start - orig_buf, sigs[i].end - sigs[i].start); |
| 1294 | |
| 1295 | return sigs[0].start != NULL; |
| 1296 | } |
| 1297 | |
| 1298 | static void handle_signed_tag(const struct commit *parent, struct commit_extra_header ***tail) |
| 1299 | { |
no test coverage detected