tests/fakedirstatewritetime.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Fri, 02 Jul 2021 02:27:48 +0200
changeset 47501 8b7e47802deb
parent 45942 89a2afe31e82
child 47539 84391ddf4c78
permissions -rw-r--r--
dirstate: split dirstatemap in its own file The dirstate file is large enough and the dirstatemap is quite insulated logic already. Differential Revision: https://phab.mercurial-scm.org/D10934
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
#
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,
47501
8b7e47802deb dirstate: split dirstatemap in its own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45942
diff changeset
    13
    dirstatemap as dirstatemapmod,
27283
b38adef652fe tests/fakedirstatewritetime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26634
diff changeset
    14
    extensions,
32372
df448de7cf3b parsers: switch to policy importer
Yuya Nishihara <yuya@tcha.org>
parents: 27283
diff changeset
    15
    policy,
34771
28b7034a916a configitems: register the test 'fakedirstatewritetime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents: 32813
diff changeset
    16
    registrar,
27283
b38adef652fe tests/fakedirstatewritetime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26634
diff changeset
    17
)
36607
c6061cadb400 util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents: 36327
diff changeset
    18
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
    19
42304
9c6c0f736e1d rust-dirstate: call parse/pack bindings from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42295
diff changeset
    20
try:
9c6c0f736e1d rust-dirstate: call parse/pack bindings from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42295
diff changeset
    21
    from mercurial import rustext
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42747
diff changeset
    22
42304
9c6c0f736e1d rust-dirstate: call parse/pack bindings from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42295
diff changeset
    23
    rustext.__name__  # force actual import (see hgdemandimport)
9c6c0f736e1d rust-dirstate: call parse/pack bindings from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42295
diff changeset
    24
except ImportError:
9c6c0f736e1d rust-dirstate: call parse/pack bindings from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42295
diff changeset
    25
    rustext = None
9c6c0f736e1d rust-dirstate: call parse/pack bindings from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42295
diff changeset
    26
34771
28b7034a916a configitems: register the test 'fakedirstatewritetime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents: 32813
diff changeset
    27
configtable = {}
28b7034a916a configitems: register the test 'fakedirstatewritetime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents: 32813
diff changeset
    28
configitem = registrar.configitem(configtable)
28b7034a916a configitems: register the test 'fakedirstatewritetime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents: 32813
diff changeset
    29
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42747
diff changeset
    30
configitem(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43506
diff changeset
    31
    b'fakedirstatewritetime',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43506
diff changeset
    32
    b'fakenow',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43506
diff changeset
    33
    default=None,
34771
28b7034a916a configitems: register the test 'fakedirstatewritetime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents: 32813
diff changeset
    34
)
28b7034a916a configitems: register the test 'fakedirstatewritetime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents: 32813
diff changeset
    35
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    36
parsers = policy.importmod('parsers')
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    37
rustmod = policy.importrust('parsers')
32372
df448de7cf3b parsers: switch to policy importer
Yuya Nishihara <yuya@tcha.org>
parents: 27283
diff changeset
    38
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42747
diff changeset
    39
25752
815df73abf12 tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    40
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
    41
    # 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
    42
    # 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
    43
    actualnow = int(now)
36327
58c1368ab629 py3: use dict.items() instead of dict.iteritems() in tests
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36324
diff changeset
    44
    for f, e in dmap.items():
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
        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
    46
            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
    47
            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
    48
815df73abf12 tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    49
    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
    50
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42747
diff changeset
    51
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
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
    53
    # 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
    54
36324
ac04f17b7041 py3: add b'' prefixes in fakedirstatewritetime.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34771
diff changeset
    55
    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
    56
    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
    57
        # 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
    58
        # 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
    59
        # 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
    60
        # 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
    61
        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
    62
815df73abf12 tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    63
    # 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
    64
    # 'fakenow' value and 'touch -t YYYYmmddHHMM' argument easy
36607
c6061cadb400 util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents: 36327
diff changeset
    65
    fakenow = dateutil.parsedate(fakenow, [b'%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
    66
42747
760a7851e9ba rust-parsers: move parser bindings to their own file and Python module
Raphaël Gomès <rgomes@octobus.net>
parents: 42304
diff changeset
    67
    if rustmod is not None:
760a7851e9ba rust-parsers: move parser bindings to their own file and Python module
Raphaël Gomès <rgomes@octobus.net>
parents: 42304
diff changeset
    68
        # 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: 42304
diff changeset
    69
        # to prevent conversion round-trips
47501
8b7e47802deb dirstate: split dirstatemap in its own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45942
diff changeset
    70
        orig_dirstatemap_write = dirstatemapmod.dirstatemap.write
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42747
diff changeset
    71
        wrapper = lambda self, st, now: orig_dirstatemap_write(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42747
diff changeset
    72
            self, st, fakenow
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42747
diff changeset
    73
        )
47501
8b7e47802deb dirstate: split dirstatemap in its own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45942
diff changeset
    74
        dirstatemapmod.dirstatemap.write = wrapper
42304
9c6c0f736e1d rust-dirstate: call parse/pack bindings from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42295
diff changeset
    75
26634
09bb1ee7e73e dirstate: make writing in-memory changes aware of transaction activity
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26630
diff changeset
    76
    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
    77
    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
    78
42747
760a7851e9ba rust-parsers: move parser bindings to their own file and Python module
Raphaël Gomès <rgomes@octobus.net>
parents: 42304
diff changeset
    79
    orig_module = parsers
760a7851e9ba rust-parsers: move parser bindings to their own file and Python module
Raphaël Gomès <rgomes@octobus.net>
parents: 42304
diff changeset
    80
    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: 42304
diff changeset
    81
42304
9c6c0f736e1d rust-dirstate: call parse/pack bindings from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42295
diff changeset
    82
    orig_module.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
    83
    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
    84
    try:
815df73abf12 tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    85
        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
    86
    finally:
42304
9c6c0f736e1d rust-dirstate: call parse/pack bindings from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42295
diff changeset
    87
        orig_module.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
    88
        dirstate._getfsnow = orig_dirstate_getfsnow
42747
760a7851e9ba rust-parsers: move parser bindings to their own file and Python module
Raphaël Gomès <rgomes@octobus.net>
parents: 42304
diff changeset
    89
        if rustmod is not None:
47501
8b7e47802deb dirstate: split dirstatemap in its own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45942
diff changeset
    90
            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
    91
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42747
diff changeset
    92
32813
6d73b7ff8f92 workingctx: also pass status tuple into poststatusfixup
Siddharth Agarwal <sid0@fb.com>
parents: 32812
diff changeset
    93
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
    94
    ui = workingctx.repo().ui
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42747
diff changeset
    95
    return fakewrite(ui, lambda: orig(workingctx, status, fixup))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42747
diff changeset
    96
25752
815df73abf12 tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    97
815df73abf12 tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    98
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
    99
    ui = committablectx.repo().ui
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42747
diff changeset
   100
    return fakewrite(ui, lambda: orig(committablectx, node))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42747
diff changeset
   101
25752
815df73abf12 tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   102
815df73abf12 tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   103
def extsetup(ui):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42747
diff changeset
   104
    extensions.wrapfunction(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42747
diff changeset
   105
        context.workingctx, '_poststatusfixup', _poststatusfixup
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42747
diff changeset
   106
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42747
diff changeset
   107
    extensions.wrapfunction(context.workingctx, 'markcommitted', markcommitted)