262
261
def supports_views(self):
263
262
return self.views.supports_views()
265
def get_config_stack(self):
266
"""Retrieve the config stack for this tree.
268
:return: A ``bzrlib.config.Stack``
270
# For the moment, just provide the branch config stack.
271
return self.branch.get_config_stack()
274
265
def open(path=None, _unsupported=False):
275
266
"""Open an existing working tree at path.
1357
1347
basis_tree.unlock()
1358
1348
return conflicts
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)
1366
if not shelf_creator.shelve_all():
1368
self.branch.store_uncommitted(shelf_creator)
1369
shelf_creator.transform()
1371
shelf_creator.finalize()
1372
note('Uncommitted changes stored in branch "%s".', self.branch.nick)
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:
1381
merger = unshelver.make_merger()
1382
merger.ignore_zero = True
1384
self.branch.store_uncommitted(None)
1386
unshelver.finalize()
1388
1350
def revision_tree(self, revision_id):
1389
1351
"""See Tree.revision_tree.
2112
2078
def has_id(self, file_id):
2113
2079
# files that have been deleted are excluded
2114
inv, inv_file_id = self._unpack_file_id(file_id)
2115
if not inv.has_id(inv_file_id):
2080
inv = self.inventory
2081
if not inv.has_id(file_id):
2117
path = inv.id2path(inv_file_id)
2083
path = inv.id2path(file_id)
2118
2084
return osutils.lexists(self.abspath(path))
2120
2086
def has_or_had_id(self, file_id):
2121
if file_id == self.get_root_id():
2087
if file_id == self.inventory.root.file_id:
2123
inv, inv_file_id = self._unpack_file_id(file_id)
2124
return inv.has_id(inv_file_id)
2089
return self.inventory.has_id(file_id)
2126
def all_file_ids(self):
2091
@symbol_versioning.deprecated_method(symbol_versioning.deprecated_in((2, 4, 0)))
2127
2093
"""Iterate through file_ids for this tree.
2129
2095
file_ids are in a WorkingTree if they are in the working inventory
2130
2096
and the working file exists.
2133
for path, ie in self.iter_entries_by_dir():
2098
inv = self._inventory
2099
for path, ie in inv.iter_entries():
2100
if osutils.lexists(self.abspath(path)):
2137
2103
@needs_tree_write_lock
2138
2104
def set_last_revision(self, new_revision):
2223
2189
def _is_executable_from_path_and_stat_from_basis(self, path, stat_result):
2224
inv, file_id = self._path2inv_file_id(path)
2190
file_id = self.path2id(path)
2225
2191
if file_id is None:
2226
2192
# For unversioned files on win32, we just assume they are not
2229
return inv[file_id].executable
2195
return self._inventory[file_id].executable
2231
2197
def _is_executable_from_path_and_stat_from_stat(self, path, stat_result):
2232
2198
mode = stat_result.st_mode
2303
2267
parent_tree = self.branch.repository.revision_tree(parent_id)
2304
2268
parent_tree.lock_read()
2307
kind = parent_tree.kind(file_id)
2308
except errors.NoSuchId:
2270
if not parent_tree.has_id(file_id):
2272
ie = parent_tree.inventory[file_id]
2273
if ie.kind != 'file':
2311
2274
# Note: this is slightly unnecessary, because symlinks and
2312
2275
# directories have a "text" which is the empty text, and we
2313
2276
# know that won't mess up annotations. But it seems cleaner
2316
file_id, parent_tree.get_file_revision(file_id))
2278
parent_text_key = (file_id, ie.revision)
2317
2279
if parent_text_key not in maybe_file_parent_keys:
2318
2280
maybe_file_parent_keys.append(parent_text_key)
2409
2371
other_tree.lock_tree_write()
2411
2373
new_parents = other_tree.get_parent_ids()
2412
other_root = other_tree.root_inventory.root
2374
other_root = other_tree.inventory.root
2413
2375
other_root.parent_id = new_root_parent
2414
2376
other_root.name = osutils.basename(other_tree_path)
2415
self.root_inventory.add(other_root)
2416
add_children(self.root_inventory, other_root)
2417
self._write_inventory(self.root_inventory)
2377
self.inventory.add(other_root)
2378
add_children(self.inventory, other_root)
2379
self._write_inventory(self.inventory)
2418
2380
# normally we don't want to fetch whole repositories, but i think
2419
2381
# here we really do want to consolidate the whole thing.
2420
2382
for parent_id in other_tree.get_parent_ids():
2490
2451
if not self.is_locked():
2491
2452
raise errors.ObjectNotLocked(self)
2454
inv = self.inventory
2493
2455
if from_dir is None and include_root is True:
2494
yield ('', 'V', 'directory', self.get_root_id(), self.root_inventory.root)
2456
yield ('', 'V', 'directory', inv.root.file_id, inv.root)
2495
2457
# Convert these into local objects to save lookup times
2496
2458
pathjoin = osutils.pathjoin
2497
2459
file_kind = self._kind
2505
2467
# directory file_id, relative path, absolute path, reverse sorted children
2506
2468
if from_dir is not None:
2507
inv, from_dir_id = self._path2inv_file_id(from_dir)
2469
from_dir_id = inv.path2id(from_dir)
2508
2470
if from_dir_id is None:
2509
2471
# Directory not versioned
2511
2473
from_dir_abspath = pathjoin(self.basedir, from_dir)
2513
inv = self.root_inventory
2514
2475
from_dir_id = inv.root.file_id
2515
2476
from_dir_abspath = self.basedir
2516
2477
children = os.listdir(from_dir_abspath)
2654
2614
if not self.has_filename(to_dir):
2655
2615
raise errors.BzrMoveFailedError('',to_dir,
2656
2616
errors.NotInWorkingDirectory(to_dir))
2657
to_inv, to_dir_id = self._path2inv_file_id(to_dir)
2617
to_dir_id = inv.path2id(to_dir)
2658
2618
if to_dir_id is None:
2659
2619
raise errors.BzrMoveFailedError('',to_dir,
2660
2620
errors.NotVersionedError(path=to_dir))
2662
to_dir_ie = to_inv[to_dir_id]
2622
to_dir_ie = inv[to_dir_id]
2663
2623
if to_dir_ie.kind != 'directory':
2664
2624
raise errors.BzrMoveFailedError('',to_dir,
2665
2625
errors.NotADirectory(to_abs))
2667
2627
# create rename entries and tuples
2668
2628
for from_rel in from_paths:
2669
2629
from_tail = splitpath(from_rel)[-1]
2670
from_inv, from_id = self._path2inv_file_id(from_rel)
2630
from_id = inv.path2id(from_rel)
2671
2631
if from_id is None:
2672
2632
raise errors.BzrMoveFailedError(from_rel,to_dir,
2673
2633
errors.NotVersionedError(path=from_rel))
2675
from_entry = from_inv[from_id]
2635
from_entry = inv[from_id]
2676
2636
from_parent_id = from_entry.parent_id
2677
2637
to_rel = pathjoin(to_dir, from_tail)
2678
2638
rename_entry = InventoryWorkingTree._RenameEntry(
2737
2697
raise errors.BzrRenameFailedError(from_rel,to_rel,
2738
2698
errors.NotVersionedError(path=from_rel))
2739
2699
# put entry back in the inventory so we can rename it
2740
from_entry = basis_tree.root_inventory[from_id].copy()
2741
from_inv.add(from_entry)
2700
from_entry = basis_tree.inventory[from_id].copy()
2743
from_inv, from_inv_id = self._unpack_file_id(from_id)
2744
from_entry = from_inv[from_inv_id]
2703
from_entry = inv[from_id]
2745
2704
from_parent_id = from_entry.parent_id
2746
2705
to_dir, to_tail = os.path.split(to_rel)
2747
to_inv, to_dir_id = self._path2inv_file_id(to_dir)
2706
to_dir_id = inv.path2id(to_dir)
2748
2707
rename_entry = InventoryWorkingTree._RenameEntry(from_rel=from_rel,
2749
2708
from_id=from_id,
2750
2709
from_tail=from_tail,
2772
2731
from_id, from_rel, to_rel, to_dir, to_dir_id)
2774
2733
self._move(rename_entries)
2775
self._write_inventory(to_inv)
2734
self._write_inventory(inv)
2777
2736
class _RenameEntry(object):
2778
2737
def __init__(self, from_rel, from_id, from_tail, from_parent_id,
3112
3070
def __ne__(self, other):
3113
3071
return not (self == other)
3074
@symbol_versioning.deprecated_method(
3075
symbol_versioning.deprecated_in((2, 4, 0)))
3076
def get_default_format(klass):
3077
"""Return the current default format."""
3078
return format_registry.get_default()
3115
3080
def get_format_description(self):
3116
3081
"""Return the short description for this format."""
3117
3082
raise NotImplementedError(self.get_format_description)
3133
3098
"""True if this format supports stored views."""
3136
def get_controldir_for_branch(self):
3137
"""Get the control directory format for creating branches.
3139
This is to support testing of working tree formats that can not exist
3140
in the same control directory as a branch.
3142
return self._matchingbzrdir
3145
class WorkingTreeFormatMetaDir(bzrdir.BzrFormat, WorkingTreeFormat):
3146
"""Base class for working trees that live in bzr meta directories."""
3149
WorkingTreeFormat.__init__(self)
3150
bzrdir.BzrFormat.__init__(self)
3153
def find_format_string(klass, controldir):
3154
"""Return format name for the working tree object in controldir."""
3156
transport = controldir.get_workingtree_transport(None)
3157
return transport.get_bytes("format")
3158
except errors.NoSuchFile:
3159
raise errors.NoWorkingTree(base=transport.base)
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',
3168
def check_support_status(self, allow_unsupported, recommend_upgrade=True,
3170
WorkingTreeFormat.check_support_status(self,
3171
allow_unsupported=allow_unsupported, recommend_upgrade=recommend_upgrade,
3173
bzrdir.BzrFormat.check_support_status(self, allow_unsupported=allow_unsupported,
3174
recommend_upgrade=recommend_upgrade, basedir=basedir)
3102
@symbol_versioning.deprecated_method(
3103
symbol_versioning.deprecated_in((2, 4, 0)))
3104
def register_format(klass, format):
3105
format_registry.register(format)
3108
@symbol_versioning.deprecated_method(
3109
symbol_versioning.deprecated_in((2, 4, 0)))
3110
def register_extra_format(klass, format):
3111
format_registry.register_extra(format)
3114
@symbol_versioning.deprecated_method(
3115
symbol_versioning.deprecated_in((2, 4, 0)))
3116
def unregister_extra_format(klass, format):
3117
format_registry.unregister_extra(format)
3120
@symbol_versioning.deprecated_method(
3121
symbol_versioning.deprecated_in((2, 4, 0)))
3122
def get_formats(klass):
3123
return format_registry._get_all()
3126
@symbol_versioning.deprecated_method(
3127
symbol_versioning.deprecated_in((2, 4, 0)))
3128
def set_default_format(klass, format):
3129
format_registry.set_default(format)
3132
@symbol_versioning.deprecated_method(
3133
symbol_versioning.deprecated_in((2, 4, 0)))
3134
def unregister_format(klass, format):
3135
format_registry.remove(format)
3176
3137
def get_controldir_for_branch(self):
3177
3138
"""Get the control directory format for creating branches.