~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Vincent Ladeuil
  • Date: 2007-07-15 11:24:18 UTC
  • mfrom: (2617 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2646.
  • Revision ID: v.ladeuil+lp@free.fr-20070715112418-9nn4n6esxv60ny4b
merge bzr.dev@1617

Show diffs side-by-side

added added

removed removed

Lines of Context:
65
65
    ignores,
66
66
    merge,
67
67
    osutils,
 
68
    revision as _mod_revision,
68
69
    revisiontree,
69
70
    repository,
70
71
    textui,
502
503
        This implementation reads the pending merges list and last_revision
503
504
        value and uses that to decide what the parents list should be.
504
505
        """
505
 
        last_rev = self._last_revision()
506
 
        if last_rev is None:
 
506
        last_rev = _mod_revision.ensure_null(self._last_revision())
 
507
        if _mod_revision.NULL_REVISION == last_rev:
507
508
            parents = []
508
509
        else:
509
510
            parents = [last_rev]
734
735
        revision_ids = [osutils.safe_revision_id(r) for r in revision_ids]
735
736
        self._check_parents_for_ghosts(revision_ids,
736
737
            allow_leftmost_as_ghost=allow_leftmost_as_ghost)
 
738
        for revision_id in revision_ids:
 
739
            _mod_revision.check_not_reserved_id(revision_id)
737
740
 
738
741
        if len(revision_ids) > 0:
739
742
            self.set_last_revision(revision_ids[0])
740
743
        else:
741
 
            self.set_last_revision(None)
 
744
            self.set_last_revision(_mod_revision.NULL_REVISION)
742
745
 
743
746
        self._set_merges_from_parent_ids(revision_ids)
744
747
 
746
749
    def set_parent_trees(self, parents_list, allow_leftmost_as_ghost=False):
747
750
        """See MutableTree.set_parent_trees."""
748
751
        parent_ids = [osutils.safe_revision_id(rev) for (rev, tree) in parents_list]
 
752
        for revision_id in parent_ids:
 
753
            _mod_revision.check_not_reserved_id(revision_id)
749
754
 
750
755
        self._check_parents_for_ghosts(parent_ids,
751
756
            allow_leftmost_as_ghost=allow_leftmost_as_ghost)
752
757
 
753
758
        if len(parent_ids) == 0:
754
 
            leftmost_parent_id = None
 
759
            leftmost_parent_id = _mod_revision.NULL_REVISION
755
760
            leftmost_parent_tree = None
756
761
        else:
757
762
            leftmost_parent_id, leftmost_parent_tree = parents_list[0]
807
812
            # local alterations
808
813
            merger.check_basis(check_clean=True, require_commits=False)
809
814
            if to_revision is None:
810
 
                to_revision = branch.last_revision()
 
815
                to_revision = _mod_revision.ensure_null(branch.last_revision())
811
816
            else:
812
817
                to_revision = osutils.safe_revision_id(to_revision)
813
818
            merger.other_rev_id = to_revision
814
 
            if merger.other_rev_id is None:
 
819
            if _mod_revision.is_null(merger.other_rev_id):
815
820
                raise errors.NoCommits(branch)
816
821
            self.branch.fetch(branch, last_revision=merger.other_rev_id)
817
822
            merger.other_basis = merger.other_rev_id
1685
1690
        This is used to allow WorkingTree3 instances to not affect branch
1686
1691
        when their last revision is set.
1687
1692
        """
1688
 
        if new_revision is None:
 
1693
        if _mod_revision.is_null(new_revision):
1689
1694
            self.branch.set_revision_history([])
1690
1695
            return False
1691
1696
        try:
1762
1767
    @needs_tree_write_lock
1763
1768
    def remove(self, files, verbose=False, to_file=None, keep_files=True,
1764
1769
        force=False):
1765
 
        """Remove nominated files from the working inventor.
 
1770
        """Remove nominated files from the working inventory.
1766
1771
 
1767
1772
        :files: File paths relative to the basedir.
1768
1773
        :keep_files: If true, the files will also be kept.
1803
1808
                    recurse_directory_to_add_files(filename)
1804
1809
        files = [f for f in new_files]
1805
1810
 
 
1811
        if len(files) == 0:
 
1812
            return # nothing to do
 
1813
 
1806
1814
        # Sort needed to first handle directory content before the directory
1807
1815
        files.sort(reverse=True)
1808
1816
        if not keep_files and not force:
1809
 
            tree_delta = self.changes_from(self.basis_tree(),
1810
 
                specific_files=files)
1811
 
            for unknown_file in unknown_files_in_directory:
1812
 
                tree_delta.unversioned.extend((unknown_file,))
1813
 
            if bool(tree_delta.modified
1814
 
                    or tree_delta.added
1815
 
                    or tree_delta.renamed
1816
 
                    or tree_delta.kind_changed
1817
 
                    or tree_delta.unversioned):
 
1817
            has_changed_files = len(unknown_files_in_directory) > 0
 
1818
            if not has_changed_files:
 
1819
                for (file_id, path, content_change, versioned, parent_id, name,
 
1820
                     kind, executable) in self._iter_changes(self.basis_tree(),
 
1821
                         include_unchanged=True, require_versioned=False,
 
1822
                         want_unversioned=True, specific_files=files):
 
1823
                    # check if it's unknown OR changed but not deleted:
 
1824
                    if (versioned == (False, False)
 
1825
                        or (content_change and kind[1] != None)):
 
1826
                        has_changed_files = True
 
1827
                        break
 
1828
 
 
1829
            if has_changed_files:
 
1830
                # make delta to show ALL applicable changes in error message.
 
1831
                tree_delta = self.changes_from(self.basis_tree(),
 
1832
                    specific_files=files)
 
1833
                for unknown_file in unknown_files_in_directory:
 
1834
                    tree_delta.unversioned.extend((unknown_file,))
1818
1835
                raise errors.BzrRemoveChangedFilesError(tree_delta)
1819
1836
 
1820
1837
        # do this before any modifications
2031
2048
        try:
2032
2049
            last_rev = self.get_parent_ids()[0]
2033
2050
        except IndexError:
2034
 
            last_rev = None
2035
 
        if last_rev != self.branch.last_revision():
 
2051
            last_rev = _mod_revision.NULL_REVISION
 
2052
        if last_rev != _mod_revision.ensure_null(self.branch.last_revision()):
2036
2053
            # merge tree state up to new branch tip.
2037
2054
            basis = self.basis_tree()
2038
2055
            basis.lock_read()
2061
2078
            for parent in merges:
2062
2079
                parent_trees.append(
2063
2080
                    (parent, self.branch.repository.revision_tree(parent)))
2064
 
            if old_tip is not None:
 
2081
            if (old_tip is not None and not _mod_revision.is_null(old_tip)):
2065
2082
                parent_trees.append(
2066
2083
                    (old_tip, self.branch.repository.revision_tree(old_tip)))
2067
2084
            self.set_parent_trees(parent_trees)
2070
2087
            # the working tree had the same last-revision as the master
2071
2088
            # branch did. We may still have pivot local work from the local
2072
2089
            # branch into old_tip:
2073
 
            if old_tip is not None:
 
2090
            if (old_tip is not None and not _mod_revision.is_null(old_tip)):
2074
2091
                self.add_parent_tree_id(old_tip)
2075
 
        if old_tip and old_tip != last_rev:
 
2092
        if (old_tip is not None and not _mod_revision.is_null(old_tip)
 
2093
            and old_tip != last_rev):
2076
2094
            # our last revision was not the prior branch last revision
2077
2095
            # and we have converted that last revision to a pending merge.
2078
2096
            # base is somewhere between the branch tip now
2594
2612
        if not isinstance(a_bzrdir.transport, LocalTransport):
2595
2613
            raise errors.NotLocalUrl(a_bzrdir.transport.base)
2596
2614
        branch = a_bzrdir.open_branch()
2597
 
        if revision_id is not None:
 
2615
        if revision_id is None:
 
2616
            revision_id = _mod_revision.ensure_null(branch.last_revision())
 
2617
        else:
2598
2618
            revision_id = osutils.safe_revision_id(revision_id)
2599
 
            branch.lock_write()
2600
 
            try:
2601
 
                revision_history = branch.revision_history()
2602
 
                try:
2603
 
                    position = revision_history.index(revision_id)
2604
 
                except ValueError:
2605
 
                    raise errors.NoSuchRevision(branch, revision_id)
2606
 
                branch.set_revision_history(revision_history[:position + 1])
2607
 
            finally:
2608
 
                branch.unlock()
2609
 
        revision = branch.last_revision()
 
2619
        branch.lock_write()
 
2620
        try:
 
2621
            branch.generate_revision_history(revision_id)
 
2622
        finally:
 
2623
            branch.unlock()
2610
2624
        inv = Inventory()
2611
2625
        wt = WorkingTree2(a_bzrdir.root_transport.local_abspath('.'),
2612
2626
                         branch,
2614
2628
                         _internal=True,
2615
2629
                         _format=self,
2616
2630
                         _bzrdir=a_bzrdir)
2617
 
        basis_tree = branch.repository.revision_tree(revision)
 
2631
        basis_tree = branch.repository.revision_tree(revision_id)
2618
2632
        if basis_tree.inventory.root is not None:
2619
2633
            wt.set_root_id(basis_tree.inventory.root.file_id)
2620
2634
        # set the parent list and cache the basis tree.
2621
 
        wt.set_parent_trees([(revision, basis_tree)])
 
2635
        if _mod_revision.is_null(revision_id):
 
2636
            parent_trees = []
 
2637
        else:
 
2638
            parent_trees = [(revision_id, basis_tree)]
 
2639
        wt.set_parent_trees(parent_trees)
2622
2640
        transform.build_tree(basis_tree, wt)
2623
2641
        return wt
2624
2642
 
2695
2713
        control_files.put_utf8('format', self.get_format_string())
2696
2714
        branch = a_bzrdir.open_branch()
2697
2715
        if revision_id is None:
2698
 
            revision_id = branch.last_revision()
 
2716
            revision_id = _mod_revision.ensure_null(branch.last_revision())
2699
2717
        else:
2700
2718
            revision_id = osutils.safe_revision_id(revision_id)
2701
2719
        # WorkingTree3 can handle an inventory which has a unique root id.