~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/wholehistory.py

  • Committer: Michael Hudson
  • Date: 2009-01-22 22:14:47 UTC
  • mto: This revision was merged to the branch mainline in revision 262.
  • Revision ID: michael.hudson@canonical.com-20090122221447-0q02kfg2qfe3tfqy
put the line numbers back

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Cache the whole history data needed by loggerhead about a branch.
 
2
#
 
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.
 
7
#
 
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.
 
12
#
 
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
 
16
#
 
17
 
 
18
import logging
 
19
import time
 
20
 
 
21
from bzrlib.revision import is_null, NULL_REVISION
 
22
from bzrlib.tsort import merge_sort
 
23
 
 
24
 
 
25
def _strip_NULL_ghosts(revision_graph):
 
26
    """
 
27
    Copied over from bzrlib meant as a temporary workaround for
 
28
    deprecated methods.
 
29
    """
 
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
 
35
            in revision_graph)
 
36
    return revision_graph
 
37
 
 
38
 
 
39
def compute_whole_history_data(branch):
 
40
    z = time.time()
 
41
 
 
42
    last_revid = branch.last_revision()
 
43
 
 
44
    log = logging.getLogger('loggerhead.%s' %
 
45
                            branch.get_config().get_nickname())
 
46
 
 
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))
 
50
 
 
51
    _revision_graph = _strip_NULL_ghosts(parent_map)
 
52
    _full_history = []
 
53
    _revision_info = {}
 
54
    _revno_revid = {}
 
55
    if is_null(last_revid):
 
56
        _merge_sort = []
 
57
    else:
 
58
        _merge_sort = merge_sort(
 
59
            _revision_graph, last_revid, generate_revno=True)
 
60
 
 
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)
 
67
 
 
68
    _where_merged = {}
 
69
 
 
70
    for revid in _revision_graph.keys():
 
71
        if _revision_info[revid][2] == 0:
 
72
            continue
 
73
        for parent in _revision_graph[revid]:
 
74
            _where_merged.setdefault(parent, set()).add(revid)
 
75
 
 
76
    log.info('built revision graph cache: %r secs' % (time.time() - z))
 
77
 
 
78
    return (_revision_graph, _full_history, _revision_info,
 
79
            _revno_revid, _merge_sort, _where_merged)