mercurial/util.py
changeset 5068 d5126a0172ba
parent 4938 02b127749dc0
parent 5067 3d35c8cb5eb4
child 5094 a2c11f49e989
equal deleted inserted replaced
5066:568bb3b4b815 5068:d5126a0172ba
   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