# HG changeset patch # User Sangeet Kumar Mishra # Date 2018-03-27 14:51:30 # Node ID a2a6755a3defe471113eb9b259dcd8fd5f20566c # Parent a54113fcc8c9ce2cc59a463ddd3f0ddce3549521 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. diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -2590,8 +2590,11 @@ def grep(ui, repo, pattern, *pats, **opt 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 diff --git a/tests/test-grep.t b/tests/test-grep.t --- a/tests/test-grep.t +++ b/tests/test-grep.t @@ -330,6 +330,17 @@ of just using revision numbers. 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