Mercurial > hg-stable
changeset 37136:a2a6755a3def
grep: fixes erroneous output of grep in forward order (issue3885)
If grep is passed a revset in forwards order via -r , say -r 0:tip
Then the output is erroneous. This patch fixes that. The output was wrong
because we deleted the last revision key in the matches and when we moved
to the next revision we didn't had this to compare the diff. So the pstates
dict was always empty and in the SequenceMatcher, to convert and empty pstate
to the states dictionary you would always insert. This patch keeps the matches
dictionary until the end of this window and clears it at once when this
window ends. This solves the above mentioned problem and also do not cause
any memory leak.
author | Sangeet Kumar Mishra <mail2sangeetmishra@gmail.com> |
---|---|
date | Tue, 27 Mar 2018 20:21:30 +0530 |
parents | a54113fcc8c9 |
children | 6890b7e991a4 |
files | mercurial/commands.py tests/test-grep.t |
diffstat | 2 files changed, 15 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/commands.py Mon Mar 26 23:02:50 2018 -0400 +++ b/mercurial/commands.py Tue Mar 27 20:21:30 2018 +0530 @@ -2590,8 +2590,11 @@ skip[fn] = True if copy: skip[copy] = True - del matches[rev] del revfiles[rev] + # We will keep the matches dict for the duration of the window + # clear the matches dict once the window is over + if not revfiles: + matches.clear() fm.end() return not found
--- a/tests/test-grep.t Mon Mar 26 23:02:50 2018 -0400 +++ b/tests/test-grep.t Tue Mar 27 20:21:30 2018 +0530 @@ -330,6 +330,17 @@ color:3:-:red color:1:+:red +Issue3885: test that changing revision order does not alter the +revisions printed, just their order. + + $ hg grep --all red -r "all()" + color:1:+:red + color:3:-:red + + $ hg grep --all red -r "reverse(all())" + color:3:-:red + color:1:+:red + $ cd .. $ hg init a