/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

Partially fix pull.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2009 Jelmer Vernooij <jelmer@samba.org>
 
1
# Copyright (C) 2007-2008 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
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
 
    urlutils,
22
 
    )
23
 
from bzrlib.bzrdir import (
24
 
    BzrDir,
25
 
    BzrDirFormat,
26
 
    )
27
 
from bzrlib.errors import (
28
 
    BzrError,
29
 
    NoSuchFile,
30
 
    NotLocalUrl,
31
 
    )
32
 
from bzrlib.lockable_files import (
33
 
    TransportLock,
34
 
    )
35
 
from bzrlib.repository import (
36
 
    Repository,
37
 
    )
38
 
from bzrlib.trace import (
39
 
    info,
40
 
    )
41
 
from bzrlib.transport import (
42
 
    Transport,
43
 
    )
 
18
from bzrlib import urlutils
 
19
from bzrlib.bzrdir import BzrDir, BzrDirFormat
 
20
from bzrlib.errors import 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
44
25
 
45
 
from bzrlib.plugins.git import (
46
 
    lazy_check_versions,
47
 
    )
 
26
from bzrlib.plugins.git import lazy_check_versions
48
27
lazy_check_versions()
49
28
 
50
 
from bzrlib.plugins.git.branch import (
51
 
    GitBranch,
52
 
    )
53
 
from bzrlib.plugins.git.errors import (
54
 
    NoSuchRef,
55
 
    )
56
 
from bzrlib.plugins.git.dir import (
57
 
    GitDir,
58
 
    )
59
 
from bzrlib.plugins.git.foreign import (
60
 
    ForeignBranch,
61
 
    )
62
 
from bzrlib.plugins.git.repository import (
63
 
    GitRepositoryFormat,
64
 
    GitRepository,
65
 
    )
 
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
66
34
 
67
 
import dulwich as git
68
 
from dulwich.errors import (
69
 
    GitProtocolError,
70
 
    )
71
 
from dulwich.pack import (
72
 
    Pack,
73
 
    PackData,
74
 
    PackIndex,
75
 
    )
76
35
import os
77
36
import tempfile
78
37
import urllib
79
38
import urlparse
80
39
 
 
40
import dulwich as git
 
41
from dulwich.pack import PackData, Pack, PackIndex
81
42
 
82
43
# Don't run any tests on GitSmartTransport as it is not intended to be 
83
44
# a full implementation of Transport
95
56
        (self._host, self._port) = urllib.splitnport(hostport, git.protocol.TCP_GIT_PORT)
96
57
        self._client = _client
97
58
 
98
 
    def has(self, relpath):
99
 
        return False
100
 
 
101
59
    def _get_client(self):
102
60
        if self._client is not None:
103
61
            ret = self._client
104
62
            self._client = None
105
63
            return ret
106
 
        return git.client.TCPGitClient(self._host, self._port, thin_packs=False)
 
64
        return git.client.TCPGitClient(self._host, self._port, 
 
65
            capabilities=["multi_ack", "side-band-64k", "ofs-delta", "side-band"])
107
66
 
108
67
    def fetch_pack(self, determine_wants, graph_walker, pack_data, progress=None):
109
68
        if progress is None:
110
69
            def progress(text):
111
70
                info("git: %s" % text)
112
 
        client = self._get_client()
113
 
        try:
114
 
            client.fetch_pack(self._path, determine_wants, 
115
 
                graph_walker, pack_data, progress)
116
 
        except GitProtocolError, e:
117
 
            raise BzrError(e)
 
71
        self._get_client().fetch_pack(self._path, determine_wants, 
 
72
            graph_walker, pack_data, progress)
118
73
 
119
74
    def get(self, path):
120
75
        raise NoSuchFile(path)
167
122
    @property
168
123
    def idx(self):
169
124
        if self._idx is None:
170
 
            if self._data is None:
171
 
                self._data = PackData(self._data_path)
172
125
            self._data.create_index_v2(self._idx_path, self.resolve_ext_ref)
173
126
            self._idx = PackIndex(self._idx_path)
174
127
        return self._idx
182
135
 
183
136
    def __init__(self, gitdir, lockfiles):
184
137
        GitRepository.__init__(self, gitdir, lockfiles)
185
 
        self._refs = None
186
 
 
187
 
    def get_refs(self):
188
 
        if self._refs is not None:
189
 
            return self._refs
190
 
        def determine_wants(heads):
191
 
            self._refs = heads
192
 
            return []
193
 
        self.bzrdir.root_transport.fetch_pack(determine_wants, None, 
194
 
            lambda x: None, lambda x: mutter("git: %s" % x))
195
 
        return self._refs
196
138
 
197
139
    def fetch_pack(self, determine_wants, graph_walker, pack_data, 
198
140
                   progress=None):
208
150
        return TemporaryPackIterator(path[:-len(".pack")], resolve_ext_ref)
209
151
 
210
152
 
211
 
class RemoteGitTagDict(tag.BasicTags):
212
 
 
213
 
    def __init__(self, branch):
214
 
        self.branch = branch
215
 
        self.repository = branch.repository
216
 
 
217
 
    def get_tag_dict(self):
218
 
        ret = {}
219
 
        refs = self.repository.get_refs()
220
 
        for k,v in refs.iteritems():
221
 
            if k.startswith("refs/tags/") and not k.endswith("^{}"):
222
 
                v = refs.get(k+"^{}", v)
223
 
                ret[k[len("refs/tags/"):]] = self.branch.mapping.revision_id_foreign_to_bzr(v)
224
 
        return ret
225
 
 
226
 
    def set_tag(self, name, revid):
227
 
        # FIXME: Not supported yet, should do a push of a new ref
228
 
        raise NotImplementedError(self.set_tag)
229
 
 
230
 
 
231
153
class RemoteGitBranch(GitBranch):
232
154
 
233
155
    def __init__(self, bzrdir, repository, name, lockfiles):
234
 
        heads = repository.get_refs()
235
 
        if not name in heads:
236
 
            raise NoSuchRef(name)
237
 
        self._ref = heads[name]
 
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))
238
162
        super(RemoteGitBranch, self).__init__(bzrdir, repository, name, self._ref, lockfiles)
239
163
 
240
164
    def last_revision(self):