Mercurial > hg
annotate tests/fakedirstatewritetime.py @ 41163:0101a35deae2
phabricator: warn if unable to amend, instead of aborting after posting
There was a divergence in behavior here between obsolete and strip based
amending. I first noticed the abort when testing outside of the test harness,
but then had trouble recreating it here after reverting the code changes. It
turns out, strip based amend was successfully amending the public commit after
it was posted! It looks like the protection is in the `commit --amend` command,
not in the underlying code that it calls.
I considered doing a preflight check and aborting. But the locks are only
acquired at the end, if amending, and this is too large a section of code to be
wrapped in a maybe-it's-held-or-not context manager for my tastes.
Additionally, some people do post-push reviews, and amending is the default
behavior, so they shouldn't see a misleading error message.
The lack of a 'Differential Revision' entry in the commit message breaks a
{phabreview} test, so it had to be partially conditionalized.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Sat, 05 Jan 2019 15:20:33 -0500 |
parents | c6061cadb400 |
children | fdd4d668ceb5 |
rev | line source |
---|---|
25752
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
1 # extension to emulate invoking 'dirstate.write()' at the time |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
2 # specified by '[fakedirstatewritetime] fakenow', only when |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
3 # 'dirstate.write()' is invoked via functions below: |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
4 # |
32812
add613cddcb6
workingctx: factor out post-status dirstate fixup
Siddharth Agarwal <sid0@fb.com>
parents:
32372
diff
changeset
|
5 # - 'workingctx._poststatusfixup()' (= 'repo.status()') |
25752
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
6 # - 'committablectx.markcommitted()' |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
7 |
27283
b38adef652fe
tests/fakedirstatewritetime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26634
diff
changeset
|
8 from __future__ import absolute_import |
b38adef652fe
tests/fakedirstatewritetime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26634
diff
changeset
|
9 |
b38adef652fe
tests/fakedirstatewritetime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26634
diff
changeset
|
10 from mercurial import ( |
b38adef652fe
tests/fakedirstatewritetime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26634
diff
changeset
|
11 context, |
b38adef652fe
tests/fakedirstatewritetime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26634
diff
changeset
|
12 dirstate, |
b38adef652fe
tests/fakedirstatewritetime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26634
diff
changeset
|
13 extensions, |
32372
df448de7cf3b
parsers: switch to policy importer
Yuya Nishihara <yuya@tcha.org>
parents:
27283
diff
changeset
|
14 policy, |
34771
28b7034a916a
configitems: register the test 'fakedirstatewritetime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents:
32813
diff
changeset
|
15 registrar, |
27283
b38adef652fe
tests/fakedirstatewritetime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26634
diff
changeset
|
16 ) |
36607
c6061cadb400
util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents:
36327
diff
changeset
|
17 from mercurial.utils import dateutil |
25752
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
18 |
34771
28b7034a916a
configitems: register the test 'fakedirstatewritetime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents:
32813
diff
changeset
|
19 configtable = {} |
28b7034a916a
configitems: register the test 'fakedirstatewritetime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents:
32813
diff
changeset
|
20 configitem = registrar.configitem(configtable) |
28b7034a916a
configitems: register the test 'fakedirstatewritetime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents:
32813
diff
changeset
|
21 |
36324
ac04f17b7041
py3: add b'' prefixes in fakedirstatewritetime.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34771
diff
changeset
|
22 configitem(b'fakedirstatewritetime', b'fakenow', |
34771
28b7034a916a
configitems: register the test 'fakedirstatewritetime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents:
32813
diff
changeset
|
23 default=None, |
28b7034a916a
configitems: register the test 'fakedirstatewritetime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents:
32813
diff
changeset
|
24 ) |
28b7034a916a
configitems: register the test 'fakedirstatewritetime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents:
32813
diff
changeset
|
25 |
32372
df448de7cf3b
parsers: switch to policy importer
Yuya Nishihara <yuya@tcha.org>
parents:
27283
diff
changeset
|
26 parsers = policy.importmod(r'parsers') |
df448de7cf3b
parsers: switch to policy importer
Yuya Nishihara <yuya@tcha.org>
parents:
27283
diff
changeset
|
27 |
25752
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
28 def pack_dirstate(fakenow, orig, dmap, copymap, pl, now): |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
29 # execute what original parsers.pack_dirstate should do actually |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
30 # for consistency |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
31 actualnow = int(now) |
36327
58c1368ab629
py3: use dict.items() instead of dict.iteritems() in tests
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36324
diff
changeset
|
32 for f, e in dmap.items(): |
25752
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
33 if e[0] == 'n' and e[3] == actualnow: |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
34 e = parsers.dirstatetuple(e[0], e[1], e[2], -1) |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
35 dmap[f] = e |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
36 |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
37 return orig(dmap, copymap, pl, fakenow) |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
38 |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
39 def fakewrite(ui, func): |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
40 # fake "now" of 'pack_dirstate' only if it is invoked while 'func' |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
41 |
36324
ac04f17b7041
py3: add b'' prefixes in fakedirstatewritetime.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34771
diff
changeset
|
42 fakenow = ui.config(b'fakedirstatewritetime', b'fakenow') |
25752
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
43 if not fakenow: |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
44 # Execute original one, if fakenow isn't configured. This is |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
45 # useful to prevent subrepos from executing replaced one, |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
46 # because replacing 'parsers.pack_dirstate' is also effective |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
47 # in subrepos. |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
48 return func() |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
49 |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
50 # parsing 'fakenow' in YYYYmmddHHMM format makes comparison between |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
51 # 'fakenow' value and 'touch -t YYYYmmddHHMM' argument easy |
36607
c6061cadb400
util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents:
36327
diff
changeset
|
52 fakenow = dateutil.parsedate(fakenow, [b'%Y%m%d%H%M'])[0] |
25752
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
53 |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
54 orig_pack_dirstate = parsers.pack_dirstate |
26634
09bb1ee7e73e
dirstate: make writing in-memory changes aware of transaction activity
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26630
diff
changeset
|
55 orig_dirstate_getfsnow = dirstate._getfsnow |
25752
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
56 wrapper = lambda *args: pack_dirstate(fakenow, orig_pack_dirstate, *args) |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
57 |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
58 parsers.pack_dirstate = wrapper |
26634
09bb1ee7e73e
dirstate: make writing in-memory changes aware of transaction activity
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26630
diff
changeset
|
59 dirstate._getfsnow = lambda *args: fakenow |
25752
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
60 try: |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
61 return func() |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
62 finally: |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
63 parsers.pack_dirstate = orig_pack_dirstate |
26634
09bb1ee7e73e
dirstate: make writing in-memory changes aware of transaction activity
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26630
diff
changeset
|
64 dirstate._getfsnow = orig_dirstate_getfsnow |
25752
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
65 |
32813
6d73b7ff8f92
workingctx: also pass status tuple into poststatusfixup
Siddharth Agarwal <sid0@fb.com>
parents:
32812
diff
changeset
|
66 def _poststatusfixup(orig, workingctx, status, fixup): |
25752
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
67 ui = workingctx.repo().ui |
32813
6d73b7ff8f92
workingctx: also pass status tuple into poststatusfixup
Siddharth Agarwal <sid0@fb.com>
parents:
32812
diff
changeset
|
68 return fakewrite(ui, lambda : orig(workingctx, status, fixup)) |
25752
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
69 |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
70 def markcommitted(orig, committablectx, node): |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
71 ui = committablectx.repo().ui |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
72 return fakewrite(ui, lambda : orig(committablectx, node)) |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
73 |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
74 def extsetup(ui): |
32812
add613cddcb6
workingctx: factor out post-status dirstate fixup
Siddharth Agarwal <sid0@fb.com>
parents:
32372
diff
changeset
|
75 extensions.wrapfunction(context.workingctx, '_poststatusfixup', |
add613cddcb6
workingctx: factor out post-status dirstate fixup
Siddharth Agarwal <sid0@fb.com>
parents:
32372
diff
changeset
|
76 _poststatusfixup) |
25752
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
77 extensions.wrapfunction(context.committablectx, 'markcommitted', |
815df73abf12
tests: add extension to emulate invoking dirstate.write at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
78 markcommitted) |