author | Augie Fackler <augie@google.com> |
Sat, 30 Sep 2017 12:57:00 -0400 | |
changeset 34386 | 44841a4d0efb |
parent 32813 | 6d73b7ff8f92 |
child 34771 | 28b7034a916a |
permissions | -rw-r--r-- |
25752
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
1 |
# extension to emulate invoking 'dirstate.write()' at the time |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
2 |
# specified by '[fakedirstatewritetime] fakenow', only when |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
3 |
# 'dirstate.write()' is invoked via functions below: |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
4 |
# |
32812
add613cddcb6
workingctx: factor out post-status dirstate fixup
Siddharth Agarwal <sid0@fb.com>
parents:
32372
diff
changeset
|
5 |
# - 'workingctx._poststatusfixup()' (= 'repo.status()') |
25752
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
6 |
# - 'committablectx.markcommitted()' |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
7 |
|
27283
b38adef652fe
tests/fakedirstatewritetime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26634
diff
changeset
|
8 |
from __future__ import absolute_import |
b38adef652fe
tests/fakedirstatewritetime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26634
diff
changeset
|
9 |
|
b38adef652fe
tests/fakedirstatewritetime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26634
diff
changeset
|
10 |
from mercurial import ( |
b38adef652fe
tests/fakedirstatewritetime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26634
diff
changeset
|
11 |
context, |
b38adef652fe
tests/fakedirstatewritetime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26634
diff
changeset
|
12 |
dirstate, |
b38adef652fe
tests/fakedirstatewritetime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26634
diff
changeset
|
13 |
extensions, |
32372
df448de7cf3b
parsers: switch to policy importer
Yuya Nishihara <yuya@tcha.org>
parents:
27283
diff
changeset
|
14 |
policy, |
27283
b38adef652fe
tests/fakedirstatewritetime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26634
diff
changeset
|
15 |
util, |
b38adef652fe
tests/fakedirstatewritetime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26634
diff
changeset
|
16 |
) |
25752
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
17 |
|
32372
df448de7cf3b
parsers: switch to policy importer
Yuya Nishihara <yuya@tcha.org>
parents:
27283
diff
changeset
|
18 |
parsers = policy.importmod(r'parsers') |
df448de7cf3b
parsers: switch to policy importer
Yuya Nishihara <yuya@tcha.org>
parents:
27283
diff
changeset
|
19 |
|
25752
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
20 |
def pack_dirstate(fakenow, orig, dmap, copymap, pl, now): |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
21 |
# execute what original parsers.pack_dirstate should do actually |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
22 |
# for consistency |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
23 |
actualnow = int(now) |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
24 |
for f, e in dmap.iteritems(): |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
25 |
if e[0] == 'n' and e[3] == actualnow: |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
26 |
e = parsers.dirstatetuple(e[0], e[1], e[2], -1) |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
27 |
dmap[f] = e |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
28 |
|
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
29 |
return orig(dmap, copymap, pl, fakenow) |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
30 |
|
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
31 |
def fakewrite(ui, func): |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
32 |
# fake "now" of 'pack_dirstate' only if it is invoked while 'func' |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
33 |
|
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
34 |
fakenow = ui.config('fakedirstatewritetime', 'fakenow') |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
35 |
if not fakenow: |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
36 |
# Execute original one, if fakenow isn't configured. This is |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
37 |
# useful to prevent subrepos from executing replaced one, |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
38 |
# because replacing 'parsers.pack_dirstate' is also effective |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
39 |
# in subrepos. |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
40 |
return func() |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
41 |
|
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
42 |
# parsing 'fakenow' in YYYYmmddHHMM format makes comparison between |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
43 |
# 'fakenow' value and 'touch -t YYYYmmddHHMM' argument easy |
26630
3111b45a2bbf
parsers: make pack_dirstate take now in integer for consistency
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25752
diff
changeset
|
44 |
fakenow = util.parsedate(fakenow, ['%Y%m%d%H%M'])[0] |
25752
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
45 |
|
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
46 |
orig_pack_dirstate = parsers.pack_dirstate |
26634
09bb1ee7e73e
dirstate: make writing in-memory changes aware of transaction activity
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26630
diff
changeset
|
47 |
orig_dirstate_getfsnow = dirstate._getfsnow |
25752
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
48 |
wrapper = lambda *args: pack_dirstate(fakenow, orig_pack_dirstate, *args) |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
49 |
|
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
50 |
parsers.pack_dirstate = wrapper |
26634
09bb1ee7e73e
dirstate: make writing in-memory changes aware of transaction activity
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26630
diff
changeset
|
51 |
dirstate._getfsnow = lambda *args: fakenow |
25752
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
52 |
try: |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
53 |
return func() |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
54 |
finally: |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
55 |
parsers.pack_dirstate = orig_pack_dirstate |
26634
09bb1ee7e73e
dirstate: make writing in-memory changes aware of transaction activity
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26630
diff
changeset
|
56 |
dirstate._getfsnow = orig_dirstate_getfsnow |
25752
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
57 |
|
32813
6d73b7ff8f92
workingctx: also pass status tuple into poststatusfixup
Siddharth Agarwal <sid0@fb.com>
parents:
32812
diff
changeset
|
58 |
def _poststatusfixup(orig, workingctx, status, fixup): |
25752
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
59 |
ui = workingctx.repo().ui |
32813
6d73b7ff8f92
workingctx: also pass status tuple into poststatusfixup
Siddharth Agarwal <sid0@fb.com>
parents:
32812
diff
changeset
|
60 |
return fakewrite(ui, lambda : orig(workingctx, status, fixup)) |
25752
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
61 |
|
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
62 |
def markcommitted(orig, committablectx, node): |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
63 |
ui = committablectx.repo().ui |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
64 |
return fakewrite(ui, lambda : orig(committablectx, node)) |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
65 |
|
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
66 |
def extsetup(ui): |
32812
add613cddcb6
workingctx: factor out post-status dirstate fixup
Siddharth Agarwal <sid0@fb.com>
parents:
32372
diff
changeset
|
67 |
extensions.wrapfunction(context.workingctx, '_poststatusfixup', |
add613cddcb6
workingctx: factor out post-status dirstate fixup
Siddharth Agarwal <sid0@fb.com>
parents:
32372
diff
changeset
|
68 |
_poststatusfixup) |
25752
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
69 |
extensions.wrapfunction(context.committablectx, 'markcommitted', |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
70 |
markcommitted) |