/brz/remove-bazaar

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