Ejemplo n.º 1
0
    def test_read_objects(self):
        f = BytesIO()
        entries = build_pack(f, [
          (Blob.type_num, 'blob'),
          (OFS_DELTA, (0, 'blob1')),
          ])
        reader = PackStreamReader(f.read)
        objects = list(reader.read_objects(compute_crc32=True))
        self.assertEqual(2, len(objects))

        unpacked_blob, unpacked_delta = objects

        self.assertEqual(entries[0][0], unpacked_blob.offset)
        self.assertEqual(Blob.type_num, unpacked_blob.pack_type_num)
        self.assertEqual(Blob.type_num, unpacked_blob.obj_type_num)
        self.assertEqual(None, unpacked_blob.delta_base)
        self.assertEqual('blob', ''.join(unpacked_blob.decomp_chunks))
        self.assertEqual(entries[0][4], unpacked_blob.crc32)

        self.assertEqual(entries[1][0], unpacked_delta.offset)
        self.assertEqual(OFS_DELTA, unpacked_delta.pack_type_num)
        self.assertEqual(None, unpacked_delta.obj_type_num)
        self.assertEqual(unpacked_delta.offset - unpacked_blob.offset,
                         unpacked_delta.delta_base)
        delta = create_delta('blob', 'blob1')
        self.assertEqual(delta, ''.join(unpacked_delta.decomp_chunks))
        self.assertEqual(entries[1][4], unpacked_delta.crc32)
Ejemplo n.º 2
0
    def test_read_objects(self):
        f = BytesIO()
        entries = build_pack(f, [
          (Blob.type_num, 'blob'),
          (OFS_DELTA, (0, 'blob1')),
          ])
        reader = PackStreamReader(f.read)
        objects = list(reader.read_objects(compute_crc32=True))
        self.assertEqual(2, len(objects))

        unpacked_blob, unpacked_delta = objects

        self.assertEqual(entries[0][0], unpacked_blob.offset)
        self.assertEqual(Blob.type_num, unpacked_blob.pack_type_num)
        self.assertEqual(Blob.type_num, unpacked_blob.obj_type_num)
        self.assertEqual(None, unpacked_blob.delta_base)
        self.assertEqual('blob', ''.join(unpacked_blob.decomp_chunks))
        self.assertEqual(entries[0][4], unpacked_blob.crc32)

        self.assertEqual(entries[1][0], unpacked_delta.offset)
        self.assertEqual(OFS_DELTA, unpacked_delta.pack_type_num)
        self.assertEqual(None, unpacked_delta.obj_type_num)
        self.assertEqual(unpacked_delta.offset - unpacked_blob.offset,
                         unpacked_delta.delta_base)
        delta = create_delta('blob', 'blob1')
        self.assertEqual(delta, ''.join(unpacked_delta.decomp_chunks))
        self.assertEqual(entries[1][4], unpacked_delta.crc32)
Ejemplo n.º 3
0
def git_receive_pack(project_name):
    p = subprocess.Popen(['git-receive-pack', '--stateless-rpc', os.path.join('.', project_name)], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
    data_in = request.data
    print('data_in is ', type(data_in))
    print('data_in is ', data_in)
    pack_file = data_in[data_in.index('PACK'.encode('utf8')):]
    print('pack_file is ', pack_file)
    objects = PackStreamReader(BytesIO(pack_file).read)
    for obj in objects.read_objects():
        if obj.obj_type_num == 1: # Commit
            print(obj)
    print('before data_in')
    import sys
    sys.stdout.flush()
    p.stdin.write(data_in)
    p.stdin.flush()
    p.stdin.close()
    print('before data_out')
    import sys
    sys.stdout.flush()
    data_out = p.stdout.read()
    print('after stdout.read()')
    import sys
    sys.stdout.flush()
    res = make_response(data_out)
    res.headers['Expires'] = 'Fri, 01 Jan 1980 00:00:00 GMT'
    res.headers['Pragma'] = 'no-cache'
    res.headers['Cache-Control'] = 'no-cache, max-age=0, must-revalidate'
    res.headers['Content-Type'] = 'application/x-git-receive-pack-result'
    #p.wait()
    print("end")
    import sys
    sys.stdout.flush()
    return res
Ejemplo n.º 4
0
 def test_read_objects_buffered(self):
     f = BytesIO()
     build_pack(f, [
       (Blob.type_num, 'blob'),
       (OFS_DELTA, (0, 'blob1')),
       ])
     reader = PackStreamReader(f.read, zlib_bufsize=4)
     self.assertEqual(2, len(list(reader.read_objects())))
Ejemplo n.º 5
0
 def test_read_objects_buffered(self):
     f = BytesIO()
     build_pack(f, [
       (Blob.type_num, 'blob'),
       (OFS_DELTA, (0, 'blob1')),
       ])
     reader = PackStreamReader(f.read, zlib_bufsize=4)
     self.assertEqual(2, len(list(reader.read_objects())))
Ejemplo n.º 6
0
 def test_read_objects_empty(self):
     reader = PackStreamReader(BytesIO().read)
     self.assertEqual([], list(reader.read_objects()))
Ejemplo n.º 7
0
 def test_read_objects_emtpy(self):
     f = BytesIO()
     build_pack(f, [])
     reader = PackStreamReader(f.read)
     self.assertEqual(0, len(list(reader.read_objects())))
Ejemplo n.º 8
0
 def test_read_objects_empty(self):
     reader = PackStreamReader(BytesIO().read)
     self.assertEqual([], list(reader.read_objects()))
Ejemplo n.º 9
0
 def test_read_objects_emtpy(self):
     f = BytesIO()
     build_pack(f, [])
     reader = PackStreamReader(f.read)
     self.assertEqual(0, len(list(reader.read_objects())))