23
23
from bzrlib.trace import info
24
24
from bzrlib.transport import Transport
26
from bzrlib.plugins.git import git
26
27
from bzrlib.plugins.git.branch import GitBranch
27
from bzrlib.plugins.git.errors import NoSuchRef
28
28
from bzrlib.plugins.git.dir import GitDir
29
29
from bzrlib.plugins.git.foreign import ForeignBranch
30
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)
102
98
def open_workingtree(self):
103
99
raise NotLocalUrl(self.transport.base)
101
def cloning_metadir(self, stacked=False):
102
"""Produce a metadir suitable for cloning with."""
104
return bzrlib.bzrdir.format_registry.make_bzrdir("1.6.1-rich-root")
106
return bzrlib.bzrdir.format_registry.make_bzrdir("rich-root-pack")
106
109
class RemoteGitRepository(GitRepository):
108
111
def __init__(self, gitdir, lockfiles):
109
112
GitRepository.__init__(self, gitdir, lockfiles)
111
def fetch_pack(self, determine_wants, graph_walker, pack_data,
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)
120
basename = path[:-len(".pack")]
122
p.create_index_v2(basename+".idx")
123
pack = Pack(basename)
125
return (len(p), pack.iterobjects())
114
def fetch_pack(self, determine_wants, graph_walker, pack_data, progress=None):
115
self._transport.fetch_pack(determine_wants, graph_walker, pack_data, progress)
128
118
class RemoteGitBranch(GitBranch):
130
120
def __init__(self, bzrdir, repository, name, lockfiles):
131
121
def determine_wants(heads):
132
if not name in heads:
133
raise NoSuchRef(name)
134
122
self._ref = heads[name]
135
123
bzrdir.root_transport.fetch_pack(determine_wants, None, lambda x: None,
136
124
lambda x: mutter("git: %s" % x))
139
127
def last_revision(self):
140
128
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())