equal
deleted
inserted
replaced
28 f = pout.read() |
28 f = pout.read() |
29 pout.close() |
29 pout.close() |
30 w.join() |
30 w.join() |
31 return f |
31 return f |
32 |
32 |
|
33 def patch(strip, patchname, ui): |
|
34 """apply the patch <patchname> to the working directory. |
|
35 a list of patched files is returned""" |
|
36 fp = os.popen('patch -p%d < "%s"' % (strip, patchname)) |
|
37 files = {} |
|
38 for line in fp: |
|
39 line = line.rstrip() |
|
40 ui.status("%s\n" % line) |
|
41 if line.startswith('patching file '): |
|
42 pf = parse_patch_output(line) |
|
43 files.setdefault(pf, 1) |
|
44 code = fp.close() |
|
45 if code: |
|
46 raise Abort("patch command failed: exit status %s " % code) |
|
47 return files.keys() |
|
48 |
33 def binary(s): |
49 def binary(s): |
34 """return true if a string is binary data using diff's heuristic""" |
50 """return true if a string is binary data using diff's heuristic""" |
35 if s and '\0' in s[:4096]: |
51 if s and '\0' in s[:4096]: |
36 return True |
52 return True |
37 return False |
53 return False |
313 |
329 |
314 # Platform specific variants |
330 # Platform specific variants |
315 if os.name == 'nt': |
331 if os.name == 'nt': |
316 nulldev = 'NUL:' |
332 nulldev = 'NUL:' |
317 |
333 |
|
334 def parse_patch_output(output_line): |
|
335 """parses the output produced by patch and returns the file name""" |
|
336 pf = output_line[14:] |
|
337 if pf[0] == '`': |
|
338 pf = pf[1:-1] # Remove the quotes |
|
339 return pf |
|
340 |
318 try: # ActivePython can create hard links using win32file module |
341 try: # ActivePython can create hard links using win32file module |
319 import win32file |
342 import win32file |
320 |
343 |
321 def os_link(src, dst): # NB will only succeed on NTFS |
344 def os_link(src, dst): # NB will only succeed on NTFS |
322 win32file.CreateHardLink(dst, src) |
345 win32file.CreateHardLink(dst, src) |
357 def explain_exit(code): |
380 def explain_exit(code): |
358 return "exited with status %d" % code, code |
381 return "exited with status %d" % code, code |
359 |
382 |
360 else: |
383 else: |
361 nulldev = '/dev/null' |
384 nulldev = '/dev/null' |
|
385 |
|
386 def parse_patch_output(output_line): |
|
387 """parses the output produced by patch and returns the file name""" |
|
388 return output_line[14:] |
362 |
389 |
363 def is_exec(f, last): |
390 def is_exec(f, last): |
364 """check whether a file is executable""" |
391 """check whether a file is executable""" |
365 return (os.stat(f).st_mode & 0100 != 0) |
392 return (os.stat(f).st_mode & 0100 != 0) |
366 |
393 |