14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
18
from subprocess import Popen, PIPE
19
19
from bzrlib.transport import get_transport
20
20
from urlparse import urlsplit, urlunsplit
21
def patch(branch, location, strip):
23
"""This class handle the additional bazaar diff tags
32
def _extractname(self, s):
50
def extractname(self, s):
51
space = s.find(" ",9) # find the 2nd space
53
return self._extractname(s[space+1:])[0]
55
def extractnames(self, s):
56
space = s.find(" ",10) # find the 2nd space
59
source, pos = self._extractname(s)
60
assert( pos +4 < len(s) )
61
dest, dummy = self._extractname(s[pos+4:])
68
def process(self, cmd = None):
70
os.rename(self.renamed[0], self.renamed[1])
75
if ( cmd.startswith("removed file") or
76
cmd.startswith("removed symlink") ):
78
target = self.extractname(cmd)
79
print "removing '%s'"%target
82
elif cmd.startswith("removed directory"):
84
target = self.extractname(cmd)
85
print "removing '%s'"%target
88
elif cmd.startswith("added file"):
89
target = self.extractname(cmd)
90
print "adding '%s'"%target
94
elif cmd.startswith("added directory"):
95
target = self.extractname(cmd)
96
print "adding '%s'"%target
99
elif cmd.startswith("added symlink"):
100
assert(not self.link)
101
self.link = self.extractname(cmd)
103
elif cmd.startswith("target is"):
105
source = self.extractname(cmd)
106
print "symlinking '%s' => '%s'"%(source, self.link)
107
os.symlink(source, self.link)
110
elif ( cmd.startswith("renamed symlink") or
111
cmd.startswith("renamed file") or
112
cmd.startswith("renamed directory") ):
114
space = cmd.find(" ",10) # find the 2nd space
116
source,dest = self.extractnames(cmd[space+1:])
117
print "renaming '%s' => '%s'"%(source,dest)
119
os.rename(source,dest)
122
sys.stderr.write("Unsupported tag: '%s'\n"%cmd)
126
def patch(branch, location, strip, legacy):
22
127
"""Apply a patch to a branch, using patch(1). URLs may be used."""
24
129
if location is None:
33
138
if my_file is None:
34
139
my_file = file(location, 'rb')
35
140
cmd = ['patch', '--directory', branch.base, '--strip', str(strip)]
36
child_proc = Popen(cmd, stdin=PIPE)
38
child_proc.stdin.write(line)
39
child_proc.stdin.close()
40
return child_proc.wait()
142
child_proc = Popen(cmd, stdin=PIPE)
144
child_proc.stdin.write(line)
145
child_proc.stdin.close()
146
r = child_proc.wait()
149
bzr_tags_proc = BzrTagProc( )
153
if line.startswith("=== "):
155
child_proc.stdin.close()
156
r = child_proc.wait()
158
bzr_tags_proc.process(line[4:])
161
child_proc = Popen(cmd, stdin=PIPE)
162
#sys.stdout.write("# %s"%line)
163
child_proc.stdin.write(line)
165
child_proc.stdin.close()
166
r = child_proc.wait()
167
bzr_tags_proc.flush( )
b'\\ No newline at end of file'