tests/fakepatchtime.py
author Pulkit Goyal <7895pulkit@gmail.com>
Sat, 23 Dec 2017 15:13:37 +0530
changeset 36101 5a53af7d09aa
parent 34772 7be2f229285b
child 36358 9a75619776ca
permissions -rw-r--r--
remotenames: introduce new template keywords for remotenames This patch introduces three new template keywords 'remotenames', 'remotebookmarks', 'remotebranches' to show remotenames, remotebookmarks and remotebranches associated to a changeset. This is a part of moving hgremotenames extension to core. The remotenames template keyword was present in the extension and the rest of the two are not present in the hgremotenames extension and are introduced in this patch. hgremotenames: https://bitbucket.org/seanfarley/hgremotenames Differential Revision: https://phab.mercurial-scm.org/D1759

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