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

  • Committer: John Arbash Meinel
  • Date: 2009-08-04 14:10:09 UTC
  • mfrom: (4585 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4588.
  • Revision ID: john@arbash-meinel.com-20090804141009-uety2n17v1atk5ok
Merge bzr.dev 4585, resolve NEWS

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007, 2008 Canonical Ltd
 
1
# Copyright (C) 2006, 2007, 2008, 2009 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
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
# TODO: At some point, handle upgrades by just passing the whole request
18
 
# across to run on the server.
19
 
 
20
17
import bz2
21
18
 
22
19
from bzrlib import (
27
24
    debug,
28
25
    errors,
29
26
    graph,
 
27
    lock,
30
28
    lockdir,
31
29
    repository,
32
30
    revision,
61
59
        except errors.ErrorFromSmartServer, err:
62
60
            self._translate_error(err, **err_context)
63
61
 
 
62
    def _call_with_body_bytes(self, method, args, body_bytes, **err_context):
 
63
        try:
 
64
            return self._client.call_with_body_bytes(method, args, body_bytes)
 
65
        except errors.ErrorFromSmartServer, err:
 
66
            self._translate_error(err, **err_context)
 
67
 
64
68
    def _call_with_body_bytes_expecting_body(self, method, args, body_bytes,
65
69
                                             **err_context):
66
70
        try:
813
817
            result.add(_mod_revision.NULL_REVISION)
814
818
        return result
815
819
 
 
820
    def _has_same_fallbacks(self, other_repo):
 
821
        """Returns true if the repositories have the same fallbacks."""
 
822
        # XXX: copied from Repository; it should be unified into a base class
 
823
        # <https://bugs.edge.launchpad.net/bzr/+bug/401622>
 
824
        my_fb = self._fallback_repositories
 
825
        other_fb = other_repo._fallback_repositories
 
826
        if len(my_fb) != len(other_fb):
 
827
            return False
 
828
        for f, g in zip(my_fb, other_fb):
 
829
            if not f.has_same_location(g):
 
830
                return False
 
831
        return True
 
832
 
816
833
    def has_same_location(self, other):
 
834
        # TODO: Move to RepositoryBase and unify with the regular Repository
 
835
        # one; unfortunately the tests rely on slightly different behaviour at
 
836
        # present -- mbp 20090710
817
837
        return (self.__class__ is other.__class__ and
818
838
                self.bzrdir.transport.base == other.bzrdir.transport.base)
819
839
 
1025
1045
 
1026
1046
    def unlock(self):
1027
1047
        if not self._lock_count:
1028
 
            raise errors.LockNotHeld(self)
 
1048
            return lock.cant_unlock_not_held(self)
1029
1049
        self._lock_count -= 1
1030
1050
        if self._lock_count > 0:
1031
1051
            return
1230
1250
            raise errors.InternalBzrError(
1231
1251
                "May not fetch while in a write group.")
1232
1252
        # fast path same-url fetch operations
1233
 
        if self.has_same_location(source) and fetch_spec is None:
 
1253
        if (self.has_same_location(source)
 
1254
            and fetch_spec is None
 
1255
            and self._has_same_fallbacks(source)):
1234
1256
            # check that last_revision is in 'from' and then return a
1235
1257
            # no-operation.
1236
1258
            if (revision_id is not None and
1711
1733
        if (self.from_repository._fallback_repositories and
1712
1734
            self.to_format._fetch_order == 'topological'):
1713
1735
            return self._real_stream(self.from_repository, search)
1714
 
        return self.missing_parents_chain(search, [self.from_repository] +
1715
 
            self.from_repository._fallback_repositories)
 
1736
        sources = []
 
1737
        seen = set()
 
1738
        repos = [self.from_repository]
 
1739
        while repos:
 
1740
            repo = repos.pop(0)
 
1741
            if repo in seen:
 
1742
                continue
 
1743
            seen.add(repo)
 
1744
            repos.extend(repo._fallback_repositories)
 
1745
            sources.append(repo)
 
1746
        return self.missing_parents_chain(search, sources)
1716
1747
 
1717
1748
    def _real_stream(self, repo, search):
1718
1749
        """Get a stream for search from repo.
2146
2177
            return self._vfs_get_tags_bytes()
2147
2178
        return response[0]
2148
2179
 
 
2180
    def _vfs_set_tags_bytes(self, bytes):
 
2181
        self._ensure_real()
 
2182
        return self._real_branch._set_tags_bytes(bytes)
 
2183
 
 
2184
    def _set_tags_bytes(self, bytes):
 
2185
        medium = self._client._medium
 
2186
        if medium._is_remote_before((1, 18)):
 
2187
            self._vfs_set_tags_bytes(bytes)
 
2188
        try:
 
2189
            args = (
 
2190
                self._remote_path(), self._lock_token, self._repo_lock_token)
 
2191
            response = self._call_with_body_bytes(
 
2192
                'Branch.set_tags_bytes', args, bytes)
 
2193
        except errors.UnknownSmartMethod:
 
2194
            medium._remember_remote_is_before((1, 18))
 
2195
            self._vfs_set_tags_bytes(bytes)
 
2196
 
2149
2197
    def lock_read(self):
2150
2198
        self.repository.lock_read()
2151
2199
        if not self._lock_mode:
2205
2253
            self.repository.lock_write(self._repo_lock_token)
2206
2254
        return self._lock_token or None
2207
2255
 
2208
 
    def _set_tags_bytes(self, bytes):
2209
 
        self._ensure_real()
2210
 
        return self._real_branch._set_tags_bytes(bytes)
2211
 
 
2212
2256
    def _unlock(self, branch_token, repo_token):
2213
2257
        err_context = {'token': str((branch_token, repo_token))}
2214
2258
        response = self._call(