~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to patch.py

  • Committer: Aaron Bentley
  • Date: 2005-10-28 04:16:32 UTC
  • Revision ID: aaron.bentley@utoronto.ca-20051028041632-274e8630cef9a1e9
Got patch working with urls

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import sys
2
2
from subprocess import Popen, PIPE
3
 
def patch(branch, filename, strip):
4
 
    """Apply a patch to a branch, using patch(1)."""
5
 
    if filename is None:
 
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."""
 
7
    my_file = None
 
8
    if location is None:
6
9
        my_file = sys.stdin
7
10
    else:
8
 
        my_file = file(filename, 'rb')
 
11
        for prefix in ('http://', 'sftp://', 'file://'):
 
12
            if not location.startswith(prefix):
 
13
                continue
 
14
            (scheme, loc, path, query, fragment) = urlsplit(location)
 
15
            loc_start = urlunsplit((scheme, loc, '/', '', ''))
 
16
            my_file = get_transport(loc_start).get(path[1:])
 
17
        if my_file is None:
 
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: