/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to diff.py

  • Committer: Aaron Bentley
  • Date: 2008-02-23 06:39:14 UTC
  • Revision ID: aaron@aaronbentley.com-20080223063914-49gdt7ed630rug9b
Add handle-patch script

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
except ImportError:
31
31
    have_gconf = False
32
32
 
33
 
from bzrlib import (
34
 
    merge as _mod_merge,
35
 
    osutils,
36
 
    progress,
37
 
    urlutils,
38
 
    workingtree,
39
 
)
 
33
from bzrlib import merge as _mod_merge, osutils, progress, workingtree
40
34
from bzrlib.diff import show_diff_trees, internal_diff
41
35
from bzrlib.errors import NoSuchFile
42
36
from bzrlib.patches import parse_patches
51
45
 
52
46
 
53
47
class DiffFileView(gtk.ScrolledWindow):
54
 
    """Window for displaying diffs from a diff file"""
55
48
 
56
49
    def __init__(self):
57
50
        gtk.ScrolledWindow.__init__(self)
227
220
#        self.parent_tree.lock_read()
228
221
#        self.rev_tree.lock_read()
229
222
#        try:
230
 
#            self.delta = iter_changes_to_status(self.parent_tree, self.rev_tree)
 
223
#            self.delta = _iter_changes_to_status(self.parent_tree, self.rev_tree)
231
224
#            self.path_to_status = {}
232
225
#            self.path_to_diff = {}
233
226
#            source_inv = self.parent_tree.inventory
266
259
        self.parent_tree = None
267
260
 
268
261
    def show_diff(self, specific_files):
269
 
        """Show the diff for the specified files"""
270
262
        s = StringIO()
271
263
        show_diff_trees(self.parent_tree, self.rev_tree, s, specific_files,
272
264
                        old_label='', new_label='',
321
313
        self.treeview.append_column(column)
322
314
 
323
315
    def set_diff_text(self, lines):
324
 
        """Set the current diff from a list of lines
325
 
 
326
 
        :param lines: The diff to show, in unified diff format
327
 
        """
328
316
        # The diffs of the  selected file: a scrollable source or
329
317
        # text view
330
318
        self.diff_view = DiffFileView()
381
369
        self.treeview.expand_all()
382
370
 
383
371
    def set_file(self, file_path):
384
 
        """Select the current file to display"""
385
372
        tv_path = None
386
373
        for data in self.model:
387
374
            for child in data.iterchildren():
439
426
        self.diff.show_all()
440
427
 
441
428
    def _get_button_bar(self):
442
 
        """Return a button bar to use.
443
 
 
444
 
        :return: None, meaning that no button bar will be used.
445
 
        """
446
429
        return None
447
430
 
448
431
    def set_diff_text(self, description, lines):
449
 
        """Set the diff from a text.
450
 
 
451
 
        The diff must be in unified diff format, and will be parsed to
452
 
        determine filenames.
453
 
        """
454
432
        self.diff.set_diff_text(lines)
455
433
        self.set_title(description + " - bzrk diff")
456
434
 
469
447
 
470
448
class MergeDirectiveWindow(DiffWindow):
471
449
 
472
 
    def __init__(self, directive, path):
473
 
        DiffWindow.__init__(self, None)
 
450
    def __init__(self, directive, parent=None):
 
451
        DiffWindow.__init__(self, parent)
474
452
        self._merge_target = None
475
453
        self.directive = directive
476
 
        self.path = path
477
454
 
478
455
    def _get_button_bar(self):
479
 
        """The button bar has only the Merge button"""
480
456
        merge_button = gtk.Button('Merge')
481
457
        merge_button.show()
482
458
        merge_button.set_relief(gtk.RELIEF_NONE)
483
459
        merge_button.connect("clicked", self.perform_merge)
484
460
 
485
 
        save_button = gtk.Button('Save')
486
 
        save_button.show()
487
 
        save_button.set_relief(gtk.RELIEF_NONE)
488
 
        save_button.connect("clicked", self.perform_save)
489
 
 
490
461
        hbox = gtk.HButtonBox()
491
462
        hbox.set_layout(gtk.BUTTONBOX_START)
492
463
        hbox.pack_start(merge_button, expand=False, fill=True)
493
 
        hbox.pack_start(save_button, expand=False, fill=True)
494
464
        hbox.show()
495
465
        return hbox
496
466
 
533
503
                                           gtk.RESPONSE_CANCEL,))
534
504
        try:
535
505
            result = d.run()
536
 
            if result != gtk.RESPONSE_OK:
 
506
            if result == gtk.RESPONSE_OK:
 
507
                uri = d.get_current_folder_uri()
 
508
                return workingtree.WorkingTree.open(uri)
 
509
            else:
537
510
                raise SelectCancelled()
538
 
            uri = d.get_current_folder_uri()
539
511
        finally:
540
512
            d.destroy()
541
 
        return workingtree.WorkingTree.open(uri)
542
 
 
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,
547
 
                                           gtk.STOCK_CANCEL,
548
 
                                           gtk.RESPONSE_CANCEL,))
549
 
        d.set_current_name(osutils.basename(self.path))
550
 
        try:
551
 
            try:
552
 
                result = d.run()
553
 
                if result != gtk.RESPONSE_OK:
554
 
                    raise SelectCancelled()
555
 
                uri = d.get_uri()
556
 
            finally:
557
 
                d.destroy()
558
 
        except SelectCancelled:
559
 
            return
560
 
        source = open(self.path, 'rb')
561
 
        try:
562
 
            target = open(urlutils.local_path_from_url(uri), 'wb')
563
 
            try:
564
 
                target.write(source.read())
565
 
            finally:
566
 
                target.close()
567
 
        finally:
568
 
            source.close()
569
 
 
570
 
 
571
 
def iter_changes_to_status(source, target):
 
513
 
 
514
 
 
515
def _iter_changes_to_status(source, target):
572
516
    """Determine the differences between trees.
573
517
 
574
 
    This is a wrapper around iter_changes which just yields more
 
518
    This is a wrapper around _iter_changes which just yields more
575
519
    understandable results.
576
520
 
577
521
    :param source: The source tree (basis tree)
593
537
        source.lock_read()
594
538
        try:
595
539
            for (file_id, paths, changed_content, versioned, parent_ids, names,
596
 
                 kinds, executables) in target.iter_changes(source):
 
540
                 kinds, executables) in target._iter_changes(source):
597
541
 
598
542
                # Skip the root entry if it isn't very interesting
599
543
                if parent_ids == (None, None):