2
# Copyright (C) 2008, 2009 Canonical Ltd.
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
"""Cache the whole history data needed by loggerhead about a branch."""
23
from bzrlib.revision import is_null, NULL_REVISION
24
from bzrlib.tsort import merge_sort
27
def _strip_NULL_ghosts(revision_graph):
29
Copied over from bzrlib meant as a temporary workaround for
32
# Filter ghosts, and null:
33
if NULL_REVISION in revision_graph:
34
del revision_graph[NULL_REVISION]
35
for key, parents in revision_graph.iteritems():
36
revision_graph[key] = tuple(parent for parent in parents if parent
41
def compute_whole_history_data(branch):
42
"""Compute _rev_info and _rev_indices for a branch.
44
See History.__doc__ for what these data structures mean.
48
last_revid = branch.last_revision()
50
log = logging.getLogger('loggerhead.%s' %
51
(branch.get_config().get_nickname(),))
53
graph = branch.repository.get_graph()
54
parent_map = dict(((key, value) for key, value in
55
graph.iter_ancestry([last_revid]) if value is not None))
57
_revision_graph = _strip_NULL_ghosts(parent_map)
62
if is_null(last_revid):
65
_merge_sort = merge_sort(
66
_revision_graph, last_revid, generate_revno=True)
68
for info in _merge_sort:
69
seq, revid, merge_depth, revno, end_of_merge = info
70
revno_str = '.'.join(str(n) for n in revno)
71
parents = _revision_graph[revid]
72
_rev_indices[revid] = len(_rev_info)
73
_rev_info.append([(seq, revid, merge_depth, revno_str, end_of_merge), (), parents])
75
for revid in _revision_graph.iterkeys():
76
if _rev_info[_rev_indices[revid]][0][2] == 0:
78
for parent in _revision_graph[revid]:
79
c = _rev_info[_rev_indices[parent]]
81
c[1] = c[1] + (revid,)
83
log.info('built revision graph cache: %r secs' % (time.time() - z))
85
return (_rev_info, _rev_indices)