~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Patch Queue Manager
  • Date: 2012-09-05 20:52:26 UTC
  • mfrom: (6549.3.1 dev_2.5_integration)
  • Revision ID: pqm@pqm.ubuntu.com-20120905205226-8s3bzolvduug3ifj
(gz) Merge 2.5 (Martin Packman)

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
    revision as _mod_revision,
61
61
    revisiontree,
62
62
    rio as _mod_rio,
 
63
    shelf,
63
64
    transform,
64
65
    transport,
65
66
    ui,
534
535
        else:
535
536
            # TODO now merge from tree.last_revision to revision (to preserve
536
537
            # user local changes)
537
 
            merge.transform_tree(tree, self)
 
538
            try:
 
539
                other_tree = self.revision_tree(revision_id)
 
540
            except errors.NoSuchRevision:
 
541
                other_tree = self.branch.repository.revision_tree(revision_id)
 
542
 
 
543
            merge.transform_tree(tree, other_tree)
538
544
            if revision_id == _mod_revision.NULL_REVISION:
539
545
                new_parents = []
540
546
            else:
1351
1357
                basis_tree.unlock()
1352
1358
        return conflicts
1353
1359
 
 
1360
    @needs_write_lock
 
1361
    def store_uncommitted(self):
 
1362
        """Store uncommitted changes from the tree in the branch."""
 
1363
        target_tree = self.basis_tree()
 
1364
        shelf_creator = shelf.ShelfCreator(self, target_tree)
 
1365
        try:
 
1366
            if not shelf_creator.shelve_all():
 
1367
                return
 
1368
            self.branch.store_uncommitted(shelf_creator)
 
1369
            shelf_creator.transform()
 
1370
        finally:
 
1371
            shelf_creator.finalize()
 
1372
        note('Uncommitted changes stored in branch "%s".', self.branch.nick)
 
1373
 
 
1374
    @needs_write_lock
 
1375
    def restore_uncommitted(self):
 
1376
        """Restore uncommitted changes from the branch into the tree."""
 
1377
        unshelver = self.branch.get_unshelver(self)
 
1378
        if unshelver is None:
 
1379
            return
 
1380
        try:
 
1381
            merger = unshelver.make_merger()
 
1382
            merger.ignore_zero = True
 
1383
            merger.do_merge()
 
1384
            self.branch.store_uncommitted(None)
 
1385
        finally:
 
1386
            unshelver.finalize()
 
1387
 
1354
1388
    def revision_tree(self, revision_id):
1355
1389
        """See Tree.revision_tree.
1356
1390
 
1974
2008
                # parent tree from the repository.
1975
2009
                self._cache_basis_inventory(leftmost_parent_id)
1976
2010
            else:
1977
 
                inv = leftmost_parent_tree.inventory
 
2011
                inv = leftmost_parent_tree.root_inventory
1978
2012
                xml = self._create_basis_xml_from_inventory(
1979
2013
                                        leftmost_parent_id, inv)
1980
2014
                self._write_basis_inventory(xml)
2084
2118
        return osutils.lexists(self.abspath(path))
2085
2119
 
2086
2120
    def has_or_had_id(self, file_id):
2087
 
        if file_id == self.inventory.root.file_id:
 
2121
        if file_id == self.get_root_id():
2088
2122
            return True
2089
2123
        inv, inv_file_id = self._unpack_file_id(file_id)
2090
2124
        return inv.has_id(inv_file_id)
2160
2194
                _mod_revision.NULL_REVISION)
2161
2195
        else:
2162
2196
            rt = self.branch.repository.revision_tree(revision_ids[0])
2163
 
        self._write_inventory(rt.inventory)
 
2197
        self._write_inventory(rt.root_inventory)
2164
2198
        self.set_parent_ids(revision_ids)
2165
2199
 
2166
2200
    def flush(self):
2221
2255
        # should probably put it back with the previous ID.
2222
2256
        # the read and write working inventory should not occur in this
2223
2257
        # function - they should be part of lock_write and unlock.
2224
 
        inv = self.inventory
 
2258
        # FIXME: nested trees
 
2259
        inv = self.root_inventory
2225
2260
        for f, file_id, kind in zip(files, ids, kinds):
2226
2261
            if file_id is None:
2227
2262
                inv.add_path(f, kind=kind)
2374
2409
        other_tree.lock_tree_write()
2375
2410
        try:
2376
2411
            new_parents = other_tree.get_parent_ids()
2377
 
            other_root = other_tree.inventory.root
 
2412
            other_root = other_tree.root_inventory.root
2378
2413
            other_root.parent_id = new_root_parent
2379
2414
            other_root.name = osutils.basename(other_tree_path)
2380
 
            self.inventory.add(other_root)
2381
 
            add_children(self.inventory, other_root)
2382
 
            self._write_inventory(self.inventory)
 
2415
            self.root_inventory.add(other_root)
 
2416
            add_children(self.root_inventory, other_root)
 
2417
            self._write_inventory(self.root_inventory)
2383
2418
            # normally we don't want to fetch whole repositories, but i think
2384
2419
            # here we really do want to consolidate the whole thing.
2385
2420
            for parent_id in other_tree.get_parent_ids():
2428
2463
            tree_bzrdir = branch_bzrdir
2429
2464
        wt = tree_bzrdir.create_workingtree(_mod_revision.NULL_REVISION)
2430
2465
        wt.set_parent_ids(self.get_parent_ids())
2431
 
        my_inv = self.inventory
 
2466
        # FIXME: Support nested trees
 
2467
        my_inv = self.root_inventory
2432
2468
        child_inv = inventory.Inventory(root_id=None)
2433
2469
        new_root = my_inv[file_id]
2434
2470
        my_inv.remove_recursive_id(file_id)
2455
2491
            raise errors.ObjectNotLocked(self)
2456
2492
 
2457
2493
        if from_dir is None and include_root is True:
2458
 
            yield ('', 'V', 'directory', self.get_root_id(), self.inventory.root)
 
2494
            yield ('', 'V', 'directory', self.get_root_id(), self.root_inventory.root)
2459
2495
        # Convert these into local objects to save lookup times
2460
2496
        pathjoin = osutils.pathjoin
2461
2497
        file_kind = self._kind
2474
2510
                return
2475
2511
            from_dir_abspath = pathjoin(self.basedir, from_dir)
2476
2512
        else:
2477
 
            inv = self.inventory
 
2513
            inv = self.root_inventory
2478
2514
            from_dir_id = inv.root.file_id
2479
2515
            from_dir_abspath = self.basedir
2480
2516
        children = os.listdir(from_dir_abspath)
2603
2639
        rename_entries = []
2604
2640
        rename_tuples = []
2605
2641
 
 
2642
        invs_to_write = set()
 
2643
 
2606
2644
        # check for deprecated use of signature
2607
2645
        if to_dir is None:
2608
2646
            raise TypeError('You must supply a target directory')
2699
2737
                raise errors.BzrRenameFailedError(from_rel,to_rel,
2700
2738
                    errors.NotVersionedError(path=from_rel))
2701
2739
            # put entry back in the inventory so we can rename it
2702
 
            from_entry = basis_tree.inventory[from_id].copy()
 
2740
            from_entry = basis_tree.root_inventory[from_id].copy()
2703
2741
            from_inv.add(from_entry)
2704
2742
        else:
2705
2743
            from_inv, from_inv_id = self._unpack_file_id(from_id)
2756
2794
 
2757
2795
        Also does basic plausability tests.
2758
2796
        """
2759
 
        inv = self.inventory
 
2797
        # FIXME: Handling of nested trees
 
2798
        inv = self.root_inventory
2760
2799
 
2761
2800
        for rename_entry in rename_entries:
2762
2801
            # store to local variables for easier reference
2846
2885
                        " Error message is: %s" % e)
2847
2886
 
2848
2887
    def _move_entry(self, entry):
2849
 
        inv = self.inventory
 
2888
        inv = self.root_inventory
2850
2889
        from_rel_abs = self.abspath(entry.from_rel)
2851
2890
        to_rel_abs = self.abspath(entry.to_rel)
2852
2891
        if from_rel_abs == to_rel_abs:
2907
2946
        This is the same order used by 'osutils.walkdirs'.
2908
2947
        """
2909
2948
        ## TODO: Work from given directory downwards
2910
 
        for path, dir_entry in self.inventory.directories():
 
2949
        for path, dir_entry in self.iter_entries_by_dir():
 
2950
            if dir_entry.kind != 'directory':
 
2951
                continue
2911
2952
            # mutter("search for unknowns in %r", path)
2912
2953
            dirabs = self.abspath(path)
2913
2954
            if not isdir(dirabs):
3071
3112
    def __ne__(self, other):
3072
3113
        return not (self == other)
3073
3114
 
3074
 
    @classmethod
3075
 
    @symbol_versioning.deprecated_method(
3076
 
        symbol_versioning.deprecated_in((2, 4, 0)))
3077
 
    def get_default_format(klass):
3078
 
        """Return the current default format."""
3079
 
        return format_registry.get_default()
3080
 
 
3081
3115
    def get_format_description(self):
3082
3116
        """Return the short description for this format."""
3083
3117
        raise NotImplementedError(self.get_format_description)
3099
3133
        """True if this format supports stored views."""
3100
3134
        return False
3101
3135
 
3102
 
    @classmethod
3103
 
    @symbol_versioning.deprecated_method(
3104
 
        symbol_versioning.deprecated_in((2, 4, 0)))
3105
 
    def register_format(klass, format):
3106
 
        format_registry.register(format)
3107
 
 
3108
 
    @classmethod
3109
 
    @symbol_versioning.deprecated_method(
3110
 
        symbol_versioning.deprecated_in((2, 4, 0)))
3111
 
    def register_extra_format(klass, format):
3112
 
        format_registry.register_extra(format)
3113
 
 
3114
 
    @classmethod
3115
 
    @symbol_versioning.deprecated_method(
3116
 
        symbol_versioning.deprecated_in((2, 4, 0)))
3117
 
    def unregister_extra_format(klass, format):
3118
 
        format_registry.unregister_extra(format)
3119
 
 
3120
 
    @classmethod
3121
 
    @symbol_versioning.deprecated_method(
3122
 
        symbol_versioning.deprecated_in((2, 4, 0)))
3123
 
    def get_formats(klass):
3124
 
        return format_registry._get_all()
3125
 
 
3126
 
    @classmethod
3127
 
    @symbol_versioning.deprecated_method(
3128
 
        symbol_versioning.deprecated_in((2, 4, 0)))
3129
 
    def set_default_format(klass, format):
3130
 
        format_registry.set_default(format)
3131
 
 
3132
 
    @classmethod
3133
 
    @symbol_versioning.deprecated_method(
3134
 
        symbol_versioning.deprecated_in((2, 4, 0)))
3135
 
    def unregister_format(klass, format):
3136
 
        format_registry.remove(format)
 
3136
    def get_controldir_for_branch(self):
 
3137
        """Get the control directory format for creating branches.
 
3138
 
 
3139
        This is to support testing of working tree formats that can not exist
 
3140
        in the same control directory as a branch.
 
3141
        """
 
3142
        return self._matchingbzrdir
 
3143
 
 
3144
 
 
3145
class WorkingTreeFormatMetaDir(bzrdir.BzrFormat, WorkingTreeFormat):
 
3146
    """Base class for working trees that live in bzr meta directories."""
 
3147
 
 
3148
    def __init__(self):
 
3149
        WorkingTreeFormat.__init__(self)
 
3150
        bzrdir.BzrFormat.__init__(self)
 
3151
 
 
3152
    @classmethod
 
3153
    def find_format_string(klass, controldir):
 
3154
        """Return format name for the working tree object in controldir."""
 
3155
        try:
 
3156
            transport = controldir.get_workingtree_transport(None)
 
3157
            return transport.get_bytes("format")
 
3158
        except errors.NoSuchFile:
 
3159
            raise errors.NoWorkingTree(base=transport.base)
 
3160
 
 
3161
    @classmethod
 
3162
    def find_format(klass, controldir):
 
3163
        """Return the format for the working tree object in controldir."""
 
3164
        format_string = klass.find_format_string(controldir)
 
3165
        return klass._find_format(format_registry, 'working tree',
 
3166
                format_string)
 
3167
 
 
3168
    def check_support_status(self, allow_unsupported, recommend_upgrade=True,
 
3169
            basedir=None):
 
3170
        WorkingTreeFormat.check_support_status(self,
 
3171
            allow_unsupported=allow_unsupported, recommend_upgrade=recommend_upgrade,
 
3172
            basedir=basedir)
 
3173
        bzrdir.BzrFormat.check_support_status(self, allow_unsupported=allow_unsupported,
 
3174
            recommend_upgrade=recommend_upgrade, basedir=basedir)
3137
3175
 
3138
3176
    def get_controldir_for_branch(self):
3139
3177
        """Get the control directory format for creating branches.