/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

Use .id rather than .sha().hexdigest().

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
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
 
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
    )
25
44
 
26
 
from bzrlib.plugins.git import lazy_check_versions
 
45
from bzrlib.plugins.git import (
 
46
    lazy_check_versions,
 
47
    )
27
48
lazy_check_versions()
28
49
 
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
 
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
    )
34
66
 
 
67
import dulwich as git
 
68
from dulwich.errors import (
 
69
    GitProtocolError,
 
70
    )
 
71
from dulwich.pack import (
 
72
    Pack,
 
73
    PackData,
 
74
    )
35
75
import os
36
76
import tempfile
37
77
import urllib
38
78
import urlparse
39
79
 
40
 
import dulwich as git
41
 
from dulwich.pack import PackData, Pack, PackIndex
 
80
try:
 
81
    from dulwich.pack import load_pack_index
 
82
except ImportError:
 
83
    from dulwich.pack import PackIndex as load_pack_index
 
84
 
42
85
 
43
86
# Don't run any tests on GitSmartTransport as it is not intended to be 
44
87
# a full implementation of Transport
51
94
    def __init__(self, url, _client=None):
52
95
        Transport.__init__(self, url)
53
96
        (scheme, _, loc, _, _) = urlparse.urlsplit(url)
54
 
        assert scheme == "git"
55
97
        hostport, self._path = urllib.splithost(loc)
56
98
        (self._host, self._port) = urllib.splitnport(hostport, git.protocol.TCP_GIT_PORT)
57
99
        self._client = _client
58
100
 
 
101
    def has(self, relpath):
 
102
        return False
 
103
 
59
104
    def _get_client(self):
60
 
        if self._client is not None:
61
 
            ret = self._client
62
 
            self._client = None
63
 
            return ret
64
 
        return git.client.TCPGitClient(self._host, self._port, 
65
 
            capabilities=["multi_ack", "side-band-64k", "ofs-delta", "side-band"])
 
105
        raise NotImplementedError(self._get_client)
66
106
 
67
107
    def fetch_pack(self, determine_wants, graph_walker, pack_data, progress=None):
68
108
        if progress is None:
69
109
            def progress(text):
70
110
                info("git: %s" % text)
71
 
        self._get_client().fetch_pack(self._path, determine_wants, 
72
 
            graph_walker, pack_data, progress)
 
111
        client = self._get_client()
 
112
        try:
 
113
            client.fetch_pack(self._path, determine_wants, 
 
114
                graph_walker, pack_data, progress)
 
115
        except GitProtocolError, e:
 
116
            raise BzrError(e)
73
117
 
74
118
    def get(self, path):
75
119
        raise NoSuchFile(path)
84
128
        else:
85
129
            newurl = urlutils.join(self.base, offset)
86
130
 
87
 
        return GitSmartTransport(newurl, self._client)
 
131
        return self.__class__(newurl, self._client)
 
132
 
 
133
 
 
134
class TCPGitSmartTransport(GitSmartTransport):
 
135
 
 
136
    def _get_client(self):
 
137
        if self._client is not None:
 
138
            ret = self._client
 
139
            self._client = None
 
140
            return ret
 
141
        return git.client.TCPGitClient(self._host, self._port, thin_packs=False)
 
142
 
 
143
 
 
144
class SSHGitSmartTransport(GitSmartTransport):
 
145
 
 
146
    def _get_client(self):
 
147
        if self._client is not None:
 
148
            ret = self._client
 
149
            self._client = None
 
150
            return ret
 
151
        return git.client.SSHGitClient(self._host, self._port, thin_packs=False)
88
152
 
89
153
 
90
154
class RemoteGitDir(GitDir):
116
180
class TemporaryPackIterator(Pack):
117
181
 
118
182
    def __init__(self, path, resolve_ext_ref):
 
183
        super(TemporaryPackIterator, self).__init__(path)
119
184
        self.resolve_ext_ref = resolve_ext_ref
120
 
        super(TemporaryPackIterator, self).__init__(path)
121
185
 
122
186
    @property
123
187
    def idx(self):
124
188
        if self._idx is None:
 
189
            if self._data is None:
 
190
                self._data = PackData(self._data_path)
125
191
            self._data.create_index_v2(self._idx_path, self.resolve_ext_ref)
126
 
            self._idx = PackIndex(self._idx_path)
 
192
            self._idx = load_pack_index(self._idx_path)
127
193
        return self._idx
128
194
 
129
195
    def __del__(self):
135
201
 
136
202
    def __init__(self, gitdir, lockfiles):
137
203
        GitRepository.__init__(self, gitdir, lockfiles)
 
204
        self._refs = None
 
205
 
 
206
    def get_refs(self):
 
207
        if self._refs is not None:
 
208
            return self._refs
 
209
        def determine_wants(heads):
 
210
            self._refs = heads
 
211
            return []
 
212
        self.bzrdir.root_transport.fetch_pack(determine_wants, None, 
 
213
            lambda x: None, lambda x: mutter("git: %s" % x))
 
214
        return self._refs
138
215
 
139
216
    def fetch_pack(self, determine_wants, graph_walker, pack_data, 
140
217
                   progress=None):
150
227
        return TemporaryPackIterator(path[:-len(".pack")], resolve_ext_ref)
151
228
 
152
229
 
 
230
class RemoteGitTagDict(tag.BasicTags):
 
231
 
 
232
    def __init__(self, branch):
 
233
        self.branch = branch
 
234
        self.repository = branch.repository
 
235
 
 
236
    def get_tag_dict(self):
 
237
        ret = {}
 
238
        refs = self.repository.get_refs()
 
239
        for k,v in refs.iteritems():
 
240
            if k.startswith("refs/tags/") and not k.endswith("^{}"):
 
241
                v = refs.get(k+"^{}", v)
 
242
                ret[k[len("refs/tags/"):]] = self.branch.mapping.revision_id_foreign_to_bzr(v)
 
243
        return ret
 
244
 
 
245
    def set_tag(self, name, revid):
 
246
        # FIXME: Not supported yet, should do a push of a new ref
 
247
        raise NotImplementedError(self.set_tag)
 
248
 
 
249
 
153
250
class RemoteGitBranch(GitBranch):
154
251
 
155
252
    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))
 
253
        heads = repository.get_refs()
 
254
        if not name in heads:
 
255
            raise NoSuchRef(name)
 
256
        self._ref = heads[name]
162
257
        super(RemoteGitBranch, self).__init__(bzrdir, repository, name, self._ref, lockfiles)
163
258
 
164
259
    def last_revision(self):