~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commit.py

  • Committer: Robert Collins
  • Date: 2005-09-30 16:38:34 UTC
  • mto: This revision was merged to the branch mainline in revision 1397.
  • Revision ID: robertc@robertcollins.net-20050930163834-6b74beb609162e00
move inventory entry centric snapshot taking logic to inventory.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
364
364
                    r[ie.revision] = ie
365
365
        return r
366
366
 
367
 
    def _snapshot_entry(self, path, ie, previous_entries):
368
 
        """Store a single possibly changed inventory entry in the branch."""
369
 
        mutter('parents of %s are %r', path, previous_entries)
370
 
        if ie.revision is not None:
371
 
            # not selected for commit
372
 
            return
373
 
        if ie.kind == 'symlink':
374
 
            ie.read_symlink_target(self.branch.abspath(path))
375
 
        if len(previous_entries) == 1:
376
 
            # cannot be unchanged unless there is only one parent file rev.
377
 
            parent_ie = previous_entries.values()[0]
378
 
            unchanged = ie.unchanged(parent_ie, self.work_tree)
379
 
            if unchanged:
380
 
                mutter("found unchanged entry")
381
 
                ie.revision = parent_ie.revision
382
 
                self.report_entry_status(previous_entries, path, ie)
383
 
                return 
384
 
        mutter('new revision for {%s}', ie.file_id)
385
 
        ie.revision = self.rev_id
386
 
        if ie.kind != 'file':
387
 
            self.report_entry_status(previous_entries, path, ie)
388
 
            return
389
 
        # file is either new, or a file merge; need to record
390
 
        # a new version
391
 
        self.report_entry_status(previous_entries, path, ie)
392
 
        #if not unchanged:
393
 
        self._commit_file(ie, previous_entries)
394
 
 
395
 
    def report_entry_status(self, previous_entries, path, ie):
396
 
        if len(previous_entries) > 1:
397
 
            note('merged %s', path)
398
 
        elif len(previous_entries) == 0:
399
 
            note('added %s', path)
400
 
        elif ie.revision == self.rev_id:
401
 
            note('modified/renamed/reparented%s', path)
402
 
        else:
403
 
            note('unchanged %s', path)
404
 
 
405
367
    def _store_snapshot(self):
406
368
        """Pass over inventory and record a snapshot.
407
369
 
424
386
        # mark-merge.  
425
387
        for path, ie in self.new_inv.iter_entries():
426
388
            previous_entries = self._find_entry_parents(ie. file_id)
427
 
            self._snapshot_entry(path, ie, previous_entries)
 
389
            if ie.revision is None:
 
390
                change = ie.snapshot(self.rev_id, path, previous_entries,
 
391
                                     self.work_tree, self.weave_store)
 
392
            else:
 
393
                change = "unchanged"
 
394
            note("%s %s", change, path)
428
395
 
429
396
    def _populate_new_inv(self):
430
397
        """Build revision inventory.
461
428
            if file_id not in self.new_inv:
462
429
                note('deleted %s', self.basis_inv.id2path(file_id))
463
430
 
464
 
    def _commit_file(self, new_ie, file_parents):                    
465
 
        mutter('storing file {%s} in revision {%s}',
466
 
               new_ie.file_id, new_ie.revision)
467
 
        # special case to avoid diffing on renames or 
468
 
        # reparenting
469
 
        if (len(file_parents) == 1
470
 
            and new_ie.text_sha1 == file_parents.values()[0].text_sha1
471
 
            and new_ie.text_size == file_parents.values()[0].text_size):
472
 
            previous_ie = file_parents.values()[0]
473
 
            self.weave_store.add_identical_text(
474
 
                new_ie.file_id, previous_ie.revision, 
475
 
                new_ie.revision, file_parents)
476
 
        else:
477
 
            new_lines = self.work_tree.get_file(new_ie.file_id).readlines()
478
 
            self._add_text_to_weave(new_ie.file_id, new_lines, file_parents)
479
 
            new_ie.text_sha1 = sha_strings(new_lines)
480
 
            new_ie.text_size = sum(map(len, new_lines))
481
431
 
482
 
    def _add_text_to_weave(self, file_id, new_lines, parents):
483
 
        self.weave_store.add_text(file_id, self.rev_id, new_lines, parents)
484
432
 
485
433
def _gen_revision_id(branch, when):
486
434
    """Return new revision-id."""