changeset 24346:31edcea517c1

record: add comparison methods for recordhunk class
author Laurent Charignon <lcharignon@fb.com>
date Fri, 13 Mar 2015 14:08:30 -0700
parents 01b39149ebb3
children 1bcfecbbf569
files mercurial/patch.py
diffstat 1 files changed, 15 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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] == '+'])