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)
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='',
261
285
self.buffer.set_text(decoded.encode('UTF-8'))
264
class DiffWindow(Window):
288
class DiffWidget(gtk.HPaned):
267
This object represents and manages a single window containing the
268
differences between two revisions on a branch.
271
def __init__(self, parent=None):
272
Window.__init__(self, parent)
273
self.set_border_width(0)
274
self.set_title("bzrk diff")
276
# Use two thirds of the screen by default
277
screen = self.get_screen()
278
monitor = screen.get_monitor_geometry(0)
279
width = int(monitor.width * 0.66)
280
height = int(monitor.height * 0.66)
281
self.set_default_size(width, height)
286
"""Construct the window contents."""
287
# The window consists of a pane containing: the
288
# hierarchical list of files on the left, and the diff
289
# for the currently selected file on the right.
293
super(DiffWidget, self).__init__()
294
295
# The file hierarchy: a scrollable treeview
295
296
scrollwin = gtk.ScrolledWindow()
296
297
scrollwin.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
297
298
scrollwin.set_shadow_type(gtk.SHADOW_IN)
298
pane.pack1(scrollwin)
299
self.pack1(scrollwin)
301
302
self.model = gtk.TreeStore(str, str)
313
314
column.add_attribute(cell, "text", 0)
314
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
316
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
318
342
self.diff_view = DiffView()
319
pane.pack2(self.diff_view)
343
self.pack2(self.diff_view)
320
344
self.diff_view.show()
322
def set_diff(self, description, rev_tree, parent_tree):
323
"""Set the differences showed by this window.
325
Compares the two trees and populates the window with the
328
345
self.diff_view.set_trees(rev_tree, parent_tree)
329
346
self.rev_tree = rev_tree
330
347
self.parent_tree = parent_tree
382
399
self.diff_view.show_diff(specific_files)
402
class DiffWindow(Window):
405
This object represents and manages a single window containing the
406
differences between two revisions on a branch.
409
def __init__(self, parent=None):
410
Window.__init__(self, parent)
411
self.set_border_width(0)
412
self.set_title("bzrk diff")
414
# Use two thirds of the screen by default
415
screen = self.get_screen()
416
monitor = screen.get_monitor_geometry(0)
417
width = int(monitor.width * 0.66)
418
height = int(monitor.height * 0.66)
419
self.set_default_size(width, height)
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)
431
self.diff = DiffWidget()
432
self.vbox.add(self.diff)
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")
451
def set_diff(self, description, rev_tree, parent_tree):
452
"""Set the differences showed by this window.
454
Compares the two trees and populates the window with the
457
self.diff.set_diff(rev_tree, parent_tree)
458
self.set_title(description + " - bzrk diff")
460
def set_file(self, file_path):
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)
385
531
def _iter_changes_to_status(source, target):
386
532
"""Determine the differences between trees.