~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commit.py

  • Committer: Robert Collins
  • Date: 2007-09-20 03:43:11 UTC
  • mto: (2840.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 2842.
  • Revision ID: robertc@robertcollins.net-20070920034311-lgjoomiumagdhksn
* Committing a change which is not a merge and does not change the number of
  files in the tree is faster by utilising the data about whether files are
  changed to determine if a the tree is unchanged rather than recalculating
  it at the end of the commit process. (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
241
241
                               " parameter is required for commit().")
242
242
 
243
243
        self.bound_branch = None
 
244
        self.entries_changed = False
 
245
        self.entries_deleted = False
244
246
        self.local = local
245
247
        self.master_branch = None
246
248
        self.master_locked = False
383
385
            return NullCommitReporter()
384
386
        return ReportCommitToLog()
385
387
 
386
 
    def _any_real_changes(self):
387
 
        """Are there real changes between new_inventory and basis?
388
 
 
389
 
        For trees without rich roots, inv.root.revision changes every commit.
390
 
        But if that is the only change, we want to treat it as though there
391
 
        are *no* changes.
392
 
        """
393
 
        new_entries = self.builder.new_inventory.iter_entries()
394
 
        basis_entries = self.basis_inv.iter_entries()
395
 
        new_path, new_root_ie = new_entries.next()
396
 
        basis_path, basis_root_ie = basis_entries.next()
397
 
 
398
 
        # This is a copy of InventoryEntry.__eq__ only leaving out .revision
399
 
        def ie_equal_no_revision(this, other):
400
 
            return ((this.file_id == other.file_id)
401
 
                    and (this.name == other.name)
402
 
                    and (this.symlink_target == other.symlink_target)
403
 
                    and (this.text_sha1 == other.text_sha1)
404
 
                    and (this.text_size == other.text_size)
405
 
                    and (this.text_id == other.text_id)
406
 
                    and (this.parent_id == other.parent_id)
407
 
                    and (this.kind == other.kind)
408
 
                    and (this.executable == other.executable)
409
 
                    and (this.reference_revision == other.reference_revision)
410
 
                    )
411
 
        if not ie_equal_no_revision(new_root_ie, basis_root_ie):
412
 
            return True
413
 
 
414
 
        for new_ie, basis_ie in zip(new_entries, basis_entries):
415
 
            if new_ie != basis_ie:
416
 
                return True
417
 
 
418
 
        # No actual changes present
419
 
        return False
420
 
 
421
388
    def _check_pointless(self):
422
389
        if self.allow_pointless:
423
390
            return
434
401
            return
435
402
        # If length == 1, then we only have the root entry. Which means
436
403
        # that there is no real difference (only the root could be different)
437
 
        if (len(self.builder.new_inventory) != 1 and self._any_real_changes()):
 
404
        if len(self.builder.new_inventory) != 1 and (self.entries_changed or
 
405
            self.entries_deleted):
438
406
            return
439
407
        raise PointlessCommit()
440
408
 
678
646
                    continue
679
647
                ie = new_ie.copy()
680
648
                ie.revision = None
681
 
                self.builder.record_entry_contents(ie, self.parent_invs, path,
682
 
                                                   self.basis_tree)
 
649
                if self.builder.record_entry_contents(ie, self.parent_invs, path,
 
650
                    self.basis_tree):
 
651
                    self.entries_changed = True
683
652
 
 
653
        # note that deletes have occured
 
654
        if set(self.basis_inv._byid.keys()) - set(self.builder.new_inventory._byid.keys()):
 
655
            self.entries_deleted = True
684
656
        # Report what was deleted.
685
 
        if self.reporter.is_verbose():
 
657
        if self.entries_deleted and self.reporter.is_verbose():
686
658
            for path, ie in self.basis_inv.iter_entries():
687
659
                if ie.file_id not in self.builder.new_inventory:
688
660
                    self.reporter.deleted(path)
735
707
            # Note: I don't particularly want to have the existing_ie
736
708
            # parameter but the test suite currently (28-Jun-07) breaks
737
709
            # without it thanks to a unicode normalisation issue. :-(
738
 
            definitely_changed = kind != existing_ie.kind 
 
710
            definitely_changed = kind != existing_ie.kind
739
711
            self._record_entry(path, file_id, specific_files, kind, name,
740
712
                parent_id, definitely_changed, existing_ie, report_changes)
741
713
 
766
738
                local=self.local, reporter=self.reporter)
767
739
        except errors.PointlessCommit:
768
740
            pass
 
741
        else:
 
742
            self.entries_changed = True
769
743
 
770
744
    def _record_entry(self, path, file_id, specific_files, kind, name,
771
745
            parent_id, definitely_changed, existing_ie=None,
788
762
                # this entry is new and not being committed
789
763
                ie = None
790
764
        if ie is not None:
791
 
            self.builder.record_entry_contents(ie, self.parent_invs, 
792
 
                path, self.work_tree)
 
765
            if self.builder.record_entry_contents(ie, self.parent_invs,
 
766
                path, self.work_tree):
 
767
                self.entries_changed = True
793
768
            if report_changes:
794
769
                self._report_change(ie, path)
795
770
        return ie