/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to remote.py

Change root id, for easy use in join --reference.

Merged from https://code.launchpad.net/~jelmer/brz-git/change-root-id/+merge/342153

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2007-2018 Jelmer Vernooij <jelmer@jelmer.uk>
 
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
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
"""Remote dirs, repositories and branches."""
 
18
 
 
19
from __future__ import absolute_import
 
20
 
 
21
from ... import (
 
22
    config,
 
23
    debug,
 
24
    trace,
 
25
    ui,
 
26
    urlutils,
 
27
    )
 
28
from ...errors import (
 
29
    AlreadyBranchError,
 
30
    BzrError,
 
31
    InProcessTransport,
 
32
    InvalidRevisionId,
 
33
    NoSuchFile,
 
34
    NoSuchRevision,
 
35
    NoSuchTag,
 
36
    NotBranchError,
 
37
    NotLocalUrl,
 
38
    UninitializableFormat,
 
39
    )
 
40
from ...transport import (
 
41
    Transport,
 
42
    )
 
43
 
 
44
from . import (
 
45
    lazy_check_versions,
 
46
    )
 
47
lazy_check_versions()
 
48
 
 
49
from .branch import (
 
50
    GitBranch,
 
51
    GitBranchFormat,
 
52
    GitTags,
 
53
    )
 
54
from .dir import (
 
55
    GitControlDirFormat,
 
56
    GitDir,
 
57
    BareLocalGitControlDirFormat,
 
58
    )
 
59
from .errors import (
 
60
    GitSmartRemoteNotSupported,
 
61
    NoSuchRef,
 
62
    )
 
63
from .mapping import (
 
64
    mapping_registry,
 
65
    )
 
66
from .repository import (
 
67
    GitRepository,
 
68
    )
 
69
from .refs import (
 
70
    branch_name_to_ref,
 
71
    is_peeled,
 
72
    ref_to_tag_name,
 
73
    tag_name_to_ref,
 
74
    )
 
75
 
 
76
import dulwich
 
77
import dulwich.client
 
78
from dulwich.errors import (
 
79
    GitProtocolError,
 
80
    )
 
81
from dulwich.pack import (
 
82
    Pack,
 
83
    pack_objects_to_data,
 
84
    )
 
85
from dulwich.refs import SYMREF
 
86
from dulwich.repo import DictRefsContainer
 
87
import os
 
88
import select
 
89
import tempfile
 
90
import urllib
 
91
import urlparse
 
92
 
 
93
# urlparse only supports a limited number of schemes by default
 
94
 
 
95
urlparse.uses_netloc.extend(['git', 'git+ssh'])
 
96
 
 
97
from dulwich.pack import load_pack_index
 
98
 
 
99
 
 
100
# Don't run any tests on GitSmartTransport as it is not intended to be
 
101
# a full implementation of Transport
 
102
def get_test_permutations():
 
103
    return []
 
104
 
 
105
 
 
106
def split_git_url(url):
 
107
    """Split a Git URL.
 
108
 
 
109
    :param url: Git URL
 
110
    :return: Tuple with host, port, username, path.
 
111
    """
 
112
    (scheme, netloc, loc, _, _) = urlparse.urlsplit(url)
 
113
    path = urllib.unquote(loc)
 
114
    if path.startswith("/~"):
 
115
        path = path[1:]
 
116
    (username, hostport) = urllib.splituser(netloc)
 
117
    (host, port) = urllib.splitnport(hostport, None)
 
118
    return (host, port, username, path)
 
119
 
 
120
 
 
121
class RemoteGitError(BzrError):
 
122
 
 
123
    _fmt = "Remote server error: %(msg)s"
 
124
 
 
125
 
 
126
def parse_git_error(url, message):
 
127
    """Parse a remote git server error and return a bzr exception.
 
128
 
 
129
    :param url: URL of the remote repository
 
130
    :param message: Message sent by the remote git server
 
131
    """
 
132
    message = str(message).strip()
 
133
    if message.startswith("Could not find Repository "):
 
134
        return NotBranchError(url, message)
 
135
    if message == "HEAD failed to update":
 
136
        base_url, _ = urlutils.split_segment_parameters(url)
 
137
        raise BzrError(
 
138
            ("Unable to update remote HEAD branch. To update the master "
 
139
             "branch, specify the URL %s,branch=master.") % base_url)
 
140
    # Don't know, just return it to the user as-is
 
141
    return RemoteGitError(message)
 
142
 
 
143
 
 
144
class GitSmartTransport(Transport):
 
145
 
 
146
    def __init__(self, url, _client=None):
 
147
        Transport.__init__(self, url)
 
148
        (self._host, self._port, self._username, self._path) = \
 
149
            split_git_url(url)
 
150
        if 'transport' in debug.debug_flags:
 
151
            trace.mutter('host: %r, user: %r, port: %r, path: %r',
 
152
                         self._host, self._username, self._port, self._path)
 
153
        self._client = _client
 
154
        self._stripped_path = self._path.rsplit(",", 1)[0]
 
155
 
 
156
    def external_url(self):
 
157
        return self.base
 
158
 
 
159
    def has(self, relpath):
 
160
        return False
 
161
 
 
162
    def _get_client(self):
 
163
        raise NotImplementedError(self._get_client)
 
164
 
 
165
    def _get_path(self):
 
166
        return self._stripped_path
 
167
 
 
168
    def get(self, path):
 
169
        raise NoSuchFile(path)
 
170
 
 
171
    def abspath(self, relpath):
 
172
        return urlutils.join(self.base, relpath)
 
173
 
 
174
    def clone(self, offset=None):
 
175
        """See Transport.clone()."""
 
176
        if offset is None:
 
177
            newurl = self.base
 
178
        else:
 
179
            newurl = urlutils.join(self.base, offset)
 
180
 
 
181
        return self.__class__(newurl, self._client)
 
182
 
 
183
 
 
184
class TCPGitSmartTransport(GitSmartTransport):
 
185
 
 
186
    _scheme = 'git'
 
187
 
 
188
    def _get_client(self):
 
189
        if self._client is not None:
 
190
            ret = self._client
 
191
            self._client = None
 
192
            return ret
 
193
        if self._host == '':
 
194
            # return dulwich.client.LocalGitClient()
 
195
            return dulwich.client.SubprocessGitClient()
 
196
        return dulwich.client.TCPGitClient(self._host, self._port,
 
197
            report_activity=self._report_activity)
 
198
 
 
199
 
 
200
class SSHSocketWrapper(object):
 
201
 
 
202
    def __init__(self, sock):
 
203
        self.sock = sock
 
204
 
 
205
    def read(self, len=None):
 
206
        return self.sock.recv(len)
 
207
 
 
208
    def write(self, data):
 
209
        return self.sock.write(data)
 
210
 
 
211
    def can_read(self):
 
212
        return len(select.select([self.sock.fileno()], [], [], 0)[0]) > 0
 
213
 
 
214
 
 
215
class DulwichSSHVendor(dulwich.client.SSHVendor):
 
216
 
 
217
    def __init__(self):
 
218
        from ...transport import ssh
 
219
        self.bzr_ssh_vendor = ssh._get_ssh_vendor()
 
220
 
 
221
    def run_command(self, host, command, username=None, port=None):
 
222
        connection = self.bzr_ssh_vendor.connect_ssh(username=username,
 
223
            password=None, port=port, host=host, command=command)
 
224
        (kind, io_object) = connection.get_sock_or_pipes()
 
225
        if kind == 'socket':
 
226
            return SSHSocketWrapper(io_object)
 
227
        else:
 
228
            raise AssertionError("Unknown io object kind %r'" % kind)
 
229
 
 
230
 
 
231
#dulwich.client.get_ssh_vendor = DulwichSSHVendor
 
232
 
 
233
 
 
234
class SSHGitSmartTransport(GitSmartTransport):
 
235
 
 
236
    _scheme = 'git+ssh'
 
237
 
 
238
    def _get_path(self):
 
239
        path = self._stripped_path
 
240
        if path.startswith("/~/"):
 
241
            return path[3:]
 
242
        return path
 
243
 
 
244
    def _get_client(self):
 
245
        if self._client is not None:
 
246
            ret = self._client
 
247
            self._client = None
 
248
            return ret
 
249
        location_config = config.LocationConfig(self.base)
 
250
        client = dulwich.client.SSHGitClient(self._host, self._port, self._username,
 
251
            report_activity=self._report_activity)
 
252
        # Set up alternate pack program paths
 
253
        upload_pack = location_config.get_user_option('git_upload_pack')
 
254
        if upload_pack:
 
255
            client.alternative_paths["upload-pack"] = upload_pack
 
256
        receive_pack = location_config.get_user_option('git_receive_pack')
 
257
        if receive_pack:
 
258
            client.alternative_paths["receive-pack"] = receive_pack
 
259
        return client
 
260
 
 
261
 
 
262
class RemoteGitBranchFormat(GitBranchFormat):
 
263
 
 
264
    def get_format_description(self):
 
265
        return 'Remote Git Branch'
 
266
 
 
267
    @property
 
268
    def _matchingcontroldir(self):
 
269
        return RemoteGitControlDirFormat()
 
270
 
 
271
    def initialize(self, a_controldir, name=None, repository=None,
 
272
                   append_revisions_only=None):
 
273
        raise UninitializableFormat(self)
 
274
 
 
275
 
 
276
def default_report_progress(text):
 
277
    if text.startswith('error: '):
 
278
        trace.show_error('git: %s', text[len('error: '):])
 
279
    else:
 
280
        trace.mutter("git: %s" % text)
 
281
 
 
282
 
 
283
class RemoteGitDir(GitDir):
 
284
 
 
285
    def __init__(self, transport, format, client, client_path):
 
286
        self._format = format
 
287
        self.root_transport = transport
 
288
        self.transport = transport
 
289
        self._mode_check_done = None
 
290
        self._client = client
 
291
        self._client_path = client_path
 
292
        self.base = self.root_transport.base
 
293
        self._refs = None
 
294
 
 
295
    @property
 
296
    def _gitrepository_class(self):
 
297
        return RemoteGitRepository
 
298
 
 
299
    def fetch_pack(self, determine_wants, graph_walker, pack_data, progress=None):
 
300
        if progress is None:
 
301
            progress = default_report_progress
 
302
        try:
 
303
            result = self._client.fetch_pack(self._client_path, determine_wants,
 
304
                graph_walker, pack_data, progress)
 
305
            if result.refs is None:
 
306
                result.refs = {}
 
307
            self._refs = remote_refs_dict_to_container(result.refs, result.symrefs)
 
308
            return result
 
309
        except GitProtocolError, e:
 
310
            raise parse_git_error(self.transport.external_url(), e)
 
311
 
 
312
    def send_pack(self, get_changed_refs, generate_pack_data, progress=None):
 
313
        if progress is None:
 
314
            progress = default_report_progress
 
315
 
 
316
        try:
 
317
            return self._client.send_pack(self._client_path, get_changed_refs,
 
318
                generate_pack_data, progress)
 
319
        except GitProtocolError, e:
 
320
            raise parse_git_error(self.transport.external_url(), e)
 
321
 
 
322
    def create_branch(self, name=None, repository=None,
 
323
                      append_revisions_only=None, ref=None):
 
324
        refname = self._get_selected_ref(name, ref)
 
325
        if refname != b'HEAD' and refname in self.get_refs_container():
 
326
            raise AlreadyBranchError(self.user_url)
 
327
        if refname in self.get_refs_container():
 
328
            ref_chain, unused_sha = self.get_refs_container().follow(self._get_selected_ref(None))
 
329
            if ref_chain[0] == b'HEAD':
 
330
                refname = ref_chain[1]
 
331
        repo = self.open_repository()
 
332
        return RemoteGitBranch(self, repo, refname)
 
333
 
 
334
    def destroy_branch(self, name=None):
 
335
        refname = self._get_selected_ref(name)
 
336
        def get_changed_refs(old_refs):
 
337
            ret = dict(old_refs)
 
338
            if not refname in ret:
 
339
                raise NotBranchError(self.user_url)
 
340
            ret[refname] = dulwich.client.ZERO_SHA
 
341
            return ret
 
342
        def generate_pack_data(have, want, ofs_delta=False):
 
343
            return pack_objects_to_data([])
 
344
        self.send_pack(get_changed_refs, generate_pack_data)
 
345
 
 
346
    @property
 
347
    def user_url(self):
 
348
        return self.control_url
 
349
 
 
350
    @property
 
351
    def user_transport(self):
 
352
        return self.root_transport
 
353
 
 
354
    @property
 
355
    def control_url(self):
 
356
        return self.control_transport.base
 
357
 
 
358
    @property
 
359
    def control_transport(self):
 
360
        return self.root_transport
 
361
 
 
362
    def open_repository(self):
 
363
        return RemoteGitRepository(self)
 
364
 
 
365
    def open_branch(self, name=None, unsupported=False,
 
366
            ignore_fallbacks=False, ref=None, possible_transports=None,
 
367
            nascent_ok=False):
 
368
        repo = self.open_repository()
 
369
        ref = self._get_selected_ref(name, ref)
 
370
        if not nascent_ok and ref not in self.get_refs_container():
 
371
            raise NotBranchError(self.root_transport.base,
 
372
                    controldir=self)
 
373
        ref_chain, unused_sha = self.get_refs_container().follow(ref)
 
374
        return RemoteGitBranch(self, repo, ref_chain[-1])
 
375
 
 
376
    def open_workingtree(self, recommend_upgrade=False):
 
377
        raise NotLocalUrl(self.transport.base)
 
378
 
 
379
    def has_workingtree(self):
 
380
        return False
 
381
 
 
382
    def get_peeled(self, name):
 
383
        return self.get_refs_container().get_peeled(name)
 
384
 
 
385
    def get_refs_container(self):
 
386
        if self._refs is not None:
 
387
            return self._refs
 
388
        result = self.fetch_pack(lambda x: None, None,
 
389
            lambda x: None, lambda x: trace.mutter("git: %s" % x))
 
390
        self._refs = remote_refs_dict_to_container(
 
391
                result.refs, result.symrefs)
 
392
        return self._refs
 
393
 
 
394
 
 
395
class EmptyObjectStoreIterator(dict):
 
396
 
 
397
    def iterobjects(self):
 
398
        return []
 
399
 
 
400
 
 
401
class TemporaryPackIterator(Pack):
 
402
 
 
403
    def __init__(self, path, resolve_ext_ref):
 
404
        super(TemporaryPackIterator, self).__init__(
 
405
            path, resolve_ext_ref=resolve_ext_ref)
 
406
        self._idx_load = lambda: self._idx_load_or_generate(self._idx_path)
 
407
 
 
408
    def _idx_load_or_generate(self, path):
 
409
        if not os.path.exists(path):
 
410
            pb = ui.ui_factory.nested_progress_bar()
 
411
            try:
 
412
                def report_progress(cur, total):
 
413
                    pb.update("generating index", cur, total)
 
414
                self.data.create_index(path,
 
415
                    progress=report_progress)
 
416
            finally:
 
417
                pb.finished()
 
418
        return load_pack_index(path)
 
419
 
 
420
    def __del__(self):
 
421
        if self._idx is not None:
 
422
            self._idx.close()
 
423
            os.remove(self._idx_path)
 
424
        if self._data is not None:
 
425
            self._data.close()
 
426
            os.remove(self._data_path)
 
427
 
 
428
 
 
429
class BzrGitHttpClient(dulwich.client.HttpGitClient):
 
430
 
 
431
    def __init__(self, transport, *args, **kwargs):
 
432
        self.transport = transport
 
433
        super(BzrGitHttpClient, self).__init__(transport.external_url(), *args, **kwargs)
 
434
        import urllib2
 
435
        self._http_perform = getattr(self.transport, "_perform", urllib2.urlopen)
 
436
 
 
437
    def _perform(self, req):
 
438
        req.accepted_errors = (200, 404)
 
439
        req.follow_redirections = True
 
440
        req.redirected_to = None
 
441
        return self._http_perform(req)
 
442
 
 
443
 
 
444
class RemoteGitControlDirFormat(GitControlDirFormat):
 
445
    """The .git directory control format."""
 
446
 
 
447
    supports_workingtrees = False
 
448
 
 
449
    @classmethod
 
450
    def _known_formats(self):
 
451
        return set([RemoteGitControlDirFormat()])
 
452
 
 
453
    def get_branch_format(self):
 
454
        return RemoteGitBranchFormat()
 
455
 
 
456
    def is_initializable(self):
 
457
        return False
 
458
 
 
459
    def is_supported(self):
 
460
        return True
 
461
 
 
462
    def open(self, transport, _found=None):
 
463
        """Open this directory.
 
464
 
 
465
        """
 
466
        # we dont grok readonly - git isn't integrated with transport.
 
467
        url = transport.base
 
468
        if url.startswith('readonly+'):
 
469
            url = url[len('readonly+'):]
 
470
        scheme = urlparse.urlsplit(transport.external_url())[0]
 
471
        if isinstance(transport, GitSmartTransport):
 
472
            client = transport._get_client()
 
473
            client_path = transport._get_path()
 
474
        elif scheme in ("http", "https"):
 
475
            client = BzrGitHttpClient(transport)
 
476
            client_path, _ = urlutils.split_segment_parameters(transport._path)
 
477
        elif scheme == 'file':
 
478
            client = dulwich.client.LocalGitClient()
 
479
            client_path = transport.local_abspath('.')
 
480
        else:
 
481
            raise NotBranchError(transport.base)
 
482
        if not _found:
 
483
            pass # TODO(jelmer): Actually probe for something
 
484
        return RemoteGitDir(transport, self, client, client_path)
 
485
 
 
486
    def get_format_description(self):
 
487
        return "Remote Git Repository"
 
488
 
 
489
    def initialize_on_transport(self, transport):
 
490
        raise UninitializableFormat(self)
 
491
 
 
492
    def supports_transport(self, transport):
 
493
        try:
 
494
            external_url = transport.external_url()
 
495
        except InProcessTransport:
 
496
            raise NotBranchError(path=transport.base)
 
497
        return (external_url.startswith("http:") or
 
498
                external_url.startswith("https:") or
 
499
                external_url.startswith("git+") or
 
500
                external_url.startswith("git:"))
 
501
 
 
502
 
 
503
class RemoteGitRepository(GitRepository):
 
504
 
 
505
    @property
 
506
    def user_url(self):
 
507
        return self.control_url
 
508
 
 
509
    def get_parent_map(self, revids):
 
510
        raise GitSmartRemoteNotSupported(self.get_parent_map, self)
 
511
 
 
512
    def fetch_pack(self, determine_wants, graph_walker, pack_data,
 
513
                   progress=None):
 
514
        return self.controldir.fetch_pack(determine_wants, graph_walker,
 
515
                                          pack_data, progress)
 
516
 
 
517
    def send_pack(self, get_changed_refs, generate_pack_data):
 
518
        return self.controldir.send_pack(get_changed_refs, generate_pack_data)
 
519
 
 
520
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref,
 
521
                      progress=None):
 
522
        fd, path = tempfile.mkstemp(suffix=".pack")
 
523
        try:
 
524
            self.fetch_pack(determine_wants, graph_walker,
 
525
                lambda x: os.write(fd, x), progress)
 
526
        finally:
 
527
            os.close(fd)
 
528
        if os.path.getsize(path) == 0:
 
529
            return EmptyObjectStoreIterator()
 
530
        return TemporaryPackIterator(path[:-len(".pack")], resolve_ext_ref)
 
531
 
 
532
    def lookup_bzr_revision_id(self, bzr_revid, mapping=None):
 
533
        # This won't work for any round-tripped bzr revisions, but it's a start..
 
534
        try:
 
535
            return mapping_registry.revision_id_bzr_to_foreign(bzr_revid)
 
536
        except InvalidRevisionId:
 
537
            raise NoSuchRevision(self, bzr_revid)
 
538
 
 
539
    def lookup_foreign_revision_id(self, foreign_revid, mapping=None):
 
540
        """Lookup a revision id.
 
541
 
 
542
        """
 
543
        if mapping is None:
 
544
            mapping = self.get_mapping()
 
545
        # Not really an easy way to parse foreign revids here..
 
546
        return mapping.revision_id_foreign_to_bzr(foreign_revid)
 
547
 
 
548
    def revision_tree(self, revid):
 
549
        raise GitSmartRemoteNotSupported(self.revision_tree, self)
 
550
 
 
551
    def get_revisions(self, revids):
 
552
        raise GitSmartRemoteNotSupported(self.get_revisions, self)
 
553
 
 
554
    def has_revisions(self, revids):
 
555
        raise GitSmartRemoteNotSupported(self.get_revisions, self)
 
556
 
 
557
 
 
558
class RemoteGitTagDict(GitTags):
 
559
 
 
560
    def set_tag(self, name, revid):
 
561
        sha = self.branch.lookup_bzr_revision_id(revid)[0]
 
562
        self._set_ref(name, sha)
 
563
 
 
564
    def delete_tag(self, name):
 
565
        self._set_ref(name, dulwich.client.ZERO_SHA)
 
566
 
 
567
    def _set_ref(self, name, sha):
 
568
        ref = tag_name_to_ref(name)
 
569
        def get_changed_refs(old_refs):
 
570
            ret = dict(old_refs)
 
571
            if sha == dulwich.client.ZERO_SHA and ref not in ret:
 
572
                raise NoSuchTag(name)
 
573
            ret[ref] = sha
 
574
            return ret
 
575
        def generate_pack_data(have, want, ofs_delta=False):
 
576
            return pack_objects_to_data([])
 
577
        self.repository.send_pack(get_changed_refs, generate_pack_data)
 
578
 
 
579
 
 
580
class RemoteGitBranch(GitBranch):
 
581
 
 
582
    def __init__(self, controldir, repository, name):
 
583
        self._sha = None
 
584
        super(RemoteGitBranch, self).__init__(controldir, repository, name,
 
585
                RemoteGitBranchFormat())
 
586
 
 
587
    def last_revision_info(self):
 
588
        raise GitSmartRemoteNotSupported(self.last_revision_info, self)
 
589
 
 
590
    @property
 
591
    def user_url(self):
 
592
        return self.control_url
 
593
 
 
594
    @property
 
595
    def control_url(self):
 
596
        return self.base
 
597
 
 
598
    def revision_id_to_revno(self, revision_id):
 
599
        raise GitSmartRemoteNotSupported(self.revision_id_to_revno, self)
 
600
 
 
601
    def last_revision(self):
 
602
        return self.lookup_foreign_revision_id(self.head)
 
603
 
 
604
    @property
 
605
    def head(self):
 
606
        if self._sha is not None:
 
607
            return self._sha
 
608
        refs = self.controldir.get_refs_container()
 
609
        name = branch_name_to_ref(self.name)
 
610
        try:
 
611
            self._sha = refs[name]
 
612
        except KeyError:
 
613
            raise NoSuchRef(name, self.repository.user_url, refs)
 
614
        return self._sha
 
615
 
 
616
    def _synchronize_history(self, destination, revision_id):
 
617
        """See Branch._synchronize_history()."""
 
618
        destination.generate_revision_history(self.last_revision())
 
619
 
 
620
    def _get_parent_location(self):
 
621
        return None
 
622
 
 
623
    def get_push_location(self):
 
624
        return None
 
625
 
 
626
    def set_push_location(self, url):
 
627
        pass
 
628
 
 
629
    def _iter_tag_refs(self):
 
630
        """Iterate over the tag refs.
 
631
 
 
632
        :param refs: Refs dictionary (name -> git sha1)
 
633
        :return: iterator over (ref_name, tag_name, peeled_sha1, unpeeled_sha1)
 
634
        """
 
635
        refs = self.controldir.get_refs_container()
 
636
        for ref_name, unpeeled in refs.as_dict().iteritems():
 
637
            try:
 
638
                tag_name = ref_to_tag_name(ref_name)
 
639
            except (ValueError, UnicodeDecodeError):
 
640
                continue
 
641
            peeled = refs.get_peeled(ref_name)
 
642
            if peeled is None:
 
643
                try:
 
644
                    peeled = refs.peel_sha(unpeeled).id
 
645
                except KeyError:
 
646
                    # Let's just hope it's a commit
 
647
                    peeled = unpeeled
 
648
            if type(tag_name) is not unicode:
 
649
                raise TypeError(tag_name)
 
650
            yield (ref_name, tag_name, peeled, unpeeled)
 
651
 
 
652
 
 
653
def remote_refs_dict_to_container(refs_dict, symrefs_dict={}):
 
654
    base = {}
 
655
    peeled = {}
 
656
    for k, v in refs_dict.iteritems():
 
657
        if is_peeled(k):
 
658
            peeled[k[:-3]] = v
 
659
        else:
 
660
            base[k] = v
 
661
            peeled[k] = v
 
662
    for name, target in symrefs_dict.iteritems():
 
663
        base[name] = SYMREF + target
 
664
    ret = DictRefsContainer(base)
 
665
    ret._peeled = peeled
 
666
    return ret