tests/fakepatchtime.py
author Jun Wu <quark@fb.com>
Wed, 10 Jan 2018 21:27:05 -0800
changeset 35666 2c6ebd0c850e
parent 34772 7be2f229285b
child 36325 9a75619776ca
permissions -rw-r--r--
lfs: remove internal url in test `test-lfs-test-server.t` refers to a FB internal domain and requires certain implementation (ex. set error code to 404) at that endpoint. Without any workaround, It should in theory error out like "Domain cannot be resolved". I don't know how Matt Harbison ran the test. This patch changes the test to only depend on `lfs-test-server`. Unfortunately the logic has to be changed since `lfs-test-server` does not set error code to 404 but just removes "download" from "actions". Differential Revision: https://phab.mercurial-scm.org/D1849

# 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,
    util,
)

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

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

def internalpatch(orig, ui, repo, patchobj, strip,
                  prefix='', files=None,
                  eolmode='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('fakepatchtime', 'fakenow')
    if fakenow:
        # parsing 'fakenow' in YYYYmmddHHMM format makes comparison between
        # 'fakenow' value and 'touch -t YYYYmmddHHMM' argument easy
        fakenow = util.parsedate(fakenow, ['%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)