30
30
except ImportError:
33
from bzrlib import osutils
33
from bzrlib import merge as _mod_merge, osutils, progress, workingtree
34
34
from bzrlib.diff import show_diff_trees, internal_diff
35
35
from bzrlib.errors import NoSuchFile
36
from bzrlib.patches import parse_patches
36
37
from bzrlib.trace import warning
37
38
from bzrlib.plugins.gtk.window import Window
40
class DiffView(gtk.ScrolledWindow):
41
"""This is the soft and chewy filling for a DiffWindow."""
39
from dialog import error_dialog, info_dialog, warning_dialog
42
class SelectCancelled(Exception):
47
class DiffFileView(gtk.ScrolledWindow):
48
"""Window for displaying diffs from a diff file"""
43
50
def __init__(self):
44
51
gtk.ScrolledWindow.__init__(self)
48
self.parent_tree = None
50
55
def construct(self):
51
56
self.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
135
140
lang.set_tag_style(tag_id, style)
138
def apply_colordiff_colors(lang):
143
def apply_colordiff_colors(klass, lang):
139
144
"""Set style colors for lang using the colordiff configuration file.
141
146
Both ~/.colordiffrc and ~/.colordiffrc.bzr-gtk are read.
237
242
# self.parent_tree.unlock()
239
244
def show_diff(self, specific_files):
246
if specific_files is None:
247
self.buffer.set_text(self._diffs[None])
249
for specific_file in specific_files:
250
sections.append(self._diffs[specific_file])
251
self.buffer.set_text(''.join(sections))
254
class DiffView(DiffFileView):
255
"""This is the soft and chewy filling for a DiffWindow."""
258
DiffFileView.__init__(self)
260
self.parent_tree = None
262
def show_diff(self, specific_files):
263
"""Show the diff for the specified files"""
241
265
show_diff_trees(self.parent_tree, self.rev_tree, s, specific_files,
242
266
old_label='', new_label='',
290
314
column.add_attribute(cell, "text", 0)
291
315
self.treeview.append_column(column)
317
def set_diff_text(self, lines):
318
"""Set the current diff from a list of lines
320
:param lines: The diff to show, in unified diff format
293
322
# The diffs of the selected file: a scrollable source or
324
self.diff_view = DiffFileView()
325
self.diff_view.show()
326
self.pack2(self.diff_view)
327
self.model.append(None, [ "Complete Diff", "" ])
328
self.diff_view._diffs[None] = ''.join(lines)
329
for patch in parse_patches(lines):
330
oldname = patch.oldname.split('\t')[0]
331
newname = patch.newname.split('\t')[0]
332
self.model.append(None, [oldname, newname])
333
self.diff_view._diffs[newname] = str(patch)
334
self.diff_view.show_diff(None)
336
def set_diff(self, rev_tree, parent_tree):
337
"""Set the differences showed by this window.
339
Compares the two trees and populates the window with the
295
342
self.diff_view = DiffView()
296
343
self.pack2(self.diff_view)
297
344
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
345
self.diff_view.set_trees(rev_tree, parent_tree)
306
346
self.rev_tree = rev_tree
307
347
self.parent_tree = parent_tree
382
423
def construct(self):
383
424
"""Construct the window contents."""
425
self.vbox = gtk.VBox()
428
hbox = self._get_button_bar()
430
self.vbox.pack_start(hbox, expand=False, fill=True)
384
431
self.diff = DiffWidget()
432
self.vbox.add(self.diff)
386
433
self.diff.show_all()
435
def _get_button_bar(self):
436
"""Return a button bar to use.
438
:return: None, meaning that no button bar will be used.
442
def set_diff_text(self, description, lines):
443
"""Set the diff from a text.
445
The diff must be in unified diff format, and will be parsed to
448
self.diff.set_diff_text(lines)
449
self.set_title(description + " - bzrk diff")
388
451
def set_diff(self, description, rev_tree, parent_tree):
389
452
"""Set the differences showed by this window.
398
461
self.diff.set_file(file_path)
464
class MergeDirectiveWindow(DiffWindow):
466
def __init__(self, directive, parent=None):
467
DiffWindow.__init__(self, parent)
468
self._merge_target = None
469
self.directive = directive
471
def _get_button_bar(self):
472
"""The button bar has only the Merge button"""
473
merge_button = gtk.Button('Merge')
475
merge_button.set_relief(gtk.RELIEF_NONE)
476
merge_button.connect("clicked", self.perform_merge)
478
hbox = gtk.HButtonBox()
479
hbox.set_layout(gtk.BUTTONBOX_START)
480
hbox.pack_start(merge_button, expand=False, fill=True)
484
def perform_merge(self, window):
486
tree = self._get_merge_target()
487
except SelectCancelled:
492
merger, verified = _mod_merge.Merger.from_mergeable(tree,
493
self.directive, progress.DummyProgress())
494
merger.check_basis(True)
495
merger.merge_type = _mod_merge.Merge3Merger
496
conflict_count = merger.do_merge()
498
if conflict_count == 0:
499
# No conflicts found.
500
info_dialog(_('Merge successful'),
501
_('All changes applied successfully.'))
503
# There are conflicts to be resolved.
504
warning_dialog(_('Conflicts encountered'),
505
_('Please resolve the conflicts manually'
506
' before committing.'))
509
error_dialog('Error', str(e))
513
def _get_merge_target(self):
514
if self._merge_target is not None:
515
return self._merge_target
516
d = gtk.FileChooserDialog('Merge branch', self,
517
gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
518
buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK,
520
gtk.RESPONSE_CANCEL,))
523
if result != gtk.RESPONSE_OK:
524
raise SelectCancelled()
525
uri = d.get_current_folder_uri()
528
return workingtree.WorkingTree.open(uri)
401
531
def _iter_changes_to_status(source, target):
402
532
"""Determine the differences between trees.