/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 breezy/plugins/git/transportgit.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2018-07-03 03:20:44 UTC
  • mfrom: (7018.3.10 git-fixes)
  • Revision ID: breezy.the.bot@gmail.com-20180703032044-t5a5w5y0tmzrbezc
Port a few more bits of the git plugin to python 3.

Merged from https://code.launchpad.net/~jelmer/brz/git-fixes2/+merge/348803

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
import os
24
24
import sys
25
 
import urllib
26
25
 
27
26
from dulwich.errors import (
28
27
    NotGitRepository,
67
66
    )
68
67
 
69
68
from ... import (
 
69
    osutils,
70
70
    transport as _mod_transport,
 
71
    urlutils,
 
72
    )
 
73
from ...sixish import (
 
74
    PY3,
 
75
    text_type,
71
76
    )
72
77
from ...errors import (
73
78
    AlreadyControlDirError,
127
132
        except NoSuchFile:
128
133
            pass
129
134
        else:
130
 
            keys.add("HEAD")
 
135
            keys.add(b"HEAD")
131
136
        try:
132
137
            iter_files = list(self.transport.clone("refs").iter_files_recursive())
133
138
            for filename in iter_files:
134
 
                refname = "refs/%s" % urllib.unquote(filename)
 
139
                unquoted_filename = urlutils.unquote(filename)
 
140
                if PY3:
 
141
                    # JRV: Work around unquote returning a text_type string on
 
142
                    # PY3.
 
143
                    unquoted_filename = unquoted_filename.encode('utf-8')
 
144
                refname = osutils.pathjoin(b"refs", unquoted_filename)
135
145
                if check_ref_format(refname):
136
146
                    keys.add(refname)
137
147
        except (TransportNotPossible, NoSuchFile):
278
288
        else:
279
289
            transport = self.transport
280
290
            self._ensure_dir_exists(realname)
281
 
        transport.put_bytes(realname, new_ref+"\n")
 
291
        transport.put_bytes(realname, new_ref+b"\n")
282
292
        return True
283
293
 
284
294
    def add_if_new(self, name, ref):
304
314
        else:
305
315
            transport = self.transport
306
316
            self._ensure_dir_exists(realname)
307
 
        transport.put_bytes(realname, ref+"\n")
 
317
        transport.put_bytes(realname, ref+b"\n")
308
318
        return True
309
319
 
310
320
    def remove_if_equals(self, name, old_ref):
630
640
        return (sha[:2], sha[2:])
631
641
 
632
642
    def _remove_loose_object(self, sha):
633
 
        path = '%s/%s' % self._split_loose_object(sha)
 
643
        path = osutils.joinpath(self._split_loose_object(sha))
634
644
        self.transport.delete(path)
635
645
 
636
646
    def _get_loose_object(self, sha):
637
 
        path = '%s/%s' % self._split_loose_object(sha)
 
647
        path = osutils.joinpath(self._split_loose_object(sha))
638
648
        try:
639
649
            return ShaFile.from_file(self.transport.get(path))
640
650
        except NoSuchFile:
650
660
            self.transport.mkdir(dir)
651
661
        except FileExists:
652
662
            pass
653
 
        path = "%s/%s" % (dir, file)
 
663
        path = osutils.pathjoin(dir, file)
654
664
        if self.transport.has(path):
655
665
            return # Already there, no need to write again
656
666
        self.transport.put_bytes(path, obj.as_legacy_object())