Skip to content

Commit 64fcec7

Browse files
René Scharfegitster
authored andcommitted
grep: grep: refactor handling of binary mode options
Turn the switch inside-out and add labels for each possible value of ->binary. This makes the code easier to read and avoids calling buffer_is_binary() if the option -a was given. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aca20dd commit 64fcec7

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

grep.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -800,17 +800,19 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,
800800
opt->show_hunk_mark = 1;
801801
opt->last_shown = 0;
802802

803-
if (buffer_is_binary(buf, size)) {
804-
switch (opt->binary) {
805-
case GREP_BINARY_DEFAULT:
803+
switch (opt->binary) {
804+
case GREP_BINARY_DEFAULT:
805+
if (buffer_is_binary(buf, size))
806806
binary_match_only = 1;
807-
break;
808-
case GREP_BINARY_NOMATCH:
807+
break;
808+
case GREP_BINARY_NOMATCH:
809+
if (buffer_is_binary(buf, size))
809810
return 0; /* Assume unmatch */
810-
break;
811-
default:
812-
break;
813-
}
811+
break;
812+
case GREP_BINARY_TEXT:
813+
break;
814+
default:
815+
die("bug: unknown binary handling mode");
814816
}
815817

816818
memset(&xecfg, 0, sizeof(xecfg));

0 commit comments

Comments
 (0)