Commit bb2b4f6c authored by Anton Shestakov's avatar Anton Shestakov
Browse files

compat: compatibility for cl.nodemap.get vs cl.index.get_rev

parent 379ce8ba150d
Pipeline #1068 canceled with stage
......@@ -527,10 +527,10 @@
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
......@@ -531,10 +531,10 @@
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
......@@ -553,6 +553,6 @@
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:
......@@ -557,6 +557,6 @@
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
......@@ -566,8 +566,8 @@
"""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]:
......@@ -570,8 +570,8 @@
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
......@@ -597,6 +597,6 @@
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:
......@@ -601,6 +601,6 @@
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
......
......@@ -532,3 +532,11 @@
if not category:
return {}
return {'helpcategory': category}
# 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
......@@ -13,6 +13,8 @@
from mercurial.i18n import _
from mercurial.node import nullrev
from . import compat
class basedag(object):
'''generic interface for DAGs
......@@ -145,4 +147,5 @@
def _internalizeall(self, ids, filterunknown):
rl = self._revlog
getrev = compat.getgetrev(rl)
if filterunknown:
......@@ -148,5 +151,5 @@
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)]
......
......@@ -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'
......
......@@ -20,6 +20,7 @@
)
from . import (
compat,
exthelper,
)
......@@ -389,5 +390,5 @@
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:
......@@ -393,5 +394,5 @@
for m in obsmarkers:
r = rev(m[0])
r = getrev(m[0])
if r is not None:
self._data[r] = 1
......
......@@ -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:
......
......@@ -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
......@@ -11,6 +11,7 @@
obsolete,
pycompat,
registrar,
util,
)
getmarkers = None
......@@ -44,3 +45,11 @@
if not category:
return {}
return {'helpcategory': category}
# 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
......@@ -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:
......
......@@ -14,6 +14,7 @@
from . import (
common,
compat,
)
basefilter = set([b'base', b'immutable'])
......@@ -69,6 +70,6 @@
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:
......@@ -73,6 +74,6 @@
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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment