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

Laurent Charignon lcharignon at fb.com
Wed Jul 1 19:05:06 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 0116a6d16c200aff522b1cc4a9a7880497f142e6
# Parent  6a7e4701a5214f3a6143ced979896ff51b6ea331
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 use the hashing function introduced in the previous patch
to enable hashing config objects.  I checked that this code works by calling it
in commandserver to detect config file changes (with includes directives).

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 __hash__(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