##// END OF EJS Templates
node: introduce nodeconstants class...
Joerg Sonnenberger -
r47538:6266d195 default
parent child Browse files
Show More
@@ -3672,7 +3672,7 def perfloadmarkers(ui, repo):
3672 3672 Result is the number of markers in the repo."""
3673 3673 timer, fm = gettimer(ui)
3674 3674 svfs = getsvfs(repo)
3675 timer(lambda: len(obsolete.obsstore(svfs)))
3675 timer(lambda: len(obsolete.obsstore(repo, svfs)))
3676 3676 fm.end()
3677 3677
3678 3678
@@ -102,6 +102,9 class nullui(object):
102 102 class emptyfilecontext(object):
103 103 """minimal filecontext representing an empty file"""
104 104
105 def __init__(self, repo):
106 self._repo = repo
107
105 108 def data(self):
106 109 return b''
107 110
@@ -212,7 +215,7 def getfilestack(stack, path, seenfctxs=
212 215 if path in pctx:
213 216 fctxs.append(pctx[path])
214 217 else:
215 fctxs.append(emptyfilecontext())
218 fctxs.append(emptyfilecontext(pctx.repo()))
216 219
217 220 fctxs.reverse()
218 221 # note: we rely on a property of hg: filerev is not reused for linear
@@ -8,6 +8,7 from mercurial.node import (
8 8 nullhex,
9 9 nullid,
10 10 nullrev,
11 sha1nodeconstants,
11 12 wdirhex,
12 13 )
13 14 from mercurial import (
@@ -422,6 +423,8 class changelog(baselog):
422 423
423 424
424 425 class manifestlog(baselog):
426 nodeconstants = sha1nodeconstants
427
425 428 def __getitem__(self, node):
426 429 return self.get(b'', node)
427 430
@@ -206,6 +206,7 def openlfdirstate(ui, repo, create=True
206 206 repo.root,
207 207 repo.dirstate._validate,
208 208 lambda: sparse.matcher(repo),
209 repo.nodeconstants,
209 210 )
210 211
211 212 # If the largefiles dirstate does not exist, populate and create
@@ -54,6 +54,7 from mercurial.i18n import _
54 54 from mercurial.node import (
55 55 nullid,
56 56 nullrev,
57 sha1nodeconstants,
57 58 short,
58 59 )
59 60 from mercurial.thirdparty import attr
@@ -305,6 +306,7 class sqlitefilestore(object):
305 306 """Implements storage for an individual tracked path."""
306 307
307 308 def __init__(self, db, path, compression):
309 self.nullid = sha1nodeconstants.nullid
308 310 self._db = db
309 311 self._path = path
310 312
@@ -623,7 +623,7 def unhexlifybookmarks(marks):
623 623 _binaryentry = struct.Struct(b'>20sH')
624 624
625 625
626 def binaryencode(bookmarks):
626 def binaryencode(repo, bookmarks):
627 627 """encode a '(bookmark, node)' iterable into a binary stream
628 628
629 629 the binary format is:
@@ -645,7 +645,7 def binaryencode(bookmarks):
645 645 return b''.join(binarydata)
646 646
647 647
648 def binarydecode(stream):
648 def binarydecode(repo, stream):
649 649 """decode a binary stream into an '(bookmark, node)' iterable
650 650
651 651 the binary format is:
@@ -97,7 +97,7 class BranchMapCache(object):
97 97 revs.extend(r for r in extrarevs if r <= bcache.tiprev)
98 98 else:
99 99 # nothing to fall back on, start empty.
100 bcache = branchcache()
100 bcache = branchcache(repo)
101 101
102 102 revs.extend(cl.revs(start=bcache.tiprev + 1))
103 103 if revs:
@@ -129,6 +129,7 class BranchMapCache(object):
129 129 if rbheads:
130 130 rtiprev = max((int(clrev(node)) for node in rbheads))
131 131 cache = branchcache(
132 repo,
132 133 remotebranchmap,
133 134 repo[rtiprev].node(),
134 135 rtiprev,
@@ -184,6 +185,7 class branchcache(object):
184 185
185 186 def __init__(
186 187 self,
188 repo,
187 189 entries=(),
188 190 tipnode=nullid,
189 191 tiprev=nullrev,
@@ -195,6 +197,7 class branchcache(object):
195 197 """hasnode is a function which can be used to verify whether changelog
196 198 has a given node or not. If it's not provided, we assume that every node
197 199 we have exists in changelog"""
200 self._repo = repo
198 201 self.tipnode = tipnode
199 202 self.tiprev = tiprev
200 203 self.filteredhash = filteredhash
@@ -280,6 +283,7 class branchcache(object):
280 283 if len(cachekey) > 2:
281 284 filteredhash = bin(cachekey[2])
282 285 bcache = cls(
286 repo,
283 287 tipnode=last,
284 288 tiprev=lrev,
285 289 filteredhash=filteredhash,
@@ -388,6 +392,7 class branchcache(object):
388 392 def copy(self):
389 393 """return an deep copy of the branchcache object"""
390 394 return type(self)(
395 self._repo,
391 396 self._entries,
392 397 self.tipnode,
393 398 self.tiprev,
@@ -2146,7 +2146,7 def handlecheckbookmarks(op, inpart):
2146 2146 contains binary encoded (bookmark, node) tuple. If the local state does
2147 2147 not marks the one in the part, a PushRaced exception is raised
2148 2148 """
2149 bookdata = bookmarks.binarydecode(inpart)
2149 bookdata = bookmarks.binarydecode(op.repo, inpart)
2150 2150
2151 2151 msgstandard = (
2152 2152 b'remote repository changed while pushing - please try again '
@@ -2376,7 +2376,7 def handlebookmark(op, inpart):
2376 2376 When mode is 'records', the information is recorded into the 'bookmarks'
2377 2377 records of the bundle operation. This behavior is suitable for pulling.
2378 2378 """
2379 changes = bookmarks.binarydecode(inpart)
2379 changes = bookmarks.binarydecode(op.repo, inpart)
2380 2380
2381 2381 pushkeycompat = op.repo.ui.configbool(
2382 2382 b'server', b'bookmarks-pushkey-compat'
@@ -175,9 +175,15 class bundlechangelog(bundlerevlog, chan
175 175
176 176 class bundlemanifest(bundlerevlog, manifest.manifestrevlog):
177 177 def __init__(
178 self, opener, cgunpacker, linkmapper, dirlogstarts=None, dir=b''
178 self,
179 nodeconstants,
180 opener,
181 cgunpacker,
182 linkmapper,
183 dirlogstarts=None,
184 dir=b'',
179 185 ):
180 manifest.manifestrevlog.__init__(self, opener, tree=dir)
186 manifest.manifestrevlog.__init__(self, nodeconstants, opener, tree=dir)
181 187 bundlerevlog.__init__(
182 188 self, opener, self.indexfile, cgunpacker, linkmapper
183 189 )
@@ -192,6 +198,7 class bundlemanifest(bundlerevlog, manif
192 198 if d in self._dirlogstarts:
193 199 self.bundle.seek(self._dirlogstarts[d])
194 200 return bundlemanifest(
201 self.nodeconstants,
195 202 self.opener,
196 203 self.bundle,
197 204 self._linkmapper,
@@ -368,7 +375,9 class bundlerepository(object):
368 375 # consume the header if it exists
369 376 self._cgunpacker.manifestheader()
370 377 linkmapper = self.unfiltered().changelog.rev
371 rootstore = bundlemanifest(self.svfs, self._cgunpacker, linkmapper)
378 rootstore = bundlemanifest(
379 self.nodeconstants, self.svfs, self._cgunpacker, linkmapper
380 )
372 381 self.filestart = self._cgunpacker.tell()
373 382
374 383 return manifest.manifestlog(
@@ -662,7 +662,7 class headerlessfixup(object):
662 662 return readexactly(self._fh, n)
663 663
664 664
665 def _revisiondeltatochunks(delta, headerfn):
665 def _revisiondeltatochunks(repo, delta, headerfn):
666 666 """Serialize a revisiondelta to changegroup chunks."""
667 667
668 668 # The captured revision delta may be encoded as a delta against
@@ -1065,7 +1065,9 class cgpacker(object):
1065 1065 sidedata_helpers=sidedata_helpers,
1066 1066 )
1067 1067 for delta in deltas:
1068 for chunk in _revisiondeltatochunks(delta, self._builddeltaheader):
1068 for chunk in _revisiondeltatochunks(
1069 self._repo, delta, self._builddeltaheader
1070 ):
1069 1071 size += len(chunk)
1070 1072 yield chunk
1071 1073
@@ -1121,7 +1123,9 class cgpacker(object):
1121 1123 yield chunk
1122 1124
1123 1125 for delta in deltas:
1124 chunks = _revisiondeltatochunks(delta, self._builddeltaheader)
1126 chunks = _revisiondeltatochunks(
1127 self._repo, delta, self._builddeltaheader
1128 )
1125 1129 for chunk in chunks:
1126 1130 size += len(chunk)
1127 1131 yield chunk
@@ -1160,7 +1164,9 class cgpacker(object):
1160 1164 yield h
1161 1165
1162 1166 for delta in deltas:
1163 chunks = _revisiondeltatochunks(delta, self._builddeltaheader)
1167 chunks = _revisiondeltatochunks(
1168 self._repo, delta, self._builddeltaheader
1169 )
1164 1170 for chunk in chunks:
1165 1171 size += len(chunk)
1166 1172 yield chunk
@@ -191,7 +191,7 class _changelogrevision(object):
191 191 # Extensions might modify _defaultextra, so let the constructor below pass
192 192 # it in
193 193 extra = attr.ib()
194 manifest = attr.ib(default=nullid)
194 manifest = attr.ib()
195 195 user = attr.ib(default=b'')
196 196 date = attr.ib(default=(0, 0))
197 197 files = attr.ib(default=attr.Factory(list))
@@ -219,9 +219,9 class changelogrevision(object):
219 219 '_changes',
220 220 )
221 221
222 def __new__(cls, text, sidedata, cpsd):
222 def __new__(cls, cl, text, sidedata, cpsd):
223 223 if not text:
224 return _changelogrevision(extra=_defaultextra)
224 return _changelogrevision(extra=_defaultextra, manifest=nullid)
225 225
226 226 self = super(changelogrevision, cls).__new__(cls)
227 227 # We could return here and implement the following as an __init__.
@@ -526,7 +526,7 class changelog(revlog.revlog):
526 526 """
527 527 d, s = self._revisiondata(nodeorrev)
528 528 c = changelogrevision(
529 d, s, self._copiesstorage == b'changeset-sidedata'
529 self, d, s, self._copiesstorage == b'changeset-sidedata'
530 530 )
531 531 return (c.manifest, c.user, c.date, c.files, c.description, c.extra)
532 532
@@ -534,7 +534,7 class changelog(revlog.revlog):
534 534 """Obtain a ``changelogrevision`` for a node or revision."""
535 535 text, sidedata = self._revisiondata(nodeorrev)
536 536 return changelogrevision(
537 text, sidedata, self._copiesstorage == b'changeset-sidedata'
537 self, text, sidedata, self._copiesstorage == b'changeset-sidedata'
538 538 )
539 539
540 540 def readfiles(self, nodeorrev):
@@ -73,13 +73,16 def _getfsnow(vfs):
73 73
74 74 @interfaceutil.implementer(intdirstate.idirstate)
75 75 class dirstate(object):
76 def __init__(self, opener, ui, root, validate, sparsematchfn):
76 def __init__(
77 self, opener, ui, root, validate, sparsematchfn, nodeconstants
78 ):
77 79 """Create a new dirstate object.
78 80
79 81 opener is an open()-like callable that can be used to open the
80 82 dirstate file; root is the root of the directory tracked by
81 83 the dirstate.
82 84 """
85 self._nodeconstants = nodeconstants
83 86 self._opener = opener
84 87 self._validate = validate
85 88 self._root = root
@@ -136,7 +139,9 class dirstate(object):
136 139 @propertycache
137 140 def _map(self):
138 141 """Return the dirstate contents (see documentation for dirstatemap)."""
139 self._map = self._mapcls(self._ui, self._opener, self._root)
142 self._map = self._mapcls(
143 self._ui, self._opener, self._root, self._nodeconstants
144 )
140 145 return self._map
141 146
142 147 @property
@@ -1420,12 +1425,13 class dirstatemap(object):
1420 1425 denormalized form that they appear as in the dirstate.
1421 1426 """
1422 1427
1423 def __init__(self, ui, opener, root):
1428 def __init__(self, ui, opener, root, nodeconstants):
1424 1429 self._ui = ui
1425 1430 self._opener = opener
1426 1431 self._root = root
1427 1432 self._filename = b'dirstate'
1428 1433 self._nodelen = 20
1434 self._nodeconstants = nodeconstants
1429 1435
1430 1436 self._parents = None
1431 1437 self._dirtyparents = False
@@ -1724,7 +1730,8 class dirstatemap(object):
1724 1730 if rustmod is not None:
1725 1731
1726 1732 class dirstatemap(object):
1727 def __init__(self, ui, opener, root):
1733 def __init__(self, ui, opener, root, nodeconstants):
1734 self._nodeconstants = nodeconstants
1728 1735 self._ui = ui
1729 1736 self._opener = opener
1730 1737 self._root = root
@@ -270,9 +270,12 def _headssummary(pushop):
270 270 # C. Update newmap with outgoing changes.
271 271 # This will possibly add new heads and remove existing ones.
272 272 newmap = branchmap.remotebranchcache(
273 repo,
274 (
273 275 (branch, heads[1])
274 276 for branch, heads in pycompat.iteritems(headssum)
275 277 if heads[0] is not None
278 ),
276 279 )
277 280 newmap.update(repo, (ctx.rev() for ctx in missingctx))
278 281 for branch, newheads in pycompat.iteritems(newmap):
@@ -827,7 +827,7 def _pushb2checkbookmarks(pushop, bundle
827 827 data = []
828 828 for book, old, new in pushop.outbookmarks:
829 829 data.append((book, old))
830 checkdata = bookmod.binaryencode(data)
830 checkdata = bookmod.binaryencode(pushop.repo, data)
831 831 bundler.newpart(b'check:bookmarks', data=checkdata)
832 832
833 833
@@ -1027,7 +1027,7 def _pushb2bookmarkspart(pushop, bundler
1027 1027 _abortonsecretctx(pushop, new, book)
1028 1028 data.append((book, new))
1029 1029 allactions.append((book, _bmaction(old, new)))
1030 checkdata = bookmod.binaryencode(data)
1030 checkdata = bookmod.binaryencode(pushop.repo, data)
1031 1031 bundler.newpart(b'bookmarks', data=checkdata)
1032 1032
1033 1033 def handlereply(op):
@@ -2455,7 +2455,7 def _getbundlebookmarkpart(
2455 2455 if not b2caps or b'bookmarks' not in b2caps:
2456 2456 raise error.Abort(_(b'no common bookmarks exchange method'))
2457 2457 books = bookmod.listbinbookmarks(repo)
2458 data = bookmod.binaryencode(books)
2458 data = bookmod.binaryencode(repo, books)
2459 2459 if data:
2460 2460 bundler.newpart(b'bookmarks', data=data)
2461 2461
@@ -33,6 +33,7 class filelog(object):
33 33 # Used by LFS.
34 34 self._revlog.filename = path
35 35 self._revlog.revlog_kind = b'filelog'
36 self.nullid = self._revlog.nullid
36 37
37 38 def __len__(self):
38 39 return len(self._revlog)
@@ -8,7 +8,7 from . import util as interfaceutil
8 8
9 9
10 10 class idirstate(interfaceutil.Interface):
11 def __init__(opener, ui, root, validate, sparsematchfn):
11 def __init__(opener, ui, root, validate, sparsematchfn, nodeconstants):
12 12 """Create a new dirstate object.
13 13
14 14 opener is an open()-like callable that can be used to open the
@@ -523,6 +523,10 class ifileindex(interfaceutil.Interface
523 523 * Metadata to facilitate storage.
524 524 """
525 525
526 nullid = interfaceutil.Attribute(
527 """node for the null revision for use as delta base."""
528 )
529
526 530 def __len__():
527 531 """Obtain the number of revisions stored for this file."""
528 532
@@ -1143,6 +1147,10 class imanifestrevisionwritable(imanifes
1143 1147 class imanifeststorage(interfaceutil.Interface):
1144 1148 """Storage interface for manifest data."""
1145 1149
1150 nodeconstants = interfaceutil.Attribute(
1151 """nodeconstants used by the current repository."""
1152 )
1153
1146 1154 tree = interfaceutil.Attribute(
1147 1155 """The path to the directory this manifest tracks.
1148 1156
@@ -1366,6 +1374,10 class imanifestlog(interfaceutil.Interfa
1366 1374 tree manifests.
1367 1375 """
1368 1376
1377 nodeconstants = interfaceutil.Attribute(
1378 """nodeconstants used by the current repository."""
1379 )
1380
1369 1381 def __getitem__(node):
1370 1382 """Obtain a manifest instance for a given binary node.
1371 1383
@@ -1434,6 +1446,13 class ilocalrepositorymain(interfaceutil
1434 1446 This currently captures the reality of things - not how things should be.
1435 1447 """
1436 1448
1449 nodeconstants = interfaceutil.Attribute(
1450 """Constant nodes matching the hash function used by the repository."""
1451 )
1452 nullid = interfaceutil.Attribute(
1453 """null revision for the hash function used by the repository."""
1454 )
1455
1437 1456 supportedformats = interfaceutil.Attribute(
1438 1457 """Set of requirements that apply to stream clone.
1439 1458
@@ -21,6 +21,7 from .node import (
21 21 hex,
22 22 nullid,
23 23 nullrev,
24 sha1nodeconstants,
24 25 short,
25 26 )
26 27 from .pycompat import (
@@ -1330,6 +1331,8 class localrepository(object):
1330 1331 self.vfs = hgvfs
1331 1332 self.path = hgvfs.base
1332 1333 self.requirements = requirements
1334 self.nodeconstants = sha1nodeconstants
1335 self.nullid = self.nodeconstants.nullid
1333 1336 self.supported = supportedrequirements
1334 1337 self.sharedpath = sharedpath
1335 1338 self.store = store
@@ -1676,7 +1679,12 class localrepository(object):
1676 1679 sparsematchfn = lambda: sparse.matcher(self)
1677 1680
1678 1681 return dirstate.dirstate(
1679 self.vfs, self.ui, self.root, self._dirstatevalidate, sparsematchfn
1682 self.vfs,
1683 self.ui,
1684 self.root,
1685 self._dirstatevalidate,
1686 sparsematchfn,
1687 self.nodeconstants,
1680 1688 )
1681 1689
1682 1690 def _dirstatevalidate(self, node):
@@ -792,8 +792,9 def _splittopdir(f):
792 792
793 793 @interfaceutil.implementer(repository.imanifestdict)
794 794 class treemanifest(object):
795 def __init__(self, dir=b'', text=b''):
795 def __init__(self, nodeconstants, dir=b'', text=b''):
796 796 self._dir = dir
797 self.nodeconstants = nodeconstants
797 798 self._node = nullid
798 799 self._loadfunc = _noop
799 800 self._copyfunc = _noop
@@ -1051,7 +1052,9 class treemanifest(object):
1051 1052 if dir:
1052 1053 self._loadlazy(dir)
1053 1054 if dir not in self._dirs:
1054 self._dirs[dir] = treemanifest(self._subpath(dir))
1055 self._dirs[dir] = treemanifest(
1056 self.nodeconstants, self._subpath(dir)
1057 )
1055 1058 self._dirs[dir].__setitem__(subpath, n)
1056 1059 else:
1057 1060 # manifest nodes are either 20 bytes or 32 bytes,
@@ -1078,14 +1081,16 class treemanifest(object):
1078 1081 if dir:
1079 1082 self._loadlazy(dir)
1080 1083 if dir not in self._dirs:
1081 self._dirs[dir] = treemanifest(self._subpath(dir))
1084 self._dirs[dir] = treemanifest(
1085 self.nodeconstants, self._subpath(dir)
1086 )
1082 1087 self._dirs[dir].setflag(subpath, flags)
1083 1088 else:
1084 1089 self._flags[f] = flags
1085 1090 self._dirty = True
1086 1091
1087 1092 def copy(self):
1088 copy = treemanifest(self._dir)
1093 copy = treemanifest(self.nodeconstants, self._dir)
1089 1094 copy._node = self._node
1090 1095 copy._dirty = self._dirty
1091 1096 if self._copyfunc is _noop:
@@ -1215,7 +1220,7 class treemanifest(object):
1215 1220 visit = match.visitchildrenset(self._dir[:-1])
1216 1221 if visit == b'all':
1217 1222 return self.copy()
1218 ret = treemanifest(self._dir)
1223 ret = treemanifest(self.nodeconstants, self._dir)
1219 1224 if not visit:
1220 1225 return ret
1221 1226
@@ -1272,7 +1277,7 class treemanifest(object):
1272 1277 m2 = m2._matches(match)
1273 1278 return m1.diff(m2, clean=clean)
1274 1279 result = {}
1275 emptytree = treemanifest()
1280 emptytree = treemanifest(self.nodeconstants)
1276 1281
1277 1282 def _iterativediff(t1, t2, stack):
1278 1283 """compares two tree manifests and append new tree-manifests which
@@ -1368,7 +1373,7 class treemanifest(object):
1368 1373 self._load() # for consistency; should never have any effect here
1369 1374 m1._load()
1370 1375 m2._load()
1371 emptytree = treemanifest()
1376 emptytree = treemanifest(self.nodeconstants)
1372 1377
1373 1378 def getnode(m, d):
1374 1379 ld = m._lazydirs.get(d)
@@ -1551,6 +1556,7 class manifestrevlog(object):
1551 1556
1552 1557 def __init__(
1553 1558 self,
1559 nodeconstants,
1554 1560 opener,
1555 1561 tree=b'',
1556 1562 dirlogcache=None,
@@ -1567,6 +1573,7 class manifestrevlog(object):
1567 1573 option takes precedence, so if it is set to True, we ignore whatever
1568 1574 value is passed in to the constructor.
1569 1575 """
1576 self.nodeconstants = nodeconstants
1570 1577 # During normal operations, we expect to deal with not more than four
1571 1578 # revs at a time (such as during commit --amend). When rebasing large
1572 1579 # stacks of commits, the number can go up, hence the config knob below.
@@ -1654,7 +1661,11 class manifestrevlog(object):
1654 1661 assert self._treeondisk
1655 1662 if d not in self._dirlogcache:
1656 1663 mfrevlog = manifestrevlog(
1657 self.opener, d, self._dirlogcache, treemanifest=self._treeondisk
1664 self.nodeconstants,
1665 self.opener,
1666 d,
1667 self._dirlogcache,
1668 treemanifest=self._treeondisk,
1658 1669 )
1659 1670 self._dirlogcache[d] = mfrevlog
1660 1671 return self._dirlogcache[d]
@@ -1917,6 +1928,7 class manifestlog(object):
1917 1928 they receive (i.e. tree or flat or lazily loaded, etc)."""
1918 1929
1919 1930 def __init__(self, opener, repo, rootstore, narrowmatch):
1931 self.nodeconstants = repo.nodeconstants
1920 1932 usetreemanifest = False
1921 1933 cachesize = 4
1922 1934
@@ -1955,7 +1967,7 class manifestlog(object):
1955 1967
1956 1968 if not self._narrowmatch.always():
1957 1969 if not self._narrowmatch.visitdir(tree[:-1]):
1958 return excludeddirmanifestctx(tree, node)
1970 return excludeddirmanifestctx(self.nodeconstants, tree, node)
1959 1971 if tree:
1960 1972 if self._rootstore._treeondisk:
1961 1973 if verify:
@@ -2118,7 +2130,7 class memtreemanifestctx(object):
2118 2130 def __init__(self, manifestlog, dir=b''):
2119 2131 self._manifestlog = manifestlog
2120 2132 self._dir = dir
2121 self._treemanifest = treemanifest()
2133 self._treemanifest = treemanifest(manifestlog.nodeconstants)
2122 2134
2123 2135 def _storage(self):
2124 2136 return self._manifestlog.getstorage(b'')
@@ -2168,17 +2180,19 class treemanifestctx(object):
2168 2180 narrowmatch = self._manifestlog._narrowmatch
2169 2181 if not narrowmatch.always():
2170 2182 if not narrowmatch.visitdir(self._dir[:-1]):
2171 return excludedmanifestrevlog(self._dir)
2183 return excludedmanifestrevlog(
2184 self._manifestlog.nodeconstants, self._dir
2185 )
2172 2186 return self._manifestlog.getstorage(self._dir)
2173 2187
2174 2188 def read(self):
2175 2189 if self._data is None:
2176 2190 store = self._storage()
2177 2191 if self._node == nullid:
2178 self._data = treemanifest()
2192 self._data = treemanifest(self._manifestlog.nodeconstants)
2179 2193 # TODO accessing non-public API
2180 2194 elif store._treeondisk:
2181 m = treemanifest(dir=self._dir)
2195 m = treemanifest(self._manifestlog.nodeconstants, dir=self._dir)
2182 2196
2183 2197 def gettext():
2184 2198 return store.revision(self._node)
@@ -2198,7 +2212,9 class treemanifestctx(object):
2198 2212 text = store.revision(self._node)
2199 2213 arraytext = bytearray(text)
2200 2214 store.fulltextcache[self._node] = arraytext
2201 self._data = treemanifest(dir=self._dir, text=text)
2215 self._data = treemanifest(
2216 self._manifestlog.nodeconstants, dir=self._dir, text=text
2217 )
2202 2218
2203 2219 return self._data
2204 2220
@@ -2235,7 +2251,7 class treemanifestctx(object):
2235 2251 r0 = store.deltaparent(store.rev(self._node))
2236 2252 m0 = self._manifestlog.get(self._dir, store.node(r0)).read()
2237 2253 m1 = self.read()
2238 md = treemanifest(dir=self._dir)
2254 md = treemanifest(self._manifestlog.nodeconstants, dir=self._dir)
2239 2255 for f, ((n0, fl0), (n1, fl1)) in pycompat.iteritems(m0.diff(m1)):
2240 2256 if n1:
2241 2257 md[f] = n1
@@ -2278,8 +2294,8 class excludeddir(treemanifest):
2278 2294 whose contents are unknown.
2279 2295 """
2280 2296
2281 def __init__(self, dir, node):
2282 super(excludeddir, self).__init__(dir)
2297 def __init__(self, nodeconstants, dir, node):
2298 super(excludeddir, self).__init__(nodeconstants, dir)
2283 2299 self._node = node
2284 2300 # Add an empty file, which will be included by iterators and such,
2285 2301 # appearing as the directory itself (i.e. something like "dir/")
@@ -2298,12 +2314,13 class excludeddir(treemanifest):
2298 2314 class excludeddirmanifestctx(treemanifestctx):
2299 2315 """context wrapper for excludeddir - see that docstring for rationale"""
2300 2316
2301 def __init__(self, dir, node):
2317 def __init__(self, nodeconstants, dir, node):
2318 self.nodeconstants = nodeconstants
2302 2319 self._dir = dir
2303 2320 self._node = node
2304 2321
2305 2322 def read(self):
2306 return excludeddir(self._dir, self._node)
2323 return excludeddir(self.nodeconstants, self._dir, self._node)
2307 2324
2308 2325 def readfast(self, shallow=False):
2309 2326 # special version of readfast since we don't have underlying storage
@@ -2325,7 +2342,8 class excludedmanifestrevlog(manifestrev
2325 2342 outside the narrowspec.
2326 2343 """
2327 2344
2328 def __init__(self, dir):
2345 def __init__(self, nodeconstants, dir):
2346 self.nodeconstants = nodeconstants
2329 2347 self._dir = dir
2330 2348
2331 2349 def __len__(self):
@@ -21,9 +21,22 def bin(s):
21 21 raise TypeError(e)
22 22
23 23
24 def short(node):
25 return hex(node[:6])
26
27
24 28 nullrev = -1
29
30 # pseudo identifier for working directory
31 # (experimental, so don't add too many dependencies on it)
32 wdirrev = 0x7FFFFFFF
33
34
35 class sha1nodeconstants(object):
36 nodelen = 20
37
25 38 # In hex, this is '0000000000000000000000000000000000000000'
26 nullid = b"\0" * 20
39 nullid = b"\0" * nodelen
27 40 nullhex = hex(nullid)
28 41
29 42 # Phony node value to stand-in for new files in some uses of
@@ -37,13 +50,19 modifiednodeid = b'000000000000modified'
37 50
38 51 wdirfilenodeids = {newnodeid, addednodeid, modifiednodeid}
39 52
40 # pseudo identifiers for working directory
41 # (they are experimental, so don't add too many dependencies on them)
42 wdirrev = 0x7FFFFFFF
53 # pseudo identifier for working directory
54 # (experimental, so don't add too many dependencies on it)
43 55 # In hex, this is 'ffffffffffffffffffffffffffffffffffffffff'
44 wdirid = b"\xff" * 20
56 wdirid = b"\xff" * nodelen
45 57 wdirhex = hex(wdirid)
46 58
47 59
48 def short(node):
49 return hex(node[:6])
60 # legacy starting point for porting modules
61 nullid = sha1nodeconstants.nullid
62 nullhex = sha1nodeconstants.nullhex
63 newnodeid = sha1nodeconstants.newnodeid
64 addednodeid = sha1nodeconstants.addednodeid
65 modifiednodeid = sha1nodeconstants.modifiednodeid
66 wdirfilenodeids = sha1nodeconstants.wdirfilenodeids
67 wdirid = sha1nodeconstants.wdirid
68 wdirhex = sha1nodeconstants.wdirhex
@@ -560,10 +560,11 class obsstore(object):
560 560 # parents: (tuple of nodeid) or None, parents of predecessors
561 561 # None is used when no data has been recorded
562 562
563 def __init__(self, svfs, defaultformat=_fm1version, readonly=False):
563 def __init__(self, repo, svfs, defaultformat=_fm1version, readonly=False):
564 564 # caches for various obsolescence related cache
565 565 self.caches = {}
566 566 self.svfs = svfs
567 self.repo = repo
567 568 self._defaultformat = defaultformat
568 569 self._readonly = readonly
569 570
@@ -806,7 +807,7 def makestore(ui, repo):
806 807 if defaultformat is not None:
807 808 kwargs['defaultformat'] = defaultformat
808 809 readonly = not isenabled(repo, createmarkersopt)
809 store = obsstore(repo.svfs, readonly=readonly, **kwargs)
810 store = obsstore(repo, repo.svfs, readonly=readonly, **kwargs)
810 811 if store and readonly:
811 812 ui.warn(
812 813 _(b'obsolete feature not enabled but %i markers found!\n')
@@ -28,6 +28,7 from .node import (
28 28 nullhex,
29 29 nullid,
30 30 nullrev,
31 sha1nodeconstants,
31 32 short,
32 33 wdirfilenodeids,
33 34 wdirhex,
@@ -651,6 +652,10 class revlog(object):
651 652 raise error.RevlogError(
652 653 _(b'unknown version (%d) in revlog %s') % (fmt, self.indexfile)
653 654 )
655
656 self.nodeconstants = sha1nodeconstants
657 self.nullid = self.nodeconstants.nullid
658
654 659 # sparse-revlog can't be on without general-delta (issue6056)
655 660 if not self._generaldelta:
656 661 self._sparserevlog = False
@@ -12,6 +12,7 from __future__ import absolute_import
12 12 import errno
13 13
14 14 from .i18n import _
15 from .node import sha1nodeconstants
15 16 from . import (
16 17 branchmap,
17 18 changelog,
@@ -198,6 +199,8 class statichttprepository(
198 199 requirements, supportedrequirements
199 200 )
200 201 localrepo.ensurerequirementscompatible(ui, requirements)
202 self.nodeconstants = sha1nodeconstants
203 self.nullid = self.nodeconstants.nullid
201 204
202 205 # setup store
203 206 self.store = localrepo.makestore(requirements, self.path, vfsclass)
@@ -207,7 +210,7 class statichttprepository(
207 210 self._filecache = {}
208 211 self.requirements = requirements
209 212
210 rootmanifest = manifest.manifestrevlog(self.svfs)
213 rootmanifest = manifest.manifestrevlog(self.nodeconstants, self.svfs)
211 214 self.manifestlog = manifest.manifestlog(
212 215 self.svfs, self, rootmanifest, self.narrowmatch()
213 216 )
@@ -441,7 +441,7 class basicstore(object):
441 441 )
442 442
443 443 def manifestlog(self, repo, storenarrowmatch):
444 rootstore = manifest.manifestrevlog(self.vfs)
444 rootstore = manifest.manifestrevlog(repo.nodeconstants, self.vfs)
445 445 return manifest.manifestlog(self.vfs, repo, rootstore, storenarrowmatch)
446 446
447 447 def datafiles(self, matcher=None):
@@ -153,9 +153,9 class unionchangelog(unionrevlog, change
153 153
154 154
155 155 class unionmanifest(unionrevlog, manifest.manifestrevlog):
156 def __init__(self, opener, opener2, linkmapper):
157 manifest.manifestrevlog.__init__(self, opener)
158 manifest2 = manifest.manifestrevlog(opener2)
156 def __init__(self, nodeconstants, opener, opener2, linkmapper):
157 manifest.manifestrevlog.__init__(self, nodeconstants, opener)
158 manifest2 = manifest.manifestrevlog(nodeconstants, opener2)
159 159 unionrevlog.__init__(
160 160 self, opener, self.indexfile, manifest2, linkmapper
161 161 )
@@ -205,7 +205,10 class unionrepository(object):
205 205 @localrepo.unfilteredpropertycache
206 206 def manifestlog(self):
207 207 rootstore = unionmanifest(
208 self.svfs, self.repo2.svfs, self.unfiltered()._clrev
208 self.nodeconstants,
209 self.svfs,
210 self.repo2.svfs,
211 self.unfiltered()._clrev,
209 212 )
210 213 return manifest.manifestlog(
211 214 self.svfs, self, rootstore, self.narrowmatch()
@@ -36,7 +36,9 def _revlogfrompath(repo, path):
36 36 return changelog.changelog(repo.svfs)
37 37 elif path.endswith(b'00manifest.i'):
38 38 mandir = path[: -len(b'00manifest.i')]
39 return manifest.manifestrevlog(repo.svfs, tree=mandir)
39 return manifest.manifestrevlog(
40 repo.nodeconstants, repo.svfs, tree=mandir
41 )
40 42 else:
41 43 # reverse of "/".join(("data", path + ".i"))
42 44 return filelog.filelog(repo.svfs, path[5:-2])
@@ -43,3 +43,7
43 43 now get a revision number as argument instead of a node.
44 44
45 45 * revlog.addrevision returns the revision number instead of the node.
46
47 * `nodes.nullid` and related constants are being phased out as part of
48 the deprecation of SHA1. Repository instances and related classes
49 provide access via `nodeconstants` and in some cases `nullid` attributes.
@@ -106,7 +106,9 class filestorage(object):
106 106
107 107 _flagserrorclass = simplestoreerror
108 108
109 def __init__(self, svfs, path):
109 def __init__(self, repo, svfs, path):
110 self.nullid = repo.nullid
111 self._repo = repo
110 112 self._svfs = svfs
111 113 self._path = path
112 114
@@ -689,7 +691,7 def reposetup(ui, repo):
689 691
690 692 class simplestorerepo(repo.__class__):
691 693 def file(self, f):
692 return filestorage(self.svfs, f)
694 return filestorage(repo, self.svfs, f)
693 695
694 696 repo.__class__ = simplestorerepo
695 697
@@ -248,7 +248,10 def main():
248 248
249 249 # Conforms to imanifestlog.
250 250 ml = manifest.manifestlog(
251 vfs, repo, manifest.manifestrevlog(repo.svfs), repo.narrowmatch()
251 vfs,
252 repo,
253 manifest.manifestrevlog(repo.nodeconstants, repo.svfs),
254 repo.narrowmatch(),
252 255 )
253 256 checkzobject(ml)
254 257 checkzobject(repo.manifestlog)
@@ -263,7 +266,7 def main():
263 266 # Conforms to imanifestdict.
264 267 checkzobject(mctx.read())
265 268
266 mrl = manifest.manifestrevlog(vfs)
269 mrl = manifest.manifestrevlog(repo.nodeconstants, vfs)
267 270 checkzobject(mrl)
268 271
269 272 ziverify.verifyClass(repository.irevisiondelta, revlog.revlogrevisiondelta)
@@ -6,6 +6,8 import silenttestrunner
6 6 import unittest
7 7 import zlib
8 8
9 from mercurial.node import sha1nodeconstants
10
9 11 from mercurial import (
10 12 manifest as manifestmod,
11 13 match as matchmod,
@@ -436,7 +438,7 class testmanifestdict(unittest.TestCase
436 438
437 439 class testtreemanifest(unittest.TestCase, basemanifesttests):
438 440 def parsemanifest(self, text):
439 return manifestmod.treemanifest(b'', text)
441 return manifestmod.treemanifest(sha1nodeconstants, b'', text)
440 442
441 443 def testWalkSubtrees(self):
442 444 m = self.parsemanifest(A_DEEPER_MANIFEST)
General Comments 0
You need to be logged in to leave comments. Login now