Skip to content

Commit 9364fc2

Browse files
larsxschneidergitster
authored andcommitted
convert: move multiple file filter error handling to separate function
Refactoring the filter error handling is useful for the subsequent patch 'convert: add "status=delayed" to filter process protocol'. In addition, replace the parentheses around the empty "if" block with a single semicolon to adhere to the Git style guide. Signed-off-by: Lars Schneider <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 42b0a86 commit 9364fc2

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

convert.c

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,29 @@ static int start_multi_file_filter_fn(struct subprocess_entry *subprocess)
565565
return err;
566566
}
567567

568+
static void handle_filter_error(const struct strbuf *filter_status,
569+
struct cmd2process *entry,
570+
const unsigned int wanted_capability) {
571+
if (!strcmp(filter_status->buf, "error"))
572+
; /* The filter signaled a problem with the file. */
573+
else if (!strcmp(filter_status->buf, "abort") && wanted_capability) {
574+
/*
575+
* The filter signaled a permanent problem. Don't try to filter
576+
* files with the same command for the lifetime of the current
577+
* Git process.
578+
*/
579+
entry->supported_capabilities &= ~wanted_capability;
580+
} else {
581+
/*
582+
* Something went wrong with the protocol filter.
583+
* Force shutdown and restart if another blob requires filtering.
584+
*/
585+
error("external filter '%s' failed", entry->subprocess.cmd);
586+
subprocess_stop(&subprocess_map, &entry->subprocess);
587+
free(entry);
588+
}
589+
}
590+
568591
static int apply_multi_file_filter(const char *path, const char *src, size_t len,
569592
int fd, struct strbuf *dst, const char *cmd,
570593
const unsigned int wanted_capability)
@@ -656,28 +679,10 @@ static int apply_multi_file_filter(const char *path, const char *src, size_t len
656679
done:
657680
sigchain_pop(SIGPIPE);
658681

659-
if (err) {
660-
if (!strcmp(filter_status.buf, "error")) {
661-
/* The filter signaled a problem with the file. */
662-
} else if (!strcmp(filter_status.buf, "abort")) {
663-
/*
664-
* The filter signaled a permanent problem. Don't try to filter
665-
* files with the same command for the lifetime of the current
666-
* Git process.
667-
*/
668-
entry->supported_capabilities &= ~wanted_capability;
669-
} else {
670-
/*
671-
* Something went wrong with the protocol filter.
672-
* Force shutdown and restart if another blob requires filtering.
673-
*/
674-
error("external filter '%s' failed", cmd);
675-
subprocess_stop(&subprocess_map, &entry->subprocess);
676-
free(entry);
677-
}
678-
} else {
682+
if (err)
683+
handle_filter_error(&filter_status, entry, wanted_capability);
684+
else
679685
strbuf_swap(dst, &nbuf);
680-
}
681686
strbuf_release(&nbuf);
682687
return !err;
683688
}

0 commit comments

Comments
 (0)