324
325
def _set_inventory(self, inv):
325
326
assert inv.root is not None
326
327
self._inventory = inv
327
self.path2id = self._inventory.path2id
329
def is_control_filename(self, filename):
330
"""True if filename is the name of a control file in this tree.
332
:param filename: A filename within the tree. This is a relative path
333
from the root of this tree.
335
This is true IF and ONLY IF the filename is part of the meta data
336
that bzr controls in this tree. I.E. a random .bzr directory placed
337
on disk will not be a control file for this tree.
339
return self.bzrdir.is_control_filename(filename)
342
330
def open(path=None, _unsupported=False):
543
531
transform_tree(tree, self)
544
532
tree.set_parent_ids([revision_id])
547
def commit(self, message=None, revprops=None, *args, **kwargs):
548
# avoid circular imports
549
from bzrlib.commit import Commit
552
if not 'branch-nick' in revprops:
553
revprops['branch-nick'] = self.branch.nick
554
# args for wt.commit start at message from the Commit.commit method,
555
# but with branch a kwarg now, passing in args as is results in the
556
#message being used for the branch
557
args = (DEPRECATED_PARAMETER, message, ) + args
558
committed_id = Commit().commit( working_tree=self, revprops=revprops,
560
self._set_inventory(self.read_working_inventory())
563
534
def id2abspath(self, file_id):
564
535
return self.abspath(self.id2path(file_id))
603
574
return bool(stat.S_ISREG(mode) and stat.S_IEXEC & mode)
605
576
@needs_write_lock
606
def add(self, files, ids=None):
607
"""Make files versioned.
609
Note that the command line normally calls smart_add instead,
610
which can automatically recurse.
612
This adds the files to the inventory, so that they will be
613
recorded by the next commit.
616
List of paths to add, relative to the base of the tree.
619
If set, use these instead of automatically generated ids.
620
Must be the same length as the list of files, but may
621
contain None for ids that are to be autogenerated.
623
TODO: Perhaps have an option to add the ids even if the files do
626
TODO: Perhaps callback with the ids and paths as they're added.
577
def _add(self, files, ids, kinds):
578
"""See MutableTree._add."""
628
579
# TODO: Re-adding a file that is removed in the working copy
629
580
# should probably put it back with the previous ID.
630
if isinstance(files, basestring):
631
assert(ids is None or isinstance(ids, basestring))
637
ids = [None] * len(files)
639
assert(len(ids) == len(files))
581
# the read and write working inventory should not occur in this
582
# function - they should be part of lock_write and unlock.
641
583
inv = self.read_working_inventory()
642
for f,file_id in zip(files, ids):
643
if self.is_control_filename(f):
644
raise errors.ForbiddenControlFileError(filename=f)
649
raise BzrError("cannot add top-level %r" % f)
651
fullpath = normpath(self.abspath(f))
653
kind = file_kind(fullpath)
655
if e.errno == errno.ENOENT:
656
raise NoSuchFile(fullpath)
657
if not InventoryEntry.versionable_kind(kind):
658
raise errors.BadFileKindError(filename=f, kind=kind)
584
for f, file_id, kind in zip(files, ids, kinds):
585
assert kind is not None
659
586
if file_id is None:
660
587
inv.add_path(f, kind=kind)
662
589
inv.add_path(f, kind=kind, file_id=file_id)
664
590
self._write_inventory(inv)
592
def _gather_kinds(self, files, kinds):
593
"""See MutableTree._gather_kinds."""
594
for pos, f in enumerate(files):
595
if kinds[pos] is None:
596
fullpath = normpath(self.abspath(f))
598
kinds[pos] = file_kind(fullpath)
600
if e.errno == errno.ENOENT:
601
raise NoSuchFile(fullpath)
666
603
@needs_write_lock
667
604
def add_parent_tree_id(self, revision_id, allow_leftmost_as_ghost=False):
668
605
"""Add revision_id as a parent.
751
688
@needs_write_lock
752
689
def set_parent_trees(self, parents_list, allow_leftmost_as_ghost=False):
753
"""Set the parents of the working tree.
755
:param parents_list: A list of (revision_id, tree) tuples.
756
If tree is None, then that element is treated as an unreachable
757
parent tree - i.e. a ghost.
690
"""See MutableTree.set_parent_trees."""
759
691
# parent trees are not used in current format trees, delegate to
761
693
self.set_parent_ids([rev for (rev, tree) in parents_list],
844
776
merge_hashes[file_id] = hash
845
777
return merge_hashes
780
def mkdir(self, path, file_id=None):
781
"""See MutableTree.mkdir()."""
783
file_id = gen_file_id(os.path.basename(path))
784
os.mkdir(self.abspath(path))
785
self.add(path, file_id, 'directory')
847
788
def get_symlink_target(self, file_id):
848
789
return os.readlink(self.id2abspath(file_id))