Mercurial > hg-stable
changeset 45441:e47385ef4e17
grep: fix hash(linestate) to not include linenum
linestate.__eq__() just compares the line values whereas __hash__() does
hash both self.line and self.linenum, which violates the rule. __hash__()
was added at fb502719c75c, "python 2.6 compatibility: add __hash__ to
classes that have __eq__" with no additional remarks, so this would probably
be a simple mistake.
The test output changed because difflib.SequenceMatcher() internally uses
a dict. As you can see, the line "export" is unchanged at the revision 2,
so the new output is correct.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Wed, 09 Sep 2020 11:41:18 +0900 |
parents | 9c8d2cf7f591 |
children | 7a57ced7de87 |
files | mercurial/commands.py tests/test-grep.t |
diffstat | 2 files changed, 50 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/commands.py Tue Sep 08 21:38:10 2020 +0900 +++ b/mercurial/commands.py Wed Sep 09 11:41:18 2020 +0900 @@ -3400,7 +3400,7 @@ self.colend = colend def __hash__(self): - return hash((self.linenum, self.line)) + return hash(self.line) def __eq__(self, other): return self.line == other.line
--- a/tests/test-grep.t Tue Sep 08 21:38:10 2020 +0900 +++ b/tests/test-grep.t Wed Sep 09 11:41:18 2020 +0900 @@ -321,14 +321,61 @@ } ] +diff of each revision for reference + + $ hg log -p -T'== rev: {rev} ==\n' + == rev: 4 == + diff -r 95040cfd017d -r 914fa752cdea port + --- a/port Thu Jan 01 00:00:03 1970 +0000 + +++ b/port Thu Jan 01 00:00:04 1970 +0000 + @@ -1,4 +1,3 @@ + export + vaportight + import/export + -import/export + + == rev: 3 == + diff -r 3b325e3481a1 -r 95040cfd017d port + --- a/port Thu Jan 01 00:00:02 1970 +0000 + +++ b/port Thu Jan 01 00:00:03 1970 +0000 + @@ -1,3 +1,4 @@ + export + vaportight + import/export + +import/export + + == rev: 2 == + diff -r 8b20f75c1585 -r 3b325e3481a1 port + --- a/port Thu Jan 01 00:00:01 1970 +0000 + +++ b/port Thu Jan 01 00:00:02 1970 +0000 + @@ -1,2 +1,3 @@ + -import + export + +vaportight + +import/export + + == rev: 1 == + diff -r f31323c92170 -r 8b20f75c1585 port + --- a/port Thu Jan 01 00:00:00 1970 +0000 + +++ b/port Thu Jan 01 00:00:01 1970 +0000 + @@ -1,1 +1,2 @@ + import + +export + + == rev: 0 == + diff -r 000000000000 -r f31323c92170 port + --- /dev/null Thu Jan 01 00:00:00 1970 +0000 + +++ b/port Thu Jan 01 00:00:00 1970 +0000 + @@ -0,0 +1,1 @@ + +import + + all $ hg grep --traceback --all -nu port port port:4:4:-:spam:import/export port:3:4:+:eggs:import/export port:2:1:-:spam:import - port:2:2:-:spam:export - port:2:1:+:spam:export port:2:2:+:spam:vaportight port:2:3:+:spam:import/export port:1:2:+:eggs:export @@ -369,26 +416,6 @@ "user": "spam" }, { - "change": "-", - "date": [2, 0], - "lineno": 2, - "node": "3b325e3481a1f07435d81dfdbfa434d9a0245b47", - "path": "port", - "rev": 2, - "texts": [{"matched": false, "text": "ex"}, {"matched": true, "text": "port"}], - "user": "spam" - }, - { - "change": "+", - "date": [2, 0], - "lineno": 1, - "node": "3b325e3481a1f07435d81dfdbfa434d9a0245b47", - "path": "port", - "rev": 2, - "texts": [{"matched": false, "text": "ex"}, {"matched": true, "text": "port"}], - "user": "spam" - }, - { "change": "+", "date": [2, 0], "lineno": 2, @@ -460,8 +487,6 @@ port:4:4:-:spam:import/export port:3:4:+:eggs:import/export port:2:1:-:spam:import - port:2:2:-:spam:export - port:2:1:+:spam:export port:2:2:+:spam:vaportight port:2:3:+:spam:import/export port:1:2:+:eggs:export