356.3.1
by Martin Albisetti
Bumped the minimun bzr version to 1.13, and removed some compatibility, as well as random header cleanups |
1 |
#
|
2 |
# Copyright (C) 2008, 2009 Canonical Ltd.
|
|
183.2.1
by John Arbash Meinel
Add Copyright information to most files. |
3 |
#
|
4 |
# This program is free software; you can redistribute it and/or modify
|
|
5 |
# it under the terms of the GNU General Public License as published by
|
|
6 |
# the Free Software Foundation; either version 2 of the License, or
|
|
7 |
# (at your option) any later version.
|
|
8 |
#
|
|
9 |
# This program is distributed in the hope that it will be useful,
|
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU General Public License for more details.
|
|
13 |
#
|
|
14 |
# You should have received a copy of the GNU General Public License
|
|
15 |
# along with this program; if not, write to the Free Software
|
|
467.2.1
by Toshio Kuratomi
Change to the FSF address in license headers |
16 |
# Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
|
183.2.1
by John Arbash Meinel
Add Copyright information to most files. |
17 |
#
|
356.3.1
by Martin Albisetti
Bumped the minimun bzr version to 1.13, and removed some compatibility, as well as random header cleanups |
18 |
"""Cache the whole history data needed by loggerhead about a branch."""
|
179.1.2
by Michael Hudson
don't recalculate the whole history the whole time. |
19 |
|
20 |
import logging |
|
21 |
import time |
|
22 |
||
543.2.1
by Jelmer Vernooij
Sort Python import definitions with isort |
23 |
from breezy.revision import NULL_REVISION, is_null |
491.2.1
by Jelmer Vernooij
s/bzrlib/breezy/ |
24 |
from breezy.tsort import merge_sort |
179.1.2
by Michael Hudson
don't recalculate the whole history the whole time. |
25 |
|
26 |
||
27 |
def _strip_NULL_ghosts(revision_graph): |
|
28 |
"""
|
|
491.2.1
by Jelmer Vernooij
s/bzrlib/breezy/ |
29 |
Copied over from breezy meant as a temporary workaround for
|
179.1.7
by Michael Hudson
more style and dead code removal |
30 |
deprecated methods.
|
179.1.2
by Michael Hudson
don't recalculate the whole history the whole time. |
31 |
"""
|
32 |
# Filter ghosts, and null:
|
|
179.1.7
by Michael Hudson
more style and dead code removal |
33 |
if NULL_REVISION in revision_graph: |
34 |
del revision_graph[NULL_REVISION] |
|
496.2.1
by Jelmer Vernooij
Avoid breezy.sixish. |
35 |
for key, parents in revision_graph.items(): |
179.1.2
by Michael Hudson
don't recalculate the whole history the whole time. |
36 |
revision_graph[key] = tuple(parent for parent in parents if parent |
37 |
in revision_graph) |
|
38 |
return revision_graph |
|
39 |
||
40 |
||
332.2.3
by Michael Hudson
fairly tortuous two level caching |
41 |
def compute_whole_history_data(branch): |
332.2.8
by Michael Hudson
docstrings (omg!!) |
42 |
"""Compute _rev_info and _rev_indices for a branch.
|
43 |
||
44 |
See History.__doc__ for what these data structures mean.
|
|
45 |
"""
|
|
179.1.2
by Michael Hudson
don't recalculate the whole history the whole time. |
46 |
z = time.time() |
47 |
||
332.2.4
by Michael Hudson
remove semantic-free changes |
48 |
last_revid = branch.last_revision() |
49 |
||
247.1.1
by Martin Albisetti
Change API used to get branch nicks so they don't access the network |
50 |
log = logging.getLogger('loggerhead.%s' % |
329.1.14
by Matt Nordhoff
Always use a tuple in string formatting |
51 |
(branch.get_config().get_nickname(),)) |
179.1.2
by Michael Hudson
don't recalculate the whole history the whole time. |
52 |
|
53 |
graph = branch.repository.get_graph() |
|
389.2.7
by Matt Nordhoff
Remove some redundant parens. |
54 |
parent_map = dict((key, value) for key, value in |
393
by Matt Nordhoff
Heh, just noticed another PEP 8 fix. |
55 |
graph.iter_ancestry([last_revid]) if value is not None) |
179.1.2
by Michael Hudson
don't recalculate the whole history the whole time. |
56 |
|
57 |
_revision_graph = _strip_NULL_ghosts(parent_map) |
|
332.1.1
by Michael Hudson
eliminate some of the more egregious memory usage. |
58 |
|
59 |
_rev_info = [] |
|
60 |
_rev_indices = {} |
|
61 |
||
179.1.7
by Michael Hudson
more style and dead code removal |
62 |
if is_null(last_revid): |
179.1.2
by Michael Hudson
don't recalculate the whole history the whole time. |
63 |
_merge_sort = [] |
64 |
else: |
|
179.1.7
by Michael Hudson
more style and dead code removal |
65 |
_merge_sort = merge_sort( |
179.1.2
by Michael Hudson
don't recalculate the whole history the whole time. |
66 |
_revision_graph, last_revid, generate_revno=True) |
67 |
||
332.1.1
by Michael Hudson
eliminate some of the more egregious memory usage. |
68 |
for info in _merge_sort: |
69 |
seq, revid, merge_depth, revno, end_of_merge = info |
|
179.1.2
by Michael Hudson
don't recalculate the whole history the whole time. |
70 |
revno_str = '.'.join(str(n) for n in revno) |
332.1.1
by Michael Hudson
eliminate some of the more egregious memory usage. |
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]) |
|
179.1.2
by Michael Hudson
don't recalculate the whole history the whole time. |
74 |
|
496.2.1
by Jelmer Vernooij
Avoid breezy.sixish. |
75 |
for revid in _revision_graph.keys(): |
332.1.1
by Michael Hudson
eliminate some of the more egregious memory usage. |
76 |
if _rev_info[_rev_indices[revid]][0][2] == 0: |
179.1.2
by Michael Hudson
don't recalculate the whole history the whole time. |
77 |
continue
|
78 |
for parent in _revision_graph[revid]: |
|
332.1.1
by Michael Hudson
eliminate some of the more egregious memory usage. |
79 |
c = _rev_info[_rev_indices[parent]] |
80 |
if revid not in c[1]: |
|
81 |
c[1] = c[1] + (revid,) |
|
179.1.2
by Michael Hudson
don't recalculate the whole history the whole time. |
82 |
|
411.2.2
by John Arbash Meinel
Make some of the info calls a bit less noisy. |
83 |
log.info('built revision graph cache: %.3f secs' % (time.time() - z,)) |
179.1.2
by Michael Hudson
don't recalculate the whole history the whole time. |
84 |
|
332.2.4
by Michael Hudson
remove semantic-free changes |
85 |
return (_rev_info, _rev_indices) |