9 # |
9 # |
10 # $ HGREPOFEATURES="simplestore" ./run-tests.py \ |
10 # $ HGREPOFEATURES="simplestore" ./run-tests.py \ |
11 # --extra-config-opt extensions.simplestore=`pwd`/simplestorerepo.py |
11 # --extra-config-opt extensions.simplestore=`pwd`/simplestorerepo.py |
12 |
12 |
13 from __future__ import absolute_import |
13 from __future__ import absolute_import |
|
14 |
|
15 import stat |
14 |
16 |
15 from mercurial.i18n import _ |
17 from mercurial.i18n import _ |
16 from mercurial.node import ( |
18 from mercurial.node import ( |
17 bin, |
19 bin, |
18 hex, |
20 hex, |
24 ) |
26 ) |
25 from mercurial import ( |
27 from mercurial import ( |
26 ancestor, |
28 ancestor, |
27 bundlerepo, |
29 bundlerepo, |
28 error, |
30 error, |
|
31 extensions, |
29 filelog, |
32 filelog, |
|
33 localrepo, |
30 mdiff, |
34 mdiff, |
31 pycompat, |
35 pycompat, |
32 revlog, |
36 revlog, |
|
37 store, |
33 ) |
38 ) |
34 |
39 |
35 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for |
40 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for |
36 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should |
41 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should |
37 # be specifying the version(s) of Mercurial they are tested with, or |
42 # be specifying the version(s) of Mercurial they are tested with, or |
38 # leave the attribute unspecified. |
43 # leave the attribute unspecified. |
39 testedwith = 'ships-with-hg-core' |
44 testedwith = 'ships-with-hg-core' |
|
45 |
|
46 REQUIREMENT = 'testonly-simplestore' |
40 |
47 |
41 def validatenode(node): |
48 def validatenode(node): |
42 if isinstance(node, int): |
49 if isinstance(node, int): |
43 raise ValueError('expected node; got int') |
50 raise ValueError('expected node; got int') |
44 |
51 |
579 |
586 |
580 # Purge index data starting at the requested revision. |
587 # Purge index data starting at the requested revision. |
581 self._indexdata[rev:] = [] |
588 self._indexdata[rev:] = [] |
582 self._reflectindexupdate() |
589 self._reflectindexupdate() |
583 |
590 |
|
591 def issimplestorefile(f, kind, st): |
|
592 if kind != stat.S_IFREG: |
|
593 return False |
|
594 |
|
595 if store.isrevlog(f, kind, st): |
|
596 return False |
|
597 |
|
598 # Ignore transaction undo files. |
|
599 if f.startswith('undo.'): |
|
600 return False |
|
601 |
|
602 # Otherwise assume it belongs to the simple store. |
|
603 return True |
|
604 |
|
605 class simplestore(store.encodedstore): |
|
606 def datafiles(self): |
|
607 for x in super(simplestore, self).datafiles(): |
|
608 yield x |
|
609 |
|
610 # Supplement with non-revlog files. |
|
611 extrafiles = self._walk('data', True, filefilter=issimplestorefile) |
|
612 |
|
613 for unencoded, encoded, size in extrafiles: |
|
614 try: |
|
615 unencoded = store.decodefilename(unencoded) |
|
616 except KeyError: |
|
617 unencoded = None |
|
618 |
|
619 yield unencoded, encoded, size |
|
620 |
584 def reposetup(ui, repo): |
621 def reposetup(ui, repo): |
585 if not repo.local(): |
622 if not repo.local(): |
586 return |
623 return |
587 |
624 |
588 if isinstance(repo, bundlerepo.bundlerepository): |
625 if isinstance(repo, bundlerepo.bundlerepository): |
591 class simplestorerepo(repo.__class__): |
628 class simplestorerepo(repo.__class__): |
592 def file(self, f): |
629 def file(self, f): |
593 return filestorage(self.svfs, f) |
630 return filestorage(self.svfs, f) |
594 |
631 |
595 repo.__class__ = simplestorerepo |
632 repo.__class__ = simplestorerepo |
|
633 |
|
634 def featuresetup(ui, supported): |
|
635 supported.add(REQUIREMENT) |
|
636 |
|
637 def newreporequirements(orig, repo): |
|
638 """Modifies default requirements for new repos to use the simple store.""" |
|
639 requirements = orig(repo) |
|
640 |
|
641 # These requirements are only used to affect creation of the store |
|
642 # object. We have our own store. So we can remove them. |
|
643 # TODO do this once we feel like taking the test hit. |
|
644 #if 'fncache' in requirements: |
|
645 # requirements.remove('fncache') |
|
646 #if 'dotencode' in requirements: |
|
647 # requirements.remove('dotencode') |
|
648 |
|
649 requirements.add(REQUIREMENT) |
|
650 |
|
651 return requirements |
|
652 |
|
653 def makestore(orig, requirements, path, vfstype): |
|
654 if REQUIREMENT not in requirements: |
|
655 return orig(requirements, path, vfstype) |
|
656 |
|
657 return simplestore(path, vfstype) |
|
658 |
|
659 def extsetup(ui): |
|
660 localrepo.featuresetupfuncs.add(featuresetup) |
|
661 |
|
662 extensions.wrapfunction(localrepo, 'newreporequirements', |
|
663 newreporequirements) |
|
664 extensions.wrapfunction(store, 'store', makestore) |