~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commit.py

  • Committer: Martin Pool
  • Date: 2005-09-13 02:11:41 UTC
  • Revision ID: mbp@sourcefrog.net-20050913021141-263bfc2655ac3ed2
- store inventories in weave

- put more intelligence into WeaveStore

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
                            rand_bytes, compact_date, user_email,
42
42
                            kind_marker, is_inside_any, quotefn,
43
43
                            sha_string, sha_file, isdir, isfile)
44
 
from bzrlib.branch import gen_file_id
 
44
from bzrlib.branch import gen_file_id, INVENTORY_FILEID
45
45
from bzrlib.errors import BzrError, PointlessCommit
46
46
from bzrlib.revision import Revision, RevisionReference
47
47
from bzrlib.trace import mutter, note
186
186
            self.basis_tree = self.branch.basis_tree()
187
187
            self.basis_inv = self.basis_tree.inventory
188
188
 
189
 
            self.pending_merges = self.branch.pending_merges()
190
 
            if self.pending_merges:
191
 
                raise NotImplementedError("sorry, can't commit merges to the weave format yet")
192
 
            
 
189
            self._gather_parents()
 
190
 
193
191
            if self.rev_id is None:
194
192
                self.rev_id = _gen_revision_id(self.branch, time.time())
195
193
 
199
197
 
200
198
            if not (self.delta.has_changed()
201
199
                    or self.allow_pointless
202
 
                    or self.pending_merges):
 
200
                    or len(self.parents) != 1):
203
201
                raise PointlessCommit()
204
202
 
205
203
            self.new_inv = self.basis_inv.copy()
222
220
 
223
221
 
224
222
    def _record_inventory(self):
 
223
        """Store the inventory for the new revision."""
225
224
        inv_tmp = StringIO()
226
225
        serializer_v5.write_inventory(self.new_inv, inv_tmp)
 
226
        inv_tmp.seek(0)
227
227
        self.inv_sha1 = sha_string(inv_tmp.getvalue())
228
 
        inv_tmp.seek(0)
229
 
        self.branch.inventory_store.add(inv_tmp, self.rev_id)
 
228
        inv_lines = inv_tmp.readlines()
 
229
        self.branch.weave_store.add_text(INVENTORY_FILEID, self.rev_id,
 
230
                                         inv_lines, self.parents)
 
231
 
 
232
 
 
233
    def _gather_parents(self):
 
234
        pending_merges = self.branch.pending_merges()
 
235
        if pending_merges:
 
236
            raise NotImplementedError("sorry, can't commit merges to the weave format yet")
 
237
        self.parents = []
 
238
        precursor_id = self.branch.last_patch()
 
239
        if precursor_id:
 
240
            self.parents.append(precursor_id)
 
241
        self.parents += pending_merges
230
242
 
231
243
 
232
244
    def _make_revision(self):
237
249
                            message=self.message,
238
250
                            inventory_sha1=self.inv_sha1,
239
251
                            revision_id=self.rev_id)
240
 
 
241
 
        self.rev.parents = []
242
 
        precursor_id = self.branch.last_patch()
243
 
        if precursor_id:
244
 
            self.rev.parents.append(RevisionReference(precursor_id))
245
 
        for merge_rev in self.pending_merges:
246
 
            rev.parents.append(RevisionReference(merge_rev))
247
 
 
 
252
        self.rev.parents = map(RevisionReference, self.parents)
248
253
        rev_tmp = tempfile.TemporaryFile()
249
254
        serializer_v5.write_revision(self.rev, rev_tmp)
250
255
        rev_tmp.seek(0)
316
321
 
317
322
 
318
323
    def _add_text_to_weave(self, file_id, new_lines, parents):
319
 
        weave_fn = self.branch.controlfilename(['weaves', file_id+'.weave'])
320
 
        if os.path.exists(weave_fn):
321
 
            w = read_weave(file(weave_fn, 'rb'))
322
 
        else:
323
 
            w = Weave()
324
 
        # XXX: Should set the appropriate parents by looking for this file_id
325
 
        # in all revision parents
326
 
        parent_idxs = map(w.lookup, parents)
327
 
        w.add(self.rev_id, parent_idxs, new_lines)
328
 
        af = AtomicFile(weave_fn)
329
 
        try:
330
 
            write_weave_v5(w, af)
331
 
            af.commit()
332
 
        finally:
333
 
            af.close()
 
324
        if file_id.startswith('__'):
 
325
            raise ValueError('illegal file-id %r for text file' % file_id)
 
326
        self.branch.weave_store.add_text(file_id, self.rev_id, new_lines, parents)
334
327
 
335
328
 
336
329
def _gen_revision_id(branch, when):