comparison mercurial/util.py @ 5067:3d35c8cb5eb4

Simplify/correct finding the hg executable (fixes issue644) Simply use find_exe('hg') as the default value for $HG and require to manually set it if you have special requirements. While the default will not always be 100% correct (i.e. the identical hg version) for many users it is and for the others the hg executable found in the PATH should do most things correctly. Developers or other users with multiple installs can set $HG or run something like util.set_hgexecutable in their shell or python scripts. Additionally util.hgexecutable() is now available so extensions can access the value with a public interface, too.
author Thomas Arendsen Hein <thomas@intevation.de>
date Sat, 04 Aug 2007 22:25:12 +0200
parents 0875082d5471
children d5126a0172ba 84b10dc3dccc
comparison
equal deleted inserted replaced
5061:a49f2a4d5ff7 5067:3d35c8cb5eb4
538 else: 538 else:
539 match = lambda fn: incmatch(fn) and not excmatch(fn) and patmatch(fn) 539 match = lambda fn: incmatch(fn) and not excmatch(fn) and patmatch(fn)
540 540
541 return (roots, match, (inc or exc or anypats) and True) 541 return (roots, match, (inc or exc or anypats) and True)
542 542
543 _hgexecutable = 'hg' 543 _hgexecutable = None
544
545 def hgexecutable():
546 """return location of the 'hg' executable.
547
548 Defaults to $HG or 'hg' in the search path.
549 """
550 if _hgexecutable is None:
551 set_hgexecutable(os.environ.get('HG') or find_exe('hg', 'hg'))
552 return _hgexecutable
544 553
545 def set_hgexecutable(path): 554 def set_hgexecutable(path):
546 """remember location of the 'hg' executable if easily possible 555 """set location of the 'hg' executable"""
547
548 path might be None or empty if hg was loaded as a module,
549 fall back to 'hg' in this case.
550 """
551 global _hgexecutable 556 global _hgexecutable
552 if path: 557 _hgexecutable = path
553 _hgexecutable = os.path.abspath(path)
554 558
555 def system(cmd, environ={}, cwd=None, onerr=None, errprefix=None): 559 def system(cmd, environ={}, cwd=None, onerr=None, errprefix=None):
556 '''enhanced shell command execution. 560 '''enhanced shell command execution.
557 run with environment maybe modified, maybe in different dir. 561 run with environment maybe modified, maybe in different dir.
558 562
575 if os.name == 'nt': 579 if os.name == 'nt':
576 cmd = '"%s"' % cmd 580 cmd = '"%s"' % cmd
577 try: 581 try:
578 for k, v in environ.iteritems(): 582 for k, v in environ.iteritems():
579 os.environ[k] = py2shell(v) 583 os.environ[k] = py2shell(v)
580 if 'HG' not in os.environ: 584 os.environ['HG'] = hgexecutable()
581 os.environ['HG'] = _hgexecutable
582 if cwd is not None and oldcwd != cwd: 585 if cwd is not None and oldcwd != cwd:
583 os.chdir(cwd) 586 os.chdir(cwd)
584 rc = os.system(cmd) 587 rc = os.system(cmd)
585 if sys.platform == 'OpenVMS' and rc & 1: 588 if sys.platform == 'OpenVMS' and rc & 1:
586 rc = 0 589 rc = 0