30
30
except ImportError:
33
from bzrlib import osutils
34
40
from bzrlib.diff import show_diff_trees, internal_diff
35
41
from bzrlib.errors import NoSuchFile
42
from bzrlib.patches import parse_patches
36
43
from bzrlib.trace import warning
37
44
from bzrlib.plugins.gtk.window import Window
40
class DiffView(gtk.ScrolledWindow):
41
"""This is the soft and chewy filling for a DiffWindow."""
45
from dialog import error_dialog, info_dialog, warning_dialog
48
class SelectCancelled(Exception):
53
class DiffFileView(gtk.ScrolledWindow):
54
"""Window for displaying diffs from a diff file"""
43
56
def __init__(self):
44
57
gtk.ScrolledWindow.__init__(self)
48
self.parent_tree = None
50
61
def construct(self):
51
62
self.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
237
248
# self.parent_tree.unlock()
239
250
def show_diff(self, specific_files):
252
if specific_files is None:
253
self.buffer.set_text(self._diffs[None])
255
for specific_file in specific_files:
256
sections.append(self._diffs[specific_file])
257
self.buffer.set_text(''.join(sections))
260
class DiffView(DiffFileView):
261
"""This is the soft and chewy filling for a DiffWindow."""
264
DiffFileView.__init__(self)
266
self.parent_tree = None
268
def show_diff(self, specific_files):
269
"""Show the diff for the specified files"""
241
271
show_diff_trees(self.parent_tree, self.rev_tree, s, specific_files,
242
272
old_label='', new_label='',
290
320
column.add_attribute(cell, "text", 0)
291
321
self.treeview.append_column(column)
323
def set_diff_text(self, lines):
324
"""Set the current diff from a list of lines
326
:param lines: The diff to show, in unified diff format
293
328
# The diffs of the selected file: a scrollable source or
330
self.diff_view = DiffFileView()
331
self.diff_view.show()
332
self.pack2(self.diff_view)
333
self.model.append(None, [ "Complete Diff", "" ])
334
self.diff_view._diffs[None] = ''.join(lines)
335
for patch in parse_patches(lines):
336
oldname = patch.oldname.split('\t')[0]
337
newname = patch.newname.split('\t')[0]
338
self.model.append(None, [oldname, newname])
339
self.diff_view._diffs[newname] = str(patch)
340
self.diff_view.show_diff(None)
342
def set_diff(self, rev_tree, parent_tree):
343
"""Set the differences showed by this window.
345
Compares the two trees and populates the window with the
295
348
self.diff_view = DiffView()
296
349
self.pack2(self.diff_view)
297
350
self.diff_view.show()
299
def set_diff(self, rev_tree, parent_tree):
300
"""Set the differences showed by this window.
302
Compares the two trees and populates the window with the
305
351
self.diff_view.set_trees(rev_tree, parent_tree)
306
352
self.rev_tree = rev_tree
307
353
self.parent_tree = parent_tree
382
429
def construct(self):
383
430
"""Construct the window contents."""
431
self.vbox = gtk.VBox()
434
hbox = self._get_button_bar()
436
self.vbox.pack_start(hbox, expand=False, fill=True)
384
437
self.diff = DiffWidget()
438
self.vbox.add(self.diff)
386
439
self.diff.show_all()
441
def _get_button_bar(self):
442
"""Return a button bar to use.
444
:return: None, meaning that no button bar will be used.
448
def set_diff_text(self, description, lines):
449
"""Set the diff from a text.
451
The diff must be in unified diff format, and will be parsed to
454
self.diff.set_diff_text(lines)
455
self.set_title(description + " - bzrk diff")
388
457
def set_diff(self, description, rev_tree, parent_tree):
389
458
"""Set the differences showed by this window.
398
467
self.diff.set_file(file_path)
401
def _iter_changes_to_status(source, target):
470
class MergeDirectiveWindow(DiffWindow):
472
def __init__(self, directive, path):
473
DiffWindow.__init__(self, None)
474
self._merge_target = None
475
self.directive = directive
478
def _get_button_bar(self):
479
"""The button bar has only the Merge button"""
480
merge_button = gtk.Button('Merge')
482
merge_button.set_relief(gtk.RELIEF_NONE)
483
merge_button.connect("clicked", self.perform_merge)
485
save_button = gtk.Button('Save')
487
save_button.set_relief(gtk.RELIEF_NONE)
488
save_button.connect("clicked", self.perform_save)
490
hbox = gtk.HButtonBox()
491
hbox.set_layout(gtk.BUTTONBOX_START)
492
hbox.pack_start(merge_button, expand=False, fill=True)
493
hbox.pack_start(save_button, expand=False, fill=True)
497
def perform_merge(self, window):
499
tree = self._get_merge_target()
500
except SelectCancelled:
505
merger, verified = _mod_merge.Merger.from_mergeable(tree,
506
self.directive, progress.DummyProgress())
507
merger.check_basis(True)
508
merger.merge_type = _mod_merge.Merge3Merger
509
conflict_count = merger.do_merge()
511
if conflict_count == 0:
512
# No conflicts found.
513
info_dialog(_('Merge successful'),
514
_('All changes applied successfully.'))
516
# There are conflicts to be resolved.
517
warning_dialog(_('Conflicts encountered'),
518
_('Please resolve the conflicts manually'
519
' before committing.'))
522
error_dialog('Error', str(e))
526
def _get_merge_target(self):
527
if self._merge_target is not None:
528
return self._merge_target
529
d = gtk.FileChooserDialog('Merge branch', self,
530
gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
531
buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK,
533
gtk.RESPONSE_CANCEL,))
536
if result != gtk.RESPONSE_OK:
537
raise SelectCancelled()
538
uri = d.get_current_folder_uri()
541
return workingtree.WorkingTree.open(uri)
543
def perform_save(self, window):
544
d = gtk.FileChooserDialog('Save As', self,
545
gtk.FILE_CHOOSER_ACTION_SAVE,
546
buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK,
548
gtk.RESPONSE_CANCEL,))
549
d.set_current_name(osutils.basename(self.path))
553
if result != gtk.RESPONSE_OK:
554
raise SelectCancelled()
558
except SelectCancelled:
560
source = open(self.path, 'rb')
562
target = open(urlutils.local_path_from_url(uri), 'wb')
564
target.write(source.read())
571
def iter_changes_to_status(source, target):
402
572
"""Determine the differences between trees.
404
This is a wrapper around _iter_changes which just yields more
574
This is a wrapper around iter_changes which just yields more
405
575
understandable results.
407
577
:param source: The source tree (basis tree)