/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
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
21
import gzip
7404.5.3 by Jelmer Vernooij
Reuse connections.
22
from io import BytesIO
0.405.1 by Jelmer Vernooij
Use same logic for interpreting progress reports everywhere.
23
import re
24
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
25
from .. import (
0.200.596 by Jelmer Vernooij
Import RemoteGitBranch._get_config().
26
    config,
0.200.707 by Jelmer Vernooij
Add debug routines.
27
    debug,
0.404.5 by Jelmer Vernooij
Check for diverged branches during push.
28
    errors,
6968.4.4 by Jelmer Vernooij
Update for API changes from archive branch.
29
    osutils,
0.200.586 by Jelmer Vernooij
Fix issues pointed out by pyflakes.
30
    trace,
0.200.333 by Jelmer Vernooij
Support progress reporting when creating index.
31
    ui,
0.200.289 by Jelmer Vernooij
Cope with new member variables in RepositoryFormat.
32
    urlutils,
33
    )
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
34
from ..push import (
0.401.4 by Jelmer Vernooij
Implement RemoteGitDir.push_branch.
35
    PushResult,
36
    )
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
37
from ..errors import (
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
38
    AlreadyBranchError,
0.200.289 by Jelmer Vernooij
Cope with new member variables in RepositoryFormat.
39
    BzrError,
0.404.5 by Jelmer Vernooij
Check for diverged branches during push.
40
    DivergedBranches,
0.200.1412 by Jelmer Vernooij
Implement GitControlDirFormat.supports_transport.
41
    InProcessTransport,
0.200.415 by Jelmer Vernooij
make 'bzr pull --revision' work for remote repositories.
42
    InvalidRevisionId,
0.200.289 by Jelmer Vernooij
Cope with new member variables in RepositoryFormat.
43
    NoSuchFile,
0.200.415 by Jelmer Vernooij
make 'bzr pull --revision' work for remote repositories.
44
    NoSuchRevision,
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
45
    NoSuchTag,
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
46
    NotBranchError,
0.200.289 by Jelmer Vernooij
Cope with new member variables in RepositoryFormat.
47
    NotLocalUrl,
7103.1.2 by Jelmer Vernooij
Handle PermissionDenied.
48
    PermissionDenied,
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
49
    UninitializableFormat,
0.200.289 by Jelmer Vernooij
Cope with new member variables in RepositoryFormat.
50
    )
7484.1.2 by Jelmer Vernooij
Add some tests.
51
from ..revision import NULL_REVISION
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
52
from ..revisiontree import RevisionTree
53
from ..transport import (
0.200.292 by Jelmer Vernooij
Fix formatting.
54
    Transport,
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
55
    register_urlparse_netloc_protocol,
0.200.292 by Jelmer Vernooij
Fix formatting.
56
    )
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
57
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
58
from . import (
0.200.292 by Jelmer Vernooij
Fix formatting.
59
    lazy_check_versions,
7359.1.1 by Jelmer Vernooij
Only set user agent for GitHub.
60
    is_github_url,
0.409.2 by Jelmer Vernooij
call out to HTTP transport rather than creating new connection.
61
    user_agent_for_github,
0.200.292 by Jelmer Vernooij
Fix formatting.
62
    )
0.200.200 by Jelmer Vernooij
Register lazily where possible.
63
lazy_check_versions()
64
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
65
from .branch import (
0.200.292 by Jelmer Vernooij
Fix formatting.
66
    GitBranch,
0.295.1 by Jelmer Vernooij
Split up branch formats.
67
    GitBranchFormat,
0.403.3 by Jelmer Vernooij
Test RemoteGitDir.push_branch.
68
    GitBranchPushResult,
0.200.1064 by Jelmer Vernooij
Use common base class for tags.
69
    GitTags,
0.406.2 by Jelmer Vernooij
Add tests.
70
    _quick_lookup_revno,
0.200.292 by Jelmer Vernooij
Fix formatting.
71
    )
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
72
from .dir import (
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
73
    GitControlDirFormat,
74
    GitDir,
75
    )
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
76
from .errors import (
0.200.319 by Jelmer Vernooij
Print proper error when trying unsupported operations against a git server.
77
    GitSmartRemoteNotSupported,
0.200.292 by Jelmer Vernooij
Fix formatting.
78
    NoSuchRef,
79
    )
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
80
from .mapping import (
0.200.415 by Jelmer Vernooij
make 'bzr pull --revision' work for remote repositories.
81
    mapping_registry,
82
    )
0.401.4 by Jelmer Vernooij
Implement RemoteGitDir.push_branch.
83
from .object_store import (
84
    get_object_store,
85
    )
0.404.5 by Jelmer Vernooij
Check for diverged branches during push.
86
from .push import (
87
    remote_divergence,
88
    )
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
89
from .repository import (
0.200.289 by Jelmer Vernooij
Cope with new member variables in RepositoryFormat.
90
    GitRepository,
7290.20.3 by Jelmer Vernooij
Fix tests for git/full history branches.
91
    GitRepositoryFormat,
0.200.289 by Jelmer Vernooij
Cope with new member variables in RepositoryFormat.
92
    )
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
93
from .refs import (
0.200.872 by Jelmer Vernooij
Move refs code to separate module.
94
    branch_name_to_ref,
0.200.1487 by Jelmer Vernooij
Use peeling.
95
    is_peeled,
0.375.1 by Jelmer Vernooij
Fix remote tests, warn when fetching git->bzr and bzr->git.
96
    ref_to_tag_name,
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
97
    tag_name_to_ref,
0.200.872 by Jelmer Vernooij
Move refs code to separate module.
98
    )
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
99
0.200.1336 by Jelmer Vernooij
Support the git smart server http protocol.
100
import dulwich
101
import dulwich.client
0.200.292 by Jelmer Vernooij
Fix formatting.
102
from dulwich.errors import (
103
    GitProtocolError,
7143.2.1 by Jelmer Vernooij
Don't hardcode the list of supported archive formats.
104
    HangupException,
0.200.292 by Jelmer Vernooij
Fix formatting.
105
    )
0.200.289 by Jelmer Vernooij
Cope with new member variables in RepositoryFormat.
106
from dulwich.pack import (
107
    Pack,
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
108
    pack_objects_to_data,
0.200.289 by Jelmer Vernooij
Cope with new member variables in RepositoryFormat.
109
    )
0.403.3 by Jelmer Vernooij
Test RemoteGitDir.push_branch.
110
from dulwich.protocol import ZERO_SHA
0.409.2 by Jelmer Vernooij
call out to HTTP transport rather than creating new connection.
111
from dulwich.refs import (
112
    DictRefsContainer,
113
    SYMREF,
114
    )
115
from dulwich.repo import (
116
    NotGitRepository,
117
    )
0.200.167 by Jelmer Vernooij
Implement fetch_objects properly.
118
import os
0.200.1624 by Jelmer Vernooij
Add ssh vendor for dulwich that uses the bzr ssh vendor.
119
import select
0.200.167 by Jelmer Vernooij
Implement fetch_objects properly.
120
import tempfile
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
121
7479.2.1 by Jelmer Vernooij
Drop python2 support.
122
import urllib.parse as urlparse
123
from urllib.parse import splituser
0.200.1555 by Jelmer Vernooij
Remove segment parameters for http smart transports.
124
125
# urlparse only supports a limited number of schemes by default
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
126
register_urlparse_netloc_protocol('git')
127
register_urlparse_netloc_protocol('git+ssh')
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
128
0.200.586 by Jelmer Vernooij
Fix issues pointed out by pyflakes.
129
from dulwich.pack import load_pack_index
0.200.306 by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository.
130
0.200.143 by Jelmer Vernooij
Reoncile InterGitRepository objects.
131
0.406.1 by Jelmer Vernooij
Properly lookup revnos for brz-git push result.
132
class GitPushResult(PushResult):
133
134
    def _lookup_revno(self, revid):
0.406.2 by Jelmer Vernooij
Add tests.
135
        try:
136
            return _quick_lookup_revno(self.source_branch, self.target_branch,
7143.15.2 by Jelmer Vernooij
Run autopep8.
137
                                       revid)
0.406.2 by Jelmer Vernooij
Add tests.
138
        except GitSmartRemoteNotSupported:
139
            return None
0.406.1 by Jelmer Vernooij
Properly lookup revnos for brz-git push result.
140
141
    @property
142
    def old_revno(self):
143
        return self._lookup_revno(self.old_revid)
144
145
    @property
146
    def new_revno(self):
147
        return self._lookup_revno(self.new_revid)
148
149
0.200.695 by Jelmer Vernooij
Clean up trailing whitespace.
150
# Don't run any tests on GitSmartTransport as it is not intended to be
0.200.181 by Jelmer Vernooij
Support setting tags.
151
# a full implementation of Transport
152
def get_test_permutations():
153
    return []
154
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
155
0.200.708 by Jelmer Vernooij
Factor out URL parsing.
156
def split_git_url(url):
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
157
    """Split a Git URL.
158
159
    :param url: Git URL
160
    :return: Tuple with host, port, username, path.
161
    """
7290.38.1 by Jelmer Vernooij
Backport python3.8 support patch to breezy 3.0.
162
    parsed_url = urlparse.urlparse(url)
163
    path = urlparse.unquote(parsed_url.path)
0.246.2 by Jelmer Vernooij
Improve the fix dealing with git repo's in home directories.
164
    if path.startswith("/~"):
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
165
        path = path[1:]
7290.38.1 by Jelmer Vernooij
Backport python3.8 support patch to breezy 3.0.
166
    return ((parsed_url.hostname or '', parsed_url.port, parsed_url.username, path))
0.200.708 by Jelmer Vernooij
Factor out URL parsing.
167
168
0.200.1562 by Jelmer Vernooij
Add separate exception for remote errors.
169
class RemoteGitError(BzrError):
170
0.290.1 by Jelmer Vernooij
Avoid 'message' argument in RemoteGitError; apparently it breaks some versions of Python.
171
    _fmt = "Remote server error: %(msg)s"
0.200.1562 by Jelmer Vernooij
Add separate exception for remote errors.
172
173
7103.1.1 by Jelmer Vernooij
Improved error parsing for Git branches.
174
class HeadUpdateFailed(BzrError):
175
176
    _fmt = ("Unable to update remote HEAD branch. To update the master "
177
            "branch, specify the URL %(base_url)s,branch=master.")
178
179
    def __init__(self, base_url):
180
        super(HeadUpdateFailed, self).__init__()
181
        self.base_url = base_url
182
183
0.200.1275 by Jelmer Vernooij
recognize missing repositories
184
def parse_git_error(url, message):
185
    """Parse a remote git server error and return a bzr exception.
186
187
    :param url: URL of the remote repository
188
    :param message: Message sent by the remote git server
189
    """
190
    message = str(message).strip()
7143.15.2 by Jelmer Vernooij
Run autopep8.
191
    if (message.startswith("Could not find Repository ")
192
        or message == 'Repository not found.'
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
193
            or (message.startswith('Repository ') and
194
                message.endswith(' not found.'))):
0.200.1275 by Jelmer Vernooij
recognize missing repositories
195
        return NotBranchError(url, message)
0.200.1563 by Jelmer Vernooij
Improve error message.
196
    if message == "HEAD failed to update":
7441.1.1 by Jelmer Vernooij
Add strip_segment_parameters function.
197
        base_url = urlutils.strip_segment_parameters(url)
7103.1.1 by Jelmer Vernooij
Improved error parsing for Git branches.
198
        return HeadUpdateFailed(base_url)
7103.1.2 by Jelmer Vernooij
Handle PermissionDenied.
199
    if message.startswith('access denied or repository not exported:'):
7428.1.2 by Jelmer Vernooij
Don't require head whitespace.
200
        extra, path = message.split(':', 1)
201
        return PermissionDenied(path.strip(), extra)
7131.7.4 by Jelmer Vernooij
Don't use GitLab string.
202
    if message.endswith('You are not allowed to push code to this project.'):
7131.7.2 by Jelmer Vernooij
Handle github PermissionDenied.
203
        return PermissionDenied(url, message)
7131.7.3 by Jelmer Vernooij
Handle one more error.
204
    if message.endswith(' does not appear to be a git repository'):
205
        return NotBranchError(url, message)
7379.1.1 by Jelmer Vernooij
Handle invalid repository name on GitHub.
206
    if re.match('(.+) is not a valid repository name',
207
                message.splitlines()[0]):
208
        return NotBranchError(url, message)
7131.7.2 by Jelmer Vernooij
Handle github PermissionDenied.
209
    m = re.match(r'Permission to ([^ ]+) denied to ([^ ]+)\.', message)
210
    if m:
211
        return PermissionDenied(m.group(1), 'denied to %s' % m.group(2))
0.200.1275 by Jelmer Vernooij
recognize missing repositories
212
    # Don't know, just return it to the user as-is
0.200.1562 by Jelmer Vernooij
Add separate exception for remote errors.
213
    return RemoteGitError(message)
0.200.1275 by Jelmer Vernooij
recognize missing repositories
214
215
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
216
class GitSmartTransport(Transport):
217
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
218
    def __init__(self, url, _client=None):
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
219
        Transport.__init__(self, url)
0.200.708 by Jelmer Vernooij
Factor out URL parsing.
220
        (self._host, self._port, self._username, self._path) = \
221
            split_git_url(url)
0.200.707 by Jelmer Vernooij
Add debug routines.
222
        if 'transport' in debug.debug_flags:
223
            trace.mutter('host: %r, user: %r, port: %r, path: %r',
224
                         self._host, self._username, self._port, self._path)
0.200.166 by Jelmer Vernooij
don't reuse client objects.
225
        self._client = _client
0.200.1464 by Jelmer Vernooij
Warn about ignoring path segment parameters when using bzr 2.4.
226
        self._stripped_path = self._path.rsplit(",", 1)[0]
0.200.166 by Jelmer Vernooij
don't reuse client objects.
227
0.200.543 by Jelmer Vernooij
Implement GitSmartTransport.external_url().
228
    def external_url(self):
229
        return self.base
230
0.200.238 by Jelmer Vernooij
Import Transport.has().
231
    def has(self, relpath):
232
        return False
233
0.344.1 by Jelmer Vernooij
Allow using local git executable by accessing git:///some/path.
234
    def _get_client(self):
0.200.307 by Jelmer Vernooij
Support git+ssh.
235
        raise NotImplementedError(self._get_client)
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
236
0.200.470 by Jelmer Vernooij
Properly parse username in URLs.
237
    def _get_path(self):
0.200.1464 by Jelmer Vernooij
Warn about ignoring path segment parameters when using bzr 2.4.
238
        return self._stripped_path
0.200.470 by Jelmer Vernooij
Properly parse username in URLs.
239
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
240
    def get(self, path):
241
        raise NoSuchFile(path)
242
0.200.160 by Jelmer Vernooij
Implement abspath.
243
    def abspath(self, relpath):
244
        return urlutils.join(self.base, relpath)
245
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
246
    def clone(self, offset=None):
247
        """See Transport.clone()."""
248
        if offset is None:
249
            newurl = self.base
250
        else:
251
            newurl = urlutils.join(self.base, offset)
252
0.200.307 by Jelmer Vernooij
Support git+ssh.
253
        return self.__class__(newurl, self._client)
254
255
256
class TCPGitSmartTransport(GitSmartTransport):
257
0.200.332 by Jelmer Vernooij
Support activity reporting.
258
    _scheme = 'git'
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.344.1 by Jelmer Vernooij
Allow using local git executable by accessing git:///some/path.
265
        if self._host == '':
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
266
            # return dulwich.client.LocalGitClient()
267
            return dulwich.client.SubprocessGitClient()
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
268
        return dulwich.client.TCPGitClient(
269
            self._host, self._port, report_activity=self._report_activity)
0.200.307 by Jelmer Vernooij
Support git+ssh.
270
271
0.200.1624 by Jelmer Vernooij
Add ssh vendor for dulwich that uses the bzr ssh vendor.
272
class SSHSocketWrapper(object):
273
274
    def __init__(self, sock):
275
        self.sock = sock
276
277
    def read(self, len=None):
278
        return self.sock.recv(len)
279
280
    def write(self, data):
281
        return self.sock.write(data)
282
283
    def can_read(self):
284
        return len(select.select([self.sock.fileno()], [], [], 0)[0]) > 0
285
286
287
class DulwichSSHVendor(dulwich.client.SSHVendor):
288
289
    def __init__(self):
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
290
        from ..transport import ssh
0.200.1624 by Jelmer Vernooij
Add ssh vendor for dulwich that uses the bzr ssh vendor.
291
        self.bzr_ssh_vendor = ssh._get_ssh_vendor()
292
293
    def run_command(self, host, command, username=None, port=None):
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
294
        connection = self.bzr_ssh_vendor.connect_ssh(
295
            username=username, password=None, port=port, host=host,
296
            command=command)
0.200.1624 by Jelmer Vernooij
Add ssh vendor for dulwich that uses the bzr ssh vendor.
297
        (kind, io_object) = connection.get_sock_or_pipes()
298
        if kind == 'socket':
299
            return SSHSocketWrapper(io_object)
300
        else:
301
            raise AssertionError("Unknown io object kind %r'" % kind)
302
303
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
304
# dulwich.client.get_ssh_vendor = DulwichSSHVendor
0.200.1624 by Jelmer Vernooij
Add ssh vendor for dulwich that uses the bzr ssh vendor.
305
306
0.200.307 by Jelmer Vernooij
Support git+ssh.
307
class SSHGitSmartTransport(GitSmartTransport):
308
0.200.332 by Jelmer Vernooij
Support activity reporting.
309
    _scheme = 'git+ssh'
310
0.200.470 by Jelmer Vernooij
Properly parse username in URLs.
311
    def _get_path(self):
0.200.1464 by Jelmer Vernooij
Warn about ignoring path segment parameters when using bzr 2.4.
312
        path = self._stripped_path
0.200.1318 by Jelmer Vernooij
Strip segment parameters where necessary.
313
        if path.startswith("/~/"):
314
            return path[3:]
315
        return path
0.200.470 by Jelmer Vernooij
Properly parse username in URLs.
316
0.344.1 by Jelmer Vernooij
Allow using local git executable by accessing git:///some/path.
317
    def _get_client(self):
0.200.307 by Jelmer Vernooij
Support git+ssh.
318
        if self._client is not None:
319
            ret = self._client
320
            self._client = None
321
            return ret
0.253.1 by Ross Light
Added configuration options for git-upload-pack and git-receive-pack
322
        location_config = config.LocationConfig(self.base)
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
323
        client = dulwich.client.SSHGitClient(
324
            self._host, self._port, self._username,
325
            report_activity=self._report_activity)
0.253.1 by Ross Light
Added configuration options for git-upload-pack and git-receive-pack
326
        # Set up alternate pack program paths
327
        upload_pack = location_config.get_user_option('git_upload_pack')
328
        if upload_pack:
0.200.949 by Jelmer Vernooij
merge support for specifying alternative paths for git executables.
329
            client.alternative_paths["upload-pack"] = upload_pack
0.253.1 by Ross Light
Added configuration options for git-upload-pack and git-receive-pack
330
        receive_pack = location_config.get_user_option('git_receive_pack')
331
        if receive_pack:
0.200.949 by Jelmer Vernooij
merge support for specifying alternative paths for git executables.
332
            client.alternative_paths["receive-pack"] = receive_pack
0.253.1 by Ross Light
Added configuration options for git-upload-pack and git-receive-pack
333
        return client
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
334
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
335
0.295.1 by Jelmer Vernooij
Split up branch formats.
336
class RemoteGitBranchFormat(GitBranchFormat):
337
338
    def get_format_description(self):
339
        return 'Remote Git Branch'
340
341
    @property
342
    def _matchingcontroldir(self):
343
        return RemoteGitControlDirFormat()
344
0.295.2 by Jelmer Vernooij
Make RemoteGitBranchFormat uninitializeable.
345
    def initialize(self, a_controldir, name=None, repository=None,
346
                   append_revisions_only=None):
347
        raise UninitializableFormat(self)
348
0.295.1 by Jelmer Vernooij
Split up branch formats.
349
0.407.1 by Jelmer Vernooij
Improve progress reporting.
350
class DefaultProgressReporter(object):
351
352
    _GIT_PROGRESS_PARTIAL_RE = re.compile(r"(.*?): +(\d+)% \((\d+)/(\d+)\)")
353
    _GIT_PROGRESS_TOTAL_RE = re.compile(r"(.*?): (\d+)")
354
355
    def __init__(self, pb):
356
        self.pb = pb
357
358
    def progress(self, text):
7018.3.2 by Jelmer Vernooij
Fix some git tests.
359
        text = text.rstrip(b"\r\n")
360
        text = text.decode('utf-8')
7131.7.1 by Jelmer Vernooij
Handle permission denied by GitLab.
361
        if text.lower().startswith('error: '):
7018.3.2 by Jelmer Vernooij
Fix some git tests.
362
            trace.show_error('git: %s', text[len(b'error: '):])
0.405.1 by Jelmer Vernooij
Use same logic for interpreting progress reports everywhere.
363
        else:
0.407.1 by Jelmer Vernooij
Improve progress reporting.
364
            trace.mutter("git: %s", text)
365
            g = self._GIT_PROGRESS_PARTIAL_RE.match(text)
0.405.1 by Jelmer Vernooij
Use same logic for interpreting progress reports everywhere.
366
            if g is not None:
0.407.1 by Jelmer Vernooij
Improve progress reporting.
367
                (text, pct, current, total) = g.groups()
368
                self.pb.update(text, int(current), int(total))
0.405.1 by Jelmer Vernooij
Use same logic for interpreting progress reports everywhere.
369
            else:
0.407.1 by Jelmer Vernooij
Improve progress reporting.
370
                g = self._GIT_PROGRESS_TOTAL_RE.match(text)
371
                if g is not None:
372
                    (text, total) = g.groups()
373
                    self.pb.update(text, None, int(total))
374
                else:
375
                    trace.note("%s", text)
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
376
377
0.200.148 by Jelmer Vernooij
Share more infrastructure between LocalGitDir and RemoteGitDir.
378
class RemoteGitDir(GitDir):
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
379
0.344.1 by Jelmer Vernooij
Allow using local git executable by accessing git:///some/path.
380
    def __init__(self, transport, format, client, client_path):
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
381
        self._format = format
382
        self.root_transport = transport
383
        self.transport = transport
0.200.381 by Jelmer Vernooij
Support working trees properly, status and ls.
384
        self._mode_check_done = None
0.344.1 by Jelmer Vernooij
Allow using local git executable by accessing git:///some/path.
385
        self._client = client
0.200.1336 by Jelmer Vernooij
Support the git smart server http protocol.
386
        self._client_path = client_path
0.200.1396 by Jelmer Vernooij
Support updating tags in remote branches during pull.
387
        self.base = self.root_transport.base
0.200.1434 by Jelmer Vernooij
Move refs access to control dir.
388
        self._refs = None
0.200.1335 by Jelmer Vernooij
Move _get_client.
389
0.322.1 by Jelmer Vernooij
Fix access of remote git branches.
390
    @property
391
    def _gitrepository_class(self):
392
        return RemoteGitRepository
393
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
394
    def archive(self, format, committish, write_data, progress=None,
7143.2.1 by Jelmer Vernooij
Don't hardcode the list of supported archive formats.
395
                write_error=None, subdirs=None, prefix=None):
6968.4.1 by Jelmer Vernooij
Add support for exporting archives in Git.
396
        if progress is None:
397
            pb = ui.ui_factory.nested_progress_bar()
398
            progress = DefaultProgressReporter(pb).progress
399
        else:
400
            pb = None
7143.2.1 by Jelmer Vernooij
Don't hardcode the list of supported archive formats.
401
        def progress_wrapper(message):
402
            if message.startswith(b"fatal: Unknown archive format \'"):
403
                format = message.strip()[len(b"fatal: Unknown archive format '"):-1]
404
                raise errors.NoSuchExportFormat(format.decode('ascii'))
405
            return progress(message)
6968.4.1 by Jelmer Vernooij
Add support for exporting archives in Git.
406
        try:
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
407
            self._client.archive(
7143.2.1 by Jelmer Vernooij
Don't hardcode the list of supported archive formats.
408
                self._client_path, committish, write_data, progress_wrapper,
409
                write_error,
410
                format=(format.encode('ascii') if format else None),
411
                subdirs=subdirs,
412
                prefix=(prefix.encode('utf-8') if prefix else None))
6968.4.1 by Jelmer Vernooij
Add support for exporting archives in Git.
413
        except GitProtocolError as e:
414
            raise parse_git_error(self.transport.external_url(), e)
415
        finally:
416
            if pb is not None:
417
                pb.finished()
418
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
419
    def fetch_pack(self, determine_wants, graph_walker, pack_data,
420
                   progress=None):
0.200.1335 by Jelmer Vernooij
Move _get_client.
421
        if progress is None:
0.405.1 by Jelmer Vernooij
Use same logic for interpreting progress reports everywhere.
422
            pb = ui.ui_factory.nested_progress_bar()
0.407.1 by Jelmer Vernooij
Improve progress reporting.
423
            progress = DefaultProgressReporter(pb).progress
0.405.1 by Jelmer Vernooij
Use same logic for interpreting progress reports everywhere.
424
        else:
425
            pb = None
0.200.1335 by Jelmer Vernooij
Move _get_client.
426
        try:
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
427
            result = self._client.fetch_pack(
428
                self._client_path, determine_wants, graph_walker, pack_data,
429
                progress)
0.376.1 by Jelmer Vernooij
Add tests for remote operations.
430
            if result.refs is None:
431
                result.refs = {}
7143.15.2 by Jelmer Vernooij
Run autopep8.
432
            self._refs = remote_refs_dict_to_container(
433
                result.refs, result.symrefs)
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
434
            return result
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
435
        except GitProtocolError as e:
0.200.1335 by Jelmer Vernooij
Move _get_client.
436
            raise parse_git_error(self.transport.external_url(), e)
0.405.1 by Jelmer Vernooij
Use same logic for interpreting progress reports everywhere.
437
        finally:
438
            if pb is not None:
439
                pb.finished()
0.200.1335 by Jelmer Vernooij
Move _get_client.
440
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
441
    def send_pack(self, get_changed_refs, generate_pack_data, progress=None):
442
        if progress is None:
0.405.1 by Jelmer Vernooij
Use same logic for interpreting progress reports everywhere.
443
            pb = ui.ui_factory.nested_progress_bar()
0.407.1 by Jelmer Vernooij
Improve progress reporting.
444
            progress = DefaultProgressReporter(pb).progress
0.405.1 by Jelmer Vernooij
Use same logic for interpreting progress reports everywhere.
445
        else:
446
            pb = None
7143.15.2 by Jelmer Vernooij
Run autopep8.
447
7484.1.1 by Jelmer Vernooij
Follow symrefs when pushing to git repositories.
448
        def get_changed_refs_wrapper(remote_refs):
7484.1.2 by Jelmer Vernooij
Add some tests.
449
            if self._refs is not None:
450
                update_refs_container(self._refs, remote_refs)
7484.1.1 by Jelmer Vernooij
Follow symrefs when pushing to git repositories.
451
            return get_changed_refs(remote_refs)
0.200.1335 by Jelmer Vernooij
Move _get_client.
452
        try:
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
453
            return self._client.send_pack(
454
                self._client_path, get_changed_refs_wrapper,
455
                generate_pack_data, progress)
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
456
        except GitProtocolError as e:
0.200.1335 by Jelmer Vernooij
Move _get_client.
457
            raise parse_git_error(self.transport.external_url(), e)
0.405.1 by Jelmer Vernooij
Use same logic for interpreting progress reports everywhere.
458
        finally:
459
            if pb is not None:
460
                pb.finished()
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
461
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
462
    def create_branch(self, name=None, repository=None,
463
                      append_revisions_only=None, ref=None):
464
        refname = self._get_selected_ref(name, ref)
465
        if refname != b'HEAD' and refname in self.get_refs_container():
466
            raise AlreadyBranchError(self.user_url)
7484.1.1 by Jelmer Vernooij
Follow symrefs when pushing to git repositories.
467
        ref_chain, unused_sha = self.get_refs_container().follow(
7484.1.2 by Jelmer Vernooij
Add some tests.
468
            self._get_selected_ref(name))
7484.1.1 by Jelmer Vernooij
Follow symrefs when pushing to git repositories.
469
        if ref_chain and ref_chain[0] == b'HEAD':
470
            refname = ref_chain[1]
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
471
        repo = self.open_repository()
472
        return RemoteGitBranch(self, repo, refname)
473
0.200.1393 by Jelmer Vernooij
Implement removal of remote branches.
474
    def destroy_branch(self, name=None):
475
        refname = self._get_selected_ref(name)
7143.15.2 by Jelmer Vernooij
Run autopep8.
476
0.200.1393 by Jelmer Vernooij
Implement removal of remote branches.
477
        def get_changed_refs(old_refs):
7240.3.1 by Jelmer Vernooij
When sending refs to a remote server, don't send a copy of the old refs.
478
            ret = {}
7240.3.2 by Jelmer Vernooij
Fix tests.
479
            if refname not in old_refs:
0.200.1395 by Jelmer Vernooij
Fix error reporting.
480
                raise NotBranchError(self.user_url)
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
481
            ret[refname] = dulwich.client.ZERO_SHA
0.200.1393 by Jelmer Vernooij
Implement removal of remote branches.
482
            return ret
7143.15.2 by Jelmer Vernooij
Run autopep8.
483
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
484
        def generate_pack_data(have, want, ofs_delta=False):
485
            return pack_objects_to_data([])
486
        self.send_pack(get_changed_refs, generate_pack_data)
0.200.1393 by Jelmer Vernooij
Implement removal of remote branches.
487
0.200.1068 by Jelmer Vernooij
Implement user_url/control_url.
488
    @property
489
    def user_url(self):
490
        return self.control_url
491
0.200.1314 by Jelmer Vernooij
Provide RemoteGitDir.user_transport.
492
    @property
493
    def user_transport(self):
494
        return self.root_transport
495
0.200.1395 by Jelmer Vernooij
Fix error reporting.
496
    @property
497
    def control_url(self):
498
        return self.control_transport.base
499
500
    @property
501
    def control_transport(self):
502
        return self.root_transport
503
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
504
    def open_repository(self):
0.200.1415 by Jelmer Vernooij
Fix lock files for remote directories.
505
        return RemoteGitRepository(self)
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
506
7142.3.1 by Jelmer Vernooij
Support .nick on remote branches and fix get_branch_reference.
507
    def get_branch_reference(self, name=None):
508
        ref = branch_name_to_ref(name)
509
        val = self.get_refs_container().read_ref(ref)
510
        if val.startswith(SYMREF):
511
            return val[len(SYMREF):]
512
        return None
513
0.200.1310 by Jelmer Vernooij
Add _get_selected_ref method.
514
    def open_branch(self, name=None, unsupported=False,
7143.15.2 by Jelmer Vernooij
Run autopep8.
515
                    ignore_fallbacks=False, ref=None, possible_transports=None,
516
                    nascent_ok=False):
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
517
        repo = self.open_repository()
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
518
        ref = self._get_selected_ref(name, ref)
7143.2.1 by Jelmer Vernooij
Don't hardcode the list of supported archive formats.
519
        try:
520
            if not nascent_ok and ref not in self.get_refs_container():
7143.16.10 by Jelmer Vernooij
Fix E128.
521
                raise NotBranchError(
522
                    self.root_transport.base, controldir=self)
7143.2.1 by Jelmer Vernooij
Don't hardcode the list of supported archive formats.
523
        except NotGitRepository:
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
524
            raise NotBranchError(self.root_transport.base,
7143.15.2 by Jelmer Vernooij
Run autopep8.
525
                                 controldir=self)
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
526
        ref_chain, unused_sha = self.get_refs_container().follow(ref)
527
        return RemoteGitBranch(self, repo, ref_chain[-1])
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
528
0.200.662 by Jelmer Vernooij
Deal with recommend_upgrade argument to open_workingtree.
529
    def open_workingtree(self, recommend_upgrade=False):
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
530
        raise NotLocalUrl(self.transport.base)
531
0.310.4 by Jelmer Vernooij
Implement RemoteControlDir.has_workingtree.
532
    def has_workingtree(self):
533
        return False
534
0.200.1489 by Jelmer Vernooij
More fixes to peel handling.
535
    def get_peeled(self, name):
536
        return self.get_refs_container().get_peeled(name)
537
0.200.1487 by Jelmer Vernooij
Use peeling.
538
    def get_refs_container(self):
0.200.1434 by Jelmer Vernooij
Move refs access to control dir.
539
        if self._refs is not None:
540
            return self._refs
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
541
        result = self.fetch_pack(lambda x: None, None,
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
542
                                 lambda x: None,
543
                                 lambda x: trace.mutter("git: %s" % x))
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
544
        self._refs = remote_refs_dict_to_container(
7143.15.2 by Jelmer Vernooij
Run autopep8.
545
            result.refs, result.symrefs)
0.200.1434 by Jelmer Vernooij
Move refs access to control dir.
546
        return self._refs
547
0.401.4 by Jelmer Vernooij
Implement RemoteGitDir.push_branch.
548
    def push_branch(self, source, revision_id=None, overwrite=False,
549
                    remember=False, create_prefix=False, lossy=False,
550
                    name=None):
551
        """Push the source branch into this ControlDir."""
552
        if revision_id is None:
553
            # No revision supplied by the user, default to the branch
554
            # revision
555
            revision_id = source.last_revision()
556
0.406.1 by Jelmer Vernooij
Properly lookup revnos for brz-git push result.
557
        push_result = GitPushResult()
0.401.4 by Jelmer Vernooij
Implement RemoteGitDir.push_branch.
558
        push_result.workingtree_updated = None
559
        push_result.master_branch = None
560
        push_result.source_branch = source
561
        push_result.stacked_on = None
562
        push_result.branch_push_result = None
563
        repo = self.find_repository()
564
        refname = self._get_selected_ref(name)
7484.1.1 by Jelmer Vernooij
Follow symrefs when pushing to git repositories.
565
        ref_chain, old_sha = self.get_refs_container().follow(refname)
566
        if ref_chain:
567
            actual_refname = ref_chain[-1]
568
        else:
569
            actual_refname = refname
0.407.1 by Jelmer Vernooij
Improve progress reporting.
570
        if isinstance(source, GitBranch) and lossy:
571
            raise errors.LossyPushToSameVCS(source.controldir, self)
0.401.4 by Jelmer Vernooij
Implement RemoteGitDir.push_branch.
572
        source_store = get_object_store(source.repository)
7289.1.2 by Jelmer Vernooij
Fix pushing of tags as part of nascent git branches.
573
        fetch_tags = source.get_config_stack().get('branch.fetch_tags')
7484.1.1 by Jelmer Vernooij
Follow symrefs when pushing to git repositories.
574
        def get_changed_refs(remote_refs):
7484.1.2 by Jelmer Vernooij
Add some tests.
575
            if self._refs is not None:
576
                update_refs_container(self._refs, remote_refs)
7289.1.2 by Jelmer Vernooij
Fix pushing of tags as part of nascent git branches.
577
            ret = {}
578
            # TODO(jelmer): Unpeel if necessary
579
            push_result.new_original_revid = revision_id
580
            if lossy:
581
                new_sha = source_store._lookup_revision_sha1(revision_id)
582
            else:
583
                try:
584
                    new_sha = repo.lookup_bzr_revision_id(revision_id)[0]
585
                except errors.NoSuchRevision:
586
                    raise errors.NoRoundtrippingSupport(
587
                        source, self.open_branch(name=name, nascent_ok=True))
588
            if not overwrite:
7484.1.1 by Jelmer Vernooij
Follow symrefs when pushing to git repositories.
589
                if remote_divergence(old_sha, new_sha, source_store):
7289.1.2 by Jelmer Vernooij
Fix pushing of tags as part of nascent git branches.
590
                    raise DivergedBranches(
591
                        source, self.open_branch(name, nascent_ok=True))
7484.1.1 by Jelmer Vernooij
Follow symrefs when pushing to git repositories.
592
            ret[actual_refname] = new_sha
7289.1.2 by Jelmer Vernooij
Fix pushing of tags as part of nascent git branches.
593
            if fetch_tags:
7479.2.1 by Jelmer Vernooij
Drop python2 support.
594
                for tagname, revid in source.tags.get_tag_dict().items():
7289.1.2 by Jelmer Vernooij
Fix pushing of tags as part of nascent git branches.
595
                    if lossy:
7489.1.1 by Jelmer Vernooij
Ignore ghost tags when pushing to a remote git repo.
596
                        try:
597
                            new_sha = source_store._lookup_revision_sha1(revid)
598
                        except KeyError:
599
                            if source.repository.has_revision(revid):
600
                                raise
7289.1.2 by Jelmer Vernooij
Fix pushing of tags as part of nascent git branches.
601
                    else:
602
                        try:
603
                            new_sha = repo.lookup_bzr_revision_id(revid)[0]
604
                        except errors.NoSuchRevision:
605
                            continue
7289.1.5 by Jelmer Vernooij
Fix flake8 warning.
606
                    ret[tag_name_to_ref(tagname)] = new_sha
7289.1.2 by Jelmer Vernooij
Fix pushing of tags as part of nascent git branches.
607
            return ret
0.403.3 by Jelmer Vernooij
Test RemoteGitDir.push_branch.
608
        with source_store.lock_read():
609
            if lossy:
610
                generate_pack_data = source_store.generate_lossy_pack_data
611
            else:
612
                generate_pack_data = source_store.generate_pack_data
613
            new_refs = self.send_pack(get_changed_refs, generate_pack_data)
0.401.4 by Jelmer Vernooij
Implement RemoteGitDir.push_branch.
614
        push_result.new_revid = repo.lookup_foreign_revision_id(
7484.1.1 by Jelmer Vernooij
Follow symrefs when pushing to git repositories.
615
            new_refs[actual_refname])
7484.1.2 by Jelmer Vernooij
Add some tests.
616
        if old_sha is not None:
617
            push_result.old_revid = repo.lookup_foreign_revision_id(old_sha)
618
        else:
619
            push_result.old_revid = NULL_REVISION
620
        if self._refs is not None:
621
            update_refs_container(self._refs, new_refs)
0.401.4 by Jelmer Vernooij
Implement RemoteGitDir.push_branch.
622
        push_result.target_branch = self.open_branch(name)
7484.1.2 by Jelmer Vernooij
Add some tests.
623
        if old_sha is not None:
0.403.3 by Jelmer Vernooij
Test RemoteGitDir.push_branch.
624
            push_result.branch_push_result = GitBranchPushResult()
625
            push_result.branch_push_result.source_branch = source
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
626
            push_result.branch_push_result.target_branch = (
627
                push_result.target_branch)
0.403.3 by Jelmer Vernooij
Test RemoteGitDir.push_branch.
628
            push_result.branch_push_result.local_branch = None
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
629
            push_result.branch_push_result.master_branch = (
630
                push_result.target_branch)
0.403.3 by Jelmer Vernooij
Test RemoteGitDir.push_branch.
631
            push_result.branch_push_result.old_revid = push_result.old_revid
632
            push_result.branch_push_result.new_revid = push_result.new_revid
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
633
            push_result.branch_push_result.new_original_revid = (
634
                push_result.new_original_revid)
0.401.4 by Jelmer Vernooij
Implement RemoteGitDir.push_branch.
635
        if source.get_push_location() is None or remember:
636
            source.set_push_location(push_result.target_branch.base)
637
        return push_result
638
0.409.1 by Jelmer Vernooij
Don't probe for commondir over remote transport.
639
    def _find_commondir(self):
640
        # There is no way to find the commondir, if there is any.
641
        return self
642
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
643
0.225.2 by Jelmer Vernooij
Handle situation when repository is already up to date during pull.
644
class EmptyObjectStoreIterator(dict):
645
646
    def iterobjects(self):
647
        return []
648
649
0.200.218 by Jelmer Vernooij
Simplify TemporaryPack implementation.
650
class TemporaryPackIterator(Pack):
651
0.200.226 by Jelmer Vernooij
Merge thin-pack work.
652
    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.
653
        super(TemporaryPackIterator, self).__init__(
654
            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.
655
        self._idx_load = lambda: self._idx_load_or_generate(self._idx_path)
0.200.226 by Jelmer Vernooij
Merge thin-pack work.
656
0.278.2 by William Grant
Also override _idx_load rather than index, to be a bit cleaner.
657
    def _idx_load_or_generate(self, path):
658
        if not os.path.exists(path):
7143.22.2 by Jelmer Vernooij
use more context libs for progress bars.
659
            with ui.ui_factory.nested_progress_bar() as pb:
0.278.2 by William Grant
Also override _idx_load rather than index, to be a bit cleaner.
660
                def report_progress(cur, total):
661
                    pb.update("generating index", cur, total)
7143.22.3 by Jelmer Vernooij
merge trunk.
662
                self.data.create_index(path, progress=report_progress)
0.278.2 by William Grant
Also override _idx_load rather than index, to be a bit cleaner.
663
        return load_pack_index(path)
0.200.205 by Jelmer Vernooij
Fix remote fetching.
664
665
    def __del__(self):
0.200.611 by Jelmer Vernooij
Merge warning fix from Naoki.
666
        if self._idx is not None:
0.241.1 by Naoki INADA
Fix can't delete tempfile on Windows
667
            self._idx.close()
668
            os.remove(self._idx_path)
0.200.611 by Jelmer Vernooij
Merge warning fix from Naoki.
669
        if self._data is not None:
0.241.1 by Naoki INADA
Fix can't delete tempfile on Windows
670
            self._data.close()
671
            os.remove(self._data_path)
0.200.205 by Jelmer Vernooij
Fix remote fetching.
672
673
0.200.1337 by Jelmer Vernooij
Re-use http connection if possible.
674
class BzrGitHttpClient(dulwich.client.HttpGitClient):
675
676
    def __init__(self, transport, *args, **kwargs):
677
        self.transport = transport
7268.10.2 by Jelmer Vernooij
Strip username.
678
        url = urlutils.URL.from_string(transport.external_url())
679
        url.user = url.quoted_user = None
680
        url.password = url.quoted_password = None
7441.1.1 by Jelmer Vernooij
Add strip_segment_parameters function.
681
        url = urlutils.strip_segment_parameters(str(url))
7371.3.2 by Jelmer Vernooij
Fix URL parsing for Git.
682
        super(BzrGitHttpClient, self).__init__(url, *args, **kwargs)
0.409.2 by Jelmer Vernooij
call out to HTTP transport rather than creating new connection.
683
684
    def _http_request(self, url, headers=None, data=None,
685
                      allow_compression=False):
686
        """Perform HTTP request.
687
688
        :param url: Request URL.
689
        :param headers: Optional custom headers to override defaults.
690
        :param data: Request data.
691
        :param allow_compression: Allow GZipped communication.
692
        :return: Tuple (`response`, `read`), where response is an `urllib3`
7140.1.1 by Jelmer Vernooij
Rollback https://code.launchpad.net/~jelmer/brz/python3-git-fix-http/+merge/356238
693
            response object with additional `content_type` and
694
            `redirect_location` properties, and `read` is a consumable read
695
            method for the response data.
0.409.2 by Jelmer Vernooij
call out to HTTP transport rather than creating new connection.
696
        """
7359.1.1 by Jelmer Vernooij
Only set user agent for GitHub.
697
        if is_github_url(url):
698
            headers['User-agent'] = user_agent_for_github()
0.409.2 by Jelmer Vernooij
call out to HTTP transport rather than creating new connection.
699
        headers["Pragma"] = "no-cache"
700
        if allow_compression:
701
            headers["Accept-Encoding"] = "gzip"
702
        else:
703
            headers["Accept-Encoding"] = "identity"
704
7296.2.2 by Jelmer Vernooij
Add a urllib3-like interface.
705
        response = self.transport.request(
0.409.2 by Jelmer Vernooij
call out to HTTP transport rather than creating new connection.
706
            ('GET' if data is None else 'POST'),
7320.1.1 by Jelmer Vernooij
Fix git http support.
707
            url,
7296.2.2 by Jelmer Vernooij
Add a urllib3-like interface.
708
            body=data,
709
            headers=headers, retries=8)
710
711
        if response.status == 404:
0.409.2 by Jelmer Vernooij
call out to HTTP transport rather than creating new connection.
712
            raise NotGitRepository()
7296.2.2 by Jelmer Vernooij
Add a urllib3-like interface.
713
        elif response.status != 200:
0.409.2 by Jelmer Vernooij
call out to HTTP transport rather than creating new connection.
714
            raise GitProtocolError("unexpected http resp %d for %s" %
715
                                   (response.code, url))
716
717
        # TODO: Optimization available by adding `preload_content=False` to the
718
        # request and just passing the `read` method on instead of going via
719
        # `BytesIO`, if we can guarantee that the entire response is consumed
720
        # before issuing the next to still allow for connection reuse from the
721
        # pool.
722
        if response.getheader("Content-Encoding") == "gzip":
7404.5.3 by Jelmer Vernooij
Reuse connections.
723
            read = gzip.GzipFile(fileobj=BytesIO(response.read())).read
0.409.2 by Jelmer Vernooij
call out to HTTP transport rather than creating new connection.
724
        else:
725
            read = response.read
726
727
        class WrapResponse(object):
728
729
            def __init__(self, response):
730
                self._response = response
7320.1.1 by Jelmer Vernooij
Fix git http support.
731
                self.status = response.status
0.409.2 by Jelmer Vernooij
call out to HTTP transport rather than creating new connection.
732
                self.content_type = response.getheader("Content-Type")
7320.1.1 by Jelmer Vernooij
Fix git http support.
733
                self.redirect_location = response._actual.geturl()
0.409.2 by Jelmer Vernooij
call out to HTTP transport rather than creating new connection.
734
7143.2.1 by Jelmer Vernooij
Don't hardcode the list of supported archive formats.
735
            def readlines(self):
736
                return self._response.readlines()
737
0.409.2 by Jelmer Vernooij
call out to HTTP transport rather than creating new connection.
738
            def close(self):
7320.1.1 by Jelmer Vernooij
Fix git http support.
739
                pass
0.409.2 by Jelmer Vernooij
call out to HTTP transport rather than creating new connection.
740
741
        return WrapResponse(response), read
0.200.1337 by Jelmer Vernooij
Re-use http connection if possible.
742
743
7371.3.2 by Jelmer Vernooij
Fix URL parsing for Git.
744
def _git_url_and_path_from_transport(external_url):
7441.1.1 by Jelmer Vernooij
Add strip_segment_parameters function.
745
    url = urlutils.strip_segment_parameters(external_url)
7371.3.2 by Jelmer Vernooij
Fix URL parsing for Git.
746
    return urlparse.urlsplit(url)
747
748
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
749
class RemoteGitControlDirFormat(GitControlDirFormat):
750
    """The .git directory control format."""
751
752
    supports_workingtrees = False
753
754
    @classmethod
755
    def _known_formats(self):
756
        return set([RemoteGitControlDirFormat()])
757
0.295.1 by Jelmer Vernooij
Split up branch formats.
758
    def get_branch_format(self):
759
        return RemoteGitBranchFormat()
760
7290.20.3 by Jelmer Vernooij
Fix tests for git/full history branches.
761
    @property
762
    def repository_format(self):
763
        return GitRepositoryFormat()
764
0.200.1413 by Jelmer Vernooij
Fix is_initializable()
765
    def is_initializable(self):
766
        return False
767
768
    def is_supported(self):
769
        return True
770
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
771
    def open(self, transport, _found=None):
772
        """Open this directory.
773
774
        """
7371.3.2 by Jelmer Vernooij
Fix URL parsing for Git.
775
        split_url = _git_url_and_path_from_transport(transport.external_url())
0.200.1336 by Jelmer Vernooij
Support the git smart server http protocol.
776
        if isinstance(transport, GitSmartTransport):
0.344.1 by Jelmer Vernooij
Allow using local git executable by accessing git:///some/path.
777
            client = transport._get_client()
7371.3.2 by Jelmer Vernooij
Fix URL parsing for Git.
778
        elif split_url.scheme in ("http", "https"):
0.344.1 by Jelmer Vernooij
Allow using local git executable by accessing git:///some/path.
779
            client = BzrGitHttpClient(transport)
7380.1.1 by Jelmer Vernooij
Several more fixes for git merge proposals.
780
        elif split_url.scheme in ('file', ):
0.344.1 by Jelmer Vernooij
Allow using local git executable by accessing git:///some/path.
781
            client = dulwich.client.LocalGitClient()
0.200.1336 by Jelmer Vernooij
Support the git smart server http protocol.
782
        else:
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
783
            raise NotBranchError(transport.base)
0.344.1 by Jelmer Vernooij
Allow using local git executable by accessing git:///some/path.
784
        if not _found:
7143.15.2 by Jelmer Vernooij
Run autopep8.
785
            pass  # TODO(jelmer): Actually probe for something
7371.3.2 by Jelmer Vernooij
Fix URL parsing for Git.
786
        return RemoteGitDir(transport, self, client, split_url.path)
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
787
788
    def get_format_description(self):
789
        return "Remote Git Repository"
790
791
    def initialize_on_transport(self, transport):
792
        raise UninitializableFormat(self)
793
0.200.1412 by Jelmer Vernooij
Implement GitControlDirFormat.supports_transport.
794
    def supports_transport(self, transport):
795
        try:
796
            external_url = transport.external_url()
797
        except InProcessTransport:
798
            raise NotBranchError(path=transport.base)
7143.15.2 by Jelmer Vernooij
Run autopep8.
799
        return (external_url.startswith("http:")
800
                or external_url.startswith("https:")
801
                or external_url.startswith("git+")
802
                or external_url.startswith("git:"))
0.200.1412 by Jelmer Vernooij
Implement GitControlDirFormat.supports_transport.
803
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
804
6968.4.1 by Jelmer Vernooij
Add support for exporting archives in Git.
805
class GitRemoteRevisionTree(RevisionTree):
806
6968.4.4 by Jelmer Vernooij
Update for API changes from archive branch.
807
    def archive(self, format, name, root=None, subdir=None, force_mtime=None):
6968.4.1 by Jelmer Vernooij
Add support for exporting archives in Git.
808
        """Create an archive of this tree.
809
6968.4.4 by Jelmer Vernooij
Update for API changes from archive branch.
810
        :param format: Format name (e.g. 'tar')
6968.4.1 by Jelmer Vernooij
Add support for exporting archives in Git.
811
        :param name: target file name
812
        :param root: Root directory name (or None)
813
        :param subdir: Subdirectory to export (or None)
814
        :return: Iterator over archive chunks
815
        """
816
        commit = self._repository.lookup_bzr_revision_id(
817
            self.get_revision_id())[0]
6968.4.4 by Jelmer Vernooij
Update for API changes from archive branch.
818
        f = tempfile.SpooledTemporaryFile()
819
        # git-upload-archive(1) generaly only supports refs. So let's see if we
820
        # can find one.
6968.4.1 by Jelmer Vernooij
Add support for exporting archives in Git.
821
        reverse_refs = {
7143.15.2 by Jelmer Vernooij
Run autopep8.
822
            v: k for (k, v) in
823
            self._repository.controldir.get_refs_container().as_dict().items()}
6968.4.4 by Jelmer Vernooij
Update for API changes from archive branch.
824
        try:
825
            committish = reverse_refs[commit]
826
        except KeyError:
827
            # No? Maybe the user has uploadArchive.allowUnreachable enabled.
828
            # Let's hope for the best.
829
            committish = commit
6968.4.1 by Jelmer Vernooij
Add support for exporting archives in Git.
830
        self._repository.archive(
7143.15.2 by Jelmer Vernooij
Run autopep8.
831
            format, committish, f.write,
832
            subdirs=([subdir] if subdir else None),
833
            prefix=(root + '/') if root else '')
6968.4.1 by Jelmer Vernooij
Add support for exporting archives in Git.
834
        f.seek(0)
6968.4.4 by Jelmer Vernooij
Update for API changes from archive branch.
835
        return osutils.file_iterator(f)
6968.4.1 by Jelmer Vernooij
Add support for exporting archives in Git.
836
7192.5.1 by Jelmer Vernooij
Remove more file ids.
837
    def is_versioned(self, path):
7143.2.1 by Jelmer Vernooij
Don't hardcode the list of supported archive formats.
838
        raise GitSmartRemoteNotSupported(self.is_versioned, self)
839
840
    def has_filename(self, path):
841
        raise GitSmartRemoteNotSupported(self.has_filename, self)
842
7192.5.1 by Jelmer Vernooij
Remove more file ids.
843
    def get_file_text(self, path):
7143.2.1 by Jelmer Vernooij
Don't hardcode the list of supported archive formats.
844
        raise GitSmartRemoteNotSupported(self.get_file_text, self)
845
7413.4.4 by Jelmer Vernooij
'Implement' RevisionTree.list_files.
846
    def list_files(self, include_root=False, from_dir=None, recursive=True):
847
        raise GitSmartRemoteNotSupported(self.list_files, self)
848
6968.4.1 by Jelmer Vernooij
Add support for exporting archives in Git.
849
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
850
class RemoteGitRepository(GitRepository):
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
851
7254.5.1 by Jelmer Vernooij
Add supports_random_access attribute to repositories.
852
    supports_random_access = False
853
0.200.319 by Jelmer Vernooij
Print proper error when trying unsupported operations against a git server.
854
    @property
0.200.1068 by Jelmer Vernooij
Implement user_url/control_url.
855
    def user_url(self):
856
        return self.control_url
857
0.200.1288 by Jelmer Vernooij
Properly raise GitRemoteNotSupported from RemoteGitRepository.
858
    def get_parent_map(self, revids):
0.200.1398 by Jelmer Vernooij
Make GitSmartRemoteNotSupported derive from UnsupportedOperation.
859
        raise GitSmartRemoteNotSupported(self.get_parent_map, self)
0.200.319 by Jelmer Vernooij
Print proper error when trying unsupported operations against a git server.
860
6968.4.1 by Jelmer Vernooij
Add support for exporting archives in Git.
861
    def archive(self, *args, **kwargs):
862
        return self.controldir.archive(*args, **kwargs)
863
0.200.695 by Jelmer Vernooij
Clean up trailing whitespace.
864
    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.
865
                   progress=None):
7143.2.1 by Jelmer Vernooij
Don't hardcode the list of supported archive formats.
866
        return self.controldir.fetch_pack(
7143.16.8 by Jelmer Vernooij
Fix E126
867
            determine_wants, graph_walker, pack_data, progress)
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
868
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
869
    def send_pack(self, get_changed_refs, generate_pack_data):
870
        return self.controldir.send_pack(get_changed_refs, generate_pack_data)
0.200.427 by Jelmer Vernooij
make send_pack accessible.
871
0.200.695 by Jelmer Vernooij
Clean up trailing whitespace.
872
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref,
873
                      progress=None):
0.200.167 by Jelmer Vernooij
Implement fetch_objects properly.
874
        fd, path = tempfile.mkstemp(suffix=".pack")
0.200.1299 by Jelmer Vernooij
Make sure file gets closed.
875
        try:
876
            self.fetch_pack(determine_wants, graph_walker,
7143.15.2 by Jelmer Vernooij
Run autopep8.
877
                            lambda x: os.write(fd, x), progress)
0.200.1299 by Jelmer Vernooij
Make sure file gets closed.
878
        finally:
879
            os.close(fd)
0.200.226 by Jelmer Vernooij
Merge thin-pack work.
880
        if os.path.getsize(path) == 0:
0.225.2 by Jelmer Vernooij
Handle situation when repository is already up to date during pull.
881
            return EmptyObjectStoreIterator()
0.200.226 by Jelmer Vernooij
Merge thin-pack work.
882
        return TemporaryPackIterator(path[:-len(".pack")], resolve_ext_ref)
0.200.167 by Jelmer Vernooij
Implement fetch_objects properly.
883
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
884
    def lookup_bzr_revision_id(self, bzr_revid, mapping=None):
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
885
        # This won't work for any round-tripped bzr revisions, but it's a
886
        # start..
0.200.415 by Jelmer Vernooij
make 'bzr pull --revision' work for remote repositories.
887
        try:
888
            return mapping_registry.revision_id_bzr_to_foreign(bzr_revid)
889
        except InvalidRevisionId:
890
            raise NoSuchRevision(self, bzr_revid)
891
0.252.48 by Jelmer Vernooij
Implement lookup_foreign_revision for remote branches.
892
    def lookup_foreign_revision_id(self, foreign_revid, mapping=None):
893
        """Lookup a revision id.
894
895
        """
896
        if mapping is None:
897
            mapping = self.get_mapping()
898
        # Not really an easy way to parse foreign revids here..
899
        return mapping.revision_id_foreign_to_bzr(foreign_revid)
900
0.200.1446 by Jelmer Vernooij
Add stub for RemoteGitRepository.revision_tree.
901
    def revision_tree(self, revid):
6968.4.1 by Jelmer Vernooij
Add support for exporting archives in Git.
902
        return GitRemoteRevisionTree(self, revid)
0.200.1446 by Jelmer Vernooij
Add stub for RemoteGitRepository.revision_tree.
903
0.200.1481 by Jelmer Vernooij
'Implement' RemoteGitRepository.get_revisions.
904
    def get_revisions(self, revids):
905
        raise GitSmartRemoteNotSupported(self.get_revisions, self)
906
0.200.1557 by Jelmer Vernooij
Implement RemoteGitRepository.has_revisions.
907
    def has_revisions(self, revids):
908
        raise GitSmartRemoteNotSupported(self.get_revisions, self)
909
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
910
0.200.1064 by Jelmer Vernooij
Use common base class for tags.
911
class RemoteGitTagDict(GitTags):
0.228.3 by Jelmer Vernooij
Fix tags when fetching from remotes.
912
913
    def set_tag(self, name, revid):
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
914
        sha = self.branch.lookup_bzr_revision_id(revid)[0]
915
        self._set_ref(name, sha)
916
917
    def delete_tag(self, name):
918
        self._set_ref(name, dulwich.client.ZERO_SHA)
919
920
    def _set_ref(self, name, sha):
921
        ref = tag_name_to_ref(name)
7143.15.2 by Jelmer Vernooij
Run autopep8.
922
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
923
        def get_changed_refs(old_refs):
7240.3.1 by Jelmer Vernooij
When sending refs to a remote server, don't send a copy of the old refs.
924
            ret = {}
7240.3.2 by Jelmer Vernooij
Fix tests.
925
            if sha == dulwich.client.ZERO_SHA and ref not in old_refs:
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
926
                raise NoSuchTag(name)
927
            ret[ref] = sha
928
            return ret
7143.15.2 by Jelmer Vernooij
Run autopep8.
929
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
930
        def generate_pack_data(have, want, ofs_delta=False):
931
            return pack_objects_to_data([])
932
        self.repository.send_pack(get_changed_refs, generate_pack_data)
0.228.3 by Jelmer Vernooij
Fix tags when fetching from remotes.
933
934
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
935
class RemoteGitBranch(GitBranch):
936
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
937
    def __init__(self, controldir, repository, name):
0.200.919 by Jelmer Vernooij
Simplify ref handling in remote.py.
938
        self._sha = None
0.295.1 by Jelmer Vernooij
Split up branch formats.
939
        super(RemoteGitBranch, self).__init__(controldir, repository, name,
7143.15.2 by Jelmer Vernooij
Run autopep8.
940
                                              RemoteGitBranchFormat())
0.200.461 by Jelmer Vernooij
Reduce number of round trips when fetching from Git.
941
0.200.1317 by Jelmer Vernooij
Avoid NotImplementedError.
942
    def last_revision_info(self):
0.200.1398 by Jelmer Vernooij
Make GitSmartRemoteNotSupported derive from UnsupportedOperation.
943
        raise GitSmartRemoteNotSupported(self.last_revision_info, self)
0.200.1317 by Jelmer Vernooij
Avoid NotImplementedError.
944
0.200.1068 by Jelmer Vernooij
Implement user_url/control_url.
945
    @property
946
    def user_url(self):
947
        return self.control_url
948
949
    @property
950
    def control_url(self):
951
        return self.base
952
0.200.1436 by Jelmer Vernooij
Raise UnsupportedOperation for `Branch.revision_id_to_dotted_revno`,
953
    def revision_id_to_revno(self, revision_id):
954
        raise GitSmartRemoteNotSupported(self.revision_id_to_revno, self)
0.200.461 by Jelmer Vernooij
Reduce number of round trips when fetching from Git.
955
956
    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.
957
        return self.lookup_foreign_revision_id(self.head)
0.200.461 by Jelmer Vernooij
Reduce number of round trips when fetching from Git.
958
959
    @property
960
    def head(self):
0.200.919 by Jelmer Vernooij
Simplify ref handling in remote.py.
961
        if self._sha is not None:
962
            return self._sha
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
963
        refs = self.controldir.get_refs_container()
0.200.1561 by Jelmer Vernooij
Some fixes for colocated branch handling.
964
        name = branch_name_to_ref(self.name)
0.200.1386 by Jelmer Vernooij
Friendlier message if HEAD is not found.
965
        try:
966
            self._sha = refs[name]
967
        except KeyError:
968
            raise NoSuchRef(name, self.repository.user_url, refs)
0.200.919 by Jelmer Vernooij
Simplify ref handling in remote.py.
969
        return self._sha
0.200.141 by Jelmer Vernooij
Separate out local and remote fetching.
970
0.200.169 by Jelmer Vernooij
Fix branch cloning.
971
    def _synchronize_history(self, destination, revision_id):
972
        """See Branch._synchronize_history()."""
7143.12.1 by Jelmer Vernooij
Support cloning revisions referenced only by an annotated tag.
973
        if revision_id is None:
974
            revision_id = self.last_revision()
975
        destination.generate_revision_history(revision_id)
0.200.695 by Jelmer Vernooij
Clean up trailing whitespace.
976
0.289.1 by Jelmer Vernooij
No parent location for remote repos.
977
    def _get_parent_location(self):
978
        return None
979
0.200.499 by Jelmer Vernooij
Implement RemoteBranch.{get,set}_push_location.
980
    def get_push_location(self):
981
        return None
982
983
    def set_push_location(self, url):
984
        pass
0.200.1488 by Jelmer Vernooij
Factor out remote_refs_dict_to_container.
985
0.375.1 by Jelmer Vernooij
Fix remote tests, warn when fetching git->bzr and bzr->git.
986
    def _iter_tag_refs(self):
987
        """Iterate over the tag refs.
988
989
        :param refs: Refs dictionary (name -> git sha1)
990
        :return: iterator over (ref_name, tag_name, peeled_sha1, unpeeled_sha1)
991
        """
992
        refs = self.controldir.get_refs_container()
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
993
        for ref_name, unpeeled in refs.as_dict().items():
0.375.1 by Jelmer Vernooij
Fix remote tests, warn when fetching git->bzr and bzr->git.
994
            try:
995
                tag_name = ref_to_tag_name(ref_name)
996
            except (ValueError, UnicodeDecodeError):
997
                continue
998
            peeled = refs.get_peeled(ref_name)
999
            if peeled is None:
7058.4.36 by Jelmer Vernooij
Fix peeled error.
1000
                # Let's just hope it's a commit
1001
                peeled = unpeeled
7479.2.1 by Jelmer Vernooij
Drop python2 support.
1002
            if not isinstance(tag_name, str):
0.375.1 by Jelmer Vernooij
Fix remote tests, warn when fetching git->bzr and bzr->git.
1003
                raise TypeError(tag_name)
1004
            yield (ref_name, tag_name, peeled, unpeeled)
1005
7131.12.1 by Jelmer Vernooij
Support uncommit on remote git branches.
1006
    def set_last_revision_info(self, revno, revid):
1007
        self.generate_revision_history(revid)
1008
1009
    def generate_revision_history(self, revision_id, last_rev=None,
1010
                                  other_branch=None):
1011
        sha = self.lookup_bzr_revision_id(revision_id)[0]
1012
        def get_changed_refs(old_refs):
1013
            return {self.ref: sha}
1014
        def generate_pack_data(have, want, ofs_delta=False):
1015
            return pack_objects_to_data([])
1016
        self.repository.send_pack(get_changed_refs, generate_pack_data)
1017
        self._sha = sha
1018
0.200.1488 by Jelmer Vernooij
Factor out remote_refs_dict_to_container.
1019
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
1020
def remote_refs_dict_to_container(refs_dict, symrefs_dict={}):
0.200.1488 by Jelmer Vernooij
Factor out remote_refs_dict_to_container.
1021
    base = {}
1022
    peeled = {}
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
1023
    for k, v in refs_dict.items():
0.200.1488 by Jelmer Vernooij
Factor out remote_refs_dict_to_container.
1024
        if is_peeled(k):
1025
            peeled[k[:-3]] = v
1026
        else:
1027
            base[k] = v
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
1028
    for name, target in symrefs_dict.items():
0.382.1 by Jelmer Vernooij
Various fixes for annotated tags and symrefs.
1029
        base[name] = SYMREF + target
0.200.1488 by Jelmer Vernooij
Factor out remote_refs_dict_to_container.
1030
    ret = DictRefsContainer(base)
1031
    ret._peeled = peeled
1032
    return ret
7484.1.1 by Jelmer Vernooij
Follow symrefs when pushing to git repositories.
1033
1034
1035
def update_refs_container(container, refs_dict):
1036
    peeled = {}
1037
    base = {}
1038
    for k, v in refs_dict.items():
1039
        if is_peeled(k):
1040
            peeled[k[:-3]] = v
1041
        else:
1042
            base[k] = v
1043
    container._peeled = peeled
1044
    container._refs.update(base)