/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: Jelmer Vernooij
  • Date: 2012-07-09 15:23:26 UTC
  • mto: This revision was merged to the branch mainline in revision 794.
  • Revision ID: jelmer@samba.org-20120709152326-dzxb8zoz0btull7n
Remove bzr-notify.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
"""
6
6
 
7
7
__copyright__ = "Copyright 2005 Canonical Ltd."
8
 
__author__    = "Scott James Remnant <scott@ubuntu.com>"
 
8
__author__ = "Scott James Remnant <scott@ubuntu.com>"
9
9
 
10
10
 
11
11
from cStringIO import StringIO
12
12
 
13
 
import pygtk
14
 
pygtk.require("2.0")
15
 
import gtk
16
 
import pango
17
 
import os
18
 
import re
19
13
import sys
20
 
from xml.etree.ElementTree import Element, SubElement, tostring
 
14
import inspect
21
15
 
 
16
from gi.repository import Gtk
 
17
from gi.repository import Pango
22
18
try:
23
 
    import gtksourceview2
 
19
    from gi.repository import GtkSource
24
20
    have_gtksourceview = True
25
21
except ImportError:
26
22
    have_gtksourceview = False
27
 
try:
28
 
    import gconf
29
 
    have_gconf = True
30
 
except ImportError:
31
 
    have_gconf = False
32
23
 
33
24
from bzrlib import (
 
25
    errors,
34
26
    merge as _mod_merge,
35
27
    osutils,
36
 
    progress,
37
28
    urlutils,
38
29
    workingtree,
39
 
)
40
 
from bzrlib.diff import show_diff_trees, internal_diff
41
 
from bzrlib.errors import NoSuchFile
 
30
    )
 
31
from bzrlib.diff import show_diff_trees
42
32
from bzrlib.patches import parse_patches
43
 
from bzrlib.trace import warning
44
 
from bzrlib.plugins.gtk import _i18n
 
33
from bzrlib.plugins.gtk.dialog import (
 
34
    error_dialog,
 
35
    info_dialog,
 
36
    warning_dialog,
 
37
    )
 
38
from bzrlib.plugins.gtk.i18n import _i18n
45
39
from bzrlib.plugins.gtk.window import Window
46
 
from dialog import error_dialog, info_dialog, warning_dialog
 
40
 
 
41
 
 
42
def fallback_guess_language(slm, content_type):
 
43
    for lang_id in slm.get_language_ids():
 
44
        lang = slm.get_language(lang_id)
 
45
        if "text/x-patch" in lang.get_mime_types():
 
46
            return lang
 
47
    return None
47
48
 
48
49
 
49
50
class SelectCancelled(Exception):
51
52
    pass
52
53
 
53
54
 
54
 
class DiffFileView(gtk.ScrolledWindow):
 
55
class DiffFileView(Gtk.ScrolledWindow):
55
56
    """Window for displaying diffs from a diff file"""
56
57
 
 
58
    SHOW_WIDGETS = True
 
59
 
57
60
    def __init__(self):
58
 
        gtk.ScrolledWindow.__init__(self)
 
61
        super(DiffFileView, self).__init__()
59
62
        self.construct()
60
63
        self._diffs = {}
61
64
 
62
65
    def construct(self):
63
 
        self.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
64
 
        self.set_shadow_type(gtk.SHADOW_IN)
 
66
        self.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
 
67
        self.set_shadow_type(Gtk.ShadowType.IN)
65
68
 
66
69
        if have_gtksourceview:
67
 
            self.buffer = gtksourceview2.Buffer()
68
 
            slm = gtksourceview2.LanguageManager()
69
 
            gsl = slm.guess_language(content_type="text/x-patch")
70
 
            if have_gconf:
71
 
                self.apply_gedit_colors(self.buffer)
72
 
            self.apply_colordiff_colors(self.buffer)
73
 
            self.buffer.set_language(gsl)
 
70
            self.buffer = GtkSource.Buffer()
 
71
            lang_manager = GtkSource.LanguageManager.get_default()
 
72
            language = lang_manager.guess_language(None, "text/x-patch")
 
73
            self.buffer.set_language(language)
74
74
            self.buffer.set_highlight_syntax(True)
75
 
 
76
 
            self.sourceview = gtksourceview2.View(self.buffer)
 
75
            self.sourceview = GtkSource.View(buffer=self.buffer)
77
76
        else:
78
 
            self.buffer = gtk.TextBuffer()
79
 
            self.sourceview = gtk.TextView(self.buffer)
 
77
            self.buffer = Gtk.TextBuffer()
 
78
            self.sourceview = Gtk.TextView(self.buffer)
80
79
 
81
80
        self.sourceview.set_editable(False)
82
 
        self.sourceview.modify_font(pango.FontDescription("Monospace"))
 
81
        self.sourceview.override_font(Pango.FontDescription("Monospace"))
83
82
        self.add(self.sourceview)
84
 
        self.sourceview.show()
85
 
 
86
 
    @staticmethod
87
 
    def apply_gedit_colors(buf):
88
 
        """Set style to that specified in gedit configuration.
89
 
 
90
 
        This method needs the gconf module.
91
 
 
92
 
        :param buf: a gtksourceview2.Buffer object.
93
 
        """
94
 
        GEDIT_SCHEME_PATH = '/apps/gedit-2/preferences/editor/colors/scheme'
95
 
 
96
 
        client = gconf.client_get_default()
97
 
        style_scheme_name = client.get_string(GEDIT_SCHEME_PATH)
98
 
        style_scheme = gtksourceview2.StyleSchemeManager().get_scheme(style_scheme_name)
99
 
        
100
 
        buf.set_style_scheme(style_scheme)
101
 
 
102
 
    @classmethod
103
 
    def apply_colordiff_colors(klass, buf):
104
 
        """Set style colors for lang using the colordiff configuration file.
105
 
 
106
 
        Both ~/.colordiffrc and ~/.colordiffrc.bzr-gtk are read.
107
 
 
108
 
        :param buf: a "Diff" gtksourceview2.Buffer object.
109
 
        """
110
 
        scheme_manager = gtksourceview2.StyleSchemeManager()
111
 
        style_scheme = scheme_manager.get_scheme('colordiff')
112
 
        
113
 
        # if style scheme not found, we'll generate it from colordiffrc
114
 
        # TODO: reload if colordiffrc has changed.
115
 
        if style_scheme is None:
116
 
            colors = {}
117
 
 
118
 
            for f in ('~/.colordiffrc', '~/.colordiffrc.bzr-gtk'):
119
 
                f = os.path.expanduser(f)
120
 
                if os.path.exists(f):
121
 
                    try:
122
 
                        f = file(f)
123
 
                    except IOError, e:
124
 
                        warning('could not open file %s: %s' % (f, str(e)))
125
 
                    else:
126
 
                        colors.update(klass.parse_colordiffrc(f))
127
 
                        f.close()
128
 
 
129
 
            if not colors:
130
 
                # ~/.colordiffrc does not exist
131
 
                return
132
 
            
133
 
            mapping = {
134
 
                # map GtkSourceView2 scheme styles to colordiff names
135
 
                # since GSV is richer, accept new names for extra bits,
136
 
                # defaulting to old names if they're not present
137
 
                'diff:added-line': ['newtext'],
138
 
                'diff:removed-line': ['oldtext'],
139
 
                'diff:location': ['location', 'diffstuff'],
140
 
                'diff:file': ['file', 'diffstuff'],
141
 
                'diff:special-case': ['specialcase', 'diffstuff'],
142
 
            }
143
 
            
144
 
            converted_colors = {}
145
 
            for name, values in mapping.items():
146
 
                color = None
147
 
                for value in values:
148
 
                    color = colors.get(value, None)
149
 
                    if color is not None:
150
 
                        break
151
 
                if color is None:
152
 
                    continue
153
 
                converted_colors[name] = color
154
 
            
155
 
            # some xml magic to produce needed style scheme description
156
 
            e_style_scheme = Element('style-scheme')
157
 
            e_style_scheme.set('id', 'colordiff')
158
 
            e_style_scheme.set('_name', 'ColorDiff')
159
 
            e_style_scheme.set('version', '1.0')
160
 
            for name, color in converted_colors.items():
161
 
                style = SubElement(e_style_scheme, 'style')
162
 
                style.set('name', name)
163
 
                style.set('foreground', '#%s' % color)
164
 
            
165
 
            scheme_xml = tostring(e_style_scheme, 'UTF-8')
166
 
            if not os.path.exists(os.path.expanduser('~/.local/share/gtksourceview-2.0/styles')):
167
 
                os.makedirs(os.path.expanduser('~/.local/share/gtksourceview-2.0/styles'))
168
 
            file(os.path.expanduser('~/.local/share/gtksourceview-2.0/styles/colordiff.xml'), 'w').write(scheme_xml)
169
 
            
170
 
            scheme_manager.force_rescan()
171
 
            style_scheme = scheme_manager.get_scheme('colordiff')
172
 
        
173
 
        buf.set_style_scheme(style_scheme)
174
 
 
175
 
    @staticmethod
176
 
    def parse_colordiffrc(fileobj):
177
 
        """Parse fileobj as a colordiff configuration file.
178
 
 
179
 
        :return: A dict with the key -> value pairs.
180
 
        """
181
 
        colors = {}
182
 
        for line in fileobj:
183
 
            if re.match(r'^\s*#', line):
184
 
                continue
185
 
            if '=' not in line:
186
 
                continue
187
 
            key, val = line.split('=', 1)
188
 
            colors[key.strip()] = val.strip()
189
 
        return colors
 
83
        if self.SHOW_WIDGETS:
 
84
            self.sourceview.show()
190
85
 
191
86
    def set_trees(self, rev_tree, parent_tree):
192
87
        self.rev_tree = rev_tree
197
92
#        self.parent_tree.lock_read()
198
93
#        self.rev_tree.lock_read()
199
94
#        try:
200
 
#            self.delta = iter_changes_to_status(self.parent_tree, self.rev_tree)
 
95
#            self.delta = iter_changes_to_status(
 
96
#               self.parent_tree, self.rev_tree)
201
97
#            self.path_to_status = {}
202
98
#            self.path_to_diff = {}
203
99
#            source_inv = self.parent_tree.inventory
204
100
#            target_inv = self.rev_tree.inventory
205
101
#            for (file_id, real_path, change_type, display_path) in self.delta:
206
 
#                self.path_to_status[real_path] = u'=== %s %s' % (change_type, display_path)
 
102
#                self.path_to_status[real_path] = u'=== %s %s' % (
 
103
#                    change_type, display_path)
207
104
#                if change_type in ('modified', 'renamed and modified'):
208
105
#                    source_ie = source_inv[file_id]
209
106
#                    target_ie = target_inv[file_id]
211
108
#                    source_ie.diff(internal_diff, *old path, *old_tree,
212
109
#                                   *new_path, target_ie, self.rev_tree,
213
110
#                                   sio)
214
 
#                    self.path_to_diff[real_path] = 
 
111
#                    self.path_to_diff[real_path] =
215
112
#
216
113
#        finally:
217
114
#            self.rev_tree.unlock()
231
128
    """This is the soft and chewy filling for a DiffWindow."""
232
129
 
233
130
    def __init__(self):
234
 
        DiffFileView.__init__(self)
 
131
        super(DiffView, self).__init__()
235
132
        self.rev_tree = None
236
133
        self.parent_tree = None
237
134
 
261
158
        self.buffer.set_text(decoded.encode('UTF-8'))
262
159
 
263
160
 
264
 
class DiffWidget(gtk.HPaned):
 
161
class DiffWidget(Gtk.HPaned):
265
162
    """Diff widget
266
163
 
267
164
    """
 
165
 
 
166
    SHOW_WIDGETS = True
 
167
 
268
168
    def __init__(self):
269
169
        super(DiffWidget, self).__init__()
270
170
 
271
171
        # The file hierarchy: a scrollable treeview
272
 
        scrollwin = gtk.ScrolledWindow()
273
 
        scrollwin.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
274
 
        scrollwin.set_shadow_type(gtk.SHADOW_IN)
 
172
        scrollwin = Gtk.ScrolledWindow()
 
173
        scrollwin.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
 
174
        scrollwin.set_shadow_type(Gtk.ShadowType.IN)
275
175
        self.pack1(scrollwin)
276
 
        scrollwin.show()
277
 
        
278
 
        self.model = gtk.TreeStore(str, str)
279
 
        self.treeview = gtk.TreeView(self.model)
 
176
        if self.SHOW_WIDGETS:
 
177
            scrollwin.show()
 
178
 
 
179
        self.model = Gtk.TreeStore(str, str)
 
180
        self.treeview = Gtk.TreeView(model=self.model)
280
181
        self.treeview.set_headers_visible(False)
281
182
        self.treeview.set_search_column(1)
282
183
        self.treeview.connect("cursor-changed", self._treeview_cursor_cb)
283
184
        scrollwin.add(self.treeview)
284
 
        self.treeview.show()
 
185
        if self.SHOW_WIDGETS:
 
186
            self.treeview.show()
285
187
 
286
 
        cell = gtk.CellRendererText()
 
188
        cell = Gtk.CellRendererText()
287
189
        cell.set_property("width-chars", 20)
288
 
        column = gtk.TreeViewColumn()
289
 
        column.pack_start(cell, expand=True)
 
190
        column = Gtk.TreeViewColumn()
 
191
        column.pack_start(cell, True)
290
192
        column.add_attribute(cell, "text", 0)
291
193
        self.treeview.append_column(column)
292
194
 
302
204
        if getattr(self, 'diff_view', None) is None:
303
205
            self.diff_view = DiffFileView()
304
206
            self.pack2(self.diff_view)
305
 
        self.diff_view.show()
 
207
        if self.SHOW_WIDGETS:
 
208
            self.diff_view.show()
306
209
        for oldname, newname, patch in sections:
307
210
            self.diff_view._diffs[newname] = str(patch)
308
211
            if newname is None:
319
222
        if getattr(self, 'diff_view', None) is None:
320
223
            self.diff_view = DiffView()
321
224
            self.pack2(self.diff_view)
322
 
        self.diff_view.show()
 
225
        if self.SHOW_WIDGETS:
 
226
            self.diff_view.show()
323
227
        self.diff_view.set_trees(rev_tree, parent_tree)
324
228
        self.rev_tree = rev_tree
325
229
        self.parent_tree = parent_tree
327
231
        self.model.clear()
328
232
        delta = self.rev_tree.changes_from(self.parent_tree)
329
233
 
330
 
        self.model.append(None, [ "Complete Diff", "" ])
 
234
        self.model.append(None, ["Complete Diff", ""])
331
235
 
332
236
        if len(delta.added):
333
 
            titer = self.model.append(None, [ "Added", None ])
 
237
            titer = self.model.append(None, ["Added", None])
334
238
            for path, id, kind in delta.added:
335
 
                self.model.append(titer, [ path, path ])
 
239
                self.model.append(titer, [path, path])
336
240
 
337
241
        if len(delta.removed):
338
 
            titer = self.model.append(None, [ "Removed", None ])
 
242
            titer = self.model.append(None, ["Removed", None])
339
243
            for path, id, kind in delta.removed:
340
 
                self.model.append(titer, [ path, path ])
 
244
                self.model.append(titer, [path, path])
341
245
 
342
246
        if len(delta.renamed):
343
 
            titer = self.model.append(None, [ "Renamed", None ])
 
247
            titer = self.model.append(None, ["Renamed", None])
344
248
            for oldpath, newpath, id, kind, text_modified, meta_modified \
345
249
                    in delta.renamed:
346
 
                self.model.append(titer, [ oldpath, newpath ])
 
250
                self.model.append(titer, [oldpath, newpath])
347
251
 
348
252
        if len(delta.modified):
349
 
            titer = self.model.append(None, [ "Modified", None ])
 
253
            titer = self.model.append(None, ["Modified", None])
350
254
            for path, id, kind, text_modified, meta_modified in delta.modified:
351
 
                self.model.append(titer, [ path, path ])
 
255
                self.model.append(titer, [path, path])
352
256
 
353
257
        self.treeview.expand_all()
354
258
        self.diff_view.show_diff(None)
362
266
                    tv_path = child.path
363
267
                    break
364
268
        if tv_path is None:
365
 
            raise NoSuchFile(file_path)
366
 
        self.treeview.set_cursor(tv_path)
 
269
            raise errors.NoSuchFile(file_path)
 
270
        self.treeview.set_cursor(tv_path, None, False)
367
271
        self.treeview.scroll_to_cell(tv_path)
368
272
 
369
273
    def _treeview_cursor_cb(self, *args):
370
274
        """Callback for when the treeview cursor changes."""
371
275
        (path, col) = self.treeview.get_cursor()
372
 
        specific_files = [ self.model[path][1] ]
373
 
        if specific_files == [ None ]:
374
 
            return
375
 
        elif specific_files == [ "" ]:
 
276
        if path is None:
 
277
            return
 
278
        specific_files = [self.model[path][1]]
 
279
        if specific_files == [None]:
 
280
            return
 
281
        elif specific_files == [""]:
376
282
            specific_files = None
377
 
        
 
283
 
378
284
        self.diff_view.show_diff(specific_files)
379
 
    
 
285
 
380
286
    def _on_wraplines_toggled(self, widget=None, wrap=False):
381
287
        """Callback for when the wrap lines checkbutton is toggled"""
382
288
        if wrap or widget.get_active():
383
 
            self.diff_view.sourceview.set_wrap_mode(gtk.WRAP_WORD)
 
289
            self.diff_view.sourceview.set_wrap_mode(Gtk.WrapMode.WORD)
384
290
        else:
385
 
            self.diff_view.sourceview.set_wrap_mode(gtk.WRAP_NONE)
 
291
            self.diff_view.sourceview.set_wrap_mode(Gtk.WrapMode.NONE)
 
292
 
386
293
 
387
294
class DiffWindow(Window):
388
295
    """Diff window.
391
298
    differences between two revisions on a branch.
392
299
    """
393
300
 
 
301
    SHOW_WIDGETS = True
 
302
 
394
303
    def __init__(self, parent=None, operations=None):
395
 
        Window.__init__(self, parent)
 
304
        super(DiffWindow, self).__init__(parent=parent)
396
305
        self.set_border_width(0)
397
 
        self.set_title("bzrk diff")
 
306
        self.set_title("bzr diff")
398
307
 
399
308
        # Use two thirds of the screen by default
400
309
        screen = self.get_screen()
406
315
 
407
316
    def construct(self, operations):
408
317
        """Construct the window contents."""
409
 
        self.vbox = gtk.VBox()
 
318
        self.vbox = Gtk.VBox()
410
319
        self.add(self.vbox)
411
 
        self.vbox.show()
 
320
        if self.SHOW_WIDGETS:
 
321
            self.vbox.show()
412
322
        self.diff = DiffWidget()
413
323
        self.vbox.pack_end(self.diff, True, True, 0)
414
 
        self.diff.show_all()
 
324
        if self.SHOW_WIDGETS:
 
325
            self.diff.show_all()
415
326
        # Build after DiffWidget to connect signals
416
327
        menubar = self._get_menu_bar()
417
328
        self.vbox.pack_start(menubar, False, False, 0)
418
329
        hbox = self._get_button_bar(operations)
419
330
        if hbox is not None:
420
331
            self.vbox.pack_start(hbox, False, True, 0)
421
 
        
422
 
    
 
332
 
423
333
    def _get_menu_bar(self):
424
 
        menubar = gtk.MenuBar()
 
334
        menubar = Gtk.MenuBar()
425
335
        # View menu
426
 
        mb_view = gtk.MenuItem(_i18n("_View"))
427
 
        mb_view_menu = gtk.Menu()
428
 
        mb_view_wrapsource = gtk.CheckMenuItem(_i18n("Wrap _Long Lines"))
 
336
        mb_view = Gtk.MenuItem.new_with_mnemonic(_i18n("_View"))
 
337
        mb_view_menu = Gtk.Menu()
 
338
        mb_view_wrapsource = Gtk.CheckMenuItem.new_with_mnemonic(
 
339
            _i18n("Wrap _Long Lines"))
429
340
        mb_view_wrapsource.connect('activate', self.diff._on_wraplines_toggled)
430
 
        mb_view_wrapsource.show()
431
341
        mb_view_menu.append(mb_view_wrapsource)
432
 
        mb_view.show()
433
342
        mb_view.set_submenu(mb_view_menu)
434
 
        mb_view.show()
435
343
        menubar.append(mb_view)
436
 
        menubar.show()
 
344
        if self.SHOW_WIDGETS:
 
345
            menubar.show_all()
437
346
        return menubar
438
 
    
 
347
 
439
348
    def _get_button_bar(self, operations):
440
349
        """Return a button bar to use.
441
350
 
443
352
        """
444
353
        if operations is None:
445
354
            return None
446
 
        hbox = gtk.HButtonBox()
447
 
        hbox.set_layout(gtk.BUTTONBOX_START)
 
355
        hbox = Gtk.HButtonBox()
 
356
        hbox.set_layout(Gtk.ButtonBoxStyle.START)
448
357
        for title, method in operations:
449
 
            merge_button = gtk.Button(title)
450
 
            merge_button.show()
451
 
            merge_button.set_relief(gtk.RELIEF_NONE)
 
358
            merge_button = Gtk.Button(title)
 
359
            if self.SHOW_WIDGETS:
 
360
                merge_button.show()
 
361
            merge_button.set_relief(Gtk.ReliefStyle.NONE)
452
362
            merge_button.connect("clicked", method)
453
 
            hbox.pack_start(merge_button, expand=False, fill=True)
454
 
        hbox.show()
 
363
            hbox.pack_start(merge_button, False, True, 0)
 
364
        if self.SHOW_WIDGETS:
 
365
            hbox.show()
455
366
        return hbox
456
367
 
457
368
    def _get_merge_target(self):
458
 
        d = gtk.FileChooserDialog('Merge branch', self,
459
 
                                  gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
460
 
                                  buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK,
461
 
                                           gtk.STOCK_CANCEL,
462
 
                                           gtk.RESPONSE_CANCEL,))
 
369
        d = Gtk.FileChooserDialog('Merge branch', self,
 
370
                                  Gtk.FileChooserAction.SELECT_FOLDER,
 
371
                                  buttons=(Gtk.STOCK_OK, Gtk.ResponseType.OK,
 
372
                                           Gtk.STOCK_CANCEL,
 
373
                                           Gtk.ResponseType.CANCEL,))
463
374
        try:
464
375
            result = d.run()
465
 
            if result != gtk.RESPONSE_OK:
 
376
            if result != Gtk.ResponseType.OK:
466
377
                raise SelectCancelled()
467
378
            return d.get_current_folder_uri()
468
379
        finally:
482
393
        error_dialog('Error', str(e))
483
394
 
484
395
    def _get_save_path(self, basename):
485
 
        d = gtk.FileChooserDialog('Save As', self,
486
 
                                  gtk.FILE_CHOOSER_ACTION_SAVE,
487
 
                                  buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK,
488
 
                                           gtk.STOCK_CANCEL,
489
 
                                           gtk.RESPONSE_CANCEL,))
 
396
        d = Gtk.FileChooserDialog('Save As', self,
 
397
                                  Gtk.FileChooserAction.SAVE,
 
398
                                  buttons=(Gtk.STOCK_OK, Gtk.ResponseType.OK,
 
399
                                           Gtk.STOCK_CANCEL,
 
400
                                           Gtk.ResponseType.CANCEL,))
490
401
        d.set_current_name(basename)
491
402
        try:
492
403
            result = d.run()
493
 
            if result != gtk.RESPONSE_OK:
 
404
            if result != Gtk.ResponseType.OK:
494
405
                raise SelectCancelled()
495
406
            return urlutils.local_path_from_url(d.get_uri())
496
407
        finally:
511
422
 
512
423
class DiffController(object):
513
424
 
514
 
    def __init__(self, path, patch, window=None):
 
425
    def __init__(self, path, patch, window=None, allow_dirty=False):
515
426
        self.path = path
516
427
        self.patch = patch
 
428
        self.allow_dirty = allow_dirty
517
429
        if window is None:
518
430
            window = DiffWindow(operations=self._provide_operations())
519
431
            self.initialize_window(window)
525
437
 
526
438
    def get_diff_sections(self):
527
439
        yield "Complete Diff", None, ''.join(self.patch)
528
 
        for patch in parse_patches(self.patch):
 
440
        # allow_dirty was added to parse_patches in bzrlib 2.2b1
 
441
        if 'allow_dirty' in inspect.getargspec(parse_patches).args:
 
442
            patches = parse_patches(self.patch, allow_dirty=self.allow_dirty)
 
443
        else:
 
444
            patches = parse_patches(self.patch)
 
445
        for patch in patches:
529
446
            oldname = patch.oldname.split('\t')[0]
530
447
            newname = patch.newname.split('\t')[0]
531
448
            yield oldname, newname, str(patch)
552
469
class MergeDirectiveController(DiffController):
553
470
 
554
471
    def __init__(self, path, directive, window=None):
555
 
        DiffController.__init__(self, path, directive.patch.splitlines(True),
556
 
                                window)
 
472
        super(MergeDirectiveController, self).__init__(
 
473
            path, directive.patch.splitlines(True), window)
557
474
        self.directive = directive
558
475
        self.merge_target = None
559
476
 
570
487
        tree.lock_write()
571
488
        try:
572
489
            try:
573
 
                merger, verified = _mod_merge.Merger.from_mergeable(tree,
574
 
                    self.directive, progress.DummyProgress())
575
 
                merger.check_basis(True)
 
490
                if tree.has_changes():
 
491
                    raise errors.UncommittedChanges(tree)
 
492
                merger, verified = _mod_merge.Merger.from_mergeable(
 
493
                    tree, self.directive, pb=None)
576
494
                merger.merge_type = _mod_merge.Merge3Merger
577
495
                conflict_count = merger.do_merge()
578
496
                merger.set_pending()