~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/store/compressed_text.py

  • Committer: Robert Collins
  • Date: 2005-10-16 02:52:53 UTC
  • mto: This revision was merged to the branch mainline in revision 1459.
  • Revision ID: robertc@lifelesslap.robertcollins.net-20051016025253-bee0d4e8715606d4
pull up core TransportStore.add from TextStore.add and CompressedTextStore.add

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
    def _relpath(self, fileid):
61
61
        return super(CompressedTextStore, self)._relpath(fileid, ['gz'])
62
62
 
63
 
    def add(self, f, fileid):
64
 
        """Add contents of a file into the store.
65
 
 
66
 
        f -- An open file, or file-like object."""
67
 
        # TODO: implement an add_multi which can do some of it's
68
 
        #       own piplelining, and possible take advantage of
69
 
        #       transport.put_multi(). The problem is that
70
 
        #       entries potentially need to be compressed as they
71
 
        #       are received, which implies translation, which
72
 
        #       means it isn't as straightforward as we would like.
 
63
    def _add(self, fn, f):
73
64
        from cStringIO import StringIO
74
65
        from bzrlib.osutils import pumpfile
75
66
        
76
 
        mutter("add store entry %r" % (fileid))
77
67
        if isinstance(f, basestring):
78
68
            f = StringIO(f)
79
69
            
80
 
        fn = self._relpath(fileid)
81
 
        if self._transport.has(fn):
82
 
            raise BzrError("store %r already contains id %r" % (self._transport.base, fileid))
83
 
 
84
 
        if self._prefixed:
85
 
            try:
86
 
                self._transport.mkdir(hash_prefix(fileid))
87
 
            except FileExists:
88
 
                pass
89
 
 
90
70
        sio = StringIO()
91
71
        gf = gzip.GzipFile(mode='wb', fileobj=sio)
92
72
        # if pumpfile handles files that don't fit in ram,