~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-05-06 17:31:37 UTC
  • mfrom: (4000.5.23 interbranch-pull)
  • Revision ID: pqm@pqm.ubuntu.com-20090506173137-di6mfn1f3od2khp3
(Jelmer) Add InterBranch.pull.

Show diffs side-by-side

added added

removed removed

Lines of Context:
845
845
            raise errors.NoSuchRevision(self, revno)
846
846
        return history[revno - 1]
847
847
 
 
848
    @needs_write_lock
848
849
    def pull(self, source, overwrite=False, stop_revision=None,
849
 
             possible_transports=None, _override_hook_target=None,
850
 
             local=False):
 
850
             possible_transports=None, *args, **kwargs):
851
851
        """Mirror source into this branch.
852
852
 
853
853
        This branch is considered to be 'local', having low latency.
854
854
 
855
855
        :returns: PullResult instance
856
856
        """
857
 
        raise NotImplementedError(self.pull)
 
857
        return InterBranch.get(source, self).pull(overwrite=overwrite,
 
858
            stop_revision=stop_revision,
 
859
            possible_transports=possible_transports, *args, **kwargs)
858
860
 
859
861
    def push(self, target, overwrite=False, stop_revision=None, *args,
860
862
        **kwargs):
2178
2180
        """See Branch.basis_tree."""
2179
2181
        return self.repository.revision_tree(self.last_revision())
2180
2182
 
2181
 
    @needs_write_lock
2182
 
    def pull(self, source, overwrite=False, stop_revision=None,
2183
 
             _hook_master=None, run_hooks=True, possible_transports=None,
2184
 
             _override_hook_target=None, local=False):
2185
 
        """See Branch.pull.
2186
 
 
2187
 
        :param _hook_master: Private parameter - set the branch to
2188
 
            be supplied as the master to pull hooks.
2189
 
        :param run_hooks: Private parameter - if false, this branch
2190
 
            is being called because it's the master of the primary branch,
2191
 
            so it should not run its hooks.
2192
 
        :param _override_hook_target: Private parameter - set the branch to be
2193
 
            supplied as the target_branch to pull hooks.
2194
 
        :param local: Only update the local branch, and not the bound branch.
2195
 
        """
2196
 
        # This type of branch can't be bound.
2197
 
        if local:
2198
 
            raise errors.LocalRequiresBoundBranch()
2199
 
        
2200
 
        result = PullResult()
2201
 
        result.source_branch = source
2202
 
        if _override_hook_target is None:
2203
 
            result.target_branch = self
2204
 
        else:
2205
 
            result.target_branch = _override_hook_target
2206
 
        source.lock_read()
2207
 
        try:
2208
 
            # We assume that during 'pull' the local repository is closer than
2209
 
            # the remote one.
2210
 
            source.update_references(self)
2211
 
            graph = self.repository.get_graph(source.repository)
2212
 
            result.old_revno, result.old_revid = self.last_revision_info()
2213
 
            self.update_revisions(source, stop_revision, overwrite=overwrite,
2214
 
                                  graph=graph)
2215
 
            result.tag_conflicts = source.tags.merge_to(self.tags, overwrite)
2216
 
            result.new_revno, result.new_revid = self.last_revision_info()
2217
 
            if _hook_master:
2218
 
                result.master_branch = _hook_master
2219
 
                result.local_branch = result.target_branch
2220
 
            else:
2221
 
                result.master_branch = result.target_branch
2222
 
                result.local_branch = None
2223
 
            if run_hooks:
2224
 
                for hook in Branch.hooks['post_pull']:
2225
 
                    hook(result)
2226
 
        finally:
2227
 
            source.unlock()
2228
 
        return result
2229
 
 
2230
2183
    def _get_parent_location(self):
2231
2184
        _locs = ['parent', 'pull', 'x-pull']
2232
2185
        for l in _locs:
2281
2234
    It has support for a master_branch which is the data for bound branches.
2282
2235
    """
2283
2236
 
2284
 
    @needs_write_lock
2285
 
    def pull(self, source, overwrite=False, stop_revision=None,
2286
 
             run_hooks=True, possible_transports=None,
2287
 
             _override_hook_target=None, local=False):
2288
 
        """Pull from source into self, updating my master if any.
2289
 
 
2290
 
        :param run_hooks: Private parameter - if false, this branch
2291
 
            is being called because it's the master of the primary branch,
2292
 
            so it should not run its hooks.
2293
 
        """
2294
 
        bound_location = self.get_bound_location()
2295
 
        if local and not bound_location:
2296
 
            raise errors.LocalRequiresBoundBranch()
2297
 
        master_branch = None
2298
 
        if not local and bound_location and source.base != bound_location:
2299
 
            # not pulling from master, so we need to update master.
2300
 
            master_branch = self.get_master_branch(possible_transports)
2301
 
            master_branch.lock_write()
2302
 
        try:
2303
 
            if master_branch:
2304
 
                # pull from source into master.
2305
 
                master_branch.pull(source, overwrite, stop_revision,
2306
 
                    run_hooks=False)
2307
 
            return super(BzrBranch5, self).pull(source, overwrite,
2308
 
                stop_revision, _hook_master=master_branch,
2309
 
                run_hooks=run_hooks,
2310
 
                _override_hook_target=_override_hook_target)
2311
 
        finally:
2312
 
            if master_branch:
2313
 
                master_branch.unlock()
2314
 
 
2315
2237
    def get_bound_location(self):
2316
2238
        try:
2317
2239
            return self._transport.get_bytes('bound')[:-1]
2949
2871
        """Return a tuple with the Branch formats to use when testing."""
2950
2872
        raise NotImplementedError(self._get_branch_formats_to_test)
2951
2873
 
 
2874
    def pull(self, overwrite=False, stop_revision=None,
 
2875
             possible_transports=None, local=False):
 
2876
        """Mirror source into target branch.
 
2877
 
 
2878
        The target branch is considered to be 'local', having low latency.
 
2879
 
 
2880
        :returns: PullResult instance
 
2881
        """
 
2882
        raise NotImplementedError(self.pull)
 
2883
 
2952
2884
    def update_revisions(self, stop_revision=None, overwrite=False,
2953
2885
                         graph=None):
2954
2886
        """Pull in new perfect-fit revisions.
3022
2954
        finally:
3023
2955
            self.source.unlock()
3024
2956
 
 
2957
    def pull(self, overwrite=False, stop_revision=None,
 
2958
             possible_transports=None, _hook_master=None, run_hooks=True,
 
2959
             _override_hook_target=None, local=False):
 
2960
        """See Branch.pull.
 
2961
 
 
2962
        :param _hook_master: Private parameter - set the branch to
 
2963
            be supplied as the master to pull hooks.
 
2964
        :param run_hooks: Private parameter - if false, this branch
 
2965
            is being called because it's the master of the primary branch,
 
2966
            so it should not run its hooks.
 
2967
        :param _override_hook_target: Private parameter - set the branch to be
 
2968
            supplied as the target_branch to pull hooks.
 
2969
        :param local: Only update the local branch, and not the bound branch.
 
2970
        """
 
2971
        # This type of branch can't be bound.
 
2972
        if local:
 
2973
            raise errors.LocalRequiresBoundBranch()
 
2974
        result = PullResult()
 
2975
        result.source_branch = self.source
 
2976
        if _override_hook_target is None:
 
2977
            result.target_branch = self.target
 
2978
        else:
 
2979
            result.target_branch = _override_hook_target
 
2980
        self.source.lock_read()
 
2981
        try:
 
2982
            # We assume that during 'pull' the target repository is closer than
 
2983
            # the source one.
 
2984
            self.source.update_references(self.target)
 
2985
            graph = self.target.repository.get_graph(self.source.repository)
 
2986
            # TODO: Branch formats should have a flag that indicates 
 
2987
            # that revno's are expensive, and pull() should honor that flag.
 
2988
            # -- JRV20090506
 
2989
            result.old_revno, result.old_revid = \
 
2990
                self.target.last_revision_info()
 
2991
            self.target.update_revisions(self.source, stop_revision,
 
2992
                overwrite=overwrite, graph=graph)
 
2993
            # TODO: The old revid should be specified when merging tags, 
 
2994
            # so a tags implementation that versions tags can only 
 
2995
            # pull in the most recent changes. -- JRV20090506
 
2996
            result.tag_conflicts = self.source.tags.merge_to(self.target.tags,
 
2997
                overwrite)
 
2998
            result.new_revno, result.new_revid = self.target.last_revision_info()
 
2999
            if _hook_master:
 
3000
                result.master_branch = _hook_master
 
3001
                result.local_branch = result.target_branch
 
3002
            else:
 
3003
                result.master_branch = result.target_branch
 
3004
                result.local_branch = None
 
3005
            if run_hooks:
 
3006
                for hook in Branch.hooks['post_pull']:
 
3007
                    hook(result)
 
3008
        finally:
 
3009
            self.source.unlock()
 
3010
        return result
 
3011
 
3025
3012
    def push(self, overwrite=False, stop_revision=None,
3026
3013
             _override_hook_source_branch=None):
3027
3014
        """See InterBranch.push.
3043
3030
                _override_hook_source_branch=_override_hook_source_branch)
3044
3031
        finally:
3045
3032
            self.source.unlock()
 
3033
        return result
3046
3034
 
3047
3035
    def _push_with_bound_branches(self, overwrite, stop_revision,
3048
3036
            _override_hook_source_branch=None):
3094
3082
        return True
3095
3083
 
3096
3084
 
 
3085
class InterToBranch5(GenericInterBranch):
 
3086
 
 
3087
    @staticmethod
 
3088
    def _get_branch_formats_to_test():
 
3089
        return BranchFormat._default_format, BzrBranchFormat5()
 
3090
 
 
3091
    def pull(self, overwrite=False, stop_revision=None,
 
3092
             possible_transports=None, run_hooks=True,
 
3093
             _override_hook_target=None, local=False):
 
3094
        """Pull from source into self, updating my master if any.
 
3095
 
 
3096
        :param run_hooks: Private parameter - if false, this branch
 
3097
            is being called because it's the master of the primary branch,
 
3098
            so it should not run its hooks.
 
3099
        """
 
3100
        bound_location = self.target.get_bound_location()
 
3101
        if local and not bound_location:
 
3102
            raise errors.LocalRequiresBoundBranch()
 
3103
        master_branch = None
 
3104
        if not local and bound_location and self.source.base != bound_location:
 
3105
            # not pulling from master, so we need to update master.
 
3106
            master_branch = self.target.get_master_branch(possible_transports)
 
3107
            master_branch.lock_write()
 
3108
        try:
 
3109
            if master_branch:
 
3110
                # pull from source into master.
 
3111
                master_branch.pull(self.source, overwrite, stop_revision,
 
3112
                    run_hooks=False)
 
3113
            return super(InterToBranch5, self).pull(overwrite,
 
3114
                stop_revision, _hook_master=master_branch,
 
3115
                run_hooks=run_hooks,
 
3116
                _override_hook_target=_override_hook_target)
 
3117
        finally:
 
3118
            if master_branch:
 
3119
                master_branch.unlock()
 
3120
 
 
3121
 
3097
3122
InterBranch.register_optimiser(GenericInterBranch)
 
3123
InterBranch.register_optimiser(InterToBranch5)