~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commit.py

  • Committer: Aaron Bentley
  • Date: 2007-12-25 04:17:50 UTC
  • mto: This revision was merged to the branch mainline in revision 3160.
  • Revision ID: aaron.bentley@utoronto.ca-20071225041750-t6chr3pmgnebvqcz
Handle non-directory parent conflicts (abentley, #177390)

Show diffs side-by-side

added added

removed removed

Lines of Context:
204
204
               reporter=None,
205
205
               config=None,
206
206
               message_callback=None,
207
 
               recursive='down',
208
 
               exclude=None):
 
207
               recursive='down'):
209
208
        """Commit working copy as a new revision.
210
209
 
211
210
        :param message: the commit message (it or message_callback is required)
233
232
        :param verbose: if True and the reporter is not None, report everything
234
233
        :param recursive: If set to 'down', commit in any subtrees that have
235
234
            pending changes of any sort during this commit.
236
 
        :param exclude: None or a list of relative paths to exclude from the
237
 
            commit. Pending changes to excluded files will be ignored by the
238
 
            commit. 
239
235
        """
240
236
        mutter('preparing to commit')
241
237
 
259
255
        self.bound_branch = None
260
256
        self.any_entries_changed = False
261
257
        self.any_entries_deleted = False
262
 
        if exclude is not None:
263
 
            self.exclude = sorted(
264
 
                minimum_path_selection(exclude))
265
 
        else:
266
 
            self.exclude = []
267
258
        self.local = local
268
259
        self.master_branch = None
269
260
        self.master_locked = False
338
329
            self.pb.show_count = True
339
330
            self.pb.show_bar = True
340
331
 
 
332
            # After a merge, a selected file commit is not supported.
 
333
            # See 'bzr help merge' for an explanation as to why.
341
334
            self.basis_inv = self.basis_tree.inventory
342
335
            self._gather_parents()
343
 
            # After a merge, a selected file commit is not supported.
344
 
            # See 'bzr help merge' for an explanation as to why.
345
336
            if len(self.parents) > 1 and self.specific_files:
346
337
                raise errors.CannotCommitSelectedFileMerge(self.specific_files)
347
 
            # Excludes are a form of selected file commit.
348
 
            if len(self.parents) > 1 and self.exclude:
349
 
                raise errors.CannotCommitSelectedFileMerge(self.exclude)
350
338
 
351
339
            # Collect the changes
352
340
            self._set_progress_stage("Collecting changes",
377
365
 
378
366
                # Prompt the user for a commit message if none provided
379
367
                message = message_callback(self)
 
368
                assert isinstance(message, unicode), type(message)
380
369
                self.message = message
381
370
                self._escape_commit_message()
382
371
 
660
649
        # in bugs like #46635.  Any reason not to use/enhance Tree.changes_from?
661
650
        # ADHB 11-07-2006
662
651
 
663
 
        exclude = self.exclude
664
 
        specific_files = self.specific_files or []
 
652
        specific_files = self.specific_files
665
653
        mutter("Selecting files for commit with filter %s", specific_files)
666
654
 
667
655
        # Build the new inventory
668
 
        self._populate_from_inventory()
 
656
        self._populate_from_inventory(specific_files)
669
657
 
670
658
        # If specific files are selected, then all un-selected files must be
671
659
        # recorded in their previous state. For more details, see
672
660
        # https://lists.ubuntu.com/archives/bazaar/2007q3/028476.html.
673
 
        if specific_files or exclude:
 
661
        if specific_files:
674
662
            for path, old_ie in self.basis_inv.iter_entries():
675
663
                if old_ie.file_id in self.builder.new_inventory:
676
664
                    # already added - skip.
677
665
                    continue
678
 
                if (is_inside_any(specific_files, path)
679
 
                    and not is_inside_any(exclude, path)):
680
 
                    # was inside the selected path, and not excluded - if not
681
 
                    # present it has been deleted so skip.
 
666
                if is_inside_any(specific_files, path):
 
667
                    # was inside the selected path, if not present it has been
 
668
                    # deleted so skip.
682
669
                    continue
683
 
                # From here down it was either not selected, or was excluded:
684
670
                if old_ie.kind == 'directory':
685
671
                    self._next_progress_entry()
686
 
                # We preserve the entry unaltered.
 
672
                # not in final inv yet, was not in the selected files, so is an
 
673
                # entry to be preserved unaltered.
687
674
                ie = old_ie.copy()
688
675
                # Note: specific file commits after a merge are currently
689
676
                # prohibited. This test is for sanity/safety in case it's
711
698
                self._basis_delta.append((path, None, file_id, None))
712
699
                self.reporter.deleted(path)
713
700
 
714
 
    def _populate_from_inventory(self):
 
701
    def _populate_from_inventory(self, specific_files):
715
702
        """Populate the CommitBuilder by walking the working tree inventory."""
716
703
        if self.strict:
717
704
            # raise an exception as soon as we find a single unknown.
718
705
            for unknown in self.work_tree.unknowns():
719
706
                raise StrictCommitFailed()
720
 
        
721
 
        specific_files = self.specific_files
722
 
        exclude = self.exclude
 
707
               
723
708
        report_changes = self.reporter.is_verbose()
724
709
        deleted_ids = []
725
710
        # A tree of paths that have been deleted. E.g. if foo/bar has been
728
713
        # XXX: Note that entries may have the wrong kind because the entry does
729
714
        # not reflect the status on disk.
730
715
        work_inv = self.work_tree.inventory
731
 
        # NB: entries will include entries within the excluded ids/paths
732
 
        # because iter_entries_by_dir has no 'exclude' facility today.
733
716
        entries = work_inv.iter_entries_by_dir(
734
717
            specific_file_ids=self.specific_file_ids, yield_parents=True)
735
718
        for path, existing_ie in entries:
757
740
                if deleted_dict is not None:
758
741
                    # the path has a deleted parent, do not add it.
759
742
                    continue
760
 
            if exclude and is_inside_any(exclude, path):
761
 
                # Skip excluded paths. Excluded paths are processed by
762
 
                # _update_builder_with_changes.
763
 
                continue
764
743
            content_summary = self.work_tree.path_content_summary(path)
765
744
            # Note that when a filter of specific files is given, we must only
766
745
            # skip/record deleted files matching that filter.