mercurial/util.py
changeset 2864 71e78f2ca5ae
parent 2858 345bac2bc4ec
parent 2860 0f08f2c042ec
child 2882 c2932ad5476a
equal deleted inserted replaced
2858:345bac2bc4ec 2864:71e78f2ca5ae
    92     for p in path:
    92     for p in path:
    93         p_name = os.path.join(p, name)
    93         p_name = os.path.join(p, name)
    94         if os.path.exists(p_name):
    94         if os.path.exists(p_name):
    95             return p_name
    95             return p_name
    96     return default
    96     return default
    97 
       
    98 def patch(strip, patchname, ui, cwd=None):
       
    99     """apply the patch <patchname> to the working directory.
       
   100     a list of patched files is returned"""
       
   101     patcher = find_in_path('gpatch', os.environ.get('PATH', ''), 'patch')
       
   102     args = []
       
   103     if cwd:
       
   104         args.append('-d %s' % shellquote(cwd))
       
   105     fp = os.popen('%s %s -p%d < %s' % (patcher, ' '.join(args), strip,
       
   106                                        shellquote(patchname)))
       
   107     files = {}
       
   108     for line in fp:
       
   109         line = line.rstrip()
       
   110         ui.status("%s\n" % line)
       
   111         if line.startswith('patching file '):
       
   112             pf = parse_patch_output(line)
       
   113             files.setdefault(pf, 1)
       
   114     code = fp.close()
       
   115     if code:
       
   116         raise Abort(_("patch command failed: %s") % explain_exit(code)[0])
       
   117     return files.keys()
       
   118 
    97 
   119 def binary(s):
    98 def binary(s):
   120     """return true if a string is binary data using diff's heuristic"""
    99     """return true if a string is binary data using diff's heuristic"""
   121     if s and '\0' in s[:4096]:
   100     if s and '\0' in s[:4096]:
   122         return True
   101         return True