99
99
from bzrlib.trace import mutter, note
100
100
from bzrlib.transport import get_transport
101
101
from bzrlib.transport.local import LocalTransport
102
import bzrlib.urlutils as urlutils
103
104
import bzrlib.xml5
279
280
# if needed, or, when the cache sees a change, append it to the hash
280
281
# cache file, and have the parser take the most recent entry for a
281
282
# given path only.
282
cache_filename = self.bzrdir.get_workingtree_transport(None).abspath('stat-cache')
283
cache_filename = self.bzrdir.get_workingtree_transport(None).local_abspath('stat-cache')
283
284
hc = self._hashcache = HashCache(basedir, cache_filename, self._control_files._file_mode)
285
286
# is this scan needed ? it makes things kinda slow.
349
350
run into /. If there isn't one, raises NotBranchError.
350
351
TODO: give this a new exception.
351
352
If there is one, it is returned, along with the unused portion of path.
354
:return: The WorkingTree that contains 'path', and the rest of path
354
357
path = os.getcwdu()
355
358
control, relpath = bzrdir.BzrDir.open_containing(path)
356
360
return control.open_workingtree(), relpath
536
540
path = self._inventory.id2path(file_id)
537
541
return self._hashcache.get_sha1(path)
543
def get_file_mtime(self, file_id, path=None):
545
path = self._inventory.id2path(file_id)
546
return os.lstat(self.abspath(path)).st_mtime
539
548
if not supports_executable():
540
549
def is_executable(self, file_id, path=None):
541
550
return self._inventory[file_id].executable
1080
1089
l = bzrlib.DEFAULT_IGNORE[:]
1081
1090
if self.has_filename(bzrlib.IGNORE_FILENAME):
1082
1091
f = self.get_file_byname(bzrlib.IGNORE_FILENAME)
1083
l.extend([line.rstrip("\n\r") for line in f.readlines()])
1092
l.extend([line.rstrip("\n\r").decode('utf-8')
1093
for line in f.readlines()])
1084
1094
self._ignorelist = l
1085
1095
self._ignore_regex = self._combine_ignore_rules(l)
1193
1203
def _cache_basis_inventory(self, new_revision):
1194
1204
"""Cache new_revision as the basis inventory."""
1205
# TODO: this should allow the ready-to-use inventory to be passed in,
1206
# as commit already has that ready-to-use [while the format is the
1196
1209
# this double handles the inventory - unpack and repack -
1197
1210
# but is easier to understand. We can/should put a conditional
1198
1211
# in here based on whether the inventory is in the latest format
1199
1212
# - perhaps we should repack all inventories on a repository
1201
inv = self.branch.repository.get_inventory(new_revision)
1202
inv.revision_id = new_revision
1203
xml = bzrlib.xml5.serializer_v5.write_inventory_to_string(inv)
1214
# the fast path is to copy the raw xml from the repository. If the
1215
# xml contains 'revision_id="', then we assume the right
1216
# revision_id is set. We must check for this full string, because a
1217
# root node id can legitimately look like 'revision_id' but cannot
1219
xml = self.branch.repository.get_inventory_xml(new_revision)
1220
if not 'revision_id="' in xml.split('\n', 1)[0]:
1221
inv = self.branch.repository.deserialise_inventory(
1223
inv.revision_id = new_revision
1224
xml = bzrlib.xml5.serializer_v5.write_inventory_to_string(inv)
1205
1226
path = self._basis_inventory_name()
1206
1227
self._control_files.put_utf8(path, xml)
1225
1246
@needs_write_lock
1226
def remove(self, files, verbose=False):
1247
def remove(self, files, verbose=False, to_file=None):
1227
1248
"""Remove nominated files from the working inventory..
1229
1250
This does not remove their text. This does not run on XXX on what? RBC
1258
1279
new_status = 'I'
1260
1281
new_status = '?'
1261
show_status(new_status, inv[fid].kind, quotefn(f))
1282
show_status(new_status, inv[fid].kind, quotefn(f), to_file=to_file)
1264
1285
self._write_inventory(inv)
1649
1670
branch.unlock()
1650
1671
revision = branch.last_revision()
1651
1672
inv = Inventory(root_id=gen_root_id())
1652
wt = WorkingTree(a_bzrdir.root_transport.base,
1673
wt = WorkingTree(a_bzrdir.root_transport.local_abspath('.'),
1655
1676
_internal=True,
1679
1700
raise NotImplementedError
1680
1701
if not isinstance(a_bzrdir.transport, LocalTransport):
1681
1702
raise errors.NotLocalUrl(a_bzrdir.transport.base)
1682
return WorkingTree(a_bzrdir.root_transport.base,
1703
return WorkingTree(a_bzrdir.root_transport.local_abspath('.'),
1683
1704
_internal=True,
1685
1706
_bzrdir=a_bzrdir)
1730
1751
if revision_id is None:
1731
1752
revision_id = branch.last_revision()
1732
1753
inv = Inventory(root_id=gen_root_id())
1733
wt = WorkingTree3(a_bzrdir.root_transport.base,
1754
wt = WorkingTree3(a_bzrdir.root_transport.local_abspath('.'),
1736
1757
_internal=True,
1767
1788
if not isinstance(a_bzrdir.transport, LocalTransport):
1768
1789
raise errors.NotLocalUrl(a_bzrdir.transport.base)
1769
1790
control_files = self._open_control_files(a_bzrdir)
1770
return WorkingTree3(a_bzrdir.root_transport.base,
1791
return WorkingTree3(a_bzrdir.root_transport.local_abspath('.'),
1771
1792
_internal=True,
1773
1794
_bzrdir=a_bzrdir,