30
30
except ImportError:
33
from bzrlib import merge as _mod_merge, osutils, progress, workingtree
33
from bzrlib import osutils
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
37
36
from bzrlib.trace import warning
38
37
from bzrlib.plugins.gtk.window import Window
39
from dialog import error_dialog, info_dialog, warning_dialog
42
class SelectCancelled(Exception):
47
class DiffFileView(gtk.ScrolledWindow):
40
class DiffView(gtk.ScrolledWindow):
41
"""This is the soft and chewy filling for a DiffWindow."""
49
43
def __init__(self):
50
44
gtk.ScrolledWindow.__init__(self)
48
self.parent_tree = None
54
50
def construct(self):
55
51
self.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
241
237
# self.parent_tree.unlock()
243
239
def show_diff(self, specific_files):
245
if specific_files is None:
246
self.buffer.set_text(self._diffs[None])
248
for specific_file in specific_files:
249
sections.append(self._diffs[specific_file])
250
self.buffer.set_text(''.join(sections))
253
class DiffView(DiffFileView):
254
"""This is the soft and chewy filling for a DiffWindow."""
257
DiffFileView.__init__(self)
259
self.parent_tree = None
261
def show_diff(self, specific_files):
263
241
show_diff_trees(self.parent_tree, self.rev_tree, s, specific_files,
264
242
old_label='', new_label='',
283
261
self.buffer.set_text(decoded.encode('UTF-8'))
286
class DiffWidget(gtk.HPaned):
264
class DiffWindow(Window):
267
This object represents and manages a single window containing the
268
differences between two revisions on a branch.
291
super(DiffWidget, self).__init__()
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
294
# The file hierarchy: a scrollable treeview
294
295
scrollwin = gtk.ScrolledWindow()
295
296
scrollwin.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
296
297
scrollwin.set_shadow_type(gtk.SHADOW_IN)
297
self.pack1(scrollwin)
298
pane.pack1(scrollwin)
300
301
self.model = gtk.TreeStore(str, str)
312
313
column.add_attribute(cell, "text", 0)
313
314
self.treeview.append_column(column)
315
def set_diff_text(self, lines):
316
316
# The diffs of the selected file: a scrollable source or
318
self.diff_view = DiffFileView()
319
self.diff_view.show()
320
self.pack2(self.diff_view)
321
self.model.append(None, [ "Complete Diff", "" ])
322
self.diff_view._diffs[None] = ''.join(lines)
323
for patch in parse_patches(lines):
324
oldname = patch.oldname.split('\t')[0]
325
newname = patch.newname.split('\t')[0]
326
self.model.append(None, [oldname, newname])
327
self.diff_view._diffs[newname] = str(patch)
328
self.diff_view.show_diff(None)
330
def set_diff(self, rev_tree, parent_tree):
331
"""Set the differences showed by this window.
333
Compares the two trees and populates the window with the
336
318
self.diff_view = DiffView()
337
self.pack2(self.diff_view)
319
pane.pack2(self.diff_view)
338
320
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
339
328
self.diff_view.set_trees(rev_tree, parent_tree)
340
329
self.rev_tree = rev_tree
341
330
self.parent_tree = parent_tree
392
382
self.diff_view.show_diff(specific_files)
395
class DiffWindow(Window):
398
This object represents and manages a single window containing the
399
differences between two revisions on a branch.
402
def __init__(self, parent=None):
403
Window.__init__(self, parent)
404
self.set_border_width(0)
405
self.set_title("bzrk diff")
407
# Use two thirds of the screen by default
408
screen = self.get_screen()
409
monitor = screen.get_monitor_geometry(0)
410
width = int(monitor.width * 0.66)
411
height = int(monitor.height * 0.66)
412
self.set_default_size(width, height)
417
"""Construct the window contents."""
418
self.vbox = gtk.VBox()
421
hbox = self._get_button_bar()
423
self.vbox.pack_start(hbox, expand=False, fill=True)
424
self.diff = DiffWidget()
425
self.vbox.add(self.diff)
428
def _get_button_bar(self):
431
def set_diff_text(self, description, lines):
432
self.diff.set_diff_text(lines)
433
self.set_title(description + " - bzrk diff")
435
def set_diff(self, description, rev_tree, parent_tree):
436
"""Set the differences showed by this window.
438
Compares the two trees and populates the window with the
441
self.diff.set_diff(rev_tree, parent_tree)
442
self.set_title(description + " - bzrk diff")
444
def set_file(self, file_path):
445
self.diff.set_file(file_path)
448
class MergeDirectiveWindow(DiffWindow):
450
def __init__(self, directive, parent=None):
451
DiffWindow.__init__(self, parent)
452
self._merge_target = None
453
self.directive = directive
455
def _get_button_bar(self):
456
merge_button = gtk.Button('Merge')
458
merge_button.set_relief(gtk.RELIEF_NONE)
459
merge_button.connect("clicked", self.perform_merge)
461
hbox = gtk.HButtonBox()
462
hbox.set_layout(gtk.BUTTONBOX_START)
463
hbox.pack_start(merge_button, expand=False, fill=True)
467
def perform_merge(self, window):
469
tree = self._get_merge_target()
470
except SelectCancelled:
475
merger, verified = _mod_merge.Merger.from_mergeable(tree,
476
self.directive, progress.DummyProgress())
477
merger.check_basis(True)
478
merger.merge_type = _mod_merge.Merge3Merger
479
conflict_count = merger.do_merge()
481
if conflict_count == 0:
482
# No conflicts found.
483
info_dialog(_('Merge successful'),
484
_('All changes applied successfully.'))
486
# There are conflicts to be resolved.
487
warning_dialog(_('Conflicts encountered'),
488
_('Please resolve the conflicts manually'
489
' before committing.'))
492
error_dialog('Error', str(e))
496
def _get_merge_target(self):
497
if self._merge_target is not None:
498
return self._merge_target
499
d = gtk.FileChooserDialog('Merge branch', self,
500
gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
501
buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK,
503
gtk.RESPONSE_CANCEL,))
506
if result == gtk.RESPONSE_OK:
507
uri = d.get_current_folder_uri()
508
return workingtree.WorkingTree.open(uri)
510
raise SelectCancelled()
515
385
def _iter_changes_to_status(source, target):
516
386
"""Determine the differences between trees.