示例#1
0
    def test_read_with_peeled_errors(self):
        f = StringIO('^%s\n%s ref/1' % (TWOS, ONES))
        self.assertRaises(errors.PackedRefsException, list,
                          read_packed_refs(f))

        f = StringIO('%s ref/1\n^%s\n^%s' % (ONES, TWOS, THREES))
        self.assertRaises(errors.PackedRefsException, list,
                          read_packed_refs(f))
示例#2
0
    def test_read_with_peeled_errors(self):
        with BytesIO(b'^' + TWOS.hex_bytes + b'\n' + ONES.hex_bytes +
                     b' ref/1') as f:
            self.assertRaises(errors.PackedRefsException, list,
                              read_packed_refs(f))

        with BytesIO(ONES.hex_bytes + b' ref/1\n^' + TWOS.hex_bytes +
                     b'\n^' + THREES.hex_bytes) as f:
            self.assertRaises(errors.PackedRefsException, list,
                              read_packed_refs(f))
示例#3
0
    def get_packed_refs(self):
        """Get contents of the packed-refs file.

        :return: Dictionary mapping ref names to SHA1s

        :note: Will return an empty dictionary when no packed-refs file is
            present.
        """
        # TODO: invalidate the cache on repacking
        if self._packed_refs is None:
            # set both to empty because we want _peeled_refs to be
            # None if and only if _packed_refs is also None.
            self._packed_refs = {}
            self._peeled_refs = {}
            try:
                f = self.transport.get("packed-refs")
            except NoSuchFile:
                return {}
            try:
                first_line = next(iter(f)).rstrip()
                if (first_line.startswith(b"# pack-refs") and b" peeled" in
                        first_line):
                    for sha, name, peeled in read_packed_refs_with_peeled(f):
                        self._packed_refs[name] = sha
                        if peeled:
                            self._peeled_refs[name] = peeled
                else:
                    f.seek(0)
                    for sha, name in read_packed_refs(f):
                        self._packed_refs[name] = sha
            finally:
                f.close()
        return self._packed_refs
示例#4
0
 def test_read_without_peeled(self):
     f = StringIO('# comment\n%s ref/1\n%s ref/2' % (ONES, TWOS))
     self.assertEqual([(ONES, 'ref/1'), (TWOS, 'ref/2')],
                      list(read_packed_refs(f)))
示例#5
0
    def test_read_with_peeled_errors(self):
        f = StringIO('^%s\n%s ref/1' % (TWOS, ONES))
        self.assertRaises(errors.PackedRefsException, list, read_packed_refs(f))

        f = StringIO('%s ref/1\n^%s\n^%s' % (ONES, TWOS, THREES))
        self.assertRaises(errors.PackedRefsException, list, read_packed_refs(f))
示例#6
0
 def test_read_without_peeled(self):
     f = StringIO('# comment\n%s ref/1\n%s ref/2' % (ONES, TWOS))
     self.assertEqual([(ONES, 'ref/1'), (TWOS, 'ref/2')],
                      list(read_packed_refs(f)))
示例#7
0
 def test_read_without_peeled_errors(self):
     f = StringIO("%s ref/1\n^%s" % (ONES, TWOS))
     self.assertRaises(errors.PackedRefsException, list, read_packed_refs(f))
示例#8
0
 def test_read_without_peeled(self):
     with BytesIO(b'# comment\n' + ONES.hex_bytes + b' ref/1\n' +
                  TWOS.hex_bytes + b' ref/2') as f:
         self.assertEqual([(ONES, b'ref/1'), (TWOS, b'ref/2')],
                          list(read_packed_refs(f)))