author | Raphaël Gomès <rgomes@octobus.net> |
Mon, 22 Jul 2024 14:42:54 +0200 | |
changeset 51710 | 8fe7c0e1df1e |
parent 51703 | ca7bde5dbafb |
child 51862 | 607e94e01851 |
permissions | -rw-r--r-- |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1 |
# __init__.py - fsmonitor initialization and overrides |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
2 |
# |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
3 |
# Copyright 2013-2016 Facebook, Inc. |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
4 |
# |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
5 |
# This software may be used and distributed according to the terms of the |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
6 |
# GNU General Public License version 2 or any later version. |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
7 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
8 |
'''Faster status operations with the Watchman file monitor (EXPERIMENTAL) |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
9 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
10 |
Integrates the file-watching program Watchman with Mercurial to produce faster |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
11 |
status results. |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
12 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
13 |
On a particular Linux system, for a real-world repository with over 400,000 |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
14 |
files hosted on ext4, vanilla `hg status` takes 1.3 seconds. On the same |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
15 |
system, with fsmonitor it takes about 0.3 seconds. |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
16 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
17 |
fsmonitor requires no configuration -- it will tell Watchman about your |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
18 |
repository as necessary. You'll need to install Watchman from |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
19 |
https://facebook.github.io/watchman/ and make sure it is in your PATH. |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
20 |
|
34885
df2ff314e36f
fsmonitor: warn when fsmonitor could be used
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34647
diff
changeset
|
21 |
fsmonitor is incompatible with the largefiles and eol extensions, and |
df2ff314e36f
fsmonitor: warn when fsmonitor could be used
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34647
diff
changeset
|
22 |
will disable itself if any of those are active. |
df2ff314e36f
fsmonitor: warn when fsmonitor could be used
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34647
diff
changeset
|
23 |
|
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
24 |
The following configuration options exist: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
25 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
26 |
:: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
27 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
28 |
[fsmonitor] |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
29 |
mode = {off, on, paranoid} |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
30 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
31 |
When `mode = off`, fsmonitor will disable itself (similar to not loading the |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
32 |
extension at all). When `mode = on`, fsmonitor will be enabled (the default). |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
33 |
When `mode = paranoid`, fsmonitor will query both Watchman and the filesystem, |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
34 |
and ensure that the results are consistent. |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
35 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
36 |
:: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
37 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
38 |
[fsmonitor] |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
39 |
timeout = (float) |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
40 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
41 |
A value, in seconds, that determines how long fsmonitor will wait for Watchman |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
42 |
to return results. Defaults to `2.0`. |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
43 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
44 |
:: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
45 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
46 |
[fsmonitor] |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
47 |
blacklistusers = (list of userids) |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
48 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
49 |
A list of usernames for which fsmonitor will disable itself altogether. |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
50 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
51 |
:: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
52 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
53 |
[fsmonitor] |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
54 |
walk_on_invalidate = (boolean) |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
55 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
56 |
Whether or not to walk the whole repo ourselves when our cached state has been |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
57 |
invalidated, for example when Watchman has been restarted or .hgignore rules |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
58 |
have been changed. Walking the repo in that case can result in competing for |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
59 |
I/O with Watchman. For large repos it is recommended to set this value to |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
60 |
false. You may wish to set this to true if you have a very fast filesystem |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
61 |
that can outpace the IPC overhead of getting the result data for the full repo |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
62 |
from Watchman. Defaults to false. |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
63 |
|
34885
df2ff314e36f
fsmonitor: warn when fsmonitor could be used
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34647
diff
changeset
|
64 |
:: |
df2ff314e36f
fsmonitor: warn when fsmonitor could be used
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34647
diff
changeset
|
65 |
|
df2ff314e36f
fsmonitor: warn when fsmonitor could be used
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34647
diff
changeset
|
66 |
[fsmonitor] |
df2ff314e36f
fsmonitor: warn when fsmonitor could be used
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34647
diff
changeset
|
67 |
warn_when_unused = (boolean) |
df2ff314e36f
fsmonitor: warn when fsmonitor could be used
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34647
diff
changeset
|
68 |
|
df2ff314e36f
fsmonitor: warn when fsmonitor could be used
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34647
diff
changeset
|
69 |
Whether to print a warning during certain operations when fsmonitor would be |
df2ff314e36f
fsmonitor: warn when fsmonitor could be used
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34647
diff
changeset
|
70 |
beneficial to performance but isn't enabled. |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
71 |
|
34885
df2ff314e36f
fsmonitor: warn when fsmonitor could be used
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34647
diff
changeset
|
72 |
:: |
df2ff314e36f
fsmonitor: warn when fsmonitor could be used
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34647
diff
changeset
|
73 |
|
df2ff314e36f
fsmonitor: warn when fsmonitor could be used
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34647
diff
changeset
|
74 |
[fsmonitor] |
df2ff314e36f
fsmonitor: warn when fsmonitor could be used
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34647
diff
changeset
|
75 |
warn_update_file_count = (integer) |
45462
c1d6e930ac8a
fsmonitor: increase the threshold before we recommend it, when using rust
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
44829
diff
changeset
|
76 |
# or when mercurial is built with rust support |
c1d6e930ac8a
fsmonitor: increase the threshold before we recommend it, when using rust
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
44829
diff
changeset
|
77 |
warn_update_file_count_rust = (integer) |
34885
df2ff314e36f
fsmonitor: warn when fsmonitor could be used
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34647
diff
changeset
|
78 |
|
df2ff314e36f
fsmonitor: warn when fsmonitor could be used
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34647
diff
changeset
|
79 |
If ``warn_when_unused`` is set and fsmonitor isn't enabled, a warning will |
df2ff314e36f
fsmonitor: warn when fsmonitor could be used
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34647
diff
changeset
|
80 |
be printed during working directory updates if this many files will be |
df2ff314e36f
fsmonitor: warn when fsmonitor could be used
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34647
diff
changeset
|
81 |
created. |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
82 |
''' |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
83 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
84 |
# Platforms Supported |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
85 |
# =================== |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
86 |
# |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
87 |
# **Linux:** *Stable*. Watchman and fsmonitor are both known to work reliably, |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
88 |
# even under severe loads. |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
89 |
# |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
90 |
# **Mac OS X:** *Stable*. The Mercurial test suite passes with fsmonitor |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
91 |
# turned on, on case-insensitive HFS+. There has been a reasonable amount of |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
92 |
# user testing under normal loads. |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
93 |
# |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
94 |
# **Solaris, BSD:** *Alpha*. watchman and fsmonitor are believed to work, but |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
95 |
# very little testing has been done. |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
96 |
# |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
97 |
# **Windows:** *Alpha*. Not in a release version of watchman or fsmonitor yet. |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
98 |
# |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
99 |
# Known Issues |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
100 |
# ============ |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
101 |
# |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
102 |
# * fsmonitor will disable itself if any of the following extensions are |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
103 |
# enabled: largefiles, inotify, eol; or if the repository has subrepos. |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
104 |
# * fsmonitor will produce incorrect results if nested repos that are not |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
105 |
# subrepos exist. *Workaround*: add nested repo paths to your `.hgignore`. |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
106 |
# |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
107 |
# The issues related to nested repos and subrepos are probably not fundamental |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
108 |
# ones. Patches to fix them are welcome. |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
109 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
110 |
|
31846
1064a296a2a7
fsmonitor: match watchman and filesystem encoding
Olivier Trempe <oliviertrempe@gmail.com>
parents:
30666
diff
changeset
|
111 |
import codecs |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
112 |
import os |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
113 |
import stat |
31846
1064a296a2a7
fsmonitor: match watchman and filesystem encoding
Olivier Trempe <oliviertrempe@gmail.com>
parents:
30666
diff
changeset
|
114 |
import sys |
42652
684b56ade431
fsmonitor: add support for extra `hg debuginstall` data
Augie Fackler <augie@google.com>
parents:
42650
diff
changeset
|
115 |
import tempfile |
34565
4aa57627692a
fsmonitor: add new watchman notifications to fsmonitor extension
Eamonn Kent <ekent@fb.com>
parents:
34564
diff
changeset
|
116 |
import weakref |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
117 |
|
29205
a0939666b836
py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents:
28443
diff
changeset
|
118 |
from mercurial.i18n import _ |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
119 |
from mercurial.node import hex |
49468
2905b78fc52e
fsmonitor: use new dirstate APIs (issue6728)
Raphaël Gomès <rgomes@octobus.net>
parents:
49044
diff
changeset
|
120 |
|
43085
eef9a2d67051
py3: manually import pycompat.open into files that need it
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43077
diff
changeset
|
121 |
from mercurial.pycompat import open |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
122 |
from mercurial import ( |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
123 |
context, |
30666
6ada1658fc6b
py3: use python 3 compatible variables in hgext/fsmontor/__init__.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30332
diff
changeset
|
124 |
encoding, |
31846
1064a296a2a7
fsmonitor: match watchman and filesystem encoding
Olivier Trempe <oliviertrempe@gmail.com>
parents:
30666
diff
changeset
|
125 |
error, |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
126 |
extensions, |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
127 |
localrepo, |
28443
49d65663d7e4
fsmonitor: hook up state-enter, state-leave signals
Martijn Pieters <mjpieters@fb.com>
parents:
28433
diff
changeset
|
128 |
merge, |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
129 |
pathutil, |
30666
6ada1658fc6b
py3: use python 3 compatible variables in hgext/fsmontor/__init__.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30332
diff
changeset
|
130 |
pycompat, |
34463
718f7acd6d5e
fsmonitor: use configitem
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34462
diff
changeset
|
131 |
registrar, |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
132 |
scmutil, |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
133 |
util, |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
134 |
) |
49468
2905b78fc52e
fsmonitor: use new dirstate APIs (issue6728)
Raphaël Gomès <rgomes@octobus.net>
parents:
49044
diff
changeset
|
135 |
|
2905b78fc52e
fsmonitor: use new dirstate APIs (issue6728)
Raphaël Gomès <rgomes@octobus.net>
parents:
49044
diff
changeset
|
136 |
# no-check-code because we're accessing private information only public in pure |
2905b78fc52e
fsmonitor: use new dirstate APIs (issue6728)
Raphaël Gomès <rgomes@octobus.net>
parents:
49044
diff
changeset
|
137 |
from mercurial.pure import parsers |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
138 |
from mercurial import match as matchmod |
44062
2d49482d0dd4
hgext: replace references to hashlib.sha1 with hashutil.sha1
Augie Fackler <augie@google.com>
parents:
43403
diff
changeset
|
139 |
from mercurial.utils import ( |
2d49482d0dd4
hgext: replace references to hashlib.sha1 with hashutil.sha1
Augie Fackler <augie@google.com>
parents:
43403
diff
changeset
|
140 |
hashutil, |
2d49482d0dd4
hgext: replace references to hashlib.sha1 with hashutil.sha1
Augie Fackler <augie@google.com>
parents:
43403
diff
changeset
|
141 |
stringutil, |
2d49482d0dd4
hgext: replace references to hashlib.sha1 with hashutil.sha1
Augie Fackler <augie@google.com>
parents:
43403
diff
changeset
|
142 |
) |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
143 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
144 |
from . import ( |
31846
1064a296a2a7
fsmonitor: match watchman and filesystem encoding
Olivier Trempe <oliviertrempe@gmail.com>
parents:
30666
diff
changeset
|
145 |
pywatchman, |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
146 |
state, |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
147 |
watchmanclient, |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
148 |
) |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
149 |
|
29841
d5883fd055c6
extensions: change magic "shipped with hg" string
Augie Fackler <augie@google.com>
parents:
29341
diff
changeset
|
150 |
# Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
151 |
# extensions which SHIP WITH MERCURIAL. Non-mainline extensions should |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
152 |
# be specifying the version(s) of Mercurial they are tested with, or |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
153 |
# leave the attribute unspecified. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
154 |
testedwith = b'ships-with-hg-core' |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
155 |
|
34463
718f7acd6d5e
fsmonitor: use configitem
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34462
diff
changeset
|
156 |
configtable = {} |
718f7acd6d5e
fsmonitor: use configitem
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34462
diff
changeset
|
157 |
configitem = registrar.configitem(configtable) |
718f7acd6d5e
fsmonitor: use configitem
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34462
diff
changeset
|
158 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
159 |
configitem( |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45557
diff
changeset
|
160 |
b'fsmonitor', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45557
diff
changeset
|
161 |
b'mode', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45557
diff
changeset
|
162 |
default=b'on', |
34463
718f7acd6d5e
fsmonitor: use configitem
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34462
diff
changeset
|
163 |
) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
164 |
configitem( |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45557
diff
changeset
|
165 |
b'fsmonitor', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45557
diff
changeset
|
166 |
b'walk_on_invalidate', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45557
diff
changeset
|
167 |
default=False, |
34463
718f7acd6d5e
fsmonitor: use configitem
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34462
diff
changeset
|
168 |
) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
169 |
configitem( |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45557
diff
changeset
|
170 |
b'fsmonitor', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45557
diff
changeset
|
171 |
b'timeout', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45557
diff
changeset
|
172 |
default=b'2', |
34463
718f7acd6d5e
fsmonitor: use configitem
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34462
diff
changeset
|
173 |
) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
174 |
configitem( |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45557
diff
changeset
|
175 |
b'fsmonitor', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45557
diff
changeset
|
176 |
b'blacklistusers', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45557
diff
changeset
|
177 |
default=list, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45557
diff
changeset
|
178 |
) |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45557
diff
changeset
|
179 |
configitem( |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45557
diff
changeset
|
180 |
b'fsmonitor', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45557
diff
changeset
|
181 |
b'watchman_exe', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45557
diff
changeset
|
182 |
default=b'watchman', |
34463
718f7acd6d5e
fsmonitor: use configitem
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34462
diff
changeset
|
183 |
) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
184 |
configitem( |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45557
diff
changeset
|
185 |
b'fsmonitor', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45557
diff
changeset
|
186 |
b'verbose', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45557
diff
changeset
|
187 |
default=True, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45557
diff
changeset
|
188 |
experimental=True, |
41968
57264906a996
watchman: add the possibility to set the exact watchman binary location
Boris Feld <boris.feld@octobus.net>
parents:
41676
diff
changeset
|
189 |
) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
190 |
configitem( |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45557
diff
changeset
|
191 |
b'experimental', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45557
diff
changeset
|
192 |
b'fsmonitor.transaction_notify', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45557
diff
changeset
|
193 |
default=False, |
35313
c67fb3bfe3a1
fsmonitor: fsmonitor should send wlock notifications to watchman
Eamonn Kent <ekent@fb.com>
parents:
35312
diff
changeset
|
194 |
) |
34463
718f7acd6d5e
fsmonitor: use configitem
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34462
diff
changeset
|
195 |
|
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
196 |
# This extension is incompatible with the following blacklisted extensions |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
197 |
# and will disable itself when encountering one of these: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
198 |
_blacklist = [b'largefiles', b'eol'] |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
199 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
200 |
|
42652
684b56ade431
fsmonitor: add support for extra `hg debuginstall` data
Augie Fackler <augie@google.com>
parents:
42650
diff
changeset
|
201 |
def debuginstall(ui, fm): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
202 |
fm.write( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
203 |
b"fsmonitor-watchman", |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
204 |
_(b"fsmonitor checking for watchman binary... (%s)\n"), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
205 |
ui.configpath(b"fsmonitor", b"watchman_exe"), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
206 |
) |
42652
684b56ade431
fsmonitor: add support for extra `hg debuginstall` data
Augie Fackler <augie@google.com>
parents:
42650
diff
changeset
|
207 |
root = tempfile.mkdtemp() |
684b56ade431
fsmonitor: add support for extra `hg debuginstall` data
Augie Fackler <augie@google.com>
parents:
42650
diff
changeset
|
208 |
c = watchmanclient.client(ui, root) |
684b56ade431
fsmonitor: add support for extra `hg debuginstall` data
Augie Fackler <augie@google.com>
parents:
42650
diff
changeset
|
209 |
err = None |
684b56ade431
fsmonitor: add support for extra `hg debuginstall` data
Augie Fackler <augie@google.com>
parents:
42650
diff
changeset
|
210 |
try: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
211 |
v = c.command(b"version") |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
212 |
fm.write( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
213 |
b"fsmonitor-watchman-version", |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
214 |
_(b" watchman binary version %s\n"), |
43389
e6ce1599af74
fsmonitor: fix str/bytes mismatch when accessing watchman version
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43374
diff
changeset
|
215 |
pycompat.bytestr(v["version"]), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
216 |
) |
42652
684b56ade431
fsmonitor: add support for extra `hg debuginstall` data
Augie Fackler <augie@google.com>
parents:
42650
diff
changeset
|
217 |
except watchmanclient.Unavailable as e: |
43403
90fba2248693
fsmonitor: use stringutil.forcebytestr() instead of str() on an exception
Ian Moody <moz-ian@perix.co.uk>
parents:
43397
diff
changeset
|
218 |
err = stringutil.forcebytestr(e) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
219 |
fm.condwrite( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
220 |
err, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
221 |
b"fsmonitor-watchman-error", |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
222 |
_(b" watchman binary missing or broken: %s\n"), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
223 |
err, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
224 |
) |
42652
684b56ade431
fsmonitor: add support for extra `hg debuginstall` data
Augie Fackler <augie@google.com>
parents:
42650
diff
changeset
|
225 |
return 1 if err else 0 |
684b56ade431
fsmonitor: add support for extra `hg debuginstall` data
Augie Fackler <augie@google.com>
parents:
42650
diff
changeset
|
226 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
227 |
|
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
228 |
def _handleunavailable(ui, state, ex): |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
229 |
"""Exception handler for Watchman interaction exceptions""" |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
230 |
if isinstance(ex, watchmanclient.Unavailable): |
41609
286eeed14893
fsmonitor: rename new verbose config knob
Boris Feld <boris.feld@octobus.net>
parents:
41489
diff
changeset
|
231 |
# experimental config: fsmonitor.verbose |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
232 |
if ex.warn and ui.configbool(b'fsmonitor', b'verbose'): |
43362
ddfd0f3956f4
py3: fix fsmonitor's _handleunavailable exception message encoding
Emmanuel Leblond <emmanuel.leblond@gmail.com>
parents:
43105
diff
changeset
|
233 |
if b'illegal_fstypes' not in stringutil.forcebytestr(ex): |
ddfd0f3956f4
py3: fix fsmonitor's _handleunavailable exception message encoding
Emmanuel Leblond <emmanuel.leblond@gmail.com>
parents:
43105
diff
changeset
|
234 |
ui.warn(stringutil.forcebytestr(ex) + b'\n') |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
235 |
if ex.invalidate: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
236 |
state.invalidate() |
41609
286eeed14893
fsmonitor: rename new verbose config knob
Boris Feld <boris.feld@octobus.net>
parents:
41489
diff
changeset
|
237 |
# experimental config: fsmonitor.verbose |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
238 |
if ui.configbool(b'fsmonitor', b'verbose'): |
43390
5fa8ac91190e
fsmonitor: coerce watchman exception to bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43389
diff
changeset
|
239 |
ui.log( |
5fa8ac91190e
fsmonitor: coerce watchman exception to bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43389
diff
changeset
|
240 |
b'fsmonitor', |
5fa8ac91190e
fsmonitor: coerce watchman exception to bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43389
diff
changeset
|
241 |
b'Watchman unavailable: %s\n', |
5fa8ac91190e
fsmonitor: coerce watchman exception to bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43389
diff
changeset
|
242 |
stringutil.forcebytestr(ex.msg), |
5fa8ac91190e
fsmonitor: coerce watchman exception to bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43389
diff
changeset
|
243 |
) |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
244 |
else: |
43390
5fa8ac91190e
fsmonitor: coerce watchman exception to bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43389
diff
changeset
|
245 |
ui.log( |
5fa8ac91190e
fsmonitor: coerce watchman exception to bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43389
diff
changeset
|
246 |
b'fsmonitor', |
5fa8ac91190e
fsmonitor: coerce watchman exception to bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43389
diff
changeset
|
247 |
b'Watchman exception: %s\n', |
5fa8ac91190e
fsmonitor: coerce watchman exception to bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43389
diff
changeset
|
248 |
stringutil.forcebytestr(ex), |
5fa8ac91190e
fsmonitor: coerce watchman exception to bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43389
diff
changeset
|
249 |
) |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
250 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
251 |
|
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
252 |
def _hashignore(ignore): |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
253 |
"""Calculate hash for ignore patterns and filenames |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
254 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
255 |
If this information changes between Mercurial invocations, we can't |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
256 |
rely on Watchman information anymore and have to re-scan the working |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
257 |
copy. |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
258 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
259 |
""" |
44062
2d49482d0dd4
hgext: replace references to hashlib.sha1 with hashutil.sha1
Augie Fackler <augie@google.com>
parents:
43403
diff
changeset
|
260 |
sha1 = hashutil.sha1() |
43393
bdebc7b54dca
fsmonitor: make _hashignore compatible with Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43391
diff
changeset
|
261 |
sha1.update(pycompat.byterepr(ignore)) |
bdebc7b54dca
fsmonitor: make _hashignore compatible with Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43391
diff
changeset
|
262 |
return pycompat.sysbytes(sha1.hexdigest()) |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
263 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
264 |
|
31846
1064a296a2a7
fsmonitor: match watchman and filesystem encoding
Olivier Trempe <oliviertrempe@gmail.com>
parents:
30666
diff
changeset
|
265 |
_watchmanencoding = pywatchman.encoding.get_local_encoding() |
1064a296a2a7
fsmonitor: match watchman and filesystem encoding
Olivier Trempe <oliviertrempe@gmail.com>
parents:
30666
diff
changeset
|
266 |
_fsencoding = sys.getfilesystemencoding() or sys.getdefaultencoding() |
1064a296a2a7
fsmonitor: match watchman and filesystem encoding
Olivier Trempe <oliviertrempe@gmail.com>
parents:
30666
diff
changeset
|
267 |
_fixencoding = codecs.lookup(_watchmanencoding) != codecs.lookup(_fsencoding) |
1064a296a2a7
fsmonitor: match watchman and filesystem encoding
Olivier Trempe <oliviertrempe@gmail.com>
parents:
30666
diff
changeset
|
268 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
269 |
|
31846
1064a296a2a7
fsmonitor: match watchman and filesystem encoding
Olivier Trempe <oliviertrempe@gmail.com>
parents:
30666
diff
changeset
|
270 |
def _watchmantofsencoding(path): |
1064a296a2a7
fsmonitor: match watchman and filesystem encoding
Olivier Trempe <oliviertrempe@gmail.com>
parents:
30666
diff
changeset
|
271 |
"""Fix path to match watchman and local filesystem encoding |
1064a296a2a7
fsmonitor: match watchman and filesystem encoding
Olivier Trempe <oliviertrempe@gmail.com>
parents:
30666
diff
changeset
|
272 |
|
1064a296a2a7
fsmonitor: match watchman and filesystem encoding
Olivier Trempe <oliviertrempe@gmail.com>
parents:
30666
diff
changeset
|
273 |
watchman's paths encoding can differ from filesystem encoding. For example, |
1064a296a2a7
fsmonitor: match watchman and filesystem encoding
Olivier Trempe <oliviertrempe@gmail.com>
parents:
30666
diff
changeset
|
274 |
on Windows, it's always utf-8. |
1064a296a2a7
fsmonitor: match watchman and filesystem encoding
Olivier Trempe <oliviertrempe@gmail.com>
parents:
30666
diff
changeset
|
275 |
""" |
1064a296a2a7
fsmonitor: match watchman and filesystem encoding
Olivier Trempe <oliviertrempe@gmail.com>
parents:
30666
diff
changeset
|
276 |
try: |
1064a296a2a7
fsmonitor: match watchman and filesystem encoding
Olivier Trempe <oliviertrempe@gmail.com>
parents:
30666
diff
changeset
|
277 |
decoded = path.decode(_watchmanencoding) |
1064a296a2a7
fsmonitor: match watchman and filesystem encoding
Olivier Trempe <oliviertrempe@gmail.com>
parents:
30666
diff
changeset
|
278 |
except UnicodeDecodeError as e: |
43374
65c37b431e76
py3: fix fsmonitor's _watchmantofsencoding exception message encoding
Emmanuel Leblond <emmanuel.leblond@gmail.com>
parents:
43362
diff
changeset
|
279 |
raise error.Abort( |
65c37b431e76
py3: fix fsmonitor's _watchmantofsencoding exception message encoding
Emmanuel Leblond <emmanuel.leblond@gmail.com>
parents:
43362
diff
changeset
|
280 |
stringutil.forcebytestr(e), hint=b'watchman encoding error' |
65c37b431e76
py3: fix fsmonitor's _watchmantofsencoding exception message encoding
Emmanuel Leblond <emmanuel.leblond@gmail.com>
parents:
43362
diff
changeset
|
281 |
) |
31846
1064a296a2a7
fsmonitor: match watchman and filesystem encoding
Olivier Trempe <oliviertrempe@gmail.com>
parents:
30666
diff
changeset
|
282 |
|
1064a296a2a7
fsmonitor: match watchman and filesystem encoding
Olivier Trempe <oliviertrempe@gmail.com>
parents:
30666
diff
changeset
|
283 |
try: |
1064a296a2a7
fsmonitor: match watchman and filesystem encoding
Olivier Trempe <oliviertrempe@gmail.com>
parents:
30666
diff
changeset
|
284 |
encoded = decoded.encode(_fsencoding, 'strict') |
1064a296a2a7
fsmonitor: match watchman and filesystem encoding
Olivier Trempe <oliviertrempe@gmail.com>
parents:
30666
diff
changeset
|
285 |
except UnicodeEncodeError as e: |
43374
65c37b431e76
py3: fix fsmonitor's _watchmantofsencoding exception message encoding
Emmanuel Leblond <emmanuel.leblond@gmail.com>
parents:
43362
diff
changeset
|
286 |
raise error.Abort(stringutil.forcebytestr(e)) |
31846
1064a296a2a7
fsmonitor: match watchman and filesystem encoding
Olivier Trempe <oliviertrempe@gmail.com>
parents:
30666
diff
changeset
|
287 |
|
1064a296a2a7
fsmonitor: match watchman and filesystem encoding
Olivier Trempe <oliviertrempe@gmail.com>
parents:
30666
diff
changeset
|
288 |
return encoded |
1064a296a2a7
fsmonitor: match watchman and filesystem encoding
Olivier Trempe <oliviertrempe@gmail.com>
parents:
30666
diff
changeset
|
289 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
290 |
|
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
291 |
def overridewalk(orig, self, match, subrepos, unknown, ignored, full=True): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45557
diff
changeset
|
292 |
"""Replacement for dirstate.walk, hooking into Watchman. |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
293 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
294 |
Whenever full is False, ignored is False, and the Watchman client is |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
295 |
available, use Watchman combined with saved state to possibly return only a |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45557
diff
changeset
|
296 |
subset of files.""" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
297 |
|
35146
0b5716ec8500
fsmonitor: issue debug messages when we fall back to core status
Boris Feld <boris.feld@octobus.net>
parents:
35085
diff
changeset
|
298 |
def bail(reason): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
299 |
self._ui.debug(b'fsmonitor: fallback to core status, %s\n' % reason) |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
300 |
return orig(match, subrepos, unknown, ignored, full=True) |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
301 |
|
35146
0b5716ec8500
fsmonitor: issue debug messages when we fall back to core status
Boris Feld <boris.feld@octobus.net>
parents:
35085
diff
changeset
|
302 |
if full: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
303 |
return bail(b'full rewalk requested') |
35146
0b5716ec8500
fsmonitor: issue debug messages when we fall back to core status
Boris Feld <boris.feld@octobus.net>
parents:
35085
diff
changeset
|
304 |
if ignored: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
305 |
return bail(b'listing ignored files') |
35146
0b5716ec8500
fsmonitor: issue debug messages when we fall back to core status
Boris Feld <boris.feld@octobus.net>
parents:
35085
diff
changeset
|
306 |
if not self._watchmanclient.available(): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
307 |
return bail(b'client unavailable') |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
308 |
state = self._fsmonitorstate |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
309 |
clock, ignorehash, notefiles = state.get() |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
310 |
if not clock: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
311 |
if state.walk_on_invalidate: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
312 |
return bail(b'no clock') |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
313 |
# Initial NULL clock value, see |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
314 |
# https://facebook.github.io/watchman/docs/clockspec.html |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
315 |
clock = b'c:0:0' |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
316 |
notefiles = [] |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
317 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
318 |
ignore = self._ignore |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
319 |
dirignore = self._dirignore |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
320 |
if unknown: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
321 |
if _hashignore(ignore) != ignorehash and clock != b'c:0:0': |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
322 |
# ignore list changed -- can't rely on Watchman state any more |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
323 |
if state.walk_on_invalidate: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
324 |
return bail(b'ignore rules changed') |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
325 |
notefiles = [] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
326 |
clock = b'c:0:0' |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
327 |
else: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
328 |
# always ignore |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
329 |
ignore = util.always |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
330 |
dirignore = util.always |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
331 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
332 |
matchfn = match.matchfn |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
333 |
matchalways = match.always() |
35085
ae7ad53d3c8d
fsmonitor: only access inner dirstate map if it is available
Mark Thomas <mbthomas@fb.com>
parents:
34897
diff
changeset
|
334 |
dmap = self._map |
51129
1625fe807c04
py3: pass unicode strings to hasattr() throughout
Martin von Zweigbergk <martinvonz@google.com>
parents:
50928
diff
changeset
|
335 |
if hasattr(dmap, '_map'): |
35085
ae7ad53d3c8d
fsmonitor: only access inner dirstate map if it is available
Mark Thomas <mbthomas@fb.com>
parents:
34897
diff
changeset
|
336 |
# for better performance, directly access the inner dirstate map if the |
ae7ad53d3c8d
fsmonitor: only access inner dirstate map if it is available
Mark Thomas <mbthomas@fb.com>
parents:
34897
diff
changeset
|
337 |
# standard dirstate implementation is in use. |
ae7ad53d3c8d
fsmonitor: only access inner dirstate map if it is available
Mark Thomas <mbthomas@fb.com>
parents:
34897
diff
changeset
|
338 |
dmap = dmap._map |
49468
2905b78fc52e
fsmonitor: use new dirstate APIs (issue6728)
Raphaël Gomès <rgomes@octobus.net>
parents:
49044
diff
changeset
|
339 |
|
2905b78fc52e
fsmonitor: use new dirstate APIs (issue6728)
Raphaël Gomès <rgomes@octobus.net>
parents:
49044
diff
changeset
|
340 |
has_mtime = parsers.DIRSTATE_V2_HAS_MTIME |
2905b78fc52e
fsmonitor: use new dirstate APIs (issue6728)
Raphaël Gomès <rgomes@octobus.net>
parents:
49044
diff
changeset
|
341 |
mtime_is_ambiguous = parsers.DIRSTATE_V2_MTIME_SECOND_AMBIGUOUS |
2905b78fc52e
fsmonitor: use new dirstate APIs (issue6728)
Raphaël Gomès <rgomes@octobus.net>
parents:
49044
diff
changeset
|
342 |
mask = has_mtime | mtime_is_ambiguous |
2905b78fc52e
fsmonitor: use new dirstate APIs (issue6728)
Raphaël Gomès <rgomes@octobus.net>
parents:
49044
diff
changeset
|
343 |
|
2905b78fc52e
fsmonitor: use new dirstate APIs (issue6728)
Raphaël Gomès <rgomes@octobus.net>
parents:
49044
diff
changeset
|
344 |
# All entries that may not be clean |
48306
1421c75b20de
fsmonitor: fix traceback after removal of nonnormalset (issue6600)
Raphaël Gomès <rgomes@octobus.net>
parents:
48305
diff
changeset
|
345 |
nonnormalset = { |
1421c75b20de
fsmonitor: fix traceback after removal of nonnormalset (issue6600)
Raphaël Gomès <rgomes@octobus.net>
parents:
48305
diff
changeset
|
346 |
f |
1421c75b20de
fsmonitor: fix traceback after removal of nonnormalset (issue6600)
Raphaël Gomès <rgomes@octobus.net>
parents:
48305
diff
changeset
|
347 |
for f, e in self._map.items() |
49468
2905b78fc52e
fsmonitor: use new dirstate APIs (issue6728)
Raphaël Gomès <rgomes@octobus.net>
parents:
49044
diff
changeset
|
348 |
if not e.maybe_clean |
2905b78fc52e
fsmonitor: use new dirstate APIs (issue6728)
Raphaël Gomès <rgomes@octobus.net>
parents:
49044
diff
changeset
|
349 |
# same as "not has_time or has_ambiguous_time", but factored to only |
2905b78fc52e
fsmonitor: use new dirstate APIs (issue6728)
Raphaël Gomès <rgomes@octobus.net>
parents:
49044
diff
changeset
|
350 |
# need a single access to flags for performance. |
2905b78fc52e
fsmonitor: use new dirstate APIs (issue6728)
Raphaël Gomès <rgomes@octobus.net>
parents:
49044
diff
changeset
|
351 |
# `mask` removes all irrelevant bits, then we flip the `mtime` bit so |
2905b78fc52e
fsmonitor: use new dirstate APIs (issue6728)
Raphaël Gomès <rgomes@octobus.net>
parents:
49044
diff
changeset
|
352 |
# its `true` value is NOT having a mtime, then check if either bit |
2905b78fc52e
fsmonitor: use new dirstate APIs (issue6728)
Raphaël Gomès <rgomes@octobus.net>
parents:
49044
diff
changeset
|
353 |
# is set. |
2905b78fc52e
fsmonitor: use new dirstate APIs (issue6728)
Raphaël Gomès <rgomes@octobus.net>
parents:
49044
diff
changeset
|
354 |
or bool((e.v2_data()[0] & mask) ^ has_mtime) |
48306
1421c75b20de
fsmonitor: fix traceback after removal of nonnormalset (issue6600)
Raphaël Gomès <rgomes@octobus.net>
parents:
48305
diff
changeset
|
355 |
} |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
356 |
|
34462
8337f7772aa2
fsmonitor: access copymap in new location
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33649
diff
changeset
|
357 |
copymap = self._map.copymap |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
358 |
getkind = stat.S_IFMT |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
359 |
dirkind = stat.S_IFDIR |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
360 |
regkind = stat.S_IFREG |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
361 |
lnkkind = stat.S_IFLNK |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
362 |
join = self._join |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
363 |
normcase = util.normcase |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
364 |
fresh_instance = False |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
365 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
366 |
exact = skipstep3 = False |
32321
7df259077d4b
fsmonitor: use modern match API
Martin von Zweigbergk <martinvonz@google.com>
parents:
32226
diff
changeset
|
367 |
if match.isexact(): # match.exact |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
368 |
exact = True |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
369 |
dirignore = util.always # skip step 2 |
32321
7df259077d4b
fsmonitor: use modern match API
Martin von Zweigbergk <martinvonz@google.com>
parents:
32226
diff
changeset
|
370 |
elif match.prefix(): # match.match, no patterns |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
371 |
skipstep3 = True |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
372 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
373 |
if not exact and self._checkcase: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
374 |
# note that even though we could receive directory entries, we're only |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
375 |
# interested in checking if a file with the same name exists. So only |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
376 |
# normalize files if possible. |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
377 |
normalize = self._normalizefile |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
378 |
skipstep3 = False |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
379 |
else: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
380 |
normalize = None |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
381 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
382 |
# step 1: find all explicit files |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
383 |
results, work, dirsnotfound = self._walkexplicit(match, subrepos) |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
384 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
385 |
skipstep3 = skipstep3 and not (work or dirsnotfound) |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
386 |
work = [d for d in work if not dirignore(d[0])] |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
387 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
388 |
if not work and (exact or skipstep3): |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
389 |
for s in subrepos: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
390 |
del results[s] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
391 |
del results[b'.hg'] |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
392 |
return results |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
393 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
394 |
# step 2: query Watchman |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
395 |
try: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
396 |
# Use the user-configured timeout for the query. |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
397 |
# Add a little slack over the top of the user query to allow for |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
398 |
# overheads while transferring the data |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
399 |
self._watchmanclient.settimeout(state.timeout + 0.1) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
400 |
result = self._watchmanclient.command( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
401 |
b'query', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
402 |
{ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
403 |
b'fields': [b'mode', b'mtime', b'size', b'exists', b'name'], |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
404 |
b'since': clock, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
405 |
b'expression': [ |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
406 |
b'not', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
407 |
[ |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
408 |
b'anyof', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
409 |
[b'dirname', b'.hg'], |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
410 |
[b'name', b'.hg', b'wholename'], |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
411 |
], |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
412 |
], |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
413 |
b'sync_timeout': int(state.timeout * 1000), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
414 |
b'empty_on_fresh_instance': state.walk_on_invalidate, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
415 |
}, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
416 |
) |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
417 |
except Exception as ex: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
418 |
_handleunavailable(self._ui, state, ex) |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
419 |
self._watchmanclient.clearconnection() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
420 |
return bail(b'exception during run') |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
421 |
else: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
422 |
# We need to propagate the last observed clock up so that we |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
423 |
# can use it for our next query |
43397
09ab61c0ab4b
fsmonitor: normalize clock value to bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43396
diff
changeset
|
424 |
state.setlastclock(pycompat.sysbytes(result[b'clock'])) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
425 |
if result[b'is_fresh_instance']: |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
426 |
if state.walk_on_invalidate: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
427 |
state.invalidate() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
428 |
return bail(b'fresh instance') |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
429 |
fresh_instance = True |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
430 |
# Ignore any prior noteable files from the state info |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
431 |
notefiles = [] |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
432 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
433 |
# for file paths which require normalization and we encounter a case |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
434 |
# collision, we store our own foldmap |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
435 |
if normalize: |
44452
9d2b2df2c2ba
cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents:
44062
diff
changeset
|
436 |
foldmap = {normcase(k): k for k in results} |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
437 |
|
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
438 |
switch_slashes = pycompat.ossep == b'\\' |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
439 |
# The order of the results is, strictly speaking, undefined. |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
440 |
# For case changes on a case insensitive filesystem we may receive |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
441 |
# two entries, one with exists=True and another with exists=False. |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
442 |
# The exists=True entries in the same response should be interpreted |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
443 |
# as being happens-after the exists=False entries due to the way that |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
444 |
# Watchman tracks files. We use this property to reconcile deletes |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
445 |
# for name case changes. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
446 |
for entry in result[b'files']: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
447 |
fname = entry[b'name'] |
43395
2b8be670dcb6
fsmonitor: normalize Watchman paths to bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43393
diff
changeset
|
448 |
|
2b8be670dcb6
fsmonitor: normalize Watchman paths to bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43393
diff
changeset
|
449 |
# Watchman always give us a str. Normalize to bytes on Python 3 |
2b8be670dcb6
fsmonitor: normalize Watchman paths to bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43393
diff
changeset
|
450 |
# using Watchman's encoding, if needed. |
2b8be670dcb6
fsmonitor: normalize Watchman paths to bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43393
diff
changeset
|
451 |
if not isinstance(fname, bytes): |
2b8be670dcb6
fsmonitor: normalize Watchman paths to bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43393
diff
changeset
|
452 |
fname = fname.encode(_watchmanencoding) |
2b8be670dcb6
fsmonitor: normalize Watchman paths to bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43393
diff
changeset
|
453 |
|
31846
1064a296a2a7
fsmonitor: match watchman and filesystem encoding
Olivier Trempe <oliviertrempe@gmail.com>
parents:
30666
diff
changeset
|
454 |
if _fixencoding: |
1064a296a2a7
fsmonitor: match watchman and filesystem encoding
Olivier Trempe <oliviertrempe@gmail.com>
parents:
30666
diff
changeset
|
455 |
fname = _watchmantofsencoding(fname) |
43395
2b8be670dcb6
fsmonitor: normalize Watchman paths to bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43393
diff
changeset
|
456 |
|
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
457 |
if switch_slashes: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
458 |
fname = fname.replace(b'\\', b'/') |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
459 |
if normalize: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
460 |
normed = normcase(fname) |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
461 |
fname = normalize(fname, True, True) |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
462 |
foldmap[normed] = fname |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
463 |
fmode = entry[b'mode'] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
464 |
fexists = entry[b'exists'] |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
465 |
kind = getkind(fmode) |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
466 |
|
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
467 |
if b'/.hg/' in fname or fname.endswith(b'/.hg'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
468 |
return bail(b'nested-repo-detected') |
41489
5125f0a9728b
watchman: detect nested mercurial repositories and abort
Boris Feld <boris.feld@octobus.net>
parents:
41488
diff
changeset
|
469 |
|
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
470 |
if not fexists: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
471 |
# if marked as deleted and we don't already have a change |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
472 |
# record, mark it as deleted. If we already have an entry |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
473 |
# for fname then it was either part of walkexplicit or was |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
474 |
# an earlier result that was a case change |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
475 |
if ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
476 |
fname not in results |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
477 |
and fname in dmap |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
478 |
and (matchalways or matchfn(fname)) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
479 |
): |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
480 |
results[fname] = None |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
481 |
elif kind == dirkind: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
482 |
if fname in dmap and (matchalways or matchfn(fname)): |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
483 |
results[fname] = None |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
484 |
elif kind == regkind or kind == lnkkind: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
485 |
if fname in dmap: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
486 |
if matchalways or matchfn(fname): |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
487 |
results[fname] = entry |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
488 |
elif (matchalways or matchfn(fname)) and not ignore(fname): |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
489 |
results[fname] = entry |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
490 |
elif fname in dmap and (matchalways or matchfn(fname)): |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
491 |
results[fname] = None |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
492 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
493 |
# step 3: query notable files we don't already know about |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
494 |
# XXX try not to iterate over the entire dmap |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
495 |
if normalize: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
496 |
# any notable files that have changed case will already be handled |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
497 |
# above, so just check membership in the foldmap |
44452
9d2b2df2c2ba
cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents:
44062
diff
changeset
|
498 |
notefiles = { |
9d2b2df2c2ba
cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents:
44062
diff
changeset
|
499 |
normalize(f, True, True) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
500 |
for f in notefiles |
44452
9d2b2df2c2ba
cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents:
44062
diff
changeset
|
501 |
if normcase(f) not in foldmap |
9d2b2df2c2ba
cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents:
44062
diff
changeset
|
502 |
} |
9d2b2df2c2ba
cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents:
44062
diff
changeset
|
503 |
visit = { |
9d2b2df2c2ba
cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents:
44062
diff
changeset
|
504 |
f |
9d2b2df2c2ba
cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents:
44062
diff
changeset
|
505 |
for f in notefiles |
9d2b2df2c2ba
cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents:
44062
diff
changeset
|
506 |
if (f not in results and matchfn(f) and (f in dmap or not ignore(f))) |
9d2b2df2c2ba
cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents:
44062
diff
changeset
|
507 |
} |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
508 |
|
34897
2e350d2a0eca
fsmonitor: use nonnormalset from dirstatemap
Jun Wu <quark@fb.com>
parents:
34886
diff
changeset
|
509 |
if not fresh_instance: |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
510 |
if matchalways: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
511 |
visit.update(f for f in nonnormalset if f not in results) |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
512 |
visit.update(f for f in copymap if f not in results) |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
513 |
else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
514 |
visit.update( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
515 |
f for f in nonnormalset if f not in results and matchfn(f) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
516 |
) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
517 |
visit.update(f for f in copymap if f not in results and matchfn(f)) |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
518 |
else: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
519 |
if matchalways: |
48913
f254fc73d956
global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
520 |
visit.update(f for f, st in dmap.items() if f not in results) |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
521 |
visit.update(f for f in copymap if f not in results) |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
522 |
else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
523 |
visit.update( |
48913
f254fc73d956
global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
524 |
f for f, st in dmap.items() if f not in results and matchfn(f) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
525 |
) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
526 |
visit.update(f for f in copymap if f not in results and matchfn(f)) |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
527 |
|
33649
377e8ddaebef
pathauditor: disable cache of audited paths by default (issue5628)
Yuya Nishihara <yuya@tcha.org>
parents:
33387
diff
changeset
|
528 |
audit = pathutil.pathauditor(self._root, cached=True).check |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
529 |
auditpass = [f for f in visit if audit(f)] |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
530 |
auditpass.sort() |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
531 |
auditfail = visit.difference(auditpass) |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
532 |
for f in auditfail: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
533 |
results[f] = None |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
534 |
|
43396
2b5aab5e9e36
fsmonitor: use next() instead of .next()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43395
diff
changeset
|
535 |
nf = iter(auditpass) |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
536 |
for st in util.statfiles([join(f) for f in auditpass]): |
43396
2b5aab5e9e36
fsmonitor: use next() instead of .next()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43395
diff
changeset
|
537 |
f = next(nf) |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
538 |
if st or f in dmap: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
539 |
results[f] = st |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
540 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
541 |
for s in subrepos: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
542 |
del results[s] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
543 |
del results[b'.hg'] |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
544 |
return results |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
545 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
546 |
|
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
547 |
def overridestatus( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
548 |
orig, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
549 |
self, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
550 |
node1=b'.', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
551 |
node2=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
552 |
match=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
553 |
ignored=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
554 |
clean=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
555 |
unknown=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
556 |
listsubrepos=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
557 |
): |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
558 |
listignored = ignored |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
559 |
listclean = clean |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
560 |
listunknown = unknown |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
561 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
562 |
def _cmpsets(l1, l2): |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
563 |
try: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
564 |
if b'FSMONITOR_LOG_FILE' in encoding.environ: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
565 |
fn = encoding.environ[b'FSMONITOR_LOG_FILE'] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
566 |
f = open(fn, b'wb') |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
567 |
else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
568 |
fn = b'fsmonitorfail.log' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
569 |
f = self.vfs.open(fn, b'wb') |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
570 |
except (IOError, OSError): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
571 |
self.ui.warn(_(b'warning: unable to write to %s\n') % fn) |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
572 |
return |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
573 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
574 |
try: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
575 |
for i, (s1, s2) in enumerate(zip(l1, l2)): |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
576 |
if set(s1) != set(s2): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
577 |
f.write(b'sets at position %d are unequal\n' % i) |
48305
6fb282ce9113
fsmonitor: fix traceback about bytes and str incompatibility
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
578 |
f.write(b'watchman returned: %r\n' % s1) |
6fb282ce9113
fsmonitor: fix traceback about bytes and str incompatibility
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
579 |
f.write(b'stat returned: %r\n' % s2) |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
580 |
finally: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
581 |
f.close() |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
582 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
583 |
if isinstance(node1, context.changectx): |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
584 |
ctx1 = node1 |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
585 |
else: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
586 |
ctx1 = self[node1] |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
587 |
if isinstance(node2, context.changectx): |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
588 |
ctx2 = node2 |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
589 |
else: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
590 |
ctx2 = self[node2] |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
591 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
592 |
working = ctx2.rev() is None |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
593 |
parentworking = working and ctx1 == self[b'.'] |
41676
0531dff73d0b
match: delete unused root and cwd arguments from {always,never,exact}() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41609
diff
changeset
|
594 |
match = match or matchmod.always() |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
595 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
596 |
# Maybe we can use this opportunity to update Watchman's state. |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
597 |
# Mercurial uses workingcommitctx and/or memctx to represent the part of |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
598 |
# the workingctx that is to be committed. So don't update the state in |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
599 |
# that case. |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
600 |
# HG_PENDING is set in the environment when the dirstate is being updated |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
601 |
# in the middle of a transaction; we must not update our state in that |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
602 |
# case, or we risk forgetting about changes in the working copy. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
603 |
updatestate = ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
604 |
parentworking |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
605 |
and match.always() |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
606 |
and not isinstance(ctx2, (context.workingcommitctx, context.memctx)) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
607 |
and b'HG_PENDING' not in encoding.environ |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
608 |
) |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
609 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
610 |
try: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
611 |
if self._fsmonitorstate.walk_on_invalidate: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
612 |
# Use a short timeout to query the current clock. If that |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
613 |
# takes too long then we assume that the service will be slow |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
614 |
# to answer our query. |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
615 |
# walk_on_invalidate indicates that we prefer to walk the |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
616 |
# tree ourselves because we can ignore portions that Watchman |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
617 |
# cannot and we tend to be faster in the warmer buffer cache |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
618 |
# cases. |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
619 |
self._watchmanclient.settimeout(0.1) |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
620 |
else: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
621 |
# Give Watchman more time to potentially complete its walk |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
622 |
# and return the initial clock. In this mode we assume that |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
623 |
# the filesystem will be slower than parsing a potentially |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
624 |
# very large Watchman result set. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
625 |
self._watchmanclient.settimeout(self._fsmonitorstate.timeout + 0.1) |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
626 |
startclock = self._watchmanclient.getcurrentclock() |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
627 |
except Exception as ex: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
628 |
self._watchmanclient.clearconnection() |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
629 |
_handleunavailable(self.ui, self._fsmonitorstate, ex) |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
630 |
# boo, Watchman failed. bail |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
631 |
return orig( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
632 |
node1, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
633 |
node2, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
634 |
match, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
635 |
listignored, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
636 |
listclean, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
637 |
listunknown, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
638 |
listsubrepos, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
639 |
) |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
640 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
641 |
if updatestate: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
642 |
# We need info about unknown files. This may make things slower the |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
643 |
# first time, but whatever. |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
644 |
stateunknown = True |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
645 |
else: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
646 |
stateunknown = listunknown |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
647 |
|
32815
15e85dded933
fsmonitor: write state with wlock held and dirstate unchanged (issue5581)
Siddharth Agarwal <sid0@fb.com>
parents:
32722
diff
changeset
|
648 |
if updatestate: |
15e85dded933
fsmonitor: write state with wlock held and dirstate unchanged (issue5581)
Siddharth Agarwal <sid0@fb.com>
parents:
32722
diff
changeset
|
649 |
ps = poststatus(startclock) |
15e85dded933
fsmonitor: write state with wlock held and dirstate unchanged (issue5581)
Siddharth Agarwal <sid0@fb.com>
parents:
32722
diff
changeset
|
650 |
self.addpostdsstatus(ps) |
15e85dded933
fsmonitor: write state with wlock held and dirstate unchanged (issue5581)
Siddharth Agarwal <sid0@fb.com>
parents:
32722
diff
changeset
|
651 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
652 |
r = orig( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
653 |
node1, node2, match, listignored, listclean, stateunknown, listsubrepos |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
654 |
) |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
655 |
modified, added, removed, deleted, unknown, ignored, clean = r |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
656 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
657 |
if not listunknown: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
658 |
unknown = [] |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
659 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
660 |
# don't do paranoid checks if we're not going to query Watchman anyway |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
661 |
full = listclean or match.traversedir is not None |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
662 |
if self._fsmonitorstate.mode == b'paranoid' and not full: |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
663 |
# run status again and fall back to the old walk this time |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
664 |
self.dirstate._fsmonitordisable = True |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
665 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
666 |
# shut the UI up |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
667 |
quiet = self.ui.quiet |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
668 |
self.ui.quiet = True |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
669 |
fout, ferr = self.ui.fout, self.ui.ferr |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
670 |
self.ui.fout = self.ui.ferr = open(os.devnull, b'wb') |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
671 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
672 |
try: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
673 |
rv2 = orig( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
674 |
node1, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
675 |
node2, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
676 |
match, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
677 |
listignored, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
678 |
listclean, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
679 |
listunknown, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
680 |
listsubrepos, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
681 |
) |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
682 |
finally: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
683 |
self.dirstate._fsmonitordisable = False |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
684 |
self.ui.quiet = quiet |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
685 |
self.ui.fout, self.ui.ferr = fout, ferr |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
686 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
687 |
# clean isn't tested since it's set to True above |
40209
6b1a8c396b05
fsmonitor: use vfs instead of opener (issue5938)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
35313
diff
changeset
|
688 |
with self.wlock(): |
6b1a8c396b05
fsmonitor: use vfs instead of opener (issue5938)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
35313
diff
changeset
|
689 |
_cmpsets( |
6b1a8c396b05
fsmonitor: use vfs instead of opener (issue5938)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
35313
diff
changeset
|
690 |
[modified, added, removed, deleted, unknown, ignored, clean], |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
691 |
rv2, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
692 |
) |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
693 |
modified, added, removed, deleted, unknown, ignored, clean = rv2 |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
694 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
695 |
return scmutil.status( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
696 |
modified, added, removed, deleted, unknown, ignored, clean |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
697 |
) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
698 |
|
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
699 |
|
48946
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48913
diff
changeset
|
700 |
class poststatus: |
32815
15e85dded933
fsmonitor: write state with wlock held and dirstate unchanged (issue5581)
Siddharth Agarwal <sid0@fb.com>
parents:
32722
diff
changeset
|
701 |
def __init__(self, startclock): |
44829
017cc5ee537f
fsmonitor: coerce `clock` variable to byte-string (issue6321)
Connor Sheehan <sheehan@mozilla.com>
parents:
44452
diff
changeset
|
702 |
self._startclock = pycompat.sysbytes(startclock) |
32815
15e85dded933
fsmonitor: write state with wlock held and dirstate unchanged (issue5581)
Siddharth Agarwal <sid0@fb.com>
parents:
32722
diff
changeset
|
703 |
|
15e85dded933
fsmonitor: write state with wlock held and dirstate unchanged (issue5581)
Siddharth Agarwal <sid0@fb.com>
parents:
32722
diff
changeset
|
704 |
def __call__(self, wctx, status): |
15e85dded933
fsmonitor: write state with wlock held and dirstate unchanged (issue5581)
Siddharth Agarwal <sid0@fb.com>
parents:
32722
diff
changeset
|
705 |
clock = wctx.repo()._fsmonitorstate.getlastclock() or self._startclock |
15e85dded933
fsmonitor: write state with wlock held and dirstate unchanged (issue5581)
Siddharth Agarwal <sid0@fb.com>
parents:
32722
diff
changeset
|
706 |
hashignore = _hashignore(wctx.repo().dirstate._ignore) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
707 |
notefiles = ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
708 |
status.modified |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
709 |
+ status.added |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
710 |
+ status.removed |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
711 |
+ status.deleted |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
712 |
+ status.unknown |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
713 |
) |
32815
15e85dded933
fsmonitor: write state with wlock held and dirstate unchanged (issue5581)
Siddharth Agarwal <sid0@fb.com>
parents:
32722
diff
changeset
|
714 |
wctx.repo()._fsmonitorstate.set(clock, hashignore, notefiles) |
15e85dded933
fsmonitor: write state with wlock held and dirstate unchanged (issue5581)
Siddharth Agarwal <sid0@fb.com>
parents:
32722
diff
changeset
|
715 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
716 |
|
33386
5a9b4370bb3b
fsmonitor: centralize setup procedures for dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33385
diff
changeset
|
717 |
def makedirstate(repo, dirstate): |
5a9b4370bb3b
fsmonitor: centralize setup procedures for dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33385
diff
changeset
|
718 |
class fsmonitordirstate(dirstate.__class__): |
34565
4aa57627692a
fsmonitor: add new watchman notifications to fsmonitor extension
Eamonn Kent <ekent@fb.com>
parents:
34564
diff
changeset
|
719 |
def _fsmonitorinit(self, repo): |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
720 |
# _fsmonitordisable is used in paranoid mode |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
721 |
self._fsmonitordisable = False |
34565
4aa57627692a
fsmonitor: add new watchman notifications to fsmonitor extension
Eamonn Kent <ekent@fb.com>
parents:
34564
diff
changeset
|
722 |
self._fsmonitorstate = repo._fsmonitorstate |
4aa57627692a
fsmonitor: add new watchman notifications to fsmonitor extension
Eamonn Kent <ekent@fb.com>
parents:
34564
diff
changeset
|
723 |
self._watchmanclient = repo._watchmanclient |
4aa57627692a
fsmonitor: add new watchman notifications to fsmonitor extension
Eamonn Kent <ekent@fb.com>
parents:
34564
diff
changeset
|
724 |
self._repo = weakref.proxy(repo) |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
725 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
726 |
def walk(self, *args, **kwargs): |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
727 |
orig = super(fsmonitordirstate, self).walk |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
728 |
if self._fsmonitordisable: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
729 |
return orig(*args, **kwargs) |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
730 |
return overridewalk(orig, self, *args, **kwargs) |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
731 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
732 |
def rebuild(self, *args, **kwargs): |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
733 |
self._fsmonitorstate.invalidate() |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
734 |
return super(fsmonitordirstate, self).rebuild(*args, **kwargs) |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
735 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
736 |
def invalidate(self, *args, **kwargs): |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
737 |
self._fsmonitorstate.invalidate() |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
738 |
return super(fsmonitordirstate, self).invalidate(*args, **kwargs) |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
739 |
|
33386
5a9b4370bb3b
fsmonitor: centralize setup procedures for dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33385
diff
changeset
|
740 |
dirstate.__class__ = fsmonitordirstate |
34565
4aa57627692a
fsmonitor: add new watchman notifications to fsmonitor extension
Eamonn Kent <ekent@fb.com>
parents:
34564
diff
changeset
|
741 |
dirstate._fsmonitorinit(repo) |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
742 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
743 |
|
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
744 |
def wrapdirstate(orig, self): |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
745 |
ds = orig(self) |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
746 |
# only override the dirstate when Watchman is available for the repo |
51129
1625fe807c04
py3: pass unicode strings to hasattr() throughout
Martin von Zweigbergk <martinvonz@google.com>
parents:
50928
diff
changeset
|
747 |
if hasattr(self, '_fsmonitorstate'): |
33386
5a9b4370bb3b
fsmonitor: centralize setup procedures for dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33385
diff
changeset
|
748 |
makedirstate(self, ds) |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
749 |
return ds |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
750 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
751 |
|
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
752 |
def extsetup(ui): |
32722
de09138bf0f5
extensions: move wrapfilecache function from fsmonitor
Augie Fackler <augie@google.com>
parents:
32406
diff
changeset
|
753 |
extensions.wrapfilecache( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
754 |
localrepo.localrepository, b'dirstate', wrapdirstate |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
755 |
) |
34647 | 756 |
if pycompat.isdarwin: |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
757 |
# An assist for avoiding the dangling-symlink fsevents bug |
50778
ba3add904ab4
wrapfunction: use sysstr instead of bytes as argument in "fsmonitor"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49468
diff
changeset
|
758 |
extensions.wrapfunction(os, 'symlink', wrapsymlink) |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
759 |
|
50778
ba3add904ab4
wrapfunction: use sysstr instead of bytes as argument in "fsmonitor"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49468
diff
changeset
|
760 |
extensions.wrapfunction(merge, '_update', wrapupdate) |
28443
49d65663d7e4
fsmonitor: hook up state-enter, state-leave signals
Martijn Pieters <mjpieters@fb.com>
parents:
28433
diff
changeset
|
761 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
762 |
|
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
763 |
def wrapsymlink(orig, source, link_name): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45557
diff
changeset
|
764 |
"""if we create a dangling symlink, also touch the parent dir |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45557
diff
changeset
|
765 |
to encourage fsevents notifications to work more correctly""" |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
766 |
try: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
767 |
return orig(source, link_name) |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
768 |
finally: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
769 |
try: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
770 |
os.utime(os.path.dirname(link_name), None) |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
771 |
except OSError: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
772 |
pass |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
773 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
774 |
|
48946
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48913
diff
changeset
|
775 |
class state_update: |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45557
diff
changeset
|
776 |
"""This context manager is responsible for dispatching the state-enter |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45557
diff
changeset
|
777 |
and state-leave signals to the watchman service. The enter and leave |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45557
diff
changeset
|
778 |
methods can be invoked manually (for scenarios where context manager |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45557
diff
changeset
|
779 |
semantics are not possible). If parameters oldnode and newnode are None, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45557
diff
changeset
|
780 |
they will be populated based on current working copy in enter and |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45557
diff
changeset
|
781 |
leave, respectively. Similarly, if the distance is none, it will be |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45557
diff
changeset
|
782 |
calculated based on the oldnode and newnode in the leave method.""" |
28443
49d65663d7e4
fsmonitor: hook up state-enter, state-leave signals
Martijn Pieters <mjpieters@fb.com>
parents:
28433
diff
changeset
|
783 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
784 |
def __init__( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
785 |
self, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
786 |
repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
787 |
name, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
788 |
oldnode=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
789 |
newnode=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
790 |
distance=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
791 |
partial=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
792 |
): |
34565
4aa57627692a
fsmonitor: add new watchman notifications to fsmonitor extension
Eamonn Kent <ekent@fb.com>
parents:
34564
diff
changeset
|
793 |
self.repo = repo.unfiltered() |
4aa57627692a
fsmonitor: add new watchman notifications to fsmonitor extension
Eamonn Kent <ekent@fb.com>
parents:
34564
diff
changeset
|
794 |
self.name = name |
4aa57627692a
fsmonitor: add new watchman notifications to fsmonitor extension
Eamonn Kent <ekent@fb.com>
parents:
34564
diff
changeset
|
795 |
self.oldnode = oldnode |
4aa57627692a
fsmonitor: add new watchman notifications to fsmonitor extension
Eamonn Kent <ekent@fb.com>
parents:
34564
diff
changeset
|
796 |
self.newnode = newnode |
28443
49d65663d7e4
fsmonitor: hook up state-enter, state-leave signals
Martijn Pieters <mjpieters@fb.com>
parents:
28433
diff
changeset
|
797 |
self.distance = distance |
49d65663d7e4
fsmonitor: hook up state-enter, state-leave signals
Martijn Pieters <mjpieters@fb.com>
parents:
28433
diff
changeset
|
798 |
self.partial = partial |
32334
6e0d1043e8fc
fsmonitor: acquire localrepo.wlock prior to emitting hg.update state
Wez Furlong <wez@fb.com>
parents:
32321
diff
changeset
|
799 |
self._lock = None |
32335
354329178dee
fsmonitor: don't attempt state-leave if we didn't state-enter
Wez Furlong <wez@fb.com>
parents:
32334
diff
changeset
|
800 |
self.need_leave = False |
28443
49d65663d7e4
fsmonitor: hook up state-enter, state-leave signals
Martijn Pieters <mjpieters@fb.com>
parents:
28433
diff
changeset
|
801 |
|
49d65663d7e4
fsmonitor: hook up state-enter, state-leave signals
Martijn Pieters <mjpieters@fb.com>
parents:
28433
diff
changeset
|
802 |
def __enter__(self): |
34565
4aa57627692a
fsmonitor: add new watchman notifications to fsmonitor extension
Eamonn Kent <ekent@fb.com>
parents:
34564
diff
changeset
|
803 |
self.enter() |
4aa57627692a
fsmonitor: add new watchman notifications to fsmonitor extension
Eamonn Kent <ekent@fb.com>
parents:
34564
diff
changeset
|
804 |
|
4aa57627692a
fsmonitor: add new watchman notifications to fsmonitor extension
Eamonn Kent <ekent@fb.com>
parents:
34564
diff
changeset
|
805 |
def enter(self): |
35313
c67fb3bfe3a1
fsmonitor: fsmonitor should send wlock notifications to watchman
Eamonn Kent <ekent@fb.com>
parents:
35312
diff
changeset
|
806 |
# Make sure we have a wlock prior to sending notifications to watchman. |
c67fb3bfe3a1
fsmonitor: fsmonitor should send wlock notifications to watchman
Eamonn Kent <ekent@fb.com>
parents:
35312
diff
changeset
|
807 |
# We don't want to race with other actors. In the update case, |
c67fb3bfe3a1
fsmonitor: fsmonitor should send wlock notifications to watchman
Eamonn Kent <ekent@fb.com>
parents:
35312
diff
changeset
|
808 |
# merge.update is going to take the wlock almost immediately. We are |
c67fb3bfe3a1
fsmonitor: fsmonitor should send wlock notifications to watchman
Eamonn Kent <ekent@fb.com>
parents:
35312
diff
changeset
|
809 |
# effectively extending the lock around several short sanity checks. |
34565
4aa57627692a
fsmonitor: add new watchman notifications to fsmonitor extension
Eamonn Kent <ekent@fb.com>
parents:
34564
diff
changeset
|
810 |
if self.oldnode is None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
811 |
self.oldnode = self.repo[b'.'].node() |
35313
c67fb3bfe3a1
fsmonitor: fsmonitor should send wlock notifications to watchman
Eamonn Kent <ekent@fb.com>
parents:
35312
diff
changeset
|
812 |
|
c67fb3bfe3a1
fsmonitor: fsmonitor should send wlock notifications to watchman
Eamonn Kent <ekent@fb.com>
parents:
35312
diff
changeset
|
813 |
if self.repo.currentwlock() is None: |
51129
1625fe807c04
py3: pass unicode strings to hasattr() throughout
Martin von Zweigbergk <martinvonz@google.com>
parents:
50928
diff
changeset
|
814 |
if hasattr(self.repo, 'wlocknostateupdate'): |
35313
c67fb3bfe3a1
fsmonitor: fsmonitor should send wlock notifications to watchman
Eamonn Kent <ekent@fb.com>
parents:
35312
diff
changeset
|
815 |
self._lock = self.repo.wlocknostateupdate() |
c67fb3bfe3a1
fsmonitor: fsmonitor should send wlock notifications to watchman
Eamonn Kent <ekent@fb.com>
parents:
35312
diff
changeset
|
816 |
else: |
c67fb3bfe3a1
fsmonitor: fsmonitor should send wlock notifications to watchman
Eamonn Kent <ekent@fb.com>
parents:
35312
diff
changeset
|
817 |
self._lock = self.repo.wlock() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
818 |
self.need_leave = self._state(b'state-enter', hex(self.oldnode)) |
28443
49d65663d7e4
fsmonitor: hook up state-enter, state-leave signals
Martijn Pieters <mjpieters@fb.com>
parents:
28433
diff
changeset
|
819 |
return self |
49d65663d7e4
fsmonitor: hook up state-enter, state-leave signals
Martijn Pieters <mjpieters@fb.com>
parents:
28433
diff
changeset
|
820 |
|
49d65663d7e4
fsmonitor: hook up state-enter, state-leave signals
Martijn Pieters <mjpieters@fb.com>
parents:
28433
diff
changeset
|
821 |
def __exit__(self, type_, value, tb): |
34565
4aa57627692a
fsmonitor: add new watchman notifications to fsmonitor extension
Eamonn Kent <ekent@fb.com>
parents:
34564
diff
changeset
|
822 |
abort = True if type_ else False |
4aa57627692a
fsmonitor: add new watchman notifications to fsmonitor extension
Eamonn Kent <ekent@fb.com>
parents:
34564
diff
changeset
|
823 |
self.exit(abort=abort) |
4aa57627692a
fsmonitor: add new watchman notifications to fsmonitor extension
Eamonn Kent <ekent@fb.com>
parents:
34564
diff
changeset
|
824 |
|
4aa57627692a
fsmonitor: add new watchman notifications to fsmonitor extension
Eamonn Kent <ekent@fb.com>
parents:
34564
diff
changeset
|
825 |
def exit(self, abort=False): |
32334
6e0d1043e8fc
fsmonitor: acquire localrepo.wlock prior to emitting hg.update state
Wez Furlong <wez@fb.com>
parents:
32321
diff
changeset
|
826 |
try: |
32335
354329178dee
fsmonitor: don't attempt state-leave if we didn't state-enter
Wez Furlong <wez@fb.com>
parents:
32334
diff
changeset
|
827 |
if self.need_leave: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
828 |
status = b'failed' if abort else b'ok' |
34565
4aa57627692a
fsmonitor: add new watchman notifications to fsmonitor extension
Eamonn Kent <ekent@fb.com>
parents:
34564
diff
changeset
|
829 |
if self.newnode is None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
830 |
self.newnode = self.repo[b'.'].node() |
34565
4aa57627692a
fsmonitor: add new watchman notifications to fsmonitor extension
Eamonn Kent <ekent@fb.com>
parents:
34564
diff
changeset
|
831 |
if self.distance is None: |
4aa57627692a
fsmonitor: add new watchman notifications to fsmonitor extension
Eamonn Kent <ekent@fb.com>
parents:
34564
diff
changeset
|
832 |
self.distance = calcdistance( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
833 |
self.repo, self.oldnode, self.newnode |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
834 |
) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
835 |
self._state(b'state-leave', hex(self.newnode), status=status) |
32334
6e0d1043e8fc
fsmonitor: acquire localrepo.wlock prior to emitting hg.update state
Wez Furlong <wez@fb.com>
parents:
32321
diff
changeset
|
836 |
finally: |
34565
4aa57627692a
fsmonitor: add new watchman notifications to fsmonitor extension
Eamonn Kent <ekent@fb.com>
parents:
34564
diff
changeset
|
837 |
self.need_leave = False |
32334
6e0d1043e8fc
fsmonitor: acquire localrepo.wlock prior to emitting hg.update state
Wez Furlong <wez@fb.com>
parents:
32321
diff
changeset
|
838 |
if self._lock: |
6e0d1043e8fc
fsmonitor: acquire localrepo.wlock prior to emitting hg.update state
Wez Furlong <wez@fb.com>
parents:
32321
diff
changeset
|
839 |
self._lock.release() |
28443
49d65663d7e4
fsmonitor: hook up state-enter, state-leave signals
Martijn Pieters <mjpieters@fb.com>
parents:
28433
diff
changeset
|
840 |
|
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
841 |
def _state(self, cmd, commithash, status=b'ok'): |
51129
1625fe807c04
py3: pass unicode strings to hasattr() throughout
Martin von Zweigbergk <martinvonz@google.com>
parents:
50928
diff
changeset
|
842 |
if not hasattr(self.repo, '_watchmanclient'): |
32335
354329178dee
fsmonitor: don't attempt state-leave if we didn't state-enter
Wez Furlong <wez@fb.com>
parents:
32334
diff
changeset
|
843 |
return False |
28443
49d65663d7e4
fsmonitor: hook up state-enter, state-leave signals
Martijn Pieters <mjpieters@fb.com>
parents:
28433
diff
changeset
|
844 |
try: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
845 |
self.repo._watchmanclient.command( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
846 |
cmd, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
847 |
{ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
848 |
b'name': self.name, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
849 |
b'metadata': { |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
850 |
# the target revision |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
851 |
b'rev': commithash, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
852 |
# approximate number of commits between current and target |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
853 |
b'distance': self.distance if self.distance else 0, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
854 |
# success/failure (only really meaningful for state-leave) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
855 |
b'status': status, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
856 |
# whether the working copy parent is changing |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
857 |
b'partial': self.partial, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
858 |
}, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
859 |
}, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
860 |
) |
32335
354329178dee
fsmonitor: don't attempt state-leave if we didn't state-enter
Wez Furlong <wez@fb.com>
parents:
32334
diff
changeset
|
861 |
return True |
28443
49d65663d7e4
fsmonitor: hook up state-enter, state-leave signals
Martijn Pieters <mjpieters@fb.com>
parents:
28433
diff
changeset
|
862 |
except Exception as e: |
49d65663d7e4
fsmonitor: hook up state-enter, state-leave signals
Martijn Pieters <mjpieters@fb.com>
parents:
28433
diff
changeset
|
863 |
# Swallow any errors; fire and forget |
49d65663d7e4
fsmonitor: hook up state-enter, state-leave signals
Martijn Pieters <mjpieters@fb.com>
parents:
28433
diff
changeset
|
864 |
self.repo.ui.log( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
865 |
b'watchman', b'Exception %s while running %s\n', e, cmd |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
866 |
) |
32335
354329178dee
fsmonitor: don't attempt state-leave if we didn't state-enter
Wez Furlong <wez@fb.com>
parents:
32334
diff
changeset
|
867 |
return False |
28443
49d65663d7e4
fsmonitor: hook up state-enter, state-leave signals
Martijn Pieters <mjpieters@fb.com>
parents:
28433
diff
changeset
|
868 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
869 |
|
34564
b79f59425964
fsmonitor: change the distance calculation
Eamonn Kent <ekent@fb.com>
parents:
34463
diff
changeset
|
870 |
# Estimate the distance between two nodes |
b79f59425964
fsmonitor: change the distance calculation
Eamonn Kent <ekent@fb.com>
parents:
34463
diff
changeset
|
871 |
def calcdistance(repo, oldnode, newnode): |
b79f59425964
fsmonitor: change the distance calculation
Eamonn Kent <ekent@fb.com>
parents:
34463
diff
changeset
|
872 |
anc = repo.changelog.ancestor(oldnode, newnode) |
b79f59425964
fsmonitor: change the distance calculation
Eamonn Kent <ekent@fb.com>
parents:
34463
diff
changeset
|
873 |
ancrev = repo[anc].rev() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
874 |
distance = abs(repo[oldnode].rev() - ancrev) + abs( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
875 |
repo[newnode].rev() - ancrev |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
876 |
) |
34564
b79f59425964
fsmonitor: change the distance calculation
Eamonn Kent <ekent@fb.com>
parents:
34463
diff
changeset
|
877 |
return distance |
b79f59425964
fsmonitor: change the distance calculation
Eamonn Kent <ekent@fb.com>
parents:
34463
diff
changeset
|
878 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
879 |
|
28443
49d65663d7e4
fsmonitor: hook up state-enter, state-leave signals
Martijn Pieters <mjpieters@fb.com>
parents:
28433
diff
changeset
|
880 |
# Bracket working copy updates with calls to the watchman state-enter |
49d65663d7e4
fsmonitor: hook up state-enter, state-leave signals
Martijn Pieters <mjpieters@fb.com>
parents:
28433
diff
changeset
|
881 |
# and state-leave commands. This allows clients to perform more intelligent |
49d65663d7e4
fsmonitor: hook up state-enter, state-leave signals
Martijn Pieters <mjpieters@fb.com>
parents:
28433
diff
changeset
|
882 |
# settling during bulk file change scenarios |
49d65663d7e4
fsmonitor: hook up state-enter, state-leave signals
Martijn Pieters <mjpieters@fb.com>
parents:
28433
diff
changeset
|
883 |
# https://facebook.github.io/watchman/docs/cmd/subscribe.html#advanced-settling |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
884 |
def wrapupdate( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
885 |
orig, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
886 |
repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
887 |
node, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
888 |
branchmerge, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
889 |
force, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
890 |
ancestor=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
891 |
mergeancestor=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
892 |
labels=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
893 |
matcher=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
894 |
**kwargs |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
895 |
): |
28443
49d65663d7e4
fsmonitor: hook up state-enter, state-leave signals
Martijn Pieters <mjpieters@fb.com>
parents:
28433
diff
changeset
|
896 |
distance = 0 |
49d65663d7e4
fsmonitor: hook up state-enter, state-leave signals
Martijn Pieters <mjpieters@fb.com>
parents:
28433
diff
changeset
|
897 |
partial = True |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
898 |
oldnode = repo[b'.'].node() |
34565
4aa57627692a
fsmonitor: add new watchman notifications to fsmonitor extension
Eamonn Kent <ekent@fb.com>
parents:
34564
diff
changeset
|
899 |
newnode = repo[node].node() |
28443
49d65663d7e4
fsmonitor: hook up state-enter, state-leave signals
Martijn Pieters <mjpieters@fb.com>
parents:
28433
diff
changeset
|
900 |
if matcher is None or matcher.always(): |
49d65663d7e4
fsmonitor: hook up state-enter, state-leave signals
Martijn Pieters <mjpieters@fb.com>
parents:
28433
diff
changeset
|
901 |
partial = False |
34565
4aa57627692a
fsmonitor: add new watchman notifications to fsmonitor extension
Eamonn Kent <ekent@fb.com>
parents:
34564
diff
changeset
|
902 |
distance = calcdistance(repo.unfiltered(), oldnode, newnode) |
28443
49d65663d7e4
fsmonitor: hook up state-enter, state-leave signals
Martijn Pieters <mjpieters@fb.com>
parents:
28433
diff
changeset
|
903 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
904 |
with state_update( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
905 |
repo, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
906 |
name=b"hg.update", |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
907 |
oldnode=oldnode, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
908 |
newnode=newnode, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
909 |
distance=distance, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
910 |
partial=partial, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
911 |
): |
28443
49d65663d7e4
fsmonitor: hook up state-enter, state-leave signals
Martijn Pieters <mjpieters@fb.com>
parents:
28433
diff
changeset
|
912 |
return orig( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
913 |
repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
914 |
node, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
915 |
branchmerge, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
916 |
force, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
917 |
ancestor, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
918 |
mergeancestor, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
919 |
labels, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
920 |
matcher, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
921 |
**kwargs |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
922 |
) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
923 |
|
28443
49d65663d7e4
fsmonitor: hook up state-enter, state-leave signals
Martijn Pieters <mjpieters@fb.com>
parents:
28433
diff
changeset
|
924 |
|
41489
5125f0a9728b
watchman: detect nested mercurial repositories and abort
Boris Feld <boris.feld@octobus.net>
parents:
41488
diff
changeset
|
925 |
def repo_has_depth_one_nested_repo(repo): |
5125f0a9728b
watchman: detect nested mercurial repositories and abort
Boris Feld <boris.feld@octobus.net>
parents:
41488
diff
changeset
|
926 |
for f in repo.wvfs.listdir(): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
927 |
if os.path.isdir(os.path.join(repo.root, f, b'.hg')): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
928 |
msg = b'fsmonitor: sub-repository %r detected, fsmonitor disabled\n' |
41489
5125f0a9728b
watchman: detect nested mercurial repositories and abort
Boris Feld <boris.feld@octobus.net>
parents:
41488
diff
changeset
|
929 |
repo.ui.debug(msg % f) |
5125f0a9728b
watchman: detect nested mercurial repositories and abort
Boris Feld <boris.feld@octobus.net>
parents:
41488
diff
changeset
|
930 |
return True |
5125f0a9728b
watchman: detect nested mercurial repositories and abort
Boris Feld <boris.feld@octobus.net>
parents:
41488
diff
changeset
|
931 |
return False |
5125f0a9728b
watchman: detect nested mercurial repositories and abort
Boris Feld <boris.feld@octobus.net>
parents:
41488
diff
changeset
|
932 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
933 |
|
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
934 |
def reposetup(ui, repo): |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
935 |
# We don't work with largefiles or inotify |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
936 |
exts = extensions.enabled() |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
937 |
for ext in _blacklist: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
938 |
if ext in exts: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
939 |
ui.warn( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
940 |
_( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
941 |
b'The fsmonitor extension is incompatible with the %s ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
942 |
b'extension and has been disabled.\n' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
943 |
) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
944 |
% ext |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
945 |
) |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
946 |
return |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
947 |
|
33385
8bb4c69c4000
fsmonitor: avoid needless instantiation of dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
32815
diff
changeset
|
948 |
if repo.local(): |
8bb4c69c4000
fsmonitor: avoid needless instantiation of dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
32815
diff
changeset
|
949 |
# We don't work with subrepos either. |
8bb4c69c4000
fsmonitor: avoid needless instantiation of dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
32815
diff
changeset
|
950 |
# |
8bb4c69c4000
fsmonitor: avoid needless instantiation of dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
32815
diff
changeset
|
951 |
# if repo[None].substate can cause a dirstate parse, which is too |
8bb4c69c4000
fsmonitor: avoid needless instantiation of dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
32815
diff
changeset
|
952 |
# slow. Instead, look for a file called hgsubstate, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
953 |
if repo.wvfs.exists(b'.hgsubstate') or repo.wvfs.exists(b'.hgsub'): |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
954 |
return |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
955 |
|
41489
5125f0a9728b
watchman: detect nested mercurial repositories and abort
Boris Feld <boris.feld@octobus.net>
parents:
41488
diff
changeset
|
956 |
if repo_has_depth_one_nested_repo(repo): |
5125f0a9728b
watchman: detect nested mercurial repositories and abort
Boris Feld <boris.feld@octobus.net>
parents:
41488
diff
changeset
|
957 |
return |
5125f0a9728b
watchman: detect nested mercurial repositories and abort
Boris Feld <boris.feld@octobus.net>
parents:
41488
diff
changeset
|
958 |
|
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
959 |
fsmonitorstate = state.state(repo) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
960 |
if fsmonitorstate.mode == b'off': |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
961 |
return |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
962 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
963 |
try: |
43391
ffdf0bf28212
fsmonitor: access repo.root
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43390
diff
changeset
|
964 |
client = watchmanclient.client(repo.ui, repo.root) |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
965 |
except Exception as ex: |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
966 |
_handleunavailable(ui, fsmonitorstate, ex) |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
967 |
return |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
968 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
969 |
repo._fsmonitorstate = fsmonitorstate |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
970 |
repo._watchmanclient = client |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
971 |
|
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
972 |
dirstate, cached = localrepo.isfilecached(repo, b'dirstate') |
33387
68e9762a357b
fsmonitor: execute setup procedures only if dirstate is already instantiated
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33386
diff
changeset
|
973 |
if cached: |
68e9762a357b
fsmonitor: execute setup procedures only if dirstate is already instantiated
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33386
diff
changeset
|
974 |
# at this point since fsmonitorstate wasn't present, |
68e9762a357b
fsmonitor: execute setup procedures only if dirstate is already instantiated
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33386
diff
changeset
|
975 |
# repo.dirstate is not a fsmonitordirstate |
68e9762a357b
fsmonitor: execute setup procedures only if dirstate is already instantiated
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
33386
diff
changeset
|
976 |
makedirstate(repo, dirstate) |
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
977 |
|
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
978 |
class fsmonitorrepo(repo.__class__): |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
979 |
def status(self, *args, **kwargs): |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
980 |
orig = super(fsmonitorrepo, self).status |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
981 |
return overridestatus(orig, self, *args, **kwargs) |
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
982 |
|
35313
c67fb3bfe3a1
fsmonitor: fsmonitor should send wlock notifications to watchman
Eamonn Kent <ekent@fb.com>
parents:
35312
diff
changeset
|
983 |
def wlocknostateupdate(self, *args, **kwargs): |
c67fb3bfe3a1
fsmonitor: fsmonitor should send wlock notifications to watchman
Eamonn Kent <ekent@fb.com>
parents:
35312
diff
changeset
|
984 |
return super(fsmonitorrepo, self).wlock(*args, **kwargs) |
c67fb3bfe3a1
fsmonitor: fsmonitor should send wlock notifications to watchman
Eamonn Kent <ekent@fb.com>
parents:
35312
diff
changeset
|
985 |
|
c67fb3bfe3a1
fsmonitor: fsmonitor should send wlock notifications to watchman
Eamonn Kent <ekent@fb.com>
parents:
35312
diff
changeset
|
986 |
def wlock(self, *args, **kwargs): |
c67fb3bfe3a1
fsmonitor: fsmonitor should send wlock notifications to watchman
Eamonn Kent <ekent@fb.com>
parents:
35312
diff
changeset
|
987 |
l = super(fsmonitorrepo, self).wlock(*args, **kwargs) |
c67fb3bfe3a1
fsmonitor: fsmonitor should send wlock notifications to watchman
Eamonn Kent <ekent@fb.com>
parents:
35312
diff
changeset
|
988 |
if not ui.configbool( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
989 |
b"experimental", b"fsmonitor.transaction_notify" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42760
diff
changeset
|
990 |
): |
35313
c67fb3bfe3a1
fsmonitor: fsmonitor should send wlock notifications to watchman
Eamonn Kent <ekent@fb.com>
parents:
35312
diff
changeset
|
991 |
return l |
c67fb3bfe3a1
fsmonitor: fsmonitor should send wlock notifications to watchman
Eamonn Kent <ekent@fb.com>
parents:
35312
diff
changeset
|
992 |
if l.held != 1: |
c67fb3bfe3a1
fsmonitor: fsmonitor should send wlock notifications to watchman
Eamonn Kent <ekent@fb.com>
parents:
35312
diff
changeset
|
993 |
return l |
c67fb3bfe3a1
fsmonitor: fsmonitor should send wlock notifications to watchman
Eamonn Kent <ekent@fb.com>
parents:
35312
diff
changeset
|
994 |
origrelease = l.releasefn |
c67fb3bfe3a1
fsmonitor: fsmonitor should send wlock notifications to watchman
Eamonn Kent <ekent@fb.com>
parents:
35312
diff
changeset
|
995 |
|
c67fb3bfe3a1
fsmonitor: fsmonitor should send wlock notifications to watchman
Eamonn Kent <ekent@fb.com>
parents:
35312
diff
changeset
|
996 |
def staterelease(): |
c67fb3bfe3a1
fsmonitor: fsmonitor should send wlock notifications to watchman
Eamonn Kent <ekent@fb.com>
parents:
35312
diff
changeset
|
997 |
if origrelease: |
c67fb3bfe3a1
fsmonitor: fsmonitor should send wlock notifications to watchman
Eamonn Kent <ekent@fb.com>
parents:
35312
diff
changeset
|
998 |
origrelease() |
c67fb3bfe3a1
fsmonitor: fsmonitor should send wlock notifications to watchman
Eamonn Kent <ekent@fb.com>
parents:
35312
diff
changeset
|
999 |
if l.stateupdate: |
c67fb3bfe3a1
fsmonitor: fsmonitor should send wlock notifications to watchman
Eamonn Kent <ekent@fb.com>
parents:
35312
diff
changeset
|
1000 |
l.stateupdate.exit() |
c67fb3bfe3a1
fsmonitor: fsmonitor should send wlock notifications to watchman
Eamonn Kent <ekent@fb.com>
parents:
35312
diff
changeset
|
1001 |
l.stateupdate = None |
c67fb3bfe3a1
fsmonitor: fsmonitor should send wlock notifications to watchman
Eamonn Kent <ekent@fb.com>
parents:
35312
diff
changeset
|
1002 |
|
c67fb3bfe3a1
fsmonitor: fsmonitor should send wlock notifications to watchman
Eamonn Kent <ekent@fb.com>
parents:
35312
diff
changeset
|
1003 |
try: |
c67fb3bfe3a1
fsmonitor: fsmonitor should send wlock notifications to watchman
Eamonn Kent <ekent@fb.com>
parents:
35312
diff
changeset
|
1004 |
l.stateupdate = None |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1005 |
l.stateupdate = state_update(self, name=b"hg.transaction") |
35313
c67fb3bfe3a1
fsmonitor: fsmonitor should send wlock notifications to watchman
Eamonn Kent <ekent@fb.com>
parents:
35312
diff
changeset
|
1006 |
l.stateupdate.enter() |
c67fb3bfe3a1
fsmonitor: fsmonitor should send wlock notifications to watchman
Eamonn Kent <ekent@fb.com>
parents:
35312
diff
changeset
|
1007 |
l.releasefn = staterelease |
c67fb3bfe3a1
fsmonitor: fsmonitor should send wlock notifications to watchman
Eamonn Kent <ekent@fb.com>
parents:
35312
diff
changeset
|
1008 |
except Exception as e: |
c67fb3bfe3a1
fsmonitor: fsmonitor should send wlock notifications to watchman
Eamonn Kent <ekent@fb.com>
parents:
35312
diff
changeset
|
1009 |
# Swallow any errors; fire and forget |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1010 |
self.ui.log( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1011 |
b'watchman', b'Exception in state update %s\n', e |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1012 |
) |
35313
c67fb3bfe3a1
fsmonitor: fsmonitor should send wlock notifications to watchman
Eamonn Kent <ekent@fb.com>
parents:
35312
diff
changeset
|
1013 |
return l |
c67fb3bfe3a1
fsmonitor: fsmonitor should send wlock notifications to watchman
Eamonn Kent <ekent@fb.com>
parents:
35312
diff
changeset
|
1014 |
|
28433
3b67f27bb908
fsmonitor: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1015 |
repo.__class__ = fsmonitorrepo |