/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/workingtree.py

  • Committer: John Arbash Meinel
  • Date: 2007-11-16 01:39:55 UTC
  • mfrom: (2998 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3003.
  • Revision ID: john@arbash-meinel.com-20071116013955-3zy651u2crhk31xx
[merge] bzr.dev 2998

Show diffs side-by-side

added added

removed removed

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