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