convert: treat an empty string for clean/smudge filters as "cat"

Once a lower-priority configuration file defines a clean or smudge filter, there is no convenient way to override it to produce as-is output. Even though the configuration mechanism implements "the last one wins" semantics, you cannot set them to an empty string and expect them to work, as apply_filter() would try to run the empty string as an external command and fail. The conversion is not done, but the function would still report a failure to convert. Even though resetting the variable to "cat" (i.e. pass the data back as-is and report success) is an obvious and a viable way to solve this, it is wasteful to spawn an external process just as a workaround. Instead, teach apply_filter() to treat an empty string as a no-op filter that always returns successfully its input as-is without conversion. Signed-off-by: Lars Schneider <larsxschneider@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Lars Schneider committed Jan 29, 2016 at 09:21 UTC 1a8630dc3b1cc6f1361a4e5d94630133c24c97d9
2 files changed +17 -1
convert.c
+1 -1
@@ -395,7 +395,7 @@ static int apply_filter(const char *path, const char *src, size_t len, int fd,
395 struct async async;
396 struct filter_params params;
397
398 - if (!cmd)
398 + if (!cmd || !*cmd)
399 return 0;
400
401 if (!dst)
t/t0021-conversion.sh
+16
@@ -252,4 +252,20 @@ test_expect_success "filter: smudge empty file" '
252 test_cmp expected filtered-empty-in-repo
253 '
254
255 +test_expect_success 'disable filter with empty override' '
256 + test_config_global filter.disable.smudge false &&
257 + test_config_global filter.disable.clean false &&
258 + test_config filter.disable.smudge false &&
259 + test_config filter.disable.clean false &&
260 +
261 + echo "*.disable filter=disable" >.gitattributes &&
262 +
263 + echo test >test.disable &&
264 + git -c filter.disable.clean= add test.disable 2>err &&
265 + test_must_be_empty err &&
266 + rm -f test.disable &&
267 + git -c filter.disable.smudge= checkout -- test.disable 2>err &&
268 + test_must_be_empty err
269 +'
270 +
271 test_done