47
48
self.inv = self.repo.get_inventory(h[-1])
50
def get_fileid_no(self, path):
51
print "+++++++++++++++",path,"+++++++++++++++++"
52
return self.inv.path2id(path)
55
51
def get_transid(self, path):
56
print "****************",path,"*****************"
57
52
return self.tt.trans_id_tree_path(path)
78
74
def extractname(self, s):
79
space = s.find(" ",13) # find the 2nd space
77
space = s.find(" ",space+1) # find the 2nd space
81
79
return self._extractname(s[space+1:])[0]
83
82
def extractnames(self, s):
84
space = s.find(" ",14) # find the 2nd space
85
space = s.find(" ",space+1) # find the 2nd space
87
88
source, pos = self._extractname(s)
88
89
assert( pos +4 < len(s) )
96
99
def do_patch(self, changes, targetid):
97
# applay change to target_id
98
print "******** do patch *********"
100
print "******** do patch *********"
100
# apply change to target_id
102
cmd = ['patch', '-o', self.tt._limbo_name(targetid),
103
'--directory', self.branch.base, '-p1']
104
#sys.stdout.write("# %r\n"%cmd)
105
child_proc = Popen(cmd, stdin=PIPE)
107
#sys.stdout.write("# %s\n"%line)
108
child_proc.stdin.write(line+'\n')
109
child_proc.stdin.close()
110
r = child_proc.wait()
101
112
self.changes = []
103
114
def process(self, cmd = None):
108
119
if ( cmd == None or cmd.startswith("===") ) and self.changes:
109
120
assert(self.target_id)
110
self.do_patch(self.changes, self.target_id)
122
#print "********** mode=",self.mode
124
if self.mode == "mv" or self.mode == "mod":
125
self.tt.delete_contents(self.target_id)
127
if self.mode == "add" or self.mode == "mod" or self.mode == "mv":
128
self.tt.create_file([],self.target_id)
129
self.do_patch(self.changes, self.target_id)
111
131
self.target_id = None
112
132
self.changes = []
114
135
if cmd == None: return
115
136
if not cmd.startswith("==="):
116
137
if self.skipchange: return
117
138
assert(self.target_id)
118
140
self.changes.append(cmd)
123
145
self.target_id = None
125
147
self.skipchange = False
127
150
if ( cmd.startswith("=== removed file") or
128
151
cmd.startswith("=== removed directory") or
129
152
cmd.startswith("=== removed symlink") ):
131
target = self.extractname(cmd)
154
target = self.extractname(cmd)[2:]
132
155
tid = self.get_transid(target)
133
156
self.tt.delete_versioned(tid)
134
157
print "removing '%s'"%target
135
158
self.skipchange = True
137
161
elif cmd.startswith("=== added file"):
138
target = self.extractname(cmd)
163
target = self.extractname(cmd)[2:]
139
164
self.target_id = self.get_transid(target)
165
#self.tt.create_file([],self.target_id)
166
print "adding '%s'"%target
141
169
elif cmd.startswith("=== modified file"):
142
target = self.extractname(cmd)
170
target = self.extractname(cmd)[2:]
143
171
self.target_id = self.get_transid(target)
173
print "patching '%s'"%target
145
175
elif cmd.startswith("=== added directory"):
146
target = self.extractname(cmd)
147
pdir = os.path.basedir(target)
148
pname = os.path.basename(target)
149
pdir_id = self.get_transid(pdir)
150
self.tt.new_directory(pname, pdir_id)
151
print "adding '%s'"%target
176
target = self.extractname(cmd)[2:]
177
target_id = self.get_transid(target)
178
self.tt.create_directory(target_id)
179
print "adding directory '%s'"%target
153
181
elif cmd.startswith("=== added symlink"):
154
182
assert(not self.link)
155
self.link = self.extractname(cmd)
183
self.link = self.extractname(cmd)[2:]
157
185
elif cmd.startswith("=== target is"):
158
186
assert(self.link)
159
187
target = self.extractname(cmd)
160
pdir = os.path.basedir(self.link)
161
pname = os.path.basename(self.link)
162
pdir_id = self.get_transid(pdir)
163
self.tt.new_symlink(pname, pdir_id, target )
164
print "symlinking '%s' => '%s'"%(target, self.link)
188
link_id = self.get_transid(self.link)
190
print "symlinking '%s' => '%s'\n"%(target, link_id)
191
self.tt.create_symlink(target, link_id)
167
194
elif ( cmd.startswith("=== renamed symlink") or
168
195
cmd.startswith("=== renamed file") or
169
196
cmd.startswith("=== renamed directory") ):
171
space = cmd.find(" ",14) # find the 2nd space
173
source,dest = self.extractnames(cmd[space+1:])
198
source,dest = self.extractnames(cmd)
174
201
sourceid = self.get_transid(source)
175
pdir = os.path.basedir(dest)
176
pname = os.path.basename(dest)
202
pdir,pname = os.path.split(dest)
177
203
pdir_id = self.get_transid(pdir)
178
204
self.tt.adjust_path(pname, pdir_id, sourceid)
206
if cmd.startswith("=== renamed file"):
207
self.target_id = sourceid
180
210
print "renaming '%s' => '%s'"%(source,dest)
225
255
child_proc.stdin.close()
226
256
r = child_proc.wait()
228
#bzr_tags_proc = BzrTagProc(WorkingTree.open_containing(u'.')[0])
230
#for line in my_file:
231
#if line.startswith("=== "):
233
#child_proc.stdin.close()
234
#r = child_proc.wait()
236
#bzr_tags_proc.process(line[4:])
239
#child_proc = Popen(cmd, stdin=PIPE)
240
##sys.stdout.write("# %s"%line)
241
#child_proc.stdin.write(line)
243
#child_proc.stdin.close()
244
#r = child_proc.wait()
245
#bzr_tags_proc.flush( )
246
259
do_patch(sys.stdin.readlines( ))
b'\\ No newline at end of file'