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' % (branch.nick,))
46
graph = branch.repository.get_graph()
47
parent_map = dict(((key, value) for key, value in
48
graph.iter_ancestry([last_revid]) if value is not None))
50
_revision_graph = _strip_NULL_ghosts(parent_map)
54
if is_null(last_revid):
57
_merge_sort = merge_sort(
58
_revision_graph, last_revid, generate_revno=True)
60
for (seq, revid, merge_depth, revno, end_of_merge) in _merge_sort:
61
_full_history.append(revid)
62
revno_str = '.'.join(str(n) for n in revno)
63
_revno_revid[revno_str] = revid
64
_revision_info[revid] = (
65
seq, revid, merge_depth, revno_str, end_of_merge)
69
for revid in _revision_graph.keys():
70
if _revision_info[revid][2] == 0:
72
for parent in _revision_graph[revid]:
73
_where_merged.setdefault(parent, set()).add(revid)
75
log.info('built revision graph cache: %r secs' % (time.time() - z,))
77
return (_revision_graph, _full_history, _revision_info,
78
_revno_revid, _merge_sort, _where_merged)