~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tree.py

  • Committer: Aaron Bentley
  • Date: 2005-07-26 14:06:11 UTC
  • mto: (1092.1.41) (1185.3.4) (974.1.47)
  • mto: This revision was merged to the branch mainline in revision 982.
  • Revision ID: abentley@panoramicfeedback.com-20050726140611-403e366f3c79c1f1
Fixed python invocation

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Tree classes, representing directory at point in time.
18
18
"""
19
19
 
 
20
from osutils import pumpfile, appendpath, fingerprint_file
20
21
import os
21
 
from cStringIO import StringIO
 
22
 
 
23
from bzrlib.trace import mutter, note
 
24
from bzrlib.errors import BzrError
22
25
 
23
26
import bzrlib
24
 
from bzrlib.trace import mutter, note
25
 
from bzrlib.errors import BzrError, BzrCheckError
26
 
from bzrlib.inventory import Inventory
27
 
from bzrlib.osutils import pumpfile, appendpath, fingerprint_file
28
 
 
29
27
 
30
28
exporters = {}
31
29
 
68
66
 
69
67
    def _get_inventory(self):
70
68
        return self._inventory
71
 
    
72
 
    def get_file_by_path(self, path):
73
 
        return self.get_file(self._inventory.path2id(path))
74
69
 
75
70
    inventory = property(_get_inventory,
76
71
                         doc="Inventory of this Tree")
93
88
                     "store is probably damaged/corrupt"])
94
89
 
95
90
 
96
 
    def print_file(self, file_id):
97
 
        """Print file with id `file_id` to stdout."""
 
91
    def print_file(self, fileid):
 
92
        """Print file with id `fileid` to stdout."""
98
93
        import sys
99
 
        sys.stdout.write(self.get_file_text(file_id))
 
94
        pumpfile(self.get_file(fileid), sys.stdout)
100
95
        
101
96
        
102
97
    def export(self, dest, format='dir', root=None):
120
115
           or at least passing a description to the constructor.
121
116
    """
122
117
    
123
 
    def __init__(self, weave_store, inv, revision_id):
124
 
        self._weave_store = weave_store
 
118
    def __init__(self, store, inv):
 
119
        self._store = store
125
120
        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
139
121
 
140
122
    def get_file(self, file_id):
141
 
        return StringIO(self.get_file_text(file_id))
 
123
        ie = self._inventory[file_id]
 
124
        f = self._store[ie.text_id]
 
125
        mutter("  get fileid{%s} from %r" % (file_id, self))
 
126
        self._check_retrieved(ie, f)
 
127
        return f
142
128
 
143
129
    def get_file_size(self, file_id):
144
130
        return self._inventory[file_id].text_size
145
131
 
146
132
    def get_file_sha1(self, file_id):
147
133
        ie = self._inventory[file_id]
148
 
        if ie.kind == "file":
149
 
            return ie.text_sha1
 
134
        return ie.text_sha1
150
135
 
151
136
    def has_filename(self, filename):
152
137
        return bool(self.inventory.path2id(filename))
158
143
 
159
144
 
160
145
class EmptyTree(Tree):
161
 
    def __init__(self):
162
 
        self._inventory = Inventory()
 
146
    def __init__(self, root_id):
 
147
        from bzrlib.inventory import Inventory
 
148
        self._inventory = Inventory(root_id)
163
149
 
164
150
    def has_filename(self, filename):
165
151
        return False
168
154
        if False:  # just to make it a generator
169
155
            yield None
170
156
    
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
 
 
179
157
 
180
158
 
181
159
######################################################################