Debian Codegraph @

tests/fakepatchtime.py

raw
1 # extension to emulate invoking 'patch.internalpatch()' at the time
2 # specified by '[fakepatchtime] fakenow'
3
4
5 from mercurial import (
6 extensions,
7 patch as patchmod,
8 registrar,
9 )
10 from mercurial.utils import dateutil
11
12 configtable = {}
13 configitem = registrar.configitem(configtable)
14
15 configitem(
16 b'fakepatchtime',
17 b'fakenow',
18 default=None,
19 )
20
21
22 def internalpatch(
23 orig,
24 ui,
25 repo,
26 patchobj,
27 strip,
28 prefix=b'',
29 files=None,
30 eolmode=b'strict',
31 similarity=0,
32 ):
33 if files is None:
34 files = set()
35 r = orig(
36 ui,
37 repo,
38 patchobj,
39 strip,
40 prefix=prefix,
41 files=files,
42 eolmode=eolmode,
43 similarity=similarity,
44 )
45
46 fakenow = ui.config(b'fakepatchtime', b'fakenow')
47 if fakenow:
48 # parsing 'fakenow' in YYYYmmddHHMM format makes comparison between
49 # 'fakenow' value and 'touch -t YYYYmmddHHMM' argument easy
50 fakenow = dateutil.parsedate(fakenow, [b'%Y%m%d%H%M'])[0]
51 for f in files:
52 repo.wvfs.utime(f, (fakenow, fakenow))
53
54 return r
55
56
57 def extsetup(ui):
58 extensions.wrapfunction(patchmod, 'internalpatch', internalpatch)