configwizard: prompt to install fsmonitor extension (
bug 1277406); r?glob
Rather than port support for hgwatchman, let's drop support for it
and encourage people to upgrade to Mercurial 3.8.
MozReview-Commit-ID: Ft0iBO5VOqk
--- a/hgext/configwizard/__init__.py
+++ b/hgext/configwizard/__init__.py
@@ -64,28 +64,52 @@ acceptable.
'''.lstrip()
BAD_DIFF_SETTINGS = '''
Mercurial is not configured to produce diffs in a more readable format.
Would you like to change this (Yn)? $$ &Yes $$ &No
'''.strip()
+FSMONITOR_INFO = '''
+The fsmonitor extension integrates the watchman filesystem watching tool
+with Mercurial. Commands like `hg status`, `hg diff`, and `hg commit`
+(which need to examine filesystem state) can query watchman to obtain
+this state, allowing these commands to complete much quicker.
+
+When installed, the fsmonitor extension will automatically launch a
+background watchman daemon for accessed Mercurial repositories. It
+should "just work."
+
+Would you like to enable fsmonitor (Yn)? $$ &Yes $$ &No
+'''.strip()
+
+FSMONITOR_NOT_AVAILABLE = '''
+Newer versions of Mercurial have built-in support for integrating with
+filesystem watching services to make common operations faster.
+
+This integration is STRONGLY RECOMMENDED when using the Firefox
+repository.
+
+Please upgrade to Mercurial 3.8+ so this feature is available.
+'''.lstrip()
+
testedwith = '3.5 3.6 3.7 3.8'
buglink = 'https://bugzilla.mozilla.org/enter_bug.cgi?product=Developer%20Services&component=General'
cmdtable = {}
command = cmdutil.command(cmdtable)
wizardsteps = {
'hgversion',
'username',
'diff',
'color',
'historyediting',
+ 'fsmonitor',
'configchange',
}
@command('configwizard', [
('s', 'statedir', '', _('directory to store state')),
], _('hg configwizard'), optionalrepo=True)
def configwizard(ui, repo, statedir=None, **opts):
"""Ensure your Mercurial configuration is up to date."""
@@ -116,16 +140,19 @@ def configwizard(ui, repo, statedir=None
_checkdiffsettings(ui, cw)
if 'color' in runsteps:
_promptnativeextension(ui, cw, 'color', 'Enable color output to your terminal')
if 'historyediting' in runsteps:
_checkhistoryediting(ui, cw)
+ if 'fsmonitor' in runsteps:
+ _checkfsmonitor(ui, cw, hgversion)
+
if 'configchange' in runsteps:
return _handleconfigchange(ui, cw)
return 0
def _checkhgversion(ui, hgversion):
if hgversion >= OLDEST_NON_LEGACY_VERSION:
@@ -200,17 +227,17 @@ def _checkdiffsettings(ui, cw):
cw.c['diff']['git'] = 'true'
cw.c['diff']['showfunc'] = 'true'
def _promptnativeextension(ui, cw, ext, msg):
if ui.hasconfig('extensions', ext):
return
- if not ui.promptchoice('%s (Yn) $$ &Yes $$ &No' % msg):
+ if not uipromptchoice(ui, '%s (Yn) $$ &Yes $$ &No' % msg):
if 'extensions' not in cw.c:
cw.c['extensions'] = {}
cw.c['extensions'][ext] = ''
def _checkhistoryediting(ui, cw):
if all(ui.hasconfig('extensions', e) for e in ('histedit', 'rebase')):
@@ -221,16 +248,38 @@ def _checkhistoryediting(ui, cw):
if 'extensions' not in cw.c:
cw.c['extensions'] = {}
cw.c['extensions']['histedit'] = ''
cw.c['extensions']['rebase'] = ''
+def _checkfsmonitor(ui, cw, hgversion):
+ # fsmonitor came into existence in Mercurial 3.8. Before that, it
+ # was the "hgwatchman" extension from a 3rd party repository.
+ # Instead of dealing with installing hgwatchman, we version sniff
+ # and print a message about wanting a more modern Mercurial version.
+
+ if ui.hasconfig('extensions', 'fsmonitor'):
+ try:
+ del cw.c['extensions']['hgwatchman']
+ ui.write('Removing extensions.hgwatchman because fsmonitor is installed\n')
+ except KeyError:
+ pass
+
+ return
+
+ # Mercurial 3.8+ has fsmonitor built-in.
+ if hgversion >= (3, 8, 0):
+ _promptnativeextension(ui, cw, 'fsmonitor', FSMONITOR_INFO)
+ else:
+ ui.write(FSMONITOR_NOT_AVAILABLE)
+
+
def _handleconfigchange(ui, cw):
# Obtain the old and new content so we can show a diff.
newbuf = io.BytesIO()
cw.write(newbuf)
newbuf.seek(0)
newlines = [l.rstrip() for l in newbuf.readlines()]
oldlines = []
if os.path.exists(cw.path):
--- a/hgext/configwizard/hgsetup/wizard.py
+++ b/hgext/configwizard/hgsetup/wizard.py
@@ -156,32 +156,16 @@ Example Usage:
(Not shown are the colors that help denote the state each changeset
is in.)
(Relevant config options: alias.wip, revsetalias.wip, templates.wip)
Would you like to install the `hg wip` alias?
'''.strip()
-HGWATCHMAN_MINIMUM_VERSION = LooseVersion('3.5.2')
-
-HGWATCHMAN_INFO = '''
-The hgwatchman extension integrates the watchman filesystem watching
-tool with Mercurial. Commands like `hg status`, `hg diff`, and
-`hg commit` that need to examine filesystem state can query watchman
-and obtain filesystem state nearly instantaneously. The result is much
-faster command execution.
-
-When installed, the hgwatchman extension will launch a background
-watchman file watching daemon for accessed Mercurial repositories. It
-should "just work."
-
-Would you like to install hgwatchman
-'''.strip()
-
FILE_PERMISSIONS_WARNING = '''
Your hgrc file is currently readable by others.
Sensitive information such as your Bugzilla credentials could be
stolen if others have access to this file/machine.
'''.strip()
MULTIPLE_VCT = '''
@@ -218,38 +202,16 @@ class MercurialSetupWizard(object):
hg = get_hg_path()
config_path = config_file(config_paths)
self.updater.update_all()
hg_version = get_hg_version(hg)
- # hgwatchman is provided by MozillaBuild and we don't yet support
- # Linux/BSD.
- if ('hgwatchman' not in c.extensions
- and sys.platform.startswith('darwin')
- and hg_version >= HGWATCHMAN_MINIMUM_VERSION
- and self._prompt_yn(HGWATCHMAN_INFO)):
- # Unlike other extensions, we need to run an installer
- # to compile a Python C extension.
- try:
- subprocess.check_output(
- ['make', 'local'],
- cwd=self.updater.hgwatchman_dir,
- stderr=subprocess.STDOUT)
-
- ext_path = os.path.join(self.updater.hgwatchman_dir,
- 'hgwatchman')
- if self.can_use_extension(c, 'hgwatchman', ext_path):
- c.activate_extension('hgwatchman', ext_path)
- except subprocess.CalledProcessError as e:
- print('Error compiling hgwatchman; will not install hgwatchman')
- print(e.output)
-
if 'reviewboard' not in c.extensions:
if hg_version < REVIEWBOARD_MINIMUM_VERSION:
print(REVIEWBOARD_INCOMPATIBLE % REVIEWBOARD_MINIMUM_VERSION)
else:
p = os.path.join(self.vcs_tools_dir, 'hgext', 'reviewboard',
'client.py')
self.prompt_external_extension(c, 'reviewboard',
'Would you like to enable the reviewboard extension so '
new file mode 100644
--- /dev/null
+++ b/hgext/configwizard/tests/test-fsmonitor.t
@@ -0,0 +1,72 @@
+ $ . $TESTDIR/hgext/configwizard/tests/helpers.sh
+
+ $ cat > fakeversion.py << EOF
+ > from mercurial import util
+ > util.version = lambda: '3.8.1'
+ > EOF
+
+Rejecting fsmonitor doesn't enable it
+
+ $ hg --config extensions.fakeversion=fakeversion.py --config ui.interactive=true --config configwizard.steps=fsmonitor,configchange configwizard << EOF
+ >
+ > n
+ > EOF
+ This wizard will guide you through configuring Mercurial for an optimal
+ experience contributing to Mozilla projects.
+
+ The wizard makes no changes without your permission.
+
+ To begin, press the enter/return key.
+ <RETURN>
+ The fsmonitor extension integrates the watchman filesystem watching tool
+ with Mercurial. Commands like `hg status`, `hg diff`, and `hg commit`
+ (which need to examine filesystem state) can query watchman to obtain
+ this state, allowing these commands to complete much quicker.
+
+ When installed, the fsmonitor extension will automatically launch a
+ background watchman daemon for accessed Mercurial repositories. It
+ should "just work."
+
+ Would you like to enable fsmonitor (Yn)? n
+
+#if hg38+
+
+No prompt if extensions already enabled
+
+ $ hg --config configwizard.steps=fsmonitor --config extensions.fsmonitor= configwizard
+
+#endif
+
+fsmonitor enabled when requested
+
+ $ hg --config extensions.fakeversion=fakeversion.py --config configwizard.steps=fsmonitor,configchange configwizard
+ This wizard will guide you through configuring Mercurial for an optimal
+ experience contributing to Mozilla projects.
+
+ The wizard makes no changes without your permission.
+
+ To begin, press the enter/return key.
+ <RETURN>
+ The fsmonitor extension integrates the watchman filesystem watching tool
+ with Mercurial. Commands like `hg status`, `hg diff`, and `hg commit`
+ (which need to examine filesystem state) can query watchman to obtain
+ this state, allowing these commands to complete much quicker.
+
+ When installed, the fsmonitor extension will automatically launch a
+ background watchman daemon for accessed Mercurial repositories. It
+ should "just work."
+
+ Would you like to enable fsmonitor (Yn)? y
+ Your config file needs updating.
+ Would you like to see a diff of the changes first (Yn)? y
+ --- hgrc.old
+ +++ hgrc.new
+ @@ -0,0 +1,2 @@
+ +[extensions]
+ +fsmonitor =
+
+ Write changes to hgrc file (Yn)? y
+
+ $ cat .hgrc
+ [extensions]
+ fsmonitor =