##// END OF EJS Templates
setup: prefer using the system hg to interact with the local repository...
Adam Simpkins -
r33114:8b20338b default
parent child Browse files
Show More
@@ -149,9 +149,9 b' def runcmd(cmd, env):'
149 149 return p.returncode, out, err
150 150
151 151 class hgcommand(object):
152 def __init__(self):
153 self.cmd = [sys.executable, 'hg']
154 self.env = gethgenv()
152 def __init__(self, cmd, env):
153 self.cmd = cmd
154 self.env = env
155 155
156 156 def run(self, args):
157 157 cmd = self.cmd + args
@@ -171,7 +171,50 b' class hgcommand(object):'
171 171 return ''
172 172 return out
173 173
174 def gethgenv():
174 def findhg():
175 """Try to figure out how we should invoke hg for examining the local
176 repository contents.
177
178 Returns an hgcommand object."""
179 # By default, prefer the "hg" command in the user's path. This was
180 # presumably the hg command that the user used to create this repository.
181 #
182 # This repository may require extensions or other settings that would not
183 # be enabled by running the hg script directly from this local repository.
184 hgenv = os.environ.copy()
185 # Use HGPLAIN to disable hgrc settings that would change output formatting,
186 # and disable localization for the same reasons.
187 hgenv['HGPLAIN'] = '1'
188 hgenv['LANGUAGE'] = 'C'
189 hgcmd = ['hg']
190 # Run a simple "hg log" command just to see if using hg from the user's
191 # path works and can successfully interact with this repository.
192 check_cmd = ['log', '-r.', '-Ttest']
193 try:
194 retcode, out, err = runcmd(hgcmd + check_cmd, hgenv)
195 except EnvironmentError:
196 retcode = -1
197 if retcode == 0:
198 return hgcommand(hgcmd, hgenv)
199
200 # Fall back to trying the local hg installation.
201 hgenv = localhgenv()
202 # Don't source any system hgrc files when using the local hg.
203 hgenv['HGRCPATH'] = ''
204 hgcmd = [sys.executable, 'hg']
205 try:
206 retcode, out, err = runcmd(hgcmd + check_cmd, hgenv)
207 except EnvironmentError:
208 retcode = -1
209 if retcode == 0:
210 return hgcommand(hgcmd, hgenv)
211
212 raise SystemExit('Unable to find a working hg binary to extract the '
213 'version from the repository tags')
214
215 def localhgenv():
216 """Get an environment dictionary to use for invoking or importing
217 mercurial from the local repository."""
175 218 # Execute hg out of this directory with a custom environment which takes
176 219 # care to not use any hgrc files and do no localization.
177 220 env = {'HGMODULEPOLICY': 'py',
@@ -188,7 +231,7 b' def gethgenv():'
188 231 version = ''
189 232
190 233 if os.path.isdir('.hg'):
191 hg = hgcommand()
234 hg = findhg()
192 235 cmd = ['log', '-r', '.', '--template', '{tags}\n']
193 236 numerictags = [t for t in hg.run(cmd).split() if t[0:1].isdigit()]
194 237 hgid = hg.run(['id', '-i']).strip()
@@ -410,7 +453,8 b' class buildhgextindex(Command):'
410 453 # here no extension enabled, disabled() lists up everything
411 454 code = ('import pprint; from mercurial import extensions; '
412 455 'pprint.pprint(extensions.disabled())')
413 returncode, out, err = runcmd([sys.executable, '-c', code], gethgenv())
456 returncode, out, err = runcmd([sys.executable, '-c', code],
457 localhgenv())
414 458 if err or returncode != 0:
415 459 raise DistutilsExecError(err)
416 460
General Comments 0
You need to be logged in to leave comments. Login now