@matheusbsbs / matheus-bagliano / commits / 64fcec78b5
Fork 0

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 <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed May 22, 2010 at 23:28 UTC 64fcec78b5c52a054eab482e91d58f7b41d1dfaf
1 file changed +11 -9
grep.c
+11 -9
@@ -800,17 +800,19 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,
800 opt->show_hunk_mark = 1;
801 opt->last_shown = 0;
802
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))
806 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))
810 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");
816 }
817
818 memset(&xecfg, 0, sizeof(xecfg));