1169
1155
:return: A bzrlib.lock.LogicalLockResult.
1171
raise NotImplementedError(self.lock_read)
1157
if not self.is_locked():
1159
self.branch.lock_read()
1161
self._control_files.lock_read()
1162
return LogicalLockResult(self.unlock)
1164
self.branch.unlock()
1173
1167
def lock_tree_write(self):
1174
1168
"""See MutableTree.lock_tree_write, and WorkingTree.unlock.
1176
1170
:return: A bzrlib.lock.LogicalLockResult.
1178
raise NotImplementedError(self.lock_tree_write)
1172
if not self.is_locked():
1174
self.branch.lock_read()
1176
self._control_files.lock_write()
1177
return LogicalLockResult(self.unlock)
1179
self.branch.unlock()
1180
1182
def lock_write(self):
1181
1183
"""See MutableTree.lock_write, and WorkingTree.unlock.
1183
1185
:return: A bzrlib.lock.LogicalLockResult.
1185
raise NotImplementedError(self.lock_write)
1187
if not self.is_locked():
1189
self.branch.lock_write()
1191
self._control_files.lock_write()
1192
return LogicalLockResult(self.unlock)
1194
self.branch.unlock()
1187
1197
def get_physical_lock_status(self):
1188
raise NotImplementedError(self.get_physical_lock_status)
1198
return self._control_files.get_physical_lock_status()
1200
def _reset_data(self):
1201
"""Reset transient data that cannot be revalidated."""
1202
raise NotImplementedError(self._reset_data)
1190
1204
def set_last_revision(self, new_revision):
1191
1205
"""Change the last revision in the working tree."""
1357
1371
basis_tree.unlock()
1358
1372
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
1374
def revision_tree(self, revision_id):
1389
1375
"""See Tree.revision_tree.
1843
1828
def _deserialize(selt, in_file):
1844
1829
return xml5.serializer_v5.read_inventory(in_file)
1846
def break_lock(self):
1847
"""Break a lock if one is present from another instance.
1849
Uses the ui factory to ask for confirmation if the lock may be from
1852
This will probe the repository for its lock as well.
1854
self._control_files.break_lock()
1855
self.branch.break_lock()
1857
def is_locked(self):
1858
return self._control_files.is_locked()
1860
def _must_be_locked(self):
1861
if not self.is_locked():
1862
raise errors.ObjectNotLocked(self)
1864
def lock_read(self):
1865
"""Lock the tree for reading.
1867
This also locks the branch, and can be unlocked via self.unlock().
1869
:return: A bzrlib.lock.LogicalLockResult.
1871
if not self.is_locked():
1873
self.branch.lock_read()
1875
self._control_files.lock_read()
1876
return LogicalLockResult(self.unlock)
1878
self.branch.unlock()
1881
def lock_tree_write(self):
1882
"""See MutableTree.lock_tree_write, and WorkingTree.unlock.
1884
:return: A bzrlib.lock.LogicalLockResult.
1886
if not self.is_locked():
1888
self.branch.lock_read()
1890
self._control_files.lock_write()
1891
return LogicalLockResult(self.unlock)
1893
self.branch.unlock()
1896
def lock_write(self):
1897
"""See MutableTree.lock_write, and WorkingTree.unlock.
1899
:return: A bzrlib.lock.LogicalLockResult.
1901
if not self.is_locked():
1903
self.branch.lock_write()
1905
self._control_files.lock_write()
1906
return LogicalLockResult(self.unlock)
1908
self.branch.unlock()
1911
def get_physical_lock_status(self):
1912
return self._control_files.get_physical_lock_status()
1914
1831
@needs_tree_write_lock
1915
1832
def _write_inventory(self, inv):
1916
1833
"""Write inventory as the current inventory."""
2112
2033
def has_id(self, file_id):
2113
2034
# 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):
2035
inv = self.inventory
2036
if not inv.has_id(file_id):
2117
path = inv.id2path(inv_file_id)
2038
path = inv.id2path(file_id)
2118
2039
return osutils.lexists(self.abspath(path))
2120
2041
def has_or_had_id(self, file_id):
2121
if file_id == self.get_root_id():
2042
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)
2044
return self.inventory.has_id(file_id)
2126
def all_file_ids(self):
2046
@symbol_versioning.deprecated_method(symbol_versioning.deprecated_in((2, 4, 0)))
2127
2048
"""Iterate through file_ids for this tree.
2129
2050
file_ids are in a WorkingTree if they are in the working inventory
2130
2051
and the working file exists.
2133
for path, ie in self.iter_entries_by_dir():
2053
inv = self._inventory
2054
for path, ie in inv.iter_entries():
2055
if osutils.lexists(self.abspath(path)):
2137
2058
@needs_tree_write_lock
2138
2059
def set_last_revision(self, new_revision):
2223
2144
def _is_executable_from_path_and_stat_from_basis(self, path, stat_result):
2224
inv, file_id = self._path2inv_file_id(path)
2145
file_id = self.path2id(path)
2225
2146
if file_id is None:
2226
2147
# For unversioned files on win32, we just assume they are not
2229
return inv[file_id].executable
2150
return self._inventory[file_id].executable
2231
2152
def _is_executable_from_path_and_stat_from_stat(self, path, stat_result):
2232
2153
mode = stat_result.st_mode
2233
2154
return bool(stat.S_ISREG(mode) and stat.S_IEXEC & mode)
2235
def is_executable(self, file_id, path=None):
2236
if not self._supports_executable():
2237
inv, inv_file_id = self._unpack_file_id(file_id)
2238
return inv[inv_file_id].executable
2156
if not supports_executable():
2157
def is_executable(self, file_id, path=None):
2158
return self._inventory[file_id].executable
2160
_is_executable_from_path_and_stat = \
2161
_is_executable_from_path_and_stat_from_basis
2163
def is_executable(self, file_id, path=None):
2241
2165
path = self.id2path(file_id)
2242
2166
mode = os.lstat(self.abspath(path)).st_mode
2243
2167
return bool(stat.S_ISREG(mode) and stat.S_IEXEC & mode)
2245
def _is_executable_from_path_and_stat(self, path, stat_result):
2246
if not self._supports_executable():
2247
return self._is_executable_from_path_and_stat_from_basis(path, stat_result)
2249
return self._is_executable_from_path_and_stat_from_stat(path, stat_result)
2169
_is_executable_from_path_and_stat = \
2170
_is_executable_from_path_and_stat_from_stat
2251
2172
@needs_tree_write_lock
2252
2173
def _add(self, files, ids, kinds):
3090
2982
supports_versioned_directories = None
3092
def initialize(self, controldir, revision_id=None, from_branch=None,
2985
def find_format_string(klass, a_bzrdir):
2986
"""Return format name for the working tree object in a_bzrdir."""
2988
transport = a_bzrdir.get_workingtree_transport(None)
2989
return transport.get_bytes("format")
2990
except errors.NoSuchFile:
2991
raise errors.NoWorkingTree(base=transport.base)
2994
def find_format(klass, a_bzrdir):
2995
"""Return the format for the working tree object in a_bzrdir."""
2997
format_string = klass.find_format_string(a_bzrdir)
2998
return format_registry.get(format_string)
3000
raise errors.UnknownFormatError(format=format_string,
3001
kind="working tree")
3003
def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
3093
3004
accelerator_tree=None, hardlink=False):
3094
"""Initialize a new working tree in controldir.
3005
"""Initialize a new working tree in a_bzrdir.
3096
:param controldir: ControlDir to initialize the working tree in.
3007
:param a_bzrdir: BzrDir to initialize the working tree in.
3097
3008
:param revision_id: allows creating a working tree at a different
3098
3009
revision than the branch is at.
3099
3010
:param from_branch: Branch to checkout
3133
3055
"""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)
3176
def get_controldir_for_branch(self):
3177
"""Get the control directory format for creating branches.
3179
This is to support testing of working tree formats that can not exist
3180
in the same control directory as a branch.
3182
return self._matchingbzrdir
3185
class WorkingTreeFormatMetaDir(bzrdir.BzrFormat, WorkingTreeFormat):
3186
"""Base class for working trees that live in bzr meta directories."""
3189
WorkingTreeFormat.__init__(self)
3190
bzrdir.BzrFormat.__init__(self)
3193
def find_format_string(klass, controldir):
3194
"""Return format name for the working tree object in controldir."""
3196
transport = controldir.get_workingtree_transport(None)
3197
return transport.get_bytes("format")
3198
except errors.NoSuchFile:
3199
raise errors.NoWorkingTree(base=transport.base)
3202
def find_format(klass, controldir):
3203
"""Return the format for the working tree object in controldir."""
3204
format_string = klass.find_format_string(controldir)
3205
return klass._find_format(format_registry, 'working tree',
3208
def check_support_status(self, allow_unsupported, recommend_upgrade=True,
3210
WorkingTreeFormat.check_support_status(self,
3211
allow_unsupported=allow_unsupported, recommend_upgrade=recommend_upgrade,
3213
bzrdir.BzrFormat.check_support_status(self, allow_unsupported=allow_unsupported,
3214
recommend_upgrade=recommend_upgrade, basedir=basedir)
3059
@symbol_versioning.deprecated_method(
3060
symbol_versioning.deprecated_in((2, 4, 0)))
3061
def register_format(klass, format):
3062
format_registry.register(format)
3065
@symbol_versioning.deprecated_method(
3066
symbol_versioning.deprecated_in((2, 4, 0)))
3067
def register_extra_format(klass, format):
3068
format_registry.register_extra(format)
3071
@symbol_versioning.deprecated_method(
3072
symbol_versioning.deprecated_in((2, 4, 0)))
3073
def unregister_extra_format(klass, format):
3074
format_registry.unregister_extra(format)
3077
@symbol_versioning.deprecated_method(
3078
symbol_versioning.deprecated_in((2, 4, 0)))
3079
def get_formats(klass):
3080
return format_registry._get_all()
3083
@symbol_versioning.deprecated_method(
3084
symbol_versioning.deprecated_in((2, 4, 0)))
3085
def set_default_format(klass, format):
3086
format_registry.set_default(format)
3089
@symbol_versioning.deprecated_method(
3090
symbol_versioning.deprecated_in((2, 4, 0)))
3091
def unregister_format(klass, format):
3092
format_registry.remove(format)
3094
def get_controldir_for_branch(self):
3095
"""Get the control directory format for creating branches.
3097
This is to support testing of working tree formats that can not exist
3098
in the same control directory as a branch.
3100
return self._matchingbzrdir
3217
3103
format_registry.register_lazy("Bazaar Working Tree Format 4 (bzr 0.15)\n",