comparison mercurial/patch.py @ 4482:62019c4427e3

Introduce find_exe. Use instead of find_in_path for programs. The behaviour of find_in_path was broken for config options containing path names, because it always searched the given path, even when not necessary. The find_exe function is more polite: if the name passed to it contains a path component, it just returns it.
author Bryan O'Sullivan <bos@serpentine.com>
date Sun, 27 May 2007 14:26:54 -0700
parents a764edb6fc95
children c927c568a5ad
comparison
equal deleted inserted replaced
4481:1b5b98837bb5 4482:62019c4427e3
293 """patch and updates the files and fuzz variables""" 293 """patch and updates the files and fuzz variables"""
294 fuzz = False 294 fuzz = False
295 295
296 args = [] 296 args = []
297 patcher = ui.config('ui', 'patch') 297 patcher = ui.config('ui', 'patch')
298 patcher = ((patcher and util.find_exe(patcher)) or
299 util.find_exe('gpatch') or
300 util.find_exe('patch'))
298 if not patcher: 301 if not patcher:
299 patcher = util.find_in_path('gpatch', os.environ.get('PATH', ''), 302 raise util.Abort(_('no patch command found in hgrc or PATH'))
300 'patch') 303 if util.needbinarypatch():
301 if util.needbinarypatch(): 304 args.append('--binary')
302 args.append('--binary')
303 305
304 if cwd: 306 if cwd:
305 args.append('-d %s' % util.shellquote(cwd)) 307 args.append('-d %s' % util.shellquote(cwd))
306 fp = os.popen('%s %s -p%d < %s' % (patcher, ' '.join(args), strip, 308 fp = os.popen('%s %s -p%d < %s' % (patcher, ' '.join(args), strip,
307 util.shellquote(patchname))) 309 util.shellquote(patchname)))
641 643
642 for seqno, rev in enumerate(revs): 644 for seqno, rev in enumerate(revs):
643 single(rev, seqno+1, fp) 645 single(rev, seqno+1, fp)
644 646
645 def diffstat(patchlines): 647 def diffstat(patchlines):
646 if not util.find_in_path('diffstat', os.environ.get('PATH', '')): 648 if not util.find_exe('diffstat'):
647 return 649 return
648 fd, name = tempfile.mkstemp(prefix="hg-patchbomb-", suffix=".txt") 650 fd, name = tempfile.mkstemp(prefix="hg-patchbomb-", suffix=".txt")
649 try: 651 try:
650 p = popen2.Popen3('diffstat -p1 -w79 2>/dev/null > ' + name) 652 p = popen2.Popen3('diffstat -p1 -w79 2>/dev/null > ' + name)
651 try: 653 try: