def test_write_with_peeled(self): f = StringIO() write_packed_refs(f, {'ref/1': ONES, 'ref/2': TWOS}, {'ref/1': THREES}) self.assertEqual( "# pack-refs with: peeled\n%s ref/1\n^%s\n%s ref/2\n" % ( ONES, THREES, TWOS), f.getvalue())
def test_write_with_peeled(self): with BytesIO() as f: write_packed_refs(f, {b'ref/1': ONES.hex_bytes, b'ref/2': TWOS.hex_bytes}, {b'ref/1': THREES.hex_bytes}) self.assertEqual( b'# pack-refs with: peeled\n' + ONES.hex_bytes + b' ref/1\n^' + THREES.hex_bytes + b'\n' + TWOS.hex_bytes + b' ref/2\n', f.getvalue())
def _remove_packed_ref(self, name): if self._packed_refs is None: return # reread cached refs from disk, while holding the lock self._packed_refs = None self.get_packed_refs() if name not in self._packed_refs: return del self._packed_refs[name] if name in self._peeled_refs: del self._peeled_refs[name] with self.transport.open_write_stream("packed-refs") as f: write_packed_refs(f, self._packed_refs, self._peeled_refs)
def test_write_without_peeled(self): f = StringIO() write_packed_refs(f, {'ref/1': ONES, 'ref/2': TWOS}) self.assertEqual("%s ref/1\n%s ref/2\n" % (ONES, TWOS), f.getvalue())
def test_write_with_peeled(self): f = StringIO() write_packed_refs(f, {'ref/1': ONES, 'ref/2': TWOS}, {'ref/1': THREES}) self.assertEqual( "# pack-refs with: peeled\n%s ref/1\n^%s\n%s ref/2\n" % (ONES, THREES, TWOS), f.getvalue())
def test_write_without_peeled(self): with BytesIO() as f: write_packed_refs(f, {b'ref/1': ONES.hex_bytes, b'ref/2': TWOS.hex_bytes}) self.assertEqual(ONES.hex_bytes + b' ref/1\n' + TWOS.hex_bytes + b' ref/2\n', f.getvalue())