bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
0.200.252
by Jelmer Vernooij
Clarify history, copyright. |
1 |
# Copyright (C) 2007-2009 Jelmer Vernooij <jelmer@samba.org>
|
|
0.200.138
by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories. |
2 |
#
|
3 |
# This program is free software; you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
7 |
#
|
|
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
||
|
0.200.139
by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches. |
17 |
import bzrlib |
|
0.200.289
by Jelmer Vernooij
Cope with new member variables in RepositoryFormat. |
18 |
from bzrlib import ( |
19 |
branch, |
|
20 |
tag, |
|
21 |
urlutils, |
|
22 |
)
|
|
23 |
from bzrlib.bzrdir import ( |
|
24 |
BzrDir, |
|
25 |
BzrDirFormat, |
|
26 |
)
|
|
27 |
from bzrlib.errors import ( |
|
28 |
BzrError, |
|
29 |
NoSuchFile, |
|
30 |
NotLocalUrl, |
|
31 |
)
|
|
|
0.200.292
by Jelmer Vernooij
Fix formatting. |
32 |
from bzrlib.lockable_files import ( |
33 |
TransportLock, |
|
34 |
)
|
|
35 |
from bzrlib.repository import ( |
|
36 |
Repository, |
|
37 |
)
|
|
38 |
from bzrlib.trace import ( |
|
39 |
info, |
|
40 |
)
|
|
41 |
from bzrlib.transport import ( |
|
42 |
Transport, |
|
43 |
)
|
|
|
0.200.138
by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories. |
44 |
|
|
0.200.292
by Jelmer Vernooij
Fix formatting. |
45 |
from bzrlib.plugins.git import ( |
46 |
lazy_check_versions, |
|
47 |
)
|
|
|
0.200.200
by Jelmer Vernooij
Register lazily where possible. |
48 |
lazy_check_versions() |
49 |
||
|
0.200.292
by Jelmer Vernooij
Fix formatting. |
50 |
from bzrlib.plugins.git.branch import ( |
51 |
GitBranch, |
|
52 |
)
|
|
53 |
from bzrlib.plugins.git.errors import ( |
|
54 |
NoSuchRef, |
|
55 |
)
|
|
56 |
from bzrlib.plugins.git.dir import ( |
|
57 |
GitDir, |
|
58 |
)
|
|
59 |
from bzrlib.plugins.git.foreign import ( |
|
60 |
ForeignBranch, |
|
61 |
)
|
|
|
0.200.289
by Jelmer Vernooij
Cope with new member variables in RepositoryFormat. |
62 |
from bzrlib.plugins.git.repository import ( |
63 |
GitRepositoryFormat, |
|
64 |
GitRepository, |
|
65 |
)
|
|
|
0.200.138
by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories. |
66 |
|
|
0.200.289
by Jelmer Vernooij
Cope with new member variables in RepositoryFormat. |
67 |
import dulwich as git |
|
0.200.292
by Jelmer Vernooij
Fix formatting. |
68 |
from dulwich.errors import ( |
69 |
GitProtocolError, |
|
70 |
)
|
|
|
0.200.289
by Jelmer Vernooij
Cope with new member variables in RepositoryFormat. |
71 |
from dulwich.pack import ( |
72 |
Pack, |
|
73 |
PackData, |
|
74 |
)
|
|
|
0.200.167
by Jelmer Vernooij
Implement fetch_objects properly. |
75 |
import os |
76 |
import tempfile |
|
|
0.200.138
by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories. |
77 |
import urllib |
78 |
import urlparse |
|
79 |
||
|
0.200.306
by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository. |
80 |
try: |
81 |
from dulwich.pack import load_pack_index |
|
82 |
except ImportError: |
|
83 |
from dulwich.pack import PackIndex as load_pack_index |
|
84 |
||
|
0.200.143
by Jelmer Vernooij
Reoncile InterGitRepository objects. |
85 |
|
|
0.200.181
by Jelmer Vernooij
Support setting tags. |
86 |
# Don't run any tests on GitSmartTransport as it is not intended to be
|
87 |
# a full implementation of Transport
|
|
88 |
def get_test_permutations(): |
|
89 |
return [] |
|
90 |
||
|
0.200.138
by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories. |
91 |
|
92 |
class GitSmartTransport(Transport): |
|
93 |
||
|
0.200.139
by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches. |
94 |
def __init__(self, url, _client=None): |
|
0.200.138
by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories. |
95 |
Transport.__init__(self, url) |
|
0.200.139
by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches. |
96 |
(scheme, _, loc, _, _) = urlparse.urlsplit(url) |
97 |
hostport, self._path = urllib.splithost(loc) |
|
98 |
(self._host, self._port) = urllib.splitnport(hostport, git.protocol.TCP_GIT_PORT) |
|
|
0.200.166
by Jelmer Vernooij
don't reuse client objects. |
99 |
self._client = _client |
100 |
||
|
0.200.238
by Jelmer Vernooij
Import Transport.has(). |
101 |
def has(self, relpath): |
102 |
return False |
|
103 |
||
|
0.200.166
by Jelmer Vernooij
don't reuse client objects. |
104 |
def _get_client(self): |
|
0.200.307
by Jelmer Vernooij
Support git+ssh. |
105 |
raise NotImplementedError(self._get_client) |
|
0.200.138
by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories. |
106 |
|
|
0.200.139
by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches. |
107 |
def fetch_pack(self, determine_wants, graph_walker, pack_data, progress=None): |
108 |
if progress is None: |
|
109 |
def progress(text): |
|
110 |
info("git: %s" % text) |
|
|
0.200.240
by Jelmer Vernooij
Wrap socket errors. |
111 |
client = self._get_client() |
112 |
try: |
|
113 |
client.fetch_pack(self._path, determine_wants, |
|
114 |
graph_walker, pack_data, progress) |
|
115 |
except GitProtocolError, e: |
|
116 |
raise BzrError(e) |
|
|
0.200.138
by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories. |
117 |
|
|
0.200.139
by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches. |
118 |
def get(self, path): |
119 |
raise NoSuchFile(path) |
|
120 |
||
|
0.200.160
by Jelmer Vernooij
Implement abspath. |
121 |
def abspath(self, relpath): |
122 |
return urlutils.join(self.base, relpath) |
|
123 |
||
|
0.200.139
by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches. |
124 |
def clone(self, offset=None): |
125 |
"""See Transport.clone().""" |
|
126 |
if offset is None: |
|
127 |
newurl = self.base |
|
128 |
else: |
|
129 |
newurl = urlutils.join(self.base, offset) |
|
130 |
||
|
0.200.307
by Jelmer Vernooij
Support git+ssh. |
131 |
return self.__class__(newurl, self._client) |
132 |
||
133 |
||
134 |
class TCPGitSmartTransport(GitSmartTransport): |
|
135 |
||
136 |
def _get_client(self): |
|
137 |
if self._client is not None: |
|
138 |
ret = self._client |
|
139 |
self._client = None |
|
140 |
return ret |
|
141 |
return git.client.TCPGitClient(self._host, self._port, thin_packs=False) |
|
142 |
||
143 |
||
144 |
class SSHGitSmartTransport(GitSmartTransport): |
|
145 |
||
146 |
def _get_client(self): |
|
147 |
if self._client is not None: |
|
148 |
ret = self._client |
|
149 |
self._client = None |
|
150 |
return ret |
|
|
0.200.308
by Jelmer Vernooij
Register git protocols. |
151 |
return git.client.SSHGitClient(self._host, self._port, thin_packs=False) |
|
0.200.139
by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches. |
152 |
|
|
0.200.138
by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories. |
153 |
|
|
0.200.148
by Jelmer Vernooij
Share more infrastructure between LocalGitDir and RemoteGitDir. |
154 |
class RemoteGitDir(GitDir): |
|
0.200.138
by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories. |
155 |
|
|
0.200.139
by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches. |
156 |
def __init__(self, transport, lockfiles, format): |
|
0.200.138
by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories. |
157 |
self._format = format |
158 |
self.root_transport = transport |
|
159 |
self.transport = transport |
|
160 |
self._lockfiles = lockfiles |
|
161 |
||
162 |
def open_repository(self): |
|
163 |
return RemoteGitRepository(self, self._lockfiles) |
|
164 |
||
|
0.200.174
by Jelmer Vernooij
Merge John. |
165 |
def open_branch(self, _unsupported=False): |
|
0.200.138
by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories. |
166 |
repo = self.open_repository() |
167 |
# TODO: Support for multiple branches in one bzrdir in bzrlib!
|
|
|
0.200.139
by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches. |
168 |
return RemoteGitBranch(self, repo, "HEAD", self._lockfiles) |
|
0.200.138
by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories. |
169 |
|
170 |
def open_workingtree(self): |
|
171 |
raise NotLocalUrl(self.transport.base) |
|
172 |
||
|
0.200.139
by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches. |
173 |
|
|
0.225.2
by Jelmer Vernooij
Handle situation when repository is already up to date during pull. |
174 |
class EmptyObjectStoreIterator(dict): |
175 |
||
176 |
def iterobjects(self): |
|
177 |
return [] |
|
178 |
||
179 |
||
|
0.200.218
by Jelmer Vernooij
Simplify TemporaryPack implementation. |
180 |
class TemporaryPackIterator(Pack): |
181 |
||
|
0.200.226
by Jelmer Vernooij
Merge thin-pack work. |
182 |
def __init__(self, path, resolve_ext_ref): |
183 |
self.resolve_ext_ref = resolve_ext_ref |
|
184 |
super(TemporaryPackIterator, self).__init__(path) |
|
185 |
||
|
0.200.218
by Jelmer Vernooij
Simplify TemporaryPack implementation. |
186 |
@property
|
187 |
def idx(self): |
|
188 |
if self._idx is None: |
|
|
0.200.302
by Jelmer Vernooij
Fix index creation when fetching from remote host. |
189 |
if self._data is None: |
190 |
self._data = PackData(self._data_path) |
|
|
0.200.226
by Jelmer Vernooij
Merge thin-pack work. |
191 |
self._data.create_index_v2(self._idx_path, self.resolve_ext_ref) |
|
0.200.306
by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository. |
192 |
self._idx = load_pack_index(self._idx_path) |
|
0.200.218
by Jelmer Vernooij
Simplify TemporaryPack implementation. |
193 |
return self._idx |
|
0.200.205
by Jelmer Vernooij
Fix remote fetching. |
194 |
|
195 |
def __del__(self): |
|
|
0.200.218
by Jelmer Vernooij
Simplify TemporaryPack implementation. |
196 |
os.remove(self._data_path) |
197 |
os.remove(self._idx_path) |
|
|
0.200.205
by Jelmer Vernooij
Fix remote fetching. |
198 |
|
199 |
||
|
0.200.139
by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches. |
200 |
class RemoteGitRepository(GitRepository): |
|
0.200.138
by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories. |
201 |
|
202 |
def __init__(self, gitdir, lockfiles): |
|
|
0.200.139
by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches. |
203 |
GitRepository.__init__(self, gitdir, lockfiles) |
|
0.228.3
by Jelmer Vernooij
Fix tags when fetching from remotes. |
204 |
self._refs = None |
205 |
||
206 |
def get_refs(self): |
|
207 |
if self._refs is not None: |
|
208 |
return self._refs |
|
209 |
def determine_wants(heads): |
|
210 |
self._refs = heads |
|
211 |
return [] |
|
212 |
self.bzrdir.root_transport.fetch_pack(determine_wants, None, |
|
213 |
lambda x: None, lambda x: mutter("git: %s" % x)) |
|
214 |
return self._refs |
|
|
0.200.138
by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories. |
215 |
|
|
0.200.155
by Jelmer Vernooij
Fix formatting, remove catch-all for exceptions when opening local repositories. |
216 |
def fetch_pack(self, determine_wants, graph_walker, pack_data, |
217 |
progress=None): |
|
218 |
self._transport.fetch_pack(determine_wants, graph_walker, pack_data, |
|
219 |
progress) |
|
|
0.200.138
by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories. |
220 |
|
|
0.200.226
by Jelmer Vernooij
Merge thin-pack work. |
221 |
def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref, progress=None): |
|
0.200.167
by Jelmer Vernooij
Implement fetch_objects properly. |
222 |
fd, path = tempfile.mkstemp(suffix=".pack") |
223 |
self.fetch_pack(determine_wants, graph_walker, lambda x: os.write(fd, x), progress) |
|
224 |
os.close(fd) |
|
|
0.200.226
by Jelmer Vernooij
Merge thin-pack work. |
225 |
if os.path.getsize(path) == 0: |
|
0.225.2
by Jelmer Vernooij
Handle situation when repository is already up to date during pull. |
226 |
return EmptyObjectStoreIterator() |
|
0.200.226
by Jelmer Vernooij
Merge thin-pack work. |
227 |
return TemporaryPackIterator(path[:-len(".pack")], resolve_ext_ref) |
|
0.200.167
by Jelmer Vernooij
Implement fetch_objects properly. |
228 |
|
|
0.200.138
by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories. |
229 |
|
|
0.228.3
by Jelmer Vernooij
Fix tags when fetching from remotes. |
230 |
class RemoteGitTagDict(tag.BasicTags): |
231 |
||
232 |
def __init__(self, branch): |
|
233 |
self.branch = branch |
|
234 |
self.repository = branch.repository |
|
235 |
||
236 |
def get_tag_dict(self): |
|
237 |
ret = {} |
|
238 |
refs = self.repository.get_refs() |
|
239 |
for k,v in refs.iteritems(): |
|
240 |
if k.startswith("refs/tags/") and not k.endswith("^{}"): |
|
241 |
v = refs.get(k+"^{}", v) |
|
|
0.228.4
by Jelmer Vernooij
Strip ref directory name from tag names. |
242 |
ret[k[len("refs/tags/"):]] = self.branch.mapping.revision_id_foreign_to_bzr(v) |
|
0.228.3
by Jelmer Vernooij
Fix tags when fetching from remotes. |
243 |
return ret |
244 |
||
245 |
def set_tag(self, name, revid): |
|
246 |
# FIXME: Not supported yet, should do a push of a new ref
|
|
247 |
raise NotImplementedError(self.set_tag) |
|
248 |
||
249 |
||
|
0.200.139
by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches. |
250 |
class RemoteGitBranch(GitBranch): |
251 |
||
252 |
def __init__(self, bzrdir, repository, name, lockfiles): |
|
|
0.228.3
by Jelmer Vernooij
Fix tags when fetching from remotes. |
253 |
heads = repository.get_refs() |
254 |
if not name in heads: |
|
255 |
raise NoSuchRef(name) |
|
256 |
self._ref = heads[name] |
|
|
0.200.139
by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches. |
257 |
super(RemoteGitBranch, self).__init__(bzrdir, repository, name, self._ref, lockfiles) |
258 |
||
259 |
def last_revision(self): |
|
|
0.200.140
by Jelmer Vernooij
Support negotiating with remote git repository and receiving pack. |
260 |
return self.mapping.revision_id_foreign_to_bzr(self._ref) |
|
0.200.141
by Jelmer Vernooij
Separate out local and remote fetching. |
261 |
|
|
0.200.169
by Jelmer Vernooij
Fix branch cloning. |
262 |
def _synchronize_history(self, destination, revision_id): |
263 |
"""See Branch._synchronize_history().""" |
|
264 |
destination.generate_revision_history(self.last_revision()) |
|
265 |