/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.358.2 by Jelmer Vernooij
Refresh copyright headers, add my email.
1
# Copyright (C) 2007-2018 Jelmer Vernooij <jelmer@jelmer.uk>
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
0.358.1 by Jelmer Vernooij
Fix FSF address.
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
16
0.358.3 by Jelmer Vernooij
Enable absolute import.
17
"""Remote dirs, repositories and branches."""
18
0.200.1594 by Jelmer Vernooij
Use absolute_import everywhere.
19
from __future__ import absolute_import
20
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
21
from ... import (
0.200.596 by Jelmer Vernooij
Import RemoteGitBranch._get_config().
22
    config,
0.200.707 by Jelmer Vernooij
Add debug routines.
23
    debug,
0.200.586 by Jelmer Vernooij
Fix issues pointed out by pyflakes.
24
    trace,
0.200.333 by Jelmer Vernooij
Support progress reporting when creating index.
25
    ui,
0.200.289 by Jelmer Vernooij
Cope with new member variables in RepositoryFormat.
26
    urlutils,
27
    )
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
28
from ...errors import (
0.200.289 by Jelmer Vernooij
Cope with new member variables in RepositoryFormat.
29
    BzrError,
0.200.1412 by Jelmer Vernooij
Implement GitControlDirFormat.supports_transport.
30
    InProcessTransport,
0.200.415 by Jelmer Vernooij
make 'bzr pull --revision' work for remote repositories.
31
    InvalidRevisionId,
0.200.289 by Jelmer Vernooij
Cope with new member variables in RepositoryFormat.
32
    NoSuchFile,
0.200.415 by Jelmer Vernooij
make 'bzr pull --revision' work for remote repositories.
33
    NoSuchRevision,
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
34
    NotBranchError,
0.200.289 by Jelmer Vernooij
Cope with new member variables in RepositoryFormat.
35
    NotLocalUrl,
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
36
    UninitializableFormat,
0.200.289 by Jelmer Vernooij
Cope with new member variables in RepositoryFormat.
37
    )
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
38
from ...transport import (
0.200.292 by Jelmer Vernooij
Fix formatting.
39
    Transport,
40
    )
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
41
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
42
from . import (
0.200.292 by Jelmer Vernooij
Fix formatting.
43
    lazy_check_versions,
44
    )
0.200.200 by Jelmer Vernooij
Register lazily where possible.
45
lazy_check_versions()
46
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
47
from .branch import (
0.200.292 by Jelmer Vernooij
Fix formatting.
48
    GitBranch,
0.295.1 by Jelmer Vernooij
Split up branch formats.
49
    GitBranchFormat,
0.200.1064 by Jelmer Vernooij
Use common base class for tags.
50
    GitTags,
0.200.292 by Jelmer Vernooij
Fix formatting.
51
    )
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
52
from .dir import (
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
53
    GitControlDirFormat,
54
    GitDir,
0.344.1 by Jelmer Vernooij
Allow using local git executable by accessing git:///some/path.
55
    BareLocalGitControlDirFormat,
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
56
    )
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
57
from .errors import (
0.200.319 by Jelmer Vernooij
Print proper error when trying unsupported operations against a git server.
58
    GitSmartRemoteNotSupported,
0.200.292 by Jelmer Vernooij
Fix formatting.
59
    NoSuchRef,
60
    )
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
61
from .mapping import (
0.200.415 by Jelmer Vernooij
make 'bzr pull --revision' work for remote repositories.
62
    mapping_registry,
63
    )
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
64
from .repository import (
0.200.289 by Jelmer Vernooij
Cope with new member variables in RepositoryFormat.
65
    GitRepository,
66
    )
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
67
from .refs import (
0.200.872 by Jelmer Vernooij
Move refs code to separate module.
68
    branch_name_to_ref,
0.200.1487 by Jelmer Vernooij
Use peeling.
69
    is_peeled,
0.200.872 by Jelmer Vernooij
Move refs code to separate module.
70
    )
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
71
0.200.1336 by Jelmer Vernooij
Support the git smart server http protocol.
72
import dulwich
73
import dulwich.client
0.200.292 by Jelmer Vernooij
Fix formatting.
74
from dulwich.errors import (
75
    GitProtocolError,
76
    )
0.200.289 by Jelmer Vernooij
Cope with new member variables in RepositoryFormat.
77
from dulwich.pack import (
78
    Pack,
79
    )
0.200.1487 by Jelmer Vernooij
Use peeling.
80
from dulwich.repo import DictRefsContainer
0.200.167 by Jelmer Vernooij
Implement fetch_objects properly.
81
import os
0.200.1624 by Jelmer Vernooij
Add ssh vendor for dulwich that uses the bzr ssh vendor.
82
import select
0.200.167 by Jelmer Vernooij
Implement fetch_objects properly.
83
import tempfile
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
84
import urllib
85
import urlparse
0.200.1555 by Jelmer Vernooij
Remove segment parameters for http smart transports.
86
87
# urlparse only supports a limited number of schemes by default
88
0.200.741 by Jelmer Vernooij
Cope with older versions of Python by adding git and git+ssh to the list of known schemes.
89
urlparse.uses_netloc.extend(['git', 'git+ssh'])
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
90
0.200.586 by Jelmer Vernooij
Fix issues pointed out by pyflakes.
91
from dulwich.pack import load_pack_index
0.200.306 by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository.
92
0.200.143 by Jelmer Vernooij
Reoncile InterGitRepository objects.
93
0.200.695 by Jelmer Vernooij
Clean up trailing whitespace.
94
# Don't run any tests on GitSmartTransport as it is not intended to be
0.200.181 by Jelmer Vernooij
Support setting tags.
95
# a full implementation of Transport
96
def get_test_permutations():
97
    return []
98
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
99
0.200.708 by Jelmer Vernooij
Factor out URL parsing.
100
def split_git_url(url):
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
101
    """Split a Git URL.
102
103
    :param url: Git URL
104
    :return: Tuple with host, port, username, path.
105
    """
0.200.743 by Jelmer Vernooij
Fix URL parsing.
106
    (scheme, netloc, loc, _, _) = urlparse.urlsplit(url)
107
    path = urllib.unquote(loc)
0.246.2 by Jelmer Vernooij
Improve the fix dealing with git repo's in home directories.
108
    if path.startswith("/~"):
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
109
        path = path[1:]
0.200.743 by Jelmer Vernooij
Fix URL parsing.
110
    (username, hostport) = urllib.splituser(netloc)
0.200.708 by Jelmer Vernooij
Factor out URL parsing.
111
    (host, port) = urllib.splitnport(hostport, None)
112
    return (host, port, username, path)
113
114
0.200.1562 by Jelmer Vernooij
Add separate exception for remote errors.
115
class RemoteGitError(BzrError):
116
0.290.1 by Jelmer Vernooij
Avoid 'message' argument in RemoteGitError; apparently it breaks some versions of Python.
117
    _fmt = "Remote server error: %(msg)s"
0.200.1562 by Jelmer Vernooij
Add separate exception for remote errors.
118
119
0.200.1275 by Jelmer Vernooij
recognize missing repositories
120
def parse_git_error(url, message):
121
    """Parse a remote git server error and return a bzr exception.
122
123
    :param url: URL of the remote repository
124
    :param message: Message sent by the remote git server
125
    """
126
    message = str(message).strip()
127
    if message.startswith("Could not find Repository "):
128
        return NotBranchError(url, message)
0.200.1563 by Jelmer Vernooij
Improve error message.
129
    if message == "HEAD failed to update":
130
        base_url, _ = urlutils.split_segment_parameters(url)
131
        raise BzrError(
132
            ("Unable to update remote HEAD branch. To update the master "
133
             "branch, specify the URL %s,branch=master.") % base_url)
0.200.1275 by Jelmer Vernooij
recognize missing repositories
134
    # Don't know, just return it to the user as-is
0.200.1562 by Jelmer Vernooij
Add separate exception for remote errors.
135
    return RemoteGitError(message)
0.200.1275 by Jelmer Vernooij
recognize missing repositories
136
137
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
138
class GitSmartTransport(Transport):
139
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
140
    def __init__(self, url, _client=None):
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
141
        Transport.__init__(self, url)
0.200.708 by Jelmer Vernooij
Factor out URL parsing.
142
        (self._host, self._port, self._username, self._path) = \
143
            split_git_url(url)
0.200.707 by Jelmer Vernooij
Add debug routines.
144
        if 'transport' in debug.debug_flags:
145
            trace.mutter('host: %r, user: %r, port: %r, path: %r',
146
                         self._host, self._username, self._port, self._path)
0.200.166 by Jelmer Vernooij
don't reuse client objects.
147
        self._client = _client
0.200.1464 by Jelmer Vernooij
Warn about ignoring path segment parameters when using bzr 2.4.
148
        self._stripped_path = self._path.rsplit(",", 1)[0]
0.200.166 by Jelmer Vernooij
don't reuse client objects.
149
0.200.543 by Jelmer Vernooij
Implement GitSmartTransport.external_url().
150
    def external_url(self):
151
        return self.base
152
0.200.238 by Jelmer Vernooij
Import Transport.has().
153
    def has(self, relpath):
154
        return False
155
0.344.1 by Jelmer Vernooij
Allow using local git executable by accessing git:///some/path.
156
    def _get_client(self):
0.200.307 by Jelmer Vernooij
Support git+ssh.
157
        raise NotImplementedError(self._get_client)
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
158
0.200.470 by Jelmer Vernooij
Properly parse username in URLs.
159
    def _get_path(self):
0.200.1464 by Jelmer Vernooij
Warn about ignoring path segment parameters when using bzr 2.4.
160
        return self._stripped_path
0.200.470 by Jelmer Vernooij
Properly parse username in URLs.
161
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
162
    def get(self, path):
163
        raise NoSuchFile(path)
164
0.200.160 by Jelmer Vernooij
Implement abspath.
165
    def abspath(self, relpath):
166
        return urlutils.join(self.base, relpath)
167
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
168
    def clone(self, offset=None):
169
        """See Transport.clone()."""
170
        if offset is None:
171
            newurl = self.base
172
        else:
173
            newurl = urlutils.join(self.base, offset)
174
0.200.307 by Jelmer Vernooij
Support git+ssh.
175
        return self.__class__(newurl, self._client)
176
177
178
class TCPGitSmartTransport(GitSmartTransport):
179
0.200.332 by Jelmer Vernooij
Support activity reporting.
180
    _scheme = 'git'
181
0.344.1 by Jelmer Vernooij
Allow using local git executable by accessing git:///some/path.
182
    def _get_client(self):
0.200.307 by Jelmer Vernooij
Support git+ssh.
183
        if self._client is not None:
184
            ret = self._client
185
            self._client = None
186
            return ret
0.344.1 by Jelmer Vernooij
Allow using local git executable by accessing git:///some/path.
187
        if self._host == '':
188
            return dulwich.client.LocalGitClient()
0.200.1336 by Jelmer Vernooij
Support the git smart server http protocol.
189
        return dulwich.client.TCPGitClient(self._host, self._port,
0.344.1 by Jelmer Vernooij
Allow using local git executable by accessing git:///some/path.
190
            report_activity=self._report_activity)
0.200.307 by Jelmer Vernooij
Support git+ssh.
191
192
0.200.1624 by Jelmer Vernooij
Add ssh vendor for dulwich that uses the bzr ssh vendor.
193
class SSHSocketWrapper(object):
194
195
    def __init__(self, sock):
196
        self.sock = sock
197
198
    def read(self, len=None):
199
        return self.sock.recv(len)
200
201
    def write(self, data):
202
        return self.sock.write(data)
203
204
    def can_read(self):
205
        return len(select.select([self.sock.fileno()], [], [], 0)[0]) > 0
206
207
208
class DulwichSSHVendor(dulwich.client.SSHVendor):
209
210
    def __init__(self):
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
211
        from ...transport import ssh
0.200.1624 by Jelmer Vernooij
Add ssh vendor for dulwich that uses the bzr ssh vendor.
212
        self.bzr_ssh_vendor = ssh._get_ssh_vendor()
213
214
    def run_command(self, host, command, username=None, port=None):
215
        connection = self.bzr_ssh_vendor.connect_ssh(username=username,
216
            password=None, port=port, host=host, command=command)
217
        (kind, io_object) = connection.get_sock_or_pipes()
218
        if kind == 'socket':
219
            return SSHSocketWrapper(io_object)
220
        else:
221
            raise AssertionError("Unknown io object kind %r'" % kind)
222
223
224
#dulwich.client.get_ssh_vendor = DulwichSSHVendor
225
226
0.200.307 by Jelmer Vernooij
Support git+ssh.
227
class SSHGitSmartTransport(GitSmartTransport):
228
0.200.332 by Jelmer Vernooij
Support activity reporting.
229
    _scheme = 'git+ssh'
230
0.200.470 by Jelmer Vernooij
Properly parse username in URLs.
231
    def _get_path(self):
0.200.1464 by Jelmer Vernooij
Warn about ignoring path segment parameters when using bzr 2.4.
232
        path = self._stripped_path
0.200.1318 by Jelmer Vernooij
Strip segment parameters where necessary.
233
        if path.startswith("/~/"):
234
            return path[3:]
235
        return path
0.200.470 by Jelmer Vernooij
Properly parse username in URLs.
236
0.344.1 by Jelmer Vernooij
Allow using local git executable by accessing git:///some/path.
237
    def _get_client(self):
0.200.307 by Jelmer Vernooij
Support git+ssh.
238
        if self._client is not None:
239
            ret = self._client
240
            self._client = None
241
            return ret
0.253.1 by Ross Light
Added configuration options for git-upload-pack and git-receive-pack
242
        location_config = config.LocationConfig(self.base)
0.200.1336 by Jelmer Vernooij
Support the git smart server http protocol.
243
        client = dulwich.client.SSHGitClient(self._host, self._port, self._username,
0.344.1 by Jelmer Vernooij
Allow using local git executable by accessing git:///some/path.
244
            report_activity=self._report_activity)
0.253.1 by Ross Light
Added configuration options for git-upload-pack and git-receive-pack
245
        # Set up alternate pack program paths
246
        upload_pack = location_config.get_user_option('git_upload_pack')
247
        if upload_pack:
0.200.949 by Jelmer Vernooij
merge support for specifying alternative paths for git executables.
248
            client.alternative_paths["upload-pack"] = upload_pack
0.253.1 by Ross Light
Added configuration options for git-upload-pack and git-receive-pack
249
        receive_pack = location_config.get_user_option('git_receive_pack')
250
        if receive_pack:
0.200.949 by Jelmer Vernooij
merge support for specifying alternative paths for git executables.
251
            client.alternative_paths["receive-pack"] = receive_pack
0.253.1 by Ross Light
Added configuration options for git-upload-pack and git-receive-pack
252
        return client
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
253
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
254
0.295.1 by Jelmer Vernooij
Split up branch formats.
255
class RemoteGitBranchFormat(GitBranchFormat):
256
257
    def get_format_description(self):
258
        return 'Remote Git Branch'
259
260
    @property
261
    def _matchingcontroldir(self):
262
        return RemoteGitControlDirFormat()
263
0.295.2 by Jelmer Vernooij
Make RemoteGitBranchFormat uninitializeable.
264
    def initialize(self, a_controldir, name=None, repository=None,
265
                   append_revisions_only=None):
266
        raise UninitializableFormat(self)
267
0.295.1 by Jelmer Vernooij
Split up branch formats.
268
0.200.148 by Jelmer Vernooij
Share more infrastructure between LocalGitDir and RemoteGitDir.
269
class RemoteGitDir(GitDir):
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
270
0.344.1 by Jelmer Vernooij
Allow using local git executable by accessing git:///some/path.
271
    def __init__(self, transport, format, client, client_path):
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
272
        self._format = format
273
        self.root_transport = transport
274
        self.transport = transport
0.200.381 by Jelmer Vernooij
Support working trees properly, status and ls.
275
        self._mode_check_done = None
0.344.1 by Jelmer Vernooij
Allow using local git executable by accessing git:///some/path.
276
        self._client = client
0.200.1336 by Jelmer Vernooij
Support the git smart server http protocol.
277
        self._client_path = client_path
0.200.1396 by Jelmer Vernooij
Support updating tags in remote branches during pull.
278
        self.base = self.root_transport.base
0.200.1434 by Jelmer Vernooij
Move refs access to control dir.
279
        self._refs = None
0.200.1335 by Jelmer Vernooij
Move _get_client.
280
0.322.1 by Jelmer Vernooij
Fix access of remote git branches.
281
    @property
282
    def _gitrepository_class(self):
283
        return RemoteGitRepository
284
0.200.1335 by Jelmer Vernooij
Move _get_client.
285
    def fetch_pack(self, determine_wants, graph_walker, pack_data, progress=None):
286
        if progress is None:
287
            def progress(text):
288
                trace.info("git: %s" % text)
0.200.1489 by Jelmer Vernooij
More fixes to peel handling.
289
        def wrap_determine_wants(refs_dict):
290
            return determine_wants(remote_refs_dict_to_container(refs_dict))
0.200.1335 by Jelmer Vernooij
Move _get_client.
291
        try:
0.344.1 by Jelmer Vernooij
Allow using local git executable by accessing git:///some/path.
292
            refs_dict = self._client.fetch_pack(self._client_path, wrap_determine_wants,
0.200.1335 by Jelmer Vernooij
Move _get_client.
293
                graph_walker, pack_data, progress)
0.200.1628 by Jelmer Vernooij
Handle empty repositories during clone.
294
            if refs_dict is None:
295
                refs_dict = {}
0.200.1488 by Jelmer Vernooij
Factor out remote_refs_dict_to_container.
296
            self._refs = remote_refs_dict_to_container(refs_dict)
0.200.1487 by Jelmer Vernooij
Use peeling.
297
            return refs_dict
0.200.1335 by Jelmer Vernooij
Move _get_client.
298
        except GitProtocolError, e:
299
            raise parse_git_error(self.transport.external_url(), e)
300
301
    def send_pack(self, get_changed_refs, generate_pack_contents):
302
        try:
0.344.1 by Jelmer Vernooij
Allow using local git executable by accessing git:///some/path.
303
            return self._client.send_pack(self._client_path, get_changed_refs,
0.200.1335 by Jelmer Vernooij
Move _get_client.
304
                generate_pack_contents)
305
        except GitProtocolError, e:
306
            raise parse_git_error(self.transport.external_url(), e)
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
307
0.200.1561 by Jelmer Vernooij
Some fixes for colocated branch handling.
308
    def _get_default_ref(self):
309
        return "refs/heads/master"
310
0.200.1393 by Jelmer Vernooij
Implement removal of remote branches.
311
    def destroy_branch(self, name=None):
312
        refname = self._get_selected_ref(name)
313
        def get_changed_refs(old_refs):
314
            ret = dict(old_refs)
315
            if not refname in ret:
0.200.1395 by Jelmer Vernooij
Fix error reporting.
316
                raise NotBranchError(self.user_url)
0.200.1393 by Jelmer Vernooij
Implement removal of remote branches.
317
            ret[refname] = "00" * 20
318
            return ret
319
        self.send_pack(get_changed_refs, lambda have, want: [])
320
0.200.1068 by Jelmer Vernooij
Implement user_url/control_url.
321
    @property
322
    def user_url(self):
323
        return self.control_url
324
0.200.1314 by Jelmer Vernooij
Provide RemoteGitDir.user_transport.
325
    @property
326
    def user_transport(self):
327
        return self.root_transport
328
0.200.1395 by Jelmer Vernooij
Fix error reporting.
329
    @property
330
    def control_url(self):
331
        return self.control_transport.base
332
333
    @property
334
    def control_transport(self):
335
        return self.root_transport
336
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
337
    def open_repository(self):
0.200.1415 by Jelmer Vernooij
Fix lock files for remote directories.
338
        return RemoteGitRepository(self)
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
339
0.200.1310 by Jelmer Vernooij
Add _get_selected_ref method.
340
    def open_branch(self, name=None, unsupported=False,
0.200.1473 by Jelmer Vernooij
Support possible_transports argument to .open_branch.
341
            ignore_fallbacks=False, ref=None, possible_transports=None):
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
342
        repo = self.open_repository()
0.269.8 by Jelmer Vernooij
Support push in git-remote-bzr.
343
        refname = self._get_selected_ref(name, ref)
0.200.1415 by Jelmer Vernooij
Fix lock files for remote directories.
344
        return RemoteGitBranch(self, repo, refname)
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
345
0.200.662 by Jelmer Vernooij
Deal with recommend_upgrade argument to open_workingtree.
346
    def open_workingtree(self, recommend_upgrade=False):
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
347
        raise NotLocalUrl(self.transport.base)
348
0.310.4 by Jelmer Vernooij
Implement RemoteControlDir.has_workingtree.
349
    def has_workingtree(self):
350
        return False
351
0.200.1489 by Jelmer Vernooij
More fixes to peel handling.
352
    def get_peeled(self, name):
353
        return self.get_refs_container().get_peeled(name)
354
0.200.1487 by Jelmer Vernooij
Use peeling.
355
    def get_refs_container(self):
0.200.1434 by Jelmer Vernooij
Move refs access to control dir.
356
        if self._refs is not None:
357
            return self._refs
0.200.1487 by Jelmer Vernooij
Use peeling.
358
        refs_dict = self.fetch_pack(lambda x: [], None,
0.200.1434 by Jelmer Vernooij
Move refs access to control dir.
359
            lambda x: None, lambda x: trace.mutter("git: %s" % x))
0.200.1488 by Jelmer Vernooij
Factor out remote_refs_dict_to_container.
360
        self._refs = remote_refs_dict_to_container(refs_dict)
0.200.1434 by Jelmer Vernooij
Move refs access to control dir.
361
        return self._refs
362
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
363
0.225.2 by Jelmer Vernooij
Handle situation when repository is already up to date during pull.
364
class EmptyObjectStoreIterator(dict):
365
366
    def iterobjects(self):
367
        return []
368
369
0.200.218 by Jelmer Vernooij
Simplify TemporaryPack implementation.
370
class TemporaryPackIterator(Pack):
371
0.200.226 by Jelmer Vernooij
Merge thin-pack work.
372
    def __init__(self, path, resolve_ext_ref):
0.279.1 by William Grant
Support thin packs in fetch_pack and send_pack, since dulwich now handles them properly.
373
        super(TemporaryPackIterator, self).__init__(
374
            path, resolve_ext_ref=resolve_ext_ref)
0.278.2 by William Grant
Also override _idx_load rather than index, to be a bit cleaner.
375
        self._idx_load = lambda: self._idx_load_or_generate(self._idx_path)
0.200.226 by Jelmer Vernooij
Merge thin-pack work.
376
0.278.2 by William Grant
Also override _idx_load rather than index, to be a bit cleaner.
377
    def _idx_load_or_generate(self, path):
378
        if not os.path.exists(path):
379
            pb = ui.ui_factory.nested_progress_bar()
380
            try:
381
                def report_progress(cur, total):
382
                    pb.update("generating index", cur, total)
383
                self.data.create_index(path,
384
                    progress=report_progress)
385
            finally:
386
                pb.finished()
387
        return load_pack_index(path)
0.200.205 by Jelmer Vernooij
Fix remote fetching.
388
389
    def __del__(self):
0.200.611 by Jelmer Vernooij
Merge warning fix from Naoki.
390
        if self._idx is not None:
0.241.1 by Naoki INADA
Fix can't delete tempfile on Windows
391
            self._idx.close()
392
            os.remove(self._idx_path)
0.200.611 by Jelmer Vernooij
Merge warning fix from Naoki.
393
        if self._data is not None:
0.241.1 by Naoki INADA
Fix can't delete tempfile on Windows
394
            self._data.close()
395
            os.remove(self._data_path)
0.200.205 by Jelmer Vernooij
Fix remote fetching.
396
397
0.200.1337 by Jelmer Vernooij
Re-use http connection if possible.
398
class BzrGitHttpClient(dulwich.client.HttpGitClient):
399
400
    def __init__(self, transport, *args, **kwargs):
401
        self.transport = transport
402
        super(BzrGitHttpClient, self).__init__(transport.external_url(), *args, **kwargs)
403
        import urllib2
404
        self._http_perform = getattr(self.transport, "_perform", urllib2.urlopen)
405
406
    def _perform(self, req):
407
        req.accepted_errors = (200, 404)
408
        req.follow_redirections = True
409
        req.redirected_to = None
410
        return self._http_perform(req)
411
412
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
413
class RemoteGitControlDirFormat(GitControlDirFormat):
414
    """The .git directory control format."""
415
416
    supports_workingtrees = False
417
418
    @classmethod
419
    def _known_formats(self):
420
        return set([RemoteGitControlDirFormat()])
421
0.295.1 by Jelmer Vernooij
Split up branch formats.
422
    def get_branch_format(self):
423
        return RemoteGitBranchFormat()
424
0.200.1413 by Jelmer Vernooij
Fix is_initializable()
425
    def is_initializable(self):
426
        return False
427
428
    def is_supported(self):
429
        return True
430
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
431
    def open(self, transport, _found=None):
432
        """Open this directory.
433
434
        """
435
        # we dont grok readonly - git isn't integrated with transport.
436
        url = transport.base
437
        if url.startswith('readonly+'):
438
            url = url[len('readonly+'):]
0.344.1 by Jelmer Vernooij
Allow using local git executable by accessing git:///some/path.
439
        scheme = urlparse.urlsplit(transport.external_url())[0]
0.200.1336 by Jelmer Vernooij
Support the git smart server http protocol.
440
        if isinstance(transport, GitSmartTransport):
0.344.1 by Jelmer Vernooij
Allow using local git executable by accessing git:///some/path.
441
            client = transport._get_client()
0.200.1336 by Jelmer Vernooij
Support the git smart server http protocol.
442
            client_path = transport._get_path()
0.344.1 by Jelmer Vernooij
Allow using local git executable by accessing git:///some/path.
443
        elif scheme in ("http", "https"):
444
            client = BzrGitHttpClient(transport)
0.200.1555 by Jelmer Vernooij
Remove segment parameters for http smart transports.
445
            client_path, _ = urlutils.split_segment_parameters(transport._path)
0.344.1 by Jelmer Vernooij
Allow using local git executable by accessing git:///some/path.
446
        elif scheme == 'file':
447
            client = dulwich.client.LocalGitClient()
448
            client_path = transport.local_abspath('.')
0.200.1336 by Jelmer Vernooij
Support the git smart server http protocol.
449
        else:
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
450
            raise NotBranchError(transport.base)
0.344.1 by Jelmer Vernooij
Allow using local git executable by accessing git:///some/path.
451
        if not _found:
452
            pass # TODO(jelmer): Actually probe for something
453
        return RemoteGitDir(transport, self, client, client_path)
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
454
455
    def get_format_description(self):
456
        return "Remote Git Repository"
457
458
    def initialize_on_transport(self, transport):
459
        raise UninitializableFormat(self)
460
0.200.1412 by Jelmer Vernooij
Implement GitControlDirFormat.supports_transport.
461
    def supports_transport(self, transport):
462
        try:
463
            external_url = transport.external_url()
464
        except InProcessTransport:
465
            raise NotBranchError(path=transport.base)
466
        return (external_url.startswith("http:") or
467
                external_url.startswith("https:") or
468
                external_url.startswith("git+") or
469
                external_url.startswith("git:"))
470
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
471
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
472
class RemoteGitRepository(GitRepository):
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
473
0.200.319 by Jelmer Vernooij
Print proper error when trying unsupported operations against a git server.
474
    @property
0.200.1068 by Jelmer Vernooij
Implement user_url/control_url.
475
    def user_url(self):
476
        return self.control_url
477
0.200.1288 by Jelmer Vernooij
Properly raise GitRemoteNotSupported from RemoteGitRepository.
478
    def get_parent_map(self, revids):
0.200.1398 by Jelmer Vernooij
Make GitSmartRemoteNotSupported derive from UnsupportedOperation.
479
        raise GitSmartRemoteNotSupported(self.get_parent_map, self)
0.200.319 by Jelmer Vernooij
Print proper error when trying unsupported operations against a git server.
480
0.200.695 by Jelmer Vernooij
Clean up trailing whitespace.
481
    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.
482
                   progress=None):
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
483
        return self.controldir.fetch_pack(determine_wants, graph_walker,
0.200.456 by Jelmer Vernooij
Fix git -> git fetching.
484
                                          pack_data, progress)
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
485
0.200.427 by Jelmer Vernooij
make send_pack accessible.
486
    def send_pack(self, get_changed_refs, generate_pack_contents):
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
487
        return self.controldir.send_pack(get_changed_refs, generate_pack_contents)
0.200.427 by Jelmer Vernooij
make send_pack accessible.
488
0.200.695 by Jelmer Vernooij
Clean up trailing whitespace.
489
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref,
490
                      progress=None):
0.200.167 by Jelmer Vernooij
Implement fetch_objects properly.
491
        fd, path = tempfile.mkstemp(suffix=".pack")
0.200.1299 by Jelmer Vernooij
Make sure file gets closed.
492
        try:
493
            self.fetch_pack(determine_wants, graph_walker,
494
                lambda x: os.write(fd, x), progress)
495
        finally:
496
            os.close(fd)
0.200.226 by Jelmer Vernooij
Merge thin-pack work.
497
        if os.path.getsize(path) == 0:
0.225.2 by Jelmer Vernooij
Handle situation when repository is already up to date during pull.
498
            return EmptyObjectStoreIterator()
0.200.226 by Jelmer Vernooij
Merge thin-pack work.
499
        return TemporaryPackIterator(path[:-len(".pack")], resolve_ext_ref)
0.200.167 by Jelmer Vernooij
Implement fetch_objects properly.
500
0.200.650 by Jelmer Vernooij
Use standard names for lookup functions.
501
    def lookup_bzr_revision_id(self, bzr_revid):
0.200.415 by Jelmer Vernooij
make 'bzr pull --revision' work for remote repositories.
502
        # This won't work for any round-tripped bzr revisions, but it's a start..
503
        try:
504
            return mapping_registry.revision_id_bzr_to_foreign(bzr_revid)
505
        except InvalidRevisionId:
506
            raise NoSuchRevision(self, bzr_revid)
507
0.252.48 by Jelmer Vernooij
Implement lookup_foreign_revision for remote branches.
508
    def lookup_foreign_revision_id(self, foreign_revid, mapping=None):
509
        """Lookup a revision id.
510
511
        """
512
        if mapping is None:
513
            mapping = self.get_mapping()
514
        # Not really an easy way to parse foreign revids here..
515
        return mapping.revision_id_foreign_to_bzr(foreign_revid)
516
0.200.1446 by Jelmer Vernooij
Add stub for RemoteGitRepository.revision_tree.
517
    def revision_tree(self, revid):
518
        raise GitSmartRemoteNotSupported(self.revision_tree, self)
519
0.200.1481 by Jelmer Vernooij
'Implement' RemoteGitRepository.get_revisions.
520
    def get_revisions(self, revids):
521
        raise GitSmartRemoteNotSupported(self.get_revisions, self)
522
0.200.1557 by Jelmer Vernooij
Implement RemoteGitRepository.has_revisions.
523
    def has_revisions(self, revids):
524
        raise GitSmartRemoteNotSupported(self.get_revisions, self)
525
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
526
0.200.1064 by Jelmer Vernooij
Use common base class for tags.
527
class RemoteGitTagDict(GitTags):
0.228.3 by Jelmer Vernooij
Fix tags when fetching from remotes.
528
529
    def set_tag(self, name, revid):
530
        # FIXME: Not supported yet, should do a push of a new ref
531
        raise NotImplementedError(self.set_tag)
532
533
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
534
class RemoteGitBranch(GitBranch):
535
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
536
    def __init__(self, controldir, repository, name):
0.200.919 by Jelmer Vernooij
Simplify ref handling in remote.py.
537
        self._sha = None
0.295.1 by Jelmer Vernooij
Split up branch formats.
538
        super(RemoteGitBranch, self).__init__(controldir, repository, name,
539
                RemoteGitBranchFormat())
0.200.461 by Jelmer Vernooij
Reduce number of round trips when fetching from Git.
540
0.200.1317 by Jelmer Vernooij
Avoid NotImplementedError.
541
    def last_revision_info(self):
0.200.1398 by Jelmer Vernooij
Make GitSmartRemoteNotSupported derive from UnsupportedOperation.
542
        raise GitSmartRemoteNotSupported(self.last_revision_info, self)
0.200.1317 by Jelmer Vernooij
Avoid NotImplementedError.
543
0.200.1068 by Jelmer Vernooij
Implement user_url/control_url.
544
    @property
545
    def user_url(self):
546
        return self.control_url
547
548
    @property
549
    def control_url(self):
550
        return self.base
551
0.200.1436 by Jelmer Vernooij
Raise UnsupportedOperation for `Branch.revision_id_to_dotted_revno`,
552
    def revision_id_to_revno(self, revision_id):
553
        raise GitSmartRemoteNotSupported(self.revision_id_to_revno, self)
0.200.461 by Jelmer Vernooij
Reduce number of round trips when fetching from Git.
554
555
    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.
556
        return self.lookup_foreign_revision_id(self.head)
0.200.461 by Jelmer Vernooij
Reduce number of round trips when fetching from Git.
557
558
    @property
559
    def head(self):
0.200.919 by Jelmer Vernooij
Simplify ref handling in remote.py.
560
        if self._sha is not None:
561
            return self._sha
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
562
        refs = self.controldir.get_refs_container()
0.200.1561 by Jelmer Vernooij
Some fixes for colocated branch handling.
563
        name = branch_name_to_ref(self.name)
0.200.1386 by Jelmer Vernooij
Friendlier message if HEAD is not found.
564
        try:
565
            self._sha = refs[name]
566
        except KeyError:
567
            raise NoSuchRef(name, self.repository.user_url, refs)
0.200.919 by Jelmer Vernooij
Simplify ref handling in remote.py.
568
        return self._sha
0.200.141 by Jelmer Vernooij
Separate out local and remote fetching.
569
0.200.169 by Jelmer Vernooij
Fix branch cloning.
570
    def _synchronize_history(self, destination, revision_id):
571
        """See Branch._synchronize_history()."""
572
        destination.generate_revision_history(self.last_revision())
0.200.695 by Jelmer Vernooij
Clean up trailing whitespace.
573
0.289.1 by Jelmer Vernooij
No parent location for remote repos.
574
    def _get_parent_location(self):
575
        return None
576
0.200.499 by Jelmer Vernooij
Implement RemoteBranch.{get,set}_push_location.
577
    def get_push_location(self):
578
        return None
579
580
    def set_push_location(self, url):
581
        pass
0.200.1488 by Jelmer Vernooij
Factor out remote_refs_dict_to_container.
582
583
584
def remote_refs_dict_to_container(refs_dict):
585
    base = {}
586
    peeled = {}
587
    for k, v in refs_dict.iteritems():
588
        if is_peeled(k):
589
            peeled[k[:-3]] = v
590
        else:
591
            base[k] = v
592
            peeled[k] = v
593
    ret = DictRefsContainer(base)
594
    ret._peeled = peeled
595
    return ret