tests/fakedirstatewritetime.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Tue, 10 Oct 2023 18:02:20 +0200
changeset 51050 127656e0b97b
parent 48966 6000f5b25c9b
permissions -rw-r--r--
revlog: use the new Config classes in _testrevlog the mock object need to follow the new interface. We allow ourself a small hacky import since this is testing code. The legacy attribute are still here because some code still use them. We will drop them when this code is updated.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
#
32831
add613cddcb6 workingctx: factor out post-status dirstate fixup
Siddharth Agarwal <sid0@fb.com>
parents: 32411
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
b38adef652fe tests/fakedirstatewritetime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26634
diff changeset
     9
from mercurial import (
b38adef652fe tests/fakedirstatewritetime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26634
diff changeset
    10
    context,
47506
8b7e47802deb dirstate: split dirstatemap in its own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45957
diff changeset
    11
    dirstatemap as dirstatemapmod,
27283
b38adef652fe tests/fakedirstatewritetime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26634
diff changeset
    12
    extensions,
32411
df448de7cf3b parsers: switch to policy importer
Yuya Nishihara <yuya@tcha.org>
parents: 27283
diff changeset
    13
    policy,
34771
28b7034a916a configitems: register the test 'fakedirstatewritetime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents: 32832
diff changeset
    14
    registrar,
27283
b38adef652fe tests/fakedirstatewritetime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26634
diff changeset
    15
)
48271
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
    16
from mercurial.dirstateutils import timestamp
36636
c6061cadb400 util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents: 36360
diff changeset
    17
from mercurial.utils import dateutil
25752
815df73abf12 tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    18
42331
9c6c0f736e1d rust-dirstate: call parse/pack bindings from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42322
diff changeset
    19
try:
9c6c0f736e1d rust-dirstate: call parse/pack bindings from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42322
diff changeset
    20
    from mercurial import rustext
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42763
diff changeset
    21
42331
9c6c0f736e1d rust-dirstate: call parse/pack bindings from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42322
diff changeset
    22
    rustext.__name__  # force actual import (see hgdemandimport)
9c6c0f736e1d rust-dirstate: call parse/pack bindings from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42322
diff changeset
    23
except ImportError:
9c6c0f736e1d rust-dirstate: call parse/pack bindings from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42322
diff changeset
    24
    rustext = None
9c6c0f736e1d rust-dirstate: call parse/pack bindings from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42322
diff changeset
    25
34771
28b7034a916a configitems: register the test 'fakedirstatewritetime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents: 32832
diff changeset
    26
configtable = {}
28b7034a916a configitems: register the test 'fakedirstatewritetime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents: 32832
diff changeset
    27
configitem = registrar.configitem(configtable)
28b7034a916a configitems: register the test 'fakedirstatewritetime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents: 32832
diff changeset
    28
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42763
diff changeset
    29
configitem(
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43554
diff changeset
    30
    b'fakedirstatewritetime',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43554
diff changeset
    31
    b'fakenow',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43554
diff changeset
    32
    default=None,
34771
28b7034a916a configitems: register the test 'fakedirstatewritetime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents: 32832
diff changeset
    33
)
28b7034a916a configitems: register the test 'fakedirstatewritetime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents: 32832
diff changeset
    34
43554
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    35
parsers = policy.importmod('parsers')
48042
1194394510ba rust: Remove the `rustext.parsers` module
Simon Sapin <simon.sapin@octobus.net>
parents: 47674
diff changeset
    36
has_rust_dirstate = policy.importrust('dirstate') is not None
32411
df448de7cf3b parsers: switch to policy importer
Yuya Nishihara <yuya@tcha.org>
parents: 27283
diff changeset
    37
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42763
diff changeset
    38
48440
434de12918fd dirstate: remove need_delay logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48427
diff changeset
    39
def pack_dirstate(orig, dmap, copymap, pl):
434de12918fd dirstate: remove need_delay logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48427
diff changeset
    40
    return orig(dmap, copymap, pl)
25752
815df73abf12 tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    41
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42763
diff changeset
    42
25752
815df73abf12 tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    43
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
    44
    # 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
    45
36357
ac04f17b7041 py3: add b'' prefixes in fakedirstatewritetime.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34771
diff changeset
    46
    fakenow = ui.config(b'fakedirstatewritetime', b'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
    47
    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
    48
        # 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
    49
        # 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
    50
        # 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
    51
        # 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
    52
        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
    53
815df73abf12 tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    54
    # 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
    55
    # 'fakenow' value and 'touch -t YYYYmmddHHMM' argument easy
36636
c6061cadb400 util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents: 36360
diff changeset
    56
    fakenow = dateutil.parsedate(fakenow, [b'%Y%m%d%H%M'])[0]
48446
111098af6356 dirstate-item: add a "second_ambiguous` flag in the mtime tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48440
diff changeset
    57
    fakenow = timestamp.timestamp((fakenow, 0, False))
25752
815df73abf12 tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    58
48042
1194394510ba rust: Remove the `rustext.parsers` module
Simon Sapin <simon.sapin@octobus.net>
parents: 47674
diff changeset
    59
    if has_rust_dirstate:
42763
760a7851e9ba rust-parsers: move parser bindings to their own file and Python module
Raphaël Gomès <rgomes@octobus.net>
parents: 42331
diff changeset
    60
        # The Rust implementation does not use public parse/pack dirstate
760a7851e9ba rust-parsers: move parser bindings to their own file and Python module
Raphaël Gomès <rgomes@octobus.net>
parents: 42331
diff changeset
    61
        # to prevent conversion round-trips
47506
8b7e47802deb dirstate: split dirstatemap in its own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45957
diff changeset
    62
        orig_dirstatemap_write = dirstatemapmod.dirstatemap.write
48440
434de12918fd dirstate: remove need_delay logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48427
diff changeset
    63
        wrapper = lambda self, tr, st: orig_dirstatemap_write(self, tr, st)
47506
8b7e47802deb dirstate: split dirstatemap in its own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45957
diff changeset
    64
        dirstatemapmod.dirstatemap.write = wrapper
42331
9c6c0f736e1d rust-dirstate: call parse/pack bindings from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42322
diff changeset
    65
48427
08b060abd658 dirstate: move "get fs now" in the timestamp utility module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48271
diff changeset
    66
    orig_get_fs_now = timestamp.get_fs_now
48440
434de12918fd dirstate: remove need_delay logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48427
diff changeset
    67
    wrapper = lambda *args: pack_dirstate(orig_pack_dirstate, *args)
25752
815df73abf12 tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    68
42763
760a7851e9ba rust-parsers: move parser bindings to their own file and Python module
Raphaël Gomès <rgomes@octobus.net>
parents: 42331
diff changeset
    69
    orig_module = parsers
760a7851e9ba rust-parsers: move parser bindings to their own file and Python module
Raphaël Gomès <rgomes@octobus.net>
parents: 42331
diff changeset
    70
    orig_pack_dirstate = parsers.pack_dirstate
760a7851e9ba rust-parsers: move parser bindings to their own file and Python module
Raphaël Gomès <rgomes@octobus.net>
parents: 42331
diff changeset
    71
42331
9c6c0f736e1d rust-dirstate: call parse/pack bindings from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42322
diff changeset
    72
    orig_module.pack_dirstate = wrapper
48440
434de12918fd dirstate: remove need_delay logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48427
diff changeset
    73
    timestamp.get_fs_now = (
434de12918fd dirstate: remove need_delay logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48427
diff changeset
    74
        lambda *args: fakenow
434de12918fd dirstate: remove need_delay logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48427
diff changeset
    75
    )  # XXX useless for this purpose now
25752
815df73abf12 tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    76
    try:
815df73abf12 tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    77
        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
    78
    finally:
42331
9c6c0f736e1d rust-dirstate: call parse/pack bindings from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42322
diff changeset
    79
        orig_module.pack_dirstate = orig_pack_dirstate
48427
08b060abd658 dirstate: move "get fs now" in the timestamp utility module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48271
diff changeset
    80
        timestamp.get_fs_now = orig_get_fs_now
48042
1194394510ba rust: Remove the `rustext.parsers` module
Simon Sapin <simon.sapin@octobus.net>
parents: 47674
diff changeset
    81
        if has_rust_dirstate:
47506
8b7e47802deb dirstate: split dirstatemap in its own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45957
diff changeset
    82
            dirstatemapmod.dirstatemap.write = orig_dirstatemap_write
25752
815df73abf12 tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    83
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42763
diff changeset
    84
32832
6d73b7ff8f92 workingctx: also pass status tuple into poststatusfixup
Siddharth Agarwal <sid0@fb.com>
parents: 32831
diff changeset
    85
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
    86
    ui = workingctx.repo().ui
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42763
diff changeset
    87
    return fakewrite(ui, lambda: orig(workingctx, status, fixup))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42763
diff changeset
    88
25752
815df73abf12 tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    89
815df73abf12 tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    90
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
    91
    ui = committablectx.repo().ui
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42763
diff changeset
    92
    return fakewrite(ui, lambda: orig(committablectx, node))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42763
diff changeset
    93
25752
815df73abf12 tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    94
815df73abf12 tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    95
def extsetup(ui):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42763
diff changeset
    96
    extensions.wrapfunction(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42763
diff changeset
    97
        context.workingctx, '_poststatusfixup', _poststatusfixup
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42763
diff changeset
    98
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42763
diff changeset
    99
    extensions.wrapfunction(context.workingctx, 'markcommitted', markcommitted)