Skip to content

Commit 17d9d13

Browse files
committed
Merge branch 'pack_writing'
2 parents df570f0 + 0c7a3ec commit 17d9d13

11 files changed

+737
-42
lines changed

gitdb.pro

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
2+
OTHER_FILES += \
3+
setup.py \
4+
README.rst \
5+
MANIFEST \
6+
Makefile \
7+
LICENSE \
8+
AUTHORS \
9+
gitdb/util.py \
10+
gitdb/typ.py \
11+
gitdb/stream.py \
12+
gitdb/pack.py \
13+
gitdb/__init__.py \
14+
gitdb/fun.py \
15+
gitdb/exc.py \
16+
gitdb/base.py \
17+
doc/source/tutorial.rst \
18+
doc/source/intro.rst \
19+
doc/source/index.rst \
20+
doc/source/conf.py \
21+
doc/source/changes.rst \
22+
doc/source/api.rst \
23+
doc/source/algorithm.rst \
24+
gitdb/db/ref.py \
25+
gitdb/db/pack.py \
26+
gitdb/db/mem.py \
27+
gitdb/db/loose.py \
28+
gitdb/db/__init__.py \
29+
gitdb/db/git.py \
30+
gitdb/db/base.py \
31+
gitdb/test/test_util.py \
32+
gitdb/test/test_stream.py \
33+
gitdb/test/test_pack.py \
34+
gitdb/test/test_example.py \
35+
gitdb/test/test_base.py \
36+
gitdb/test/lib.py \
37+
gitdb/test/__init__.py \
38+
gitdb/test/performance/test_stream.py \
39+
gitdb/test/performance/test_pack_streaming.py \
40+
gitdb/test/performance/test_pack.py \
41+
gitdb/test/performance/lib.py
42+
43+
HEADERS += \
44+
gitdb/_delta_apply.h
45+
46+
SOURCES += \
47+
gitdb/_fun.c \
48+
gitdb/_delta_apply.c

gitdb.pro.user

+267
Large diffs are not rendered by default.

gitdb/_delta_apply.c

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "_delta_apply.h"
1+
#include <_delta_apply.h>
22
#include <stdint.h>
33
#include <assert.h>
44
#include <stdio.h>
@@ -463,7 +463,7 @@ void DIV_reset(DeltaInfoVector* vec)
463463

464464
// Append one chunk to the end of the list, and return a pointer to it
465465
// It will not have been initialized !
466-
static inline
466+
inline
467467
DeltaInfo* DIV_append(DeltaInfoVector* vec)
468468
{
469469
if (vec->size + 1 > vec->reserved_size){
@@ -703,7 +703,7 @@ typedef struct {
703703
} DeltaChunkList;
704704

705705

706-
static
706+
707707
int DCL_init(DeltaChunkList*self, PyObject *args, PyObject *kwds)
708708
{
709709
if(args && PySequence_Size(args) > 0){
@@ -715,20 +715,20 @@ int DCL_init(DeltaChunkList*self, PyObject *args, PyObject *kwds)
715715
return 0;
716716
}
717717

718-
static
718+
719719
void DCL_dealloc(DeltaChunkList* self)
720720
{
721721
TSI_destroy(&(self->istream));
722722
}
723723

724-
static
724+
725725
PyObject* DCL_py_rbound(DeltaChunkList* self)
726726
{
727727
return PyLong_FromUnsignedLongLong(self->istream.target_size);
728728
}
729729

730730
// Write using a write function, taking remaining bytes from a base buffer
731-
static
731+
732732
PyObject* DCL_apply(DeltaChunkList* self, PyObject* args)
733733
{
734734
PyObject* pybuf = 0;
@@ -769,13 +769,13 @@ PyObject* DCL_apply(DeltaChunkList* self, PyObject* args)
769769
Py_RETURN_NONE;
770770
}
771771

772-
static PyMethodDef DCL_methods[] = {
772+
PyMethodDef DCL_methods[] = {
773773
{"apply", (PyCFunction)DCL_apply, METH_VARARGS, "Apply the given iterable of delta streams" },
774774
{"rbound", (PyCFunction)DCL_py_rbound, METH_NOARGS, NULL},
775775
{NULL} /* Sentinel */
776776
};
777777

778-
static PyTypeObject DeltaChunkListType = {
778+
PyTypeObject DeltaChunkListType = {
779779
PyObject_HEAD_INIT(NULL)
780780
0, /*ob_size*/
781781
"DeltaChunkList", /*tp_name*/
@@ -897,7 +897,7 @@ uint compute_chunk_count(const uchar* data, const uchar* dend, bool read_header)
897897
return num_chunks;
898898
}
899899

900-
static PyObject* connect_deltas(PyObject *self, PyObject *dstreams)
900+
PyObject* connect_deltas(PyObject *self, PyObject *dstreams)
901901
{
902902
// obtain iterator
903903
PyObject* stream_iter = 0;
@@ -1088,7 +1088,6 @@ static PyObject* connect_deltas(PyObject *self, PyObject *dstreams)
10881088

10891089
// Write using a write function, taking remaining bytes from a base buffer
10901090
// replaces the corresponding method in python
1091-
static
10921091
PyObject* apply_delta(PyObject* self, PyObject* args)
10931092
{
10941093
PyObject* pybbuf = 0;

gitdb/_delta_apply.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <Python.h>
22

3-
static PyObject* connect_deltas(PyObject *self, PyObject *dstreams);
4-
static PyObject* apply_delta(PyObject* self, PyObject* args);
3+
extern PyObject* connect_deltas(PyObject *self, PyObject *dstreams);
4+
extern PyObject* apply_delta(PyObject* self, PyObject* args);
55

6-
static PyTypeObject DeltaChunkListType;
6+
extern PyTypeObject DeltaChunkListType;

gitdb/exc.py

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class BadObject(ODBError):
1717

1818
def __str__(self):
1919
return "BadObject: %s" % to_hex_sha(self.args[0])
20+
21+
class ParseError(ODBError):
22+
"""Thrown if the parsing of a file failed due to an invalid format"""
2023

2124
class AmbiguousObjectName(ODBError):
2225
"""Thrown if a possibly shortened name does not uniquely represent a single object

gitdb/fun.py

+20-10
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
__all__ = ('is_loose_object', 'loose_object_header_info', 'msb_size', 'pack_object_header_info',
5050
'write_object', 'loose_object_header', 'stream_copy', 'apply_delta_data',
51-
'is_equal_canonical_sha', 'connect_deltas', 'DeltaChunkList')
51+
'is_equal_canonical_sha', 'connect_deltas', 'DeltaChunkList', 'create_pack_object_header')
5252

5353

5454
#{ Structures
@@ -411,15 +411,25 @@ def pack_object_header_info(data):
411411
size += (c & 0x7f) << s
412412
s += 7
413413
# END character loop
414-
415-
try:
416-
return (type_id, size, i)
417-
except KeyError:
418-
# invalid object type - we could try to be smart now and decode part
419-
# of the stream to get the info, problem is that we had trouble finding
420-
# the exact start of the content stream
421-
raise BadObjectType(type_id)
422-
# END handle exceptions
414+
return (type_id, size, i)
415+
416+
def create_pack_object_header(obj_type, obj_size):
417+
""":return: string defining the pack header comprised of the object type
418+
and its incompressed size in bytes
419+
:parmam obj_type: pack type_id of the object
420+
:param obj_size: uncompressed size in bytes of the following object stream"""
421+
c = 0 # 1 byte
422+
hdr = str() # output string
423+
424+
c = (obj_type << 4) | (obj_size & 0xf)
425+
obj_size >>= 4
426+
while obj_size:
427+
hdr += chr(c | 0x80)
428+
c = obj_size & 0x7f
429+
obj_size >>= 7
430+
#END until size is consumed
431+
hdr += chr(c)
432+
return hdr
423433

424434
def msb_size(data, offset=0):
425435
"""

0 commit comments

Comments
 (0)