Mercurial > hg
comparison tests/fakedirstatewritetime.py @ 42747:760a7851e9ba
rust-parsers: move parser bindings to their own file and Python module
This tidies up the Rust side while simplifying the Python side.
Differential Revision: https://phab.mercurial-scm.org/D6627
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Wed, 10 Jul 2019 10:16:28 +0200 |
parents | 9c6c0f736e1d |
children | 2372284d9457 |
comparison
equal
deleted
inserted
replaced
42746:b3518b0baa47 | 42747:760a7851e9ba |
---|---|
28 configitem(b'fakedirstatewritetime', b'fakenow', | 28 configitem(b'fakedirstatewritetime', b'fakenow', |
29 default=None, | 29 default=None, |
30 ) | 30 ) |
31 | 31 |
32 parsers = policy.importmod(r'parsers') | 32 parsers = policy.importmod(r'parsers') |
33 rustmod = policy.importrust(r'parsers') | |
33 | 34 |
34 def pack_dirstate(fakenow, orig, dmap, copymap, pl, now): | 35 def pack_dirstate(fakenow, orig, dmap, copymap, pl, now): |
35 # execute what original parsers.pack_dirstate should do actually | 36 # execute what original parsers.pack_dirstate should do actually |
36 # for consistency | 37 # for consistency |
37 actualnow = int(now) | 38 actualnow = int(now) |
55 | 56 |
56 # parsing 'fakenow' in YYYYmmddHHMM format makes comparison between | 57 # parsing 'fakenow' in YYYYmmddHHMM format makes comparison between |
57 # 'fakenow' value and 'touch -t YYYYmmddHHMM' argument easy | 58 # 'fakenow' value and 'touch -t YYYYmmddHHMM' argument easy |
58 fakenow = dateutil.parsedate(fakenow, [b'%Y%m%d%H%M'])[0] | 59 fakenow = dateutil.parsedate(fakenow, [b'%Y%m%d%H%M'])[0] |
59 | 60 |
60 if rustext is not None: | 61 if rustmod is not None: |
61 orig_module = rustext.dirstate | 62 # The Rust implementation does not use public parse/pack dirstate |
62 orig_pack_dirstate = rustext.dirstate.pack_dirstate | 63 # to prevent conversion round-trips |
63 else: | 64 orig_dirstatemap_write = dirstate.dirstatemap.write |
64 orig_module = parsers | 65 wrapper = lambda self, st, now: orig_dirstatemap_write(self, |
65 orig_pack_dirstate = parsers.pack_dirstate | 66 st, |
67 fakenow) | |
68 dirstate.dirstatemap.write = wrapper | |
66 | 69 |
67 orig_dirstate_getfsnow = dirstate._getfsnow | 70 orig_dirstate_getfsnow = dirstate._getfsnow |
68 wrapper = lambda *args: pack_dirstate(fakenow, orig_pack_dirstate, *args) | 71 wrapper = lambda *args: pack_dirstate(fakenow, orig_pack_dirstate, *args) |
72 | |
73 orig_module = parsers | |
74 orig_pack_dirstate = parsers.pack_dirstate | |
69 | 75 |
70 orig_module.pack_dirstate = wrapper | 76 orig_module.pack_dirstate = wrapper |
71 dirstate._getfsnow = lambda *args: fakenow | 77 dirstate._getfsnow = lambda *args: fakenow |
72 try: | 78 try: |
73 return func() | 79 return func() |
74 finally: | 80 finally: |
75 orig_module.pack_dirstate = orig_pack_dirstate | 81 orig_module.pack_dirstate = orig_pack_dirstate |
76 dirstate._getfsnow = orig_dirstate_getfsnow | 82 dirstate._getfsnow = orig_dirstate_getfsnow |
83 if rustmod is not None: | |
84 dirstate.dirstatemap.write = orig_dirstatemap_write | |
77 | 85 |
78 def _poststatusfixup(orig, workingctx, status, fixup): | 86 def _poststatusfixup(orig, workingctx, status, fixup): |
79 ui = workingctx.repo().ui | 87 ui = workingctx.repo().ui |
80 return fakewrite(ui, lambda : orig(workingctx, status, fixup)) | 88 return fakewrite(ui, lambda : orig(workingctx, status, fixup)) |
81 | 89 |