Patchwork [3,of,3,stable] obsolete: add __eq__ and __hash__ to marker to make set() deduplication work

login
register
mail settings
Submitter Pierre-Yves David
Date Nov. 17, 2013, 1:45 a.m.
Message ID <94fa59f68e5a796f5d74.1384652712@vulgaris>
Download mbox | patch
Permalink /patch/3007/
State Accepted
Commit 3485d14ec69a82737d05bb1a387dd9c7501312fc
Headers show

Comments

Pierre-Yves David - Nov. 17, 2013, 1:45 a.m.
# HG changeset patch
# User Augie Fackler <raf@durin42.com>
# Date 1384650722 18000
#      Sat Nov 16 20:12:02 2013 -0500
# Branch stable
# Node ID 94fa59f68e5a796f5d74c57097ca6af8c866efa9
# Parent  913ccfc2f66abe0b937caa40a64a5ea21d53f763
obsolete: add __eq__ and __hash__ to marker to make set() deduplication work
Augie Fackler - Nov. 17, 2013, 4 p.m.
queued these with english tweaks in 2 of 3, thanks

On Nov 16, 2013, at 8:45 PM, pierre-yves.david@ens-lyon.org wrote:

> # HG changeset patch
> # User Augie Fackler <raf@durin42.com>
> # Date 1384650722 18000
> #      Sat Nov 16 20:12:02 2013 -0500
> # Branch stable
> # Node ID 94fa59f68e5a796f5d74c57097ca6af8c866efa9
> # Parent  913ccfc2f66abe0b937caa40a64a5ea21d53f763
> obsolete: add __eq__ and __hash__ to marker to make set() deduplication work
> 
> diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py
> --- a/mercurial/obsolete.py
> +++ b/mercurial/obsolete.py
> @@ -194,10 +194,18 @@ class marker(object):
>         # the repo argument will be used to create changectx in later version
>         self._repo = repo
>         self._data = data
>         self._decodedmeta = None
> 
> +    def __hash__(self):
> +        return hash(self._data)
> +
> +    def __eq__(self, other):
> +        if type(other) != type(self):
> +            return False
> +        return self._data == other._data
> +
>     def precnode(self):
>         """Precursor changeset node identifier"""
>         return self._data[0]
> 
>     def succnodes(self):

Patch

diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py
--- a/mercurial/obsolete.py
+++ b/mercurial/obsolete.py
@@ -194,10 +194,18 @@  class marker(object):
         # the repo argument will be used to create changectx in later version
         self._repo = repo
         self._data = data
         self._decodedmeta = None
 
+    def __hash__(self):
+        return hash(self._data)
+
+    def __eq__(self, other):
+        if type(other) != type(self):
+            return False
+        return self._data == other._data
+
     def precnode(self):
         """Precursor changeset node identifier"""
         return self._data[0]
 
     def succnodes(self):