From: Neil Brown Date: Thu, 5 Mar 2009 05:59:14 +0000 (+1100) Subject: Improve parsing of diff -u output. X-Git-Tag: v0.7~7 X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=1967b8e3b3da0b9bae39e03b4309b487edcb6310;p=wiggle.git Improve parsing of diff -u output. Normally chunks start @@ -%d,%d +%d%d @@ but if a section is just one line long, the ',1' is dropped, so @@ -%d +%d @@ is possible. --- diff --git a/extract.c b/extract.c index 755a725..f901617 100644 --- a/extract.c +++ b/extract.c @@ -67,6 +67,7 @@ int split_patch(struct stream f, struct stream *f1, struct stream *f2) int acnt=0, bcnt=0; int a,b,c,d; int lineno = 0; + char before[100], after[100]; f1->body = f2->body = NULL; @@ -89,10 +90,25 @@ int split_patch(struct stream f, struct stream *f1, struct stream *f2) lineno++; switch(state) { case 0: - if (sscanf(cp, "@@ -%d,%d +%d,%d @@", &a, &b, &c, &d)==4) { - acnt = b; - bcnt = d; - state = 3; + if (sscanf(cp, "@@ -%s +%s @@", before, after)==2) { + int ok = 1; + if (sscanf(before, "%d,%d", &a, &b) == 2) + acnt = b; + else if (sscanf(before, "%d", &a) == 1) + acnt = 1; + else + ok = 0; + + if (sscanf(after, "%d,%d", &c, &d) == 2) + bcnt = d; + else if (sscanf(after, "%d", &c) == 1) + bcnt = 1; + else + ok = 0; + if (ok) + state = 3; + else + state = 0; } else if (sscanf(cp, "*** %d,%d ****", &a, &b)==2) { acnt = b-a+1; state = 1;