2
from subprocess import Popen, PIPE
3
from bzrlib.transport import get_transport
4
from urlparse import urlsplit, urlunsplit
5
def patch(branch, location, strip):
6
"""Apply a patch to a branch, using patch(1). URLs may be used."""
11
for prefix in ('http://', 'sftp://', 'file://'):
12
if not location.startswith(prefix):
14
(scheme, loc, path, query, fragment) = urlsplit(location)
15
loc_start = urlunsplit((scheme, loc, '/', '', ''))
16
my_file = get_transport(loc_start).get(path[1:])
18
my_file = file(location, 'rb')
19
cmd = ['patch', '--directory', branch.base, '--strip', str(strip)]
20
child_proc = Popen(cmd, stdin=PIPE)
22
child_proc.stdin.write(line)
23
child_proc.stdin.close()
24
return child_proc.wait()