comparison tests/fakedirstatewritetime.py @ 42304:9c6c0f736e1d

rust-dirstate: call parse/pack bindings from Python A future patch will need to address the issue of Rust module policy, to avoid having ugly duplicate imports and conditionals all over the place. As the rewrite of dirstate in Rust progresses, we will need fewer of those "contact points". Differential Revision: https://phab.mercurial-scm.org/D6350
author Raphaël Gomès <rgomes@octobus.net>
date Mon, 06 May 2019 22:51:10 +0200
parents fdd4d668ceb5
children 760a7851e9ba
comparison
equal deleted inserted replaced
42303:e240bec26626 42304:9c6c0f736e1d
13 extensions, 13 extensions,
14 policy, 14 policy,
15 registrar, 15 registrar,
16 ) 16 )
17 from mercurial.utils import dateutil 17 from mercurial.utils import dateutil
18
19 try:
20 from mercurial import rustext
21 rustext.__name__ # force actual import (see hgdemandimport)
22 except ImportError:
23 rustext = None
18 24
19 configtable = {} 25 configtable = {}
20 configitem = registrar.configitem(configtable) 26 configitem = registrar.configitem(configtable)
21 27
22 configitem(b'fakedirstatewritetime', b'fakenow', 28 configitem(b'fakedirstatewritetime', b'fakenow',
49 55
50 # parsing 'fakenow' in YYYYmmddHHMM format makes comparison between 56 # parsing 'fakenow' in YYYYmmddHHMM format makes comparison between
51 # 'fakenow' value and 'touch -t YYYYmmddHHMM' argument easy 57 # 'fakenow' value and 'touch -t YYYYmmddHHMM' argument easy
52 fakenow = dateutil.parsedate(fakenow, [b'%Y%m%d%H%M'])[0] 58 fakenow = dateutil.parsedate(fakenow, [b'%Y%m%d%H%M'])[0]
53 59
54 orig_pack_dirstate = parsers.pack_dirstate 60 if rustext is not None:
61 orig_module = rustext.dirstate
62 orig_pack_dirstate = rustext.dirstate.pack_dirstate
63 else:
64 orig_module = parsers
65 orig_pack_dirstate = parsers.pack_dirstate
66
55 orig_dirstate_getfsnow = dirstate._getfsnow 67 orig_dirstate_getfsnow = dirstate._getfsnow
56 wrapper = lambda *args: pack_dirstate(fakenow, orig_pack_dirstate, *args) 68 wrapper = lambda *args: pack_dirstate(fakenow, orig_pack_dirstate, *args)
57 69
58 parsers.pack_dirstate = wrapper 70 orig_module.pack_dirstate = wrapper
59 dirstate._getfsnow = lambda *args: fakenow 71 dirstate._getfsnow = lambda *args: fakenow
60 try: 72 try:
61 return func() 73 return func()
62 finally: 74 finally:
63 parsers.pack_dirstate = orig_pack_dirstate 75 orig_module.pack_dirstate = orig_pack_dirstate
64 dirstate._getfsnow = orig_dirstate_getfsnow 76 dirstate._getfsnow = orig_dirstate_getfsnow
65 77
66 def _poststatusfixup(orig, workingctx, status, fixup): 78 def _poststatusfixup(orig, workingctx, status, fixup):
67 ui = workingctx.repo().ui 79 ui = workingctx.repo().ui
68 return fakewrite(ui, lambda : orig(workingctx, status, fixup)) 80 return fakewrite(ui, lambda : orig(workingctx, status, fixup))