##// END OF EJS Templates
configitems: register the test 'fakedirstatewritetime.fakenow' config
Boris Feld -
r34772:28b7034a default
parent child Browse files
Show More
@@ -1,70 +1,78
1 1 # extension to emulate invoking 'dirstate.write()' at the time
2 2 # specified by '[fakedirstatewritetime] fakenow', only when
3 3 # 'dirstate.write()' is invoked via functions below:
4 4 #
5 5 # - 'workingctx._poststatusfixup()' (= 'repo.status()')
6 6 # - 'committablectx.markcommitted()'
7 7
8 8 from __future__ import absolute_import
9 9
10 10 from mercurial import (
11 11 context,
12 12 dirstate,
13 13 extensions,
14 14 policy,
15 registrar,
15 16 util,
16 17 )
17 18
19 configtable = {}
20 configitem = registrar.configitem(configtable)
21
22 configitem('fakedirstatewritetime', 'fakenow',
23 default=None,
24 )
25
18 26 parsers = policy.importmod(r'parsers')
19 27
20 28 def pack_dirstate(fakenow, orig, dmap, copymap, pl, now):
21 29 # execute what original parsers.pack_dirstate should do actually
22 30 # for consistency
23 31 actualnow = int(now)
24 32 for f, e in dmap.iteritems():
25 33 if e[0] == 'n' and e[3] == actualnow:
26 34 e = parsers.dirstatetuple(e[0], e[1], e[2], -1)
27 35 dmap[f] = e
28 36
29 37 return orig(dmap, copymap, pl, fakenow)
30 38
31 39 def fakewrite(ui, func):
32 40 # fake "now" of 'pack_dirstate' only if it is invoked while 'func'
33 41
34 42 fakenow = ui.config('fakedirstatewritetime', 'fakenow')
35 43 if not fakenow:
36 44 # Execute original one, if fakenow isn't configured. This is
37 45 # useful to prevent subrepos from executing replaced one,
38 46 # because replacing 'parsers.pack_dirstate' is also effective
39 47 # in subrepos.
40 48 return func()
41 49
42 50 # parsing 'fakenow' in YYYYmmddHHMM format makes comparison between
43 51 # 'fakenow' value and 'touch -t YYYYmmddHHMM' argument easy
44 52 fakenow = util.parsedate(fakenow, ['%Y%m%d%H%M'])[0]
45 53
46 54 orig_pack_dirstate = parsers.pack_dirstate
47 55 orig_dirstate_getfsnow = dirstate._getfsnow
48 56 wrapper = lambda *args: pack_dirstate(fakenow, orig_pack_dirstate, *args)
49 57
50 58 parsers.pack_dirstate = wrapper
51 59 dirstate._getfsnow = lambda *args: fakenow
52 60 try:
53 61 return func()
54 62 finally:
55 63 parsers.pack_dirstate = orig_pack_dirstate
56 64 dirstate._getfsnow = orig_dirstate_getfsnow
57 65
58 66 def _poststatusfixup(orig, workingctx, status, fixup):
59 67 ui = workingctx.repo().ui
60 68 return fakewrite(ui, lambda : orig(workingctx, status, fixup))
61 69
62 70 def markcommitted(orig, committablectx, node):
63 71 ui = committablectx.repo().ui
64 72 return fakewrite(ui, lambda : orig(committablectx, node))
65 73
66 74 def extsetup(ui):
67 75 extensions.wrapfunction(context.workingctx, '_poststatusfixup',
68 76 _poststatusfixup)
69 77 extensions.wrapfunction(context.committablectx, 'markcommitted',
70 78 markcommitted)
General Comments 0
You need to be logged in to leave comments. Login now