mercurial/util.py
changeset 4686 849f011dbf79
parent 4673 d8442fc0da8d
child 4708 01f9ee4de1ad
equal deleted inserted replaced
4683:8c3d449ecc63 4686:849f011dbf79
   535     else:
   535     else:
   536         match = lambda fn: incmatch(fn) and not excmatch(fn) and patmatch(fn)
   536         match = lambda fn: incmatch(fn) and not excmatch(fn) and patmatch(fn)
   537 
   537 
   538     return (roots, match, (inc or exc or anypats) and True)
   538     return (roots, match, (inc or exc or anypats) and True)
   539 
   539 
       
   540 _hgexecutable = None
       
   541 
       
   542 def set_hgexecutable(path):
       
   543     """remember location of the 'hg' executable if easily possible
       
   544 
       
   545     path might be None or empty if hg was loaded as a module,
       
   546     fall back to 'hg' in this case.
       
   547     """
       
   548     global _hgexecutable
       
   549     _hgexecutable = path and os.path.abspath(path) or 'hg'
       
   550 
   540 def system(cmd, environ={}, cwd=None, onerr=None, errprefix=None):
   551 def system(cmd, environ={}, cwd=None, onerr=None, errprefix=None):
   541     '''enhanced shell command execution.
   552     '''enhanced shell command execution.
   542     run with environment maybe modified, maybe in different dir.
   553     run with environment maybe modified, maybe in different dir.
   543 
   554 
   544     if command fails and onerr is None, return status.  if ui object,
   555     if command fails and onerr is None, return status.  if ui object,
   560     if os.name == 'nt':
   571     if os.name == 'nt':
   561         cmd = '"%s"' % cmd
   572         cmd = '"%s"' % cmd
   562     try:
   573     try:
   563         for k, v in environ.iteritems():
   574         for k, v in environ.iteritems():
   564             os.environ[k] = py2shell(v)
   575             os.environ[k] = py2shell(v)
       
   576         if 'HG' not in os.environ:
       
   577             os.environ['HG'] = _hgexecutable
   565         if cwd is not None and oldcwd != cwd:
   578         if cwd is not None and oldcwd != cwd:
   566             os.chdir(cwd)
   579             os.chdir(cwd)
   567         rc = os.system(cmd)
   580         rc = os.system(cmd)
   568         if rc and onerr:
   581         if rc and onerr:
   569             errmsg = '%s %s' % (os.path.basename(origcmd.split(None, 1)[0]),
   582             errmsg = '%s %s' % (os.path.basename(origcmd.split(None, 1)[0]),