Bug 3885 - `hg grep --all -r REV` reports irrelevant diffs
Summary: `hg grep --all -r REV` reports irrelevant diffs
Status: RESOLVED FIXED
Alias: None
Product: Mercurial
Classification: Unclassified
Component: Mercurial (show other bugs)
Version: earlier
Hardware: PC Linux
: normal bug
Assignee: Bugzilla
URL:
Keywords:
: 5199 (view as bug list)
Depends on:
Blocks:
 
Reported: 2013-04-10 17:42 UTC by Jordi Gutiérrez Hermoso
Modified: 2018-04-07 00:00 UTC (History)
6 users (show)

See Also:
Python Version: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jordi Gutiérrez Hermoso 2013-04-10 17:42 UTC
Clone our repo:

hg clone http://hg.savannah.gnu.org/hgweb/octave

And try grepping for this:

hg grep -fn --all -r 0:tip "renderer.set_color" libinterp/interpfcn/graphics.cc

In the output, there are many irrelevant hits. For example, why is revision 14258 there? Furthermore, many are output more than once.
Comment 1 kiilerix 2013-04-10 18:45 UTC
(In reply to comment #0)
> For example, why is revision 14258 there?

Because the text was found in that revision and you asked for it with --all.

> Furthermore, many are output more than once.

That's caused by --follow which makes walkchangerevs list the same file several times in the prep callback.

I guess _that_ is the issue that is reported here.
Comment 2 Jordi Gutiérrez Hermoso 2013-04-11 09:14 UTC
(In reply to comment #1)

>> For example, why is revision 14258 there?

> Because the text was found in that revision and you asked for it with --all.

What does it mean for the text to be found in a revision? I was expecting this to produce an output:

hg diff -c 14258 | grep renderer.set_color

but it doesn't. I really can't understand from the help what "a change in match status" means. What does it mean when a non-match becomes a match? I was expecting it meant that it would appear in a "+" line in the unified diff.

At the very least, the help text ought to be rewritten.
Comment 3 Jordi Gutiérrez Hermoso 2013-10-07 16:59 UTC
To be a bit more explicit, this is the output that I get:

$ hg grep -fn --all -r 0:tip "renderer.set_color" libinterp/corefcn/graphics.cc
src/graphics.cc:11455:5086:+:  renderer.set_color (get_color_rgb ());
src/graphics.cc:11455:5086:+:  renderer.set_color (get_color_rgb ());
src/graphics.cc:11456:5086:+:  renderer.set_color (get_color_rgb ());
src/graphics.cc:11456:5086:+:  renderer.set_color (get_color_rgb ());
src/graphics.cc:12348:5640:+:  renderer.set_color (get_color_rgb ());
src/graphics.cc:12348:5640:+:  renderer.set_color (get_color_rgb ());
src/graphics.cc:12441:5833:+:  renderer.set_color (get_color_rgb ());
src/graphics.cc:12441:5833:+:  renderer.set_color (get_color_rgb ());
src/graphics.cc:13109:5878:+:  renderer.set_color (get_color_rgb ());
src/graphics.cc:13109:5878:+:  renderer.set_color (get_color_rgb ());
src/graphics.cc:13211:6118:+:  renderer.set_color (get_color_rgb ());
src/graphics.cc:13211:6118:+:  renderer.set_color (get_color_rgb ());
src/graphics.cc:13324:6397:+:  renderer.set_color (get_color_rgb ());
src/graphics.cc:13324:6397:+:  renderer.set_color (get_color_rgb ());
src/graphics.cc:13757:6509:+:  renderer.set_color (get_color_rgb ());
src/graphics.cc:13757:6509:+:  renderer.set_color (get_color_rgb ());
src/graphics.cc:13897:6605:+:  renderer.set_color (get_color_rgb ());
src/graphics.cc:13897:6605:+:  renderer.set_color (get_color_rgb ());
src/graphics.cc:13925:6624:+:  renderer.set_color (get_color_rgb ());
src/graphics.cc:13925:6624:+:  renderer.set_color (get_color_rgb ());
src/graphics.cc:14022:6608:+:  renderer.set_color (get_color_rgb ());
src/graphics.cc:14022:6608:+:  renderer.set_color (get_color_rgb ());
src/graphics.cc:14258:6747:+:  renderer.set_color (get_color_rgb ());
src/graphics.cc:14312:6658:+:  renderer.set_color (get_color_rgb ());
src/graphics.cc:14312:6658:+:  renderer.set_color (get_color_rgb ());
src/graphics.cc:14314:6878:+:  renderer.set_color (get_color_rgb ());
src/graphics.cc:14322:6661:+:  renderer.set_color (get_color_rgb ());
src/graphics.cc:14322:6661:+:  renderer.set_color (get_color_rgb ());
src/graphics.cc:14323:6881:+:  renderer.set_color (get_color_rgb ());
src/graphics.cc:14324:6878:+:  renderer.set_color (get_color_rgb ());
src/graphics.cc:14325:6669:+:  renderer.set_color (get_color_rgb ());
src/graphics.cc:14325:6669:+:  renderer.set_color (get_color_rgb ());
src/graphics.cc:14326:6878:+:  renderer.set_color (get_color_rgb ());
src/interpfcn/graphics.cc:15088:6970:+:  renderer.set_color (get_color_rgb ());
libinterp/interpfcn/graphics.cc:15195:6970:+:  renderer.set_color (get_color_rgb ());
libinterp/interpfcn/graphics.cc:15467:6971:+:  renderer.set_color (get_color_rgb ());
libinterp/interpfcn/graphics.cc:16206:7009:+:  renderer.set_color (get_color_rgb ());
libinterp/interpfcn/graphics.cc:16832:7157:+:  renderer.set_color (get_color_rgb ());
libinterp/interpfcn/graphics.cc:16841:7153:+:  renderer.set_color (get_color_rgb ());
libinterp/interpfcn/graphics.cc:16855:7155:+:  renderer.set_color (get_color_rgb ());
libinterp/corefcn/graphics.cc:16892:7155:+:  renderer.set_color (get_color_rgb ());
libinterp/corefcn/graphics.cc:17223:7093:+:  renderer.set_color (get_color_rgb ());
$ hg diff -c 14258 | grep renderer

I don't understand why understand why that revision, 14258 is being
output, since there is no change in the match status of that string
I'm grepping for.
Comment 4 Bugzilla 2015-02-22 01:00 UTC
Bug was inactive for 502 days, archiving
Comment 5 Pierre-Yves David 2015-03-31 14:05 UTC
This is happening because `hg grep --all` is using raw revlog delta without checking if they apply againts the proper parent.

For the improperly reported revision, the index says:

  323    177479    1242    322   14257 3bc861f30a42 a17784245864 000000000000
  324    178721    1183    323   14258 fe80cdb7b84d 3bc861f30a42 000000000000

While the log says:

  changeset:   14258:08779abcb640
  user:        Rik <octave@nomad.inbox5.com>
  date:        Tue Jan 24 08:53:42 2012 -0800
  summary:     maint: Style fixes for 5cc69bafe3b9

  changeset:   14257:5cc69bafe3b9
  parent:      14254:73086d4b64fa
  user:        Ben Abbott  <bpabbott@mac.com>
  date:        Tue Jan 24 08:29:33 2012 -0500
  summary:     Add updating for figure paperorientation property. Bug # 35329.
Comment 6 Bugzilla 2015-10-18 16:24 UTC
Bug was inactive for 198 days, archiving
Comment 7 Pierre-Yves David 2015-11-06 20:03 UTC
still a thing
Comment 8 Bugzilla 2016-04-06 00:00 UTC
Bug was inactive for 151 days, archiving
Comment 9 Jordi Gutiérrez Hermoso 2016-04-06 20:19 UTC
I'll get around to working on this, I promise. Maybe this weekend.
Comment 10 Jordi Gutiérrez Hermoso 2016-04-13 08:19 UTC
*** Bug 5199 has been marked as a duplicate of this bug. ***
Comment 11 Jordi Gutiérrez Hermoso 2016-05-22 19:42 UTC
The key part about this bug is that adding a revset to `hg grep --all` will result in a different order of traversal. Since `hg grep` expects a reverse revlog order when it calls `walkchangerevs`, things get messed up. The `matches` and `revfiles` caches get filled with junk which normally would get cleaned up properly in reverse revlog order. I have not yet managed to figure out what they should contain instead, or if `walkchangerevs` is even desirable when the revisions are searched in revlog order instead of reverse revlog order.
Comment 12 Bugzilla 2017-02-04 00:00 UTC
Bug was inactive for 257 days, archiving
Comment 13 Bugzilla 2017-07-05 00:00 UTC
Bug was inactive for 151 days, archiving
Comment 14 HG Bot 2018-03-30 12:31 UTC
Fixed by https://mercurial-scm.org/repo/hg/rev/a2a6755a3def
Sangeet Kumar Mishra <mail2sangeetmishra@gmail.com>
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.

(please test the fix)
Comment 15 Bugzilla 2018-04-07 00:00 UTC
Bug was set to TESTING for 7 days, resolving