/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-09-10 13:13:15 UTC
  • mto: (0.200.602 trunk)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@samba.org-20090910131315-6890xg58pl2jseml
Allow serving remote URLs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
 
17
import bzrlib
17
18
from bzrlib import (
18
19
    config,
19
20
    tag,
64
65
    )
65
66
from dulwich.pack import (
66
67
    Pack,
67
 
    PackData,
68
68
    )
69
69
import os
70
70
import tempfile
74
74
from dulwich.pack import load_pack_index
75
75
 
76
76
 
77
 
# Don't run any tests on GitSmartTransport as it is not intended to be
 
77
# Don't run any tests on GitSmartTransport as it is not intended to be 
78
78
# a full implementation of Transport
79
79
def get_test_permutations():
80
80
    return []
85
85
    def __init__(self, url, _client=None):
86
86
        Transport.__init__(self, url)
87
87
        (scheme, _, loc, _, _) = urlparse.urlsplit(url)
88
 
        hostport, escaped_path = urllib.splithost(loc)
89
 
        self._path = urllib.unquote(escaped_path)
 
88
        hostport, self._path = urllib.splithost(loc)
90
89
        (self._username, hostport) = urllib.splituser(hostport)
91
90
        (self._host, self._port) = urllib.splitnport(hostport, None)
92
91
        self._client = _client
109
108
                info("git: %s" % text)
110
109
        client = self._get_client(thin_packs=False)
111
110
        try:
112
 
            return client.fetch_pack(self._get_path(), determine_wants,
 
111
            return client.fetch_pack(self._get_path(), determine_wants, 
113
112
                graph_walker, pack_data, progress)
114
113
        except GitProtocolError, e:
115
114
            raise BzrError(e)
117
116
    def send_pack(self, get_changed_refs, generate_pack_contents):
118
117
        client = self._get_client(thin_packs=False)
119
118
        try:
120
 
            return client.send_pack(self._get_path(), get_changed_refs,
 
119
            return client.send_pack(self._get_path(), get_changed_refs, 
121
120
                generate_pack_contents)
122
121
        except GitProtocolError, e:
123
122
            raise BzrError(e)
186
185
        # TODO: Support for multiple branches in one bzrdir in bzrlib!
187
186
        return RemoteGitBranch(self, repo, "HEAD", self._lockfiles)
188
187
 
189
 
    def open_workingtree(self, recommend_upgrade=False):
 
188
    def open_workingtree(self):
190
189
        raise NotLocalUrl(self.transport.base)
191
190
 
192
191
 
203
202
        self.resolve_ext_ref = resolve_ext_ref
204
203
 
205
204
    @property
206
 
    def data(self):
207
 
        if self._data is None:
208
 
            self._data = PackData(self._data_path)
209
 
        return self._data
210
 
 
211
 
    @property
212
205
    def index(self):
213
206
        if self._idx is None:
214
207
            if not os.path.exists(self._idx_path):
224
217
        return self._idx
225
218
 
226
219
    def __del__(self):
227
 
        if self._idx is not None:
228
 
            self._idx.close()
229
 
            os.remove(self._idx_path)
230
 
        if self._data is not None:
231
 
            self._data.close()
232
 
            os.remove(self._data_path)
 
220
        os.remove(self._data_path)
 
221
        os.remove(self._idx_path)
233
222
 
234
223
 
235
224
class RemoteGitRepository(GitRepository):
253
242
    def get_refs(self):
254
243
        if self._refs is not None:
255
244
            return self._refs
256
 
        self._refs = self.bzrdir.root_transport.fetch_pack(lambda x: [], None,
 
245
        self._refs = self.bzrdir.root_transport.fetch_pack(lambda x: [], None, 
257
246
            lambda x: None, lambda x: trace.mutter("git: %s" % x))
258
247
        return self._refs
259
248
 
260
 
    def fetch_pack(self, determine_wants, graph_walker, pack_data,
 
249
    def fetch_pack(self, determine_wants, graph_walker, pack_data, 
261
250
                   progress=None):
262
251
        return self._transport.fetch_pack(determine_wants, graph_walker,
263
252
                                          pack_data, progress)
265
254
    def send_pack(self, get_changed_refs, generate_pack_contents):
266
255
        return self._transport.send_pack(get_changed_refs, generate_pack_contents)
267
256
 
268
 
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref,
269
 
                      progress=None):
 
257
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref, progress=None):
270
258
        fd, path = tempfile.mkstemp(suffix=".pack")
271
 
        self.fetch_pack(determine_wants, graph_walker,
272
 
            lambda x: os.write(fd, x), progress)
 
259
        self.fetch_pack(determine_wants, graph_walker, lambda x: os.write(fd, x), progress)
273
260
        os.close(fd)
274
261
        if os.path.getsize(path) == 0:
275
262
            return EmptyObjectStoreIterator()
276
263
        return TemporaryPackIterator(path[:-len(".pack")], resolve_ext_ref)
277
264
 
278
 
    def lookup_bzr_revision_id(self, bzr_revid):
 
265
    def lookup_git_revid(self, bzr_revid):
279
266
        # This won't work for any round-tripped bzr revisions, but it's a start..
280
267
        try:
281
268
            return mapping_registry.revision_id_bzr_to_foreign(bzr_revid)
290
277
        self.repository = branch.repository
291
278
 
292
279
    def get_tag_dict(self):
293
 
        tags = {}
294
 
        for k, v in extract_tags(self.repository.get_refs()).iteritems():
295
 
            tags[k] = self.branch.mapping.revision_id_foreign_to_bzr(v)
296
 
        return tags
 
280
        return extract_tags(self.repository.get_refs(), self.branch.mapping)
297
281
 
298
282
    def set_tag(self, name, revid):
299
283
        # FIXME: Not supported yet, should do a push of a new ref
304
288
 
305
289
    def __init__(self, bzrdir, repository, name, lockfiles):
306
290
        self._ref = None
307
 
        super(RemoteGitBranch, self).__init__(bzrdir, repository, name,
 
291
        super(RemoteGitBranch, self).__init__(bzrdir, repository, name, 
308
292
                lockfiles)
309
293
 
310
294
    def revision_history(self):
334
318
    def _synchronize_history(self, destination, revision_id):
335
319
        """See Branch._synchronize_history()."""
336
320
        destination.generate_revision_history(self.last_revision())
337
 
 
 
321
 
338
322
    def get_push_location(self):
339
323
        return None
340
324