sapling/eden/scm/tests/fakepatchtime.py
Jun Wu 5da0c6903d util: switch to Rust time parsing
Summary:
The Rust bindings now provide a subset of time parsing features.  Replace the
old Python implementation. This has multiple benefits:
- Strong gurarnatee that Rust and Python behave the same.
- Parse relative time (ex. `5 minutes ago`)
- Parse date beyound i32 range (ex. >= year 2038)

Reviewed By: DurhamG

Differential Revision: D18946332

fbshipit-source-id: 721f47bc5b2835d7ca0a05ab34ea4faa1a411a4e
2020-01-09 11:51:31 -08:00

50 lines
1011 B
Python

# extension to emulate invoking 'patch.internalpatch()' at the time
# specified by '[fakepatchtime] fakenow'
from __future__ import absolute_import
from edenscm.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:
fakenow = util.parsedate(fakenow)[0]
for f in files:
repo.wvfs.utime(f, (fakenow, fakenow))
return r
def extsetup(ui):
extensions.wrapfunction(patchmod, "internalpatch", internalpatch)