26
26
from bzrlib.plugins.git import git
27
27
from bzrlib.plugins.git.branch import GitBranch
28
from bzrlib.plugins.git.errors import NoSuchRef
28
29
from bzrlib.plugins.git.dir import GitDir
29
30
from bzrlib.plugins.git.foreign import ForeignBranch
30
31
from bzrlib.plugins.git.repository import GitFormat, GitRepository
35
from dulwich.pack import PackData
38
from dulwich.pack import PackData, Pack
40
# Don't run any tests on GitSmartTransport as it is not intended to be
41
# a full implementation of Transport
42
def get_test_permutations():
38
46
class GitSmartTransport(Transport):
43
51
assert scheme == "git"
44
52
hostport, self._path = urllib.splithost(loc)
45
53
(self._host, self._port) = urllib.splitnport(hostport, git.protocol.TCP_GIT_PORT)
46
if _client is not None:
47
self._client = _client
49
self._client = git.client.TCPGitClient(self._host, self._port)
54
self._client = _client
56
def _get_client(self):
57
if self._client is not None:
61
return git.client.TCPGitClient(self._host, self._port)
51
63
def fetch_pack(self, determine_wants, graph_walker, pack_data, progress=None):
52
64
if progress is None:
53
65
def progress(text):
54
66
info("git: %s" % text)
55
self._client.fetch_pack(self._path, determine_wants, graph_walker,
58
def fetch_objects(self, determine_wants, graph_walker, progress=None):
59
fd, path = tempfile.mkstemp(dir=self.pack_dir(), suffix=".pack")
60
self.fetch_pack(determine_wants, graph_walker, lambda x: os.write(fd, x), progress)
64
for o in p.iterobjects():
67
self._get_client().fetch_pack(self._path, determine_wants,
68
graph_walker, pack_data, progress)
69
70
def get(self, path):
70
71
raise NoSuchFile(path)
73
def abspath(self, relpath):
74
return urlutils.join(self.base, relpath)
72
76
def clone(self, offset=None):
73
77
"""See Transport.clone()."""
90
94
def open_repository(self):
91
95
return RemoteGitRepository(self, self._lockfiles)
93
def open_branch(self):
97
def open_branch(self, _unsupported=False):
94
98
repo = self.open_repository()
95
99
# TODO: Support for multiple branches in one bzrdir in bzrlib!
96
100
return RemoteGitBranch(self, repo, "HEAD", self._lockfiles)
109
113
self._transport.fetch_pack(determine_wants, graph_walker, pack_data,
116
def fetch_objects(self, determine_wants, graph_walker, progress=None):
117
fd, path = tempfile.mkstemp(suffix=".pack")
118
self.fetch_pack(determine_wants, graph_walker, lambda x: os.write(fd, x), progress)
121
basename = path[:-len(".pack")]
123
p.create_index_v2(basename+".idx")
124
for o in Pack(basename).iterobjects():
113
130
class RemoteGitBranch(GitBranch):
115
132
def __init__(self, bzrdir, repository, name, lockfiles):
116
133
def determine_wants(heads):
134
if not name in heads:
135
raise NoSuchRef(name)
117
136
self._ref = heads[name]
118
137
bzrdir.root_transport.fetch_pack(determine_wants, None, lambda x: None,
119
138
lambda x: mutter("git: %s" % x))
122
141
def last_revision(self):
123
142
return self.mapping.revision_id_foreign_to_bzr(self._ref)
144
def _synchronize_history(self, destination, revision_id):
145
"""See Branch._synchronize_history()."""
146
destination.generate_revision_history(self.last_revision())