1
# Copyright (C) 2007-2009 Jelmer Vernooij <jelmer@samba.org>
1
# Copyright (C) 2007-2008 Canonical Ltd
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
18
from bzrlib import branch, tag, urlutils
18
from bzrlib import urlutils
19
19
from bzrlib.bzrdir import BzrDir, BzrDirFormat
20
from bzrlib.errors import BzrError, NoSuchFile, NotLocalUrl
20
from bzrlib.errors import NoSuchFile, NotLocalUrl
21
21
from bzrlib.lockable_files import TransportLock
22
22
from bzrlib.repository import Repository
23
23
from bzrlib.trace import info
57
56
(self._host, self._port) = urllib.splitnport(hostport, git.protocol.TCP_GIT_PORT)
58
57
self._client = _client
60
def has(self, relpath):
63
59
def _get_client(self):
64
60
if self._client is not None:
66
62
self._client = None
68
return git.client.TCPGitClient(self._host, self._port, thin_packs=False)
64
return git.client.TCPGitClient(self._host, self._port)
70
66
def fetch_pack(self, determine_wants, graph_walker, pack_data, progress=None):
71
67
if progress is None:
72
68
def progress(text):
73
69
info("git: %s" % text)
74
client = self._get_client()
76
client.fetch_pack(self._path, determine_wants,
77
graph_walker, pack_data, progress)
78
except GitProtocolError, e:
70
self._get_client().fetch_pack(self._path, determine_wants,
71
graph_walker, pack_data, progress)
81
73
def get(self, path):
82
74
raise NoSuchFile(path)
114
106
raise NotLocalUrl(self.transport.base)
117
class EmptyObjectStoreIterator(dict):
119
def iterobjects(self):
123
109
class TemporaryPackIterator(Pack):
125
111
def __init__(self, path, resolve_ext_ref):
143
129
def __init__(self, gitdir, lockfiles):
144
130
GitRepository.__init__(self, gitdir, lockfiles)
148
if self._refs is not None:
150
def determine_wants(heads):
153
self.bzrdir.root_transport.fetch_pack(determine_wants, None,
154
lambda x: None, lambda x: mutter("git: %s" % x))
157
132
def fetch_pack(self, determine_wants, graph_walker, pack_data,
164
139
self.fetch_pack(determine_wants, graph_walker, lambda x: os.write(fd, x), progress)
166
141
if os.path.getsize(path) == 0:
167
return EmptyObjectStoreIterator()
168
143
return TemporaryPackIterator(path[:-len(".pack")], resolve_ext_ref)
171
class RemoteGitTagDict(tag.BasicTags):
173
def __init__(self, branch):
175
self.repository = branch.repository
177
def get_tag_dict(self):
179
refs = self.repository.get_refs()
180
for k,v in refs.iteritems():
181
if k.startswith("refs/tags/") and not k.endswith("^{}"):
182
v = refs.get(k+"^{}", v)
183
ret[k[len("refs/tags/"):]] = self.branch.mapping.revision_id_foreign_to_bzr(v)
186
def set_tag(self, name, revid):
187
# FIXME: Not supported yet, should do a push of a new ref
188
raise NotImplementedError(self.set_tag)
191
146
class RemoteGitBranch(GitBranch):
193
148
def __init__(self, bzrdir, repository, name, lockfiles):
194
heads = repository.get_refs()
195
if not name in heads:
196
raise NoSuchRef(name)
197
self._ref = heads[name]
149
def determine_wants(heads):
150
if not name in heads:
151
raise NoSuchRef(name)
152
self._ref = heads[name]
153
bzrdir.root_transport.fetch_pack(determine_wants, None, lambda x: None,
154
lambda x: mutter("git: %s" % x))
198
155
super(RemoteGitBranch, self).__init__(bzrdir, repository, name, self._ref, lockfiles)
200
157
def last_revision(self):