bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
0.78.3
by Ian Clatworthy
move GenericCacheManager into its own module |
1 |
# Copyright (C) 2009 Canonical Ltd
|
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 |
"""A manager of caches."""
|
|
18 |
||
19 |
||
|
0.64.118
by Ian Clatworthy
fix lru_cache import |
20 |
from bzrlib import lru_cache |
21 |
||
22 |
||
|
0.78.3
by Ian Clatworthy
move GenericCacheManager into its own module |
23 |
class CacheManager(object): |
24 |
||
25 |
def __init__(self, info, verbose=False, inventory_cache_size=10): |
|
26 |
"""Create a manager of caches. |
|
27 |
||
28 |
:param info: a ConfigObj holding the output from
|
|
29 |
the --info processor, or None if no hints are available
|
|
30 |
"""
|
|
31 |
self.verbose = verbose |
|
32 |
||
33 |
# dataref -> data. datref is either :mark or the sha-1.
|
|
34 |
# Sticky blobs aren't removed after being referenced.
|
|
35 |
self._blobs = {} |
|
36 |
self._sticky_blobs = {} |
|
37 |
||
38 |
# revision-id -> Inventory cache
|
|
39 |
# these are large and we probably don't need too many as
|
|
40 |
# most parents are recent in history
|
|
41 |
self.inventories = lru_cache.LRUCache(inventory_cache_size) |
|
42 |
||
43 |
# import commmit-ids -> revision-id lookup table
|
|
44 |
# we need to keep all of these but they are small
|
|
45 |
self.revision_ids = {} |
|
46 |
||
47 |
# path -> file-ids - as generated
|
|
48 |
self.file_ids = {} |
|
49 |
||
50 |
# Head tracking: last ref, last id per ref & map of commit ids to ref*s*
|
|
51 |
self.last_ref = None |
|
52 |
self.last_ids = {} |
|
53 |
self.heads = {} |
|
54 |
||
55 |
# Work out the blobs to make sticky - None means all
|
|
56 |
self._blobs_to_keep = None |
|
57 |
if info is not None: |
|
58 |
try: |
|
59 |
self._blobs_to_keep = info['Blob usage tracking']['multi'] |
|
60 |
except KeyError: |
|
61 |
# info not in file - possible when no blobs used
|
|
62 |
pass
|
|
63 |
||
64 |
def store_blob(self, id, data): |
|
65 |
"""Store a blob of data.""" |
|
66 |
if (self._blobs_to_keep is None or data == '' or |
|
67 |
id in self._blobs_to_keep): |
|
68 |
self._sticky_blobs[id] = data |
|
69 |
else: |
|
70 |
self._blobs[id] = data |
|
71 |
||
72 |
def fetch_blob(self, id): |
|
73 |
"""Fetch a blob of data.""" |
|
74 |
try: |
|
75 |
return self._sticky_blobs[id] |
|
76 |
except KeyError: |
|
77 |
return self._blobs.pop(id) |
|
78 |
||
79 |
def delete_path(self, path): |
|
80 |
"""Remove a path from caches.""" |
|
81 |
# we actually want to remember what file-id we gave a path,
|
|
82 |
# even when that file is deleted, so doing nothing is correct
|
|
83 |
pass
|
|
84 |
||
85 |
def rename_path(self, old_path, new_path): |
|
86 |
"""Rename a path in the caches.""" |
|
87 |
# In this case, we need to forget the file-id we gave a path,
|
|
88 |
# otherwise, we'll get duplicate file-ids in the repository.
|
|
89 |
self.file_ids[new_path] = self.file_ids[old_path] |
|
90 |
del self.file_ids[old_path] |
|
91 |
||
92 |
def track_heads_for_ref(self, cmd_ref, cmd_id, parents=None): |
|
93 |
if parents is not None: |
|
94 |
for parent in parents: |
|
95 |
refs = self.heads.get(parent) |
|
96 |
if refs: |
|
97 |
refs.discard(cmd_ref) |
|
98 |
if not refs: |
|
99 |
del self.heads[parent] |
|
100 |
self.heads.setdefault(cmd_id, set()).add(cmd_ref) |
|
101 |
self.last_ids[cmd_ref] = cmd_id |
|
102 |
self.last_ref = cmd_ref |