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 <larsxschneider@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Lars Schneider committed
Jun 28, 2017 at 23:29 UTC
9364fc298a32b19fbfe545974cbf9e46d5c7e67f
1 file changed
+26
-21
convert.c
+26
-21
@@ -565,6 +565,29 @@ done:
565
return err;
566
}
567
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
+
591
static int apply_multi_file_filter(const char *path, const char *src, size_t len,
592
int fd, struct strbuf *dst, const char *cmd,
593
const unsigned int wanted_capability)
@@ -656,28 +679,10 @@ static int apply_multi_file_filter(const char *path, const char *src, size_t len
679
done:
680
sigchain_pop(SIGPIPE);
681
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
685
strbuf_swap(dst, &nbuf);
680
- }
686
strbuf_release(&nbuf);
687
return !err;
688
}