/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: 2012-02-17 15:03:17 UTC
  • Revision ID: jelmer@samba.org-20120217150317-bz27z9fanucxel18
Avoid the use of Repository.get_ancestry().

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,
28
29
    trace,
 
30
    tsort,
29
31
    )
30
32
from bzrlib.plugins.gtk.dialog import question_dialog
31
33
from bzrlib.plugins.gtk.errors import show_bzr_error
40
42
    have_dbus = False
41
43
 
42
44
 
 
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
 
43
71
def pending_revisions(wt):
44
72
    """Return a list of pending merges or None if there are none of them.
45
73
 
50
78
    """
51
79
    parents = wt.get_parent_ids()
52
80
    if len(parents) < 2:
53
 
        return None
 
81
        return
54
82
 
55
83
    # The basic pending merge algorithm uses the same algorithm as
56
84
    # bzrlib.status.show_pending_merges
58
86
    branch = wt.branch
59
87
    last_revision = parents[0]
60
88
 
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([])
 
89
    graph = branch.repository.get_graph()
 
90
    other_revisions = [last_revision]
66
91
 
67
92
    pm = []
68
93
    for merge in pending:
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
 
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)
90
139
 
91
140
 
92
141
_newline_variants_re = re.compile(r'\r\n?')
128
177
        self._delta = None
129
178
        self._wt.lock_read()
130
179
        try:
131
 
            self._pending = pending_revisions(self._wt)
 
180
            self._pending = list(pending_revisions(self._wt))
132
181
        finally:
133
182
            self._wt.unlock()
134
183
 
247
296
                trace.mutter("networkmanager not available.")
248
297
                self._check_local.show()
249
298
                return
250
 
            
 
299
 
251
300
            dbus_iface = dbus.Interface(proxy_obj,
252
301
                                        'org.freedesktop.NetworkManager')
253
302
            try: