Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/manifest.py @ 38532:c82ea938efbb
repository: define manifest interfaces
The long march towards declaring interfaces for repository
primitives continues.
This commit essentially defines interfaces based on the following
types:
* manifest.manifestdict -> imanifestdict
* manifest.manifestlog -> imanifestlog
* manifest.memmanifestctx -> imanifestrevisionwritable
* manifest.manifestctx -> imanifestrevisionstored
* manifest.memtreemanifestctx -> imanifestrevisionwritable
* manifest.treemanifestctx -> imanifestrevisionstored
* util.dirs -> idirs
The interfaces are thoroughly documented. Their documentation is
now better than the documentation in manifest.py in many cases.
With the exception of util.dirs, classes have been annotated with
their interfaces. (I didn't feel like util.dirs needed the
proper interface treatment.)
Tests have been added demonstrating that all classes and instances
conform to their interfaces.
This work was much easier than filelogs. That's because Durham
did an excellent job formalizing the manifest API a while back.
There are still some minor kludges with the interfaces that should
probably be addressed. But the primary goal with interface
declarations is getting something established. Once we have an
interface, we can modify it later easily enough.
Differential Revision: https://phab.mercurial-scm.org/D3869
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sat, 30 Jun 2018 18:34:33 -0700 |
parents | 561a450c7b64 |
children | f2f9bacf0587 |
comparison
equal
deleted
inserted
replaced
38531:1ad873c3e4a4 | 38532:c82ea938efbb |
---|---|
19 from . import ( | 19 from . import ( |
20 error, | 20 error, |
21 mdiff, | 21 mdiff, |
22 policy, | 22 policy, |
23 pycompat, | 23 pycompat, |
24 repository, | |
24 revlog, | 25 revlog, |
25 util, | 26 util, |
27 ) | |
28 from .utils import ( | |
29 interfaceutil, | |
26 ) | 30 ) |
27 | 31 |
28 parsers = policy.importmod(r'parsers') | 32 parsers = policy.importmod(r'parsers') |
29 propertycache = util.propertycache | 33 propertycache = util.propertycache |
30 | 34 |
361 try: | 365 try: |
362 _lazymanifest = parsers.lazymanifest | 366 _lazymanifest = parsers.lazymanifest |
363 except AttributeError: | 367 except AttributeError: |
364 pass | 368 pass |
365 | 369 |
370 @interfaceutil.implementer(repository.imanifestdict) | |
366 class manifestdict(object): | 371 class manifestdict(object): |
367 def __init__(self, data=''): | 372 def __init__(self, data=''): |
368 self._lm = _lazymanifest(data) | 373 self._lm = _lazymanifest(data) |
369 | 374 |
370 def __getitem__(self, key): | 375 def __getitem__(self, key): |
1260 | 1265 |
1261 # Save nodeid so parent manifest can calculate its nodeid | 1266 # Save nodeid so parent manifest can calculate its nodeid |
1262 m.setnode(n) | 1267 m.setnode(n) |
1263 return n | 1268 return n |
1264 | 1269 |
1270 @interfaceutil.implementer(repository.imanifestlog) | |
1265 class manifestlog(object): | 1271 class manifestlog(object): |
1266 """A collection class representing the collection of manifest snapshots | 1272 """A collection class representing the collection of manifest snapshots |
1267 referenced by commits in the repository. | 1273 referenced by commits in the repository. |
1268 | 1274 |
1269 In this situation, 'manifest' refers to the abstract concept of a snapshot | 1275 In this situation, 'manifest' refers to the abstract concept of a snapshot |
1340 | 1346 |
1341 def clearcaches(self): | 1347 def clearcaches(self): |
1342 self._dirmancache.clear() | 1348 self._dirmancache.clear() |
1343 self._revlog.clearcaches() | 1349 self._revlog.clearcaches() |
1344 | 1350 |
1351 @interfaceutil.implementer(repository.imanifestrevisionwritable) | |
1345 class memmanifestctx(object): | 1352 class memmanifestctx(object): |
1346 def __init__(self, manifestlog): | 1353 def __init__(self, manifestlog): |
1347 self._manifestlog = manifestlog | 1354 self._manifestlog = manifestlog |
1348 self._manifestdict = manifestdict() | 1355 self._manifestdict = manifestdict() |
1349 | 1356 |
1363 | 1370 |
1364 def write(self, transaction, link, p1, p2, added, removed): | 1371 def write(self, transaction, link, p1, p2, added, removed): |
1365 return self._revlog().add(self._manifestdict, transaction, link, p1, p2, | 1372 return self._revlog().add(self._manifestdict, transaction, link, p1, p2, |
1366 added, removed) | 1373 added, removed) |
1367 | 1374 |
1375 @interfaceutil.implementer(repository.imanifestrevisionstored) | |
1368 class manifestctx(object): | 1376 class manifestctx(object): |
1369 """A class representing a single revision of a manifest, including its | 1377 """A class representing a single revision of a manifest, including its |
1370 contents, its parent revs, and its linkrev. | 1378 contents, its parent revs, and its linkrev. |
1371 """ | 1379 """ |
1372 def __init__(self, manifestlog, node): | 1380 def __init__(self, manifestlog, node): |
1439 return manifestdict(d) | 1447 return manifestdict(d) |
1440 | 1448 |
1441 def find(self, key): | 1449 def find(self, key): |
1442 return self.read().find(key) | 1450 return self.read().find(key) |
1443 | 1451 |
1452 @interfaceutil.implementer(repository.imanifestrevisionwritable) | |
1444 class memtreemanifestctx(object): | 1453 class memtreemanifestctx(object): |
1445 def __init__(self, manifestlog, dir=''): | 1454 def __init__(self, manifestlog, dir=''): |
1446 self._manifestlog = manifestlog | 1455 self._manifestlog = manifestlog |
1447 self._dir = dir | 1456 self._dir = dir |
1448 self._treemanifest = treemanifest() | 1457 self._treemanifest = treemanifest() |
1465 def readtree(dir, node): | 1474 def readtree(dir, node): |
1466 return self._manifestlog.get(dir, node).read() | 1475 return self._manifestlog.get(dir, node).read() |
1467 return self._revlog().add(self._treemanifest, transaction, link, p1, p2, | 1476 return self._revlog().add(self._treemanifest, transaction, link, p1, p2, |
1468 added, removed, readtree=readtree) | 1477 added, removed, readtree=readtree) |
1469 | 1478 |
1479 @interfaceutil.implementer(repository.imanifestrevisionstored) | |
1470 class treemanifestctx(object): | 1480 class treemanifestctx(object): |
1471 def __init__(self, manifestlog, dir, node): | 1481 def __init__(self, manifestlog, dir, node): |
1472 self._manifestlog = manifestlog | 1482 self._manifestlog = manifestlog |
1473 self._dir = dir | 1483 self._dir = dir |
1474 self._data = None | 1484 self._data = None |