~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Robert Collins
  • Date: 2005-10-18 13:11:57 UTC
  • mfrom: (1185.16.72) (0.2.1)
  • Revision ID: robertc@robertcollins.net-20051018131157-76a9970aa78e927e
Merged Martin.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
                           DivergedBranches, LockError, UnlistableStore,
36
36
                           UnlistableBranch, NoSuchFile, NotVersionedError)
37
37
from bzrlib.textui import show_status
38
 
from bzrlib.revision import (Revision, is_ancestor, get_intervening_revisions,
39
 
                             NULL_REVISION)
 
38
from bzrlib.revision import Revision, is_ancestor, get_intervening_revisions
40
39
 
41
40
from bzrlib.delta import compare_trees
42
41
from bzrlib.tree import EmptyTree, RevisionTree
209
208
        """Create new branch object at a particular location.
210
209
 
211
210
        transport -- A Transport object, defining how to access files.
 
211
                (If a string, transport.transport() will be used to
 
212
                create a Transport object)
212
213
        
213
214
        init -- If True, create new control files in a previously
214
215
             unversioned directory.  If False, the branch must already
258
259
            self.text_store = get_store('text-store')
259
260
            self.revision_store = get_store('revision-store')
260
261
        elif self._branch_format == 5:
261
 
            self.control_weaves = get_weave('')
 
262
            self.control_weaves = get_weave([])
262
263
            self.weave_store = get_weave('weaves')
263
264
            self.revision_store = get_store('revision-store', compressed=False)
264
265
        elif self._branch_format == 6:
265
 
            self.control_weaves = get_weave('')
 
266
            self.control_weaves = get_weave([])
266
267
            self.weave_store = get_weave('weaves', prefixed=True)
267
268
            self.revision_store = get_store('revision-store', compressed=False,
268
269
                                            prefixed=True)
317
318
        """Return the current active transaction.
318
319
 
319
320
        If no transaction is active, this returns a passthrough object
320
 
        for which all data is immediately flushed and no caching happens.
 
321
        for which all data is immedaitely flushed and no caching happens.
321
322
        """
322
323
        if self._transaction is None:
323
324
            return transactions.PassThroughTransaction()
384
385
        return self._transport.abspath(name)
385
386
 
386
387
    def _rel_controlfilename(self, file_or_path):
387
 
        if not isinstance(file_or_path, basestring):
388
 
            file_or_path = '/'.join(file_or_path)
389
 
        if file_or_path == '':
390
 
            return bzrlib.BZRDIR
391
 
        return bzrlib.transport.urlescape(bzrlib.BZRDIR + '/' + file_or_path)
 
388
        if isinstance(file_or_path, basestring):
 
389
            file_or_path = [file_or_path]
 
390
        return [bzrlib.BZRDIR] + file_or_path
392
391
 
393
392
    def controlfilename(self, file_or_path):
394
393
        """Return location relative to branch."""
395
394
        return self._transport.abspath(self._rel_controlfilename(file_or_path))
396
395
 
 
396
 
397
397
    def controlfile(self, file_or_path, mode='r'):
398
398
        """Open a control file for this branch.
399
399
 
695
695
    def get_revision_xml_file(self, revision_id):
696
696
        """Return XML file object for revision object."""
697
697
        if not revision_id or not isinstance(revision_id, basestring):
698
 
            raise InvalidRevisionId(revision_id=revision_id, branch=self)
 
698
            raise InvalidRevisionId(revision_id)
699
699
        try:
700
700
            return self.revision_store.get(revision_id)
701
701
        except (IndexError, KeyError):
878
878
 
879
879
    def update_revisions(self, other, stop_revision=None):
880
880
        """Pull in new perfect-fit revisions."""
 
881
        # FIXME: If the branches have diverged, but the latest
 
882
        # revision in this branch is completely merged into the other,
 
883
        # then we should still be able to pull.
881
884
        from bzrlib.fetch import greedy_fetch
882
885
        if stop_revision is None:
883
886
            stop_revision = other.last_revision()
938
941
        an `EmptyTree` is returned."""
939
942
        # TODO: refactor this to use an existing revision object
940
943
        # so we don't need to read it in twice.
941
 
        if revision_id == None or revision_id == NULL_REVISION:
 
944
        if revision_id == None:
942
945
            return EmptyTree()
943
946
        else:
944
947
            inv = self.get_revision_inventory(revision_id)
954
957
        # for that.
955
958
        return WorkingTree(self.base, branch=self)
956
959
 
957
 
    @needs_write_lock
958
 
    def pull(self, source, overwrite=False):
959
 
        source.lock_read()
960
 
        try:
961
 
            try:
962
 
                self.update_revisions(source)
963
 
            except DivergedBranches:
964
 
                if not overwrite:
965
 
                    raise
966
 
                self.set_revision_history(source.revision_history())
967
 
        finally:
968
 
            source.unlock()
969
960
 
970
961
    def basis_tree(self):
971
962
        """Return `Tree` object for last revision.
1177
1168
                    raise
1178
1169
        return None
1179
1170
 
1180
 
    def get_push_location(self):
1181
 
        """Return the None or the location to push this branch to."""
1182
 
        config = bzrlib.config.BranchConfig(self)
1183
 
        push_loc = config.get_user_option('push_location')
1184
 
        return push_loc
1185
 
 
1186
 
    def set_push_location(self, location):
1187
 
        """Set a new push location for this branch."""
1188
 
        config = bzrlib.config.LocationConfig(self.base)
1189
 
        config.set_user_option('push_location', location)
1190
 
 
1191
1171
    @needs_write_lock
1192
1172
    def set_parent(self, url):
1193
1173
        # TODO: Maybe delete old location files?