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