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

login
register
mail settings
Submitter Laurent Charignon
Date July 7, 2015, 11:07 p.m.
Message ID <0ed3fe503fe494cd25d6.1436310459@lcharignon-mbp.local>
Download mbox | patch
Permalink /patch/9911/
State Changes Requested
Headers show

Comments

Laurent Charignon - July 7, 2015, 11:07 p.m.
# HG changeset patch
# User Laurent Charignon <lcharignon@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.

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):