/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
31
from bzrlib.plugins.gtk.errors import show_bzr_error
42
40
    have_dbus = False
43
41
 
44
42
 
45
 
def _get_sorted_revisions(tip_revision, revision_ids, parent_map):
46
 
    """Get an iterator which will return the revisions in merge sorted order.
47
 
 
48
 
    This will build up a list of all nodes, such that only nodes in the list
49
 
    are referenced. It then uses MergeSorter to return them in 'merge-sorted'
50
 
    order.
51
 
 
52
 
    :param revision_ids: A set of revision_ids
53
 
    :param parent_map: The parent information for each node. Revisions which
54
 
        are considered ghosts should not be present in the map.
55
 
    :return: iterator from MergeSorter.iter_topo_order()
56
 
    """
57
 
    # MergeSorter requires that all nodes be present in the graph, so get rid
58
 
    # of any references pointing outside of this graph.
59
 
    parent_graph = {}
60
 
    for revision_id in revision_ids:
61
 
        if revision_id not in parent_map: # ghost
62
 
            parent_graph[revision_id] = []
63
 
        else:
64
 
            # Only include parents which are in this sub-graph
65
 
            parent_graph[revision_id] = [p for p in parent_map[revision_id]
66
 
                                            if p in revision_ids]
67
 
    sorter = tsort.MergeSorter(parent_graph, tip_revision)
68
 
    return sorter.iter_topo_order()
69
 
 
70
 
 
71
43
def pending_revisions(wt):
72
44
    """Return a list of pending merges or None if there are none of them.
73
45
 
78
50
    """
79
51
    parents = wt.get_parent_ids()
80
52
    if len(parents) < 2:
81
 
        return
 
53
        return None
82
54
 
83
55
    # The basic pending merge algorithm uses the same algorithm as
84
56
    # bzrlib.status.show_pending_merges
86
58
    branch = wt.branch
87
59
    last_revision = parents[0]
88
60
 
89
 
    graph = branch.repository.get_graph()
90
 
    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([])
91
66
 
92
67
    pm = []
93
68
    for merge in pending:
94
 
        try:
95
 
            merge_rev = branch.repository.get_revision(merge)
96
 
        except errors.NoSuchRevision:
97
 
            # If we are missing a revision, just print out the revision id
98
 
            trace.mutter("ghost: %r", merge)
99
 
            other_revisions.append(merge)
100
 
            continue
101
 
 
102
 
        # Find all of the revisions in the merge source, which are not in the
103
 
        # last committed revision.
104
 
        merge_extra = graph.find_unique_ancestors(merge, other_revisions)
105
 
        other_revisions.append(merge)
106
 
        merge_extra.discard(_mod_revision.NULL_REVISION)
107
 
 
108
 
        # Get a handle to all of the revisions we will need
109
 
        try:
110
 
            revisions = dict((rev.revision_id, rev) for rev in
111
 
                             branch.repository.get_revisions(merge_extra))
112
 
        except errors.NoSuchRevision:
113
 
            # One of the sub nodes is a ghost, check each one
114
 
            revisions = {}
115
 
            for revision_id in merge_extra:
116
 
                try:
117
 
                    rev = branch.repository.get_revisions([revision_id])[0]
118
 
                except errors.NoSuchRevision:
119
 
                    revisions[revision_id] = None
120
 
                else:
121
 
                    revisions[revision_id] = rev
122
 
 
123
 
         # Display the revisions brought in by this merge.
124
 
        rev_id_iterator = _get_sorted_revisions(merge, merge_extra,
125
 
                            branch.repository.get_parent_map(merge_extra))
126
 
        # Skip the first node
127
 
        num, first, depth, eom = rev_id_iterator.next()
128
 
        if first != merge:
129
 
            raise AssertionError('Somehow we misunderstood how'
130
 
                ' iter_topo_order works %s != %s' % (first, merge))
131
 
        children = []
132
 
        for num, sub_merge, depth, eom in rev_id_iterator:
133
 
            rev = revisions[sub_merge]
134
 
            if rev is None:
135
 
                trace.warning("ghost: %r", sub_merge)
136
 
                continue
137
 
            children.append(rev)
138
 
        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
139
90
 
140
91
 
141
92
_newline_variants_re = re.compile(r'\r\n?')
163
114
        self._enable_per_file_commits = True
164
115
        self._commit_all_changes = True
165
116
        self.committed_revision_id = None # Nothing has been committed yet
166
 
        self._last_selected_file = None
167
117
        self._saved_commit_messages_manager = SavedCommitMessagesManager(
168
118
            self._wt, self._wt.branch)
169
119
 
177
127
        self._delta = None
178
128
        self._wt.lock_read()
179
129
        try:
180
 
            self._pending = list(pending_revisions(self._wt))
 
130
            self._pending = pending_revisions(self._wt)
181
131
        finally:
182
132
            self._wt.unlock()
183
133
 
288
238
            self._check_local.hide()
289
239
            return
290
240
        if have_dbus:
291
 
            try:
292
 
                bus = dbus.SystemBus()
293
 
            except dbus.DBusException:
294
 
                trace.mutter("DBus system bus not available")
295
 
                self._check_local.show()
296
 
                return
 
241
            bus = dbus.SystemBus()
297
242
            try:
298
243
                proxy_obj = bus.get_object('org.freedesktop.NetworkManager',
299
244
                                           '/org/freedesktop/NetworkManager')
301
246
                trace.mutter("networkmanager not available.")
302
247
                self._check_local.show()
303
248
                return
304
 
 
 
249
            
305
250
            dbus_iface = dbus.Interface(proxy_obj,
306
251
                                        'org.freedesktop.NetworkManager')
307
252
            try:
333
278
        """Build up the dialog widgets."""
334
279
        # The primary pane which splits it into left and right (adjustable)
335
280
        # sections.
336
 
        self._hpane = Gtk.Paned.new(Gtk.Orientation.HORIZONTAL)
 
281
        self._hpane = Gtk.HPaned()
337
282
 
338
283
        self._construct_left_pane()
339
284
        self._construct_right_pane()
622
567
 
623
568
    def _on_treeview_files_cursor_changed(self, treeview):
624
569
        treeselection = treeview.get_selection()
625
 
        if treeselection is None:
626
 
            # The treeview was probably destroyed as the dialog closes.
627
 
            return
628
570
        (model, selection) = treeselection.get_selected()
629
571
 
630
572
        if selection is not None: