Re: [PATCH v5 2/5] commit.c/GPG signature verification: Also look at the first GPG status line
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Mar 30, 2013, 03:37 UTC
- Message-ID
- <7va9pllfr8.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <51562E5C.8020206@physik.tu-berlin.de>
Sebastian Götte <jaseg@physik.tu-berlin.de> writes:
Show 24 quoted lines
> static void parse_gpg_output(struct signature_check *sigc)
> {
> - const char *buf = sigc->gpg_status;
> int i;
>
> + /* Iterate over all search strings */
> for (i = 0; i < ARRAY_SIZE(sigcheck_gpg_status); i++) {
> + const char *found = sigc->gpg_status;
> +
> + /* Iterate over all lines */
> + do {
> + if (!prefixcmp(found, sigcheck_gpg_status[i].check)) {
> + const char *next;
> +
> + found += strlen(sigcheck_gpg_status[i].check);
> + sigc->check_result = sigcheck_gpg_status[i].result;
> + sigc->key = xmemdupz(found, 16);
> + found += 17;
> + next = strchrnul(found, '\n');
> + sigc->signer = xmemdupz(found, next - found);
> + return;
> + }
> + found = strchr(found, '\n')+1;
> + } while(found-1);Yuck. That termination condition is horrible.
Honestly speaking, I find the one I suggested the other day (which has been queued on 'pu') much nicer than this loop.
If you really really want to do a line at a time, discarding the "allow strstr() to scan over multiple lines" optimization, it is more natural to iterate over buffer one line at a time, and check for each expected output with an inner loop, perhaps like this:
const char *cp = buf;
while (*cp) {
for (i = 0; i < ARRAY_SIZE(sig_check); i++) {
if (!prefixcmp(cp, sig_check[i].check) &&
parse_gpg_status(sigc, cp, &sig_check[i]))
return;
}
cp = strchrnul(cp, '\n');
if (*cp)
cp++;
}But I do not see much point in doing so.