Patchwork [6,of,6] record: add comparison methods for recordhunk class

login
register
mail settings
Submitter Laurent Charignon
Date March 13, 2015, 9:21 p.m.
Message ID <897ab5f050bae8a33fa9.1426281717@dev919.prn2.facebook.com>
Download mbox | patch
Permalink /patch/8067/
State Accepted
Headers show

Comments

Laurent Charignon - March 13, 2015, 9:21 p.m.
# HG changeset patch
# User Laurent Charignon <lcharignon@fb.com>
# Date 1426280910 25200
#      Fri Mar 13 14:08:30 2015 -0700
# Node ID 897ab5f050bae8a33fa9a732db697f93ee03f330
# Parent  c5650ec7e9b12e14b7d9be5b0997f0712e17016e
record: add comparison methods for recordhunk class
Pierre-Yves David - March 13, 2015, 10:46 p.m.
On 03/13/2015 02:21 PM, Laurent Charignon wrote:
> # HG changeset patch
> # User Laurent Charignon <lcharignon@fb.com>
> # Date 1426280910 25200
> #      Fri Mar 13 14:08:30 2015 -0700
> # Node ID 897ab5f050bae8a33fa9a732db697f93ee03f330
> # Parent  c5650ec7e9b12e14b7d9be5b0997f0712e17016e
> record: add comparison methods for recordhunk class

I've pushed these 6 to the clowncopter after minor fixing.

> diff --git a/mercurial/patch.py b/mercurial/patch.py
> --- a/mercurial/patch.py
> +++ b/mercurial/patch.py
> @@ -884,6 +884,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] == '+'])
> @@ -1076,6 +1091,7 @@
>               else:
>                   self.read_unified_hunk(lr)
>
> +

sneaky new line (dropped locally)

Patch

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -884,6 +884,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] == '+'])
@@ -1076,6 +1091,7 @@ 
             else:
                 self.read_unified_hunk(lr)
 
+
     def getnormalized(self):
         """Return a copy with line endings normalized to LF."""