/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: Robert Collins
  • Date: 2009-02-24 08:09:17 UTC
  • mfrom: (4037 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4038.
  • Revision ID: robertc@robertcollins.net-20090224080917-9k7ib4oj1godlp3k
Merge bzr (resolve conflicts).

Show diffs side-by-side

added added

removed removed

Lines of Context:
135
135
    @staticmethod
136
136
    def open_containing(url, possible_transports=None):
137
137
        """Open an existing branch which contains url.
138
 
        
 
138
 
139
139
        This probes for a branch at url, and searches upwards from there.
140
140
 
141
141
        Basically we keep looking up until we find the control directory or
142
142
        run into the root.  If there isn't one, raises NotBranchError.
143
 
        If there is one and it is either an unrecognised format or an unsupported 
 
143
        If there is one and it is either an unrecognised format or an unsupported
144
144
        format, UnknownFormatError or UnsupportedFormatError are raised.
145
145
        If there is one, it is returned, along with the unused portion of url.
146
146
        """
256
256
    @needs_read_lock
257
257
    def revision_id_to_dotted_revno(self, revision_id):
258
258
        """Given a revision id, return its dotted revno.
259
 
        
 
259
 
260
260
        :return: a tuple like (1,) or (400,1,3).
261
261
        """
262
262
        return self._do_revision_id_to_dotted_revno(revision_id)
426
426
    def leave_lock_in_place(self):
427
427
        """Tell this branch object not to release the physical lock when this
428
428
        object is unlocked.
429
 
        
 
429
 
430
430
        If lock_write doesn't return a token, then this method is not supported.
431
431
        """
432
432
        self.control_files.leave_in_place()
488
488
        branch.
489
489
        """
490
490
        return None
491
 
    
 
491
 
492
492
    def get_old_bound_location(self):
493
493
        """Return the URL of the branch we used to be bound to
494
494
        """
495
495
        raise errors.UpgradeRequired(self.base)
496
496
 
497
 
    def get_commit_builder(self, parents, config=None, timestamp=None, 
498
 
                           timezone=None, committer=None, revprops=None, 
 
497
    def get_commit_builder(self, parents, config=None, timestamp=None,
 
498
                           timezone=None, committer=None, revprops=None,
499
499
                           revision_id=None):
500
500
        """Obtain a CommitBuilder for this branch.
501
 
        
 
501
 
502
502
        :param parents: Revision ids of the parents of the new revision.
503
503
        :param config: Optional configuration to use.
504
504
        :param timestamp: Optional timestamp recorded for commit.
510
510
 
511
511
        if config is None:
512
512
            config = self.get_config()
513
 
        
 
513
 
514
514
        return self.repository.get_commit_builder(self, parents, config,
515
515
            timestamp, timezone, committer, revprops, revision_id)
516
516
 
517
517
    def get_master_branch(self, possible_transports=None):
518
518
        """Return the branch we are bound to.
519
 
        
 
519
 
520
520
        :return: Either a Branch, or None
521
521
        """
522
522
        return None
593
593
 
594
594
    def _gen_revision_history(self):
595
595
        """Return sequence of revision hashes on to this branch.
596
 
        
 
596
 
597
597
        Unlike revision_history, this method always regenerates or rereads the
598
598
        revision history, i.e. it does not cache the result, so repeated calls
599
599
        may be expensive.
600
600
 
601
601
        Concrete subclasses should override this instead of revision_history so
602
602
        that subclasses do not need to deal with caching logic.
603
 
        
 
603
 
604
604
        This API is semi-public; it only for use by subclasses, all other code
605
605
        should consider it to be private.
606
606
        """
609
609
    @needs_read_lock
610
610
    def revision_history(self):
611
611
        """Return sequence of revision ids on this branch.
612
 
        
 
612
 
613
613
        This method will cache the revision history for as long as it is safe to
614
614
        do so.
615
615
        """
663
663
    @deprecated_method(deprecated_in((1, 6, 0)))
664
664
    def missing_revisions(self, other, stop_revision=None):
665
665
        """Return a list of new revisions that would perfectly fit.
666
 
        
 
666
 
667
667
        If self and other have not diverged, return a list of the revisions
668
668
        present in other, but missing from self.
669
669
        """
711
711
            # possibly]
712
712
            last_rev = _mod_revision.ensure_null(self.last_revision())
713
713
            # we fetch here so that we don't process data twice in the common
714
 
            # case of having something to pull, and so that the check for 
 
714
            # case of having something to pull, and so that the check for
715
715
            # already merged can operate on the just fetched graph, which will
716
716
            # be cached in memory.
717
717
            self.fetch(other, stop_revision)
779
779
    def get_parent(self):
780
780
        """Return the parent location of the branch.
781
781
 
782
 
        This is the default location for push/pull/missing.  The usual
 
782
        This is the default location for pull/missing.  The usual
783
783
        pattern is that the user can override it by specifying a
784
784
        location.
785
785
        """
882
882
 
883
883
    @needs_write_lock
884
884
    def update(self):
885
 
        """Synchronise this branch with the master branch if any. 
 
885
        """Synchronise this branch with the master branch if any.
886
886
 
887
887
        :return: None or the last_revision pivoted out during the update.
888
888
        """
895
895
        """
896
896
        if revno != 0:
897
897
            self.check_real_revno(revno)
898
 
            
 
898
 
899
899
    def check_real_revno(self, revno):
900
900
        """\
901
901
        Check whether a revno corresponds to a real revision.
907
907
    @needs_read_lock
908
908
    def clone(self, to_bzrdir, revision_id=None):
909
909
        """Clone this branch into to_bzrdir preserving all semantic values.
910
 
        
 
910
 
911
911
        revision_id: if not None, the revision history in the new branch will
912
912
                     be truncated to end with revision_id.
913
913
        """
957
957
            revno = len(list(self.repository.iter_reverse_revision_history(
958
958
                                                                revision_id)))
959
959
        destination.set_last_revision_info(revno, revision_id)
960
 
    
 
960
 
961
961
    @needs_read_lock
962
962
    def copy_content_into(self, destination, revision_id=None):
963
963
        """Copy the content of self into destination.
981
981
        """Check consistency of the branch.
982
982
 
983
983
        In particular this checks that revisions given in the revision-history
984
 
        do actually match up in the revision graph, and that they're all 
 
984
        do actually match up in the revision graph, and that they're all
985
985
        present in the repository.
986
 
        
 
986
 
987
987
        Callers will typically also want to check the repository.
988
988
 
989
989
        :return: A BranchCheckResult.
1032
1032
                        lightweight=False, accelerator_tree=None,
1033
1033
                        hardlink=False):
1034
1034
        """Create a checkout of a branch.
1035
 
        
 
1035
 
1036
1036
        :param to_location: The url to produce the checkout at
1037
1037
        :param revision_id: The revision to check out
1038
1038
        :param lightweight: If True, produce a lightweight checkout, otherwise,
1057
1057
                to_location, force_new_tree=False, format=format)
1058
1058
            checkout = checkout_branch.bzrdir
1059
1059
            checkout_branch.bind(self)
1060
 
            # pull up to the specified revision_id to set the initial 
 
1060
            # pull up to the specified revision_id to set the initial
1061
1061
            # branch tip correctly, and seed it with history.
1062
1062
            checkout_branch.pull(self, stop_revision=revision_id)
1063
1063
            from_branch=None
1102
1102
        """Ensure that revision_b is a descendant of revision_a.
1103
1103
 
1104
1104
        This is a helper function for update_revisions.
1105
 
        
 
1105
 
1106
1106
        :raises: DivergedBranches if revision_b has diverged from revision_a.
1107
1107
        :returns: True if revision_b is a descendant of revision_a.
1108
1108
        """
1118
1118
 
1119
1119
    def _revision_relations(self, revision_a, revision_b, graph):
1120
1120
        """Determine the relationship between two revisions.
1121
 
        
 
1121
 
1122
1122
        :returns: One of: 'a_descends_from_b', 'b_descends_from_a', 'diverged'
1123
1123
        """
1124
1124
        heads = graph.heads([revision_a, revision_b])
1141
1141
     * a format string,
1142
1142
     * an open routine.
1143
1143
 
1144
 
    Formats are placed in an dict by their format string for reference 
 
1144
    Formats are placed in an dict by their format string for reference
1145
1145
    during branch opening. Its not required that these be instances, they
1146
 
    can be classes themselves with class methods - it simply depends on 
 
1146
    can be classes themselves with class methods - it simply depends on
1147
1147
    whether state is needed for a given format or not.
1148
1148
 
1149
1149
    Once a format is deprecated, just deprecate the initialize and open
1150
 
    methods on the format class. Do not deprecate the object, as the 
 
1150
    methods on the format class. Do not deprecate the object, as the
1151
1151
    object will be created every time regardless.
1152
1152
    """
1153
1153
 
1255
1255
        """Is this format supported?
1256
1256
 
1257
1257
        Supported formats can be initialized and opened.
1258
 
        Unsupported formats may not support initialization or committing or 
 
1258
        Unsupported formats may not support initialization or committing or
1259
1259
        some other features depending on the reason for not being supported.
1260
1260
        """
1261
1261
        return True
1307
1307
 
1308
1308
class BranchHooks(Hooks):
1309
1309
    """A dictionary mapping hook name to a list of callables for branch hooks.
1310
 
    
 
1310
 
1311
1311
    e.g. ['set_rh'] Is the list of items to be called when the
1312
1312
    set_revision_history function is invoked.
1313
1313
    """
1332
1332
        # (push_result)
1333
1333
        # containing the members
1334
1334
        # (source, local, master, old_revno, old_revid, new_revno, new_revid)
1335
 
        # where local is the local target branch or None, master is the target 
 
1335
        # where local is the local target branch or None, master is the target
1336
1336
        # master branch, and the rest should be self explanatory. The source
1337
1337
        # is read locked and the target branches write locked. Source will
1338
1338
        # be the local low-latency branch.
1342
1342
        # (pull_result)
1343
1343
        # containing the members
1344
1344
        # (source, local, master, old_revno, old_revid, new_revno, new_revid)
1345
 
        # where local is the local branch or None, master is the target 
 
1345
        # where local is the local branch or None, master is the target
1346
1346
        # master branch, and the rest should be self explanatory. The source
1347
1347
        # is read locked and the target branches write locked. The local
1348
1348
        # branch is the low-latency branch.
1358
1358
        # CommitBuilder.revision_tree() and hooks MUST NOT modify this tree
1359
1359
        self['pre_commit'] = []
1360
1360
        # invoked after a commit operation completes.
1361
 
        # the api signature is 
 
1361
        # the api signature is
1362
1362
        # (local, master, old_revno, old_revid, new_revno, new_revid)
1363
1363
        # old_revid is NULL_REVISION for the first commit to a branch.
1364
1364
        self['post_commit'] = []
1425
1425
 
1426
1426
    def __eq__(self, other):
1427
1427
        return self.__dict__ == other.__dict__
1428
 
    
 
1428
 
1429
1429
    def __repr__(self):
1430
1430
        return "<%s of %s from (%s, %s) to (%s, %s)>" % (
1431
 
            self.__class__.__name__, self.branch, 
 
1431
            self.__class__.__name__, self.branch,
1432
1432
            self.old_revno, self.old_revid, self.new_revno, self.new_revid)
1433
1433
 
1434
1434
 
1546
1546
    def get_format_description(self):
1547
1547
        """See BranchFormat.get_format_description()."""
1548
1548
        return "Branch format 5"
1549
 
        
 
1549
 
1550
1550
    def initialize(self, a_bzrdir):
1551
1551
        """Create a branch of this format in a_bzrdir."""
1552
1552
        utf8_files = [('revision-history', ''),
1746
1746
    really matter if it's on an nfs/smb/afs/coda/... share, as long as
1747
1747
    it's writable, and can be accessed via the normal filesystem API.
1748
1748
 
1749
 
    :ivar _transport: Transport for file operations on this branch's 
 
1749
    :ivar _transport: Transport for file operations on this branch's
1750
1750
        control files, typically pointing to the .bzr/branch directory.
1751
1751
    :ivar repository: Repository for this branch.
1752
 
    :ivar base: The url of the base directory for this branch; the one 
 
1752
    :ivar base: The url of the base directory for this branch; the one
1753
1753
        containing the .bzr directory.
1754
1754
    """
1755
 
    
 
1755
 
1756
1756
    def __init__(self, _format=None,
1757
1757
                 _control_files=None, a_bzrdir=None, _repository=None):
1758
1758
        """Create new branch object at a particular location."""
1812
1812
        if not self.control_files.is_locked():
1813
1813
            # we just released the lock
1814
1814
            self._clear_cached_state()
1815
 
        
 
1815
 
1816
1816
    def peek_lock_mode(self):
1817
1817
        if self.control_files._lock_count == 0:
1818
1818
            return None
1898
1898
        for this revision id.
1899
1899
 
1900
1900
        It may be possible to set the branch last revision to an id not
1901
 
        present in the repository.  However, branches can also be 
 
1901
        present in the repository.  However, branches can also be
1902
1902
        configured to check constraints on history, in which case this may not
1903
1903
        be permitted.
1904
1904
        """
1942
1942
             _override_hook_target=None):
1943
1943
        """See Branch.pull.
1944
1944
 
1945
 
        :param _hook_master: Private parameter - set the branch to 
 
1945
        :param _hook_master: Private parameter - set the branch to
1946
1946
            be supplied as the master to pull hooks.
1947
1947
        :param run_hooks: Private parameter - if false, this branch
1948
1948
            is being called because it's the master of the primary branch,
1996
1996
        This is the basic concrete implementation of push()
1997
1997
 
1998
1998
        :param _override_hook_source_branch: If specified, run
1999
 
        the hooks passing this Branch as the source, rather than self.  
 
1999
        the hooks passing this Branch as the source, rather than self.
2000
2000
        This is for use of RemoteBranch, where push is delegated to the
2001
 
        underlying vfs-based Branch. 
 
2001
        underlying vfs-based Branch.
2002
2002
        """
2003
2003
        # TODO: Public option to disable running hooks - should be trivial but
2004
2004
        # needs tests.
2011
2011
            stop_revision,
2012
2012
            _override_hook_source_branch=None):
2013
2013
        """Push from self into target, and into target's master if any.
2014
 
        
2015
 
        This is on the base BzrBranch class even though it doesn't support 
 
2014
 
 
2015
        This is on the base BzrBranch class even though it doesn't support
2016
2016
        bound branches because the *target* might be bound.
2017
2017
        """
2018
2018
        def _run_hooks():
2075
2075
 
2076
2076
    def _push_should_merge_tags(self):
2077
2077
        """Should _basic_push merge this branch's tags into the target?
2078
 
        
 
2078
 
2079
2079
        The default implementation returns False if this branch has no tags,
2080
2080
        and True the rest of the time.  Subclasses may override this.
2081
2081
        """
2144
2144
             run_hooks=True, possible_transports=None,
2145
2145
             _override_hook_target=None):
2146
2146
        """Pull from source into self, updating my master if any.
2147
 
        
 
2147
 
2148
2148
        :param run_hooks: Private parameter - if false, this branch
2149
2149
            is being called because it's the master of the primary branch,
2150
2150
            so it should not run its hooks.
2177
2177
    @needs_read_lock
2178
2178
    def get_master_branch(self, possible_transports=None):
2179
2179
        """Return the branch we are bound to.
2180
 
        
 
2180
 
2181
2181
        :return: Either a Branch, or None
2182
2182
 
2183
2183
        This could memoise the branch, but if thats done
2219
2219
        check for divergence to raise an error when the branches are not
2220
2220
        either the same, or one a prefix of the other. That behaviour may not
2221
2221
        be useful, so that check may be removed in future.
2222
 
        
 
2222
 
2223
2223
        :param other: The branch to bind to
2224
2224
        :type other: Branch
2225
2225
        """
2244
2244
 
2245
2245
    @needs_write_lock
2246
2246
    def update(self, possible_transports=None):
2247
 
        """Synchronise this branch with the master branch if any. 
 
2247
        """Synchronise this branch with the master branch if any.
2248
2248
 
2249
2249
        :return: None or the last_revision that was pivoted out during the
2250
2250
                 update.
2341
2341
 
2342
2342
    def _synchronize_history(self, destination, revision_id):
2343
2343
        """Synchronize last revision and revision history between branches.
2344
 
        
 
2344
 
2345
2345
        :see: Branch._synchronize_history
2346
2346
        """
2347
2347
        # XXX: The base Branch has a fast implementation of this method based
2644
2644
 
2645
2645
    def report_results(self, verbose):
2646
2646
        """Report the check results via trace.note.
2647
 
        
 
2647
 
2648
2648
        :param verbose: Requests more detailed display of what was checked,
2649
2649
            if any.
2650
2650
        """
2710
2710
            return callable(*args, **kwargs)
2711
2711
        finally:
2712
2712
            target.unlock()
2713
 
    
 
2713
 
2714
2714
    """
2715
2715
    # This is very similar to bzrlib.decorators.needs_write_lock.  Perhaps they
2716
2716
    # should share code?