325
327
def _set_inventory(self, inv):
326
328
assert inv.root is not None
327
329
self._inventory = inv
328
self.path2id = self._inventory.path2id
330
def is_control_filename(self, filename):
331
"""True if filename is the name of a control file in this tree.
333
:param filename: A filename within the tree. This is a relative path
334
from the root of this tree.
336
This is true IF and ONLY IF the filename is part of the meta data
337
that bzr controls in this tree. I.E. a random .bzr directory placed
338
on disk will not be a control file for this tree.
340
return self.bzrdir.is_control_filename(filename)
343
332
def open(path=None, _unsupported=False):
552
541
transform_tree(tree, self)
553
542
tree.set_parent_ids([revision_id])
556
def commit(self, message=None, revprops=None, *args, **kwargs):
557
# avoid circular imports
558
from bzrlib.commit import Commit
561
if not 'branch-nick' in revprops:
562
revprops['branch-nick'] = self.branch.nick
563
# args for wt.commit start at message from the Commit.commit method,
564
# but with branch a kwarg now, passing in args as is results in the
565
#message being used for the branch
566
args = (DEPRECATED_PARAMETER, message, ) + args
567
committed_id = Commit().commit( working_tree=self, revprops=revprops,
571
544
def id2abspath(self, file_id):
572
545
return self.abspath(self.id2path(file_id))
611
584
return bool(stat.S_ISREG(mode) and stat.S_IEXEC & mode)
613
586
@needs_write_lock
614
def add(self, files, ids=None):
615
"""Make files versioned.
617
Note that the command line normally calls smart_add instead,
618
which can automatically recurse.
620
This adds the files to the inventory, so that they will be
621
recorded by the next commit.
624
List of paths to add, relative to the base of the tree.
627
If set, use these instead of automatically generated ids.
628
Must be the same length as the list of files, but may
629
contain None for ids that are to be autogenerated.
631
TODO: Perhaps have an option to add the ids even if the files do
634
TODO: Perhaps callback with the ids and paths as they're added.
587
def _add(self, files, ids, kinds):
588
"""See MutableTree._add."""
636
589
# TODO: Re-adding a file that is removed in the working copy
637
590
# should probably put it back with the previous ID.
638
if isinstance(files, basestring):
639
assert(ids is None or isinstance(ids, basestring))
645
ids = [None] * len(files)
647
assert(len(ids) == len(files))
591
# the read and write working inventory should not occur in this
592
# function - they should be part of lock_write and unlock.
649
593
inv = self.read_working_inventory()
650
for f,file_id in zip(files, ids):
651
if self.is_control_filename(f):
652
raise errors.ForbiddenControlFileError(filename=f)
657
raise BzrError("cannot add top-level %r" % f)
659
fullpath = normpath(self.abspath(f))
661
kind = file_kind(fullpath)
663
if e.errno == errno.ENOENT:
664
raise NoSuchFile(fullpath)
665
if not InventoryEntry.versionable_kind(kind):
666
raise errors.BadFileKindError(filename=f, kind=kind)
594
for f, file_id, kind in zip(files, ids, kinds):
595
assert kind is not None
667
596
if file_id is None:
668
597
inv.add_path(f, kind=kind)
670
599
inv.add_path(f, kind=kind, file_id=file_id)
672
600
self._write_inventory(inv)
602
@needs_tree_write_lock
603
def _gather_kinds(self, files, kinds):
604
"""See MutableTree._gather_kinds."""
605
for pos, f in enumerate(files):
606
if kinds[pos] is None:
607
fullpath = normpath(self.abspath(f))
609
kinds[pos] = file_kind(fullpath)
611
if e.errno == errno.ENOENT:
612
raise NoSuchFile(fullpath)
674
614
@needs_write_lock
675
615
def add_parent_tree_id(self, revision_id, allow_leftmost_as_ghost=False):
676
616
"""Add revision_id as a parent.
760
700
merges = revision_ids[1:]
761
701
self._control_files.put_utf8('pending-merges', '\n'.join(merges))
703
@needs_tree_write_lock
764
704
def set_parent_trees(self, parents_list, allow_leftmost_as_ghost=False):
765
"""Set the parents of the working tree.
767
:param parents_list: A list of (revision_id, tree) tuples.
768
If tree is None, then that element is treated as an unreachable
769
parent tree - i.e. a ghost.
705
"""See MutableTree.set_parent_trees."""
771
706
# parent trees are not used in current format trees, delegate to
773
708
self.set_parent_ids([rev for (rev, tree) in parents_list],
774
709
allow_leftmost_as_ghost=allow_leftmost_as_ghost)
711
@needs_tree_write_lock
777
712
def set_pending_merges(self, rev_list):
778
713
parents = self.get_parent_ids()
779
714
leftmost = parents[:1]
780
715
new_parents = leftmost + rev_list
781
716
self.set_parent_ids(new_parents)
718
@needs_tree_write_lock
784
719
def set_merge_modified(self, modified_hashes):
785
720
def iter_stanzas():
786
721
for file_id, hash in modified_hashes.iteritems():
787
722
yield Stanza(file_id=file_id, hash=hash)
788
723
self._put_rio('merge-hashes', iter_stanzas(), MERGE_MODIFIED_HEADER_1)
725
@needs_tree_write_lock
791
726
def _put_rio(self, filename, stanzas, header):
792
727
my_file = rio_file(stanzas, header)
793
728
self._control_files.put(filename, my_file)
730
@needs_write_lock # because merge pulls data into the branch.
796
731
def merge_from_branch(self, branch, to_revision=None):
797
732
"""Merge from a branch into this working tree.
856
791
merge_hashes[file_id] = hash
857
792
return merge_hashes
795
def mkdir(self, path, file_id=None):
796
"""See MutableTree.mkdir()."""
798
file_id = gen_file_id(os.path.basename(path))
799
os.mkdir(self.abspath(path))
800
self.add(path, file_id, 'directory')
859
803
def get_symlink_target(self, file_id):
860
804
return os.readlink(self.id2abspath(file_id))
1364
1317
return file_kind(self.id2abspath(file_id))
1366
1319
def last_revision(self):
1367
"""Return the last revision id of this working tree.
1369
In early branch formats this was the same as the branch last_revision,
1370
but that cannot be relied upon - for working tree operations,
1371
always use tree.last_revision(). This returns the left most parent id,
1372
or None if there are no parents.
1374
This was deprecated as of 0.11. Please use get_parent_ids instead.
1320
"""Return the last revision of the branch for this tree.
1322
This format tree does not support a separate marker for last-revision
1323
compared to the branch.
1325
See MutableTree.last_revision
1376
1327
return self._last_revision()