# HG changeset patch
# User ***@gmx.de
# Node ID 29d8f9a16eecb5b1cf112dcfdaf5223d2bf64e4f
# Parent c3cb9f39a91f893e803c011afb3e602531a0963d
Make 'hg import' plattform independent.
- moved popen("patch ...") from commands.py to util.py
- files may not be single quoted in popen under windows: fixed
- patch returns the files quoted under windows. quotes need to
be stripped off: fixed
diff -r c3cb9f39a91f -r 29d8f9a16eec mercurial/commands.py
--- a/mercurial/commands.py Mon Aug 29 19:15:37 2005
+++ b/mercurial/commands.py Thu Sep 01 21:09:12 2005
@@ -1041,18 +1041,7 @@
message = "%s\n" % '\n'.join(message)
ui.debug('message:\n%s\n' % message)
- f = os.popen("patch -p%d < '%s'" % (strip, pf))
- files = []
- for l in f.read().splitlines():
- l.rstrip('\r\n');
- ui.status("%s\n" % l)
- if l.startswith('patching file '):
- pf = l[14:]
- if pf not in files:
- files.append(pf)
- patcherr = f.close()
- if patcherr:
- raise util.Abort("patch failed")
+ files = util.patch(strip,pf,ui)
if len(files) > 0:
addremove(ui, repo, *files)
diff -r c3cb9f39a91f -r 29d8f9a16eec mercurial/util.py
--- a/mercurial/util.py Mon Aug 29 19:15:37 2005
+++ b/mercurial/util.py Thu Sep 01 21:09:12 2005
@@ -14,6 +14,23 @@
from demandload import *
demandload(globals(), "re")
+def patch(strip,patchname,ui):
+ """apply the patch <patchname> to the working directory.
+ a list of patched files is returned"""
+ f = os.popen(patchcmd % (strip, patchname))
+ files = []
+ for l in f.read().splitlines():
+ l.rstrip('\r\n');
+ ui.status("%s\n" % l)
+ if l.startswith('patching file '):
+ pf = parse_patch_output(l)
+ if pf not in files:
+ files.append(pf)
+ patcherr = f.close()
+ if patcherr:
+ raise Abort("patch failed")
+ return files
+
def binary(s):
"""return true if a string is binary data using diff's heuristic"""
if s and '\0' in s[:4096]:
@@ -272,6 +289,14 @@
# Platform specific variants
if os.name == 'nt':
nulldev = 'NUL:'
+ patchcmd = "patch -p%d < \"%s\""
+
+ def parse_patch_output(output_line):
+ """parses the out produced by patch and returns the file name"""
+ pf = output_line[14:]
+ if pf[0] == '`':
+ pf = pf[1:-1] # Remove the quotes
+ return pf
def is_exec(f, last):
return last
@@ -296,6 +321,11 @@
else:
nulldev = '/dev/null'
+ patchcmd = "patch -p%d < '%s'"
+
+ def parse_patch_output(output_line):
+ """parses the out produced by patch and returns the file name"""
+ return output_line[14:]
def is_exec(f, last):
"""check whether a file is executable"""