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

Fix tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
import bzrlib
18
 
from bzrlib import (
19
 
    branch,
20
 
    tag,
21
 
    ui,
22
 
    urlutils,
23
 
    )
24
 
from bzrlib.errors import (
25
 
    BzrError,
26
 
    InvalidRevisionId,
27
 
    NoSuchFile,
28
 
    NoSuchRevision,
29
 
    NotLocalUrl,
30
 
    )
31
 
from bzrlib.trace import (
32
 
    info,
33
 
    )
34
 
from bzrlib.transport import (
35
 
    Transport,
36
 
    )
 
18
from bzrlib import urlutils
 
19
from bzrlib.bzrdir import BzrDir, BzrDirFormat
 
20
from bzrlib.errors import BzrError, NoSuchFile, NotLocalUrl
 
21
from bzrlib.lockable_files import TransportLock
 
22
from bzrlib.repository import Repository
 
23
from bzrlib.trace import info
 
24
from bzrlib.transport import Transport
37
25
 
38
 
from bzrlib.plugins.git import (
39
 
    lazy_check_versions,
40
 
    )
 
26
from bzrlib.plugins.git import lazy_check_versions
41
27
lazy_check_versions()
42
28
 
43
 
from bzrlib.plugins.git.branch import (
44
 
    GitBranch,
45
 
    extract_tags,
46
 
    )
47
 
from bzrlib.plugins.git.errors import (
48
 
    GitSmartRemoteNotSupported,
49
 
    NoSuchRef,
50
 
    )
51
 
from bzrlib.plugins.git.dir import (
52
 
    GitDir,
53
 
    )
54
 
from bzrlib.plugins.git.mapping import (
55
 
    mapping_registry,
56
 
    )
57
 
from bzrlib.plugins.git.repository import (
58
 
    GitRepositoryFormat,
59
 
    GitRepository,
60
 
    )
 
29
from bzrlib.plugins.git.branch import GitBranch
 
30
from bzrlib.plugins.git.errors import NoSuchRef
 
31
from bzrlib.plugins.git.dir import GitDir
 
32
from bzrlib.plugins.git.foreign import ForeignBranch
 
33
from bzrlib.plugins.git.repository import GitFormat, GitRepository
61
34
 
62
 
import dulwich as git
63
 
from dulwich.errors import (
64
 
    GitProtocolError,
65
 
    )
66
 
from dulwich.pack import (
67
 
    Pack,
68
 
    PackData,
69
 
    )
70
35
import os
71
36
import tempfile
72
37
import urllib
73
38
import urlparse
74
39
 
75
 
try:
76
 
    from dulwich.pack import load_pack_index
77
 
except ImportError:
78
 
    from dulwich.pack import PackIndex as load_pack_index
79
 
 
 
40
import dulwich as git
 
41
from dulwich.errors import GitProtocolError
 
42
from dulwich.pack import PackData, Pack, PackIndex
80
43
 
81
44
# Don't run any tests on GitSmartTransport as it is not intended to be 
82
45
# a full implementation of Transport
89
52
    def __init__(self, url, _client=None):
90
53
        Transport.__init__(self, url)
91
54
        (scheme, _, loc, _, _) = urlparse.urlsplit(url)
 
55
        assert scheme == "git"
92
56
        hostport, self._path = urllib.splithost(loc)
93
 
        (self._username, hostport) = urllib.splituser(hostport)
94
 
        (self._host, self._port) = urllib.splitnport(hostport, None)
 
57
        (self._host, self._port) = urllib.splitnport(hostport, git.protocol.TCP_GIT_PORT)
95
58
        self._client = _client
96
59
 
97
 
    def external_url(self):
98
 
        return self.base
99
 
 
100
60
    def has(self, relpath):
101
61
        return False
102
62
 
103
63
    def _get_client(self):
104
 
        raise NotImplementedError(self._get_client)
105
 
 
106
 
    def _get_path(self):
107
 
        return self._path
 
64
        if self._client is not None:
 
65
            ret = self._client
 
66
            self._client = None
 
67
            return ret
 
68
        return git.client.TCPGitClient(self._host, self._port, thin_packs=False)
108
69
 
109
70
    def fetch_pack(self, determine_wants, graph_walker, pack_data, progress=None):
110
71
        if progress is None:
112
73
                info("git: %s" % text)
113
74
        client = self._get_client()
114
75
        try:
115
 
            return client.fetch_pack(self._get_path(), determine_wants, 
 
76
            client.fetch_pack(self._path, determine_wants, 
116
77
                graph_walker, pack_data, progress)
117
78
        except GitProtocolError, e:
118
79
            raise BzrError(e)
119
80
 
120
 
    def send_pack(self, get_changed_refs, generate_pack_contents):
121
 
        client = self._get_client()
122
 
        try:
123
 
            return client.send_pack(self._get_path(), get_changed_refs, 
124
 
                generate_pack_contents)
125
 
        except GitProtocolError, e:
126
 
            raise BzrError(e)
127
 
 
128
81
    def get(self, path):
129
82
        raise NoSuchFile(path)
130
83
 
138
91
        else:
139
92
            newurl = urlutils.join(self.base, offset)
140
93
 
141
 
        return self.__class__(newurl, self._client)
142
 
 
143
 
 
144
 
class TCPGitSmartTransport(GitSmartTransport):
145
 
 
146
 
    _scheme = 'git'
147
 
 
148
 
    def _get_client(self):
149
 
        if self._client is not None:
150
 
            ret = self._client
151
 
            self._client = None
152
 
            return ret
153
 
        return git.client.TCPGitClient(self._host, self._port, thin_packs=False,
154
 
            report_activity=self._report_activity)
155
 
 
156
 
 
157
 
class SSHGitSmartTransport(GitSmartTransport):
158
 
 
159
 
    _scheme = 'git+ssh'
160
 
 
161
 
    def _get_path(self):
162
 
        if self._path.startswith("/~/"):
163
 
            return self._path[3:]
164
 
        return self._path
165
 
 
166
 
    def _get_client(self):
167
 
        if self._client is not None:
168
 
            ret = self._client
169
 
            self._client = None
170
 
            return ret
171
 
        return git.client.SSHGitClient(self._host, self._port, self._username,
172
 
            thin_packs=False, report_activity=self._report_activity)
 
94
        return GitSmartTransport(newurl, self._client)
173
95
 
174
96
 
175
97
class RemoteGitDir(GitDir):
179
101
        self.root_transport = transport
180
102
        self.transport = transport
181
103
        self._lockfiles = lockfiles
182
 
        self._mode_check_done = None
183
104
 
184
105
    def open_repository(self):
185
106
        return RemoteGitRepository(self, self._lockfiles)
186
107
 
187
 
    def open_branch(self, ignore_fallbacks=False):
 
108
    def open_branch(self, _unsupported=False):
188
109
        repo = self.open_repository()
189
110
        # TODO: Support for multiple branches in one bzrdir in bzrlib!
190
111
        return RemoteGitBranch(self, repo, "HEAD", self._lockfiles)
202
123
class TemporaryPackIterator(Pack):
203
124
 
204
125
    def __init__(self, path, resolve_ext_ref):
 
126
        self.resolve_ext_ref = resolve_ext_ref
205
127
        super(TemporaryPackIterator, self).__init__(path)
206
 
        self.resolve_ext_ref = resolve_ext_ref
207
128
 
208
129
    @property
209
 
    def index(self):
 
130
    def idx(self):
210
131
        if self._idx is None:
211
 
            pb = ui.ui_factory.nested_progress_bar()
212
 
            try:
213
 
                def report_progress(cur, total):
214
 
                    pb.update("generating index", cur, total)
215
 
                self.data.create_index(self._idx_path, self.resolve_ext_ref,
216
 
                    progress=report_progress)
217
 
            finally:
218
 
                pb.finished()
219
 
            self._idx = load_pack_index(self._idx_path)
 
132
            self._data.create_index_v2(self._idx_path, self.resolve_ext_ref)
 
133
            self._idx = PackIndex(self._idx_path)
220
134
        return self._idx
221
135
 
222
136
    def __del__(self):
228
142
 
229
143
    def __init__(self, gitdir, lockfiles):
230
144
        GitRepository.__init__(self, gitdir, lockfiles)
231
 
        self._refs = None
232
 
 
233
 
    @property
234
 
    def inventories(self):
235
 
        raise GitSmartRemoteNotSupported()
236
 
 
237
 
    @property
238
 
    def revisions(self):
239
 
        raise GitSmartRemoteNotSupported()
240
 
 
241
 
    @property
242
 
    def texts(self):
243
 
        raise GitSmartRemoteNotSupported()
244
 
 
245
 
    def get_refs(self):
246
 
        if self._refs is not None:
247
 
            return self._refs
248
 
        self._refs = self.bzrdir.root_transport.fetch_pack(lambda x: [], None, 
249
 
            lambda x: None, lambda x: mutter("git: %s" % x))
250
 
        return self._refs
251
145
 
252
146
    def fetch_pack(self, determine_wants, graph_walker, pack_data, 
253
147
                   progress=None):
254
 
        return self._transport.fetch_pack(determine_wants, graph_walker,
255
 
                                          pack_data, progress)
256
 
 
257
 
    def send_pack(self, get_changed_refs, generate_pack_contents):
258
 
        return self._transport.send_pack(get_changed_refs, generate_pack_contents)
 
148
        self._transport.fetch_pack(determine_wants, graph_walker, pack_data, 
 
149
            progress)
259
150
 
260
151
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref, progress=None):
261
152
        fd, path = tempfile.mkstemp(suffix=".pack")
265
156
            return EmptyObjectStoreIterator()
266
157
        return TemporaryPackIterator(path[:-len(".pack")], resolve_ext_ref)
267
158
 
268
 
    def lookup_git_revid(self, bzr_revid):
269
 
        # This won't work for any round-tripped bzr revisions, but it's a start..
270
 
        try:
271
 
            return mapping_registry.revision_id_bzr_to_foreign(bzr_revid)
272
 
        except InvalidRevisionId:
273
 
            raise NoSuchRevision(self, bzr_revid)
274
 
 
275
 
 
276
 
class RemoteGitTagDict(tag.BasicTags):
277
 
 
278
 
    def __init__(self, branch):
279
 
        self.branch = branch
280
 
        self.repository = branch.repository
281
 
 
282
 
    def get_tag_dict(self):
283
 
        return extract_tags(self.repository.get_refs(), self.branch.mapping)
284
 
 
285
 
    def set_tag(self, name, revid):
286
 
        # FIXME: Not supported yet, should do a push of a new ref
287
 
        raise NotImplementedError(self.set_tag)
288
 
 
289
159
 
290
160
class RemoteGitBranch(GitBranch):
291
161
 
292
162
    def __init__(self, bzrdir, repository, name, lockfiles):
293
 
        self._ref = None
294
 
        super(RemoteGitBranch, self).__init__(bzrdir, repository, name, 
295
 
                lockfiles)
296
 
 
297
 
    def revision_history(self):
298
 
        raise GitSmartRemoteNotSupported()
 
163
        def determine_wants(heads):
 
164
            if not name in heads:
 
165
                raise NoSuchRef(name)
 
166
            self._ref = heads[name]
 
167
        bzrdir.root_transport.fetch_pack(determine_wants, None, lambda x: None, 
 
168
                             lambda x: mutter("git: %s" % x))
 
169
        super(RemoteGitBranch, self).__init__(bzrdir, repository, name, self._ref, lockfiles)
299
170
 
300
171
    def last_revision(self):
301
 
        return self.mapping.revision_id_foreign_to_bzr(self.head)
302
 
 
303
 
    @property
304
 
    def head(self):
305
 
        if self._ref is not None:
306
 
            return self._ref
307
 
        heads = self.repository.get_refs()
308
 
        if not self.name in heads:
309
 
            raise NoSuchRef(name)
310
 
        self._ref = heads[self.name]
311
 
        return self._ref
 
172
        return self.mapping.revision_id_foreign_to_bzr(self._ref)
312
173
 
313
174
    def _synchronize_history(self, destination, revision_id):
314
175
        """See Branch._synchronize_history()."""
315
176
        destination.generate_revision_history(self.last_revision())
316
177
 
317
 
    def get_push_location(self):
318
 
        return None
319
 
 
320
 
    def set_push_location(self, url):
321
 
        pass