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
29
28
from bzrlib.plugins.git.dir import GitDir
30
29
from bzrlib.plugins.git.foreign import ForeignBranch
31
30
from bzrlib.plugins.git.repository import GitFormat, GitRepository
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():
35
from dulwich.pack import PackData
46
38
class GitSmartTransport(Transport):
51
43
assert scheme == "git"
52
44
hostport, self._path = urllib.splithost(loc)
53
45
(self._host, self._port) = urllib.splitnport(hostport, git.protocol.TCP_GIT_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)
46
if _client is not None:
47
self._client = _client
49
self._client = git.client.TCPGitClient(self._host, self._port)
63
51
def fetch_pack(self, determine_wants, graph_walker, pack_data, progress=None):
64
52
if progress is None:
65
53
def progress(text):
66
54
info("git: %s" % text)
67
self._get_client().fetch_pack(self._path, determine_wants,
68
graph_walker, pack_data, progress)
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():
70
69
def get(self, path):
71
70
raise NoSuchFile(path)
73
def abspath(self, relpath):
74
return urlutils.join(self.base, relpath)
76
72
def clone(self, offset=None):
77
73
"""See Transport.clone()."""
94
90
def open_repository(self):
95
91
return RemoteGitRepository(self, self._lockfiles)
97
def open_branch(self, _unsupported=False):
93
def open_branch(self):
98
94
repo = self.open_repository()
99
95
# TODO: Support for multiple branches in one bzrdir in bzrlib!
100
96
return RemoteGitBranch(self, repo, "HEAD", self._lockfiles)
113
109
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)
120
basename = path[:-len(".pack")]
122
p.create_index_v2(basename+".idx")
123
pack = Pack(basename)
125
return (len(p), pack.iterobjects())
128
113
class RemoteGitBranch(GitBranch):
130
115
def __init__(self, bzrdir, repository, name, lockfiles):
131
116
def determine_wants(heads):
132
if not name in heads:
133
raise NoSuchRef(name)
134
117
self._ref = heads[name]
135
118
bzrdir.root_transport.fetch_pack(determine_wants, None, lambda x: None,
136
119
lambda x: mutter("git: %s" % x))
139
122
def last_revision(self):
140
123
return self.mapping.revision_id_foreign_to_bzr(self._ref)
142
def _synchronize_history(self, destination, revision_id):
143
"""See Branch._synchronize_history()."""
144
destination.generate_revision_history(self.last_revision())