Show More
@@ -103,8 +103,7 b' struct indexObjectStruct {' | |||||
103 | */ |
|
103 | */ | |
104 | long rust_ext_compat; /* compatibility with being used in rust |
|
104 | long rust_ext_compat; /* compatibility with being used in rust | |
105 | extensions */ |
|
105 | extensions */ | |
106 | char format_version; /* size of index headers. Differs in v1 v.s. v2 |
|
106 | long format_version; /* format version selector (format_*) */ | |
107 | format */ |
|
|||
108 | }; |
|
107 | }; | |
109 |
|
108 | |||
110 | static Py_ssize_t index_length(const indexObject *self) |
|
109 | static Py_ssize_t index_length(const indexObject *self) | |
@@ -133,9 +132,14 b' static const long v1_entry_size = 64;' | |||||
133 | /* A Revlogv2 index entry is 96 bytes long. */ |
|
132 | /* A Revlogv2 index entry is 96 bytes long. */ | |
134 | static const long v2_entry_size = 96; |
|
133 | static const long v2_entry_size = 96; | |
135 |
|
134 | |||
136 | static const long format_v1 = 1; /* Internal only, could be any number */ |
|
135 | /* A Changelogv2 index entry is 96 bytes long. */ | |
137 | static const long format_v2 = 2; /* Internal only, could be any number */ |
|
136 | static const long cl2_entry_size = 96; | |
138 | static const long format_cl2 = 3; /* Internal only, could be any number */ |
|
137 | ||
|
138 | /* Internal format version. | |||
|
139 | * Must match their counterparts in revlogutils/constants.py */ | |||
|
140 | static const long format_v1 = 1; /* constants.py: REVLOGV1 */ | |||
|
141 | static const long format_v2 = 0xDEAD; /* constants.py: REVLOGV2 */ | |||
|
142 | static const long format_cl2 = 0xD34D; /* constants.py: CHANGELOGV2 */ | |||
139 |
|
143 | |||
140 | static const long entry_v1_offset_high = 0; |
|
144 | static const long entry_v1_offset_high = 0; | |
141 | static const long entry_v1_offset_offset_flags = 4; |
|
145 | static const long entry_v1_offset_offset_flags = 4; | |
@@ -2979,10 +2983,10 b' static Py_ssize_t inline_scan(indexObjec' | |||||
2979 |
|
2983 | |||
2980 | static int index_init(indexObject *self, PyObject *args, PyObject *kwargs) |
|
2984 | static int index_init(indexObject *self, PyObject *args, PyObject *kwargs) | |
2981 | { |
|
2985 | { | |
2982 |
PyObject *data_obj, *inlined_obj |
|
2986 | PyObject *data_obj, *inlined_obj; | |
2983 | Py_ssize_t size; |
|
2987 | Py_ssize_t size; | |
2984 |
|
2988 | |||
2985 |
static char *kwlist[] = {"data", "inlined", " |
|
2989 | static char *kwlist[] = {"data", "inlined", "format", NULL}; | |
2986 |
|
2990 | |||
2987 | /* Initialize before argument-checking to avoid index_dealloc() crash. |
|
2991 | /* Initialize before argument-checking to avoid index_dealloc() crash. | |
2988 | */ |
|
2992 | */ | |
@@ -2999,10 +3003,11 b' static int index_init(indexObject *self,' | |||||
2999 | self->nodelen = 20; |
|
3003 | self->nodelen = 20; | |
3000 | self->nullentry = NULL; |
|
3004 | self->nullentry = NULL; | |
3001 | self->rust_ext_compat = 1; |
|
3005 | self->rust_ext_compat = 1; | |
3002 |
|
3006 | self->format_version = format_v1; | ||
3003 | revlogv2 = NULL; |
|
3007 | ||
3004 |
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO| |
|
3008 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|l", kwlist, | |
3005 |
&data_obj, &inlined_obj, |
|
3009 | &data_obj, &inlined_obj, | |
|
3010 | &(self->format_version))) | |||
3006 | return -1; |
|
3011 | return -1; | |
3007 | if (!PyObject_CheckBuffer(data_obj)) { |
|
3012 | if (!PyObject_CheckBuffer(data_obj)) { | |
3008 | PyErr_SetString(PyExc_TypeError, |
|
3013 | PyErr_SetString(PyExc_TypeError, | |
@@ -3014,12 +3019,12 b' static int index_init(indexObject *self,' | |||||
3014 | return -1; |
|
3019 | return -1; | |
3015 | } |
|
3020 | } | |
3016 |
|
3021 | |||
3017 | if (revlogv2 && PyObject_IsTrue(revlogv2)) { |
|
3022 | if (self->format_version == format_v1) { | |
3018 | self->format_version = format_v2; |
|
3023 | self->entry_size = v1_entry_size; | |
|
3024 | } else if (self->format_version == format_v2) { | |||
3019 | self->entry_size = v2_entry_size; |
|
3025 | self->entry_size = v2_entry_size; | |
3020 | } else { |
|
3026 | } else if (self->format_version == format_cl2) { | |
3021 | self->format_version = format_v1; |
|
3027 | self->entry_size = cl2_entry_size; | |
3022 | self->entry_size = v1_entry_size; |
|
|||
3023 | } |
|
3028 | } | |
3024 |
|
3029 | |||
3025 | self->nullentry = |
|
3030 | self->nullentry = |
@@ -799,9 +799,14 b' class InlinedIndexObject(BaseIndexObject' | |||||
799 | return self._offsets[i] |
|
799 | return self._offsets[i] | |
800 |
|
800 | |||
801 |
|
801 | |||
802 |
def parse_index2(data, inline, |
|
802 | def parse_index2(data, inline, format=revlog_constants.REVLOGV1): | |
|
803 | if format == revlog_constants.CHANGELOGV2: | |||
|
804 | return parse_index_cl_v2(data) | |||
803 | if not inline: |
|
805 | if not inline: | |
804 | cls = IndexObject2 if revlogv2 else IndexObject |
|
806 | if format == revlog_constants.REVLOGV2: | |
|
807 | cls = IndexObject2 | |||
|
808 | else: | |||
|
809 | cls = IndexObject | |||
805 | return cls(data), None |
|
810 | return cls(data), None | |
806 | cls = InlinedIndexObject |
|
811 | cls = InlinedIndexObject | |
807 | return cls(data, inline), (0, data) |
|
812 | return cls(data, inline), (0, data) |
@@ -103,6 +103,7 b' from .utils import (' | |||||
103 | REVLOGV0 |
|
103 | REVLOGV0 | |
104 | REVLOGV1 |
|
104 | REVLOGV1 | |
105 | REVLOGV2 |
|
105 | REVLOGV2 | |
|
106 | CHANGELOGV2 | |||
106 | FLAG_INLINE_DATA |
|
107 | FLAG_INLINE_DATA | |
107 | FLAG_GENERALDELTA |
|
108 | FLAG_GENERALDELTA | |
108 | REVLOG_DEFAULT_FLAGS |
|
109 | REVLOG_DEFAULT_FLAGS | |
@@ -201,16 +202,13 b' def parse_index_v1(data, inline):' | |||||
201 |
|
202 | |||
202 | def parse_index_v2(data, inline): |
|
203 | def parse_index_v2(data, inline): | |
203 | # call the C implementation to parse the index data |
|
204 | # call the C implementation to parse the index data | |
204 |
index, cache = parsers.parse_index2(data, inline, |
|
205 | index, cache = parsers.parse_index2(data, inline, format=REVLOGV2) | |
205 | return index, cache |
|
206 | return index, cache | |
206 |
|
207 | |||
207 |
|
208 | |||
208 | def parse_index_cl_v2(data, inline): |
|
209 | def parse_index_cl_v2(data, inline): | |
209 | # call the C implementation to parse the index data |
|
210 | # call the C implementation to parse the index data | |
210 | assert not inline |
|
211 | index, cache = parsers.parse_index2(data, inline, format=CHANGELOGV2) | |
211 | from .pure.parsers import parse_index_cl_v2 |
|
|||
212 |
|
||||
213 | index, cache = parse_index_cl_v2(data) |
|
|||
214 | return index, cache |
|
212 | return index, cache | |
215 |
|
213 | |||
216 |
|
214 |
@@ -134,8 +134,8 b' data_non_inlined = (' | |||||
134 | ) |
|
134 | ) | |
135 |
|
135 | |||
136 |
|
136 | |||
137 |
def parse_index2(data, inline, |
|
137 | def parse_index2(data, inline, format=constants.REVLOGV1): | |
138 |
index, chunkcache = parsers.parse_index2(data, inline, |
|
138 | index, chunkcache = parsers.parse_index2(data, inline, format=format) | |
139 | return list(index), chunkcache |
|
139 | return list(index), chunkcache | |
140 |
|
140 | |||
141 |
|
141 |
General Comments 0
You need to be logged in to leave comments.
Login now