~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Jelmer Vernooij
  • Date: 2005-11-04 17:26:05 UTC
  • mfrom: (1185.16.146)
  • mto: (1185.33.1)
  • mto: This revision was merged to the branch mainline in revision 1509.
  • Revision ID: jelmer@samba.org-20051104172605-9288f261492667fd
MergeĀ fromĀ Martin

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
from bzrlib.osutils import appendpath, file_kind, isdir, splitpath, relpath
52
52
from bzrlib.errors import BzrCheckError, DivergedBranches, NotVersionedError
53
53
from bzrlib.trace import mutter
 
54
import bzrlib.xml5
54
55
 
55
56
 
56
57
class TreeEntry(object):
134
135
            branch = Branch.open(basedir)
135
136
        assert isinstance(branch, Branch), \
136
137
            "branch %r is not a Branch" % branch
137
 
        self._inventory = branch.inventory
138
 
        self.path2id = self._inventory.path2id
139
138
        self.branch = branch
140
139
        self.basedir = basedir
 
140
        self._inventory = self.read_working_inventory()
 
141
        self.path2id = self._inventory.path2id
141
142
 
142
143
        # update the whole cache up front and write to disk if anything changed;
143
144
        # in the future we might want to do this more selectively
187
188
    def get_file_byname(self, filename):
188
189
        return file(self.abspath(filename), 'rb')
189
190
 
 
191
    def get_root_id(self):
 
192
        """Return the id of this trees root"""
 
193
        inv = self.read_working_inventory()
 
194
        return inv.root.file_id
 
195
        
190
196
    def _get_store_filename(self, file_id):
191
197
        ## XXX: badly named; this isn't in the store at all
192
198
        return self.abspath(self.id2path(file_id))
450
456
        """See Branch.lock_write, and WorkingTree.unlock."""
451
457
        return self.branch.lock_write()
452
458
 
 
459
    @needs_read_lock
 
460
    def read_working_inventory(self):
 
461
        """Read the working inventory."""
 
462
        # ElementTree does its own conversion from UTF-8, so open in
 
463
        # binary.
 
464
        f = self.branch.controlfile('inventory', 'rb')
 
465
        return bzrlib.xml5.serializer_v5.read_inventory(f)
 
466
 
453
467
    @needs_write_lock
454
468
    def remove(self, files, verbose=False):
455
469
        """Remove nominated files from the working inventory..
491
505
 
492
506
        self.branch._write_inventory(inv)
493
507
 
 
508
    @needs_write_lock
 
509
    def set_inventory(self, new_inventory_list):
 
510
        from bzrlib.inventory import (Inventory,
 
511
                                      InventoryDirectory,
 
512
                                      InventoryEntry,
 
513
                                      InventoryFile,
 
514
                                      InventoryLink)
 
515
        inv = Inventory(self.get_root_id())
 
516
        for path, file_id, parent, kind in new_inventory_list:
 
517
            name = os.path.basename(path)
 
518
            if name == "":
 
519
                continue
 
520
            # fixme, there should be a factory function inv,add_?? 
 
521
            if kind == 'directory':
 
522
                inv.add(InventoryDirectory(file_id, name, parent))
 
523
            elif kind == 'file':
 
524
                inv.add(InventoryFile(file_id, name, parent))
 
525
            elif kind == 'symlink':
 
526
                inv.add(InventoryLink(file_id, name, parent))
 
527
            else:
 
528
                raise BzrError("unknown kind %r" % kind)
 
529
        self.branch._write_inventory(inv)
 
530
 
494
531
    def unlock(self):
495
532
        """See Branch.unlock.
496
533