changeset 2236:90f8f100dd58

obshashrange: extract computation back into the discovery module This obshash is related to discovery and it seems more appropriate to have to live there. This remove the last large piece of logic from the class. We'll now be able to slowly turn it into a tuple.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Wed, 22 Mar 2017 05:44:39 +0100
parents f80fa478e289
children 647e222cd4ab
files hgext3rd/evolve/obsdiscovery.py hgext3rd/evolve/stablerange.py
diffstat 2 files changed, 30 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/evolve/obsdiscovery.py
+++ b/hgext3rd/evolve/obsdiscovery.py
@@ -406,7 +406,36 @@
 
 def _obshashrange(repo, rangeid):
     """return the obsolete hash associated to a range"""
-    return rangeid.obshash
+    cache = repo.obsstore.rangeobshashcache
+    obshash = cache.get(rangeid)
+    if obshash is not None:
+        return obshash
+    pieces = []
+    nullid = node.nullid
+    if len(rangeid) == 1:
+        tmarkers = repo.obsstore.relevantmarkers([rangeid.node])
+        pieces = []
+        for m in tmarkers:
+            mbin = obsolete._fm1encodeonemarker(m)
+            pieces.append(mbin)
+        pieces.sort()
+    else:
+        for subrange in rangeid.subranges():
+            obshash = _obshashrange(repo, subrange)
+            if obshash != nullid:
+                pieces.append(obshash)
+
+    sha = hashlib.sha1()
+    # note: if there is only one subrange with actual data, we'll just
+    # reuse the same hash.
+    if not pieces:
+        obshash = node.nullid
+    elif len(pieces) != 1 or obshash is None:
+        sha = hashlib.sha1()
+        for p in pieces:
+            sha.update(p)
+        obshash = cache[rangeid] = sha.digest()
+    return obshash
 
 @eh.wrapfunction(obsolete.obsstore, '_addmarkers')
 def _addmarkers(orig, obsstore, *args, **kwargs):
--- a/hgext3rd/evolve/stablerange.py
+++ b/hgext3rd/evolve/stablerange.py
@@ -9,7 +9,6 @@
 
 import collections
 import math
-import hashlib
 
 from mercurial import (
     commands,
@@ -24,7 +23,6 @@
 
 from . import (
     exthelper,
-    obsolete,
 )
 
 eh = exthelper.exthelper()
@@ -387,39 +385,6 @@
     def subranges(self):
         return self._repo.stablerange.subranges(self._repo, self)
 
-    @util.propertycache
-    def obshash(self):
-        cache = self._repo.obsstore.rangeobshashcache
-        obshash = cache.get(self)
-        if obshash is not None:
-            return obshash
-        pieces = []
-        nullid = nodemod.nullid
-        if len(self) == 1:
-            tmarkers = self._repo.obsstore.relevantmarkers([self.node])
-            pieces = []
-            for m in tmarkers:
-                mbin = obsolete._fm1encodeonemarker(m)
-                pieces.append(mbin)
-            pieces.sort()
-        else:
-            for subrange in self.subranges():
-                obshash = subrange.obshash
-                if obshash != nullid:
-                    pieces.append(obshash)
-
-        sha = hashlib.sha1()
-        # note: if there is only one subrange with actual data, we'll just
-        # reuse the same hash.
-        if not pieces:
-            obshash = nodemod.nullid
-        elif len(pieces) != 1 or obshash is None:
-            sha = hashlib.sha1()
-            for p in pieces:
-                sha.update(p)
-            obshash = cache[self] = sha.digest()
-        return obshash
-
 @eh.reposetup
 def setupcache(ui, repo):