/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.200.1014 by Jelmer Vernooij
Fix tests.
1
# Copyright (C) 2007-2010 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.289 by Jelmer Vernooij
Cope with new member variables in RepositoryFormat.
17
from bzrlib import (
0.200.596 by Jelmer Vernooij
Import RemoteGitBranch._get_config().
18
    config,
0.200.707 by Jelmer Vernooij
Add debug routines.
19
    debug,
0.200.586 by Jelmer Vernooij
Fix issues pointed out by pyflakes.
20
    trace,
0.200.333 by Jelmer Vernooij
Support progress reporting when creating index.
21
    ui,
0.200.289 by Jelmer Vernooij
Cope with new member variables in RepositoryFormat.
22
    urlutils,
0.200.1464 by Jelmer Vernooij
Warn about ignoring path segment parameters when using bzr 2.4.
23
    version_info as bzrlib_version,
0.200.289 by Jelmer Vernooij
Cope with new member variables in RepositoryFormat.
24
    )
25
from bzrlib.errors import (
26
    BzrError,
0.200.1412 by Jelmer Vernooij
Implement GitControlDirFormat.supports_transport.
27
    InProcessTransport,
0.200.415 by Jelmer Vernooij
make 'bzr pull --revision' work for remote repositories.
28
    InvalidRevisionId,
0.200.289 by Jelmer Vernooij
Cope with new member variables in RepositoryFormat.
29
    NoSuchFile,
0.200.415 by Jelmer Vernooij
make 'bzr pull --revision' work for remote repositories.
30
    NoSuchRevision,
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
31
    NotBranchError,
0.200.289 by Jelmer Vernooij
Cope with new member variables in RepositoryFormat.
32
    NotLocalUrl,
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
33
    UninitializableFormat,
0.200.289 by Jelmer Vernooij
Cope with new member variables in RepositoryFormat.
34
    )
0.200.292 by Jelmer Vernooij
Fix formatting.
35
from bzrlib.transport import (
36
    Transport,
37
    )
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
38
0.200.292 by Jelmer Vernooij
Fix formatting.
39
from bzrlib.plugins.git import (
40
    lazy_check_versions,
41
    )
0.200.200 by Jelmer Vernooij
Register lazily where possible.
42
lazy_check_versions()
43
0.200.292 by Jelmer Vernooij
Fix formatting.
44
from bzrlib.plugins.git.branch import (
45
    GitBranch,
0.200.1064 by Jelmer Vernooij
Use common base class for tags.
46
    GitTags,
0.200.292 by Jelmer Vernooij
Fix formatting.
47
    )
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
48
from bzrlib.plugins.git.dir import (
49
    GitControlDirFormat,
50
    GitDir,
51
    )
0.200.292 by Jelmer Vernooij
Fix formatting.
52
from bzrlib.plugins.git.errors import (
0.200.319 by Jelmer Vernooij
Print proper error when trying unsupported operations against a git server.
53
    GitSmartRemoteNotSupported,
0.200.292 by Jelmer Vernooij
Fix formatting.
54
    NoSuchRef,
55
    )
0.200.415 by Jelmer Vernooij
make 'bzr pull --revision' work for remote repositories.
56
from bzrlib.plugins.git.mapping import (
57
    mapping_registry,
58
    )
0.200.289 by Jelmer Vernooij
Cope with new member variables in RepositoryFormat.
59
from bzrlib.plugins.git.repository import (
60
    GitRepository,
61
    )
0.200.872 by Jelmer Vernooij
Move refs code to separate module.
62
from bzrlib.plugins.git.refs import (
63
    branch_name_to_ref,
0.200.1487 by Jelmer Vernooij
Use peeling.
64
    is_peeled,
0.200.872 by Jelmer Vernooij
Move refs code to separate module.
65
    )
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
66
0.200.1336 by Jelmer Vernooij
Support the git smart server http protocol.
67
import dulwich
68
import dulwich.client
0.200.292 by Jelmer Vernooij
Fix formatting.
69
from dulwich.errors import (
70
    GitProtocolError,
71
    )
0.200.289 by Jelmer Vernooij
Cope with new member variables in RepositoryFormat.
72
from dulwich.pack import (
73
    Pack,
0.200.1298 by Jelmer Vernooij
Fix compatibility with newer versions of dulwich.
74
    PackData,
0.200.289 by Jelmer Vernooij
Cope with new member variables in RepositoryFormat.
75
    )
0.200.1487 by Jelmer Vernooij
Use peeling.
76
from dulwich.repo import DictRefsContainer
0.200.167 by Jelmer Vernooij
Implement fetch_objects properly.
77
import os
78
import tempfile
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
79
import urllib
80
import urlparse
0.200.741 by Jelmer Vernooij
Cope with older versions of Python by adding git and git+ssh to the list of known schemes.
81
urlparse.uses_netloc.extend(['git', 'git+ssh'])
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
82
0.200.586 by Jelmer Vernooij
Fix issues pointed out by pyflakes.
83
from dulwich.pack import load_pack_index
0.200.306 by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository.
84
0.200.143 by Jelmer Vernooij
Reoncile InterGitRepository objects.
85
0.200.695 by Jelmer Vernooij
Clean up trailing whitespace.
86
# Don't run any tests on GitSmartTransport as it is not intended to be
0.200.181 by Jelmer Vernooij
Support setting tags.
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
0.200.708 by Jelmer Vernooij
Factor out URL parsing.
92
def split_git_url(url):
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
93
    """Split a Git URL.
94
95
    :param url: Git URL
96
    :return: Tuple with host, port, username, path.
97
    """
0.200.743 by Jelmer Vernooij
Fix URL parsing.
98
    (scheme, netloc, loc, _, _) = urlparse.urlsplit(url)
99
    path = urllib.unquote(loc)
0.246.2 by Jelmer Vernooij
Improve the fix dealing with git repo's in home directories.
100
    if path.startswith("/~"):
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
101
        path = path[1:]
0.200.743 by Jelmer Vernooij
Fix URL parsing.
102
    (username, hostport) = urllib.splituser(netloc)
0.200.708 by Jelmer Vernooij
Factor out URL parsing.
103
    (host, port) = urllib.splitnport(hostport, None)
104
    return (host, port, username, path)
105
106
0.200.1275 by Jelmer Vernooij
recognize missing repositories
107
def parse_git_error(url, message):
108
    """Parse a remote git server error and return a bzr exception.
109
110
    :param url: URL of the remote repository
111
    :param message: Message sent by the remote git server
112
    """
113
    message = str(message).strip()
114
    if message.startswith("Could not find Repository "):
115
        return NotBranchError(url, message)
116
    # Don't know, just return it to the user as-is
117
    return BzrError(message)
118
119
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
120
class GitSmartTransport(Transport):
121
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
122
    def __init__(self, url, _client=None):
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
123
        Transport.__init__(self, url)
0.200.708 by Jelmer Vernooij
Factor out URL parsing.
124
        (self._host, self._port, self._username, self._path) = \
125
            split_git_url(url)
0.200.707 by Jelmer Vernooij
Add debug routines.
126
        if 'transport' in debug.debug_flags:
127
            trace.mutter('host: %r, user: %r, port: %r, path: %r',
128
                         self._host, self._username, self._port, self._path)
0.200.166 by Jelmer Vernooij
don't reuse client objects.
129
        self._client = _client
0.200.1464 by Jelmer Vernooij
Warn about ignoring path segment parameters when using bzr 2.4.
130
        if "," in self._path and bzrlib_version < (2, 5, 0):
131
            trace.warning(
132
                "ignoring parameters %r, not supported in bzr < 2.5.",
133
                self._path.rsplit(",", 1)[1])
134
        self._stripped_path = self._path.rsplit(",", 1)[0]
0.200.166 by Jelmer Vernooij
don't reuse client objects.
135
0.200.543 by Jelmer Vernooij
Implement GitSmartTransport.external_url().
136
    def external_url(self):
137
        return self.base
138
0.200.238 by Jelmer Vernooij
Import Transport.has().
139
    def has(self, relpath):
140
        return False
141
0.200.567 by Jelmer Vernooij
Pass along thin pack settings.
142
    def _get_client(self, thin_packs):
0.200.307 by Jelmer Vernooij
Support git+ssh.
143
        raise NotImplementedError(self._get_client)
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
144
0.200.470 by Jelmer Vernooij
Properly parse username in URLs.
145
    def _get_path(self):
0.200.1464 by Jelmer Vernooij
Warn about ignoring path segment parameters when using bzr 2.4.
146
        return self._stripped_path
0.200.470 by Jelmer Vernooij
Properly parse username in URLs.
147
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
148
    def get(self, path):
149
        raise NoSuchFile(path)
150
0.200.160 by Jelmer Vernooij
Implement abspath.
151
    def abspath(self, relpath):
152
        return urlutils.join(self.base, relpath)
153
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
154
    def clone(self, offset=None):
155
        """See Transport.clone()."""
156
        if offset is None:
157
            newurl = self.base
158
        else:
159
            newurl = urlutils.join(self.base, offset)
160
0.200.307 by Jelmer Vernooij
Support git+ssh.
161
        return self.__class__(newurl, self._client)
162
163
164
class TCPGitSmartTransport(GitSmartTransport):
165
0.200.332 by Jelmer Vernooij
Support activity reporting.
166
    _scheme = 'git'
167
0.200.567 by Jelmer Vernooij
Pass along thin pack settings.
168
    def _get_client(self, thin_packs):
0.200.307 by Jelmer Vernooij
Support git+ssh.
169
        if self._client is not None:
170
            ret = self._client
171
            self._client = None
172
            return ret
0.200.1336 by Jelmer Vernooij
Support the git smart server http protocol.
173
        return dulwich.client.TCPGitClient(self._host, self._port,
0.200.859 by Jelmer Vernooij
Trivial cleanups.
174
            thin_packs=thin_packs, report_activity=self._report_activity)
0.200.307 by Jelmer Vernooij
Support git+ssh.
175
176
177
class SSHGitSmartTransport(GitSmartTransport):
178
0.200.332 by Jelmer Vernooij
Support activity reporting.
179
    _scheme = 'git+ssh'
180
0.200.470 by Jelmer Vernooij
Properly parse username in URLs.
181
    def _get_path(self):
0.200.1464 by Jelmer Vernooij
Warn about ignoring path segment parameters when using bzr 2.4.
182
        path = self._stripped_path
0.200.1318 by Jelmer Vernooij
Strip segment parameters where necessary.
183
        if path.startswith("/~/"):
184
            return path[3:]
185
        return path
0.200.470 by Jelmer Vernooij
Properly parse username in URLs.
186
0.200.567 by Jelmer Vernooij
Pass along thin pack settings.
187
    def _get_client(self, thin_packs):
0.200.307 by Jelmer Vernooij
Support git+ssh.
188
        if self._client is not None:
189
            ret = self._client
190
            self._client = None
191
            return ret
0.253.1 by Ross Light
Added configuration options for git-upload-pack and git-receive-pack
192
        location_config = config.LocationConfig(self.base)
0.200.1336 by Jelmer Vernooij
Support the git smart server http protocol.
193
        client = dulwich.client.SSHGitClient(self._host, self._port, self._username,
0.200.567 by Jelmer Vernooij
Pass along thin pack settings.
194
            thin_packs=thin_packs, report_activity=self._report_activity)
0.253.1 by Ross Light
Added configuration options for git-upload-pack and git-receive-pack
195
        # Set up alternate pack program paths
196
        upload_pack = location_config.get_user_option('git_upload_pack')
197
        if upload_pack:
0.200.949 by Jelmer Vernooij
merge support for specifying alternative paths for git executables.
198
            client.alternative_paths["upload-pack"] = upload_pack
0.253.1 by Ross Light
Added configuration options for git-upload-pack and git-receive-pack
199
        receive_pack = location_config.get_user_option('git_receive_pack')
200
        if receive_pack:
0.200.949 by Jelmer Vernooij
merge support for specifying alternative paths for git executables.
201
            client.alternative_paths["receive-pack"] = receive_pack
0.253.1 by Ross Light
Added configuration options for git-upload-pack and git-receive-pack
202
        return client
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
203
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
204
0.200.148 by Jelmer Vernooij
Share more infrastructure between LocalGitDir and RemoteGitDir.
205
class RemoteGitDir(GitDir):
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
206
0.200.1411 by Jelmer Vernooij
Fix control files.
207
    def __init__(self, transport, format, get_client, client_path):
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
208
        self._format = format
209
        self.root_transport = transport
210
        self.transport = transport
0.200.381 by Jelmer Vernooij
Support working trees properly, status and ls.
211
        self._mode_check_done = None
0.200.1335 by Jelmer Vernooij
Move _get_client.
212
        self._get_client = get_client
0.200.1336 by Jelmer Vernooij
Support the git smart server http protocol.
213
        self._client_path = client_path
0.200.1396 by Jelmer Vernooij
Support updating tags in remote branches during pull.
214
        self.base = self.root_transport.base
0.200.1434 by Jelmer Vernooij
Move refs access to control dir.
215
        self._refs = None
0.200.1335 by Jelmer Vernooij
Move _get_client.
216
217
    def fetch_pack(self, determine_wants, graph_walker, pack_data, progress=None):
218
        if progress is None:
219
            def progress(text):
220
                trace.info("git: %s" % text)
221
        client = self._get_client(thin_packs=False)
222
        try:
0.200.1487 by Jelmer Vernooij
Use peeling.
223
            refs_dict = client.fetch_pack(self._client_path, determine_wants,
0.200.1335 by Jelmer Vernooij
Move _get_client.
224
                graph_walker, pack_data, progress)
0.200.1487 by Jelmer Vernooij
Use peeling.
225
            self._refs_dict(refs_dict)
226
            return refs_dict
0.200.1335 by Jelmer Vernooij
Move _get_client.
227
        except GitProtocolError, e:
228
            raise parse_git_error(self.transport.external_url(), e)
229
230
    def send_pack(self, get_changed_refs, generate_pack_contents):
231
        client = self._get_client(thin_packs=False)
232
        try:
0.200.1336 by Jelmer Vernooij
Support the git smart server http protocol.
233
            return client.send_pack(self._client_path, get_changed_refs,
0.200.1335 by Jelmer Vernooij
Move _get_client.
234
                generate_pack_contents)
235
        except GitProtocolError, e:
236
            raise parse_git_error(self.transport.external_url(), e)
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
237
0.200.1393 by Jelmer Vernooij
Implement removal of remote branches.
238
    def destroy_branch(self, name=None):
239
        refname = self._get_selected_ref(name)
240
        if refname is None:
241
            refname = "HEAD"
242
        def get_changed_refs(old_refs):
243
            ret = dict(old_refs)
244
            if not refname in ret:
0.200.1395 by Jelmer Vernooij
Fix error reporting.
245
                raise NotBranchError(self.user_url)
0.200.1393 by Jelmer Vernooij
Implement removal of remote branches.
246
            ret[refname] = "00" * 20
247
            return ret
248
        self.send_pack(get_changed_refs, lambda have, want: [])
249
0.200.1068 by Jelmer Vernooij
Implement user_url/control_url.
250
    @property
251
    def user_url(self):
252
        return self.control_url
253
0.200.1314 by Jelmer Vernooij
Provide RemoteGitDir.user_transport.
254
    @property
255
    def user_transport(self):
256
        return self.root_transport
257
0.200.1395 by Jelmer Vernooij
Fix error reporting.
258
    @property
259
    def control_url(self):
260
        return self.control_transport.base
261
262
    @property
263
    def control_transport(self):
264
        return self.root_transport
265
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
266
    def open_repository(self):
0.200.1415 by Jelmer Vernooij
Fix lock files for remote directories.
267
        return RemoteGitRepository(self)
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
268
0.200.1310 by Jelmer Vernooij
Add _get_selected_ref method.
269
    def open_branch(self, name=None, unsupported=False,
0.200.1473 by Jelmer Vernooij
Support possible_transports argument to .open_branch.
270
            ignore_fallbacks=False, ref=None, possible_transports=None):
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
271
        repo = self.open_repository()
0.269.8 by Jelmer Vernooij
Support push in git-remote-bzr.
272
        refname = self._get_selected_ref(name, ref)
0.200.1415 by Jelmer Vernooij
Fix lock files for remote directories.
273
        return RemoteGitBranch(self, repo, refname)
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
274
0.200.662 by Jelmer Vernooij
Deal with recommend_upgrade argument to open_workingtree.
275
    def open_workingtree(self, recommend_upgrade=False):
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
276
        raise NotLocalUrl(self.transport.base)
277
0.200.1487 by Jelmer Vernooij
Use peeling.
278
    def _set_refs(self, refs_dict):
279
        base = {}
280
        peeled = {}
281
        for k, v in refs_dict.iteritems():
282
            if is_peeled(k):
283
                peeled[k[:-3]] = v
284
            else:
285
                base[k] = v
286
                peeled[k] = v
287
        self._refs = DictRefsContainer(base)
288
        self._refs._peeled = peeled
289
290
    def get_refs_container(self):
0.200.1434 by Jelmer Vernooij
Move refs access to control dir.
291
        if self._refs is not None:
292
            return self._refs
0.200.1487 by Jelmer Vernooij
Use peeling.
293
        refs_dict = self.fetch_pack(lambda x: [], None,
0.200.1434 by Jelmer Vernooij
Move refs access to control dir.
294
            lambda x: None, lambda x: trace.mutter("git: %s" % x))
0.200.1487 by Jelmer Vernooij
Use peeling.
295
        self._set_refs(refs_dict)
0.200.1434 by Jelmer Vernooij
Move refs access to control dir.
296
        return self._refs
297
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
298
0.225.2 by Jelmer Vernooij
Handle situation when repository is already up to date during pull.
299
class EmptyObjectStoreIterator(dict):
300
301
    def iterobjects(self):
302
        return []
303
304
0.200.218 by Jelmer Vernooij
Simplify TemporaryPack implementation.
305
class TemporaryPackIterator(Pack):
306
0.200.226 by Jelmer Vernooij
Merge thin-pack work.
307
    def __init__(self, path, resolve_ext_ref):
0.200.310 by Jelmer Vernooij
Fix pull from remote branches.
308
        super(TemporaryPackIterator, self).__init__(path)
0.200.226 by Jelmer Vernooij
Merge thin-pack work.
309
        self.resolve_ext_ref = resolve_ext_ref
310
0.200.218 by Jelmer Vernooij
Simplify TemporaryPack implementation.
311
    @property
0.200.604 by Jelmer Vernooij
Fix fetching of remote repositories on Windows.
312
    def data(self):
313
        if self._data is None:
0.200.1298 by Jelmer Vernooij
Fix compatibility with newer versions of dulwich.
314
            self._data = PackData(self._data_path)
0.200.604 by Jelmer Vernooij
Fix fetching of remote repositories on Windows.
315
        return self._data
316
317
    @property
0.200.458 by Jelmer Vernooij
Fix index.
318
    def index(self):
0.200.218 by Jelmer Vernooij
Simplify TemporaryPack implementation.
319
        if self._idx is None:
0.200.562 by Jelmer Vernooij
Only create pack index if it doesn't exist yet.
320
            if not os.path.exists(self._idx_path):
321
                pb = ui.ui_factory.nested_progress_bar()
322
                try:
323
                    def report_progress(cur, total):
324
                        pb.update("generating index", cur, total)
0.200.900 by Jelmer Vernooij
Fix compatibility with newer versions of Dulwich.
325
                    self.data.create_index(self._idx_path, 
0.200.562 by Jelmer Vernooij
Only create pack index if it doesn't exist yet.
326
                        progress=report_progress)
327
                finally:
328
                    pb.finished()
0.200.306 by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository.
329
            self._idx = load_pack_index(self._idx_path)
0.200.218 by Jelmer Vernooij
Simplify TemporaryPack implementation.
330
        return self._idx
0.200.205 by Jelmer Vernooij
Fix remote fetching.
331
332
    def __del__(self):
0.200.611 by Jelmer Vernooij
Merge warning fix from Naoki.
333
        if self._idx is not None:
0.241.1 by Naoki INADA
Fix can't delete tempfile on Windows
334
            self._idx.close()
335
            os.remove(self._idx_path)
0.200.611 by Jelmer Vernooij
Merge warning fix from Naoki.
336
        if self._data is not None:
0.241.1 by Naoki INADA
Fix can't delete tempfile on Windows
337
            self._data.close()
338
            os.remove(self._data_path)
0.200.205 by Jelmer Vernooij
Fix remote fetching.
339
340
0.200.1337 by Jelmer Vernooij
Re-use http connection if possible.
341
class BzrGitHttpClient(dulwich.client.HttpGitClient):
342
343
    def __init__(self, transport, *args, **kwargs):
344
        self.transport = transport
345
        super(BzrGitHttpClient, self).__init__(transport.external_url(), *args, **kwargs)
346
        import urllib2
347
        self._http_perform = getattr(self.transport, "_perform", urllib2.urlopen)
348
349
    def _perform(self, req):
350
        req.accepted_errors = (200, 404)
351
        req.follow_redirections = True
352
        req.redirected_to = None
353
        return self._http_perform(req)
354
355
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
356
class RemoteGitControlDirFormat(GitControlDirFormat):
357
    """The .git directory control format."""
358
359
    supports_workingtrees = False
360
361
    @classmethod
362
    def _known_formats(self):
363
        return set([RemoteGitControlDirFormat()])
364
0.200.1413 by Jelmer Vernooij
Fix is_initializable()
365
    def is_initializable(self):
366
        return False
367
368
    def is_supported(self):
369
        return True
370
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
371
    def open(self, transport, _found=None):
372
        """Open this directory.
373
374
        """
375
        # we dont grok readonly - git isn't integrated with transport.
376
        url = transport.base
377
        if url.startswith('readonly+'):
378
            url = url[len('readonly+'):]
0.200.1336 by Jelmer Vernooij
Support the git smart server http protocol.
379
        if isinstance(transport, GitSmartTransport):
380
            get_client = transport._get_client
381
            client_path = transport._get_path()
382
        elif urlparse.urlsplit(transport.external_url())[0] in ("http", "https"):
383
            def get_client(thin_packs=False):
0.200.1337 by Jelmer Vernooij
Re-use http connection if possible.
384
                return BzrGitHttpClient(transport, thin_packs=thin_packs)
0.200.1336 by Jelmer Vernooij
Support the git smart server http protocol.
385
            client_path = transport._path
386
        else:
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
387
            raise NotBranchError(transport.base)
0.200.1411 by Jelmer Vernooij
Fix control files.
388
        return RemoteGitDir(transport, self, get_client, client_path)
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
389
390
    def get_format_description(self):
391
        return "Remote Git Repository"
392
393
    def initialize_on_transport(self, transport):
394
        raise UninitializableFormat(self)
395
0.200.1412 by Jelmer Vernooij
Implement GitControlDirFormat.supports_transport.
396
    def supports_transport(self, transport):
397
        try:
398
            external_url = transport.external_url()
399
        except InProcessTransport:
400
            raise NotBranchError(path=transport.base)
401
        return (external_url.startswith("http:") or
402
                external_url.startswith("https:") or
403
                external_url.startswith("git+") or
404
                external_url.startswith("git:"))
405
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
406
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
407
class RemoteGitRepository(GitRepository):
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
408
0.200.319 by Jelmer Vernooij
Print proper error when trying unsupported operations against a git server.
409
    @property
0.200.1068 by Jelmer Vernooij
Implement user_url/control_url.
410
    def user_url(self):
411
        return self.control_url
412
0.200.1288 by Jelmer Vernooij
Properly raise GitRemoteNotSupported from RemoteGitRepository.
413
    def get_parent_map(self, revids):
0.200.1398 by Jelmer Vernooij
Make GitSmartRemoteNotSupported derive from UnsupportedOperation.
414
        raise GitSmartRemoteNotSupported(self.get_parent_map, self)
0.200.319 by Jelmer Vernooij
Print proper error when trying unsupported operations against a git server.
415
0.200.695 by Jelmer Vernooij
Clean up trailing whitespace.
416
    def fetch_pack(self, determine_wants, graph_walker, pack_data,
0.200.155 by Jelmer Vernooij
Fix formatting, remove catch-all for exceptions when opening local repositories.
417
                   progress=None):
0.200.1335 by Jelmer Vernooij
Move _get_client.
418
        return self.bzrdir.fetch_pack(determine_wants, graph_walker,
0.200.456 by Jelmer Vernooij
Fix git -> git fetching.
419
                                          pack_data, progress)
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
420
0.200.427 by Jelmer Vernooij
make send_pack accessible.
421
    def send_pack(self, get_changed_refs, generate_pack_contents):
0.200.1335 by Jelmer Vernooij
Move _get_client.
422
        return self.bzrdir.send_pack(get_changed_refs, generate_pack_contents)
0.200.427 by Jelmer Vernooij
make send_pack accessible.
423
0.200.695 by Jelmer Vernooij
Clean up trailing whitespace.
424
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref,
425
                      progress=None):
0.200.167 by Jelmer Vernooij
Implement fetch_objects properly.
426
        fd, path = tempfile.mkstemp(suffix=".pack")
0.200.1299 by Jelmer Vernooij
Make sure file gets closed.
427
        try:
428
            self.fetch_pack(determine_wants, graph_walker,
429
                lambda x: os.write(fd, x), progress)
430
        finally:
431
            os.close(fd)
0.200.226 by Jelmer Vernooij
Merge thin-pack work.
432
        if os.path.getsize(path) == 0:
0.225.2 by Jelmer Vernooij
Handle situation when repository is already up to date during pull.
433
            return EmptyObjectStoreIterator()
0.200.226 by Jelmer Vernooij
Merge thin-pack work.
434
        return TemporaryPackIterator(path[:-len(".pack")], resolve_ext_ref)
0.200.167 by Jelmer Vernooij
Implement fetch_objects properly.
435
0.200.650 by Jelmer Vernooij
Use standard names for lookup functions.
436
    def lookup_bzr_revision_id(self, bzr_revid):
0.200.415 by Jelmer Vernooij
make 'bzr pull --revision' work for remote repositories.
437
        # This won't work for any round-tripped bzr revisions, but it's a start..
438
        try:
439
            return mapping_registry.revision_id_bzr_to_foreign(bzr_revid)
440
        except InvalidRevisionId:
441
            raise NoSuchRevision(self, bzr_revid)
442
0.252.48 by Jelmer Vernooij
Implement lookup_foreign_revision for remote branches.
443
    def lookup_foreign_revision_id(self, foreign_revid, mapping=None):
444
        """Lookup a revision id.
445
446
        """
447
        if mapping is None:
448
            mapping = self.get_mapping()
449
        # Not really an easy way to parse foreign revids here..
450
        return mapping.revision_id_foreign_to_bzr(foreign_revid)
451
0.200.1446 by Jelmer Vernooij
Add stub for RemoteGitRepository.revision_tree.
452
    def revision_tree(self, revid):
453
        raise GitSmartRemoteNotSupported(self.revision_tree, self)
454
0.200.1481 by Jelmer Vernooij
'Implement' RemoteGitRepository.get_revisions.
455
    def get_revisions(self, revids):
456
        raise GitSmartRemoteNotSupported(self.get_revisions, self)
457
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
458
0.200.1064 by Jelmer Vernooij
Use common base class for tags.
459
class RemoteGitTagDict(GitTags):
0.228.3 by Jelmer Vernooij
Fix tags when fetching from remotes.
460
0.200.1066 by Jelmer Vernooij
Add GitTags.get_refs.
461
    def get_refs(self):
0.200.1487 by Jelmer Vernooij
Use peeling.
462
        return self.repository.bzrdir.get_refs_container()
0.228.3 by Jelmer Vernooij
Fix tags when fetching from remotes.
463
464
    def set_tag(self, name, revid):
465
        # FIXME: Not supported yet, should do a push of a new ref
466
        raise NotImplementedError(self.set_tag)
467
468
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
469
class RemoteGitBranch(GitBranch):
470
0.200.1415 by Jelmer Vernooij
Fix lock files for remote directories.
471
    def __init__(self, bzrdir, repository, name):
0.200.919 by Jelmer Vernooij
Simplify ref handling in remote.py.
472
        self._sha = None
0.200.1415 by Jelmer Vernooij
Fix lock files for remote directories.
473
        super(RemoteGitBranch, self).__init__(bzrdir, repository, name)
0.200.461 by Jelmer Vernooij
Reduce number of round trips when fetching from Git.
474
0.200.1317 by Jelmer Vernooij
Avoid NotImplementedError.
475
    def last_revision_info(self):
0.200.1398 by Jelmer Vernooij
Make GitSmartRemoteNotSupported derive from UnsupportedOperation.
476
        raise GitSmartRemoteNotSupported(self.last_revision_info, self)
0.200.1317 by Jelmer Vernooij
Avoid NotImplementedError.
477
0.200.1068 by Jelmer Vernooij
Implement user_url/control_url.
478
    @property
479
    def user_url(self):
480
        return self.control_url
481
482
    @property
483
    def control_url(self):
484
        return self.base
485
0.200.461 by Jelmer Vernooij
Reduce number of round trips when fetching from Git.
486
    def revision_history(self):
0.200.1436 by Jelmer Vernooij
Raise UnsupportedOperation for `Branch.revision_id_to_dotted_revno`,
487
        raise GitSmartRemoteNotSupported(self.revision_history, self)
488
489
    def revision_id_to_revno(self, revision_id):
490
        raise GitSmartRemoteNotSupported(self.revision_id_to_revno, self)
0.200.461 by Jelmer Vernooij
Reduce number of round trips when fetching from Git.
491
492
    def last_revision(self):
0.252.44 by Jelmer Vernooij
Properly look up Bazaar revision ids for revision parents in case they are round-tripped.
493
        return self.lookup_foreign_revision_id(self.head)
0.200.461 by Jelmer Vernooij
Reduce number of round trips when fetching from Git.
494
495
    @property
496
    def head(self):
0.200.919 by Jelmer Vernooij
Simplify ref handling in remote.py.
497
        if self._sha is not None:
498
            return self._sha
0.200.1434 by Jelmer Vernooij
Move refs access to control dir.
499
        refs = self.bzrdir.get_refs()
0.200.1311 by Jelmer Vernooij
More work on colocated branch support.
500
        name = branch_name_to_ref(self.name, "HEAD")
0.200.1386 by Jelmer Vernooij
Friendlier message if HEAD is not found.
501
        try:
502
            self._sha = refs[name]
503
        except KeyError:
504
            raise NoSuchRef(name, self.repository.user_url, refs)
0.200.919 by Jelmer Vernooij
Simplify ref handling in remote.py.
505
        return self._sha
0.200.141 by Jelmer Vernooij
Separate out local and remote fetching.
506
0.200.169 by Jelmer Vernooij
Fix branch cloning.
507
    def _synchronize_history(self, destination, revision_id):
508
        """See Branch._synchronize_history()."""
509
        destination.generate_revision_history(self.last_revision())
0.200.695 by Jelmer Vernooij
Clean up trailing whitespace.
510
0.200.499 by Jelmer Vernooij
Implement RemoteBranch.{get,set}_push_location.
511
    def get_push_location(self):
512
        return None
513
514
    def set_push_location(self, url):
515
        pass