tests/fakepatchtime.py
author Manuel Jacob <me@manueljacob.de>
Mon, 11 Jul 2022 01:51:20 +0200
branchstable
changeset 49378 094a5fa3cf52
parent 48875 6000f5b25c9b
permissions -rw-r--r--
procutil: make stream detection in make_line_buffered more correct and strict In make_line_buffered(), we don’t want to wrap the stream if we know that lines get flushed to the underlying raw stream already. Previously, the heuristic was too optimistic. It assumed that any stream which is not an instance of io.BufferedIOBase doesn’t need wrapping. However, there are buffered streams that aren’t instances of io.BufferedIOBase, like Mercurial’s own winstdout. The new logic is different in two ways: First, only for the check, if unwraps any combination of WriteAllWrapper and winstdout. Second, it skips wrapping the stream only if it is an instance of io.RawIOBase (or already wrapped). If it is an instance of io.BufferedIOBase, it gets wrapped. In any other case, the function raises an exception. This ensures that, if an unknown stream is passed or we add another wrapper in the future, we don’t wrap the stream if it’s already line buffered or not wrap the stream if it’s not line buffered. In fact, this was already helpful during development of this change. Without it, I possibly would have forgot that WriteAllWrapper needs to be ignored for the check, leading to unnecessary wrapping if stdout is unbuffered. The alternative would have been to always wrap unknown streams. However, I don’t think that anyone would benefit from being less strict. We can expect streams from the standard library to be subclassing either io.RawIOBase or io.BufferedIOBase, so running Mercurial in the standard way should not regress by this change. Py2exe might replace sys.stdout and sys.stderr, but that currently breaks Mercurial anyway and also these streams don’t claim to be interactive, so this function is not called for them.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25756
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
     1
# extension to emulate invoking 'patch.internalpatch()' at the time
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
     2
# specified by '[fakepatchtime] fakenow'
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
     3
27284
f624b0e69105 tests/fakepatchtime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25756
diff changeset
     4
f624b0e69105 tests/fakepatchtime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25756
diff changeset
     5
from mercurial import (
f624b0e69105 tests/fakepatchtime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25756
diff changeset
     6
    extensions,
f624b0e69105 tests/fakepatchtime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25756
diff changeset
     7
    patch as patchmod,
34772
7be2f229285b configitems: register the test 'fakepatchtime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents: 27284
diff changeset
     8
    registrar,
27284
f624b0e69105 tests/fakepatchtime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25756
diff changeset
     9
)
36607
c6061cadb400 util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents: 36325
diff changeset
    10
from mercurial.utils import dateutil
25756
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    11
34772
7be2f229285b configitems: register the test 'fakepatchtime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents: 27284
diff changeset
    12
configtable = {}
7be2f229285b configitems: register the test 'fakepatchtime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents: 27284
diff changeset
    13
configitem = registrar.configitem(configtable)
7be2f229285b configitems: register the test 'fakepatchtime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents: 27284
diff changeset
    14
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36607
diff changeset
    15
configitem(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
    16
    b'fakepatchtime',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
    17
    b'fakenow',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43076
diff changeset
    18
    default=None,
34772
7be2f229285b configitems: register the test 'fakepatchtime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents: 27284
diff changeset
    19
)
7be2f229285b configitems: register the test 'fakepatchtime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents: 27284
diff changeset
    20
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36607
diff changeset
    21
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36607
diff changeset
    22
def internalpatch(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36607
diff changeset
    23
    orig,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36607
diff changeset
    24
    ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36607
diff changeset
    25
    repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36607
diff changeset
    26
    patchobj,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36607
diff changeset
    27
    strip,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36607
diff changeset
    28
    prefix=b'',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36607
diff changeset
    29
    files=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36607
diff changeset
    30
    eolmode=b'strict',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36607
diff changeset
    31
    similarity=0,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36607
diff changeset
    32
):
25756
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    33
    if files is None:
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    34
        files = set()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36607
diff changeset
    35
    r = orig(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36607
diff changeset
    36
        ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36607
diff changeset
    37
        repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36607
diff changeset
    38
        patchobj,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36607
diff changeset
    39
        strip,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36607
diff changeset
    40
        prefix=prefix,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36607
diff changeset
    41
        files=files,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36607
diff changeset
    42
        eolmode=eolmode,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36607
diff changeset
    43
        similarity=similarity,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36607
diff changeset
    44
    )
25756
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    45
36325
9a75619776ca py3: add b'' prefixes in fakepatchtime.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34772
diff changeset
    46
    fakenow = ui.config(b'fakepatchtime', b'fakenow')
25756
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    47
    if fakenow:
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    48
        # parsing 'fakenow' in YYYYmmddHHMM format makes comparison between
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    49
        # '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: 36325
diff changeset
    50
        fakenow = dateutil.parsedate(fakenow, [b'%Y%m%d%H%M'])[0]
25756
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    51
        for f in files:
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    52
            repo.wvfs.utime(f, (fakenow, fakenow))
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    53
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    54
    return r
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    55
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36607
diff changeset
    56
25756
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    57
def extsetup(ui):
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    58
    extensions.wrapfunction(patchmod, 'internalpatch', internalpatch)