/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-14 19:47:11 UTC
  • mfrom: (7027.4.12 python3-blackbox)
  • Revision ID: breezy.the.bot@gmail.com-20180714194711-h73vd0gzphiab6vf
Change run_bzr to use StringIOWithEncoding for stderr and stdout on python 3.

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

Show diffs side-by-side

added added

removed removed

Lines of Context:
220
220
            f = transport.get(name)
221
221
        except NoSuchFile:
222
222
            return None
223
 
        try:
 
223
        with f:
224
224
            header = f.read(len(SYMREF))
225
225
            if header == SYMREF:
226
226
                # Read only the first line
228
228
            else:
229
229
                # Read only the first 40 bytes
230
230
                return header + f.read(40-len(SYMREF))
231
 
        finally:
232
 
            f.close()
233
231
 
234
232
    def _remove_packed_ref(self, name):
235
233
        if self._packed_refs is None:
485
483
    def get_config(self):
486
484
        from dulwich.config import ConfigFile
487
485
        try:
488
 
            return ConfigFile.from_file(self._controltransport.get('config'))
 
486
            with self._controltransport.get('config') as f:
 
487
                return ConfigFile.from_file(f)
489
488
        except NoSuchFile:
490
489
            return ConfigFile()
491
490
 
568
567
        except NoSuchFile:
569
568
            return []
570
569
        ret = []
571
 
        try:
 
570
        with f:
572
571
            for l in f.read().splitlines():
573
 
                if l[0] == "#":
 
572
                if l[0] == b"#":
574
573
                    continue
575
574
                if os.path.isabs(l):
576
575
                    continue
577
576
                ret.append(l)
578
577
            return ret
579
 
        finally:
580
 
            f.close()
581
578
 
582
579
    @property
583
580
    def packs(self):
596
593
        except NoSuchFile:
597
594
            return self.pack_transport.list_dir(".")
598
595
        else:
599
 
            ret = []
600
 
            for line in f.read().splitlines():
601
 
                if not line:
602
 
                    continue
603
 
                (kind, name) = line.split(" ", 1)
604
 
                if kind != "P":
605
 
                    continue
606
 
                ret.append(name)
607
 
            return ret
 
596
            with f:
 
597
                ret = []
 
598
                for line in f.read().splitlines():
 
599
                    if not line:
 
600
                        continue
 
601
                    (kind, name) = line.split(b" ", 1)
 
602
                    if kind != b"P":
 
603
                        continue
 
604
                    ret.append(name)
 
605
                return ret
608
606
 
609
607
    def _remove_pack(self, pack):
610
608
        self.pack_transport.delete(os.path.basename(pack.index.path))
646
644
    def _get_loose_object(self, sha):
647
645
        path = osutils.joinpath(self._split_loose_object(sha))
648
646
        try:
649
 
            return ShaFile.from_file(self.transport.get(path))
 
647
            with self.transport.get(path) as f:
 
648
                return ShaFile.from_file(f)
650
649
        except NoSuchFile:
651
650
            return None
652
651
 
676
675
        f.seek(0)
677
676
        p = PackData("", f, len(f.getvalue()))
678
677
        entries = p.sorted_entries()
679
 
        basename = "pack-%s" % iter_sha1(entry[0] for entry in entries)
 
678
        basename = "pack-%s" % iter_sha1(entry[0] for entry in entries).decode('ascii')
680
679
        p._filename = basename + ".pack"
681
680
        f.seek(0)
682
681
        self.pack_transport.put_file(basename + ".pack", f)
709
708
        pack_sha = p.index.objects_sha1()
710
709
 
711
710
        datafile = self.pack_transport.open_write_stream(
712
 
                "pack-%s.pack" % pack_sha)
 
711
                "pack-%s.pack" % pack_sha.decode('ascii'))
713
712
        try:
714
713
            entries, data_sum = write_pack_objects(datafile, p.pack_tuples())
715
714
        finally:
716
715
            datafile.close()
717
716
        entries = sorted([(k, v[0], v[1]) for (k, v) in entries.items()])
718
717
        idxfile = self.pack_transport.open_write_stream(
719
 
            "pack-%s.idx" % pack_sha)
 
718
            "pack-%s.idx" % pack_sha.decode('ascii'))
720
719
        try:
721
720
            write_pack_index_v2(idxfile, entries, data_sum)
722
721
        finally: