Merge lp:~maxb/bzr-svn/cache-interface-tidying into lp:bzr-svn/1.1
- cache-interface-tidying
- Merge into 1.1
Proposed by
Max Bowsher
Status: | Merged |
---|---|
Merged at revision: | 3515 |
Proposed branch: | lp:~maxb/bzr-svn/cache-interface-tidying |
Merge into: | lp:bzr-svn/1.1 |
Diff against target: |
810 lines (+155/-200) 8 files modified
cache/sqlitecache.py (+47/-71) cache/tdbcache.py (+47/-72) logwalker.py (+6/-1) revids.py (+0/-36) revmeta.py (+35/-0) tests/test_cache.py (+16/-16) tests/test_logwalker.py (+2/-2) tests/test_parents.py (+2/-2) |
To merge this branch: | bzr merge lp:~maxb/bzr-svn/cache-interface-tidying |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jelmer Vernooij (community) | code | Needs Fixing | |
Review via email: mp+47187@code.launchpad.net |
Commit message
Description of the change
No user visible changes - just making the cache interface code more discoverable to coders, and eliminating duplicate documentation which is a pain to maintain.
To post a comment you must log in.
Revision history for this message
Max Bowsher (maxb) wrote : | # |
I've pushed revno 3514 to correct this and revno 3515 with an addition of an extra comment.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'cache/sqlitecache.py' |
2 | --- cache/sqlitecache.py 2011-01-16 15:53:18 +0000 |
3 | +++ cache/sqlitecache.py 2011-02-01 09:52:50 +0000 |
4 | @@ -33,6 +33,18 @@ |
5 | from bzrlib.plugins.svn.mapping import ( |
6 | mapping_registry, |
7 | ) |
8 | +from bzrlib.plugins.svn.revids import ( |
9 | + RevisionIdMapCache, |
10 | + ) |
11 | +from bzrlib.plugins.svn.revmeta import ( |
12 | + RevisionInfoCache, |
13 | + ) |
14 | +from bzrlib.plugins.svn.logwalker import ( |
15 | + LogCache, |
16 | + ) |
17 | +from bzrlib.plugins.svn.parents import ( |
18 | + ParentsCache, |
19 | + ) |
20 | |
21 | from subvertpy import NODE_UNKNOWN |
22 | |
23 | @@ -101,11 +113,7 @@ |
24 | CACHE_DB_VERSION = 5 |
25 | |
26 | |
27 | -class RevisionIdMapCache(CacheTable): |
28 | - """Revision id mapping store. |
29 | - |
30 | - Stores mapping from revid -> (path, revnum, mapping) |
31 | - """ |
32 | +class SqliteRevisionIdMapCache(RevisionIdMapCache, CacheTable): |
33 | |
34 | def _create_table(self): |
35 | self.cachedb.executescript(""" |
36 | @@ -130,23 +138,15 @@ |
37 | self._commit_interval = 500 |
38 | |
39 | def set_last_revnum_checked(self, layout, revnum): |
40 | - """Remember the latest revision number that has been checked |
41 | - for a particular layout. |
42 | + """See RevisionIdMapCache.set_last_revnum_checked.""" |
43 | |
44 | - :param layout: Repository layout. |
45 | - :param revnum: Revision number. |
46 | - """ |
47 | self.mutter("set last revnum checked for %r to %r", layout, revnum) |
48 | self.cachedb.execute("replace into revids_seen (layout, max_revnum) VALUES (?, ?)", (layout, revnum)) |
49 | self.commit() |
50 | |
51 | def last_revnum_checked(self, layout): |
52 | - """Retrieve the latest revision number that has been checked |
53 | - for revision ids for a particular layout. |
54 | + """See RevisionIdMapCache.last_revnum_checked.""" |
55 | |
56 | - :param layout: Repository layout. |
57 | - :return: Last revision number checked or 0. |
58 | - """ |
59 | ret = self.cachedb.execute( |
60 | "select max_revnum from revids_seen where layout = ?", (layout,)).fetchone() |
61 | if ret is None: |
62 | @@ -157,12 +157,8 @@ |
63 | return revnum |
64 | |
65 | def lookup_revid(self, revid): |
66 | - """Lookup the details for a particular revision id. |
67 | + """See RevisionIdMapCache.lookup_revid.""" |
68 | |
69 | - :param revid: Revision id. |
70 | - :return: Tuple with path inside repository, minimum revision number, maximum revision number and |
71 | - mapping. |
72 | - """ |
73 | assert isinstance(revid, str) |
74 | self.mutter("lookup revid %r", revid) |
75 | ret = self.cachedb.execute( |
76 | @@ -176,12 +172,8 @@ |
77 | return (path, min_revnum, max_revnum, mapping) |
78 | |
79 | def lookup_branch_revnum(self, revnum, path, mapping): |
80 | - """Lookup a revision by revision number, branch path and mapping. |
81 | + """See RevisionIdMapCache.lookup_branch_revnum.""" |
82 | |
83 | - :param revnum: Subversion revision number. |
84 | - :param path: Subversion branch path. |
85 | - :param mapping: Mapping |
86 | - """ |
87 | assert isinstance(revnum, int) |
88 | assert isinstance(path, str) |
89 | assert isinstance(mapping, str) |
90 | @@ -195,17 +187,8 @@ |
91 | return ret |
92 | |
93 | def insert_revid(self, revid, branch, min_revnum, max_revnum, mapping): |
94 | - """Insert a revision id into the revision id cache. |
95 | + """See RevisionIdMapCache.insert_revid.""" |
96 | |
97 | - :param revid: Revision id for which to insert metadata. |
98 | - :param branch: Branch path at which the revision was seen |
99 | - :param min_revnum: Minimum Subversion revision number in which the |
100 | - revid was found |
101 | - :param max_revnum: Maximum Subversion revision number in which the |
102 | - revid was found |
103 | - :param mapping: Name of the mapping with which the revision |
104 | - was found |
105 | - """ |
106 | assert revid is not None and revid != "" |
107 | assert isinstance(mapping, str) |
108 | assert isinstance(branch, str) |
109 | @@ -227,7 +210,7 @@ |
110 | self._commit_conditionally() |
111 | |
112 | |
113 | -class RevisionInfoCache(CacheTable): |
114 | +class SqliteRevisionInfoCache(RevisionInfoCache, CacheTable): |
115 | |
116 | def _create_table(self): |
117 | self.cachedb.executescript(""" |
118 | @@ -252,6 +235,8 @@ |
119 | self._commit_interval = 500 |
120 | |
121 | def set_original_mapping(self, foreign_revid, original_mapping): |
122 | + """See RevisionInfoCache.set_original_mapping.""" |
123 | + |
124 | if original_mapping is not None: |
125 | orig_mapping_name = original_mapping.name |
126 | else: |
127 | @@ -260,24 +245,14 @@ |
128 | |
129 | def insert_revision(self, foreign_revid, mapping, (revno, revid, hidden), |
130 | stored_lhs_parent_revid): |
131 | - """Insert a revision to the cache. |
132 | + """See RevisionInfoCache.insert_revision.""" |
133 | |
134 | - :param foreign_revid: Foreign revision id |
135 | - :param mapping: Mapping used |
136 | - :param info: Tuple with (revno, revid, hidden) |
137 | - :param stored_lhs_parent_revid: Stored lhs parent revision |
138 | - """ |
139 | self.cachedb.execute("insert into revmetainfo (path, revnum, mapping, revid, revno, hidden, stored_lhs_parent_revid) values (?, ?, ?, ?, ?, ?, ?)", (foreign_revid[1], foreign_revid[2], mapping.name, revid, revno, hidden, stored_lhs_parent_revid)) |
140 | self._commit_conditionally() |
141 | |
142 | def get_revision(self, foreign_revid, mapping): |
143 | - """Get the revision metadata info for a (foreign_revid, mapping) tuple. |
144 | + """See RevisionInfoCache.get_revision.""" |
145 | |
146 | - :param foreign_revid: Foreign revision id |
147 | - :param mapping: Mapping |
148 | - :return: Tuple with (stored revno, revid, hidden), |
149 | - stored_lhs_parent_revid |
150 | - """ |
151 | # Will raise KeyError if not present |
152 | row = self.cachedb.execute("select revno, revid, hidden, stored_lhs_parent_revid from revmetainfo where path = ? and revnum = ? and mapping = ?", (foreign_revid[1], foreign_revid[2], mapping.name)).fetchone() |
153 | if row is None: |
154 | @@ -294,11 +269,8 @@ |
155 | return ((row[0], stored_revid, row[2]), stored_lhs_parent_revid) |
156 | |
157 | def get_original_mapping(self, foreign_revid): |
158 | - """Find the original mapping for a revision. |
159 | + """See RevisionInfoCache.get_original_mapping.""" |
160 | |
161 | - :param foreign_revid: Foreign revision id |
162 | - :return: Mapping object or None |
163 | - """ |
164 | row = self.cachedb.execute("select original_mapping from original_mapping where path = ? and revnum = ?", (foreign_revid[1].decode("utf-8"), foreign_revid[2])).fetchone() |
165 | if row is None: |
166 | raise KeyError(foreign_revid) |
167 | @@ -308,10 +280,7 @@ |
168 | return mapping_registry.parse_mapping_name("svn-" + row[0].encode("utf-8")) |
169 | |
170 | |
171 | -class LogCache(CacheTable): |
172 | - """Log browser cache table manager. The methods of this class |
173 | - encapsulate the SQL commands used by CachingLogWalker to access |
174 | - the log cache tables.""" |
175 | +class SqliteLogCache(LogCache, CacheTable): |
176 | |
177 | def _create_table(self): |
178 | self.cachedb.executescript(""" |
179 | @@ -343,6 +312,8 @@ |
180 | pass # Column already exists. |
181 | |
182 | def find_latest_change(self, path, revnum): |
183 | + """See LogCache.find_latest_change.""" |
184 | + |
185 | if path == "": |
186 | return self.cachedb.execute("select max(rev) from changed_path where rev <= ?", (revnum,)).fetchone()[0] |
187 | return self.cachedb.execute(""" |
188 | @@ -355,10 +326,8 @@ |
189 | """, (revnum, path, path + "/*", path)).fetchone()[0] |
190 | |
191 | def get_revision_paths(self, revnum): |
192 | - """Return all history information for a given revision number. |
193 | + """See LogCache.get_revision_paths.""" |
194 | |
195 | - :param revnum: Revision number of revision. |
196 | - """ |
197 | result = self.cachedb.execute("select path, action, copyfrom_path, copyfrom_rev, kind from changed_path where rev=?", (revnum,)) |
198 | paths = {} |
199 | for p, act, cf, cr, kind in result: |
200 | @@ -368,11 +337,8 @@ |
201 | return paths |
202 | |
203 | def insert_paths(self, rev, orig_paths): |
204 | - """Insert new history information into the cache. |
205 | + """See LogCache.insert_paths.""" |
206 | |
207 | - :param rev: Revision number of the revision |
208 | - :param orig_paths: SVN-style changes dictionary |
209 | - """ |
210 | if orig_paths is None or orig_paths == {}: |
211 | return |
212 | new_paths = [] |
213 | @@ -390,13 +356,13 @@ |
214 | self.cachedb.executemany("replace into changed_path (rev, path, action, copyfrom_path, copyfrom_rev, kind) values (?, ?, ?, ?, ?, ?)", new_paths) |
215 | |
216 | def drop_revprops(self, revnum): |
217 | + """See LogCache.drop_revprops.""" |
218 | + |
219 | self.cachedb.execute("update revinfo set all_revprops = 0 where rev = ?", (revnum,)) |
220 | |
221 | def get_revprops(self, revnum): |
222 | - """Retrieve all the cached revision properties. |
223 | + """See LogCache.get_revprops.""" |
224 | |
225 | - :param revnum: Revision number of revision to retrieve revprops for. |
226 | - """ |
227 | result = self.cachedb.execute("select name, value from revprop where rev = ?", (revnum,)) |
228 | revprops = dict((k.encode("utf-8"), v.encode("utf-8")) for (k, v) in result) |
229 | result = self.cachedb.execute("select all_revprops from revinfo where rev = ?", (revnum,)).fetchone() |
230 | @@ -407,6 +373,8 @@ |
231 | return (revprops, all_revprops) |
232 | |
233 | def insert_revprops(self, revision, revprops, all_revprops): |
234 | + """See LogCache.insert_revprops.""" |
235 | + |
236 | if revprops is None: |
237 | return |
238 | self.cachedb.executemany("replace into revprop (rev, name, value) values (?, ?, ?)", [(revision, name.decode("utf-8", "replace"), value.decode("utf-8", "replace")) for (name, value) in revprops.iteritems()]) |
239 | @@ -415,16 +383,20 @@ |
240 | """, (revision, all_revprops)) |
241 | |
242 | def last_revnum(self): |
243 | + """See LogCache.last_revnum.""" |
244 | + |
245 | saved_revnum = self.cachedb.execute("SELECT MAX(rev) FROM changed_path").fetchone()[0] |
246 | if saved_revnum is None: |
247 | return 0 |
248 | return saved_revnum |
249 | |
250 | def min_revnum(self): |
251 | + """See LogCache.min_revnum.""" |
252 | + |
253 | return self.cachedb.execute("SELECT MIN(rev) FROM revprop").fetchone()[0] |
254 | |
255 | |
256 | -class ParentsCache(CacheTable): |
257 | +class SqliteParentsCache(ParentsCache, CacheTable): |
258 | |
259 | def _create_table(self): |
260 | self.cachedb.executescript(""" |
261 | @@ -439,6 +411,8 @@ |
262 | self._commit_interval = 200 |
263 | |
264 | def insert_parents(self, revid, parents): |
265 | + """See ParentsCache.insert_parents.""" |
266 | + |
267 | self.mutter('insert parents: %r -> %r', revid, parents) |
268 | if len(parents) == 0: |
269 | self.cachedb.execute("replace into parent (rev, parent, idx) values (?, NULL, -1)", (revid,)) |
270 | @@ -448,6 +422,8 @@ |
271 | self._commit_conditionally() |
272 | |
273 | def lookup_parents(self, revid): |
274 | + """See ParentsCache.lookup_parents.""" |
275 | + |
276 | self.mutter('lookup parents: %r', revid) |
277 | rows = self.cachedb.execute("select parent from parent where rev = ? order by idx", (revid, )).fetchall() |
278 | if len(rows) == 0: |
279 | @@ -466,16 +442,16 @@ |
280 | return cachedbs()[cache_file] |
281 | |
282 | def open_revid_map(self): |
283 | - return RevisionIdMapCache(self.open_sqlite()) |
284 | + return SqliteRevisionIdMapCache(self.open_sqlite()) |
285 | |
286 | def open_logwalker(self): |
287 | - return LogCache(self.open_sqlite()) |
288 | + return SqliteLogCache(self.open_sqlite()) |
289 | |
290 | def open_revision_cache(self): |
291 | - return RevisionInfoCache(self.open_sqlite()) |
292 | + return SqliteRevisionInfoCache(self.open_sqlite()) |
293 | |
294 | def open_parents(self): |
295 | - return ParentsCache(self.open_sqlite()) |
296 | + return SqliteParentsCache(self.open_sqlite()) |
297 | |
298 | def commit(self): |
299 | self.open_sqlite().commit() |
300 | |
301 | === modified file 'cache/tdbcache.py' |
302 | --- cache/tdbcache.py 2011-01-18 18:33:05 +0000 |
303 | +++ cache/tdbcache.py 2011-02-01 09:52:50 +0000 |
304 | @@ -38,6 +38,18 @@ |
305 | from bzrlib.plugins.svn.mapping import ( |
306 | mapping_registry, |
307 | ) |
308 | +from bzrlib.plugins.svn.revids import ( |
309 | + RevisionIdMapCache, |
310 | + ) |
311 | +from bzrlib.plugins.svn.revmeta import ( |
312 | + RevisionInfoCache, |
313 | + ) |
314 | +from bzrlib.plugins.svn.logwalker import ( |
315 | + LogCache, |
316 | + ) |
317 | +from bzrlib.plugins.svn.parents import ( |
318 | + ParentsCache, |
319 | + ) |
320 | |
321 | from subvertpy import NODE_UNKNOWN |
322 | |
323 | @@ -60,40 +72,24 @@ |
324 | trace.mutter(text, *args, **kwargs) |
325 | |
326 | |
327 | -class RevisionIdMapCache(CacheTable): |
328 | - """Revision id mapping store. |
329 | - |
330 | - Stores mapping from revid -> (path, revnum, mapping) |
331 | - """ |
332 | +class TdbRevisionIdMapCache(RevisionIdMapCache, CacheTable): |
333 | |
334 | def set_last_revnum_checked(self, layout, revnum): |
335 | - """Remember the latest revision number that has been checked |
336 | - for a particular layout. |
337 | + """See RevisionIdMapCache.set_last_revnum_checked.""" |
338 | |
339 | - :param layout: Repository layout. |
340 | - :param revnum: Revision number. |
341 | - """ |
342 | self.db["revidmap-last/%s" % str(layout)] = str(revnum) |
343 | |
344 | def last_revnum_checked(self, layout): |
345 | - """Retrieve the latest revision number that has been checked |
346 | - for revision ids for a particular layout. |
347 | + """See RevisionIdMapCache.last_revnum_checked.""" |
348 | |
349 | - :param layout: Repository layout. |
350 | - :return: Last revision number checked or 0. |
351 | - """ |
352 | try: |
353 | return int(self.db["revidmap-last/%s" % str(layout)]) |
354 | except KeyError: |
355 | return 0 |
356 | |
357 | def lookup_revid(self, revid): |
358 | - """Lookup the details for a particular revision id. |
359 | + """See RevisionIdMapCache.lookup_revid.""" |
360 | |
361 | - :param revid: Revision id. |
362 | - :return: Tuple with path inside repository, minimum revision number, |
363 | - maximum revision number and mapping. |
364 | - """ |
365 | self.mutter('lookup-revid %s', revid) |
366 | try: |
367 | (min_revnum, max_revnum, mapping_name, path) = self.db["native-revid/" + revid].split(" ", 3) |
368 | @@ -102,12 +98,8 @@ |
369 | return (path, int(min_revnum), int(max_revnum), mapping_name) |
370 | |
371 | def lookup_branch_revnum(self, revnum, path, mapping): |
372 | - """Lookup a revision by revision number, branch path and mapping. |
373 | + """See RevisionIdMapCache.lookup_branch_revnum.""" |
374 | |
375 | - :param revnum: Subversion revision number. |
376 | - :param path: Subversion branch path. |
377 | - :param mapping: Mapping |
378 | - """ |
379 | self.mutter('lookup-branch-revnum %s:%d', path, revnum) |
380 | try: |
381 | return self.db["foreign-revid/%d %s %s" % (revnum, getattr(mapping, "name", mapping), path)] |
382 | @@ -115,25 +107,19 @@ |
383 | return None |
384 | |
385 | def insert_revid(self, revid, branch, min_revnum, max_revnum, mapping): |
386 | - """Insert a revision id into the revision id cache. |
387 | + """See RevisionIdMapCache.insert_revid.""" |
388 | |
389 | - :param revid: Revision id for which to insert metadata. |
390 | - :param branch: Branch path at which the revision was seen |
391 | - :param min_revnum: Minimum Subversion revision number in which the |
392 | - revid was found |
393 | - :param max_revnum: Maximum Subversion revision number in which the |
394 | - revid was found |
395 | - :param mapping: Name of the mapping with which the revision was found |
396 | - """ |
397 | mappingname = getattr(mapping, "name", mapping) |
398 | self.db["native-revid/" + revid] = "%d %d %s %s" % (min_revnum, max_revnum, mappingname, branch) |
399 | if min_revnum == max_revnum: |
400 | self.db["foreign-revid/%d %s %s" % (min_revnum, mappingname, branch)] = revid |
401 | |
402 | |
403 | -class RevisionInfoCache(CacheTable): |
404 | +class TdbRevisionInfoCache(RevisionInfoCache, CacheTable): |
405 | |
406 | def set_original_mapping(self, foreign_revid, original_mapping): |
407 | + """See RevisionInfoCache.set_original_mapping.""" |
408 | + |
409 | if original_mapping is not None: |
410 | orig_mapping_name = original_mapping.name |
411 | else: |
412 | @@ -142,16 +128,8 @@ |
413 | |
414 | def insert_revision(self, foreign_revid, mapping, (revno, revid, hidden), |
415 | stored_lhs_parent_revid): |
416 | - """Insert a revision to the cache. |
417 | + """See RevisionInfoCache.insert_revision.""" |
418 | |
419 | - :param foreign_revid: Foreign revision id |
420 | - :param mapping: Mapping used |
421 | - :param revid: Revision id |
422 | - :param revno: Revision number |
423 | - :param hidden: Whether revision is hidden |
424 | - :param original_mapping: Original mapping used |
425 | - :param stored_lhs_parent_revid: Stored lhs parent revision |
426 | - """ |
427 | if revid is None: |
428 | revid = mapping.revision_id_foreign_to_bzr(foreign_revid) |
429 | self.db["foreign-revid/%d %d %s %s" % (foreign_revid[2], foreign_revid[2], mapping.name, foreign_revid[1])] = revid |
430 | @@ -165,12 +143,8 @@ |
431 | self.db["lhs-parent-revid/%s" % basekey] = stored_lhs_parent_revid |
432 | |
433 | def get_revision(self, foreign_revid, mapping): |
434 | - """Get the revision metadata info for a (foreign_revid, mapping) tuple. |
435 | + """See RevisionInfoCache.get_revision.""" |
436 | |
437 | - :param foreign_revid: Foreign revision id |
438 | - :param mapping: Mapping |
439 | - :return: Tuple with (stored revno, revid, hidden), stored_lhs_parent_revid |
440 | - """ |
441 | self.mutter("get-revision %r,%r", foreign_revid, mapping) |
442 | basekey = "%d %s %s" % (foreign_revid[2], mapping.name, foreign_revid[1]) |
443 | revid = self.db["foreign-revid/%d %d %s %s" % (foreign_revid[2], foreign_revid[2], mapping.name, foreign_revid[1])] |
444 | @@ -187,11 +161,8 @@ |
445 | return ((revno, revid, hidden), stored_lhs_parent_revid) |
446 | |
447 | def get_original_mapping(self, foreign_revid): |
448 | - """Find the original mapping for a revision. |
449 | + """See RevisionInfoCache.get_original_mapping.""" |
450 | |
451 | - :param foreign_revid: Foreign revision id |
452 | - :return: Mapping object or None |
453 | - """ |
454 | self.mutter("get-original-mapping %r", foreign_revid) |
455 | ret = self.db["original-mapping/%d %s" % (foreign_revid[2], foreign_revid[1])] |
456 | if ret == "": |
457 | @@ -199,19 +170,16 @@ |
458 | return mapping_registry.parse_mapping_name("svn-" + ret) |
459 | |
460 | |
461 | -class LogCache(CacheTable): |
462 | - """Log browser cache table manager. The methods of this class |
463 | - encapsulate the SQL commands used by CachingLogWalker to access |
464 | - the log cache tables.""" |
465 | +class TdbLogCache(LogCache, CacheTable): |
466 | |
467 | def find_latest_change(self, path, revnum): |
468 | + """See LogCache.find_latest_change.""" |
469 | + |
470 | raise NotImplementedError(self.find_latest_change) |
471 | |
472 | def get_revision_paths(self, revnum): |
473 | - """Return all history information for a given revision number. |
474 | + """See LogCache.get_revision_paths.""" |
475 | |
476 | - :param revnum: Revision number of revision. |
477 | - """ |
478 | self.mutter("get-revision-paths %d", revnum) |
479 | ret = {} |
480 | db = bencode.bdecode(self.db["paths/%d" % revnum]) |
481 | @@ -227,11 +195,8 @@ |
482 | return ret |
483 | |
484 | def insert_paths(self, rev, orig_paths): |
485 | - """Insert new history information into the cache. |
486 | + """See LogCache.insert_paths.""" |
487 | |
488 | - :param rev: Revision number of the revision |
489 | - :param orig_paths: SVN-style changes dictionary |
490 | - """ |
491 | if orig_paths is None: |
492 | orig_paths = {} |
493 | new_paths = {} |
494 | @@ -252,18 +217,20 @@ |
495 | self.db["log-last"] = "%d" % max(self.last_revnum(), rev) |
496 | |
497 | def drop_revprops(self, revnum): |
498 | + """See LogCache.drop_revprops.""" |
499 | + |
500 | self.db["revprops/%d" % revnum] = bencode.bencode({}) |
501 | |
502 | def get_revprops(self, revnum): |
503 | - """Retrieve all the cached revision properties. |
504 | + """See LogCache.get_revprops.""" |
505 | |
506 | - :param revnum: Revision number of revision to retrieve revprops for. |
507 | - """ |
508 | self.mutter("get-revision-properties %d", revnum) |
509 | ret = bencode.bdecode(self.db["revprops/%d" % revnum]) |
510 | return (ret[0], bool(ret[1])) |
511 | |
512 | def insert_revprops(self, revision, revprops, all_revprops): |
513 | + """See LogCache.insert_revprops.""" |
514 | + |
515 | if revprops is None: |
516 | revprops = {} |
517 | self.db["revprops/%d" % revision] = bencode.bencode((revprops, all_revprops)) |
518 | @@ -275,23 +242,31 @@ |
519 | self.db["log-min"] = str(min_revnum) |
520 | |
521 | def last_revnum(self): |
522 | + """See LogCache.last_revnum.""" |
523 | + |
524 | try: |
525 | return int(self.db["log-last"]) |
526 | except KeyError: |
527 | return 0 |
528 | |
529 | def min_revnum(self): |
530 | + """See LogCache.min_revnum.""" |
531 | + |
532 | try: |
533 | return int(self.db["log-min"]) |
534 | except KeyError: |
535 | return None |
536 | |
537 | -class ParentsCache(CacheTable): |
538 | +class TdbParentsCache(ParentsCache, CacheTable): |
539 | |
540 | def insert_parents(self, revid, parents): |
541 | + """See ParentsCache.insert_parents.""" |
542 | + |
543 | self.db["parents/%s" % revid] = " ".join(parents) |
544 | |
545 | def lookup_parents(self, revid): |
546 | + """See ParentsCache.lookup_parents.""" |
547 | + |
548 | self.mutter("lookup-parents %s", revid) |
549 | try: |
550 | return tuple([p for p in self.db["parents/%s" % revid].split(" ") if p != ""]) |
551 | @@ -319,13 +294,13 @@ |
552 | return db |
553 | |
554 | def open_revid_map(self): |
555 | - return RevisionIdMapCache(self.open_tdb()) |
556 | + return TdbRevisionIdMapCache(self.open_tdb()) |
557 | |
558 | def open_logwalker(self): |
559 | - return LogCache(self.open_tdb()) |
560 | + return TdbLogCache(self.open_tdb()) |
561 | |
562 | def open_revision_cache(self): |
563 | - return RevisionInfoCache(self.open_tdb()) |
564 | + return TdbRevisionInfoCache(self.open_tdb()) |
565 | |
566 | def open_parents(self): |
567 | - return ParentsCache(self.open_tdb()) |
568 | + return TdbParentsCache(self.open_tdb()) |
569 | |
570 | === modified file 'logwalker.py' |
571 | --- logwalker.py 2010-11-09 01:02:32 +0000 |
572 | +++ logwalker.py 2011-02-01 09:52:50 +0000 |
573 | @@ -141,12 +141,17 @@ |
574 | |
575 | |
576 | class LogCache(object): |
577 | - """Log browser cache. """ |
578 | + """Log browser cache manager. The methods of this class |
579 | + encapsulate the data access patterns used by CachingLogWalker to |
580 | + access the log cache.""" |
581 | |
582 | def find_latest_change(self, path, revnum): |
583 | """Find the last revision in which a particular path |
584 | was changed. |
585 | |
586 | + This is an optional operation: cache backends may choose not to |
587 | + implement it if they cannot efficiently perform this kind of lookup. |
588 | + |
589 | :param path: Path to check |
590 | :param revnum: Revision in which to check |
591 | """ |
592 | |
593 | === modified file 'revids.py' |
594 | --- revids.py 2010-08-10 02:36:24 +0000 |
595 | +++ revids.py 2011-02-01 09:52:50 +0000 |
596 | @@ -348,39 +348,3 @@ |
597 | was found |
598 | """ |
599 | raise NotImplementedError(self.insert_revid) |
600 | - |
601 | - |
602 | -class RevisionInfoCache(object): |
603 | - |
604 | - def set_original_mapping(self, foreign_revid, original_mapping): |
605 | - raise NotImplementedError(self.set_original_mapping) |
606 | - |
607 | - def insert_revision(self, foreign_revid, mapping, revinfo, |
608 | - stored_lhs_parent_revid): |
609 | - """Insert a revision to the cache. |
610 | - |
611 | - :param foreign_revid: Foreign revision id |
612 | - :param mapping: Mapping used |
613 | - :param revinfo: Tuple with (revno, revid, hidden) |
614 | - :param original_mapping: Original mapping used |
615 | - :param stored_lhs_parent_revid: Stored lhs parent revision |
616 | - """ |
617 | - raise NotImplementedError(self.insert_revision) |
618 | - |
619 | - def get_revision(self, foreign_revid, mapping): |
620 | - """Get the revision metadata info for a (foreign_revid, mapping) tuple. |
621 | - |
622 | - :param foreign_revid: Foreign reviasion id |
623 | - :param mapping: Mapping |
624 | - :return: Tuple with (stored revno, revid, hidden), original_mapping, |
625 | - stored_lhs_parent_revid |
626 | - """ |
627 | - raise NotImplementedError(self.get_revision) |
628 | - |
629 | - def get_original_mapping(self, foreign_revid): |
630 | - """Find the original mapping for a revision. |
631 | - |
632 | - :param foreign_revid: Foreign revision id |
633 | - :return: Mapping object or None |
634 | - """ |
635 | - raise NotImplementedError(self.get_original_mapping) |
636 | |
637 | === modified file 'revmeta.py' |
638 | --- revmeta.py 2011-01-18 18:33:05 +0000 |
639 | +++ revmeta.py 2011-02-01 09:52:50 +0000 |
640 | @@ -1435,3 +1435,38 @@ |
641 | for kind, item in browser: |
642 | if kind != "revision" or check_unusual_path(item.branch_path): |
643 | yield kind, item |
644 | + |
645 | + |
646 | +class RevisionInfoCache(object): |
647 | + |
648 | + def set_original_mapping(self, foreign_revid, original_mapping): |
649 | + raise NotImplementedError(self.set_original_mapping) |
650 | + |
651 | + def insert_revision(self, foreign_revid, mapping, revinfo, |
652 | + stored_lhs_parent_revid): |
653 | + """Insert a revision to the cache. |
654 | + |
655 | + :param foreign_revid: Foreign revision id |
656 | + :param mapping: Mapping used |
657 | + :param revinfo: Tuple with (revno, revid, hidden) |
658 | + :param stored_lhs_parent_revid: Stored lhs parent revision |
659 | + """ |
660 | + raise NotImplementedError(self.insert_revision) |
661 | + |
662 | + def get_revision(self, foreign_revid, mapping): |
663 | + """Get the revision metadata info for a (foreign_revid, mapping) tuple. |
664 | + |
665 | + :param foreign_revid: Foreign revision id |
666 | + :param mapping: Mapping |
667 | + :return: Tuple with (stored revno, revid, hidden), |
668 | + stored_lhs_parent_revid |
669 | + """ |
670 | + raise NotImplementedError(self.get_revision) |
671 | + |
672 | + def get_original_mapping(self, foreign_revid): |
673 | + """Find the original mapping for a revision. |
674 | + |
675 | + :param foreign_revid: Foreign revision id |
676 | + :return: Mapping object or None |
677 | + """ |
678 | + raise NotImplementedError(self.get_original_mapping) |
679 | |
680 | === modified file 'tests/test_cache.py' |
681 | --- tests/test_cache.py 2010-10-06 15:16:50 +0000 |
682 | +++ tests/test_cache.py 2011-02-01 09:52:50 +0000 |
683 | @@ -69,8 +69,8 @@ |
684 | |
685 | def setUp(self): |
686 | super(SqliteLogCacheTests, self).setUp() |
687 | - from bzrlib.plugins.svn.cache.sqlitecache import LogCache |
688 | - self.cache = LogCache() |
689 | + from bzrlib.plugins.svn.cache.sqlitecache import SqliteLogCache |
690 | + self.cache = SqliteLogCache() |
691 | |
692 | |
693 | class TdbLogCacheTests(TestCaseInTempDir,LogCacheTests): |
694 | @@ -78,11 +78,11 @@ |
695 | def setUp(self): |
696 | super(TdbLogCacheTests, self).setUp() |
697 | try: |
698 | - from bzrlib.plugins.svn.cache.tdbcache import LogCache, tdb_open |
699 | + from bzrlib.plugins.svn.cache.tdbcache import TdbLogCache, tdb_open |
700 | except ImportError: |
701 | raise UnavailableFeature("tdb") |
702 | import tdb |
703 | - self.cache = LogCache(tdb_open("cache.tdb", 0, tdb.DEFAULT, os.O_RDWR|os.O_CREAT)) |
704 | + self.cache = TdbLogCache(tdb_open("cache.tdb", 0, tdb.DEFAULT, os.O_RDWR|os.O_CREAT)) |
705 | |
706 | |
707 | class RevidMapCacheTests(object): |
708 | @@ -124,8 +124,8 @@ |
709 | |
710 | def setUp(self): |
711 | super(SqliteRevidMapCacheTests, self).setUp() |
712 | - from bzrlib.plugins.svn.cache.sqlitecache import RevisionIdMapCache |
713 | - self.cache = RevisionIdMapCache() |
714 | + from bzrlib.plugins.svn.cache.sqlitecache import SqliteRevisionIdMapCache |
715 | + self.cache = SqliteRevisionIdMapCache() |
716 | |
717 | |
718 | class TdbRevidMapCacheTests(TestCaseInTempDir,RevidMapCacheTests): |
719 | @@ -133,11 +133,11 @@ |
720 | def setUp(self): |
721 | super(TdbRevidMapCacheTests, self).setUp() |
722 | try: |
723 | - from bzrlib.plugins.svn.cache.tdbcache import RevisionIdMapCache, tdb_open |
724 | + from bzrlib.plugins.svn.cache.tdbcache import TdbRevisionIdMapCache, tdb_open |
725 | except ImportError: |
726 | raise UnavailableFeature("tdb") |
727 | import tdb |
728 | - self.cache = RevisionIdMapCache(tdb_open("cache.tdb", 0, tdb.DEFAULT, os.O_RDWR|os.O_CREAT)) |
729 | + self.cache = TdbRevisionIdMapCache(tdb_open("cache.tdb", 0, tdb.DEFAULT, os.O_RDWR|os.O_CREAT)) |
730 | |
731 | |
732 | class RevInfoCacheTests(object): |
733 | @@ -185,8 +185,8 @@ |
734 | |
735 | def setUp(self): |
736 | super(SqliteRevInfoCacheTests, self).setUp() |
737 | - from bzrlib.plugins.svn.cache.sqlitecache import RevisionInfoCache |
738 | - self.cache = RevisionInfoCache() |
739 | + from bzrlib.plugins.svn.cache.sqlitecache import SqliteRevisionInfoCache |
740 | + self.cache = SqliteRevisionInfoCache() |
741 | |
742 | |
743 | class TdbRevInfoCacheTests(TestCaseInTempDir,RevInfoCacheTests): |
744 | @@ -194,11 +194,11 @@ |
745 | def setUp(self): |
746 | super(TdbRevInfoCacheTests, self).setUp() |
747 | try: |
748 | - from bzrlib.plugins.svn.cache.tdbcache import RevisionInfoCache, tdb_open |
749 | + from bzrlib.plugins.svn.cache.tdbcache import TdbRevisionInfoCache, tdb_open |
750 | except ImportError: |
751 | raise UnavailableFeature("tdb") |
752 | import tdb |
753 | - self.cache = RevisionInfoCache(tdb_open("cache.tdb", 0, tdb.DEFAULT, os.O_RDWR|os.O_CREAT)) |
754 | + self.cache = TdbRevisionInfoCache(tdb_open("cache.tdb", 0, tdb.DEFAULT, os.O_RDWR|os.O_CREAT)) |
755 | |
756 | |
757 | class ParentsCacheTests: |
758 | @@ -228,8 +228,8 @@ |
759 | |
760 | def setUp(self): |
761 | super(SqliteParentsCacheTests, self).setUp() |
762 | - from bzrlib.plugins.svn.cache.sqlitecache import ParentsCache |
763 | - self.cache = ParentsCache() |
764 | + from bzrlib.plugins.svn.cache.sqlitecache import SqliteParentsCache |
765 | + self.cache = SqliteParentsCache() |
766 | |
767 | |
768 | class TdbParentsCacheTests(TestCaseInTempDir,ParentsCacheTests): |
769 | @@ -237,8 +237,8 @@ |
770 | def setUp(self): |
771 | super(TdbParentsCacheTests, self).setUp() |
772 | try: |
773 | - from bzrlib.plugins.svn.cache.tdbcache import ParentsCache, tdb_open |
774 | + from bzrlib.plugins.svn.cache.tdbcache import TdbParentsCache, tdb_open |
775 | except ImportError: |
776 | raise UnavailableFeature("tdb") |
777 | import tdb |
778 | - self.cache = ParentsCache(tdb_open("cache.tdb", 0, tdb.DEFAULT, os.O_RDWR|os.O_CREAT)) |
779 | + self.cache = TdbParentsCache(tdb_open("cache.tdb", 0, tdb.DEFAULT, os.O_RDWR|os.O_CREAT)) |
780 | |
781 | === modified file 'tests/test_logwalker.py' |
782 | --- tests/test_logwalker.py 2010-08-08 13:35:10 +0000 |
783 | +++ tests/test_logwalker.py 2011-02-01 09:52:50 +0000 |
784 | @@ -588,8 +588,8 @@ |
785 | logwalker.cache_dir = os.path.join(self.test_dir, "cache-dir") |
786 | |
787 | def get_log_walker(self, transport): |
788 | - from bzrlib.plugins.svn.cache.sqlitecache import LogCache |
789 | - return logwalker.CachingLogWalker(super(TestCachingLogWalker, self).get_log_walker(transport), LogCache()) |
790 | + from bzrlib.plugins.svn.cache.sqlitecache import SqliteLogCache |
791 | + return logwalker.CachingLogWalker(super(TestCachingLogWalker, self).get_log_walker(transport), SqliteLogCache()) |
792 | |
793 | |
794 | |
795 | |
796 | === modified file 'tests/test_parents.py' |
797 | --- tests/test_parents.py 2010-07-26 21:59:02 +0000 |
798 | +++ tests/test_parents.py 2011-02-01 09:52:50 +0000 |
799 | @@ -33,9 +33,9 @@ |
800 | TestCase.setUp(self) |
801 | dict_pp = _mod_graph.DictParentsProvider({'a':('b',)}) |
802 | self.inst_pp = InstrumentedParentsProvider(dict_pp) |
803 | - from bzrlib.plugins.svn.cache.sqlitecache import ParentsCache |
804 | + from bzrlib.plugins.svn.cache.sqlitecache import SqliteParentsCache |
805 | self.caching_pp = DiskCachingParentsProvider(self.inst_pp, |
806 | - ParentsCache()) |
807 | + SqliteParentsCache()) |
808 | |
809 | def test_get_parent_map(self): |
810 | """Requesting the same revision should be returned from cache""" |
Thanks for cleaning up this code.
Can you please add a comment that indicates where the base of a method is - e.g. "See RevisionInfoCac he.insert_ revision. " instead of outright removing the docstring? Otherwise it becomes hard(er) to actually find the relevant docs.