record: add comparison methods for recordhunk class
authorLaurent Charignon <lcharignon@fb.com>
Fri, 13 Mar 2015 14:08:30 -0700
changeset 24346 31edcea517c1
parent 24345 01b39149ebb3
child 24347 1bcfecbbf569
record: add comparison methods for recordhunk class
mercurial/patch.py
--- a/mercurial/patch.py	Thu Mar 12 17:50:23 2015 -0700
+++ b/mercurial/patch.py	Fri Mar 13 14:08:30 2015 -0700
@@ -893,6 +893,21 @@
         self.hunk = hunk
         self.added, self.removed = self.countchanges(self.hunk)
 
+    def __eq__(self, v):
+        if not isinstance(v, recordhunk):
+            return False
+
+        return ((v.hunk == self.hunk) and
+                (v.proc == self.proc) and
+                (self.fromline == v.fromline) and
+                (self.header.files() == v.header.files()))
+
+    def __hash__(self):
+        return hash((tuple(self.hunk),
+            tuple(self.header.files()),
+            self.fromline,
+            self.proc))
+
     def countchanges(self, hunk):
         """hunk -> (n+,n-)"""
         add = len([h for h in hunk if h[0] == '+'])