/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tree.py

  • Committer: Martin Pool
  • Date: 2005-09-12 09:11:23 UTC
  • Revision ID: mbp@sourcefrog.net-20050912091122-9315b91a7b83533d
- InventoryEntry.copy() must copy text_version

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
"""
19
19
 
20
20
import os
 
21
from cStringIO import StringIO
21
22
 
22
23
import bzrlib
23
24
from bzrlib.trace import mutter, note
24
 
from bzrlib.errors import BzrError
 
25
from bzrlib.errors import BzrError, BzrCheckError
25
26
from bzrlib.inventory import Inventory
26
27
from bzrlib.osutils import pumpfile, appendpath, fingerprint_file
27
28
 
92
93
                     "store is probably damaged/corrupt"])
93
94
 
94
95
 
95
 
    def print_file(self, fileid):
96
 
        """Print file with id `fileid` to stdout."""
 
96
    def print_file(self, file_id):
 
97
        """Print file with id `file_id` to stdout."""
97
98
        import sys
98
 
        pumpfile(self.get_file(fileid), sys.stdout)
 
99
        sys.stdout.write(self.get_file_text(file_id))
99
100
        
100
101
        
101
102
    def export(self, dest, format='dir', root=None):
119
120
           or at least passing a description to the constructor.
120
121
    """
121
122
    
122
 
    def __init__(self, store, inv):
123
 
        self._store = store
 
123
    def __init__(self, weave_store, inv, revision_id):
 
124
        self._weave_store = weave_store
124
125
        self._inventory = inv
 
126
        self._revision_id = revision_id
 
127
 
 
128
    def get_file_text(self, file_id):
 
129
        ie = self._inventory[file_id]
 
130
        weave = self._weave_store.get_weave(file_id)
 
131
        idx = weave.lookup(self._revision_id)
 
132
        content = weave.get_text(idx)
 
133
        if len(content) != ie.text_size:
 
134
            raise BzrCheckError('mismatched size on revision %s of file %s: '
 
135
                                '%d vs %d bytes'
 
136
                                % (self._revision_id, file_id, len(content),
 
137
                                   ie.text_size))
 
138
        return content
125
139
 
126
140
    def get_file(self, file_id):
127
 
        ie = self._inventory[file_id]
128
 
        f = self._store[ie.text_id]
129
 
        mutter("  get fileid{%s} from %r" % (file_id, self))
130
 
        self._check_retrieved(ie, f)
131
 
        return f
 
141
        return StringIO(self.get_file_text(file_id))
132
142
 
133
143
    def get_file_size(self, file_id):
134
144
        return self._inventory[file_id].text_size
135
145
 
136
146
    def get_file_sha1(self, file_id):
137
147
        ie = self._inventory[file_id]
138
 
        return ie.text_sha1
 
148
        if ie.kind == "file":
 
149
            return ie.text_sha1
139
150
 
140
151
    def has_filename(self, filename):
141
152
        return bool(self.inventory.path2id(filename))
157
168
        if False:  # just to make it a generator
158
169
            yield None
159
170
    
 
171
    def __contains__(self, file_id):
 
172
        return file_id in self._inventory
 
173
 
 
174
    def get_file_sha1(self, file_id):
 
175
        assert self._inventory[file_id].kind == "root_directory"
 
176
        return None
 
177
 
 
178
 
160
179
 
161
180
 
162
181
######################################################################