72
from bzrlib import symbol_versioning
72
# Explicitly import bzrlib.bzrdir so that the BzrProber
73
# is guaranteed to be registered.
73
79
from bzrlib.decorators import needs_read_lock, needs_write_lock
74
80
from bzrlib.i18n import gettext
75
81
from bzrlib.lock import LogicalLockResult
228
233
"""See `Tree.has_versioned_directories`."""
229
234
return self._format.supports_versioned_directories
236
def _supports_executable(self):
237
if sys.platform == 'win32':
239
# FIXME: Ideally this should check the file system
231
242
def break_lock(self):
232
243
"""Break a lock if one is present from another instance.
259
270
path = osutils.getcwd()
260
control = controldir.ControlDir.open(path, _unsupported)
261
return control.open_workingtree(_unsupported)
271
control = controldir.ControlDir.open(path, _unsupported=_unsupported)
272
return control.open_workingtree(unsupported=_unsupported)
264
275
def open_containing(path=None):
1113
1124
mode = stat_value.st_mode
1114
1125
kind = osutils.file_kind_from_stat_mode(mode)
1115
if not supports_executable():
1126
if not self._supports_executable():
1116
1127
executable = entry is not None and entry.executable
1118
1129
executable = bool(stat.S_ISREG(mode) and stat.S_IEXEC & mode)
2187
2198
mode = stat_result.st_mode
2188
2199
return bool(stat.S_ISREG(mode) and stat.S_IEXEC & mode)
2190
if not supports_executable():
2191
def is_executable(self, file_id, path=None):
2201
def is_executable(self, file_id, path=None):
2202
if not self._supports_executable():
2192
2203
return self._inventory[file_id].executable
2194
_is_executable_from_path_and_stat = \
2195
_is_executable_from_path_and_stat_from_basis
2197
def is_executable(self, file_id, path=None):
2199
2206
path = self.id2path(file_id)
2200
2207
mode = os.lstat(self.abspath(path)).st_mode
2201
2208
return bool(stat.S_ISREG(mode) and stat.S_IEXEC & mode)
2203
_is_executable_from_path_and_stat = \
2204
_is_executable_from_path_and_stat_from_stat
2210
def _is_executable_from_path_and_stat(self, path, stat_result):
2211
if not self._supports_executable():
2212
return self._is_executable_from_path_and_stat_from_basis(path, stat_result)
2214
return self._is_executable_from_path_and_stat_from_stat(path, stat_result)
2206
2216
@needs_tree_write_lock
2207
2217
def _add(self, files, ids, kinds):
2410
2420
tree_transport = self.bzrdir.root_transport.clone(sub_path)
2411
2421
if tree_transport.base != branch_transport.base:
2412
2422
tree_bzrdir = format.initialize_on_transport(tree_transport)
2413
branch.BranchReferenceFormat().initialize(tree_bzrdir,
2414
target_branch=new_branch)
2423
tree_bzrdir.set_branch_reference(new_branch)
2416
2425
tree_bzrdir = branch_bzrdir
2417
2426
wt = tree_bzrdir.create_workingtree(_mod_revision.NULL_REVISION)
2795
2804
# something is wrong, so lets determine what exactly
2796
2805
if not self.has_filename(from_rel) and \
2797
2806
not self.has_filename(to_rel):
2798
raise errors.BzrRenameFailedError(from_rel,to_rel,
2799
errors.PathsDoNotExist(paths=(str(from_rel),
2807
raise errors.BzrRenameFailedError(from_rel, to_rel,
2808
errors.PathsDoNotExist(paths=(from_rel, to_rel)))
2802
2810
raise errors.RenameFailedFilesExist(from_rel, to_rel)
2803
2811
rename_entry.only_change_inv = only_change_inv
2968
2976
if dir[2] == _directory:
2969
2977
pending.append(dir)
2980
def update_feature_flags(self, updated_flags):
2981
"""Update the feature flags for this branch.
2983
:param updated_flags: Dictionary mapping feature names to necessities
2984
A necessity can be None to indicate the feature should be removed
2986
self._format._update_feature_flags(updated_flags)
2987
self.control_transport.put_bytes('format', self._format.as_string())
2972
2990
class WorkingTreeFormatRegistry(controldir.ControlComponentFormatRegistry):
2973
2991
"""Registry for working tree formats."""
3030
3048
supports_versioned_directories = None
3033
def find_format_string(klass, controldir):
3034
"""Return format name for the working tree object in controldir."""
3036
transport = controldir.get_workingtree_transport(None)
3037
return transport.get_bytes("format")
3038
except errors.NoSuchFile:
3039
raise errors.NoWorkingTree(base=transport.base)
3042
def find_format(klass, controldir):
3043
"""Return the format for the working tree object in controldir."""
3045
format_string = klass.find_format_string(controldir)
3046
return format_registry.get(format_string)
3048
raise errors.UnknownFormatError(format=format_string,
3049
kind="working tree")
3051
3050
def initialize(self, controldir, revision_id=None, from_branch=None,
3052
3051
accelerator_tree=None, hardlink=False):
3053
3052
"""Initialize a new working tree in controldir.
3078
3077
"""Return the current default format."""
3079
3078
return format_registry.get_default()
3081
def get_format_string(self):
3082
"""Return the ASCII format string that identifies this format."""
3083
raise NotImplementedError(self.get_format_string)
3085
3080
def get_format_description(self):
3086
3081
"""Return the short description for this format."""
3087
3082
raise NotImplementedError(self.get_format_description)
3148
3143
return self._matchingbzrdir
3146
class WorkingTreeFormatMetaDir(bzrdir.BzrFormat, WorkingTreeFormat):
3147
"""Base class for working trees that live in bzr meta directories."""
3150
WorkingTreeFormat.__init__(self)
3151
bzrdir.BzrFormat.__init__(self)
3154
def find_format_string(klass, controldir):
3155
"""Return format name for the working tree object in controldir."""
3157
transport = controldir.get_workingtree_transport(None)
3158
return transport.get_bytes("format")
3159
except errors.NoSuchFile:
3160
raise errors.NoWorkingTree(base=transport.base)
3163
def find_format(klass, controldir):
3164
"""Return the format for the working tree object in controldir."""
3165
format_string = klass.find_format_string(controldir)
3166
return klass._find_format(format_registry, 'working tree',
3169
def check_support_status(self, allow_unsupported, recommend_upgrade=True,
3171
WorkingTreeFormat.check_support_status(self,
3172
allow_unsupported=allow_unsupported, recommend_upgrade=recommend_upgrade,
3174
bzrdir.BzrFormat.check_support_status(self, allow_unsupported=allow_unsupported,
3175
recommend_upgrade=recommend_upgrade, basedir=basedir)
3151
3178
format_registry.register_lazy("Bazaar Working Tree Format 4 (bzr 0.15)\n",
3152
3179
"bzrlib.workingtree_4", "WorkingTreeFormat4")
3153
3180
format_registry.register_lazy("Bazaar Working Tree Format 5 (bzr 1.11)\n",