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