Skip to content

Commit 1a8630d

Browse files
larsxschneidergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1b0b6dd commit 1a8630d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

‎convert.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ static int apply_filter(const char *path, const char *src, size_t len, int fd,
395395
struct async async;
396396
struct filter_params params;
397397

398-
if (!cmd)
398+
if (!cmd || !*cmd)
399399
return 0;
400400

401401
if (!dst)

‎t/t0021-conversion.sh‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,4 +252,20 @@ test_expect_success "filter: smudge empty file" '
252252
test_cmp expected filtered-empty-in-repo
253253
'
254254

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+
255271
test_done

0 commit comments

Comments
 (0)