annotate tests/mocktime.py @ 39548:7ce9dea3a14a

localrepo: move repo creation logic out of localrepository.__init__ (API) It has long bothered me that local repository creation is handled as part of localrepository.__init__. Upcoming changes I want to make around how repositories are initialized and instantiated will make the continued existence of repository creation code in localrepository.__init__ even more awkward. localrepository instances are almost never constructed directly: instead, callers are supposed to go through hg.repository() to obtain a handle on a repository. And hg.repository() calls localrepo.instance() to return a new repo instance. This commit teaches localrepo.instance() to handle the create=True logic. Most of the code for repo construction has been moved to a standalone function. This allows extensions to monkeypatch the function to further customize freshly-created repositories. A few calls to localrepo.localrepository.__init__ that were passing create=True were converted to call localrepo.instance(). .. api:: local repo creation moved out of constructor ``localrepo.localrepository.__init__`` no longer accepts a ``create`` argument to create a new repository. New repository creation is now performed as part of ``localrepo.instance()`` and the bulk of the work is performed by ``localrepo.createrepository()``. Differential Revision: https://phab.mercurial-scm.org/D4534
author Gregory Szorc <gregory.szorc@gmail.com>
date Tue, 11 Sep 2018 13:46:59 -0700
parents 12b355964de8
children 2372284d9457
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
34316
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
1 from __future__ import absolute_import
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
2
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
3 import os
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
4 import time
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
5
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
6 class mocktime(object):
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
7 def __init__(self, increment):
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
8 self.time = 0
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
9 self.increment = [float(s) for s in increment.split()]
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
10 self.pos = 0
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
11
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
12 def __call__(self):
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
13 self.time += self.increment[self.pos % len(self.increment)]
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
14 self.pos += 1
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
15 return self.time
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
16
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
17 def uisetup(ui):
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
18 time.time = mocktime(os.environ.get('MOCKTIME', '0.1'))