# HG changeset patch # User Pierre-Yves David # Date 1490157879 -3600 # Node ID 90f8f100dd58fe4cd0fc8d7041b95bf8ee88c661 # Parent f80fa478e28928ec39cdd3b06be7b68fb7d9f017 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. diff -r f80fa478e289 -r 90f8f100dd58 hgext3rd/evolve/obsdiscovery.py --- a/hgext3rd/evolve/obsdiscovery.py Wed Mar 22 05:36:45 2017 +0100 +++ b/hgext3rd/evolve/obsdiscovery.py Wed Mar 22 05:44:39 2017 +0100 @@ -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): diff -r f80fa478e289 -r 90f8f100dd58 hgext3rd/evolve/stablerange.py --- a/hgext3rd/evolve/stablerange.py Wed Mar 22 05:36:45 2017 +0100 +++ b/hgext3rd/evolve/stablerange.py Wed Mar 22 05:44:39 2017 +0100 @@ -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):