/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 commit.py

  • Committer: Jelmer Vernooij
  • Date: 2011-12-20 16:47:38 UTC
  • Revision ID: jelmer@canonical.com-20111220164738-l6tgnbttkxmq6877
Cope with some strings being unicode when returned by some versions of gtk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
    bencode,
26
26
    errors,
27
27
    osutils,
28
 
    revision as _mod_revision,
29
28
    trace,
30
 
    tsort,
31
29
    )
32
30
from bzrlib.plugins.gtk.dialog import question_dialog
33
 
from bzrlib.plugins.gtk.diff import DiffView
34
31
from bzrlib.plugins.gtk.errors import show_bzr_error
35
32
from bzrlib.plugins.gtk.i18n import _i18n
36
33
from bzrlib.plugins.gtk.commitmsgs import SavedCommitMessagesManager
43
40
    have_dbus = False
44
41
 
45
42
 
46
 
def _get_sorted_revisions(tip_revision, revision_ids, parent_map):
47
 
    """Get an iterator which will return the revisions in merge sorted order.
48
 
 
49
 
    This will build up a list of all nodes, such that only nodes in the list
50
 
    are referenced. It then uses MergeSorter to return them in 'merge-sorted'
51
 
    order.
52
 
 
53
 
    :param revision_ids: A set of revision_ids
54
 
    :param parent_map: The parent information for each node. Revisions which
55
 
        are considered ghosts should not be present in the map.
56
 
    :return: iterator from MergeSorter.iter_topo_order()
57
 
    """
58
 
    # MergeSorter requires that all nodes be present in the graph, so get rid
59
 
    # of any references pointing outside of this graph.
60
 
    parent_graph = {}
61
 
    for revision_id in revision_ids:
62
 
        if revision_id not in parent_map: # ghost
63
 
            parent_graph[revision_id] = []
64
 
        else:
65
 
            # Only include parents which are in this sub-graph
66
 
            parent_graph[revision_id] = [p for p in parent_map[revision_id]
67
 
                                            if p in revision_ids]
68
 
    sorter = tsort.MergeSorter(parent_graph, tip_revision)
69
 
    return sorter.iter_topo_order()
70
 
 
71
 
 
72
43
def pending_revisions(wt):
73
44
    """Return a list of pending merges or None if there are none of them.
74
45
 
79
50
    """
80
51
    parents = wt.get_parent_ids()
81
52
    if len(parents) < 2:
82
 
        return
 
53
        return None
83
54
 
84
55
    # The basic pending merge algorithm uses the same algorithm as
85
56
    # bzrlib.status.show_pending_merges
87
58
    branch = wt.branch
88
59
    last_revision = parents[0]
89
60
 
90
 
    graph = branch.repository.get_graph()
91
 
    other_revisions = [last_revision]
 
61
    if last_revision is not None:
 
62
        graph = branch.repository.get_graph()
 
63
        ignore = set([r for r,ps in graph.iter_ancestry([last_revision])])
 
64
    else:
 
65
        ignore = set([])
92
66
 
93
67
    pm = []
94
68
    for merge in pending:
95
 
        try:
96
 
            merge_rev = branch.repository.get_revision(merge)
97
 
        except errors.NoSuchRevision:
98
 
            # If we are missing a revision, just print out the revision id
99
 
            trace.mutter("ghost: %r", merge)
100
 
            other_revisions.append(merge)
101
 
            continue
102
 
 
103
 
        # Find all of the revisions in the merge source, which are not in the
104
 
        # last committed revision.
105
 
        merge_extra = graph.find_unique_ancestors(merge, other_revisions)
106
 
        other_revisions.append(merge)
107
 
        merge_extra.discard(_mod_revision.NULL_REVISION)
108
 
 
109
 
        # Get a handle to all of the revisions we will need
110
 
        try:
111
 
            revisions = dict((rev.revision_id, rev) for rev in
112
 
                             branch.repository.get_revisions(merge_extra))
113
 
        except errors.NoSuchRevision:
114
 
            # One of the sub nodes is a ghost, check each one
115
 
            revisions = {}
116
 
            for revision_id in merge_extra:
117
 
                try:
118
 
                    rev = branch.repository.get_revisions([revision_id])[0]
119
 
                except errors.NoSuchRevision:
120
 
                    revisions[revision_id] = None
121
 
                else:
122
 
                    revisions[revision_id] = rev
123
 
 
124
 
         # Display the revisions brought in by this merge.
125
 
        rev_id_iterator = _get_sorted_revisions(merge, merge_extra,
126
 
                            branch.repository.get_parent_map(merge_extra))
127
 
        # Skip the first node
128
 
        num, first, depth, eom = rev_id_iterator.next()
129
 
        if first != merge:
130
 
            raise AssertionError('Somehow we misunderstood how'
131
 
                ' iter_topo_order works %s != %s' % (first, merge))
132
 
        children = []
133
 
        for num, sub_merge, depth, eom in rev_id_iterator:
134
 
            rev = revisions[sub_merge]
135
 
            if rev is None:
136
 
                trace.warning("ghost: %r", sub_merge)
137
 
                continue
138
 
            children.append(rev)
139
 
        yield (merge_rev, children)
 
69
        ignore.add(merge)
 
70
        try:
 
71
            rev = branch.repository.get_revision(merge)
 
72
            children = []
 
73
            pm.append((rev, children))
 
74
 
 
75
            # This does need to be topo sorted, so we search backwards
 
76
            inner_merges = branch.repository.get_ancestry(merge)
 
77
            assert inner_merges[0] is None
 
78
            inner_merges.pop(0)
 
79
            for mmerge in reversed(inner_merges):
 
80
                if mmerge in ignore:
 
81
                    continue
 
82
                rev = branch.repository.get_revision(mmerge)
 
83
                children.append(rev)
 
84
 
 
85
                ignore.add(mmerge)
 
86
        except errors.NoSuchRevision:
 
87
            print "DEBUG: NoSuchRevision:", merge
 
88
 
 
89
    return pm
140
90
 
141
91
 
142
92
_newline_variants_re = re.compile(r'\r\n?')
164
114
        self._enable_per_file_commits = True
165
115
        self._commit_all_changes = True
166
116
        self.committed_revision_id = None # Nothing has been committed yet
167
 
        self._last_selected_file = None
168
117
        self._saved_commit_messages_manager = SavedCommitMessagesManager(
169
118
            self._wt, self._wt.branch)
170
119
 
178
127
        self._delta = None
179
128
        self._wt.lock_read()
180
129
        try:
181
 
            self._pending = list(pending_revisions(self._wt))
 
130
            self._pending = pending_revisions(self._wt)
182
131
        finally:
183
132
            self._wt.unlock()
184
133
 
289
238
            self._check_local.hide()
290
239
            return
291
240
        if have_dbus:
292
 
            try:
293
 
                bus = dbus.SystemBus()
294
 
            except dbus.DBusException:
295
 
                trace.mutter("DBus system bus not available")
296
 
                self._check_local.show()
297
 
                return
 
241
            bus = dbus.SystemBus()
298
242
            try:
299
243
                proxy_obj = bus.get_object('org.freedesktop.NetworkManager',
300
244
                                           '/org/freedesktop/NetworkManager')
302
246
                trace.mutter("networkmanager not available.")
303
247
                self._check_local.show()
304
248
                return
305
 
 
 
249
            
306
250
            dbus_iface = dbus.Interface(proxy_obj,
307
251
                                        'org.freedesktop.NetworkManager')
308
252
            try:
334
278
        """Build up the dialog widgets."""
335
279
        # The primary pane which splits it into left and right (adjustable)
336
280
        # sections.
337
 
        self._hpane = Gtk.Paned.new(Gtk.Orientation.HORIZONTAL)
 
281
        self._hpane = Gtk.HPaned()
338
282
 
339
283
        self._construct_left_pane()
340
284
        self._construct_right_pane()
560
504
                                             Gtk.CellRendererText(), text=3))
561
505
 
562
506
    def _construct_diff_view(self):
 
507
        from bzrlib.plugins.gtk.diff import DiffView
 
508
 
563
509
        # TODO: jam 2007-10-30 The diff label is currently disabled. If we
564
510
        #       decide that we really don't ever want to display it, we should
565
511
        #       actually remove it, and other references to it, along with the
574
520
        self._add_to_right_table(self._diff_view, 4, True)
575
521
        self._diff_view.show()
576
522
 
577
 
    @staticmethod
578
 
    def get_line_height(widget):
579
 
        pango_layout = widget.create_pango_layout("X");
580
 
        ink_rectangle, logical_rectangle = pango_layout.get_pixel_extents()
581
 
        return logical_rectangle.height
582
 
 
583
523
    def _construct_file_message(self):
584
524
        scroller = Gtk.ScrolledWindow()
585
525
        scroller.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
592
532
        self._file_message_text_view.modify_font(Pango.FontDescription("Monospace"))
593
533
        self._file_message_text_view.set_wrap_mode(Gtk.WrapMode.WORD)
594
534
        self._file_message_text_view.set_accepts_tab(False)
595
 
        line_height = self.get_line_height(self._file_message_text_view)
596
 
        self._file_message_text_view.set_size_request(-1, line_height * 2)
597
535
        self._file_message_text_view.show()
598
536
 
599
537
        self._file_message_expander = Gtk.Expander(
629
567
 
630
568
    def _on_treeview_files_cursor_changed(self, treeview):
631
569
        treeselection = treeview.get_selection()
632
 
        if treeselection is None:
633
 
            # The treeview was probably destroyed as the dialog closes.
634
 
            return
635
570
        (model, selection) = treeselection.get_selected()
636
571
 
637
572
        if selection is not None: