/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-05-15 18:47:57 UTC
  • mfrom: (6964.2.7 python3-git)
  • Revision ID: breezy.the.bot@gmail.com-20180515184757-xozniaj9gztgtom8
Port some of brz-git to python3.

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

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
from __future__ import absolute_import
20
20
 
21
 
from cStringIO import StringIO
 
21
from io import BytesIO
22
22
 
23
23
import os
24
24
import sys
158
158
            except NoSuchFile:
159
159
                return {}
160
160
            try:
161
 
                first_line = iter(f).next().rstrip()
 
161
                first_line = next(iter(f)).rstrip()
162
162
                if (first_line.startswith("# pack-refs") and " peeled" in
163
163
                        first_line):
164
164
                    for sha, name, peeled in read_packed_refs_with_peeled(f):
210
210
            f = transport.get(name)
211
211
        except NoSuchFile:
212
212
            return None
213
 
        f = StringIO(f.read())
 
213
        f = BytesIO(f.read())
214
214
        try:
215
215
            header = f.read(len(SYMREF))
216
216
            if header == SYMREF:
217
217
                # Read only the first line
218
 
                return header + iter(f).next().rstrip("\r\n")
 
218
                return header + next(iter(f)).rstrip(b"\r\n")
219
219
            else:
220
220
                # Read only the first 40 bytes
221
221
                return header + f.read(40-len(SYMREF))
255
255
            self._ensure_dir_exists(name)
256
256
        else:
257
257
            transport = self.worktree_transport
258
 
        transport.put_bytes(name, SYMREF + other + '\n')
 
258
        transport.put_bytes(name, SYMREF + other + b'\n')
259
259
 
260
260
    def set_if_equals(self, name, old_ref, new_ref):
261
261
        """Set a refname to new_ref only if it currently equals old_ref.
409
409
        object_store = TransportObjectStore(
410
410
            self._commontransport.clone(OBJECTDIR))
411
411
        if refs_text is not None:
412
 
            refs_container = InfoRefsContainer(StringIO(refs_text))
 
412
            refs_container = InfoRefsContainer(BytesIO(refs_text))
413
413
            try:
414
414
                head = TransportRefsContainer(self._commontransport).read_loose_ref("HEAD")
415
415
            except KeyError:
516
516
            raise AlreadyControlDirError(transport.base)
517
517
        TransportObjectStore.init(control_transport.clone(OBJECTDIR))
518
518
        ret = cls(transport, bare)
519
 
        ret.refs.set_symbolic_ref("HEAD", "refs/heads/master")
 
519
        ret.refs.set_symbolic_ref(b"HEAD", b"refs/heads/master")
520
520
        ret._init_files(bare)
521
521
        return ret
522
522
 
611
611
                    # FIXME: This reads the whole pack file at once
612
612
                    f = self.pack_transport.get(name)
613
613
                    contents = f.read()
614
 
                    pd = PackData(name, StringIO(contents), size=len(contents))
 
614
                    pd = PackData(name, BytesIO(contents), size=len(contents))
615
615
                else:
616
616
                    pd = PackData(name, self.pack_transport.get(name),
617
617
                            size=size)
723
723
        :return: Fileobject to write to and a commit function to
724
724
            call when the pack is finished.
725
725
        """
726
 
        from cStringIO import StringIO
727
 
        f = StringIO()
 
726
        f = BytesIO()
728
727
        def commit():
729
728
            if len(f.getvalue()) > 0:
730
729
                return self.move_in_pack(f)