~abentley/bzrtools/bzrtools.dev

257.1.2 by Aaron Bentley
Updated GPL notices
1
# Copyright (C) 2005 Aaron Bentley
2
# <aaron.bentley@utoronto.ca>
3
#
4
#    This program is free software; you can redistribute it and/or modify
5
#    it under the terms of the GNU General Public License as published by
6
#    the Free Software Foundation; either version 2 of the License, or
7
#    (at your option) any later version.
8
#
9
#    This program is distributed in the hope that it will be useful,
10
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
11
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
#    GNU General Public License for more details.
13
#
14
#    You should have received a copy of the GNU General Public License
15
#    along with this program; if not, write to the Free Software
16
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
473 by Aaron Bentley
Clean up patch command (support http urls again)
17
import sys
152 by Aaron Bentley
Added new bzr patch command
18
from subprocess import Popen, PIPE
473 by Aaron Bentley
Clean up patch command (support http urls again)
19
321.2.3 by ghigo
Inform bzr of a renaming
20
from bzrlib.workingtree import WorkingTree
21
import bzrlib.add
473 by Aaron Bentley
Clean up patch command (support http urls again)
22
563 by Aaron Bentley
Allow importing directly from a URL
23
from bzrlib.plugins.bzrtools.bzrtools import open_from_url
24
496 by Aaron Bentley
Add --silent option to patch
25
def patch(tree, location, strip, quiet=False):
259 by Aaron Bentley
Got patch working with urls
26
    """Apply a patch to a branch, using patch(1).  URLs may be used."""
27
    my_file = None
28
    if location is None:
152 by Aaron Bentley
Added new bzr patch command
29
        my_file = sys.stdin
30
    else:
563 by Aaron Bentley
Allow importing directly from a URL
31
        my_file = open_from_url(location)
340 by Aaron Bentley
Fixed patch on checkouts
32
    cmd = ['patch', '--directory', tree.basedir, '--strip', str(strip)]
496 by Aaron Bentley
Add --silent option to patch
33
    if quiet:
34
        cmd.append('--quiet')
321.2.2 by ghigo
Initializate r before the use
35
    r = 0
473 by Aaron Bentley
Clean up patch command (support http urls again)
36
    child_proc = Popen(cmd, stdin=PIPE)
37
    for line in my_file:
38
        child_proc.stdin.write(line)
39
    child_proc.stdin.close()
40
    r = child_proc.wait()
340 by Aaron Bentley
Fixed patch on checkouts
41
    return r