175
175
self.tempdir = tempfile.mkdtemp()
176
176
changes_shelved = 0
178
for change in creator.iter_shelvable():
179
if change[0] == 'modify text':
181
changes_shelved += self.handle_modify_text(creator,
183
except errors.BinaryFile:
184
if self.prompt_bool(self.reporter.vocab['binary']):
178
old_tree = self.target_tree
179
new_tree = self.work_tree
180
differ = diff.DiffFromTool.from_string('gvimdiff -f -o',
183
differ.force_temp = True
184
differ.allow_write = True
186
for change in creator.iter_shelvable():
187
if change[0] == 'modify text':
189
changes_shelved += self.handle_modify_text(
190
creator, change[1], differ)
191
except errors.BinaryFile:
192
if self.prompt_bool(self.reporter.vocab['binary']):
194
creator.shelve_content_change(change[1])
196
if self.prompt_bool(self.reporter.prompt_change(change)):
197
creator.shelve_change(change)
185
198
changes_shelved += 1
186
creator.shelve_content_change(change[1])
199
if changes_shelved > 0:
200
self.reporter.selected_changes(creator.work_transform)
201
if (self.auto_apply or self.prompt_bool(
202
self.reporter.vocab['final'] % changes_shelved)):
205
self.reporter.changes_destroyed()
207
shelf_id = self.manager.shelve_changes(creator,
209
self.reporter.shelved_id(shelf_id)
188
if self.prompt_bool(self.reporter.prompt_change(change)):
189
creator.shelve_change(change)
191
if changes_shelved > 0:
192
self.reporter.selected_changes(creator.work_transform)
193
if (self.auto_apply or self.prompt_bool(
194
self.reporter.vocab['final'] % changes_shelved)):
197
self.reporter.changes_destroyed()
199
shelf_id = self.manager.shelve_changes(creator,
201
self.reporter.shelved_id(shelf_id)
203
self.reporter.no_changes()
211
self.reporter.no_changes()
205
215
shutil.rmtree(self.tempdir)
206
216
creator.finalize()
276
def handle_modify_text(self, creator, file_id):
286
def handle_modify_text(self, creator, file_id, differ):
278
288
lines, change_count = self._select_hunks(creator, file_id)
279
289
except UseEditor:
280
lines, change_count = self._edit_file(creator, file_id)
290
lines, change_count = self._edit_file(creator, file_id, differ)
281
291
if change_count != 0:
282
292
creator.shelve_lines(file_id, lines)
283
293
return change_count
325
335
lines = list(patched)
326
336
return lines, change_count
328
def _edit_file(self, creator, file_id):
329
old_tree = self.target_tree
330
new_tree = self.work_tree
331
differ = diff.DiffFromTool.from_string('gvimdiff -f -o',
335
differ.force_temp = True
336
differ.allow_write = True
337
old_path = old_tree.id2path(file_id)
338
new_path = new_tree.id2path(file_id)
339
differ.diff(file_id, old_path, new_path, 'file', 'file')
340
new_abs_path = differ.get_new_path(new_path, abspath=True)
341
new_lines_file = open(new_abs_path, 'r')
343
lines = osutils.split_lines(new_lines_file.read())
344
return lines, len(lines)
346
new_lines_file.close()
338
def _edit_file(self, creator, file_id, differ):
339
old_path = differ.old_tree.id2path(file_id)
340
new_path = differ.new_tree.id2path(file_id)
341
differ.diff(file_id, old_path, new_path, 'file', 'file')
342
lines = osutils.split_lines(differ.read_new_file(new_path))
343
return lines, len(lines)
352
346
class Unshelver(object):