~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

remove all trailing whitespace from bzr source

Show diffs side-by-side

added added

removed removed

Lines of Context:
132
132
    @staticmethod
133
133
    def open_containing(url, possible_transports=None):
134
134
        """Open an existing branch which contains url.
135
 
        
 
135
 
136
136
        This probes for a branch at url, and searches upwards from there.
137
137
 
138
138
        Basically we keep looking up until we find the control directory or
139
139
        run into the root.  If there isn't one, raises NotBranchError.
140
 
        If there is one and it is either an unrecognised format or an unsupported 
 
140
        If there is one and it is either an unrecognised format or an unsupported
141
141
        format, UnknownFormatError or UnsupportedFormatError are raised.
142
142
        If there is one, it is returned, along with the unused portion of url.
143
143
        """
234
234
    def leave_lock_in_place(self):
235
235
        """Tell this branch object not to release the physical lock when this
236
236
        object is unlocked.
237
 
        
 
237
 
238
238
        If lock_write doesn't return a token, then this method is not supported.
239
239
        """
240
240
        self.control_files.leave_in_place()
296
296
        branch.
297
297
        """
298
298
        return None
299
 
    
 
299
 
300
300
    def get_old_bound_location(self):
301
301
        """Return the URL of the branch we used to be bound to
302
302
        """
303
303
        raise errors.UpgradeRequired(self.base)
304
304
 
305
 
    def get_commit_builder(self, parents, config=None, timestamp=None, 
306
 
                           timezone=None, committer=None, revprops=None, 
 
305
    def get_commit_builder(self, parents, config=None, timestamp=None,
 
306
                           timezone=None, committer=None, revprops=None,
307
307
                           revision_id=None):
308
308
        """Obtain a CommitBuilder for this branch.
309
 
        
 
309
 
310
310
        :param parents: Revision ids of the parents of the new revision.
311
311
        :param config: Optional configuration to use.
312
312
        :param timestamp: Optional timestamp recorded for commit.
318
318
 
319
319
        if config is None:
320
320
            config = self.get_config()
321
 
        
 
321
 
322
322
        return self.repository.get_commit_builder(self, parents, config,
323
323
            timestamp, timezone, committer, revprops, revision_id)
324
324
 
325
325
    def get_master_branch(self, possible_transports=None):
326
326
        """Return the branch we are bound to.
327
 
        
 
327
 
328
328
        :return: Either a Branch, or None
329
329
        """
330
330
        return None
400
400
 
401
401
    def _gen_revision_history(self):
402
402
        """Return sequence of revision hashes on to this branch.
403
 
        
 
403
 
404
404
        Unlike revision_history, this method always regenerates or rereads the
405
405
        revision history, i.e. it does not cache the result, so repeated calls
406
406
        may be expensive.
407
407
 
408
408
        Concrete subclasses should override this instead of revision_history so
409
409
        that subclasses do not need to deal with caching logic.
410
 
        
 
410
 
411
411
        This API is semi-public; it only for use by subclasses, all other code
412
412
        should consider it to be private.
413
413
        """
416
416
    @needs_read_lock
417
417
    def revision_history(self):
418
418
        """Return sequence of revision ids on this branch.
419
 
        
 
419
 
420
420
        This method will cache the revision history for as long as it is safe to
421
421
        do so.
422
422
        """
470
470
    @deprecated_method(deprecated_in((1, 6, 0)))
471
471
    def missing_revisions(self, other, stop_revision=None):
472
472
        """Return a list of new revisions that would perfectly fit.
473
 
        
 
473
 
474
474
        If self and other have not diverged, return a list of the revisions
475
475
        present in other, but missing from self.
476
476
        """
518
518
            # possibly]
519
519
            last_rev = _mod_revision.ensure_null(self.last_revision())
520
520
            # we fetch here so that we don't process data twice in the common
521
 
            # case of having something to pull, and so that the check for 
 
521
            # case of having something to pull, and so that the check for
522
522
            # already merged can operate on the just fetched graph, which will
523
523
            # be cached in memory.
524
524
            self.fetch(other, stop_revision)
659
659
 
660
660
    @needs_write_lock
661
661
    def update(self):
662
 
        """Synchronise this branch with the master branch if any. 
 
662
        """Synchronise this branch with the master branch if any.
663
663
 
664
664
        :return: None or the last_revision pivoted out during the update.
665
665
        """
672
672
        """
673
673
        if revno != 0:
674
674
            self.check_real_revno(revno)
675
 
            
 
675
 
676
676
    def check_real_revno(self, revno):
677
677
        """\
678
678
        Check whether a revno corresponds to a real revision.
684
684
    @needs_read_lock
685
685
    def clone(self, to_bzrdir, revision_id=None):
686
686
        """Clone this branch into to_bzrdir preserving all semantic values.
687
 
        
 
687
 
688
688
        revision_id: if not None, the revision history in the new branch will
689
689
                     be truncated to end with revision_id.
690
690
        """
734
734
            revno = len(list(self.repository.iter_reverse_revision_history(
735
735
                                                                revision_id)))
736
736
        destination.set_last_revision_info(revno, revision_id)
737
 
    
 
737
 
738
738
    @needs_read_lock
739
739
    def copy_content_into(self, destination, revision_id=None):
740
740
        """Copy the content of self into destination.
757
757
        """Check consistency of the branch.
758
758
 
759
759
        In particular this checks that revisions given in the revision-history
760
 
        do actually match up in the revision graph, and that they're all 
 
760
        do actually match up in the revision graph, and that they're all
761
761
        present in the repository.
762
 
        
 
762
 
763
763
        Callers will typically also want to check the repository.
764
764
 
765
765
        :return: A BranchCheckResult.
808
808
                        lightweight=False, accelerator_tree=None,
809
809
                        hardlink=False):
810
810
        """Create a checkout of a branch.
811
 
        
 
811
 
812
812
        :param to_location: The url to produce the checkout at
813
813
        :param revision_id: The revision to check out
814
814
        :param lightweight: If True, produce a lightweight checkout, otherwise,
833
833
                to_location, force_new_tree=False, format=format)
834
834
            checkout = checkout_branch.bzrdir
835
835
            checkout_branch.bind(self)
836
 
            # pull up to the specified revision_id to set the initial 
 
836
            # pull up to the specified revision_id to set the initial
837
837
            # branch tip correctly, and seed it with history.
838
838
            checkout_branch.pull(self, stop_revision=revision_id)
839
839
            from_branch=None
878
878
        """Ensure that revision_b is a descendant of revision_a.
879
879
 
880
880
        This is a helper function for update_revisions.
881
 
        
 
881
 
882
882
        :raises: DivergedBranches if revision_b has diverged from revision_a.
883
883
        :returns: True if revision_b is a descendant of revision_a.
884
884
        """
894
894
 
895
895
    def _revision_relations(self, revision_a, revision_b, graph):
896
896
        """Determine the relationship between two revisions.
897
 
        
 
897
 
898
898
        :returns: One of: 'a_descends_from_b', 'b_descends_from_a', 'diverged'
899
899
        """
900
900
        heads = graph.heads([revision_a, revision_b])
917
917
     * a format string,
918
918
     * an open routine.
919
919
 
920
 
    Formats are placed in an dict by their format string for reference 
 
920
    Formats are placed in an dict by their format string for reference
921
921
    during branch opening. Its not required that these be instances, they
922
 
    can be classes themselves with class methods - it simply depends on 
 
922
    can be classes themselves with class methods - it simply depends on
923
923
    whether state is needed for a given format or not.
924
924
 
925
925
    Once a format is deprecated, just deprecate the initialize and open
926
 
    methods on the format class. Do not deprecate the object, as the 
 
926
    methods on the format class. Do not deprecate the object, as the
927
927
    object will be created every time regardless.
928
928
    """
929
929
 
1031
1031
        """Is this format supported?
1032
1032
 
1033
1033
        Supported formats can be initialized and opened.
1034
 
        Unsupported formats may not support initialization or committing or 
 
1034
        Unsupported formats may not support initialization or committing or
1035
1035
        some other features depending on the reason for not being supported.
1036
1036
        """
1037
1037
        return True
1070
1070
 
1071
1071
class BranchHooks(Hooks):
1072
1072
    """A dictionary mapping hook name to a list of callables for branch hooks.
1073
 
    
 
1073
 
1074
1074
    e.g. ['set_rh'] Is the list of items to be called when the
1075
1075
    set_revision_history function is invoked.
1076
1076
    """
1095
1095
        # (push_result)
1096
1096
        # containing the members
1097
1097
        # (source, local, master, old_revno, old_revid, new_revno, new_revid)
1098
 
        # where local is the local target branch or None, master is the target 
 
1098
        # where local is the local target branch or None, master is the target
1099
1099
        # master branch, and the rest should be self explanatory. The source
1100
1100
        # is read locked and the target branches write locked. Source will
1101
1101
        # be the local low-latency branch.
1105
1105
        # (pull_result)
1106
1106
        # containing the members
1107
1107
        # (source, local, master, old_revno, old_revid, new_revno, new_revid)
1108
 
        # where local is the local branch or None, master is the target 
 
1108
        # where local is the local branch or None, master is the target
1109
1109
        # master branch, and the rest should be self explanatory. The source
1110
1110
        # is read locked and the target branches write locked. The local
1111
1111
        # branch is the low-latency branch.
1121
1121
        # CommitBuilder.revision_tree() and hooks MUST NOT modify this tree
1122
1122
        self['pre_commit'] = []
1123
1123
        # invoked after a commit operation completes.
1124
 
        # the api signature is 
 
1124
        # the api signature is
1125
1125
        # (local, master, old_revno, old_revid, new_revno, new_revid)
1126
1126
        # old_revid is NULL_REVISION for the first commit to a branch.
1127
1127
        self['post_commit'] = []
1188
1188
 
1189
1189
    def __eq__(self, other):
1190
1190
        return self.__dict__ == other.__dict__
1191
 
    
 
1191
 
1192
1192
    def __repr__(self):
1193
1193
        return "<%s of %s from (%s, %s) to (%s, %s)>" % (
1194
 
            self.__class__.__name__, self.branch, 
 
1194
            self.__class__.__name__, self.branch,
1195
1195
            self.old_revno, self.old_revid, self.new_revno, self.new_revid)
1196
1196
 
1197
1197
 
1298
1298
    def get_format_description(self):
1299
1299
        """See BranchFormat.get_format_description()."""
1300
1300
        return "Branch format 5"
1301
 
        
 
1301
 
1302
1302
    def initialize(self, a_bzrdir):
1303
1303
        """Create a branch of this format in a_bzrdir."""
1304
1304
        utf8_files = [('revision-history', ''),
1486
1486
    really matter if it's on an nfs/smb/afs/coda/... share, as long as
1487
1487
    it's writable, and can be accessed via the normal filesystem API.
1488
1488
 
1489
 
    :ivar _transport: Transport for file operations on this branch's 
 
1489
    :ivar _transport: Transport for file operations on this branch's
1490
1490
        control files, typically pointing to the .bzr/branch directory.
1491
1491
    :ivar repository: Repository for this branch.
1492
 
    :ivar base: The url of the base directory for this branch; the one 
 
1492
    :ivar base: The url of the base directory for this branch; the one
1493
1493
        containing the .bzr directory.
1494
1494
    """
1495
 
    
 
1495
 
1496
1496
    def __init__(self, _format=None,
1497
1497
                 _control_files=None, a_bzrdir=None, _repository=None):
1498
1498
        """Create new branch object at a particular location."""
1552
1552
        if not self.control_files.is_locked():
1553
1553
            # we just released the lock
1554
1554
            self._clear_cached_state()
1555
 
        
 
1555
 
1556
1556
    def peek_lock_mode(self):
1557
1557
        if self.control_files._lock_count == 0:
1558
1558
            return None
1648
1648
                hook_name = Branch.hooks.get_hook_name(hook)
1649
1649
                raise errors.HookFailed(
1650
1650
                    'pre_change_branch_tip', hook_name, exc_info)
1651
 
 
 
1651
 
1652
1652
    def _run_post_change_branch_tip_hooks(self, old_revno, old_revid):
1653
1653
        """Run the post_change_branch_tip hooks."""
1654
1654
        hooks = Branch.hooks['post_change_branch_tip']
1659
1659
            self, old_revno, new_revno, old_revid, new_revid)
1660
1660
        for hook in hooks:
1661
1661
            hook(params)
1662
 
 
 
1662
 
1663
1663
    @needs_write_lock
1664
1664
    def set_last_revision_info(self, revno, revision_id):
1665
1665
        """Set the last revision of this branch.
1668
1668
        for this revision id.
1669
1669
 
1670
1670
        It may be possible to set the branch last revision to an id not
1671
 
        present in the repository.  However, branches can also be 
 
1671
        present in the repository.  However, branches can also be
1672
1672
        configured to check constraints on history, in which case this may not
1673
1673
        be permitted.
1674
1674
        """
1739
1739
             _override_hook_target=None):
1740
1740
        """See Branch.pull.
1741
1741
 
1742
 
        :param _hook_master: Private parameter - set the branch to 
 
1742
        :param _hook_master: Private parameter - set the branch to
1743
1743
            be supplied as the master to pull hooks.
1744
1744
        :param run_hooks: Private parameter - if false, this branch
1745
1745
            is being called because it's the master of the primary branch,
1793
1793
        This is the basic concrete implementation of push()
1794
1794
 
1795
1795
        :param _override_hook_source_branch: If specified, run
1796
 
        the hooks passing this Branch as the source, rather than self.  
 
1796
        the hooks passing this Branch as the source, rather than self.
1797
1797
        This is for use of RemoteBranch, where push is delegated to the
1798
 
        underlying vfs-based Branch. 
 
1798
        underlying vfs-based Branch.
1799
1799
        """
1800
1800
        # TODO: Public option to disable running hooks - should be trivial but
1801
1801
        # needs tests.
1808
1808
            stop_revision,
1809
1809
            _override_hook_source_branch=None):
1810
1810
        """Push from self into target, and into target's master if any.
1811
 
        
1812
 
        This is on the base BzrBranch class even though it doesn't support 
 
1811
 
 
1812
        This is on the base BzrBranch class even though it doesn't support
1813
1813
        bound branches because the *target* might be bound.
1814
1814
        """
1815
1815
        def _run_hooks():
1872
1872
 
1873
1873
    def _push_should_merge_tags(self):
1874
1874
        """Should _basic_push merge this branch's tags into the target?
1875
 
        
 
1875
 
1876
1876
        The default implementation returns False if this branch has no tags,
1877
1877
        and True the rest of the time.  Subclasses may override this.
1878
1878
        """
1941
1941
             run_hooks=True, possible_transports=None,
1942
1942
             _override_hook_target=None):
1943
1943
        """Pull from source into self, updating my master if any.
1944
 
        
 
1944
 
1945
1945
        :param run_hooks: Private parameter - if false, this branch
1946
1946
            is being called because it's the master of the primary branch,
1947
1947
            so it should not run its hooks.
1974
1974
    @needs_read_lock
1975
1975
    def get_master_branch(self, possible_transports=None):
1976
1976
        """Return the branch we are bound to.
1977
 
        
 
1977
 
1978
1978
        :return: Either a Branch, or None
1979
1979
 
1980
1980
        This could memoise the branch, but if thats done
2016
2016
        check for divergence to raise an error when the branches are not
2017
2017
        either the same, or one a prefix of the other. That behaviour may not
2018
2018
        be useful, so that check may be removed in future.
2019
 
        
 
2019
 
2020
2020
        :param other: The branch to bind to
2021
2021
        :type other: Branch
2022
2022
        """
2041
2041
 
2042
2042
    @needs_write_lock
2043
2043
    def update(self, possible_transports=None):
2044
 
        """Synchronise this branch with the master branch if any. 
 
2044
        """Synchronise this branch with the master branch if any.
2045
2045
 
2046
2046
        :return: None or the last_revision that was pivoted out during the
2047
2047
                 update.
2138
2138
 
2139
2139
    def _synchronize_history(self, destination, revision_id):
2140
2140
        """Synchronize last revision and revision history between branches.
2141
 
        
 
2141
 
2142
2142
        :see: Branch._synchronize_history
2143
2143
        """
2144
2144
        # XXX: The base Branch has a fast implementation of this method based
2441
2441
 
2442
2442
    def report_results(self, verbose):
2443
2443
        """Report the check results via trace.note.
2444
 
        
 
2444
 
2445
2445
        :param verbose: Requests more detailed display of what was checked,
2446
2446
            if any.
2447
2447
        """
2507
2507
            return callable(*args, **kwargs)
2508
2508
        finally:
2509
2509
            target.unlock()
2510
 
    
 
2510
 
2511
2511
    """
2512
2512
    # This is very similar to bzrlib.decorators.needs_write_lock.  Perhaps they
2513
2513
    # should share code?