~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: John Arbash Meinel
  • Date: 2006-06-18 02:21:57 UTC
  • mfrom: (1787 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1794.
  • Revision ID: john@arbash-meinel.com-20060618022157-6e33aa9b67c25e4f
[merge] bzr.dev 1787

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
from copy import deepcopy
19
19
from cStringIO import StringIO
 
20
import errno
 
21
import os
 
22
import shutil
 
23
import sys
20
24
from unittest import TestSuite
21
25
from warnings import warn
22
26
 
23
27
import bzrlib
24
 
from bzrlib import bzrdir, errors, lockdir, osutils, revision, \
25
 
        tree, \
26
 
        ui, \
27
 
        urlutils
 
28
import bzrlib.bzrdir as bzrdir
28
29
from bzrlib.config import TreeConfig
29
30
from bzrlib.decorators import needs_read_lock, needs_write_lock
30
31
import bzrlib.errors as errors
35
36
                           NotBranchError, UninitializableFormat, 
36
37
                           UnlistableStore, UnlistableBranch, 
37
38
                           )
 
39
import bzrlib.inventory as inventory
 
40
from bzrlib.inventory import Inventory
38
41
from bzrlib.lockable_files import LockableFiles, TransportLock
39
 
from bzrlib.symbol_versioning import (deprecated_function,
40
 
                                      deprecated_method,
41
 
                                      DEPRECATED_PARAMETER,
42
 
                                      deprecated_passed,
43
 
                                      zero_eight,
44
 
                                      )
 
42
from bzrlib.lockdir import LockDir
 
43
from bzrlib.osutils import (isdir, quotefn,
 
44
                            rename, splitpath, sha_file,
 
45
                            file_kind, abspath, normpath, pathjoin,
 
46
                            safe_unicode,
 
47
                            rmtree,
 
48
                            )
 
49
from bzrlib.repository import Repository
 
50
from bzrlib.revision import (
 
51
                             is_ancestor,
 
52
                             NULL_REVISION,
 
53
                             Revision,
 
54
                             )
 
55
from bzrlib.store import copy_all
 
56
from bzrlib.symbol_versioning import *
 
57
from bzrlib.textui import show_status
45
58
from bzrlib.trace import mutter, note
 
59
import bzrlib.transactions as transactions
 
60
from bzrlib.transport import Transport, get_transport
 
61
import bzrlib.ui
 
62
import bzrlib.urlutils as urlutils
 
63
import bzrlib.xml5
46
64
 
47
65
 
48
66
BZR_BRANCH_FORMAT_4 = "Bazaar-NG branch, format 0.0.4\n"
199
217
        if self.base == from_branch.base:
200
218
            return (0, [])
201
219
        if pb is None:
202
 
            nested_pb = ui.ui_factory.nested_progress_bar()
 
220
            nested_pb = bzrlib.ui.ui_factory.nested_progress_bar()
203
221
            pb = nested_pb
204
222
        else:
205
223
            nested_pb = None
213
231
                    last_revision = from_history[-1]
214
232
                else:
215
233
                    # no history in the source branch
216
 
                    last_revision = revision.NULL_REVISION
 
234
                    last_revision = NULL_REVISION
217
235
            return self.repository.fetch(from_branch.repository,
218
236
                                         revision_id=last_revision,
219
237
                                         pb=nested_pb)
312
330
        
313
331
        If self and other have not diverged, return a list of the revisions
314
332
        present in other, but missing from self.
 
333
 
 
334
        >>> from bzrlib.workingtree import WorkingTree
 
335
        >>> bzrlib.trace.silent = True
 
336
        >>> d1 = bzrdir.ScratchDir()
 
337
        >>> br1 = d1.open_branch()
 
338
        >>> wt1 = d1.open_workingtree()
 
339
        >>> d2 = bzrdir.ScratchDir()
 
340
        >>> br2 = d2.open_branch()
 
341
        >>> wt2 = d2.open_workingtree()
 
342
        >>> br1.missing_revisions(br2)
 
343
        []
 
344
        >>> wt2.commit("lala!", rev_id="REVISION-ID-1")
 
345
        'REVISION-ID-1'
 
346
        >>> br1.missing_revisions(br2)
 
347
        [u'REVISION-ID-1']
 
348
        >>> br2.missing_revisions(br1)
 
349
        []
 
350
        >>> wt1.commit("lala!", rev_id="REVISION-ID-1")
 
351
        'REVISION-ID-1'
 
352
        >>> br1.missing_revisions(br2)
 
353
        []
 
354
        >>> wt2.commit("lala!", rev_id="REVISION-ID-2A")
 
355
        'REVISION-ID-2A'
 
356
        >>> br1.missing_revisions(br2)
 
357
        [u'REVISION-ID-2A']
 
358
        >>> wt1.commit("lala!", rev_id="REVISION-ID-2B")
 
359
        'REVISION-ID-2B'
 
360
        >>> br1.missing_revisions(br2)
 
361
        Traceback (most recent call last):
 
362
        DivergedBranches: These branches have diverged.  Try merge.
315
363
        """
316
364
        self_history = self.revision_history()
317
365
        self_len = len(self_history)
327
375
        else:
328
376
            assert isinstance(stop_revision, int)
329
377
            if stop_revision > other_len:
330
 
                raise errors.NoSuchRevision(self, stop_revision)
 
378
                raise bzrlib.errors.NoSuchRevision(self, stop_revision)
331
379
        return other_history[self_len:stop_revision]
332
380
 
333
381
    def update_revisions(self, other, stop_revision=None):
530
578
        In particular this checks that revisions given in the revision-history
531
579
        do actually match up in the revision graph, and that they're all 
532
580
        present in the repository.
533
 
        
534
 
        Callers will typically also want to check the repository.
535
581
 
536
582
        :return: A BranchCheckResult.
537
583
        """
540
586
            try:
541
587
                revision = self.repository.get_revision(revision_id)
542
588
            except errors.NoSuchRevision, e:
543
 
                raise errors.BzrCheckError("mainline revision {%s} not in repository"
544
 
                            % revision_id)
 
589
                raise BzrCheckError("mainline revision {%s} not in repository"
 
590
                        % revision_id)
545
591
            # In general the first entry on the revision history has no parents.
546
592
            # But it's not illegal for it to have parents listed; this can happen
547
593
            # in imports from Arch when the parents weren't reachable.
548
594
            if mainline_parent_id is not None:
549
595
                if mainline_parent_id not in revision.parent_ids:
550
 
                    raise errors.BzrCheckError("previous revision {%s} not listed among "
 
596
                    raise BzrCheckError("previous revision {%s} not listed among "
551
597
                                        "parents of {%s}"
552
598
                                        % (mainline_parent_id, revision_id))
553
599
            mainline_parent_id = revision_id
588
634
        except NoSuchFile:
589
635
            raise NotBranchError(path=transport.base)
590
636
        except KeyError:
591
 
            raise errors.UnknownFormatError(format=format_string)
 
637
            raise errors.UnknownFormatError(format_string)
592
638
 
593
639
    @classmethod
594
640
    def get_default_format(klass):
721
767
        utf8_files = [('revision-history', ''),
722
768
                      ('branch-name', ''),
723
769
                      ]
724
 
        control_files = LockableFiles(branch_transport, 'lock', lockdir.LockDir)
 
770
        control_files = LockableFiles(branch_transport, 'lock', LockDir)
725
771
        control_files.create_lock()
726
772
        control_files.lock_write()
727
773
        control_files.put_utf8('format', self.get_format_string())
746
792
            format = BranchFormat.find_format(a_bzrdir)
747
793
            assert format.__class__ == self.__class__
748
794
        transport = a_bzrdir.get_branch_transport(None)
749
 
        control_files = LockableFiles(transport, 'lock', lockdir.LockDir)
 
795
        control_files = LockableFiles(transport, 'lock', LockDir)
750
796
        return BzrBranch5(_format=self,
751
797
                          _control_files=control_files,
752
798
                          a_bzrdir=a_bzrdir,
867
913
        self._base = self._transport.base
868
914
        self._format = _format
869
915
        if _control_files is None:
870
 
            raise ValueError('BzrBranch _control_files is None')
 
916
            raise BzrBadParameterMissing('_control_files')
871
917
        self.control_files = _control_files
872
918
        if deprecated_passed(init):
873
919
            warn("BzrBranch.__init__(..., init=XXX): The init parameter is "
888
934
                 stacklevel=2)
889
935
            if (not relax_version_check
890
936
                and not self._format.is_supported()):
891
 
                raise errors.UnsupportedFormatError(format=fmt)
 
937
                raise errors.UnsupportedFormatError(
 
938
                        'sorry, branch format %r not supported' % fmt,
 
939
                        ['use a different bzr version',
 
940
                         'or remove the .bzr directory'
 
941
                         ' and "bzr init" again'])
892
942
        if deprecated_passed(transport):
893
943
            warn("BzrBranch.__init__(transport=XXX...): The transport "
894
944
                 "parameter is deprecated as of bzr 0.8. "
912
962
        # XXX: cache_root seems to be unused, 2006-01-13 mbp
913
963
        if hasattr(self, 'cache_root') and self.cache_root is not None:
914
964
            try:
915
 
                osutils.rmtree(self.cache_root)
 
965
                rmtree(self.cache_root)
916
966
            except:
917
967
                pass
918
968
            self.cache_root = None
961
1011
        FIXME: DELETE THIS METHOD when pre 0.8 support is removed.
962
1012
        """
963
1013
        if format is None:
964
 
            format = BranchFormat.find_format(self.bzrdir)
 
1014
            format = BzrBranchFormat.find_format(self.bzrdir)
965
1015
        self._format = format
966
1016
        mutter("got branch format %s", self._format)
967
1017
 
1077
1127
            # make a new revision history from the graph
1078
1128
            current_rev_id = stop_revision
1079
1129
            new_history = []
1080
 
            while current_rev_id not in (None, revision.NULL_REVISION):
 
1130
            while current_rev_id not in (None, NULL_REVISION):
1081
1131
                new_history.append(current_rev_id)
1082
1132
                current_rev_id_parents = stop_graph[current_rev_id]
1083
1133
                try:
1096
1146
    @deprecated_method(zero_eight)
1097
1147
    def working_tree(self):
1098
1148
        """Create a Working tree object for this branch."""
1099
 
 
 
1149
        from bzrlib.workingtree import WorkingTree
1100
1150
        from bzrlib.transport.local import LocalTransport
1101
1151
        if (self.base.find('://') != -1 or 
1102
1152
            not isinstance(self._transport, LocalTransport)):
1123
1173
 
1124
1174
    def get_parent(self):
1125
1175
        """See Branch.get_parent."""
1126
 
 
 
1176
        import errno
1127
1177
        _locs = ['parent', 'pull', 'x-pull']
1128
1178
        assert self.base[-1] == '/'
1129
1179
        for l in _locs:
1366
1416
 
1367
1417
 
1368
1418
@deprecated_function(zero_eight)
 
1419
def ScratchBranch(*args, **kwargs):
 
1420
    """See bzrlib.bzrdir.ScratchDir."""
 
1421
    d = ScratchDir(*args, **kwargs)
 
1422
    return d.open_branch()
 
1423
 
 
1424
 
 
1425
@deprecated_function(zero_eight)
1369
1426
def is_control_file(*args, **kwargs):
1370
1427
    """See bzrlib.workingtree.is_control_file."""
1371
1428
    return bzrlib.workingtree.is_control_file(*args, **kwargs)