Mercurial > hg-stable
annotate tests/killdaemons.py @ 24790:baa11dde8c0e
match: add a subclass for dirstate normalizing of the matched patterns
This class is only needed on case insensitive filesystems, and only
for wdir context matches. It allows the user to not match the case of
the items in the filesystem- especially for naming directories, which
dirstate doesn't handle[1]. Making dirstate handle mismatched
directory cases is too expensive[2].
Since dirstate doesn't apply to committed csets, this is only created by
overriding basectx.match() in workingctx, and only on icasefs. The default
arguments have been dropped, because the ctx must be passed to the matcher in
order to function.
For operations that can apply to both wdir and some other context, this ends up
normalizing the filename to the case as it exists in the filesystem, and using
that case for the lookup in the other context. See the diff example in the
test.
Previously, given a directory with an inexact case:
- add worked as expected
- diff, forget and status would silently ignore the request
- files would exit with 1
- commit, revert and remove would fail (even when the commands leading up to
them worked):
$ hg ci -m "AbCDef" capsdir1/capsdir
abort: CapsDir1/CapsDir: no match under directory!
$ hg revert -r '.^' capsdir1/capsdir
capsdir1\capsdir: no such file in rev 64dae27060b7
$ hg remove capsdir1/capsdir
not removing capsdir1\capsdir: no tracked files
[1]
Globs are normalized, so that the -I and -X don't need to be specified with a
case match. Without that, the second last remove (with -X) removes the files,
leaving nothing for the last remove. However, specifying the files as
'glob:**.Txt' does not work. Perhaps this requires 're.IGNORECASE'?
There are only a handful of places that create matchers directly, instead of
being routed through the context.match() method. Some may benefit from changing
over to using ctx.match() as a factory function:
revset.checkstatus()
revset.contains()
revset.filelog()
revset._matchfiles()
localrepository._loadfilter()
ignore.ignore()
fileset.subrepo()
filemerge._picktool()
overrides.addlargefiles()
lfcommands.lfconvert()
kwtemplate.__init__()
eolfile.__init__()
eolfile.checkrev()
acl.buildmatch()
Currently, a toplevel subrepo can be named with an inexact case. However, the
path auditor gets in the way of naming _anything_ in the subrepo if the top
level case doesn't match. That is trickier to handle, because there's the user
provided case, the case in the filesystem, and the case stored in .hgsub. This
can be fixed next cycle.
--- a/tests/test-subrepo-deep-nested-change.t
+++ b/tests/test-subrepo-deep-nested-change.t
@@ -170,8 +170,15 @@
R sub1/sub2/test.txt
$ hg update -Cq
$ touch sub1/sub2/folder/bar
+#if icasefs
+ $ hg addremove Sub1/sub2
+ abort: path 'Sub1\sub2' is inside nested repo 'Sub1'
+ [255]
+ $ hg -q addremove sub1/sub2
+#else
$ hg addremove sub1/sub2
adding sub1/sub2/folder/bar (glob)
+#endif
$ hg status -S
A sub1/sub2/folder/bar
? foo/bar/abc
The narrowmatcher class may need to be tweaked when that is fixed.
[1] http://www.selenic.com/pipermail/mercurial-devel/2015-April/068183.html
[2] http://www.selenic.com/pipermail/mercurial-devel/2015-April/068191.html
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Sun, 12 Apr 2015 01:39:21 -0400 |
parents | 476069509e72 |
children | 0adc22a0b6b3 |
rev | line source |
---|---|
7344
58fd3c718ca4
tests: add killdaemons helper script
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
58fd3c718ca4
tests: add killdaemons helper script
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
2 |
17466
d5a3bda6e170
killdaemons: take file argument explicitely
Patrick Mezard <patrick@mezard.eu>
parents:
17465
diff
changeset
|
3 import os, sys, time, errno, signal |
7344
58fd3c718ca4
tests: add killdaemons helper script
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
4 |
17465
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
5 if os.name =='nt': |
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
6 import ctypes |
20493
b5f43dbf64ca
tests: kill for windows in killdaemons.py checks return values
Simon Heimberg <simohe@besonet.ch>
parents:
17466
diff
changeset
|
7 |
b5f43dbf64ca
tests: kill for windows in killdaemons.py checks return values
Simon Heimberg <simohe@besonet.ch>
parents:
17466
diff
changeset
|
8 def _check(ret, expectederr=None): |
b5f43dbf64ca
tests: kill for windows in killdaemons.py checks return values
Simon Heimberg <simohe@besonet.ch>
parents:
17466
diff
changeset
|
9 if ret == 0: |
b5f43dbf64ca
tests: kill for windows in killdaemons.py checks return values
Simon Heimberg <simohe@besonet.ch>
parents:
17466
diff
changeset
|
10 winerrno = ctypes.GetLastError() |
b5f43dbf64ca
tests: kill for windows in killdaemons.py checks return values
Simon Heimberg <simohe@besonet.ch>
parents:
17466
diff
changeset
|
11 if winerrno == expectederr: |
b5f43dbf64ca
tests: kill for windows in killdaemons.py checks return values
Simon Heimberg <simohe@besonet.ch>
parents:
17466
diff
changeset
|
12 return True |
b5f43dbf64ca
tests: kill for windows in killdaemons.py checks return values
Simon Heimberg <simohe@besonet.ch>
parents:
17466
diff
changeset
|
13 raise ctypes.WinError(winerrno) |
b5f43dbf64ca
tests: kill for windows in killdaemons.py checks return values
Simon Heimberg <simohe@besonet.ch>
parents:
17466
diff
changeset
|
14 |
17465
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
15 def kill(pid, logfn, tryhard=True): |
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
16 logfn('# Killing daemon process %d' % pid) |
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
17 PROCESS_TERMINATE = 1 |
20496
acbd19b9fbe1
tests: killdaemons.py for windows distinguishes access violation and terminated
Simon Heimberg <simohe@besonet.ch>
parents:
20495
diff
changeset
|
18 PROCESS_QUERY_INFORMATION = 0x400 |
20698
1147563faf62
killdaemons: drop superfluous L suffix from constant
Augie Fackler <raf@durin42.com>
parents:
20496
diff
changeset
|
19 SYNCHRONIZE = 0x00100000 |
20494
ea3adeac5248
tests: killdaemons.py for windows waits for killed process to terminate
Simon Heimberg <simohe@besonet.ch>
parents:
20493
diff
changeset
|
20 WAIT_OBJECT_0 = 0 |
ea3adeac5248
tests: killdaemons.py for windows waits for killed process to terminate
Simon Heimberg <simohe@besonet.ch>
parents:
20493
diff
changeset
|
21 WAIT_TIMEOUT = 258 |
17465
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
22 handle = ctypes.windll.kernel32.OpenProcess( |
20496
acbd19b9fbe1
tests: killdaemons.py for windows distinguishes access violation and terminated
Simon Heimberg <simohe@besonet.ch>
parents:
20495
diff
changeset
|
23 PROCESS_TERMINATE|SYNCHRONIZE|PROCESS_QUERY_INFORMATION, |
acbd19b9fbe1
tests: killdaemons.py for windows distinguishes access violation and terminated
Simon Heimberg <simohe@besonet.ch>
parents:
20495
diff
changeset
|
24 False, pid) |
20493
b5f43dbf64ca
tests: kill for windows in killdaemons.py checks return values
Simon Heimberg <simohe@besonet.ch>
parents:
17466
diff
changeset
|
25 if handle == 0: |
20495
0cf1c8c452d3
tests: killdaemons.py for checks reason when getting no process handle
Simon Heimberg <simohe@besonet.ch>
parents:
20494
diff
changeset
|
26 _check(0, 87) # err 87 when process not found |
20493
b5f43dbf64ca
tests: kill for windows in killdaemons.py checks return values
Simon Heimberg <simohe@besonet.ch>
parents:
17466
diff
changeset
|
27 return # process not found, already finished |
b5f43dbf64ca
tests: kill for windows in killdaemons.py checks return values
Simon Heimberg <simohe@besonet.ch>
parents:
17466
diff
changeset
|
28 try: |
20496
acbd19b9fbe1
tests: killdaemons.py for windows distinguishes access violation and terminated
Simon Heimberg <simohe@besonet.ch>
parents:
20495
diff
changeset
|
29 r = ctypes.windll.kernel32.WaitForSingleObject(handle, 100) |
acbd19b9fbe1
tests: killdaemons.py for windows distinguishes access violation and terminated
Simon Heimberg <simohe@besonet.ch>
parents:
20495
diff
changeset
|
30 if r == WAIT_OBJECT_0: |
acbd19b9fbe1
tests: killdaemons.py for windows distinguishes access violation and terminated
Simon Heimberg <simohe@besonet.ch>
parents:
20495
diff
changeset
|
31 pass # terminated, but process handle still available |
acbd19b9fbe1
tests: killdaemons.py for windows distinguishes access violation and terminated
Simon Heimberg <simohe@besonet.ch>
parents:
20495
diff
changeset
|
32 elif r == WAIT_TIMEOUT: |
acbd19b9fbe1
tests: killdaemons.py for windows distinguishes access violation and terminated
Simon Heimberg <simohe@besonet.ch>
parents:
20495
diff
changeset
|
33 _check(ctypes.windll.kernel32.TerminateProcess(handle, -1)) |
acbd19b9fbe1
tests: killdaemons.py for windows distinguishes access violation and terminated
Simon Heimberg <simohe@besonet.ch>
parents:
20495
diff
changeset
|
34 else: |
acbd19b9fbe1
tests: killdaemons.py for windows distinguishes access violation and terminated
Simon Heimberg <simohe@besonet.ch>
parents:
20495
diff
changeset
|
35 _check(r) |
20494
ea3adeac5248
tests: killdaemons.py for windows waits for killed process to terminate
Simon Heimberg <simohe@besonet.ch>
parents:
20493
diff
changeset
|
36 |
ea3adeac5248
tests: killdaemons.py for windows waits for killed process to terminate
Simon Heimberg <simohe@besonet.ch>
parents:
20493
diff
changeset
|
37 # TODO?: forcefully kill when timeout |
ea3adeac5248
tests: killdaemons.py for windows waits for killed process to terminate
Simon Heimberg <simohe@besonet.ch>
parents:
20493
diff
changeset
|
38 # and ?shorter waiting time? when tryhard==True |
ea3adeac5248
tests: killdaemons.py for windows waits for killed process to terminate
Simon Heimberg <simohe@besonet.ch>
parents:
20493
diff
changeset
|
39 r = ctypes.windll.kernel32.WaitForSingleObject(handle, 100) |
ea3adeac5248
tests: killdaemons.py for windows waits for killed process to terminate
Simon Heimberg <simohe@besonet.ch>
parents:
20493
diff
changeset
|
40 # timeout = 100 ms |
ea3adeac5248
tests: killdaemons.py for windows waits for killed process to terminate
Simon Heimberg <simohe@besonet.ch>
parents:
20493
diff
changeset
|
41 if r == WAIT_OBJECT_0: |
ea3adeac5248
tests: killdaemons.py for windows waits for killed process to terminate
Simon Heimberg <simohe@besonet.ch>
parents:
20493
diff
changeset
|
42 pass # process is terminated |
ea3adeac5248
tests: killdaemons.py for windows waits for killed process to terminate
Simon Heimberg <simohe@besonet.ch>
parents:
20493
diff
changeset
|
43 elif r == WAIT_TIMEOUT: |
ea3adeac5248
tests: killdaemons.py for windows waits for killed process to terminate
Simon Heimberg <simohe@besonet.ch>
parents:
20493
diff
changeset
|
44 logfn('# Daemon process %d is stuck') |
ea3adeac5248
tests: killdaemons.py for windows waits for killed process to terminate
Simon Heimberg <simohe@besonet.ch>
parents:
20493
diff
changeset
|
45 else: |
21194
476069509e72
killdaemons: correct typo of _check() function caught by pyflakes
Yuya Nishihara <yuya@tcha.org>
parents:
20698
diff
changeset
|
46 _check(r) # any error |
20493
b5f43dbf64ca
tests: kill for windows in killdaemons.py checks return values
Simon Heimberg <simohe@besonet.ch>
parents:
17466
diff
changeset
|
47 except: #re-raises |
b5f43dbf64ca
tests: kill for windows in killdaemons.py checks return values
Simon Heimberg <simohe@besonet.ch>
parents:
17466
diff
changeset
|
48 ctypes.windll.kernel32.CloseHandle(handle) # no _check, keep error |
b5f43dbf64ca
tests: kill for windows in killdaemons.py checks return values
Simon Heimberg <simohe@besonet.ch>
parents:
17466
diff
changeset
|
49 raise |
b5f43dbf64ca
tests: kill for windows in killdaemons.py checks return values
Simon Heimberg <simohe@besonet.ch>
parents:
17466
diff
changeset
|
50 _check(ctypes.windll.kernel32.CloseHandle(handle)) |
b5f43dbf64ca
tests: kill for windows in killdaemons.py checks return values
Simon Heimberg <simohe@besonet.ch>
parents:
17466
diff
changeset
|
51 |
17465
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
52 else: |
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
53 def kill(pid, logfn, tryhard=True): |
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
54 try: |
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
55 os.kill(pid, 0) |
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
56 logfn('# Killing daemon process %d' % pid) |
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
57 os.kill(pid, signal.SIGTERM) |
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
58 if tryhard: |
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
59 for i in range(10): |
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
60 time.sleep(0.05) |
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
61 os.kill(pid, 0) |
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
62 else: |
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
63 time.sleep(0.1) |
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
64 os.kill(pid, 0) |
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
65 logfn('# Daemon process %d is stuck - really killing it' % pid) |
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
66 os.kill(pid, signal.SIGKILL) |
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
67 except OSError, err: |
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
68 if err.errno != errno.ESRCH: |
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
69 raise |
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
70 |
17464
eddfb9a550d0
run-tests: do not duplicate killdaemons() code
Patrick Mezard <patrick@mezard.eu>
parents:
10905
diff
changeset
|
71 def killdaemons(pidfile, tryhard=True, remove=False, logfn=None): |
eddfb9a550d0
run-tests: do not duplicate killdaemons() code
Patrick Mezard <patrick@mezard.eu>
parents:
10905
diff
changeset
|
72 if not logfn: |
eddfb9a550d0
run-tests: do not duplicate killdaemons() code
Patrick Mezard <patrick@mezard.eu>
parents:
10905
diff
changeset
|
73 logfn = lambda s: s |
eddfb9a550d0
run-tests: do not duplicate killdaemons() code
Patrick Mezard <patrick@mezard.eu>
parents:
10905
diff
changeset
|
74 # Kill off any leftover daemon processes |
eddfb9a550d0
run-tests: do not duplicate killdaemons() code
Patrick Mezard <patrick@mezard.eu>
parents:
10905
diff
changeset
|
75 try: |
eddfb9a550d0
run-tests: do not duplicate killdaemons() code
Patrick Mezard <patrick@mezard.eu>
parents:
10905
diff
changeset
|
76 fp = open(pidfile) |
eddfb9a550d0
run-tests: do not duplicate killdaemons() code
Patrick Mezard <patrick@mezard.eu>
parents:
10905
diff
changeset
|
77 for line in fp: |
eddfb9a550d0
run-tests: do not duplicate killdaemons() code
Patrick Mezard <patrick@mezard.eu>
parents:
10905
diff
changeset
|
78 try: |
eddfb9a550d0
run-tests: do not duplicate killdaemons() code
Patrick Mezard <patrick@mezard.eu>
parents:
10905
diff
changeset
|
79 pid = int(line) |
eddfb9a550d0
run-tests: do not duplicate killdaemons() code
Patrick Mezard <patrick@mezard.eu>
parents:
10905
diff
changeset
|
80 except ValueError: |
eddfb9a550d0
run-tests: do not duplicate killdaemons() code
Patrick Mezard <patrick@mezard.eu>
parents:
10905
diff
changeset
|
81 continue |
17465
2d4a096e213c
killdaemons: add windows implementation
Patrick Mezard <patrick@mezard.eu>
parents:
17464
diff
changeset
|
82 kill(pid, logfn, tryhard) |
17464
eddfb9a550d0
run-tests: do not duplicate killdaemons() code
Patrick Mezard <patrick@mezard.eu>
parents:
10905
diff
changeset
|
83 fp.close() |
eddfb9a550d0
run-tests: do not duplicate killdaemons() code
Patrick Mezard <patrick@mezard.eu>
parents:
10905
diff
changeset
|
84 if remove: |
eddfb9a550d0
run-tests: do not duplicate killdaemons() code
Patrick Mezard <patrick@mezard.eu>
parents:
10905
diff
changeset
|
85 os.unlink(pidfile) |
eddfb9a550d0
run-tests: do not duplicate killdaemons() code
Patrick Mezard <patrick@mezard.eu>
parents:
10905
diff
changeset
|
86 except IOError: |
eddfb9a550d0
run-tests: do not duplicate killdaemons() code
Patrick Mezard <patrick@mezard.eu>
parents:
10905
diff
changeset
|
87 pass |
eddfb9a550d0
run-tests: do not duplicate killdaemons() code
Patrick Mezard <patrick@mezard.eu>
parents:
10905
diff
changeset
|
88 |
eddfb9a550d0
run-tests: do not duplicate killdaemons() code
Patrick Mezard <patrick@mezard.eu>
parents:
10905
diff
changeset
|
89 if __name__ == '__main__': |
17466
d5a3bda6e170
killdaemons: take file argument explicitely
Patrick Mezard <patrick@mezard.eu>
parents:
17465
diff
changeset
|
90 path, = sys.argv[1:] |
d5a3bda6e170
killdaemons: take file argument explicitely
Patrick Mezard <patrick@mezard.eu>
parents:
17465
diff
changeset
|
91 killdaemons(path) |