~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/deprecated_graph.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-10-16 21:31:35 UTC
  • mfrom: (3363.19.4 fix-iter-changes)
  • Revision ID: pqm@pqm.ubuntu.com-20081016213135-0115pw9c95l2dyxq
PreviewTree.iter_changes accepts all standard parameters (abentley)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# (C) 2005 Canonical
2
 
 
 
1
# Copyright (C) 2005, 2008 Canonical Ltd
 
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
7
 
 
 
7
#
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
# GNU General Public License for more details.
12
 
 
 
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
18
 
from bzrlib.tsort import topo_sort
19
 
 
20
 
 
21
18
def max_distance(node, ancestors, distances, root_descendants):
22
19
    """Calculate the max distance to an ancestor.  
23
20
    Return None if not all possible ancestors have known distances"""
60
57
        new_lines = set()
61
58
        for line in lines:
62
59
            line_descendants = graph[line]
63
 
            assert line not in line_descendants, "%s refers to itself" % line
64
60
            for descendant in line_descendants:
65
61
                distance = max_distance(descendant, ancestors, distances,
66
62
                                        root_descendants)
125
121
 
126
122
    def add_node(self, node_id, parent_ids):
127
123
        """Add node_id to the graph with parent_ids as its parents."""
128
 
        if parent_ids == []:
 
124
        if len(parent_ids) == 0:
129
125
            self.roots.add(node_id)
130
126
        self._graph_ancestors[node_id] = list(parent_ids)
131
127
        self._ensure_descendant(node_id)
142
138
        """Return a dictionary of graph node:ancestor_list entries."""
143
139
        return dict(self._graph_ancestors.items())
144
140
 
145
 
    def get_ancestry(self, node_id):
 
141
    def get_ancestry(self, node_id, topo_sorted=True):
146
142
        """Return the inclusive ancestors of node_id in topological order."""
147
143
        # maybe optimise this ?
 
144
        from bzrlib.tsort import topo_sort
148
145
        result = {}
149
146
        pending = set([node_id])
150
147
        while len(pending):
155
152
            for parent in parents:
156
153
                if parent not in result and parent not in pending:
157
154
                    pending.add(parent)
 
155
        if not topo_sorted:
 
156
            return result.keys()
158
157
        return topo_sort(result.items())
159
158
 
160
159
    def get_descendants(self):