/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/commit.py

  • Committer: Benoît Pierre
  • Date: 2009-02-24 00:25:32 UTC
  • mfrom: (4035 +trunk)
  • mto: (4056.1.1 trunk2)
  • mto: This revision was merged to the branch mainline in revision 4058.
  • Revision ID: benoit.pierre@gmail.com-20090224002532-i2f64ou15pa7if2y
Merge with upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
237
237
            pending changes of any sort during this commit.
238
238
        :param exclude: None or a list of relative paths to exclude from the
239
239
            commit. Pending changes to excluded files will be ignored by the
240
 
            commit. 
 
240
            commit.
241
241
        """
242
242
        mutter('preparing to commit')
243
243
 
285
285
        self.committer = committer
286
286
        self.strict = strict
287
287
        self.verbose = verbose
288
 
        # accumulates an inventory delta to the basis entry, so we can make
289
 
        # just the necessary updates to the workingtree's cached basis.
290
 
        self._basis_delta = []
291
288
 
292
289
        self.work_tree.lock_write()
293
290
        self.pb = bzrlib.ui.ui_factory.nested_progress_bar()
355
352
                    entries_title="Directory")
356
353
            self.builder = self.branch.get_commit_builder(self.parents,
357
354
                self.config, timestamp, timezone, committer, revprops, rev_id)
358
 
            
 
355
 
359
356
            try:
 
357
                self.builder.will_record_deletes()
360
358
                # find the location being committed to
361
359
                if self.bound_branch:
362
360
                    master_location = self.master_branch.base
414
412
            # Make the working tree up to date with the branch
415
413
            self._set_progress_stage("Updating the working tree")
416
414
            self.work_tree.update_basis_by_delta(self.rev_id,
417
 
                 self._basis_delta)
 
415
                 self.builder.get_basis_delta())
418
416
            self.reporter.completed(new_revno, self.rev_id)
419
417
            self._process_post_hooks(old_revno, new_revno)
420
418
        finally:
433
431
        # A merge with no effect on files
434
432
        if len(self.parents) > 1:
435
433
            return
436
 
        # TODO: we could simplify this by using self._basis_delta.
 
434
        # TODO: we could simplify this by using self.builder.basis_delta.
437
435
 
438
436
        # The initial commit adds a root directory, but this in itself is not
439
437
        # a worthwhile commit.
443
441
        # If length == 1, then we only have the root entry. Which means
444
442
        # that there is no real difference (only the root could be different)
445
443
        # unless deletes occured, in which case the length is irrelevant.
446
 
        if (self.any_entries_deleted or 
 
444
        if (self.any_entries_deleted or
447
445
            (len(self.builder.new_inventory) != 1 and
448
446
             self.any_entries_changed)):
449
447
            return
478
476
        #       commits to the remote branch if they would fit.
479
477
        #       But for now, just require remote to be identical
480
478
        #       to local.
481
 
        
 
479
 
482
480
        # Make sure the local branch is identical to the master
483
481
        master_info = self.master_branch.last_revision_info()
484
482
        local_info = self.branch.last_revision_info()
541
539
    def _process_hooks(self, hook_name, old_revno, new_revno):
542
540
        if not Branch.hooks[hook_name]:
543
541
            return
544
 
        
 
542
 
545
543
        # new style commit hooks:
546
544
        if not self.bound_branch:
547
545
            hook_master = self.branch
556
554
            old_revid = self.parents[0]
557
555
        else:
558
556
            old_revid = bzrlib.revision.NULL_REVISION
559
 
        
 
557
 
560
558
        if hook_name == "pre_commit":
561
559
            future_tree = self.builder.revision_tree()
562
560
            tree_delta = future_tree.changes_from(self.basis_tree,
563
561
                                             include_root=True)
564
 
        
 
562
 
565
563
        for hook in Branch.hooks[hook_name]:
566
564
            # show the running hook in the progress bar. As hooks may
567
565
            # end up doing nothing (e.g. because they are not configured by
597
595
            # typically this will be useful enough.
598
596
            except Exception, e:
599
597
                found_exception = e
600
 
        if found_exception is not None: 
 
598
        if found_exception is not None:
601
599
            # don't do a plan raise, because the last exception may have been
602
600
            # trashed, e is our sure-to-work exception even though it loses the
603
601
            # full traceback. XXX: RBC 20060421 perhaps we could check the
604
 
            # exc_info and if its the same one do a plain raise otherwise 
 
602
            # exc_info and if its the same one do a plain raise otherwise
605
603
            # 'raise e' as we do now.
606
604
            raise e
607
605
 
623
621
        # serialiser not by commit. Then we can also add an unescaper
624
622
        # in the deserializer and start roundtripping revision messages
625
623
        # precisely. See repository_implementations/test_repository.py
626
 
        
 
624
 
627
625
        # Python strings can include characters that can't be
628
626
        # represented in well-formed XML; escape characters that
629
627
        # aren't listed in the XML specification
637
635
 
638
636
    def _gather_parents(self):
639
637
        """Record the parents of a merge for merge detection."""
640
 
        # TODO: Make sure that this list doesn't contain duplicate 
 
638
        # TODO: Make sure that this list doesn't contain duplicate
641
639
        # entries and the order is preserved when doing this.
642
640
        self.parents = self.work_tree.get_parent_ids()
643
641
        self.parent_invs = [self.basis_inv]
656
654
        #
657
655
        # This starts by creating a new empty inventory. Depending on
658
656
        # which files are selected for commit, and what is present in the
659
 
        # current tree, the new inventory is populated. inventory entries 
 
657
        # current tree, the new inventory is populated. inventory entries
660
658
        # which are candidates for modification have their revision set to
661
659
        # None; inventory entries that are carried over untouched have their
662
660
        # revision set to their prior value.
696
694
                # required after that changes.
697
695
                if len(self.parents) > 1:
698
696
                    ie.revision = None
699
 
                delta, version_recorded, _ = self.builder.record_entry_contents(
 
697
                _, version_recorded, _ = self.builder.record_entry_contents(
700
698
                    ie, self.parent_invs, path, self.basis_tree, None)
701
699
                if version_recorded:
702
700
                    self.any_entries_changed = True
703
 
                if delta:
704
 
                    self._basis_delta.append(delta)
705
701
 
706
702
    def _report_and_accumulate_deletes(self):
707
703
        # XXX: Could the list of deleted paths and ids be instead taken from
726
722
            deleted.sort()
727
723
            # XXX: this is not quite directory-order sorting
728
724
            for path, file_id in deleted:
729
 
                self._basis_delta.append((path, None, file_id, None))
 
725
                self.builder.record_delete(path, file_id)
730
726
                self.reporter.deleted(path)
731
727
 
732
728
    def _populate_from_inventory(self):
735
731
            # raise an exception as soon as we find a single unknown.
736
732
            for unknown in self.work_tree.unknowns():
737
733
                raise StrictCommitFailed()
738
 
        
 
734
 
739
735
        specific_files = self.specific_files
740
736
        exclude = self.exclude
741
737
        report_changes = self.reporter.is_verbose()
831
827
        # FIXME: be more comprehensive here:
832
828
        # this works when both trees are in --trees repository,
833
829
        # but when both are bound to a different repository,
834
 
        # it fails; a better way of approaching this is to 
 
830
        # it fails; a better way of approaching this is to
835
831
        # finally implement the explicit-caches approach design
836
832
        # a while back - RBC 20070306.
837
833
        if sub_tree.branch.repository.has_same_location(
863
859
            ie.revision = None
864
860
        # For carried over entries we don't care about the fs hash - the repo
865
861
        # isn't generating a sha, so we're not saving computation time.
866
 
        delta, version_recorded, fs_hash = self.builder.record_entry_contents(
 
862
        _, version_recorded, fs_hash = self.builder.record_entry_contents(
867
863
            ie, self.parent_invs, path, self.work_tree, content_summary)
868
 
        if delta:
869
 
            self._basis_delta.append(delta)
870
864
        if version_recorded:
871
865
            self.any_entries_changed = True
872
866
        if report_changes:
886
880
        else:
887
881
            basis_ie = None
888
882
        change = ie.describe_change(basis_ie, ie)
889
 
        if change in (InventoryEntry.RENAMED, 
 
883
        if change in (InventoryEntry.RENAMED,
890
884
            InventoryEntry.MODIFIED_AND_RENAMED):
891
885
            old_path = self.basis_inv.id2path(ie.file_id)
892
886
            self.reporter.renamed(change, old_path, path)