commit - 39807ab2985d0e296d207c49fd4ac37ce056fe89
commit + 1992b6cb3ff596207bc3efd3954cdcd13a9ab6b9
blob - ccb6cb27b7654b3404d97df966bf4f7c5e6babc6
blob + 15f5f70ed577e3817d906683deafd0bfa15d1b92
--- libexec/got-read-patch/got-read-patch.c
+++ libexec/got-read-patch/got-read-patch.c
}
static const struct got_error *
-parse_hdr(char *s, int *ok, struct got_imsg_patch_hunk *hdr)
+parse_hdr(char *s, int *done, struct got_imsg_patch_hunk *hdr)
{
static const struct got_error *err = NULL;
- *ok = 1;
if (strncmp(s, "@@ -", 4)) {
- *ok = 0;
+ *done = 1;
return NULL;
}
}
static const struct got_error *
-parse_hunk(FILE *fp, int *ok)
+parse_hunk(FILE *fp, int *done)
{
static const struct got_error *err = NULL;
struct got_imsg_patch_hunk hdr;
linelen = getline(&line, &linesize, fp);
if (linelen == -1) {
- *ok = 0;
+ *done = 1;
goto done;
}
- err = parse_hdr(line, ok, &hdr);
+ err = parse_hdr(line, done, &hdr);
if (err)
goto done;
- if (!*ok) {
+ if (*done) {
if (fseek(fp, linelen * -1, SEEK_CUR) == -1)
err = got_error_from_errno("fseek");
goto done;
/* trailing newlines may be chopped */
if (leftold < 3 && leftnew < 3) {
- *ok = 0;
+ *done = 1;
break;
}
}
while (!feof(fp)) {
- int empty = 0, ok = 1;
+ int done = 0;
- err = find_patch(&empty, fp);
+ err = find_patch(&done, fp);
if (err)
goto done;
patch_found = 1;
- for (;;) {
- if (!empty)
- err = parse_hunk(fp, &ok);
+
+ while (!done) {
+ err = parse_hunk(fp, &done);
if (err)
goto done;
- if (!ok || empty) {
- err = send_patch_done();
- if (err)
- goto done;
- break;
- }
}
+
+ err = send_patch_done();
+ if (err)
+ goto done;
}
done: