grep: read -f file with strbuf_getline()
authorJunio C Hamano <gitster@pobox.com>
Wed, 28 Oct 2015 20:53:47 +0000 (13:53 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 15 Jan 2016 18:35:07 +0000 (10:35 -0800)
List of patterns file could come from a DOS editor.

This is iffy; you may actually be trying to find a line with ^M in
it on a system whose line ending is LF. You can of course work it
around by having a line that has "^M^M^J", let the strbuf_getline()
eat the last "^M^J", leaving just the single "^M" as the pattern.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/grep.c
index 5a5beb810954afcf98d27a9615f2380f7e8b06c4..801ce60e48c0c70a5c635fbd2ff156f80a5e713f 100644 (file)
@@ -562,7 +562,7 @@ static int file_callback(const struct option *opt, const char *arg, int unset)
        patterns = from_stdin ? stdin : fopen(arg, "r");
        if (!patterns)
                die_errno(_("cannot open '%s'"), arg);
        patterns = from_stdin ? stdin : fopen(arg, "r");
        if (!patterns)
                die_errno(_("cannot open '%s'"), arg);
-       while (strbuf_getline_lf(&sb, patterns) == 0) {
+       while (strbuf_getline(&sb, patterns) == 0) {
                /* ignore empty line like grep does */
                if (sb.len == 0)
                        continue;
                /* ignore empty line like grep does */
                if (sb.len == 0)
                        continue;