/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.405.1 by Jelmer Vernooij
Use same logic for interpreting progress reports everywhere.
21
import re
22
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
23
from ... import (
0.200.596 by Jelmer Vernooij
Import RemoteGitBranch._get_config().
24
    config,
0.200.707 by Jelmer Vernooij
Add debug routines.
25
    debug,
0.404.5 by Jelmer Vernooij
Check for diverged branches during push.
26
    errors,
0.200.586 by Jelmer Vernooij
Fix issues pointed out by pyflakes.
27
    trace,
0.200.333 by Jelmer Vernooij
Support progress reporting when creating index.
28
    ui,
0.200.289 by Jelmer Vernooij
Cope with new member variables in RepositoryFormat.
29
    urlutils,
30
    )
0.403.3 by Jelmer Vernooij
Test RemoteGitDir.push_branch.
31
from ...push import (
0.401.4 by Jelmer Vernooij
Implement RemoteGitDir.push_branch.
32
    PushResult,
33
    )
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
34
from ...errors import (
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
35
    AlreadyBranchError,
0.200.289 by Jelmer Vernooij
Cope with new member variables in RepositoryFormat.
36
    BzrError,
0.404.5 by Jelmer Vernooij
Check for diverged branches during push.
37
    DivergedBranches,
0.200.1412 by Jelmer Vernooij
Implement GitControlDirFormat.supports_transport.
38
    InProcessTransport,
0.200.415 by Jelmer Vernooij
make 'bzr pull --revision' work for remote repositories.
39
    InvalidRevisionId,
0.200.289 by Jelmer Vernooij
Cope with new member variables in RepositoryFormat.
40
    NoSuchFile,
0.200.415 by Jelmer Vernooij
make 'bzr pull --revision' work for remote repositories.
41
    NoSuchRevision,
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
42
    NoSuchTag,
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
43
    NotBranchError,
0.200.289 by Jelmer Vernooij
Cope with new member variables in RepositoryFormat.
44
    NotLocalUrl,
0.401.4 by Jelmer Vernooij
Implement RemoteGitDir.push_branch.
45
    NoWorkingTree,
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
46
    UninitializableFormat,
0.200.289 by Jelmer Vernooij
Cope with new member variables in RepositoryFormat.
47
    )
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
48
from ...transport import (
0.200.292 by Jelmer Vernooij
Fix formatting.
49
    Transport,
50
    )
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
51
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
52
from . import (
0.200.292 by Jelmer Vernooij
Fix formatting.
53
    lazy_check_versions,
54
    )
0.200.200 by Jelmer Vernooij
Register lazily where possible.
55
lazy_check_versions()
56
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
57
from .branch import (
0.200.292 by Jelmer Vernooij
Fix formatting.
58
    GitBranch,
0.295.1 by Jelmer Vernooij
Split up branch formats.
59
    GitBranchFormat,
0.403.3 by Jelmer Vernooij
Test RemoteGitDir.push_branch.
60
    GitBranchPushResult,
0.200.1064 by Jelmer Vernooij
Use common base class for tags.
61
    GitTags,
0.200.292 by Jelmer Vernooij
Fix formatting.
62
    )
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
63
from .dir import (
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
64
    GitControlDirFormat,
65
    GitDir,
0.344.1 by Jelmer Vernooij
Allow using local git executable by accessing git:///some/path.
66
    BareLocalGitControlDirFormat,
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
67
    )
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
68
from .errors import (
0.200.319 by Jelmer Vernooij
Print proper error when trying unsupported operations against a git server.
69
    GitSmartRemoteNotSupported,
0.200.292 by Jelmer Vernooij
Fix formatting.
70
    NoSuchRef,
71
    )
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
72
from .mapping import (
0.200.415 by Jelmer Vernooij
make 'bzr pull --revision' work for remote repositories.
73
    mapping_registry,
74
    )
0.401.4 by Jelmer Vernooij
Implement RemoteGitDir.push_branch.
75
from .object_store import (
76
    get_object_store,
77
    )
0.404.5 by Jelmer Vernooij
Check for diverged branches during push.
78
from .push import (
79
    remote_divergence,
80
    )
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
81
from .repository import (
0.200.289 by Jelmer Vernooij
Cope with new member variables in RepositoryFormat.
82
    GitRepository,
83
    )
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
84
from .refs import (
0.200.872 by Jelmer Vernooij
Move refs code to separate module.
85
    branch_name_to_ref,
0.200.1487 by Jelmer Vernooij
Use peeling.
86
    is_peeled,
0.375.1 by Jelmer Vernooij
Fix remote tests, warn when fetching git->bzr and bzr->git.
87
    ref_to_tag_name,
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
88
    tag_name_to_ref,
0.200.872 by Jelmer Vernooij
Move refs code to separate module.
89
    )
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
90
0.200.1336 by Jelmer Vernooij
Support the git smart server http protocol.
91
import dulwich
92
import dulwich.client
0.200.292 by Jelmer Vernooij
Fix formatting.
93
from dulwich.errors import (
94
    GitProtocolError,
95
    )
0.200.289 by Jelmer Vernooij
Cope with new member variables in RepositoryFormat.
96
from dulwich.pack import (
97
    Pack,
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
98
    pack_objects_to_data,
0.200.289 by Jelmer Vernooij
Cope with new member variables in RepositoryFormat.
99
    )
0.403.3 by Jelmer Vernooij
Test RemoteGitDir.push_branch.
100
from dulwich.protocol import ZERO_SHA
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
101
from dulwich.refs import SYMREF
0.200.1487 by Jelmer Vernooij
Use peeling.
102
from dulwich.repo import DictRefsContainer
0.200.167 by Jelmer Vernooij
Implement fetch_objects properly.
103
import os
0.200.1624 by Jelmer Vernooij
Add ssh vendor for dulwich that uses the bzr ssh vendor.
104
import select
0.200.167 by Jelmer Vernooij
Implement fetch_objects properly.
105
import tempfile
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
106
import urllib
107
import urlparse
0.200.1555 by Jelmer Vernooij
Remove segment parameters for http smart transports.
108
109
# urlparse only supports a limited number of schemes by default
110
0.200.741 by Jelmer Vernooij
Cope with older versions of Python by adding git and git+ssh to the list of known schemes.
111
urlparse.uses_netloc.extend(['git', 'git+ssh'])
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
112
0.200.586 by Jelmer Vernooij
Fix issues pointed out by pyflakes.
113
from dulwich.pack import load_pack_index
0.200.306 by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository.
114
0.200.143 by Jelmer Vernooij
Reoncile InterGitRepository objects.
115
0.200.695 by Jelmer Vernooij
Clean up trailing whitespace.
116
# Don't run any tests on GitSmartTransport as it is not intended to be
0.200.181 by Jelmer Vernooij
Support setting tags.
117
# a full implementation of Transport
118
def get_test_permutations():
119
    return []
120
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
121
0.200.708 by Jelmer Vernooij
Factor out URL parsing.
122
def split_git_url(url):
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
123
    """Split a Git URL.
124
125
    :param url: Git URL
126
    :return: Tuple with host, port, username, path.
127
    """
0.200.743 by Jelmer Vernooij
Fix URL parsing.
128
    (scheme, netloc, loc, _, _) = urlparse.urlsplit(url)
129
    path = urllib.unquote(loc)
0.246.2 by Jelmer Vernooij
Improve the fix dealing with git repo's in home directories.
130
    if path.startswith("/~"):
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
131
        path = path[1:]
0.200.743 by Jelmer Vernooij
Fix URL parsing.
132
    (username, hostport) = urllib.splituser(netloc)
0.200.708 by Jelmer Vernooij
Factor out URL parsing.
133
    (host, port) = urllib.splitnport(hostport, None)
134
    return (host, port, username, path)
135
136
0.200.1562 by Jelmer Vernooij
Add separate exception for remote errors.
137
class RemoteGitError(BzrError):
138
0.290.1 by Jelmer Vernooij
Avoid 'message' argument in RemoteGitError; apparently it breaks some versions of Python.
139
    _fmt = "Remote server error: %(msg)s"
0.200.1562 by Jelmer Vernooij
Add separate exception for remote errors.
140
141
0.200.1275 by Jelmer Vernooij
recognize missing repositories
142
def parse_git_error(url, message):
143
    """Parse a remote git server error and return a bzr exception.
144
145
    :param url: URL of the remote repository
146
    :param message: Message sent by the remote git server
147
    """
148
    message = str(message).strip()
149
    if message.startswith("Could not find Repository "):
150
        return NotBranchError(url, message)
0.200.1563 by Jelmer Vernooij
Improve error message.
151
    if message == "HEAD failed to update":
152
        base_url, _ = urlutils.split_segment_parameters(url)
153
        raise BzrError(
154
            ("Unable to update remote HEAD branch. To update the master "
155
             "branch, specify the URL %s,branch=master.") % base_url)
0.200.1275 by Jelmer Vernooij
recognize missing repositories
156
    # Don't know, just return it to the user as-is
0.200.1562 by Jelmer Vernooij
Add separate exception for remote errors.
157
    return RemoteGitError(message)
0.200.1275 by Jelmer Vernooij
recognize missing repositories
158
159
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
160
class GitSmartTransport(Transport):
161
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
162
    def __init__(self, url, _client=None):
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
163
        Transport.__init__(self, url)
0.200.708 by Jelmer Vernooij
Factor out URL parsing.
164
        (self._host, self._port, self._username, self._path) = \
165
            split_git_url(url)
0.200.707 by Jelmer Vernooij
Add debug routines.
166
        if 'transport' in debug.debug_flags:
167
            trace.mutter('host: %r, user: %r, port: %r, path: %r',
168
                         self._host, self._username, self._port, self._path)
0.200.166 by Jelmer Vernooij
don't reuse client objects.
169
        self._client = _client
0.200.1464 by Jelmer Vernooij
Warn about ignoring path segment parameters when using bzr 2.4.
170
        self._stripped_path = self._path.rsplit(",", 1)[0]
0.200.166 by Jelmer Vernooij
don't reuse client objects.
171
0.200.543 by Jelmer Vernooij
Implement GitSmartTransport.external_url().
172
    def external_url(self):
173
        return self.base
174
0.200.238 by Jelmer Vernooij
Import Transport.has().
175
    def has(self, relpath):
176
        return False
177
0.344.1 by Jelmer Vernooij
Allow using local git executable by accessing git:///some/path.
178
    def _get_client(self):
0.200.307 by Jelmer Vernooij
Support git+ssh.
179
        raise NotImplementedError(self._get_client)
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
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
        return self._stripped_path
0.200.470 by Jelmer Vernooij
Properly parse username in URLs.
183
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
184
    def get(self, path):
185
        raise NoSuchFile(path)
186
0.200.160 by Jelmer Vernooij
Implement abspath.
187
    def abspath(self, relpath):
188
        return urlutils.join(self.base, relpath)
189
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
190
    def clone(self, offset=None):
191
        """See Transport.clone()."""
192
        if offset is None:
193
            newurl = self.base
194
        else:
195
            newurl = urlutils.join(self.base, offset)
196
0.200.307 by Jelmer Vernooij
Support git+ssh.
197
        return self.__class__(newurl, self._client)
198
199
200
class TCPGitSmartTransport(GitSmartTransport):
201
0.200.332 by Jelmer Vernooij
Support activity reporting.
202
    _scheme = 'git'
203
0.344.1 by Jelmer Vernooij
Allow using local git executable by accessing git:///some/path.
204
    def _get_client(self):
0.200.307 by Jelmer Vernooij
Support git+ssh.
205
        if self._client is not None:
206
            ret = self._client
207
            self._client = None
208
            return ret
0.344.1 by Jelmer Vernooij
Allow using local git executable by accessing git:///some/path.
209
        if self._host == '':
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
210
            # return dulwich.client.LocalGitClient()
211
            return dulwich.client.SubprocessGitClient()
0.200.1336 by Jelmer Vernooij
Support the git smart server http protocol.
212
        return dulwich.client.TCPGitClient(self._host, self._port,
0.344.1 by Jelmer Vernooij
Allow using local git executable by accessing git:///some/path.
213
            report_activity=self._report_activity)
0.200.307 by Jelmer Vernooij
Support git+ssh.
214
215
0.200.1624 by Jelmer Vernooij
Add ssh vendor for dulwich that uses the bzr ssh vendor.
216
class SSHSocketWrapper(object):
217
218
    def __init__(self, sock):
219
        self.sock = sock
220
221
    def read(self, len=None):
222
        return self.sock.recv(len)
223
224
    def write(self, data):
225
        return self.sock.write(data)
226
227
    def can_read(self):
228
        return len(select.select([self.sock.fileno()], [], [], 0)[0]) > 0
229
230
231
class DulwichSSHVendor(dulwich.client.SSHVendor):
232
233
    def __init__(self):
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
234
        from ...transport import ssh
0.200.1624 by Jelmer Vernooij
Add ssh vendor for dulwich that uses the bzr ssh vendor.
235
        self.bzr_ssh_vendor = ssh._get_ssh_vendor()
236
237
    def run_command(self, host, command, username=None, port=None):
238
        connection = self.bzr_ssh_vendor.connect_ssh(username=username,
239
            password=None, port=port, host=host, command=command)
240
        (kind, io_object) = connection.get_sock_or_pipes()
241
        if kind == 'socket':
242
            return SSHSocketWrapper(io_object)
243
        else:
244
            raise AssertionError("Unknown io object kind %r'" % kind)
245
246
247
#dulwich.client.get_ssh_vendor = DulwichSSHVendor
248
249
0.200.307 by Jelmer Vernooij
Support git+ssh.
250
class SSHGitSmartTransport(GitSmartTransport):
251
0.200.332 by Jelmer Vernooij
Support activity reporting.
252
    _scheme = 'git+ssh'
253
0.200.470 by Jelmer Vernooij
Properly parse username in URLs.
254
    def _get_path(self):
0.200.1464 by Jelmer Vernooij
Warn about ignoring path segment parameters when using bzr 2.4.
255
        path = self._stripped_path
0.200.1318 by Jelmer Vernooij
Strip segment parameters where necessary.
256
        if path.startswith("/~/"):
257
            return path[3:]
258
        return path
0.200.470 by Jelmer Vernooij
Properly parse username in URLs.
259
0.344.1 by Jelmer Vernooij
Allow using local git executable by accessing git:///some/path.
260
    def _get_client(self):
0.200.307 by Jelmer Vernooij
Support git+ssh.
261
        if self._client is not None:
262
            ret = self._client
263
            self._client = None
264
            return ret
0.253.1 by Ross Light
Added configuration options for git-upload-pack and git-receive-pack
265
        location_config = config.LocationConfig(self.base)
0.200.1336 by Jelmer Vernooij
Support the git smart server http protocol.
266
        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.
267
            report_activity=self._report_activity)
0.253.1 by Ross Light
Added configuration options for git-upload-pack and git-receive-pack
268
        # Set up alternate pack program paths
269
        upload_pack = location_config.get_user_option('git_upload_pack')
270
        if upload_pack:
0.200.949 by Jelmer Vernooij
merge support for specifying alternative paths for git executables.
271
            client.alternative_paths["upload-pack"] = upload_pack
0.253.1 by Ross Light
Added configuration options for git-upload-pack and git-receive-pack
272
        receive_pack = location_config.get_user_option('git_receive_pack')
273
        if receive_pack:
0.200.949 by Jelmer Vernooij
merge support for specifying alternative paths for git executables.
274
            client.alternative_paths["receive-pack"] = receive_pack
0.253.1 by Ross Light
Added configuration options for git-upload-pack and git-receive-pack
275
        return client
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
276
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
277
0.295.1 by Jelmer Vernooij
Split up branch formats.
278
class RemoteGitBranchFormat(GitBranchFormat):
279
280
    def get_format_description(self):
281
        return 'Remote Git Branch'
282
283
    @property
284
    def _matchingcontroldir(self):
285
        return RemoteGitControlDirFormat()
286
0.295.2 by Jelmer Vernooij
Make RemoteGitBranchFormat uninitializeable.
287
    def initialize(self, a_controldir, name=None, repository=None,
288
                   append_revisions_only=None):
289
        raise UninitializableFormat(self)
290
0.295.1 by Jelmer Vernooij
Split up branch formats.
291
0.405.1 by Jelmer Vernooij
Use same logic for interpreting progress reports everywhere.
292
_GIT_PROGRESS_PARTIAL_RE = re.compile(r"(.*?): +(\d+)% \((\d+)/(\d+)\)")
293
_GIT_PROGRESS_TOTAL_RE = re.compile(r"(.*?): (\d+)")
294
def default_report_progress(pb, text):
295
    text = text.rstrip("\r\n")
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
296
    if text.startswith('error: '):
297
        trace.show_error('git: %s', text[len('error: '):])
298
    else:
0.405.1 by Jelmer Vernooij
Use same logic for interpreting progress reports everywhere.
299
        trace.mutter("git: %s", text)
300
        g = _GIT_PROGRESS_PARTIAL_RE.match(text)
301
        if g is not None:
302
            (text, pct, current, total) = g.groups()
303
            pb.update(text, int(current), int(total))
304
        else:
305
            g = _GIT_PROGRESS_TOTAL_RE.match(text)
306
            if g is not None:
307
                (text, total) = g.groups()
308
                pb.update(text, None, int(total))
309
            else:
310
                pb.update(text, None, None)
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
311
312
0.200.148 by Jelmer Vernooij
Share more infrastructure between LocalGitDir and RemoteGitDir.
313
class RemoteGitDir(GitDir):
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
314
0.344.1 by Jelmer Vernooij
Allow using local git executable by accessing git:///some/path.
315
    def __init__(self, transport, format, client, client_path):
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
316
        self._format = format
317
        self.root_transport = transport
318
        self.transport = transport
0.200.381 by Jelmer Vernooij
Support working trees properly, status and ls.
319
        self._mode_check_done = None
0.344.1 by Jelmer Vernooij
Allow using local git executable by accessing git:///some/path.
320
        self._client = client
0.200.1336 by Jelmer Vernooij
Support the git smart server http protocol.
321
        self._client_path = client_path
0.200.1396 by Jelmer Vernooij
Support updating tags in remote branches during pull.
322
        self.base = self.root_transport.base
0.200.1434 by Jelmer Vernooij
Move refs access to control dir.
323
        self._refs = None
0.200.1335 by Jelmer Vernooij
Move _get_client.
324
0.322.1 by Jelmer Vernooij
Fix access of remote git branches.
325
    @property
326
    def _gitrepository_class(self):
327
        return RemoteGitRepository
328
0.200.1335 by Jelmer Vernooij
Move _get_client.
329
    def fetch_pack(self, determine_wants, graph_walker, pack_data, progress=None):
330
        if progress is None:
0.405.1 by Jelmer Vernooij
Use same logic for interpreting progress reports everywhere.
331
            progress = lambda text: default_report_progress(pb, text)
332
            pb = ui.ui_factory.nested_progress_bar()
333
        else:
334
            pb = None
0.200.1335 by Jelmer Vernooij
Move _get_client.
335
        try:
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
336
            result = self._client.fetch_pack(self._client_path, determine_wants,
0.200.1335 by Jelmer Vernooij
Move _get_client.
337
                graph_walker, pack_data, progress)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
338
            if result.refs is None:
339
                result.refs = {}
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
340
            self._refs = remote_refs_dict_to_container(result.refs, result.symrefs)
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
341
            return result
0.200.1335 by Jelmer Vernooij
Move _get_client.
342
        except GitProtocolError, e:
343
            raise parse_git_error(self.transport.external_url(), e)
0.405.1 by Jelmer Vernooij
Use same logic for interpreting progress reports everywhere.
344
        finally:
345
            if pb is not None:
346
                pb.finished()
0.200.1335 by Jelmer Vernooij
Move _get_client.
347
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
348
    def send_pack(self, get_changed_refs, generate_pack_data, progress=None):
349
        if progress is None:
0.405.1 by Jelmer Vernooij
Use same logic for interpreting progress reports everywhere.
350
            progress = lambda text: default_report_progress(pb, text)
351
            pb = ui.ui_factory.nested_progress_bar()
352
        else:
353
            pb = None
0.200.1335 by Jelmer Vernooij
Move _get_client.
354
        try:
0.344.1 by Jelmer Vernooij
Allow using local git executable by accessing git:///some/path.
355
            return self._client.send_pack(self._client_path, get_changed_refs,
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
356
                generate_pack_data, progress)
0.200.1335 by Jelmer Vernooij
Move _get_client.
357
        except GitProtocolError, e:
358
            raise parse_git_error(self.transport.external_url(), e)
0.405.1 by Jelmer Vernooij
Use same logic for interpreting progress reports everywhere.
359
        finally:
360
            if pb is not None:
361
                pb.finished()
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
362
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
363
    def create_branch(self, name=None, repository=None,
364
                      append_revisions_only=None, ref=None):
365
        refname = self._get_selected_ref(name, ref)
366
        if refname != b'HEAD' and refname in self.get_refs_container():
367
            raise AlreadyBranchError(self.user_url)
368
        if refname in self.get_refs_container():
369
            ref_chain, unused_sha = self.get_refs_container().follow(self._get_selected_ref(None))
370
            if ref_chain[0] == b'HEAD':
371
                refname = ref_chain[1]
372
        repo = self.open_repository()
373
        return RemoteGitBranch(self, repo, refname)
374
0.200.1393 by Jelmer Vernooij
Implement removal of remote branches.
375
    def destroy_branch(self, name=None):
376
        refname = self._get_selected_ref(name)
377
        def get_changed_refs(old_refs):
378
            ret = dict(old_refs)
379
            if not refname in ret:
0.200.1395 by Jelmer Vernooij
Fix error reporting.
380
                raise NotBranchError(self.user_url)
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
381
            ret[refname] = dulwich.client.ZERO_SHA
0.200.1393 by Jelmer Vernooij
Implement removal of remote branches.
382
            return ret
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
383
        def generate_pack_data(have, want, ofs_delta=False):
384
            return pack_objects_to_data([])
385
        self.send_pack(get_changed_refs, generate_pack_data)
0.200.1393 by Jelmer Vernooij
Implement removal of remote branches.
386
0.200.1068 by Jelmer Vernooij
Implement user_url/control_url.
387
    @property
388
    def user_url(self):
389
        return self.control_url
390
0.200.1314 by Jelmer Vernooij
Provide RemoteGitDir.user_transport.
391
    @property
392
    def user_transport(self):
393
        return self.root_transport
394
0.200.1395 by Jelmer Vernooij
Fix error reporting.
395
    @property
396
    def control_url(self):
397
        return self.control_transport.base
398
399
    @property
400
    def control_transport(self):
401
        return self.root_transport
402
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
403
    def open_repository(self):
0.200.1415 by Jelmer Vernooij
Fix lock files for remote directories.
404
        return RemoteGitRepository(self)
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
405
0.200.1310 by Jelmer Vernooij
Add _get_selected_ref method.
406
    def open_branch(self, name=None, unsupported=False,
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
407
            ignore_fallbacks=False, ref=None, possible_transports=None,
408
            nascent_ok=False):
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
409
        repo = self.open_repository()
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
410
        ref = self._get_selected_ref(name, ref)
411
        if not nascent_ok and ref not in self.get_refs_container():
412
            raise NotBranchError(self.root_transport.base,
413
                    controldir=self)
414
        ref_chain, unused_sha = self.get_refs_container().follow(ref)
415
        return RemoteGitBranch(self, repo, ref_chain[-1])
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
416
0.200.662 by Jelmer Vernooij
Deal with recommend_upgrade argument to open_workingtree.
417
    def open_workingtree(self, recommend_upgrade=False):
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
418
        raise NotLocalUrl(self.transport.base)
419
0.310.4 by Jelmer Vernooij
Implement RemoteControlDir.has_workingtree.
420
    def has_workingtree(self):
421
        return False
422
0.200.1489 by Jelmer Vernooij
More fixes to peel handling.
423
    def get_peeled(self, name):
424
        return self.get_refs_container().get_peeled(name)
425
0.200.1487 by Jelmer Vernooij
Use peeling.
426
    def get_refs_container(self):
0.200.1434 by Jelmer Vernooij
Move refs access to control dir.
427
        if self._refs is not None:
428
            return self._refs
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
429
        result = self.fetch_pack(lambda x: None, None,
0.200.1434 by Jelmer Vernooij
Move refs access to control dir.
430
            lambda x: None, lambda x: trace.mutter("git: %s" % x))
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
431
        self._refs = remote_refs_dict_to_container(
432
                result.refs, result.symrefs)
0.200.1434 by Jelmer Vernooij
Move refs access to control dir.
433
        return self._refs
434
0.401.4 by Jelmer Vernooij
Implement RemoteGitDir.push_branch.
435
    def push_branch(self, source, revision_id=None, overwrite=False,
436
                    remember=False, create_prefix=False, lossy=False,
437
                    name=None):
438
        """Push the source branch into this ControlDir."""
439
        if revision_id is None:
440
            # No revision supplied by the user, default to the branch
441
            # revision
442
            revision_id = source.last_revision()
443
444
        push_result = PushResult()
445
        push_result.workingtree_updated = None
446
        push_result.master_branch = None
447
        push_result.source_branch = source
448
        push_result.stacked_on = None
449
        push_result.branch_push_result = None
450
        repo = self.find_repository()
451
        refname = self._get_selected_ref(name)
452
        source_store = get_object_store(source.repository)
0.403.3 by Jelmer Vernooij
Test RemoteGitDir.push_branch.
453
        with source_store.lock_read():
454
            def get_changed_refs(refs):
455
                self._refs = remote_refs_dict_to_container(refs)
456
                ret = dict(refs)
457
                # TODO(jelmer): Unpeel if necessary
458
                if lossy:
0.404.5 by Jelmer Vernooij
Check for diverged branches during push.
459
                    new_sha = source_store._lookup_revision_sha1(revision_id)
0.403.3 by Jelmer Vernooij
Test RemoteGitDir.push_branch.
460
                else:
0.404.5 by Jelmer Vernooij
Check for diverged branches during push.
461
                    new_sha = repo.lookup_bzr_revision_id(revision_id)[0]
462
                if not overwrite:
463
                    if remote_divergence(ret.get(refname), new_sha, source_store):
464
                        raise DivergedBranches(
465
                                source, self.open_branch(name, nascent_ok=True))
466
                ret[refname] = new_sha
0.403.3 by Jelmer Vernooij
Test RemoteGitDir.push_branch.
467
                return ret
468
            if lossy:
469
                generate_pack_data = source_store.generate_lossy_pack_data
470
            else:
471
                generate_pack_data = source_store.generate_pack_data
472
            new_refs = self.send_pack(get_changed_refs, generate_pack_data)
0.401.4 by Jelmer Vernooij
Implement RemoteGitDir.push_branch.
473
        push_result.new_revid = repo.lookup_foreign_revision_id(
474
                new_refs[refname])
0.403.3 by Jelmer Vernooij
Test RemoteGitDir.push_branch.
475
        try:
476
            old_remote = self._refs[refname]
477
        except KeyError:
478
            old_remote = ZERO_SHA
479
        push_result.old_revid = repo.lookup_foreign_revision_id(old_remote)
480
        self._refs = remote_refs_dict_to_container(new_refs)
0.401.4 by Jelmer Vernooij
Implement RemoteGitDir.push_branch.
481
        push_result.old_revno = None
482
        push_result.target_branch = self.open_branch(name)
0.403.3 by Jelmer Vernooij
Test RemoteGitDir.push_branch.
483
        if old_remote != ZERO_SHA:
484
            push_result.branch_push_result = GitBranchPushResult()
485
            push_result.branch_push_result.source_branch = source
486
            push_result.branch_push_result.target_branch = push_result.target_branch
487
            push_result.branch_push_result.local_branch = None
488
            push_result.branch_push_result.master_branch = push_result.target_branch
489
            push_result.branch_push_result.old_revid = push_result.old_revid
490
            push_result.branch_push_result.new_revid = push_result.new_revid
0.401.4 by Jelmer Vernooij
Implement RemoteGitDir.push_branch.
491
        if source.get_push_location() is None or remember:
492
            source.set_push_location(push_result.target_branch.base)
493
        return push_result
494
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
495
0.225.2 by Jelmer Vernooij
Handle situation when repository is already up to date during pull.
496
class EmptyObjectStoreIterator(dict):
497
498
    def iterobjects(self):
499
        return []
500
501
0.200.218 by Jelmer Vernooij
Simplify TemporaryPack implementation.
502
class TemporaryPackIterator(Pack):
503
0.200.226 by Jelmer Vernooij
Merge thin-pack work.
504
    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.
505
        super(TemporaryPackIterator, self).__init__(
506
            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.
507
        self._idx_load = lambda: self._idx_load_or_generate(self._idx_path)
0.200.226 by Jelmer Vernooij
Merge thin-pack work.
508
0.278.2 by William Grant
Also override _idx_load rather than index, to be a bit cleaner.
509
    def _idx_load_or_generate(self, path):
510
        if not os.path.exists(path):
511
            pb = ui.ui_factory.nested_progress_bar()
512
            try:
513
                def report_progress(cur, total):
514
                    pb.update("generating index", cur, total)
515
                self.data.create_index(path,
516
                    progress=report_progress)
517
            finally:
518
                pb.finished()
519
        return load_pack_index(path)
0.200.205 by Jelmer Vernooij
Fix remote fetching.
520
521
    def __del__(self):
0.200.611 by Jelmer Vernooij
Merge warning fix from Naoki.
522
        if self._idx is not None:
0.241.1 by Naoki INADA
Fix can't delete tempfile on Windows
523
            self._idx.close()
524
            os.remove(self._idx_path)
0.200.611 by Jelmer Vernooij
Merge warning fix from Naoki.
525
        if self._data is not None:
0.241.1 by Naoki INADA
Fix can't delete tempfile on Windows
526
            self._data.close()
527
            os.remove(self._data_path)
0.200.205 by Jelmer Vernooij
Fix remote fetching.
528
529
0.200.1337 by Jelmer Vernooij
Re-use http connection if possible.
530
class BzrGitHttpClient(dulwich.client.HttpGitClient):
531
532
    def __init__(self, transport, *args, **kwargs):
533
        self.transport = transport
534
        super(BzrGitHttpClient, self).__init__(transport.external_url(), *args, **kwargs)
535
        import urllib2
536
        self._http_perform = getattr(self.transport, "_perform", urllib2.urlopen)
537
538
    def _perform(self, req):
539
        req.accepted_errors = (200, 404)
540
        req.follow_redirections = True
541
        req.redirected_to = None
542
        return self._http_perform(req)
543
544
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
545
class RemoteGitControlDirFormat(GitControlDirFormat):
546
    """The .git directory control format."""
547
548
    supports_workingtrees = False
549
550
    @classmethod
551
    def _known_formats(self):
552
        return set([RemoteGitControlDirFormat()])
553
0.295.1 by Jelmer Vernooij
Split up branch formats.
554
    def get_branch_format(self):
555
        return RemoteGitBranchFormat()
556
0.200.1413 by Jelmer Vernooij
Fix is_initializable()
557
    def is_initializable(self):
558
        return False
559
560
    def is_supported(self):
561
        return True
562
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
563
    def open(self, transport, _found=None):
564
        """Open this directory.
565
566
        """
567
        # we dont grok readonly - git isn't integrated with transport.
568
        url = transport.base
569
        if url.startswith('readonly+'):
570
            url = url[len('readonly+'):]
0.344.1 by Jelmer Vernooij
Allow using local git executable by accessing git:///some/path.
571
        scheme = urlparse.urlsplit(transport.external_url())[0]
0.200.1336 by Jelmer Vernooij
Support the git smart server http protocol.
572
        if isinstance(transport, GitSmartTransport):
0.344.1 by Jelmer Vernooij
Allow using local git executable by accessing git:///some/path.
573
            client = transport._get_client()
0.200.1336 by Jelmer Vernooij
Support the git smart server http protocol.
574
            client_path = transport._get_path()
0.344.1 by Jelmer Vernooij
Allow using local git executable by accessing git:///some/path.
575
        elif scheme in ("http", "https"):
576
            client = BzrGitHttpClient(transport)
0.200.1555 by Jelmer Vernooij
Remove segment parameters for http smart transports.
577
            client_path, _ = urlutils.split_segment_parameters(transport._path)
0.344.1 by Jelmer Vernooij
Allow using local git executable by accessing git:///some/path.
578
        elif scheme == 'file':
579
            client = dulwich.client.LocalGitClient()
580
            client_path = transport.local_abspath('.')
0.200.1336 by Jelmer Vernooij
Support the git smart server http protocol.
581
        else:
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
582
            raise NotBranchError(transport.base)
0.344.1 by Jelmer Vernooij
Allow using local git executable by accessing git:///some/path.
583
        if not _found:
584
            pass # TODO(jelmer): Actually probe for something
585
        return RemoteGitDir(transport, self, client, client_path)
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
586
587
    def get_format_description(self):
588
        return "Remote Git Repository"
589
590
    def initialize_on_transport(self, transport):
591
        raise UninitializableFormat(self)
592
0.200.1412 by Jelmer Vernooij
Implement GitControlDirFormat.supports_transport.
593
    def supports_transport(self, transport):
594
        try:
595
            external_url = transport.external_url()
596
        except InProcessTransport:
597
            raise NotBranchError(path=transport.base)
598
        return (external_url.startswith("http:") or
599
                external_url.startswith("https:") or
600
                external_url.startswith("git+") or
601
                external_url.startswith("git:"))
602
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
603
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
604
class RemoteGitRepository(GitRepository):
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
605
0.200.319 by Jelmer Vernooij
Print proper error when trying unsupported operations against a git server.
606
    @property
0.200.1068 by Jelmer Vernooij
Implement user_url/control_url.
607
    def user_url(self):
608
        return self.control_url
609
0.200.1288 by Jelmer Vernooij
Properly raise GitRemoteNotSupported from RemoteGitRepository.
610
    def get_parent_map(self, revids):
0.200.1398 by Jelmer Vernooij
Make GitSmartRemoteNotSupported derive from UnsupportedOperation.
611
        raise GitSmartRemoteNotSupported(self.get_parent_map, self)
0.200.319 by Jelmer Vernooij
Print proper error when trying unsupported operations against a git server.
612
0.200.695 by Jelmer Vernooij
Clean up trailing whitespace.
613
    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.
614
                   progress=None):
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
615
        return self.controldir.fetch_pack(determine_wants, graph_walker,
0.200.456 by Jelmer Vernooij
Fix git -> git fetching.
616
                                          pack_data, progress)
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
617
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
618
    def send_pack(self, get_changed_refs, generate_pack_data):
619
        return self.controldir.send_pack(get_changed_refs, generate_pack_data)
0.200.427 by Jelmer Vernooij
make send_pack accessible.
620
0.200.695 by Jelmer Vernooij
Clean up trailing whitespace.
621
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref,
622
                      progress=None):
0.200.167 by Jelmer Vernooij
Implement fetch_objects properly.
623
        fd, path = tempfile.mkstemp(suffix=".pack")
0.200.1299 by Jelmer Vernooij
Make sure file gets closed.
624
        try:
625
            self.fetch_pack(determine_wants, graph_walker,
626
                lambda x: os.write(fd, x), progress)
627
        finally:
628
            os.close(fd)
0.200.226 by Jelmer Vernooij
Merge thin-pack work.
629
        if os.path.getsize(path) == 0:
0.225.2 by Jelmer Vernooij
Handle situation when repository is already up to date during pull.
630
            return EmptyObjectStoreIterator()
0.200.226 by Jelmer Vernooij
Merge thin-pack work.
631
        return TemporaryPackIterator(path[:-len(".pack")], resolve_ext_ref)
0.200.167 by Jelmer Vernooij
Implement fetch_objects properly.
632
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
633
    def lookup_bzr_revision_id(self, bzr_revid, mapping=None):
0.200.415 by Jelmer Vernooij
make 'bzr pull --revision' work for remote repositories.
634
        # This won't work for any round-tripped bzr revisions, but it's a start..
635
        try:
636
            return mapping_registry.revision_id_bzr_to_foreign(bzr_revid)
637
        except InvalidRevisionId:
638
            raise NoSuchRevision(self, bzr_revid)
639
0.252.48 by Jelmer Vernooij
Implement lookup_foreign_revision for remote branches.
640
    def lookup_foreign_revision_id(self, foreign_revid, mapping=None):
641
        """Lookup a revision id.
642
643
        """
644
        if mapping is None:
645
            mapping = self.get_mapping()
646
        # Not really an easy way to parse foreign revids here..
647
        return mapping.revision_id_foreign_to_bzr(foreign_revid)
648
0.200.1446 by Jelmer Vernooij
Add stub for RemoteGitRepository.revision_tree.
649
    def revision_tree(self, revid):
650
        raise GitSmartRemoteNotSupported(self.revision_tree, self)
651
0.200.1481 by Jelmer Vernooij
'Implement' RemoteGitRepository.get_revisions.
652
    def get_revisions(self, revids):
653
        raise GitSmartRemoteNotSupported(self.get_revisions, self)
654
0.200.1557 by Jelmer Vernooij
Implement RemoteGitRepository.has_revisions.
655
    def has_revisions(self, revids):
656
        raise GitSmartRemoteNotSupported(self.get_revisions, self)
657
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
658
0.200.1064 by Jelmer Vernooij
Use common base class for tags.
659
class RemoteGitTagDict(GitTags):
0.228.3 by Jelmer Vernooij
Fix tags when fetching from remotes.
660
661
    def set_tag(self, name, revid):
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
662
        sha = self.branch.lookup_bzr_revision_id(revid)[0]
663
        self._set_ref(name, sha)
664
665
    def delete_tag(self, name):
666
        self._set_ref(name, dulwich.client.ZERO_SHA)
667
668
    def _set_ref(self, name, sha):
669
        ref = tag_name_to_ref(name)
670
        def get_changed_refs(old_refs):
671
            ret = dict(old_refs)
672
            if sha == dulwich.client.ZERO_SHA and ref not in ret:
673
                raise NoSuchTag(name)
674
            ret[ref] = sha
675
            return ret
676
        def generate_pack_data(have, want, ofs_delta=False):
677
            return pack_objects_to_data([])
678
        self.repository.send_pack(get_changed_refs, generate_pack_data)
0.228.3 by Jelmer Vernooij
Fix tags when fetching from remotes.
679
680
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
681
class RemoteGitBranch(GitBranch):
682
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
683
    def __init__(self, controldir, repository, name):
0.200.919 by Jelmer Vernooij
Simplify ref handling in remote.py.
684
        self._sha = None
0.295.1 by Jelmer Vernooij
Split up branch formats.
685
        super(RemoteGitBranch, self).__init__(controldir, repository, name,
686
                RemoteGitBranchFormat())
0.200.461 by Jelmer Vernooij
Reduce number of round trips when fetching from Git.
687
0.200.1317 by Jelmer Vernooij
Avoid NotImplementedError.
688
    def last_revision_info(self):
0.200.1398 by Jelmer Vernooij
Make GitSmartRemoteNotSupported derive from UnsupportedOperation.
689
        raise GitSmartRemoteNotSupported(self.last_revision_info, self)
0.200.1317 by Jelmer Vernooij
Avoid NotImplementedError.
690
0.200.1068 by Jelmer Vernooij
Implement user_url/control_url.
691
    @property
692
    def user_url(self):
693
        return self.control_url
694
695
    @property
696
    def control_url(self):
697
        return self.base
698
0.200.1436 by Jelmer Vernooij
Raise UnsupportedOperation for `Branch.revision_id_to_dotted_revno`,
699
    def revision_id_to_revno(self, revision_id):
700
        raise GitSmartRemoteNotSupported(self.revision_id_to_revno, self)
0.200.461 by Jelmer Vernooij
Reduce number of round trips when fetching from Git.
701
702
    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.
703
        return self.lookup_foreign_revision_id(self.head)
0.200.461 by Jelmer Vernooij
Reduce number of round trips when fetching from Git.
704
705
    @property
706
    def head(self):
0.200.919 by Jelmer Vernooij
Simplify ref handling in remote.py.
707
        if self._sha is not None:
708
            return self._sha
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
709
        refs = self.controldir.get_refs_container()
0.200.1561 by Jelmer Vernooij
Some fixes for colocated branch handling.
710
        name = branch_name_to_ref(self.name)
0.200.1386 by Jelmer Vernooij
Friendlier message if HEAD is not found.
711
        try:
712
            self._sha = refs[name]
713
        except KeyError:
714
            raise NoSuchRef(name, self.repository.user_url, refs)
0.200.919 by Jelmer Vernooij
Simplify ref handling in remote.py.
715
        return self._sha
0.200.141 by Jelmer Vernooij
Separate out local and remote fetching.
716
0.200.169 by Jelmer Vernooij
Fix branch cloning.
717
    def _synchronize_history(self, destination, revision_id):
718
        """See Branch._synchronize_history()."""
719
        destination.generate_revision_history(self.last_revision())
0.200.695 by Jelmer Vernooij
Clean up trailing whitespace.
720
0.289.1 by Jelmer Vernooij
No parent location for remote repos.
721
    def _get_parent_location(self):
722
        return None
723
0.200.499 by Jelmer Vernooij
Implement RemoteBranch.{get,set}_push_location.
724
    def get_push_location(self):
725
        return None
726
727
    def set_push_location(self, url):
728
        pass
0.200.1488 by Jelmer Vernooij
Factor out remote_refs_dict_to_container.
729
0.375.1 by Jelmer Vernooij
Fix remote tests, warn when fetching git->bzr and bzr->git.
730
    def _iter_tag_refs(self):
731
        """Iterate over the tag refs.
732
733
        :param refs: Refs dictionary (name -> git sha1)
734
        :return: iterator over (ref_name, tag_name, peeled_sha1, unpeeled_sha1)
735
        """
736
        refs = self.controldir.get_refs_container()
737
        for ref_name, unpeeled in refs.as_dict().iteritems():
738
            try:
739
                tag_name = ref_to_tag_name(ref_name)
740
            except (ValueError, UnicodeDecodeError):
741
                continue
742
            peeled = refs.get_peeled(ref_name)
743
            if peeled is None:
744
                try:
745
                    peeled = refs.peel_sha(unpeeled).id
746
                except KeyError:
747
                    # Let's just hope it's a commit
748
                    peeled = unpeeled
749
            if type(tag_name) is not unicode:
750
                raise TypeError(tag_name)
751
            yield (ref_name, tag_name, peeled, unpeeled)
752
0.200.1488 by Jelmer Vernooij
Factor out remote_refs_dict_to_container.
753
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
754
def remote_refs_dict_to_container(refs_dict, symrefs_dict={}):
0.200.1488 by Jelmer Vernooij
Factor out remote_refs_dict_to_container.
755
    base = {}
756
    peeled = {}
757
    for k, v in refs_dict.iteritems():
758
        if is_peeled(k):
759
            peeled[k[:-3]] = v
760
        else:
761
            base[k] = v
762
            peeled[k] = v
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
763
    for name, target in symrefs_dict.iteritems():
764
        base[name] = SYMREF + target
0.200.1488 by Jelmer Vernooij
Factor out remote_refs_dict_to_container.
765
    ret = DictRefsContainer(base)
766
    ret._peeled = peeled
767
    return ret