[PATCH 16/17] grep: read -f file with strbuf_gets()
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Oct 28, 2015, 22:26 UTC
- Message-ID
- <1446071161-15610-17-git-send-email-gitster@pobox.com>
- In-Reply-To
- <1446071161-15610-1-git-send-email-gitster@pobox.com>
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_gets() 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/builtin/grep.c b/builtin/grep.c index d04f440..ac27690 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -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); - while (strbuf_getline(&sb, patterns, '\n') == 0) { + while (strbuf_gets(&sb, patterns) == 0) { /* ignore empty line like grep does */ if (sb.len == 0) continue;
-- 2.6.2-423-g5314b62