~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.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:
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
 
18
import shutil
18
19
import sys
19
20
import os
20
21
import errno
33
34
from bzrlib.errors import (BzrError, InvalidRevisionNumber, InvalidRevisionId,
34
35
                           NoSuchRevision, HistoryMissing, NotBranchError,
35
36
                           DivergedBranches, LockError, UnlistableStore,
36
 
                           UnlistableBranch, NoSuchFile, NotVersionedError)
 
37
                           UnlistableBranch, NoSuchFile, NotVersionedError,
 
38
                           NoWorkingTree)
37
39
from bzrlib.textui import show_status
38
40
from bzrlib.revision import (Revision, is_ancestor, get_intervening_revisions,
39
41
                             NULL_REVISION)
224
226
    def set_root_id(self, file_id):
225
227
        raise NotImplementedError('set_root_id is abstract')
226
228
 
227
 
    def read_working_inventory(self):
228
 
        """Read the working inventory."""
229
 
        raise NotImplementedError('read_working_inventory is abstract')
230
 
 
231
229
    def add(self, files, ids=None):
232
230
        """Make files versioned.
233
231
 
256
254
        """Print `file` to stdout."""
257
255
        raise NotImplementedError('print_file is abstract')
258
256
 
259
 
    # FIXME: this doesn't need to be a branch method
260
 
    def set_inventory(self, new_inventory_list):
261
 
        raise NotImplementedError('set_inventory is abstract')
262
 
 
263
257
    def unknowns(self):
264
258
        """Return all unknown files.
265
259
 
677
671
    def __str__(self):
678
672
        return '%s(%r)' % (self.__class__.__name__, self._transport.base)
679
673
 
680
 
 
681
674
    __repr__ = __str__
682
675
 
683
 
 
684
676
    def __del__(self):
685
677
        if self._lock_mode or self._lock:
686
678
            # XXX: This should show something every time, and be suitable for
696
688
        # should never expect their __del__ function to run.
697
689
        if hasattr(self, 'cache_root') and self.cache_root is not None:
698
690
            try:
699
 
                import shutil
700
691
                shutil.rmtree(self.cache_root)
701
692
            except:
702
693
                pass
892
883
 
893
884
    def get_root_id(self):
894
885
        """See Branch.get_root_id."""
895
 
        inv = self.read_working_inventory()
 
886
        inv = self.get_inventory(self.last_revision())
896
887
        return inv.root.file_id
897
888
 
 
889
    @needs_write_lock
898
890
    def set_root_id(self, file_id):
899
891
        """See Branch.set_root_id."""
900
 
        inv = self.read_working_inventory()
 
892
        inv = self.working_tree().read_working_inventory()
901
893
        orig_root_id = inv.root.file_id
902
894
        del inv._byid[inv.root.file_id]
903
895
        inv.root.file_id = file_id
908
900
                entry.parent_id = inv.root.file_id
909
901
        self._write_inventory(inv)
910
902
 
911
 
    @needs_read_lock
912
 
    def read_working_inventory(self):
913
 
        """See Branch.read_working_inventory."""
914
 
        # ElementTree does its own conversion from UTF-8, so open in
915
 
        # binary.
916
 
        f = self.controlfile('inventory', 'rb')
917
 
        return bzrlib.xml5.serializer_v5.read_inventory(f)
918
 
 
919
903
    @needs_write_lock
920
904
    def _write_inventory(self, inv):
921
905
        """Update the working inventory.
932
916
        
933
917
        mutter('wrote working inventory')
934
918
            
935
 
    inventory = property(read_working_inventory, _write_inventory, None,
936
 
                         """Inventory for the working copy.""")
937
 
 
938
919
    @needs_write_lock
939
920
    def add(self, files, ids=None):
940
921
        """See Branch.add."""
951
932
        else:
952
933
            assert(len(ids) == len(files))
953
934
 
954
 
        inv = self.read_working_inventory()
 
935
        inv = self.working_tree().read_working_inventory()
955
936
        for f,file_id in zip(files, ids):
956
937
            if is_control_file(f):
957
938
                raise BzrError("cannot add control file %s" % quotefn(f))
991
972
            raise BzrError("%r is not present in revision %s" % (file, revno))
992
973
        tree.print_file(file_id)
993
974
 
994
 
    # FIXME: this doesn't need to be a branch method
995
 
    def set_inventory(self, new_inventory_list):
996
 
        """See Branch.set_inventory."""
997
 
        from bzrlib.inventory import Inventory, InventoryEntry
998
 
        inv = Inventory(self.get_root_id())
999
 
        for path, file_id, parent, kind in new_inventory_list:
1000
 
            name = os.path.basename(path)
1001
 
            if name == "":
1002
 
                continue
1003
 
            # fixme, there should be a factory function inv,add_?? 
1004
 
            if kind == 'directory':
1005
 
                inv.add(inventory.InventoryDirectory(file_id, name, parent))
1006
 
            elif kind == 'file':
1007
 
                inv.add(inventory.InventoryFile(file_id, name, parent))
1008
 
            elif kind == 'symlink':
1009
 
                inv.add(inventory.InventoryLink(file_id, name, parent))
1010
 
            else:
1011
 
                raise BzrError("unknown kind %r" % kind)
1012
 
        self._write_inventory(inv)
1013
 
 
1014
975
    def unknowns(self):
1015
976
        """See Branch.unknowns."""
1016
977
        return self.working_tree().unknowns()
1112
1073
        # bzr 0.0.6 and later imposes the constraint that the inventory_id
1113
1074
        # must be the same as its revision, so this is trivial.
1114
1075
        if revision_id == None:
1115
 
            return Inventory(self.get_root_id())
 
1076
            # This does not make sense: if there is no revision,
 
1077
            # then it is the current tree inventory surely ?!
 
1078
            # and thus get_root_id() is something that looks at the last
 
1079
            # commit on the branch, and the get_root_id is an inventory check.
 
1080
            raise NotImplementedError
 
1081
            # return Inventory(self.get_root_id())
1116
1082
        else:
1117
1083
            return self.get_inventory(revision_id)
1118
1084
 
1187
1153
        # much more complex to keep consistent than our careful .bzr subset.
1188
1154
        # instead, we should say that working trees are local only, and optimise
1189
1155
        # for that.
 
1156
        if self._transport.base.find('://') != -1:
 
1157
            raise NoWorkingTree(self.base)
1190
1158
        return WorkingTree(self.base, branch=self)
1191
1159
 
1192
1160
    @needs_write_lock
1304
1272
        from bzrlib.atomicfile import AtomicFile
1305
1273
        from bzrlib.osutils import backup_file
1306
1274
        
1307
 
        inv = self.read_working_inventory()
 
1275
        inv = self.working_tree().read_working_inventory()
1308
1276
        if old_tree is None:
1309
1277
            old_tree = self.basis_tree()
1310
1278
        old_inv = old_tree.inventory