Bug 902529 - Also check mercurial.ini on Windows, r=gps, DONTBUILD (NPOTB)

This commit is contained in:
Gijs Kruitbosch 2013-09-13 10:50:28 +02:00
parent 597e0fc281
commit 5931cc9ca6
3 changed files with 22 additions and 4 deletions

View File

@ -6,6 +6,7 @@ from __future__ import unicode_literals
from configobj import ConfigObj
import re
import os
BUGZILLA_FINGERPRINT = '45:77:35:fd:6f:2c:1c:c2:90:4b:f7:b4:4d:60:c6:97:c5:5c:47:27'
@ -15,9 +16,22 @@ HG_FINGERPRINT = '10:78:e8:57:2d:95:de:7c:de:90:bd:22:e1:38:17:67:c5:a7:9c:14'
class MercurialConfig(object):
"""Interface for manipulating a Mercurial config file."""
def __init__(self, infile=None):
def __init__(self, infiles=None):
"""Create a new instance, optionally from an existing hgrc file."""
if infiles:
# If multiple files were specified, figure out which file we're using:
if len(infiles) > 1:
picky_infiles = filter(os.path.isfile, infiles)
if picky_infiles:
picky_infiles = [(os.path.getsize(path), path) for path in picky_infiles]
infiles = [max(picky_infiles)[1]]
infile = infiles[0]
self.config_path = infile
else:
infile = None
# write_empty_values is necessary to prevent built-in extensions (which
# have no value) from being dropped on write.
# list_values aren't needed by Mercurial and disabling them prevents

View File

@ -90,7 +90,7 @@ class MercurialSetupWizard(object):
self.state_dir = state_dir
self.ext_dir = os.path.join(state_dir, 'mercurial', 'extensions')
def run(self, config_path):
def run(self, config_paths):
try:
os.makedirs(self.ext_dir)
except OSError as e:
@ -105,7 +105,7 @@ class MercurialSetupWizard(object):
'up to date.')
return 1
c = MercurialConfig(config_path)
c = MercurialConfig(config_paths)
print(INITIAL_MESSAGE)
raw_input()
@ -225,6 +225,7 @@ class MercurialSetupWizard(object):
new_lines = [line.rstrip() for line in b.getvalue().splitlines()]
old_lines = []
config_path = c.config_path
if os.path.exists(config_path):
with open(config_path, 'rt') as fh:
old_lines = [line.rstrip() for line in fh.readlines()]

View File

@ -26,7 +26,10 @@ class VersionControlCommands(object):
from hgsetup.wizard import MercurialSetupWizard
wizard = MercurialSetupWizard(self._context.state_dir)
result = wizard.run(os.path.expanduser('~/.hgrc'))
config_paths = ['~/.hgrc']
if sys.platform in ('win32', 'cygwin'):
config_paths.insert(0, '~/mercurial.ini')
result = wizard.run(map(os.path.expanduser, config_paths))
# Touch a file so we can periodically prompt to update extensions.
state_path = os.path.join(self._context.state_dir,