# HG changeset patch # User Anton Shestakov # Date 1573627675 -25200 # Node ID e8302f760a547e2c71af006103f4f940ab8dd6e7 # Parent 0fe5d74134d6b2889187439039cb6f6d65da3057 compat: compatibility for cl.nodemap.get vs cl.index.get_rev diff -r 0fe5d74134d6 -r e8302f760a54 hgext3rd/evolve/__init__.py --- a/hgext3rd/evolve/__init__.py Wed Nov 13 13:43:46 2019 +0700 +++ b/hgext3rd/evolve/__init__.py Wed Nov 13 13:47:55 2019 +0700 @@ -525,14 +525,14 @@ def _precursors(repo, s, includeidentical=False): """Precursor of a changeset""" cs = set() - nm = repo.changelog.nodemap + getrev = compat.getgetrev(repo.changelog) markerbysubj = repo.obsstore.predecessors node = repo.changelog.node for r in s: for p in markerbysubj.get(node(r), ()): if not includeidentical and p[2] & rewind.identicalflag: continue - pr = nm.get(p[0]) + pr = getrev(p[0]) if pr is not None: cs.add(pr) cs -= repo.changelog.filteredrevs # nodemap has no filtering @@ -551,10 +551,10 @@ if np not in seen: seen.add(np) toproceed.append(np) - nm = repo.changelog.nodemap + getrev = compat.getgetrev(repo.changelog) cs = set() for p in seen: - pr = nm.get(p) + pr = getrev(p) if pr is not None: cs.add(pr) cs -= repo.changelog.filteredrevs # nodemap has no filtering @@ -564,12 +564,12 @@ """Successors of a changeset""" cs = set() node = repo.changelog.node - nm = repo.changelog.nodemap + getrev = compat.getgetrev(repo.changelog) markerbyobj = repo.obsstore.successors for r in s: for p in markerbyobj.get(node(r), ()): for sub in p[1]: - sr = nm.get(sub) + sr = getrev(sub) if sr is not None: cs.add(sr) cs -= repo.changelog.filteredrevs # nodemap has no filtering @@ -595,10 +595,10 @@ if sub not in seen: seen.add(sub) toproceed.append(sub) - nm = repo.changelog.nodemap + getrev = compat.getgetrev(repo.changelog) cs = set() for s in seen: - sr = nm.get(s) + sr = getrev(s) if sr is not None: cs.add(sr) cs -= repo.changelog.filteredrevs # nodemap has no filtering diff -r 0fe5d74134d6 -r e8302f760a54 hgext3rd/evolve/compat.py --- a/hgext3rd/evolve/compat.py Wed Nov 13 13:43:46 2019 +0700 +++ b/hgext3rd/evolve/compat.py Wed Nov 13 13:47:55 2019 +0700 @@ -522,3 +522,11 @@ if meta.get(b'operation')) return sorted(operations) + +# nodemap.get and index.[has_node|rev|get_rev] +# hg <= 5.3 (02802fa87b74) +def getgetrev(cl): + """Returns index.get_rev or nodemap.get (for pre-5.3 Mercurial).""" + if util.safehasattr(cl.index, 'get_rev'): + return cl.index.get_rev + return cl.nodemap.get diff -r 0fe5d74134d6 -r e8302f760a54 hgext3rd/evolve/dagutil.py --- a/hgext3rd/evolve/dagutil.py Wed Nov 13 13:43:46 2019 +0700 +++ b/hgext3rd/evolve/dagutil.py Wed Nov 13 13:47:55 2019 +0700 @@ -13,6 +13,8 @@ from mercurial.i18n import _ from mercurial.node import nullrev +from . import compat + class basedag(object): '''generic interface for DAGs @@ -145,8 +147,9 @@ def _internalizeall(self, ids, filterunknown): rl = self._revlog + getrev = compat.getgetrev(rl) if filterunknown: - return [r for r in map(rl.nodemap.get, ids) + return [r for r in map(getrev, ids) if (r is not None and r != nullrev and r not in rl.filteredrevs)] diff -r 0fe5d74134d6 -r e8302f760a54 hgext3rd/evolve/debugcmd.py --- a/hgext3rd/evolve/debugcmd.py Wed Nov 13 13:43:46 2019 +0700 +++ b/hgext3rd/evolve/debugcmd.py Wed Nov 13 13:47:55 2019 +0700 @@ -17,7 +17,10 @@ from mercurial.i18n import _ -from . import exthelper +from . import ( + compat, + exthelper, +) eh = exthelper.exthelper() @@ -43,7 +46,7 @@ store = repo.obsstore unfi = repo.unfiltered() - nm = unfi.changelog.nodemap + getrev = compat.getgetrev(unfi.changelog) nbmarkers = len(store._all) ui.write(_(b'markers total: %9i\n') % nbmarkers) sucscount = [0, 0, 0, 0] @@ -58,7 +61,7 @@ size_v0 = [] size_v1 = [] for mark in store: - if mark[0] in nm: + if getrev(mark[0]) is not None: known += 1 nbsucs = len(mark[1]) sucscount[min(nbsucs, 3)] += 1 @@ -133,7 +136,7 @@ ui.write(b' any known node: %9i\n' % len([c for c in allclusters - if [n for n in c[0] if nm.get(n) is not None]])) + if [n for n in c[0] if getrev(n) is not None]])) if allclusters: nbcluster = len(allclusters) ui.write((b' smallest length: %9i\n' % len(allclusters[0][1]))) @@ -148,7 +151,7 @@ ui.write((b' using parents data: %9i\n' % len(allpclusters))) ui.write(b' any known node: %9i\n' % len([c for c in allclusters - if [n for n in c[0] if nm.get(n) is not None]])) + if [n for n in c[0] if getrev(n) is not None]])) if allpclusters: nbcluster = len(allpclusters) ui.write((b' smallest length: %9i\n' diff -r 0fe5d74134d6 -r e8302f760a54 hgext3rd/evolve/obscache.py --- a/hgext3rd/evolve/obscache.py Wed Nov 13 13:43:46 2019 +0700 +++ b/hgext3rd/evolve/obscache.py Wed Nov 13 13:47:55 2019 +0700 @@ -20,6 +20,7 @@ ) from . import ( + compat, exthelper, ) @@ -389,9 +390,9 @@ def _updatemarkers(self, repo, obsmarkers): """update the cache with new markers""" - rev = repo.changelog.nodemap.get + getrev = compat.getgetrev(repo.changelog) for m in obsmarkers: - r = rev(m[0]) + r = getrev(m[0]) if r is not None: self._data[r] = 1 diff -r 0fe5d74134d6 -r e8302f760a54 hgext3rd/evolve/obsdiscovery.py --- a/hgext3rd/evolve/obsdiscovery.py Wed Nov 13 13:43:46 2019 +0700 +++ b/hgext3rd/evolve/obsdiscovery.py Wed Nov 13 13:47:55 2019 +0700 @@ -414,8 +414,8 @@ max_stored = con.execute(_query_max_stored).fetchall()[0][0] affected_nodes = _affectedby(repo, obsmarkers) - rev = repo.changelog.nodemap.get - affected = [rev(n) for n in affected_nodes] + getrev = compat.getgetrev(repo.changelog) + affected = [getrev(n) for n in affected_nodes] affected = [r for r in affected if r is not None and r <= max_stored] @@ -646,8 +646,8 @@ The range have the id encoded as a node return 'wdirid' for unknown range""" - nm = repo.changelog.nodemap - ranges = [(nm.get(n), idx) for n, idx in ranges] + getrev = compat.getgetrev(repo.changelog) + ranges = [(getrev(n), idx) for n, idx in ranges] if ranges: maxrev = max(r for r, i in ranges) if maxrev is not None: diff -r 0fe5d74134d6 -r e8302f760a54 hgext3rd/pullbundle.py --- a/hgext3rd/pullbundle.py Wed Nov 13 13:43:46 2019 +0700 +++ b/hgext3rd/pullbundle.py Wed Nov 13 13:47:55 2019 +0700 @@ -180,7 +180,7 @@ def sliceoutgoing(repo, outgoing): cl = repo.changelog - rev = cl.nodemap.get + rev = getgetrev(cl) node = cl.node revsort = repo.stablesort @@ -623,3 +623,11 @@ def fmtdist(name, data): return STATSFORMAT.format(name=name, **data) + +# nodemap.get and index.[has_node|rev|get_rev] +# hg <= 5.3 (02802fa87b74) +def getgetrev(cl): + """Returns index.get_rev or nodemap.get (for pre-5.3 Mercurial).""" + if util.safehasattr(cl.index, 'get_rev'): + return cl.index.get_rev + return cl.nodemap.get diff -r 0fe5d74134d6 -r e8302f760a54 hgext3rd/topic/compat.py --- a/hgext3rd/topic/compat.py Wed Nov 13 13:43:46 2019 +0700 +++ b/hgext3rd/topic/compat.py Wed Nov 13 13:47:55 2019 +0700 @@ -10,6 +10,7 @@ from mercurial import ( obsolete, pycompat, + util, ) getmarkers = None @@ -34,3 +35,11 @@ def branchmapitems(branchmap): return branchmap.iteritems() # py3-transform: on + +# nodemap.get and index.[has_node|rev|get_rev] +# hg <= 5.3 (02802fa87b74) +def getgetrev(cl): + """Returns index.get_rev or nodemap.get (for pre-5.3 Mercurial).""" + if util.safehasattr(cl.index, 'get_rev'): + return cl.index.get_rev + return cl.nodemap.get diff -r 0fe5d74134d6 -r e8302f760a54 hgext3rd/topic/discovery.py --- a/hgext3rd/topic/discovery.py Wed Nov 13 13:43:46 2019 +0700 +++ b/hgext3rd/topic/discovery.py Wed Nov 13 13:47:55 2019 +0700 @@ -45,7 +45,7 @@ publishednode, pushop.remotephases.publicheads) - rev = repo.unfiltered().changelog.nodemap.get + getrev = compat.getgetrev(repo.unfiltered().changelog) def remotebranchmap(): # drop topic information from changeset about to be published @@ -56,7 +56,7 @@ else: namedbranch = branch.split(b':', 1)[0] for h in heads: - r = rev(h) + r = getrev(h) if r is not None and r in publishedset: result[namedbranch].append(h) else: diff -r 0fe5d74134d6 -r e8302f760a54 hgext3rd/topic/topicmap.py --- a/hgext3rd/topic/topicmap.py Wed Nov 13 13:43:46 2019 +0700 +++ b/hgext3rd/topic/topicmap.py Wed Nov 13 13:47:55 2019 +0700 @@ -14,6 +14,7 @@ from . import ( common, + compat, ) basefilter = set([b'base', b'immutable']) @@ -69,10 +70,10 @@ revs = set() cl = repo.changelog fr = cl.filteredrevs - nm = cl.nodemap + getrev = compat.getgetrev(cl) for roots in repo._phasecache.phaseroots[1:]: for n in roots: - r = nm.get(n) + r = getrev(n) if r not in fr and r < maxrev: revs.add(r) key = nullid