convert: make apply_filter() adhere to standard Git error handling
apply_filter() returns a boolean that tells the caller if it "did convert or did not convert". The variable `ret` was used throughout the function to track errors whereas `1` denoted success and `0` failure. This is unusual for the Git source where `0` denotes success. Rename the variable and flip its value to make the function easier readable for Git developers. Signed-off-by: Lars Schneider <larsxschneider@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Lars Schneider committed
Oct 16, 2016 at 16:20 UTC
b84be553548b6d493d6eff728f3e11b5b5f9a254
1 file changed
+6
-9
convert.c
+6
-9
@@ -451,7 +451,7 @@ static int apply_filter(const char *path, const char *src, size_t len, int fd,
451
*
452
* (child --> cmd) --> us
453
*/
454
- int ret = 1;
454
+ int err = 0;
455
struct strbuf nbuf = STRBUF_INIT;
456
struct async async;
457
struct filter_params params;
@@ -477,23 +477,20 @@ static int apply_filter(const char *path, const char *src, size_t len, int fd,
477
return 0; /* error was already reported */
478
479
if (strbuf_read(&nbuf, async.out, len) < 0) {
480
- error("read from external filter '%s' failed", cmd);
481
- ret = 0;
480
+ err = error("read from external filter '%s' failed", cmd);
481
}
482
if (close(async.out)) {
484
- error("read from external filter '%s' failed", cmd);
485
- ret = 0;
483
+ err = error("read from external filter '%s' failed", cmd);
484
}
485
if (finish_async(&async)) {
488
- error("external filter '%s' failed", cmd);
489
- ret = 0;
486
+ err = error("external filter '%s' failed", cmd);
487
}
488
492
- if (ret) {
489
+ if (!err) {
490
strbuf_swap(dst, &nbuf);
491
}
492
strbuf_release(&nbuf);
496
- return ret;
493
+ return !err;
494
}
495
496
static struct convert_driver {