~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/store.py

  • Committer: Martin Pool
  • Date: 2005-05-30 03:14:07 UTC
  • Revision ID: mbp@sourcefrog.net-20050530031407-d37f43ff76a5e0d9
- tests for add --no-recurse

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
    pass
35
35
 
36
36
 
37
 
class ImmutableStore:
 
37
class ImmutableStore(object):
38
38
    """Store that holds files indexed by unique names.
39
39
 
40
40
    Files can be added, but not modified once they are in.  Typically
57
57
    >>> st['123123'].read()
58
58
    'goodbye'
59
59
 
60
 
    :todo: Atomic add by writing to a temporary file and renaming.
 
60
    TODO: Atomic add by writing to a temporary file and renaming.
61
61
 
62
 
    :todo: Perhaps automatically transform to/from XML in a method?
 
62
    TODO: Perhaps automatically transform to/from XML in a method?
63
63
           Would just need to tell the constructor what class to
64
64
           use...
65
65
 
66
 
    :todo: Even within a simple disk store like this, we could
 
66
    TODO: Even within a simple disk store like this, we could
67
67
           gzip the files.  But since many are less than one disk
68
68
           block, that might not help a lot.
69
69
 
74
74
        self._basedir = basedir
75
75
 
76
76
    def _path(self, id):
 
77
        assert '/' not in id
77
78
        return os.path.join(self._basedir, id)
78
79
 
79
80
    def __repr__(self):
82
83
    def add(self, f, fileid, compressed=True):
83
84
        """Add contents of a file into the store.
84
85
 
85
 
        :param f: An open file, or file-like object."""
 
86
        f -- An open file, or file-like object."""
86
87
        # FIXME: Only works on smallish files
87
88
        # TODO: Can be optimized by copying at the same time as
88
89
        # computing the sum.