2
2
from subprocess import Popen, PIPE
3
def patch(branch, filename, strip):
4
"""Apply a patch to a branch, using patch(1)."""
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."""
8
my_file = file(filename, 'rb')
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')
9
19
cmd = ['patch', '--directory', branch.base, '--strip', str(strip)]
10
20
child_proc = Popen(cmd, stdin=PIPE)
11
21
for line in my_file: