/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

  • Committer: Jelmer Vernooij
  • Date: 2009-03-28 22:27:07 UTC
  • mto: (0.200.305 trunk)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@samba.org-20090328222707-n0y980ntev40xqd2
Fix blob lookup.

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
    PackIndex,
 
75
    )
35
76
import os
36
77
import tempfile
37
78
import urllib
38
79
import urlparse
39
80
 
40
 
import dulwich as git
41
 
from dulwich.pack import PackData, Pack, PackIndex
42
81
 
43
82
# Don't run any tests on GitSmartTransport as it is not intended to be 
44
83
# a full implementation of Transport
56
95
        (self._host, self._port) = urllib.splitnport(hostport, git.protocol.TCP_GIT_PORT)
57
96
        self._client = _client
58
97
 
 
98
    def has(self, relpath):
 
99
        return False
 
100
 
59
101
    def _get_client(self):
60
102
        if self._client is not None:
61
103
            ret = self._client
62
104
            self._client = None
63
105
            return ret
64
 
        return git.client.TCPGitClient(self._host, self._port, 
65
 
            capabilities=["multi_ack", "side-band-64k", "ofs-delta", "side-band"])
 
106
        return git.client.TCPGitClient(self._host, self._port, thin_packs=False)
66
107
 
67
108
    def fetch_pack(self, determine_wants, graph_walker, pack_data, progress=None):
68
109
        if progress is None:
69
110
            def progress(text):
70
111
                info("git: %s" % text)
71
 
        self._get_client().fetch_pack(self._path, determine_wants, 
72
 
            graph_walker, pack_data, progress)
 
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)
73
118
 
74
119
    def get(self, path):
75
120
        raise NoSuchFile(path)
122
167
    @property
123
168
    def idx(self):
124
169
        if self._idx is None:
 
170
            if self._data is None:
 
171
                self._data = PackData(self._data_path)
125
172
            self._data.create_index_v2(self._idx_path, self.resolve_ext_ref)
126
173
            self._idx = PackIndex(self._idx_path)
127
174
        return self._idx
135
182
 
136
183
    def __init__(self, gitdir, lockfiles):
137
184
        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
138
196
 
139
197
    def fetch_pack(self, determine_wants, graph_walker, pack_data, 
140
198
                   progress=None):
150
208
        return TemporaryPackIterator(path[:-len(".pack")], resolve_ext_ref)
151
209
 
152
210
 
 
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
 
153
231
class RemoteGitBranch(GitBranch):
154
232
 
155
233
    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))
 
234
        heads = repository.get_refs()
 
235
        if not name in heads:
 
236
            raise NoSuchRef(name)
 
237
        self._ref = heads[name]
162
238
        super(RemoteGitBranch, self).__init__(bzrdir, repository, name, self._ref, lockfiles)
163
239
 
164
240
    def last_revision(self):