comparison mercurial/util.py @ 2864:71e78f2ca5ae

merge git patch code.
author Vadim Gelfer <vadim.gelfer@gmail.com>
date Sat, 12 Aug 2006 12:47:18 -0700
parents 345bac2bc4ec 0f08f2c042ec
children c2932ad5476a
comparison
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