~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/wholehistory.py

  • Committer: Michael Hudson
  • Date: 2009-03-17 22:31:42 UTC
  • Revision ID: michael.hudson@canonical.com-20090317223142-mcvjsllsn7q21e19
mention new dependency on simplejson

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#
2
 
# Copyright (C) 2008, 2009 Canonical Ltd.
 
1
# Cache the whole history data needed by loggerhead about a branch.
3
2
#
4
3
# This program is free software; you can redistribute it and/or modify
5
4
# it under the terms of the GNU General Public License as published by
15
14
# along with this program; if not, write to the Free Software
16
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
16
#
18
 
"""Cache the whole history data needed by loggerhead about a branch."""
19
17
 
20
18
import logging
21
19
import time
32
30
    # Filter ghosts, and null:
33
31
    if NULL_REVISION in revision_graph:
34
32
        del revision_graph[NULL_REVISION]
35
 
    for key, parents in revision_graph.iteritems():
 
33
    for key, parents in revision_graph.items():
36
34
        revision_graph[key] = tuple(parent for parent in parents if parent
37
35
            in revision_graph)
38
36
    return revision_graph
39
37
 
40
38
 
41
39
def compute_whole_history_data(branch):
42
 
    """Compute _rev_info and _rev_indices for a branch.
43
 
 
44
 
    See History.__doc__ for what these data structures mean.
45
 
    """
46
40
    z = time.time()
47
41
 
48
42
    last_revid = branch.last_revision()
49
43
 
50
44
    log = logging.getLogger('loggerhead.%s' %
51
 
                            (branch.get_config().get_nickname(),))
 
45
                            branch.get_config().get_nickname())
52
46
 
53
47
    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)
 
48
    parent_map = dict(((key, value) for key, value in
 
49
         graph.iter_ancestry([last_revid]) if value is not None))
56
50
 
57
51
    _revision_graph = _strip_NULL_ghosts(parent_map)
58
 
 
59
 
    _rev_info = []
60
 
    _rev_indices = {}
61
 
 
 
52
    _full_history = []
 
53
    _revision_info = {}
 
54
    _revno_revid = {}
62
55
    if is_null(last_revid):
63
56
        _merge_sort = []
64
57
    else:
65
58
        _merge_sort = merge_sort(
66
59
            _revision_graph, last_revid, generate_revno=True)
67
60
 
68
 
    for info in _merge_sort:
69
 
        seq, revid, merge_depth, revno, end_of_merge = info
 
61
    for (seq, revid, merge_depth, revno, end_of_merge) in _merge_sort:
 
62
        _full_history.append(revid)
70
63
        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])
74
 
 
75
 
    for revid in _revision_graph.iterkeys():
76
 
        if _rev_info[_rev_indices[revid]][0][2] == 0:
 
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:
77
72
            continue
78
73
        for parent in _revision_graph[revid]:
79
 
            c = _rev_info[_rev_indices[parent]]
80
 
            if revid not in c[1]:
81
 
                c[1] = c[1] + (revid,)
82
 
 
83
 
    log.info('built revision graph cache: %.3f secs' % (time.time() - z,))
84
 
 
85
 
    return (_rev_info, _rev_indices)
 
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)