13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
17
"""WorkingTree object and friends.
235
230
wt_trans = self.bzrdir.get_workingtree_transport(None)
236
231
cache_filename = wt_trans.local_abspath('stat-cache')
237
232
self._hashcache = hashcache.HashCache(basedir, cache_filename,
238
self.bzrdir._get_file_mode(),
239
self._content_filter_stack_provider())
233
self.bzrdir._get_file_mode())
240
234
hc = self._hashcache
242
236
# is this scan needed ? it makes things kinda slow.
419
413
return self.branch.repository.revision_tree(revision_id)
420
414
except (errors.RevisionNotPresent, errors.NoSuchRevision):
421
415
# the basis tree *may* be a ghost or a low level error may have
422
# occurred. If the revision is present, its a problem, if its not
416
# occured. If the revision is present, its a problem, if its not
424
418
if self.branch.repository.has_revision(revision_id):
441
435
def has_filename(self, filename):
442
436
return osutils.lexists(self.abspath(filename))
444
def get_file(self, file_id, path=None, filtered=True):
445
return self.get_file_with_stat(file_id, path, filtered=filtered)[0]
438
def get_file(self, file_id, path=None):
439
return self.get_file_with_stat(file_id, path)[0]
447
def get_file_with_stat(self, file_id, path=None, filtered=True,
441
def get_file_with_stat(self, file_id, path=None, _fstat=os.fstat):
449
442
"""See MutableTree.get_file_with_stat."""
451
444
path = self.id2path(file_id)
452
file_obj = self.get_file_byname(path, filtered=False)
453
stat_value = _fstat(file_obj.fileno())
454
if self.supports_content_filtering() and filtered:
455
filters = self._content_filter_stack(path)
456
file_obj = filtered_input_file(file_obj, filters)
457
return (file_obj, stat_value)
459
def get_file_text(self, file_id, path=None, filtered=True):
460
return self.get_file(file_id, path=path, filtered=filtered).read()
462
def get_file_byname(self, filename, filtered=True):
463
path = self.abspath(filename)
465
if self.supports_content_filtering() and filtered:
466
filters = self._content_filter_stack(filename)
467
return filtered_input_file(f, filters)
471
def get_file_lines(self, file_id, path=None, filtered=True):
445
file_obj = self.get_file_byname(path)
446
return (file_obj, _fstat(file_obj.fileno()))
448
def get_file_byname(self, filename):
449
return file(self.abspath(filename), 'rb')
451
def get_file_lines(self, file_id, path=None):
472
452
"""See Tree.get_file_lines()"""
473
file = self.get_file(file_id, path, filtered=filtered)
453
file = self.get_file(file_id, path)
475
455
return file.readlines()
749
729
kind = 'tree-reference'
750
730
return kind, None, None, None
751
731
elif kind == 'symlink':
752
return ('symlink', None, None,
753
os.readlink(abspath.encode(osutils._fs_enc)
754
).decode(osutils._fs_enc))
732
return ('symlink', None, None, os.readlink(abspath.encode(osutils._fs_enc)))
756
734
return (kind, None, None, None)
770
748
def _set_merges_from_parent_ids(self, parent_ids):
771
749
merges = parent_ids[1:]
772
750
self._transport.put_bytes('pending-merges', '\n'.join(merges),
773
mode=self.bzrdir._get_file_mode())
751
mode=self._control_files._file_mode)
775
753
def _filter_parent_ids_by_ancestry(self, revision_ids):
776
754
"""Check that all merged revisions are proper 'heads'.
876
854
self._must_be_locked()
877
855
my_file = rio_file(stanzas, header)
878
856
self._transport.put_file(filename, my_file,
879
mode=self.bzrdir._get_file_mode())
857
mode=self._control_files._file_mode)
881
859
@needs_write_lock # because merge pulls data into the branch.
882
860
def merge_from_branch(self, branch, to_revision=None, from_revision=None,
1109
1086
self._serialize(self._inventory, sio)
1111
1088
self._transport.put_file('inventory', sio,
1112
mode=self.bzrdir._get_file_mode())
1089
mode=self._control_files._file_mode)
1113
1090
self._inventory_is_modified = False
1115
1092
def _kind(self, relpath):
1532
1509
:raises: NoSuchId if any fileid is not currently versioned.
1534
1511
for file_id in file_ids:
1535
if file_id not in self._inventory:
1536
raise errors.NoSuchId(self, file_id)
1537
for file_id in file_ids:
1538
1512
if self._inventory.has_id(file_id):
1539
1513
self._inventory.remove_recursive_id(file_id)
1515
raise errors.NoSuchId(self, file_id)
1540
1516
if len(file_ids):
1541
1517
# in the future this should just set a dirty bit to wait for the
1542
1518
# final unlock. However, until all methods of workingtree start
1833
1809
path = self._basis_inventory_name()
1834
1810
sio = StringIO(xml)
1835
1811
self._transport.put_file(path, sio,
1836
mode=self.bzrdir._get_file_mode())
1812
mode=self._control_files._file_mode)
1838
1814
def _create_basis_xml_from_inventory(self, revision_id, inventory):
1839
1815
"""Create the text that will be saved in basis-inventory"""
1967
1943
tree_delta.unversioned.extend((unknown_file,))
1968
1944
raise errors.BzrRemoveChangedFilesError(tree_delta)
1970
# Build inv_delta and delete files where applicable,
1946
# Build inv_delta and delete files where applicaple,
1971
1947
# do this before any modifications to inventory.
1972
1948
for f in files:
1973
1949
fid = self.path2id(f)
2224
2200
parent_trees = [(self.branch.last_revision(), to_tree)]
2225
2201
merges = self.get_parent_ids()[1:]
2226
2202
# Ideally we ask the tree for the trees here, that way the working
2227
# tree can decide whether to give us the entire tree or give us a
2203
# tree can decide whether to give us teh entire tree or give us a
2228
2204
# lazy initialised tree. dirstate for instance will have the trees
2229
2205
# in ram already, whereas a last-revision + basis-inventory tree
2230
2206
# will not, but also does not need them when setting parents.
2910
2886
control_files.create_lock()
2911
2887
control_files.lock_write()
2912
2888
transport.put_bytes('format', self.get_format_string(),
2913
mode=a_bzrdir._get_file_mode())
2889
mode=control_files._file_mode)
2914
2890
if from_branch is not None:
2915
2891
branch = from_branch