Mercurial > hg
annotate tests/flagprocessorext.py @ 47866:4162f6b40f2c stable
windows: degrade to py2 behavior when reading a non-symlink as a symlink
While waiting for the push to hg-committed in WSL to complete, I ran a
`phabimport` from Windows and got this traceback:
$ hg phabimport 11313
** Unknown exception encountered with possibly-broken third-party extension "mercurial_keyring" (version N/A)
** which supports versions unknown of Mercurial.
** Please disable "mercurial_keyring" and try your action again.
** If that fixes the bug please report it to https://foss.heptapod.net/mercurial/mercurial_keyring/issues
** Python 3.9.5 (default, May 6 2021, 17:29:31) [MSC v.1928 64 bit (AMD64)]
** Mercurial Distributed SCM (version 5.9rc1+hg32.0e2f5733563d)
** Extensions loaded: absorb, blackbox, evolve 10.3.3, extdiff, fastannotate, fix, mercurial_keyring, mq, phabblocker 20210126, phabricator, rebase, show, strip, topic 0.22.3
Traceback (most recent call last):
File "mercurial.lock", line 279, in _trylock
File "mercurial.vfs", line 202, in makelock
File "mercurial.util", line 2147, in makelock
FileExistsError: [WinError 183] Cannot create a file when that file already exists: b'hp-omen:78348' -> b'C:\\Users\\Matt\\hg/.hg/store/lock'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 24, in <module>
File "mercurial.dispatch", line 144, in run
File "mercurial.dispatch", line 250, in dispatch
File "mercurial.dispatch", line 294, in _rundispatch
File "mercurial.dispatch", line 470, in _runcatch
File "mercurial.dispatch", line 480, in _callcatch
File "mercurial.scmutil", line 153, in callcatch
File "mercurial.dispatch", line 460, in _runcatchfunc
File "mercurial.dispatch", line 1273, in _dispatch
File "mercurial.dispatch", line 918, in runcommand
File "mercurial.dispatch", line 1285, in _runcommand
File "mercurial.dispatch", line 1271, in <lambda>
File "mercurial.util", line 1886, in check
File "mercurial.util", line 1886, in check
File "hgext.mq", line 4239, in mqcommand
File "mercurial.util", line 1886, in check
File "mercurial.util", line 1886, in check
File "hgext.phabricator", line 314, in inner
File "hgext.phabricator", line 2222, in phabimport
File "hgext.phabricator", line 2123, in readpatch
File "hgext.phabricator", line 2199, in _write
File "mercurial.localrepo", line 2956, in lock
File "mercurial.localrepo", line 2918, in _lock
File "mercurial.lock", line 152, in trylock
File "mercurial.lock", line 283, in _trylock
File "mercurial.lock", line 314, in _readlock
File "mercurial.vfs", line 221, in readlock
File "mercurial.util", line 2163, in readlock
File "mercurial.windows", line 619, in readlink
ValueError: not a symbolic link
Both exceptions look accurate (the file exists, and the Windows side can't read
WSL side symlinks). I didn't try to reproduce this entirely within the Windows
side, but we can do better than a cryptic stacktrace. With this change, the
same scenario results in this abort:
abort: C:\Users\Matt\hg/.hg/store/lock: The file cannot be accessed by the system
When both the `push` and `phabimport` are done on the Windows side, it prints a
message about waiting for the lock, and successfully applies the patch after the
push completes.
I'm not sure if there's enough info to be able to convert the abort into the
wait scenario. As it stands now, we don't support symlinks on Windows, which
requires either a UAC Administrator level process or an opt-in in developer
mode, and there are several places where the new symlink on Windows support in
py3 was explicitly disabled in order to get tests to pass quicker.
Differential Revision: https://phab.mercurial-scm.org/D11333
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Sun, 22 Aug 2021 17:59:21 -0400 |
parents | ac60a1366a49 |
children | 6000f5b25c9b |
rev | line source |
---|---|
30745 | 1 # coding=UTF-8 |
2 | |
3 from __future__ import absolute_import | |
4 | |
5 import base64 | |
6 import zlib | |
7 | |
8 from mercurial import ( | |
45784
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43076
diff
changeset
|
9 bundlecaches, |
30745 | 10 changegroup, |
11 extensions, | |
12 revlog, | |
13 util, | |
14 ) | |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
15 from mercurial.revlogutils import flagutil |
47394
ac60a1366a49
revlog: move `offset_type` to `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46709
diff
changeset
|
16 from mercurial.interfaces import repository |
30745 | 17 |
18 # Test only: These flags are defined here only in the context of testing the | |
19 # behavior of the flag processor. The canonical way to add flags is to get in | |
20 # touch with the community and make them known in revlog. | |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
21 REVIDX_NOOP = 1 << 3 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
22 REVIDX_BASE64 = 1 << 2 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
23 REVIDX_GZIP = 1 << 1 |
30745 | 24 REVIDX_FAIL = 1 |
25 | |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
26 |
30745 | 27 def validatehash(self, text): |
28 return True | |
29 | |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
30 |
30745 | 31 def bypass(self, text): |
32 return False | |
33 | |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
34 |
46709
3d740058b467
sidedata: move to new sidedata storage in revlogv2
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
35 def noopdonothing(self, text): |
30745 | 36 return (text, True) |
37 | |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
38 |
42985
bd5858c28bbe
flagprocessors: have the read transform function return side data (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42732
diff
changeset
|
39 def noopdonothingread(self, text): |
46709
3d740058b467
sidedata: move to new sidedata storage in revlogv2
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
40 return (text, True) |
42985
bd5858c28bbe
flagprocessors: have the read transform function return side data (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42732
diff
changeset
|
41 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
42 |
46709
3d740058b467
sidedata: move to new sidedata storage in revlogv2
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
43 def b64encode(self, text): |
30745 | 44 return (base64.b64encode(text), False) |
45 | |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
46 |
30745 | 47 def b64decode(self, text): |
46709
3d740058b467
sidedata: move to new sidedata storage in revlogv2
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
48 return (base64.b64decode(text), True) |
30745 | 49 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
50 |
46709
3d740058b467
sidedata: move to new sidedata storage in revlogv2
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
51 def gzipcompress(self, text): |
30745 | 52 return (zlib.compress(text), False) |
53 | |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
54 |
30745 | 55 def gzipdecompress(self, text): |
46709
3d740058b467
sidedata: move to new sidedata storage in revlogv2
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
56 return (zlib.decompress(text), True) |
30745 | 57 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
58 |
30745 | 59 def supportedoutgoingversions(orig, repo): |
60 versions = orig(repo) | |
36114
83246d6920f2
py3: use b'' for changegroup version literals
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35570
diff
changeset
|
61 versions.discard(b'01') |
83246d6920f2
py3: use b'' for changegroup version literals
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35570
diff
changeset
|
62 versions.discard(b'02') |
83246d6920f2
py3: use b'' for changegroup version literals
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35570
diff
changeset
|
63 versions.add(b'03') |
30745 | 64 return versions |
65 | |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
66 |
30745 | 67 def allsupportedversions(orig, ui): |
68 versions = orig(ui) | |
36114
83246d6920f2
py3: use b'' for changegroup version literals
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35570
diff
changeset
|
69 versions.add(b'03') |
30745 | 70 return versions |
71 | |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
72 |
37436
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
73 def makewrappedfile(obj): |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
74 class wrappedfile(obj.__class__): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
75 def addrevision( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
76 self, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
77 text, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
78 transaction, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
79 link, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
80 p1, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
81 p2, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
82 cachedelta=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
83 node=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
84 flags=flagutil.REVIDX_DEFAULT_FLAGS, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
85 ): |
37436
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
86 if b'[NOOP]' in text: |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
87 flags |= REVIDX_NOOP |
30745 | 88 |
37436
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
89 if b'[BASE64]' in text: |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
90 flags |= REVIDX_BASE64 |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
91 |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
92 if b'[GZIP]' in text: |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
93 flags |= REVIDX_GZIP |
30745 | 94 |
37436
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
95 # This addrevision wrapper is meant to add a flag we will not have |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
96 # transforms registered for, ensuring we handle this error case. |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
97 if b'[FAIL]' in text: |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
98 flags |= REVIDX_FAIL |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
99 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
100 return super(wrappedfile, self).addrevision( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
101 text, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
102 transaction, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
103 link, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
104 p1, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
105 p2, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
106 cachedelta=cachedelta, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
107 node=node, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
108 flags=flags, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
109 ) |
30745 | 110 |
37436
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
111 obj.__class__ = wrappedfile |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
112 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
113 |
37436
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
114 def reposetup(ui, repo): |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
115 class wrappingflagprocessorrepo(repo.__class__): |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
116 def file(self, f): |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
117 orig = super(wrappingflagprocessorrepo, self).file(f) |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
118 makewrappedfile(orig) |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
119 return orig |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
120 |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
121 repo.__class__ = wrappingflagprocessorrepo |
30745 | 122 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
123 |
30745 | 124 def extsetup(ui): |
125 # Enable changegroup3 for flags to be sent over the wire | |
126 wrapfunction = extensions.wrapfunction | |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
127 wrapfunction( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
128 changegroup, 'supportedoutgoingversions', supportedoutgoingversions |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
129 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
130 wrapfunction(changegroup, 'allsupportedversions', allsupportedversions) |
30745 | 131 |
132 # Teach revlog about our test flags | |
133 flags = [REVIDX_NOOP, REVIDX_BASE64, REVIDX_GZIP, REVIDX_FAIL] | |
42730
92ac6b1697a7
flagutil: move REVIDX_KNOWN_FLAGS source of truth in flagutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41413
diff
changeset
|
134 flagutil.REVIDX_KNOWN_FLAGS |= util.bitsfrom(flags) |
47394
ac60a1366a49
revlog: move `offset_type` to `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46709
diff
changeset
|
135 repository.REVISION_FLAGS_KNOWN |= util.bitsfrom(flags) |
30745 | 136 revlog.REVIDX_FLAGS_ORDER.extend(flags) |
137 | |
31832
77f746e5383a
test-flagprocessor: use changegroup3 in bundle2
Jun Wu <quark@fb.com>
parents:
30745
diff
changeset
|
138 # Teach exchange to use changegroup 3 |
45784
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43076
diff
changeset
|
139 for k in bundlecaches._bundlespeccontentopts.keys(): |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43076
diff
changeset
|
140 bundlecaches._bundlespeccontentopts[k][b"cg.version"] = b"03" |
31832
77f746e5383a
test-flagprocessor: use changegroup3 in bundle2
Jun Wu <quark@fb.com>
parents:
30745
diff
changeset
|
141 |
30745 | 142 # Register flag processors for each extension |
42732
6d61be152c55
flagutil: move addflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42730
diff
changeset
|
143 flagutil.addflagprocessor( |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45784
diff
changeset
|
144 REVIDX_NOOP, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45784
diff
changeset
|
145 ( |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45784
diff
changeset
|
146 noopdonothingread, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45784
diff
changeset
|
147 noopdonothing, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45784
diff
changeset
|
148 validatehash, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45784
diff
changeset
|
149 ), |
30745 | 150 ) |
42732
6d61be152c55
flagutil: move addflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42730
diff
changeset
|
151 flagutil.addflagprocessor( |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45784
diff
changeset
|
152 REVIDX_BASE64, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45784
diff
changeset
|
153 ( |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45784
diff
changeset
|
154 b64decode, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45784
diff
changeset
|
155 b64encode, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45784
diff
changeset
|
156 bypass, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45784
diff
changeset
|
157 ), |
30745 | 158 ) |
42732
6d61be152c55
flagutil: move addflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42730
diff
changeset
|
159 flagutil.addflagprocessor( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
160 REVIDX_GZIP, (gzipdecompress, gzipcompress, bypass) |
30745 | 161 ) |