/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Aaron Bentley
  • Date: 2007-03-03 17:17:53 UTC
  • mfrom: (2309 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2316.
  • Revision ID: aaron.bentley@utoronto.ca-20070303171753-o0s1yrxx5sn12p2k
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
27
27
from bzrlib import (
28
28
        bzrdir,
29
29
        cache_utf8,
 
30
        config as _mod_config,
30
31
        errors,
31
32
        lockdir,
32
33
        lockable_files,
39
40
        )
40
41
from bzrlib.config import BranchConfig, TreeConfig
41
42
from bzrlib.lockable_files import LockableFiles, TransportLock
 
43
from bzrlib.tag import (
 
44
    BasicTags,
 
45
    DisabledTags,
 
46
    )
42
47
""")
43
48
 
44
49
from bzrlib.decorators import needs_read_lock, needs_write_lock
80
85
 
81
86
    base
82
87
        Base directory/url of the branch.
 
88
 
 
89
    hooks: An instance of BranchHooks.
83
90
    """
84
91
    # this is really an instance variable - FIXME move it there
85
92
    # - RBC 20060112
86
93
    base = None
87
94
 
 
95
    # override this to set the strategy for storing tags
 
96
    def _make_tags(self):
 
97
        return DisabledTags(self)
 
98
 
88
99
    def __init__(self, *ignored, **ignored_too):
89
 
        raise NotImplementedError('The Branch class is abstract')
 
100
        self.tags = self._make_tags()
90
101
 
91
102
    def break_lock(self):
92
103
        """Break a lock if one is present from another instance.
222
233
        try:
223
234
            if last_revision is None:
224
235
                pb.update('get source history')
225
 
                from_history = from_branch.revision_history()
226
 
                if from_history:
227
 
                    last_revision = from_history[-1]
228
 
                else:
229
 
                    # no history in the source branch
 
236
                last_revision = from_branch.last_revision()
 
237
                if last_revision is None:
230
238
                    last_revision = _mod_revision.NULL_REVISION
231
239
            return self.repository.fetch(from_branch.repository,
232
240
                                         revision_id=last_revision,
244
252
        """
245
253
        return None
246
254
    
 
255
    def get_old_bound_location(self):
 
256
        """Return the URL of the branch we used to be bound to
 
257
        """
 
258
        raise errors.UpgradeRequired(self.base)
 
259
 
247
260
    def get_commit_builder(self, parents, config=None, timestamp=None, 
248
261
                           timezone=None, committer=None, revprops=None, 
249
262
                           revision_id=None):
261
274
        if config is None:
262
275
            config = self.get_config()
263
276
        
264
 
        return self.repository.get_commit_builder(self, parents, config, 
 
277
        return self.repository.get_commit_builder(self, parents, config,
265
278
            timestamp, timezone, committer, revprops, revision_id)
266
279
 
267
280
    def get_master_branch(self):
313
326
        """Older format branches cannot bind or unbind."""
314
327
        raise errors.UpgradeRequired(self.base)
315
328
 
 
329
    def set_append_revisions_only(self, enabled):
 
330
        """Older format branches are never restricted to append-only"""
 
331
        raise errors.UpgradeRequired(self.base)
 
332
 
316
333
    def last_revision(self):
317
334
        """Return last revision id, or None"""
318
335
        ph = self.revision_history()
321
338
        else:
322
339
            return None
323
340
 
 
341
    def last_revision_info(self):
 
342
        """Return information about the last revision.
 
343
 
 
344
        :return: A tuple (revno, last_revision_id).
 
345
        """
 
346
        rh = self.revision_history()
 
347
        revno = len(rh)
 
348
        if revno:
 
349
            return (revno, rh[-1])
 
350
        else:
 
351
            return (0, _mod_revision.NULL_REVISION)
 
352
 
324
353
    def missing_revisions(self, other, stop_revision=None):
325
354
        """Return a list of new revisions that would perfectly fit.
326
355
        
357
386
        """Given a revision id, return its revno"""
358
387
        if revision_id is None:
359
388
            return 0
 
389
        revision_id = osutils.safe_revision_id(revision_id)
360
390
        history = self.revision_history()
361
391
        try:
362
392
            return history.index(revision_id) + 1
374
404
        return history[revno - 1]
375
405
 
376
406
    def pull(self, source, overwrite=False, stop_revision=None):
 
407
        """Mirror source into this branch.
 
408
 
 
409
        This branch is considered to be 'local', having low latency.
 
410
 
 
411
        :returns: PullResult instance
 
412
        """
377
413
        raise NotImplementedError(self.pull)
378
414
 
 
415
    def push(self, target, overwrite=False, stop_revision=None):
 
416
        """Mirror this branch into target.
 
417
 
 
418
        This branch is considered to be 'local', having low latency.
 
419
        """
 
420
        raise NotImplementedError(self.push)
 
421
 
379
422
    def basis_tree(self):
380
423
        """Return `Tree` object for last revision."""
381
424
        return self.repository.revision_tree(self.last_revision())
533
576
        result.set_parent(self.bzrdir.root_transport.base)
534
577
        return result
535
578
 
536
 
    @needs_read_lock
537
 
    def copy_content_into(self, destination, revision_id=None):
538
 
        """Copy the content of self into destination.
539
 
 
540
 
        revision_id: if not None, the revision history in the new branch will
541
 
                     be truncated to end with revision_id.
 
579
    def _synchronize_history(self, destination, revision_id):
 
580
        """Synchronize last revision and revision history between branches.
 
581
 
 
582
        This version is most efficient when the destination is also a
 
583
        BzrBranch5, but works for BzrBranch6 as long as the revision
 
584
        history is the true lefthand parent history, and all of the revisions
 
585
        are in the destination's repository.  If not, set_revision_history
 
586
        will fail.
 
587
 
 
588
        :param destination: The branch to copy the history into
 
589
        :param revision_id: The revision-id to truncate history at.  May
 
590
          be None to copy complete history.
542
591
        """
543
592
        new_history = self.revision_history()
544
593
        if revision_id is not None:
 
594
            revision_id = osutils.safe_revision_id(revision_id)
545
595
            try:
546
596
                new_history = new_history[:new_history.index(revision_id) + 1]
547
597
            except ValueError:
548
598
                rev = self.repository.get_revision(revision_id)
549
599
                new_history = rev.get_history(self.repository)[1:]
550
600
        destination.set_revision_history(new_history)
 
601
 
 
602
    @needs_read_lock
 
603
    def copy_content_into(self, destination, revision_id=None):
 
604
        """Copy the content of self into destination.
 
605
 
 
606
        revision_id: if not None, the revision history in the new branch will
 
607
                     be truncated to end with revision_id.
 
608
        """
 
609
        self._synchronize_history(destination, revision_id)
551
610
        try:
552
611
            parent = self.get_parent()
553
612
        except errors.InaccessibleParent, e:
591
650
        Weaves are used if this branch's repostory uses weaves.
592
651
        """
593
652
        if isinstance(self.bzrdir, bzrdir.BzrDirPreSplitOut):
594
 
            from bzrlib import repository
 
653
            from bzrlib.repofmt import weaverepo
595
654
            format = bzrdir.BzrDirMetaFormat1()
596
 
            format.repository_format = repository.RepositoryFormat7()
 
655
            format.repository_format = weaverepo.RepositoryFormat7()
597
656
        else:
598
657
            format = self.repository.bzrdir.cloning_metadir()
 
658
            format.branch_format = self._format
599
659
        return format
600
660
 
601
 
    def create_checkout(self, to_location, revision_id=None, 
 
661
    def create_checkout(self, to_location, revision_id=None,
602
662
                        lightweight=False):
603
663
        """Create a checkout of a branch.
604
664
        
627
687
            checkout_branch.pull(self, stop_revision=revision_id)
628
688
        return checkout.create_workingtree(revision_id)
629
689
 
 
690
    def supports_tags(self):
 
691
        return self._format.supports_tags()
 
692
 
630
693
 
631
694
class BranchFormat(object):
632
695
    """An encapsulation of the initialization and open routines for a format.
675
738
 
676
739
    def get_format_description(self):
677
740
        """Return the short format description for this format."""
678
 
        raise NotImplementedError(self.get_format_string)
 
741
        raise NotImplementedError(self.get_format_description)
 
742
 
 
743
    def _initialize_helper(self, a_bzrdir, utf8_files, lock_type='metadir',
 
744
                           set_format=True):
 
745
        """Initialize a branch in a bzrdir, with specified files
 
746
 
 
747
        :param a_bzrdir: The bzrdir to initialize the branch in
 
748
        :param utf8_files: The files to create as a list of
 
749
            (filename, content) tuples
 
750
        :param set_format: If True, set the format with
 
751
            self.get_format_string.  (BzrBranch4 has its format set
 
752
            elsewhere)
 
753
        :return: a branch in this format
 
754
        """
 
755
        mutter('creating branch %r in %s', self, a_bzrdir.transport.base)
 
756
        branch_transport = a_bzrdir.get_branch_transport(self)
 
757
        lock_map = {
 
758
            'metadir': ('lock', lockdir.LockDir),
 
759
            'branch4': ('branch-lock', lockable_files.TransportLock),
 
760
        }
 
761
        lock_name, lock_class = lock_map[lock_type]
 
762
        control_files = lockable_files.LockableFiles(branch_transport,
 
763
            lock_name, lock_class)
 
764
        control_files.create_lock()
 
765
        control_files.lock_write()
 
766
        if set_format:
 
767
            control_files.put_utf8('format', self.get_format_string())
 
768
        try:
 
769
            for file, content in utf8_files:
 
770
                control_files.put_utf8(file, content)
 
771
        finally:
 
772
            control_files.unlock()
 
773
        return self.open(a_bzrdir, _found=True)
679
774
 
680
775
    def initialize(self, a_bzrdir):
681
776
        """Create a branch of this format in a_bzrdir."""
714
809
    def __str__(self):
715
810
        return self.get_format_string().rstrip()
716
811
 
 
812
    def supports_tags(self):
 
813
        """True if this format supports tags stored in the branch"""
 
814
        return False  # by default
 
815
 
 
816
    # XXX: Probably doesn't really belong here -- mbp 20070212
 
817
    def _initialize_control_files(self, a_bzrdir, utf8_files, lock_filename,
 
818
            lock_class):
 
819
        branch_transport = a_bzrdir.get_branch_transport(self)
 
820
        control_files = lockable_files.LockableFiles(branch_transport,
 
821
            lock_filename, lock_class)
 
822
        control_files.create_lock()
 
823
        control_files.lock_write()
 
824
        try:
 
825
            for filename, content in utf8_files:
 
826
                control_files.put_utf8(filename, content)
 
827
        finally:
 
828
            control_files.unlock()
 
829
 
 
830
 
 
831
class BranchHooks(dict):
 
832
    """A dictionary mapping hook name to a list of callables for branch hooks.
 
833
    
 
834
    e.g. ['set_rh'] Is the list of items to be called when the
 
835
    set_revision_history function is invoked.
 
836
    """
 
837
 
 
838
    def __init__(self):
 
839
        """Create the default hooks.
 
840
 
 
841
        These are all empty initially, because by default nothing should get
 
842
        notified.
 
843
        """
 
844
        dict.__init__(self)
 
845
        # Introduced in 0.15:
 
846
        # invoked whenever the revision history has been set
 
847
        # with set_revision_history. The api signature is
 
848
        # (branch, revision_history), and the branch will
 
849
        # be write-locked.
 
850
        self['set_rh'] = []
 
851
        # invoked after a push operation completes.
 
852
        # the api signature is
 
853
        # (push_result)
 
854
        # containing the members
 
855
        # (source, local, master, old_revno, old_revid, new_revno, new_revid)
 
856
        # where local is the local branch or None, master is the target 
 
857
        # master branch, and the rest should be self explanatory. The source
 
858
        # is read locked and the target branches write locked. Source will
 
859
        # be the local low-latency branch.
 
860
        self['post_push'] = []
 
861
        # invoked after a pull operation completes.
 
862
        # the api signature is
 
863
        # (pull_result)
 
864
        # containing the members
 
865
        # (source, local, master, old_revno, old_revid, new_revno, new_revid)
 
866
        # where local is the local branch or None, master is the target 
 
867
        # master branch, and the rest should be self explanatory. The source
 
868
        # is read locked and the target branches write locked. The local
 
869
        # branch is the low-latency branch.
 
870
        self['post_pull'] = []
 
871
        # invoked after a commit operation completes.
 
872
        # the api signature is 
 
873
        # (local, master, old_revno, old_revid, new_revno, new_revid)
 
874
        # old_revid is NULL_REVISION for the first commit to a branch.
 
875
        self['post_commit'] = []
 
876
        # invoked after a uncommit operation completes.
 
877
        # the api signature is
 
878
        # (local, master, old_revno, old_revid, new_revno, new_revid) where
 
879
        # local is the local branch or None, master is the target branch,
 
880
        # and an empty branch recieves new_revno of 0, new_revid of None.
 
881
        self['post_uncommit'] = []
 
882
 
 
883
    def install_hook(self, hook_name, a_callable):
 
884
        """Install a_callable in to the hook hook_name.
 
885
 
 
886
        :param hook_name: A hook name. See the __init__ method of BranchHooks
 
887
            for the complete list of hooks.
 
888
        :param a_callable: The callable to be invoked when the hook triggers.
 
889
            The exact signature will depend on the hook - see the __init__ 
 
890
            method of BranchHooks for details on each hook.
 
891
        """
 
892
        try:
 
893
            self[hook_name].append(a_callable)
 
894
        except KeyError:
 
895
            raise errors.UnknownHook('branch', hook_name)
 
896
 
 
897
 
 
898
# install the default hooks into the Branch class.
 
899
Branch.hooks = BranchHooks()
 
900
 
717
901
 
718
902
class BzrBranchFormat4(BranchFormat):
719
903
    """Bzr branch format 4.
729
913
 
730
914
    def initialize(self, a_bzrdir):
731
915
        """Create a branch of this format in a_bzrdir."""
732
 
        mutter('creating branch in %s', a_bzrdir.transport.base)
733
 
        branch_transport = a_bzrdir.get_branch_transport(self)
734
916
        utf8_files = [('revision-history', ''),
735
917
                      ('branch-name', ''),
736
918
                      ]
737
 
        control_files = lockable_files.LockableFiles(branch_transport,
738
 
                             'branch-lock', lockable_files.TransportLock)
739
 
        control_files.create_lock()
740
 
        control_files.lock_write()
741
 
        try:
742
 
            for file, content in utf8_files:
743
 
                control_files.put_utf8(file, content)
744
 
        finally:
745
 
            control_files.unlock()
746
 
        return self.open(a_bzrdir, _found=True)
 
919
        return self._initialize_helper(a_bzrdir, utf8_files,
 
920
                                       lock_type='branch4', set_format=False)
747
921
 
748
922
    def __init__(self):
749
923
        super(BzrBranchFormat4, self).__init__()
790
964
        
791
965
    def initialize(self, a_bzrdir):
792
966
        """Create a branch of this format in a_bzrdir."""
793
 
        mutter('creating branch %r in %s', self, a_bzrdir.transport.base)
794
 
        branch_transport = a_bzrdir.get_branch_transport(self)
795
967
        utf8_files = [('revision-history', ''),
796
968
                      ('branch-name', ''),
797
969
                      ]
798
 
        control_files = lockable_files.LockableFiles(branch_transport, 'lock',
799
 
                                                     lockdir.LockDir)
800
 
        control_files.create_lock()
801
 
        control_files.lock_write()
802
 
        control_files.put_utf8('format', self.get_format_string())
803
 
        try:
804
 
            for file, content in utf8_files:
805
 
                control_files.put_utf8(file, content)
806
 
        finally:
807
 
            control_files.unlock()
808
 
        return self.open(a_bzrdir, _found=True, )
 
970
        return self._initialize_helper(a_bzrdir, utf8_files)
809
971
 
810
972
    def __init__(self):
811
973
        super(BzrBranchFormat5, self).__init__()
828
990
                          a_bzrdir=a_bzrdir,
829
991
                          _repository=a_bzrdir.find_repository())
830
992
 
831
 
    def __str__(self):
832
 
        return "Bazaar-NG Metadir branch format 5"
 
993
 
 
994
class BzrBranchFormat6(BzrBranchFormat5):
 
995
    """Branch format with last-revision
 
996
 
 
997
    Unlike previous formats, this has no explicit revision history. Instead,
 
998
    this just stores the last-revision, and the left-hand history leading
 
999
    up to there is the history.
 
1000
 
 
1001
    This format was introduced in bzr 0.15
 
1002
    """
 
1003
 
 
1004
    def get_format_string(self):
 
1005
        """See BranchFormat.get_format_string()."""
 
1006
        return "Bazaar-NG branch format 6\n"
 
1007
 
 
1008
    def get_format_description(self):
 
1009
        """See BranchFormat.get_format_description()."""
 
1010
        return "Branch format 6"
 
1011
 
 
1012
    def initialize(self, a_bzrdir):
 
1013
        """Create a branch of this format in a_bzrdir."""
 
1014
        utf8_files = [('last-revision', '0 null:\n'),
 
1015
                      ('branch-name', ''),
 
1016
                      ('branch.conf', ''),
 
1017
                      ('tags', ''),
 
1018
                      ]
 
1019
        return self._initialize_helper(a_bzrdir, utf8_files)
 
1020
 
 
1021
    def open(self, a_bzrdir, _found=False):
 
1022
        """Return the branch object for a_bzrdir
 
1023
 
 
1024
        _found is a private parameter, do not use it. It is used to indicate
 
1025
               if format probing has already be done.
 
1026
        """
 
1027
        if not _found:
 
1028
            format = BranchFormat.find_format(a_bzrdir)
 
1029
            assert format.__class__ == self.__class__
 
1030
        transport = a_bzrdir.get_branch_transport(None)
 
1031
        control_files = lockable_files.LockableFiles(transport, 'lock',
 
1032
                                                     lockdir.LockDir)
 
1033
        return BzrBranch6(_format=self,
 
1034
                          _control_files=control_files,
 
1035
                          a_bzrdir=a_bzrdir,
 
1036
                          _repository=a_bzrdir.find_repository())
 
1037
 
 
1038
    def supports_tags(self):
 
1039
        return True
833
1040
 
834
1041
 
835
1042
class BranchReferenceFormat(BranchFormat):
907
1114
__default_format = BzrBranchFormat5()
908
1115
BranchFormat.register_format(__default_format)
909
1116
BranchFormat.register_format(BranchReferenceFormat())
 
1117
BranchFormat.register_format(BzrBranchFormat6())
910
1118
BranchFormat.set_default_format(__default_format)
911
1119
_legacy_formats = [BzrBranchFormat4(),
912
1120
                   ]
935
1143
            upgrade/recovery type use; it's not guaranteed that
936
1144
            all operations will work on old format branches.
937
1145
        """
 
1146
        Branch.__init__(self)
938
1147
        if a_bzrdir is None:
939
1148
            self.bzrdir = bzrdir.BzrDir.open(transport.base)
940
1149
        else:
941
1150
            self.bzrdir = a_bzrdir
942
 
        self._transport = self.bzrdir.transport.clone('..')
943
 
        self._base = self._transport.base
 
1151
        # self._transport used to point to the directory containing the
 
1152
        # control directory, but was not used - now it's just the transport
 
1153
        # for the branch control files.  mbp 20070212
 
1154
        self._base = self.bzrdir.transport.clone('..').base
944
1155
        self._format = _format
945
1156
        if _control_files is None:
946
1157
            raise ValueError('BzrBranch _control_files is None')
947
1158
        self.control_files = _control_files
 
1159
        self._transport = _control_files._transport
948
1160
        if deprecated_passed(init):
949
1161
            warn("BzrBranch.__init__(..., init=XXX): The init parameter is "
950
1162
                 "deprecated as of bzr 0.8. Please use Branch.create().",
979
1191
    __repr__ = __str__
980
1192
 
981
1193
    def _get_base(self):
 
1194
        """Returns the directory containing the control directory."""
982
1195
        return self._base
983
1196
 
984
1197
    base = property(_get_base, doc="The URL for the root of this branch.")
1075
1288
    @needs_write_lock
1076
1289
    def append_revision(self, *revision_ids):
1077
1290
        """See Branch.append_revision."""
 
1291
        revision_ids = [osutils.safe_revision_id(r) for r in revision_ids]
1078
1292
        for revision_id in revision_ids:
 
1293
            _mod_revision.check_not_reserved_id(revision_id)
1079
1294
            mutter("add {%s} to revision-history" % revision_id)
1080
1295
        rev_history = self.revision_history()
1081
1296
        rev_history.extend(revision_ids)
1082
1297
        self.set_revision_history(rev_history)
1083
1298
 
 
1299
    def _write_revision_history(self, history):
 
1300
        """Factored out of set_revision_history.
 
1301
 
 
1302
        This performs the actual writing to disk.
 
1303
        It is intended to be called by BzrBranch5.set_revision_history."""
 
1304
        self.control_files.put_bytes(
 
1305
            'revision-history', '\n'.join(history))
 
1306
 
1084
1307
    @needs_write_lock
1085
1308
    def set_revision_history(self, rev_history):
1086
1309
        """See Branch.set_revision_history."""
1087
 
        self.control_files.put_utf8(
1088
 
            'revision-history', '\n'.join(rev_history))
 
1310
        rev_history = [osutils.safe_revision_id(r) for r in rev_history]
 
1311
        self._write_revision_history(rev_history)
1089
1312
        transaction = self.get_transaction()
1090
1313
        history = transaction.map.find_revision_history()
1091
1314
        if history is not None:
1099
1322
            # this call is disabled because revision_history is 
1100
1323
            # not really an object yet, and the transaction is for objects.
1101
1324
            # transaction.register_clean(history)
 
1325
        for hook in Branch.hooks['set_rh']:
 
1326
            hook(self, rev_history)
 
1327
 
 
1328
    @needs_write_lock
 
1329
    def set_last_revision_info(self, revno, revision_id):
 
1330
        revision_id = osutils.safe_revision_id(revision_id)
 
1331
        history = self._lefthand_history(revision_id)
 
1332
        assert len(history) == revno, '%d != %d' % (len(history), revno)
 
1333
        self.set_revision_history(history)
 
1334
 
 
1335
    def _gen_revision_history(self):
 
1336
        get_cached_utf8 = cache_utf8.get_cached_utf8
 
1337
        history = [get_cached_utf8(l.rstrip('\r\n')) for l in
 
1338
                self.control_files.get('revision-history').readlines()]
 
1339
        return history
1102
1340
 
1103
1341
    @needs_read_lock
1104
1342
    def revision_history(self):
1108
1346
        if history is not None:
1109
1347
            # mutter("cache hit for revision-history in %s", self)
1110
1348
            return list(history)
1111
 
        decode_utf8 = cache_utf8.decode
1112
 
        history = [decode_utf8(l.rstrip('\r\n')) for l in
1113
 
                self.control_files.get('revision-history').readlines()]
 
1349
        history = self._gen_revision_history()
1114
1350
        transaction.map.add_revision_history(history)
1115
1351
        # this call is disabled because revision_history is 
1116
1352
        # not really an object yet, and the transaction is for objects.
1117
1353
        # transaction.register_clean(history, precious=True)
1118
1354
        return list(history)
1119
1355
 
1120
 
    @needs_write_lock
1121
 
    def generate_revision_history(self, revision_id, last_rev=None, 
1122
 
        other_branch=None):
1123
 
        """Create a new revision history that will finish with revision_id.
1124
 
        
1125
 
        :param revision_id: the new tip to use.
1126
 
        :param last_rev: The previous last_revision. If not None, then this
1127
 
            must be a ancestory of revision_id, or DivergedBranches is raised.
1128
 
        :param other_branch: The other branch that DivergedBranches should
1129
 
            raise with respect to.
1130
 
        """
 
1356
    def _lefthand_history(self, revision_id, last_rev=None,
 
1357
                          other_branch=None):
1131
1358
        # stop_revision must be a descendant of last_revision
1132
1359
        stop_graph = self.repository.get_revision_graph(revision_id)
1133
1360
        if last_rev is not None and last_rev not in stop_graph:
1144
1371
            except IndexError:
1145
1372
                current_rev_id = None
1146
1373
        new_history.reverse()
1147
 
        self.set_revision_history(new_history)
 
1374
        return new_history
 
1375
 
 
1376
    @needs_write_lock
 
1377
    def generate_revision_history(self, revision_id, last_rev=None,
 
1378
        other_branch=None):
 
1379
        """Create a new revision history that will finish with revision_id.
 
1380
 
 
1381
        :param revision_id: the new tip to use.
 
1382
        :param last_rev: The previous last_revision. If not None, then this
 
1383
            must be a ancestory of revision_id, or DivergedBranches is raised.
 
1384
        :param other_branch: The other branch that DivergedBranches should
 
1385
            raise with respect to.
 
1386
        """
 
1387
        revision_id = osutils.safe_revision_id(revision_id)
 
1388
        self.set_revision_history(self._lefthand_history(revision_id,
 
1389
            last_rev, other_branch))
1148
1390
 
1149
1391
    @needs_write_lock
1150
1392
    def update_revisions(self, other, stop_revision=None):
1156
1398
                if stop_revision is None:
1157
1399
                    # if there are no commits, we're done.
1158
1400
                    return
 
1401
            else:
 
1402
                stop_revision = osutils.safe_revision_id(stop_revision)
1159
1403
            # whats the current last revision, before we fetch [and change it
1160
1404
            # possibly]
1161
1405
            last_rev = self.last_revision()
1186
1430
        return self.bzrdir.open_workingtree()
1187
1431
 
1188
1432
    @needs_write_lock
1189
 
    def pull(self, source, overwrite=False, stop_revision=None):
1190
 
        """See Branch.pull."""
 
1433
    def pull(self, source, overwrite=False, stop_revision=None,
 
1434
        _hook_master=None, _run_hooks=True):
 
1435
        """See Branch.pull.
 
1436
 
 
1437
        :param _hook_master: Private parameter - set the branch to 
 
1438
            be supplied as the master to push hooks.
 
1439
        :param _run_hooks: Private parameter - allow disabling of
 
1440
            hooks, used when pushing to a master branch.
 
1441
        """
 
1442
        result = PullResult()
 
1443
        result.source_branch = source
 
1444
        result.target_branch = self
1191
1445
        source.lock_read()
1192
1446
        try:
1193
 
            old_count = len(self.revision_history())
 
1447
            result.old_revno, result.old_revid = self.last_revision_info()
1194
1448
            try:
1195
1449
                self.update_revisions(source, stop_revision)
1196
1450
            except DivergedBranches:
1197
1451
                if not overwrite:
1198
1452
                    raise
1199
1453
            if overwrite:
1200
 
                self.set_revision_history(source.revision_history())
1201
 
            new_count = len(self.revision_history())
1202
 
            return new_count - old_count
 
1454
                if stop_revision is None:
 
1455
                    stop_revision = source.last_revision()
 
1456
                self.generate_revision_history(stop_revision)
 
1457
            result.tag_conflicts = source.tags.merge_to(self.tags)
 
1458
            result.new_revno, result.new_revid = self.last_revision_info()
 
1459
            if _hook_master:
 
1460
                result.master_branch = _hook_master
 
1461
                result.local_branch = self
 
1462
            else:
 
1463
                result.master_branch = self
 
1464
                result.local_branch = None
 
1465
            if _run_hooks:
 
1466
                for hook in Branch.hooks['post_pull']:
 
1467
                    hook(result)
1203
1468
        finally:
1204
1469
            source.unlock()
 
1470
        return result
 
1471
 
 
1472
    def _get_parent_location(self):
 
1473
        _locs = ['parent', 'pull', 'x-pull']
 
1474
        for l in _locs:
 
1475
            try:
 
1476
                return self.control_files.get(l).read().strip('\n')
 
1477
            except NoSuchFile:
 
1478
                pass
 
1479
        return None
 
1480
 
 
1481
    @needs_read_lock
 
1482
    def push(self, target, overwrite=False, stop_revision=None,
 
1483
        _hook_master=None, _run_hooks=True):
 
1484
        """See Branch.push.
 
1485
        
 
1486
        :param _hook_master: Private parameter - set the branch to 
 
1487
            be supplied as the master to push hooks.
 
1488
        :param _run_hooks: Private parameter - allow disabling of
 
1489
            hooks, used when pushing to a master branch.
 
1490
        """
 
1491
        result = PushResult()
 
1492
        result.source_branch = self
 
1493
        result.target_branch = target
 
1494
        target.lock_write()
 
1495
        try:
 
1496
            result.old_revno, result.old_revid = target.last_revision_info()
 
1497
            try:
 
1498
                target.update_revisions(self, stop_revision)
 
1499
            except DivergedBranches:
 
1500
                if not overwrite:
 
1501
                    raise
 
1502
            if overwrite:
 
1503
                target.set_revision_history(self.revision_history())
 
1504
            result.tag_conflicts = self.tags.merge_to(target.tags)
 
1505
            result.new_revno, result.new_revid = target.last_revision_info()
 
1506
            if _hook_master:
 
1507
                result.master_branch = _hook_master
 
1508
                result.local_branch = target
 
1509
            else:
 
1510
                result.master_branch = target
 
1511
                result.local_branch = None
 
1512
            if _run_hooks:
 
1513
                for hook in Branch.hooks['post_push']:
 
1514
                    hook(result)
 
1515
        finally:
 
1516
            target.unlock()
 
1517
        return result
1205
1518
 
1206
1519
    def get_parent(self):
1207
1520
        """See Branch.get_parent."""
1208
1521
 
1209
 
        _locs = ['parent', 'pull', 'x-pull']
1210
1522
        assert self.base[-1] == '/'
1211
 
        for l in _locs:
1212
 
            try:
1213
 
                parent = self.control_files.get(l).read().strip('\n')
1214
 
            except NoSuchFile:
1215
 
                continue
1216
 
            # This is an old-format absolute path to a local branch
1217
 
            # turn it into a url
1218
 
            if parent.startswith('/'):
1219
 
                parent = urlutils.local_path_to_url(parent.decode('utf8'))
1220
 
            try:
1221
 
                return urlutils.join(self.base[:-1], parent)
1222
 
            except errors.InvalidURLJoin, e:
1223
 
                raise errors.InaccessibleParent(parent, self.base)
1224
 
        return None
 
1523
        parent = self._get_parent_location()
 
1524
        if parent is None:
 
1525
            return parent
 
1526
        # This is an old-format absolute path to a local branch
 
1527
        # turn it into a url
 
1528
        if parent.startswith('/'):
 
1529
            parent = urlutils.local_path_to_url(parent.decode('utf8'))
 
1530
        try:
 
1531
            return urlutils.join(self.base[:-1], parent)
 
1532
        except errors.InvalidURLJoin, e:
 
1533
            raise errors.InaccessibleParent(parent, self.base)
1225
1534
 
1226
1535
    def get_push_location(self):
1227
1536
        """See Branch.get_push_location."""
1230
1539
 
1231
1540
    def set_push_location(self, location):
1232
1541
        """See Branch.set_push_location."""
1233
 
        self.get_config().set_user_option('push_location', location, 
1234
 
                                          local=True)
 
1542
        self.get_config().set_user_option(
 
1543
            'push_location', location,
 
1544
            store=_mod_config.STORE_LOCATION_NORECURSE)
1235
1545
 
1236
1546
    @needs_write_lock
1237
1547
    def set_parent(self, url):
1241
1551
        # FIXUP this and get_parent in a future branch format bump:
1242
1552
        # read and rewrite the file, and have the new format code read
1243
1553
        # using .get not .get_utf8. RBC 20060125
1244
 
        if url is None:
1245
 
            self.control_files._transport.delete('parent')
1246
 
        else:
 
1554
        if url is not None:
1247
1555
            if isinstance(url, unicode):
1248
1556
                try: 
1249
1557
                    url = url.encode('ascii')
1251
1559
                    raise bzrlib.errors.InvalidURL(url,
1252
1560
                        "Urls must be 7-bit ascii, "
1253
1561
                        "use bzrlib.urlutils.escape")
1254
 
                    
1255
1562
            url = urlutils.relative_url(self.base, url)
1256
 
            self.control_files.put('parent', StringIO(url + '\n'))
 
1563
        self._set_parent_location(url)
 
1564
 
 
1565
    def _set_parent_location(self, url):
 
1566
        if url is None:
 
1567
            self.control_files._transport.delete('parent')
 
1568
        else:
 
1569
            assert isinstance(url, str)
 
1570
            self.control_files.put_bytes('parent', url + '\n')
1257
1571
 
1258
1572
    @deprecated_function(zero_nine)
1259
1573
    def tree_config(self):
1279
1593
                                         _repository=_repository)
1280
1594
        
1281
1595
    @needs_write_lock
1282
 
    def pull(self, source, overwrite=False, stop_revision=None):
1283
 
        """Updates branch.pull to be bound branch aware."""
 
1596
    def pull(self, source, overwrite=False, stop_revision=None,
 
1597
        _run_hooks=True):
 
1598
        """Extends branch.pull to be bound branch aware.
 
1599
        
 
1600
        :param _run_hooks: Private parameter used to force hook running
 
1601
            off during bound branch double-pushing.
 
1602
        """
1284
1603
        bound_location = self.get_bound_location()
1285
 
        if source.base != bound_location:
 
1604
        master_branch = None
 
1605
        if bound_location and source.base != bound_location:
1286
1606
            # not pulling from master, so we need to update master.
1287
1607
            master_branch = self.get_master_branch()
1288
 
            if master_branch:
1289
 
                master_branch.pull(source)
1290
 
                source = master_branch
1291
 
        return super(BzrBranch5, self).pull(source, overwrite, stop_revision)
 
1608
            master_branch.lock_write()
 
1609
        try:
 
1610
            if master_branch:
 
1611
                # pull from source into master.
 
1612
                master_branch.pull(source, overwrite, stop_revision,
 
1613
                    _run_hooks=False)
 
1614
            return super(BzrBranch5, self).pull(source, overwrite,
 
1615
                stop_revision, _hook_master=master_branch,
 
1616
                _run_hooks=_run_hooks)
 
1617
        finally:
 
1618
            if master_branch:
 
1619
                master_branch.unlock()
 
1620
 
 
1621
    @needs_read_lock
 
1622
    def push(self, target, overwrite=False, stop_revision=None):
 
1623
        """Updates branch.push to be bound branch aware."""
 
1624
        bound_location = target.get_bound_location()
 
1625
        master_branch = None
 
1626
        if bound_location and target.base != bound_location:
 
1627
            # not pushing to master, so we need to update master.
 
1628
            master_branch = target.get_master_branch()
 
1629
            master_branch.lock_write()
 
1630
        try:
 
1631
            if master_branch:
 
1632
                # push into the master from this branch.
 
1633
                super(BzrBranch5, self).push(master_branch, overwrite,
 
1634
                    stop_revision, _run_hooks=False)
 
1635
            # and push into the target branch from this. Note that we push from
 
1636
            # this branch again, because its considered the highest bandwidth
 
1637
            # repository.
 
1638
            return super(BzrBranch5, self).push(target, overwrite,
 
1639
                stop_revision, _hook_master=master_branch)
 
1640
        finally:
 
1641
            if master_branch:
 
1642
                master_branch.unlock()
1292
1643
 
1293
1644
    def get_bound_location(self):
1294
1645
        try:
1395
1746
        return None
1396
1747
 
1397
1748
 
 
1749
class BzrBranchExperimental(BzrBranch5):
 
1750
    """Bzr experimental branch format
 
1751
 
 
1752
    This format has:
 
1753
     - a revision-history file.
 
1754
     - a format string
 
1755
     - a lock dir guarding the branch itself
 
1756
     - all of this stored in a branch/ subdirectory
 
1757
     - works with shared repositories.
 
1758
     - a tag dictionary in the branch
 
1759
 
 
1760
    This format is new in bzr 0.15, but shouldn't be used for real data, 
 
1761
    only for testing.
 
1762
 
 
1763
    This class acts as it's own BranchFormat.
 
1764
    """
 
1765
 
 
1766
    _matchingbzrdir = bzrdir.BzrDirMetaFormat1()
 
1767
 
 
1768
    @classmethod
 
1769
    def get_format_string(cls):
 
1770
        """See BranchFormat.get_format_string()."""
 
1771
        return "Bazaar-NG branch format experimental\n"
 
1772
 
 
1773
    @classmethod
 
1774
    def get_format_description(cls):
 
1775
        """See BranchFormat.get_format_description()."""
 
1776
        return "Experimental branch format"
 
1777
 
 
1778
    @classmethod
 
1779
    def _initialize_control_files(cls, a_bzrdir, utf8_files, lock_filename,
 
1780
            lock_class):
 
1781
        branch_transport = a_bzrdir.get_branch_transport(cls)
 
1782
        control_files = lockable_files.LockableFiles(branch_transport,
 
1783
            lock_filename, lock_class)
 
1784
        control_files.create_lock()
 
1785
        control_files.lock_write()
 
1786
        try:
 
1787
            for filename, content in utf8_files:
 
1788
                control_files.put_utf8(filename, content)
 
1789
        finally:
 
1790
            control_files.unlock()
 
1791
        
 
1792
    @classmethod
 
1793
    def initialize(cls, a_bzrdir):
 
1794
        """Create a branch of this format in a_bzrdir."""
 
1795
        utf8_files = [('format', cls.get_format_string()),
 
1796
                      ('revision-history', ''),
 
1797
                      ('branch-name', ''),
 
1798
                      ('tags', ''),
 
1799
                      ]
 
1800
        cls._initialize_control_files(a_bzrdir, utf8_files,
 
1801
            'lock', lockdir.LockDir)
 
1802
        return cls.open(a_bzrdir, _found=True)
 
1803
 
 
1804
    @classmethod
 
1805
    def open(cls, a_bzrdir, _found=False):
 
1806
        """Return the branch object for a_bzrdir
 
1807
 
 
1808
        _found is a private parameter, do not use it. It is used to indicate
 
1809
               if format probing has already be done.
 
1810
        """
 
1811
        if not _found:
 
1812
            format = BranchFormat.find_format(a_bzrdir)
 
1813
            assert format.__class__ == cls
 
1814
        transport = a_bzrdir.get_branch_transport(None)
 
1815
        control_files = lockable_files.LockableFiles(transport, 'lock',
 
1816
                                                     lockdir.LockDir)
 
1817
        return cls(_format=cls,
 
1818
            _control_files=control_files,
 
1819
            a_bzrdir=a_bzrdir,
 
1820
            _repository=a_bzrdir.find_repository())
 
1821
 
 
1822
    @classmethod
 
1823
    def is_supported(cls):
 
1824
        return True
 
1825
 
 
1826
    def _make_tags(self):
 
1827
        return BasicTags(self)
 
1828
 
 
1829
    @classmethod
 
1830
    def supports_tags(cls):
 
1831
        return True
 
1832
 
 
1833
 
 
1834
BranchFormat.register_format(BzrBranchExperimental)
 
1835
 
 
1836
 
 
1837
class BzrBranch6(BzrBranch5):
 
1838
 
 
1839
    @needs_read_lock
 
1840
    def last_revision_info(self):
 
1841
        revision_string = self.control_files.get('last-revision').read()
 
1842
        revno, revision_id = revision_string.rstrip('\n').split(' ', 1)
 
1843
        revision_id = cache_utf8.get_cached_utf8(revision_id)
 
1844
        revno = int(revno)
 
1845
        return revno, revision_id
 
1846
 
 
1847
    def last_revision(self):
 
1848
        """Return last revision id, or None"""
 
1849
        revision_id = self.last_revision_info()[1]
 
1850
        if revision_id == _mod_revision.NULL_REVISION:
 
1851
            revision_id = None
 
1852
        return revision_id
 
1853
 
 
1854
    def _write_last_revision_info(self, revno, revision_id):
 
1855
        """Simply write out the revision id, with no checks.
 
1856
 
 
1857
        Use set_last_revision_info to perform this safely.
 
1858
 
 
1859
        Does not update the revision_history cache.
 
1860
        Intended to be called by set_last_revision_info and
 
1861
        _write_revision_history.
 
1862
        """
 
1863
        if revision_id is None:
 
1864
            revision_id = 'null:'
 
1865
        out_string = '%d %s\n' % (revno, revision_id)
 
1866
        self.control_files.put_bytes('last-revision', out_string)
 
1867
 
 
1868
    @needs_write_lock
 
1869
    def set_last_revision_info(self, revno, revision_id):
 
1870
        revision_id = osutils.safe_revision_id(revision_id)
 
1871
        if self._get_append_revisions_only():
 
1872
            self._check_history_violation(revision_id)
 
1873
        self._write_last_revision_info(revno, revision_id)
 
1874
        transaction = self.get_transaction()
 
1875
        cached_history = transaction.map.find_revision_history()
 
1876
        if cached_history is not None:
 
1877
            transaction.map.remove_object(cached_history)
 
1878
 
 
1879
    def _check_history_violation(self, revision_id):
 
1880
        last_revision = self.last_revision()
 
1881
        if last_revision is None:
 
1882
            return
 
1883
        if last_revision not in self._lefthand_history(revision_id):
 
1884
            raise errors.AppendRevisionsOnlyViolation(self.base)
 
1885
 
 
1886
    def _gen_revision_history(self):
 
1887
        """Generate the revision history from last revision
 
1888
        """
 
1889
        history = list(self.repository.iter_reverse_revision_history(
 
1890
            self.last_revision()))
 
1891
        history.reverse()
 
1892
        return history
 
1893
 
 
1894
    def _write_revision_history(self, history):
 
1895
        """Factored out of set_revision_history.
 
1896
 
 
1897
        This performs the actual writing to disk, with format-specific checks.
 
1898
        It is intended to be called by BzrBranch5.set_revision_history.
 
1899
        """
 
1900
        if len(history) == 0:
 
1901
            last_revision = 'null:'
 
1902
        else:
 
1903
            if history != self._lefthand_history(history[-1]):
 
1904
                raise errors.NotLefthandHistory(history)
 
1905
            last_revision = history[-1]
 
1906
        if self._get_append_revisions_only():
 
1907
            self._check_history_violation(last_revision)
 
1908
        self._write_last_revision_info(len(history), last_revision)
 
1909
 
 
1910
    @needs_write_lock
 
1911
    def append_revision(self, *revision_ids):
 
1912
        revision_ids = [osutils.safe_revision_id(r) for r in revision_ids]
 
1913
        if len(revision_ids) == 0:
 
1914
            return
 
1915
        prev_revno, prev_revision = self.last_revision_info()
 
1916
        for revision in self.repository.get_revisions(revision_ids):
 
1917
            if prev_revision == _mod_revision.NULL_REVISION:
 
1918
                if revision.parent_ids != []:
 
1919
                    raise errors.NotLeftParentDescendant(self, prev_revision,
 
1920
                                                         revision.revision_id)
 
1921
            else:
 
1922
                if revision.parent_ids[0] != prev_revision:
 
1923
                    raise errors.NotLeftParentDescendant(self, prev_revision,
 
1924
                                                         revision.revision_id)
 
1925
            prev_revision = revision.revision_id
 
1926
        self.set_last_revision_info(prev_revno + len(revision_ids),
 
1927
                                    revision_ids[-1])
 
1928
 
 
1929
    def _set_config_location(self, name, url, config=None,
 
1930
                             make_relative=False):
 
1931
        if config is None:
 
1932
            config = self.get_config()
 
1933
        if url is None:
 
1934
            url = ''
 
1935
        elif make_relative:
 
1936
            url = urlutils.relative_url(self.base, url)
 
1937
        config.set_user_option(name, url)
 
1938
 
 
1939
 
 
1940
    def _get_config_location(self, name, config=None):
 
1941
        if config is None:
 
1942
            config = self.get_config()
 
1943
        location = config.get_user_option(name)
 
1944
        if location == '':
 
1945
            location = None
 
1946
        return location
 
1947
 
 
1948
    @needs_write_lock
 
1949
    def _set_parent_location(self, url):
 
1950
        """Set the parent branch"""
 
1951
        self._set_config_location('parent_location', url, make_relative=True)
 
1952
 
 
1953
    @needs_read_lock
 
1954
    def _get_parent_location(self):
 
1955
        """Set the parent branch"""
 
1956
        return self._get_config_location('parent_location')
 
1957
 
 
1958
    def set_push_location(self, location):
 
1959
        """See Branch.set_push_location."""
 
1960
        self._set_config_location('push_location', location)
 
1961
 
 
1962
    def set_bound_location(self, location):
 
1963
        """See Branch.set_push_location."""
 
1964
        result = None
 
1965
        config = self.get_config()
 
1966
        if location is None:
 
1967
            if config.get_user_option('bound') != 'True':
 
1968
                return False
 
1969
            else:
 
1970
                config.set_user_option('bound', 'False')
 
1971
                return True
 
1972
        else:
 
1973
            self._set_config_location('bound_location', location,
 
1974
                                      config=config)
 
1975
            config.set_user_option('bound', 'True')
 
1976
        return True
 
1977
 
 
1978
    def _get_bound_location(self, bound):
 
1979
        """Return the bound location in the config file.
 
1980
 
 
1981
        Return None if the bound parameter does not match"""
 
1982
        config = self.get_config()
 
1983
        config_bound = (config.get_user_option('bound') == 'True')
 
1984
        if config_bound != bound:
 
1985
            return None
 
1986
        return self._get_config_location('bound_location', config=config)
 
1987
 
 
1988
    def get_bound_location(self):
 
1989
        """See Branch.set_push_location."""
 
1990
        return self._get_bound_location(True)
 
1991
 
 
1992
    def get_old_bound_location(self):
 
1993
        """See Branch.get_old_bound_location"""
 
1994
        return self._get_bound_location(False)
 
1995
 
 
1996
    def set_append_revisions_only(self, enabled):
 
1997
        if enabled:
 
1998
            value = 'True'
 
1999
        else:
 
2000
            value = 'False'
 
2001
        self.get_config().set_user_option('append_revisions_only', value)
 
2002
 
 
2003
    def _get_append_revisions_only(self):
 
2004
        value = self.get_config().get_user_option('append_revisions_only')
 
2005
        return value == 'True'
 
2006
 
 
2007
    def _synchronize_history(self, destination, revision_id):
 
2008
        """Synchronize last revision and revision history between branches.
 
2009
 
 
2010
        This version is most efficient when the destination is also a
 
2011
        BzrBranch6, but works for BzrBranch5, as long as the destination's
 
2012
        repository contains all the lefthand ancestors of the intended
 
2013
        last_revision.  If not, set_last_revision_info will fail.
 
2014
 
 
2015
        :param destination: The branch to copy the history into
 
2016
        :param revision_id: The revision-id to truncate history at.  May
 
2017
          be None to copy complete history.
 
2018
        """
 
2019
        if revision_id is None:
 
2020
            revno, revision_id = self.last_revision_info()
 
2021
        else:
 
2022
            revno = self.revision_id_to_revno(revision_id)
 
2023
        destination.set_last_revision_info(revno, revision_id)
 
2024
 
 
2025
    def _make_tags(self):
 
2026
        return BasicTags(self)
 
2027
 
 
2028
 
1398
2029
class BranchTestProviderAdapter(object):
1399
2030
    """A tool to generate a suite testing multiple branch formats at once.
1400
2031
 
1418
2049
            new_test.bzrdir_format = bzrdir_format
1419
2050
            new_test.branch_format = branch_format
1420
2051
            def make_new_test_id():
1421
 
                new_id = "%s(%s)" % (new_test.id(), branch_format.__class__.__name__)
 
2052
                # the format can be either a class or an instance
 
2053
                name = getattr(branch_format, '__name__',
 
2054
                        branch_format.__class__.__name__)
 
2055
                new_id = "%s(%s)" % (new_test.id(), name)
1422
2056
                return lambda: new_id
1423
2057
            new_test.id = make_new_test_id()
1424
2058
            result.addTest(new_test)
1425
2059
        return result
1426
2060
 
1427
2061
 
 
2062
######################################################################
 
2063
# results of operations
 
2064
 
 
2065
 
 
2066
class _Result(object):
 
2067
 
 
2068
    def _show_tag_conficts(self, to_file):
 
2069
        if not getattr(self, 'tag_conflicts', None):
 
2070
            return
 
2071
        to_file.write('Conflicting tags:\n')
 
2072
        for name, value1, value2 in self.tag_conflicts:
 
2073
            to_file.write('    %s\n' % (name, ))
 
2074
 
 
2075
 
 
2076
class PullResult(_Result):
 
2077
    """Result of a Branch.pull operation.
 
2078
 
 
2079
    :ivar old_revno: Revision number before pull.
 
2080
    :ivar new_revno: Revision number after pull.
 
2081
    :ivar old_revid: Tip revision id before pull.
 
2082
    :ivar new_revid: Tip revision id after pull.
 
2083
    :ivar source_branch: Source (local) branch object.
 
2084
    :ivar master_branch: Master branch of the target, or None.
 
2085
    :ivar target_branch: Target/destination branch object.
 
2086
    """
 
2087
 
 
2088
    def __int__(self):
 
2089
        # DEPRECATED: pull used to return the change in revno
 
2090
        return self.new_revno - self.old_revno
 
2091
 
 
2092
    def report(self, to_file):
 
2093
        if self.old_revid == self.new_revid:
 
2094
            to_file.write('No revisions to pull.\n')
 
2095
        else:
 
2096
            to_file.write('Now on revision %d.\n' % self.new_revno)
 
2097
        self._show_tag_conficts(to_file)
 
2098
 
 
2099
 
 
2100
class PushResult(_Result):
 
2101
    """Result of a Branch.push operation.
 
2102
 
 
2103
    :ivar old_revno: Revision number before push.
 
2104
    :ivar new_revno: Revision number after push.
 
2105
    :ivar old_revid: Tip revision id before push.
 
2106
    :ivar new_revid: Tip revision id after push.
 
2107
    :ivar source_branch: Source branch object.
 
2108
    :ivar master_branch: Master branch of the target, or None.
 
2109
    :ivar target_branch: Target/destination branch object.
 
2110
    """
 
2111
 
 
2112
    def __int__(self):
 
2113
        # DEPRECATED: push used to return the change in revno
 
2114
        return self.new_revno - self.old_revno
 
2115
 
 
2116
    def report(self, to_file):
 
2117
        """Write a human-readable description of the result."""
 
2118
        if self.old_revid == self.new_revid:
 
2119
            to_file.write('No new revisions to push.\n')
 
2120
        else:
 
2121
            to_file.write('Pushed up to revision %d.\n' % self.new_revno)
 
2122
        self._show_tag_conficts(to_file)
 
2123
 
 
2124
 
1428
2125
class BranchCheckResult(object):
1429
2126
    """Results of checking branch consistency.
1430
2127
 
1445
2142
             self.branch._format)
1446
2143
 
1447
2144
 
1448
 
######################################################################
1449
 
# predicates
1450
 
 
1451
 
 
1452
 
@deprecated_function(zero_eight)
1453
 
def is_control_file(*args, **kwargs):
1454
 
    """See bzrlib.workingtree.is_control_file."""
1455
 
    return bzrlib.workingtree.is_control_file(*args, **kwargs)
 
2145
class Converter5to6(object):
 
2146
    """Perform an in-place upgrade of format 5 to format 6"""
 
2147
 
 
2148
    def convert(self, branch):
 
2149
        # Data for 5 and 6 can peacefully coexist.
 
2150
        format = BzrBranchFormat6()
 
2151
        new_branch = format.open(branch.bzrdir, _found=True)
 
2152
 
 
2153
        # Copy source data into target
 
2154
        new_branch.set_last_revision_info(*branch.last_revision_info())
 
2155
        new_branch.set_parent(branch.get_parent())
 
2156
        new_branch.set_bound_location(branch.get_bound_location())
 
2157
        new_branch.set_push_location(branch.get_push_location())
 
2158
 
 
2159
        # New branch has no tags by default
 
2160
        new_branch.tags._set_tag_dict({})
 
2161
 
 
2162
        # Copying done; now update target format
 
2163
        new_branch.control_files.put_utf8('format',
 
2164
            format.get_format_string())
 
2165
 
 
2166
        # Clean up old files
 
2167
        new_branch.control_files._transport.delete('revision-history')
 
2168
        try:
 
2169
            branch.set_parent(None)
 
2170
        except NoSuchFile:
 
2171
            pass
 
2172
        branch.set_bound_location(None)