/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 breezy/bzr/remote.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2020-01-19 15:46:24 UTC
  • mfrom: (7449.2.10 branch-reference-remote)
  • Revision ID: breezy.the.bot@gmail.com-20200119154624-anug4aee72039xw3
Support fetching / pushing reference information to remote branches.

Merged from https://code.launchpad.net/~jelmer/brz/branch-reference-remote/+merge/377806

Show diffs side-by-side

added added

removed removed

Lines of Context:
3397
3397
        self._ensure_real()
3398
3398
        return self._custom_format.supports_set_append_revisions_only()
3399
3399
 
 
3400
    @property
 
3401
    def supports_reference_locations(self):
 
3402
        self._ensure_real()
 
3403
        return self._custom_format.supports_reference_locations
 
3404
 
3400
3405
    def stores_revno(self):
3401
3406
        return True
3402
3407
 
3415
3420
                return True
3416
3421
        return False
3417
3422
 
3418
 
    supports_reference_locations = False
3419
 
 
3420
3423
 
3421
3424
class RemoteBranchStore(_mod_config.IniFileStore):
3422
3425
    """Branch store which attempts to use HPSS calls to retrieve branch store.
4179
4182
            reconciler = BranchReconciler(self, thorough=thorough)
4180
4183
            return reconciler.reconcile()
4181
4184
 
4182
 
    def set_reference_info(self, tree_path, branch_location, file_id=None):
4183
 
        raise errors.UnsupportedOperation(self.set_reference_info, self)
4184
 
 
4185
 
    def get_reference_info(self, tree_path):
4186
 
        raise errors.UnsupportedOperation(self.get_reference_info, self)
 
4185
    def get_reference_info(self, file_id):
 
4186
        """Get the tree_path and branch_location for a tree reference."""
 
4187
        if not self._format.supports_reference_locations:
 
4188
            raise errors.UnsupportedOperation(self.get_reference_info, self)
 
4189
        return self._get_all_reference_info().get(file_id, (None, None))
 
4190
 
 
4191
    def set_reference_info(self, file_id, branch_location, tree_path=None):
 
4192
        """Set the branch location to use for a tree reference."""
 
4193
        if not self._format.supports_reference_locations:
 
4194
            raise errors.UnsupportedOperation(self.set_reference_info, self)
 
4195
        self._ensure_real()
 
4196
        self._real_branch.set_reference_info(
 
4197
            file_id, branch_location, tree_path)
 
4198
 
 
4199
    def _set_all_reference_info(self, reference_info):
 
4200
        if not self._format.supports_reference_locations:
 
4201
            raise errors.UnsupportedOperation(self.set_reference_info, self)
 
4202
        self._ensure_real()
 
4203
        self._real_branch._set_all_reference_info(reference_info)
4187
4204
 
4188
4205
    def _get_all_reference_info(self):
4189
 
        self._ensure_real()
4190
 
        return self._real_branch._get_all_reference_info()
 
4206
        if not self._format.supports_reference_locations:
 
4207
            return {}
 
4208
        try:
 
4209
            response, handler = self._call_expecting_body(
 
4210
                b'Branch.get_all_reference_info', self._remote_path())
 
4211
        except errors.UnknownSmartMethod:
 
4212
            self._ensure_real()
 
4213
            return self._real_branch._get_all_reference_info()
 
4214
        if len(response) and response[0] != b'ok':
 
4215
            raise errors.UnexpectedSmartServerResponse(response)
 
4216
        ret = {}
 
4217
        for (f, u, p) in bencode.bdecode(handler.read_body_bytes()):
 
4218
            ret[f] = (u.decode('utf-8'), p.decode('utf-8') if p else None)
 
4219
        return ret
4191
4220
 
4192
 
    def reference_parent(self, path, possible_transports=None):
 
4221
    def reference_parent(self, file_id, path, possible_transports=None):
4193
4222
        """Return the parent branch for a tree-reference.
4194
4223
 
4195
4224
        :param path: The path of the nested tree in the tree
4196
4225
        :return: A branch associated with the nested tree
4197
4226
        """
4198
 
        branch_location = self.get_reference_info(path)[0]
 
4227
        branch_location = self.get_reference_info(file_id)[0]
4199
4228
        if branch_location is None:
4200
 
            return BzrBranch.reference_parent(self, path, possible_transports)
4201
 
        branch_location = urlutils.join(self.user_url, branch_location)
4202
 
        return Branch.open(branch_location,
4203
 
                           possible_transports=possible_transports)
 
4229
            try:
 
4230
                return branch.Branch.open_from_transport(
 
4231
                    self.controldir.root_transport.clone(path),
 
4232
                    possible_transports=possible_transports)
 
4233
            except errors.NotBranchError:
 
4234
                return None
 
4235
        return branch.Branch.open(
 
4236
            urlutils.join(
 
4237
                urlutils.strip_segment_parameters(self.user_url), branch_location),
 
4238
            possible_transports=possible_transports)
4204
4239
 
4205
4240
 
4206
4241
class RemoteConfig(object):