~jelmer/bzr-git/index-based

« back to all changes in this revision

Viewing changes to shamap.py

  • Committer: Jelmer Vernooij
  • Date: 2010-06-23 21:27:09 UTC
  • Revision ID: jelmer@samba.org-20100623212709-9vyjx3pctzlyuqbq
Add some docstrings.

Show diffs side-by-side

added added

removed removed

Lines of Context:
150
150
 
151
151
 
152
152
class BzrGitCacheFormat(object):
 
153
    """Bazaar-Git Cache Format."""
153
154
 
154
155
    def get_format_string(self):
155
156
        """Return a single-line unique format string for this cache format."""
160
161
        raise NotImplementedError(self.open)
161
162
 
162
163
    def initialize(self, transport):
 
164
        """Create a new instance of this cache format at transport."""
163
165
        transport.put_bytes('format', self.get_format_string())
164
166
 
165
167
    @classmethod
204
206
 
205
207
 
206
208
class CacheUpdater(object):
 
209
    """Base class for objects that can update a bzr-git cache."""
207
210
 
208
211
    def add_object(self, obj, ie):
209
212
        raise NotImplementedError(self.add_object)
221
224
        self._cache_updater_klass = cache_updater_klass
222
225
 
223
226
    def get_updater(self, rev):
 
227
        """Update an object that implements the CacheUpdater interface for 
 
228
        updating this cache.
 
229
        """
224
230
        return self._cache_updater_klass(self, rev)
225
231
 
226
232
 
228
234
 
229
235
 
230
236
class DictCacheUpdater(CacheUpdater):
 
237
    """Cache updater for dict-based caches."""
231
238
 
232
239
    def __init__(self, cache, rev):
233
240
        self.cache = cache
262
269
 
263
270
 
264
271
class DictGitShaMap(GitShaMap):
 
272
    """Git SHA map that uses a dictionary."""
265
273
 
266
274
    def __init__(self):
267
275
        self._by_sha = {}
344
352
 
345
353
 
346
354
class SqliteGitShaMap(GitShaMap):
 
355
    """Bazaar GIT Sha map that uses a sqlite database for storage."""
347
356
 
348
357
    def __init__(self, path=None):
349
358
        self.path = path
382
391
        return "%s(%r)" % (self.__class__.__name__, self.path)
383
392
    
384
393
    def lookup_commit(self, revid):
385
 
        row = self.db.execute("select sha1 from commits where revid = ?", (revid,)).fetchone()
 
394
        cursor = self.db.execute("select sha1 from commits where revid = ?", 
 
395
            (revid,))
 
396
        row = cursor.fetchone()
386
397
        if row is not None:
387
398
            return row[0]
388
399
        raise KeyError
432
443
 
433
444
 
434
445
class TdbCacheUpdater(CacheUpdater):
 
446
    """Cache updater for tdb-based caches."""
435
447
 
436
448
    def __init__(self, cache, rev):
437
449
        self.cache = cache
470
482
TdbBzrGitCache = lambda p: BzrGitCache(TdbGitShaMap(p), None, TdbCacheUpdater)
471
483
 
472
484
class TdbGitCacheFormat(BzrGitCacheFormat):
 
485
    """Cache format for tdb-based caches."""
473
486
 
474
487
    def get_format_string(self):
475
488
        return 'bzr-git sha map version 3 using tdb\n'