view tests/fakepatchtime.py @ 36608:1151c731686e

sshpeer: don't read from stderr when that behavior is disabled We previously prevented the creation of doublepipe instances when we're not supposed to automatically read from stderr. However, there were other automatic calls to read from stderr that were undermining this effort. This commit prevents all automatic reads from stderr from occurring when they are supposed to be disabled. Because stderr is no longer being read, we need to call "readavailable" from tests so stderr is read from. Test output changes because stderr is now always (manually) read after stdout. And, since sshpeer no longer automatically tends to stderr, no "remote: " messages are printed. This should fix non-deterministic test output. FWIW, doublepipe automatically reads from stderr when reading from stdout, so I'm not sure some of these calls to self._readerr() are even needed. Differential Revision: https://phab.mercurial-scm.org/D2571
author Gregory Szorc <gregory.szorc@gmail.com>
date Fri, 02 Mar 2018 18:50:49 -0500
parents c6061cadb400
children 2372284d9457
line wrap: on
line source

# extension to emulate invoking 'patch.internalpatch()' at the time
# specified by '[fakepatchtime] fakenow'

from __future__ import absolute_import

from mercurial import (
    extensions,
    patch as patchmod,
    registrar,
)
from mercurial.utils import dateutil

configtable = {}
configitem = registrar.configitem(configtable)

configitem(b'fakepatchtime', b'fakenow',
    default=None,
)

def internalpatch(orig, ui, repo, patchobj, strip,
                  prefix=b'', files=None,
                  eolmode=b'strict', similarity=0):
    if files is None:
        files = set()
    r = orig(ui, repo, patchobj, strip,
             prefix=prefix, files=files,
             eolmode=eolmode, similarity=similarity)

    fakenow = ui.config(b'fakepatchtime', b'fakenow')
    if fakenow:
        # parsing 'fakenow' in YYYYmmddHHMM format makes comparison between
        # 'fakenow' value and 'touch -t YYYYmmddHHMM' argument easy
        fakenow = dateutil.parsedate(fakenow, [b'%Y%m%d%H%M'])[0]
        for f in files:
            repo.wvfs.utime(f, (fakenow, fakenow))

    return r

def extsetup(ui):
    extensions.wrapfunction(patchmod, 'internalpatch', internalpatch)