/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:
1
 
# Copyright (C) 2007-2008 Canonical Ltd
 
1
# Copyright (C) 2007-2009 Jelmer Vernooij <jelmer@samba.org>
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
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
import bzrlib
18
 
from bzrlib import urlutils
19
 
from bzrlib.bzrdir import BzrDir, BzrDirFormat
20
 
from bzrlib.errors import NoSuchFile, NotLocalUrl
 
18
from bzrlib import (
 
19
    branch,
 
20
    tag,
 
21
    urlutils,
 
22
    )
 
23
from bzrlib.bzrdir import (
 
24
    BzrDir,
 
25
    BzrDirFormat,
 
26
    )
 
27
from bzrlib.errors import (
 
28
    BzrError,
 
29
    NoSuchFile,
 
30
    NotLocalUrl,
 
31
    )
21
32
from bzrlib.lockable_files import TransportLock
22
33
from bzrlib.repository import Repository
23
34
from bzrlib.trace import info
30
41
from bzrlib.plugins.git.errors import NoSuchRef
31
42
from bzrlib.plugins.git.dir import GitDir
32
43
from bzrlib.plugins.git.foreign import ForeignBranch
33
 
from bzrlib.plugins.git.repository import GitFormat, GitRepository
 
44
from bzrlib.plugins.git.repository import (
 
45
    GitRepositoryFormat,
 
46
    GitRepository,
 
47
    )
34
48
 
 
49
import dulwich as git
 
50
from dulwich.errors import GitProtocolError
 
51
from dulwich.pack import (
 
52
    Pack,
 
53
    PackData,
 
54
    PackIndex,
 
55
    )
35
56
import os
36
57
import tempfile
37
58
import urllib
38
59
import urlparse
39
60
 
40
 
import dulwich as git
41
 
from dulwich.pack import PackData, Pack, PackIndex
42
61
 
43
62
# Don't run any tests on GitSmartTransport as it is not intended to be 
44
63
# a full implementation of Transport
56
75
        (self._host, self._port) = urllib.splitnport(hostport, git.protocol.TCP_GIT_PORT)
57
76
        self._client = _client
58
77
 
 
78
    def has(self, relpath):
 
79
        return False
 
80
 
59
81
    def _get_client(self):
60
82
        if self._client is not None:
61
83
            ret = self._client
62
84
            self._client = None
63
85
            return ret
64
 
        return git.client.TCPGitClient(self._host, self._port, 
65
 
            capabilities=["multi_ack", "side-band-64k", "ofs-delta", "side-band"])
 
86
        return git.client.TCPGitClient(self._host, self._port, thin_packs=False)
66
87
 
67
88
    def fetch_pack(self, determine_wants, graph_walker, pack_data, progress=None):
68
89
        if progress is None:
69
90
            def progress(text):
70
91
                info("git: %s" % text)
71
 
        self._get_client().fetch_pack(self._path, determine_wants, 
72
 
            graph_walker, pack_data, progress)
 
92
        client = self._get_client()
 
93
        try:
 
94
            client.fetch_pack(self._path, determine_wants, 
 
95
                graph_walker, pack_data, progress)
 
96
        except GitProtocolError, e:
 
97
            raise BzrError(e)
73
98
 
74
99
    def get(self, path):
75
100
        raise NoSuchFile(path)
135
160
 
136
161
    def __init__(self, gitdir, lockfiles):
137
162
        GitRepository.__init__(self, gitdir, lockfiles)
 
163
        self._refs = None
 
164
 
 
165
    def get_refs(self):
 
166
        if self._refs is not None:
 
167
            return self._refs
 
168
        def determine_wants(heads):
 
169
            self._refs = heads
 
170
            return []
 
171
        self.bzrdir.root_transport.fetch_pack(determine_wants, None, 
 
172
            lambda x: None, lambda x: mutter("git: %s" % x))
 
173
        return self._refs
138
174
 
139
175
    def fetch_pack(self, determine_wants, graph_walker, pack_data, 
140
176
                   progress=None):
150
186
        return TemporaryPackIterator(path[:-len(".pack")], resolve_ext_ref)
151
187
 
152
188
 
 
189
class RemoteGitTagDict(tag.BasicTags):
 
190
 
 
191
    def __init__(self, branch):
 
192
        self.branch = branch
 
193
        self.repository = branch.repository
 
194
 
 
195
    def get_tag_dict(self):
 
196
        ret = {}
 
197
        refs = self.repository.get_refs()
 
198
        for k,v in refs.iteritems():
 
199
            if k.startswith("refs/tags/") and not k.endswith("^{}"):
 
200
                v = refs.get(k+"^{}", v)
 
201
                ret[k[len("refs/tags/"):]] = self.branch.mapping.revision_id_foreign_to_bzr(v)
 
202
        return ret
 
203
 
 
204
    def set_tag(self, name, revid):
 
205
        # FIXME: Not supported yet, should do a push of a new ref
 
206
        raise NotImplementedError(self.set_tag)
 
207
 
 
208
 
153
209
class RemoteGitBranch(GitBranch):
154
210
 
155
211
    def __init__(self, bzrdir, repository, name, lockfiles):
156
 
        def determine_wants(heads):
157
 
            if not name in heads:
158
 
                raise NoSuchRef(name)
159
 
            self._ref = heads[name]
160
 
        bzrdir.root_transport.fetch_pack(determine_wants, None, lambda x: None, 
161
 
                             lambda x: mutter("git: %s" % x))
 
212
        heads = repository.get_refs()
 
213
        if not name in heads:
 
214
            raise NoSuchRef(name)
 
215
        self._ref = heads[name]
162
216
        super(RemoteGitBranch, self).__init__(bzrdir, repository, name, self._ref, lockfiles)
163
217
 
164
218
    def last_revision(self):