~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: John Arbash Meinel
  • Date: 2007-11-16 02:11:34 UTC
  • mto: This revision was merged to the branch mainline in revision 3002.
  • Revision ID: john@arbash-meinel.com-20071116021134-e0fjjpjllimkhj3v
Re-introduce the None check in case someone asks to uncommit *to* the last revision

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
    hashcache,
65
65
    ignores,
66
66
    merge,
 
67
    osutils,
67
68
    revision as _mod_revision,
68
69
    revisiontree,
69
70
    repository,
89
90
from bzrlib.lockdir import LockDir
90
91
import bzrlib.mutabletree
91
92
from bzrlib.mutabletree import needs_tree_write_lock
92
 
from bzrlib import osutils
93
93
from bzrlib.osutils import (
94
94
    compact_date,
95
95
    file_kind,
703
703
        if updated:
704
704
            self.set_parent_ids(parents, allow_leftmost_as_ghost=True)
705
705
 
706
 
    def path_content_summary(self, path, _lstat=os.lstat,
 
706
    def path_content_summary(self, path, _lstat=osutils.lstat,
707
707
        _mapper=osutils.file_kind_from_stat_mode):
708
708
        """See Tree.path_content_summary."""
709
709
        abspath = self.abspath(path)
1326
1326
                        errors.PathsDoNotExist(paths=(str(from_rel),
1327
1327
                        str(to_rel))))
1328
1328
                else:
1329
 
                    raise errors.RenameFailedFilesExist(from_rel, to_rel)
 
1329
                    raise errors.RenameFailedFilesExist(from_rel, to_rel,
 
1330
                        extra="(Use --after to update the Bazaar id)")
1330
1331
            rename_entry.only_change_inv = only_change_inv
1331
1332
        return rename_entries
1332
1333
 
1540
1541
                                change_reporter=change_reporter)
1541
1542
                    if (basis_tree.inventory.root is None and
1542
1543
                        new_basis_tree.inventory.root is not None):
1543
 
                        self.set_root_id(new_basis_tree.get_root_id())
 
1544
                        self.set_root_id(new_basis_tree.inventory.root.file_id)
1544
1545
                finally:
1545
1546
                    pb.finished()
1546
1547
                    basis_tree.unlock()
1959
1960
                ' as of bzr 0.91.  Please use None (the default) instead.',
1960
1961
                DeprecationWarning, stacklevel=2)
1961
1962
        if old_tree is None:
1962
 
            basis_tree = self.basis_tree()
1963
 
            basis_tree.lock_read()
1964
 
            old_tree = basis_tree
 
1963
            old_tree = self.basis_tree()
 
1964
        conflicts = transform.revert(self, old_tree, filenames, backups, pb,
 
1965
                                     report_changes)
 
1966
        if filenames is None:
 
1967
            self.set_parent_ids(self.get_parent_ids()[:1])
 
1968
            resolve(self)
1965
1969
        else:
1966
 
            basis_tree = None
1967
 
        try:
1968
 
            conflicts = transform.revert(self, old_tree, filenames, backups, pb,
1969
 
                                         report_changes)
1970
 
            if filenames is None and len(self.get_parent_ids()) > 1:
1971
 
                parent_trees = []
1972
 
                last_revision = self.last_revision()
1973
 
                if last_revision != NULL_REVISION:
1974
 
                    if basis_tree is None:
1975
 
                        basis_tree = self.basis_tree()
1976
 
                        basis_tree.lock_read()
1977
 
                    parent_trees.append((last_revision, basis_tree))
1978
 
                self.set_parent_trees(parent_trees)
1979
 
                resolve(self)
1980
 
            else:
1981
 
                resolve(self, filenames, ignore_misses=True)
1982
 
        finally:
1983
 
            if basis_tree is not None:
1984
 
                basis_tree.unlock()
 
1970
            resolve(self, filenames, ignore_misses=True)
1985
1971
        return conflicts
1986
1972
 
1987
1973
    def revision_tree(self, revision_id):
2153
2139
            try:
2154
2140
                to_tree = self.branch.basis_tree()
2155
2141
                if basis.inventory.root is None:
2156
 
                    self.set_root_id(to_tree.get_root_id())
 
2142
                    self.set_root_id(to_tree.inventory.root.file_id)
2157
2143
                    self.flush()
2158
2144
                result += merge.merge_inner(
2159
2145
                                      self.branch,
2301
2287
            current_inv = None
2302
2288
            inv_finished = True
2303
2289
        while not inv_finished or not disk_finished:
2304
 
            if current_disk:
2305
 
                ((cur_disk_dir_relpath, cur_disk_dir_path_from_top),
2306
 
                    cur_disk_dir_content) = current_disk
2307
 
            else:
2308
 
                ((cur_disk_dir_relpath, cur_disk_dir_path_from_top),
2309
 
                    cur_disk_dir_content) = ((None, None), None)
2310
2290
            if not disk_finished:
2311
2291
                # strip out .bzr dirs
2312
 
                if (cur_disk_dir_path_from_top[top_strip_len:] == '' and
2313
 
                    len(cur_disk_dir_content) > 0):
2314
 
                    # osutils.walkdirs can be made nicer -
 
2292
                if current_disk[0][1][top_strip_len:] == '':
 
2293
                    # osutils.walkdirs can be made nicer - 
2315
2294
                    # yield the path-from-prefix rather than the pathjoined
2316
2295
                    # value.
2317
 
                    bzrdir_loc = bisect_left(cur_disk_dir_content,
2318
 
                        ('.bzr', '.bzr'))
2319
 
                    if cur_disk_dir_content[bzrdir_loc][0] == '.bzr':
 
2296
                    bzrdir_loc = bisect_left(current_disk[1], ('.bzr', '.bzr'))
 
2297
                    if current_disk[1][bzrdir_loc][0] == '.bzr':
2320
2298
                        # we dont yield the contents of, or, .bzr itself.
2321
 
                        del cur_disk_dir_content[bzrdir_loc]
 
2299
                        del current_disk[1][bzrdir_loc]
2322
2300
            if inv_finished:
2323
2301
                # everything is unknown
2324
2302
                direction = 1
2326
2304
                # everything is missing
2327
2305
                direction = -1
2328
2306
            else:
2329
 
                direction = cmp(current_inv[0][0], cur_disk_dir_relpath)
 
2307
                direction = cmp(current_inv[0][0], current_disk[0][0])
2330
2308
            if direction > 0:
2331
2309
                # disk is before inventory - unknown
2332
2310
                dirblock = [(relpath, basename, kind, stat, None, None) for
2333
 
                    relpath, basename, kind, stat, top_path in
2334
 
                    cur_disk_dir_content]
2335
 
                yield (cur_disk_dir_relpath, None), dirblock
 
2311
                    relpath, basename, kind, stat, top_path in current_disk[1]]
 
2312
                yield (current_disk[0][0], None), dirblock
2336
2313
                try:
2337
2314
                    current_disk = disk_iterator.next()
2338
2315
                except StopIteration:
2340
2317
            elif direction < 0:
2341
2318
                # inventory is before disk - missing.
2342
2319
                dirblock = [(relpath, basename, 'unknown', None, fileid, kind)
2343
 
                    for relpath, basename, dkind, stat, fileid, kind in
 
2320
                    for relpath, basename, dkind, stat, fileid, kind in 
2344
2321
                    current_inv[1]]
2345
2322
                yield (current_inv[0][0], current_inv[0][1]), dirblock
2346
2323
                try:
2352
2329
                # merge the inventory and disk data together
2353
2330
                dirblock = []
2354
2331
                for relpath, subiterator in itertools.groupby(sorted(
2355
 
                    current_inv[1] + cur_disk_dir_content,
2356
 
                    key=operator.itemgetter(0)), operator.itemgetter(1)):
 
2332
                    current_inv[1] + current_disk[1], key=operator.itemgetter(0)), operator.itemgetter(1)):
2357
2333
                    path_elements = list(subiterator)
2358
2334
                    if len(path_elements) == 2:
2359
2335
                        inv_row, disk_row = path_elements
2718
2694
        control_files.put_bytes('pending-merges', '')
2719
2695
        
2720
2696
 
2721
 
    def initialize(self, a_bzrdir, revision_id=None, from_branch=None):
 
2697
    def initialize(self, a_bzrdir, revision_id=None):
2722
2698
        """See WorkingTreeFormat.initialize()."""
2723
2699
        if not isinstance(a_bzrdir.transport, LocalTransport):
2724
2700
            raise errors.NotLocalUrl(a_bzrdir.transport.base)
2725
 
        if from_branch is not None:
2726
 
            branch = from_branch
2727
 
        else:
2728
 
            branch = a_bzrdir.open_branch()
 
2701
        branch = a_bzrdir.open_branch()
2729
2702
        if revision_id is None:
2730
2703
            revision_id = _mod_revision.ensure_null(branch.last_revision())
2731
2704
        branch.lock_write()
2742
2715
                         _bzrdir=a_bzrdir)
2743
2716
        basis_tree = branch.repository.revision_tree(revision_id)
2744
2717
        if basis_tree.inventory.root is not None:
2745
 
            wt.set_root_id(basis_tree.get_root_id())
 
2718
            wt.set_root_id(basis_tree.inventory.root.file_id)
2746
2719
        # set the parent list and cache the basis tree.
2747
2720
        if _mod_revision.is_null(revision_id):
2748
2721
            parent_trees = []
2810
2783
        return LockableFiles(transport, self._lock_file_name, 
2811
2784
                             self._lock_class)
2812
2785
 
2813
 
    def initialize(self, a_bzrdir, revision_id=None, from_branch=None):
 
2786
    def initialize(self, a_bzrdir, revision_id=None):
2814
2787
        """See WorkingTreeFormat.initialize().
2815
2788
        
2816
2789
        revision_id allows creating a working tree at a different
2823
2796
        control_files.create_lock()
2824
2797
        control_files.lock_write()
2825
2798
        control_files.put_utf8('format', self.get_format_string())
2826
 
        if from_branch is not None:
2827
 
            branch = from_branch
2828
 
        else:
2829
 
            branch = a_bzrdir.open_branch()
 
2799
        branch = a_bzrdir.open_branch()
2830
2800
        if revision_id is None:
2831
2801
            revision_id = _mod_revision.ensure_null(branch.last_revision())
2832
2802
        # WorkingTree3 can handle an inventory which has a unique root id.
2847
2817
            basis_tree = branch.repository.revision_tree(revision_id)
2848
2818
            # only set an explicit root id if there is one to set.
2849
2819
            if basis_tree.inventory.root is not None:
2850
 
                wt.set_root_id(basis_tree.get_root_id())
 
2820
                wt.set_root_id(basis_tree.inventory.root.file_id)
2851
2821
            if revision_id == NULL_REVISION:
2852
2822
                wt.set_parent_trees([])
2853
2823
            else: