mercurial/util.py
changeset 2760 e6bef16b6cec
parent 2740 386f04d6ecb3
child 2791 f4d916351366
equal deleted inserted replaced
2759:19436facb073 2760:e6bef16b6cec
    91         p_name = os.path.join(p, name)
    91         p_name = os.path.join(p, name)
    92         if os.path.exists(p_name):
    92         if os.path.exists(p_name):
    93             return p_name
    93             return p_name
    94     return default
    94     return default
    95 
    95 
    96 def patch(strip, patchname, ui):
    96 def patch(strip, patchname, ui, cwd=None):
    97     """apply the patch <patchname> to the working directory.
    97     """apply the patch <patchname> to the working directory.
    98     a list of patched files is returned"""
    98     a list of patched files is returned"""
    99     patcher = find_in_path('gpatch', os.environ.get('PATH', ''), 'patch')
    99     patcher = find_in_path('gpatch', os.environ.get('PATH', ''), 'patch')
   100     fp = os.popen('%s -p%d < "%s"' % (patcher, strip, patchname))
   100     args = []
       
   101     if cwd:
       
   102         args.append('-d "%s"' % cwd)
       
   103     fp = os.popen('%s %s -p%d < "%s"' % (patcher, ' '.join(args), strip,
       
   104                                          patchname))
   101     files = {}
   105     files = {}
   102     for line in fp:
   106     for line in fp:
   103         line = line.rstrip()
   107         line = line.rstrip()
   104         ui.status("%s\n" % line)
   108         ui.status("%s\n" % line)
   105         if line.startswith('patching file '):
   109         if line.startswith('patching file '):