~malept/loggerhead/standalone-auth

« back to all changes in this revision

Viewing changes to loggerhead/wholehistory.py

  • Committer: Martin Albisetti
  • Date: 2008-07-22 00:40:03 UTC
  • mfrom: (182 loggerhead.search_integration)
  • mto: This revision was merged to the branch mainline in revision 187.
  • Revision ID: argentina@gmail.com-20080722004003-lx1fp0tthpp6kl92
Merged from trunk, resolved billions of conflicts

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
import logging
 
4
import time
 
5
 
 
6
from bzrlib.revision import is_null, NULL_REVISION
 
7
from bzrlib.tsort import merge_sort
 
8
 
 
9
 
 
10
def _strip_NULL_ghosts(revision_graph):
 
11
    """
 
12
    Copied over from bzrlib meant as a temporary workaround for
 
13
    deprecated methods.
 
14
    """
 
15
    # Filter ghosts, and null:
 
16
    if NULL_REVISION in revision_graph:
 
17
        del revision_graph[NULL_REVISION]
 
18
    for key, parents in revision_graph.items():
 
19
        revision_graph[key] = tuple(parent for parent in parents if parent
 
20
            in revision_graph)
 
21
    return revision_graph
 
22
 
 
23
 
 
24
def compute_whole_history_data(branch):
 
25
    z = time.time()
 
26
 
 
27
    last_revid = branch.last_revision()
 
28
 
 
29
    log = logging.getLogger('loggerhead.%s' % (branch.nick,))
 
30
 
 
31
    graph = branch.repository.get_graph()
 
32
    parent_map = dict(((key, value) for key, value in
 
33
         graph.iter_ancestry([last_revid]) if value is not None))
 
34
 
 
35
    _revision_graph = _strip_NULL_ghosts(parent_map)
 
36
    _full_history = []
 
37
    _revision_info = {}
 
38
    _revno_revid = {}
 
39
    if is_null(last_revid):
 
40
        _merge_sort = []
 
41
    else:
 
42
        _merge_sort = merge_sort(
 
43
            _revision_graph, last_revid, generate_revno=True)
 
44
 
 
45
    for (seq, revid, merge_depth, revno, end_of_merge) in _merge_sort:
 
46
        _full_history.append(revid)
 
47
        revno_str = '.'.join(str(n) for n in revno)
 
48
        _revno_revid[revno_str] = revid
 
49
        _revision_info[revid] = (
 
50
            seq, revid, merge_depth, revno_str, end_of_merge)
 
51
 
 
52
    _where_merged = {}
 
53
 
 
54
    for revid in _revision_graph.keys():
 
55
        if _revision_info[revid][2] == 0:
 
56
            continue
 
57
        for parent in _revision_graph[revid]:
 
58
            _where_merged.setdefault(parent, set()).add(revid)
 
59
 
 
60
    log.info('built revision graph cache: %r secs' % (time.time() - z,))
 
61
 
 
62
    return (_revision_graph, _full_history, _revision_info,
 
63
            _revno_revid, _merge_sort, _where_merged)