~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/store/versioned/__init__.py

  • Committer: Robert Collins
  • Date: 2007-07-04 08:08:13 UTC
  • mfrom: (2572 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2587.
  • Revision ID: robertc@robertcollins.net-20070704080813-wzebx0r88fvwj5rq
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
import urllib
25
25
from warnings import warn
26
26
 
27
 
from bzrlib import errors
 
27
from bzrlib import (
 
28
    errors,
 
29
    osutils,
 
30
    )
28
31
from bzrlib.weavefile import read_weave, write_weave_v5
29
32
from bzrlib.weave import WeaveFile, Weave
30
33
from bzrlib.store import TransportStore
69
72
 
70
73
    def filename(self, file_id):
71
74
        """Return the path relative to the transport root."""
 
75
        file_id = osutils.safe_file_id(file_id)
72
76
        return self._relpath(file_id)
73
77
 
74
78
    def __iter__(self):
85
89
                        yield file_id
86
90
                    break # only one suffix can match
87
91
 
88
 
    def has_id(self, fileid):
 
92
    def has_id(self, file_id):
 
93
        file_id = osutils.safe_file_id(file_id)
89
94
        suffixes = self._versionedfile_class.get_suffixes()
90
 
        filename = self.filename(fileid)
 
95
        filename = self.filename(file_id)
91
96
        for suffix in suffixes:
92
97
            if not self._transport.has(filename + suffix):
93
98
                return False
95
100
 
96
101
    def get_empty(self, file_id, transaction):
97
102
        """Get an empty weave, which implies deleting the existing one first."""
 
103
        file_id = osutils.safe_file_id(file_id)
98
104
        if self.has_id(file_id):
99
105
            self.delete(file_id, transaction)
100
106
        return self.get_weave_or_empty(file_id, transaction)
101
107
 
102
108
    def delete(self, file_id, transaction):
103
109
        """Remove file_id from the store."""
 
110
        file_id = osutils.safe_file_id(file_id)
104
111
        suffixes = self._versionedfile_class.get_suffixes()
105
112
        filename = self.filename(file_id)
106
113
        for suffix in suffixes:
127
134
        file_id. This is used to reduce duplicate filename calculations when
128
135
        using 'get_weave_or_empty'. FOR INTERNAL USE ONLY.
129
136
        """
 
137
        file_id = osutils.safe_file_id(file_id)
130
138
        weave = transaction.map.find_weave(file_id)
131
139
        if weave is not None:
132
140
            #mutter("cache hit in %s for %s", self, file_id)
155
163
 
156
164
        Returned as a list of lines.
157
165
        """
 
166
        file_id = osutils.safe_file_id(file_id)
158
167
        w = self.get_weave(file_id, transaction)
159
168
        return w.get_lines(rev_id)
160
169
    
193
202
        # of calculating the filename before doing a cache lookup is more than
194
203
        # compensated for by not calculating the filename when making new
195
204
        # versioned files.
 
205
        file_id = osutils.safe_file_id(file_id)
196
206
        _filename = self.filename(file_id)
197
207
        try:
198
208
            return self.get_weave(file_id, transaction, _filename=_filename)
214
224
        Its maintained for backwards compatability but will only work on
215
225
        weave stores - pre 0.8 repositories.
216
226
        """
 
227
        file_id = osutils.safe_file_id(file_id)
217
228
        self._put_weave(file_id, weave, transaction)
218
229
 
219
230
    def _put_weave(self, file_id, weave, transaction):
228
239
        vfile = self.get_weave_or_empty(file_id, transaction)
229
240
        vfile.add_lines(rev_id, parents, new_lines)
230
241
        """
 
242
        file_id = osutils.safe_file_id(file_id)
231
243
        vfile = self.get_weave_or_empty(file_id, transaction)
232
244
        vfile.add_lines(rev_id, parents, new_lines)
233
245
        
239
251
        vfile = self.get_weave_or_empty(file_id, transaction)
240
252
        vfile.clone_text(new_rev_id, old_rev_id, parents)
241
253
        """
 
254
        file_id = osutils.safe_file_id(file_id)
 
255
        old_rev_id = osutils.safe_revision_id(old_rev_id)
 
256
        new_rev_id = osutils.safe_revision_id(new_rev_id)
242
257
        vfile = self.get_weave_or_empty(file_id, transaction)
243
258
        vfile.clone_text(new_rev_id, old_rev_id, parents)
244
259
 
294
309
            # so again with the passthrough
295
310
            to_transaction = PassThroughTransaction()
296
311
        pb = bzrlib.ui.ui_factory.nested_progress_bar()
297
 
        for count, f in enumerate(file_ids):
298
 
            mutter("copy weave {%s} into %s", f, self)
299
 
            pb.update('copy', count, len(file_ids))
300
 
            # if we have it in cache, its faster.
301
 
            # joining is fast with knits, and bearable for weaves -
302
 
            # indeed the new case can be optimised if needed.
303
 
            target = self._make_new_versionedfile(f, to_transaction)
304
 
            target.join(from_store.get_weave(f, from_transaction))
305
 
        pb.finished()
 
312
        try:
 
313
            file_ids = [osutils.safe_file_id(f) for f in file_ids]
 
314
            for count, f in enumerate(file_ids):
 
315
                mutter("copy weave {%s} into %s", f, self)
 
316
                pb.update('copy', count, len(file_ids))
 
317
                # if we have it in cache, its faster.
 
318
                # joining is fast with knits, and bearable for weaves -
 
319
                # indeed the new case can be optimised if needed.
 
320
                target = self._make_new_versionedfile(f, to_transaction)
 
321
                target.join(from_store.get_weave(f, from_transaction))
 
322
        finally:
 
323
            pb.finished()
306
324
 
307
325
    def total_size(self):
308
326
        count, bytes =  super(VersionedFileStore, self).total_size()