1
# Cache the whole history data needed by loggerhead about a branch.
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
from bzrlib.revision import is_null, NULL_REVISION
22
from bzrlib.tsort import merge_sort
25
def _strip_NULL_ghosts(revision_graph):
27
Copied over from bzrlib meant as a temporary workaround for
30
# Filter ghosts, and null:
31
if NULL_REVISION in revision_graph:
32
del revision_graph[NULL_REVISION]
33
for key, parents in revision_graph.items():
34
revision_graph[key] = tuple(parent for parent in parents if parent
39
def compute_whole_history_data(branch):
42
last_revid = branch.last_revision()
44
log = logging.getLogger('loggerhead.%s' %
45
branch.get_config().get_nickname())
47
graph = branch.repository.get_graph()
48
parent_map = dict(((key, value) for key, value in
49
graph.iter_ancestry([last_revid]) if value is not None))
51
_revision_graph = _strip_NULL_ghosts(parent_map)
55
if is_null(last_revid):
58
_merge_sort = merge_sort(
59
_revision_graph, last_revid, generate_revno=True)
61
for (seq, revid, merge_depth, revno, end_of_merge) in _merge_sort:
62
_full_history.append(revid)
63
revno_str = '.'.join(str(n) for n in revno)
64
_revno_revid[revno_str] = revid
65
_revision_info[revid] = (
66
seq, revid, merge_depth, revno_str, end_of_merge)
70
for revid in _revision_graph.keys():
71
if _revision_info[revid][2] == 0:
73
for parent in _revision_graph[revid]:
74
_where_merged.setdefault(parent, set()).add(revid)
76
log.info('built revision graph cache: %r secs' % (time.time() - z))
78
return (_revision_graph, _full_history, _revision_info,
79
_revno_revid, _merge_sort, _where_merged)