[PATCH 4 of 4 V3] config: add a __eq__ and __ne__ method for config object

Laurent Charignon lcharignon at fb.com
Tue Jul 7 18:07:39 CDT 2015


# HG changeset patch
# User Laurent Charignon <lcharignon at fb.com>
# Date 1436309290 25200
#      Tue Jul 07 15:48:10 2015 -0700
# Node ID 0ed3fe503fe494cd25d682f9e9ca72b4d3fc76a6
# Parent  a6918b3efa1a7b593867ba43901ffd2e4d6f3f79
config: add a __eq__ and __ne__ method for config object

They can be used to compare config objects later and it makes sense to introduce
them since we added a __hash__ method in a previous patch.

diff --git a/mercurial/config.py b/mercurial/config.py
--- a/mercurial/config.py
+++ b/mercurial/config.py
@@ -30,6 +30,15 @@ class config(object):
         return section in self._data
     def __getitem__(self, section):
         return self._data.get(section, {})
+    def __eq__(self, other):
+        return (isinstance(other, config) and
+                # Data and source are sortdict
+                other._data.items() == self._data.items() and
+                other._source.items() == self._source.items() and
+                other._unset == self._unset and
+                other._includepaths == self._includepaths)
+    def __ne__(self, other):
+        return not self == other
     def __hash__(self):
         return self.computehash()
     def __iter__(self):


More information about the Mercurial-devel mailing list