Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
context line printing wrong when reading from a pipe #347
Tested with both ag 0.14 and ag 0.19.2 on OS X Mountain Lion & Mavericks
It's a somewhat understandable behavior, but other related tools (grep) do this correctly.
# test setup $ for f in a b c; do echo $f; done > test.txt $ cat test.txt a b c # correct: $ ag -B1 b test.txt 1-a 2:b # correct: $ ag -C1 b test.txt 1-a 2:b 3-c # bug in -B handling: $ cat test.txt | ag -B1 b b # bug in -C handling: $ cat test.txt | ag -C1 b b :
(yes, that's a weird ":" printed at the end)
Yes, it's related & I imagine your proposal on #343 would fix this issue too. But the proposal (reading the entire stream into a buffer & then searching that as if it were a file) is overkill for both situations, with serious performance/runtime implications when searching a large stream. Issue #343 could be fixed with a simple counter, and my issue could be fixed by buffering only the requested number of previous input lines rather than the entire stream. Multi-line regexes are still a problem, though, but that's a universal truth.
(note I haven't read the ag code, so I don't know the complexity involved with these "simple fixes". But, naively, both seem like fairly minor tweaks to the state being carted around by the line-matching code.)
I can reproduce this too w/ version 0.30.0. Installed via homebrew from: https://homebrew.bintray.com/bottles/the_silver_searcher-0.30.0.yosemite.bottle.tar.gz
$ echo "A\nB\nC" > test.txt $ cat test.txt A B C
Using grep (works as expected):
Using ag (0.30.0, does not work):
Any updates on this?