[PATCH 2 of 3 V2] config: add hashing method for config object

Laurent Charignon lcharignon at fb.com
Mon Jul 6 13:42:41 CDT 2015

# HG changeset patch
# User Laurent Charignon <lcharignon at fb.com>
# Date 1435794533 25200
#      Wed Jul 01 16:48:53 2015 -0700
# Node ID 19d4a2676ee71fc8f30731ebd32cb544b28663ca
# Parent  38cd2c6265855f0a8e65e02e2cc181921df498ca
config: add hashing method for config object

The goal of this series of patches is to have a method to compute the hash of
config objects. This will enable restarting the command server when the config
change. This patch uses the hashing function introduced in the previous patch
to enable hashing config objects.

We don't just create the __hash__ method but create a separate method, to be
able to tell from the commandserver if this feature is available. This is
to ensure backward compatibility of the command server with previous versions
of mercurial. If we didn't do that, the __hash__ function would return the
id of the config object that could change and the command server would have
to restart for every single command even if the config does not change.

diff --git a/mercurial/config.py b/mercurial/config.py
--- a/mercurial/config.py
+++ b/mercurial/config.py
@@ -21,6 +21,11 @@ class config(object):
             self._source = data._source.copy()
     def copy(self):
         return config(self)
+    def computehash(self):
+        return util.makehash((self._data.items(),
+                              self._source.items(),
+                              self._unset,
+                              self._includepaths))
     def __contains__(self, section):
         return section in self._data
     def __getitem__(self, section):

More information about the Mercurial-devel mailing list