Mercurial > hg
annotate mercurial/parsers.c @ 11518:8d827f4a23f1 stable
commands: mention "hg status -C" in addremove help
author | Arnab Bose <hirak99@gmail.com> |
---|---|
date | Fri, 09 Jul 2010 13:31:37 +0200 |
parents | 3de3d670d2b6 |
children | 5ef5eb1f3515 |
rev | line source |
---|---|
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
1 /* |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
2 parsers.c - efficient content parsing |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
3 |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
4 Copyright 2008 Matt Mackall <mpm@selenic.com> and others |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
5 |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
6 This software may be used and distributed according to the terms of |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
7 the GNU General Public License, incorporated herein by reference. |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
8 */ |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
9 |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
10 #include <Python.h> |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
11 #include <ctype.h> |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
12 #include <string.h> |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
13 |
11361
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
14 #include "util.h" |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
15 |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
16 static int hexdigit(char c) |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
17 { |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
18 if (c >= '0' && c <= '9') |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
19 return c - '0'; |
7092
fb3fc27617a2
parsers: speed up hex decoding for manifests
Matt Mackall <mpm@selenic.com>
parents:
7091
diff
changeset
|
20 if (c >= 'a' && c <= 'f') |
fb3fc27617a2
parsers: speed up hex decoding for manifests
Matt Mackall <mpm@selenic.com>
parents:
7091
diff
changeset
|
21 return c - 'a' + 10; |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
22 if (c >= 'A' && c <= 'F') |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
23 return c - 'A' + 10; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
24 |
7092
fb3fc27617a2
parsers: speed up hex decoding for manifests
Matt Mackall <mpm@selenic.com>
parents:
7091
diff
changeset
|
25 PyErr_SetString(PyExc_ValueError, "input contains non-hex character"); |
fb3fc27617a2
parsers: speed up hex decoding for manifests
Matt Mackall <mpm@selenic.com>
parents:
7091
diff
changeset
|
26 return 0; |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
27 } |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
28 |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
29 /* |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
30 * Turn a hex-encoded string into binary. |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
31 */ |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
32 static PyObject *unhexlify(const char *str, int len) |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
33 { |
7092
fb3fc27617a2
parsers: speed up hex decoding for manifests
Matt Mackall <mpm@selenic.com>
parents:
7091
diff
changeset
|
34 PyObject *ret; |
6395
3f0294536b24
fix const annotation warning
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6389
diff
changeset
|
35 const char *c; |
3f0294536b24
fix const annotation warning
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6389
diff
changeset
|
36 char *d; |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
37 |
11361
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
38 ret = PyBytes_FromStringAndSize(NULL, len / 2); |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
39 |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
40 if (!ret) |
7092
fb3fc27617a2
parsers: speed up hex decoding for manifests
Matt Mackall <mpm@selenic.com>
parents:
7091
diff
changeset
|
41 return NULL; |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
42 |
11361
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
43 d = PyBytes_AsString(ret); |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
44 |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
45 for (c = str; c < str + len;) { |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
46 int hi = hexdigit(*c++); |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
47 int lo = hexdigit(*c++); |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
48 *d++ = (hi << 4) | lo; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
49 } |
7091
12b35ae03365
parsers: clean up whitespace
Matt Mackall <mpm@selenic.com>
parents:
6395
diff
changeset
|
50 |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
51 return ret; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
52 } |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
53 |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
54 /* |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
55 * This code assumes that a manifest is stitched together with newline |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
56 * ('\n') characters. |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
57 */ |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
58 static PyObject *parse_manifest(PyObject *self, PyObject *args) |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
59 { |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
60 PyObject *mfdict, *fdict; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
61 char *str, *cur, *start, *zero; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
62 int len; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
63 |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
64 if (!PyArg_ParseTuple(args, "O!O!s#:parse_manifest", |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
65 &PyDict_Type, &mfdict, |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
66 &PyDict_Type, &fdict, |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
67 &str, &len)) |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
68 goto quit; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
69 |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
70 for (start = cur = str, zero = NULL; cur < str + len; cur++) { |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
71 PyObject *file = NULL, *node = NULL; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
72 PyObject *flags = NULL; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
73 int nlen; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
74 |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
75 if (!*cur) { |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
76 zero = cur; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
77 continue; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
78 } |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
79 else if (*cur != '\n') |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
80 continue; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
81 |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
82 if (!zero) { |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
83 PyErr_SetString(PyExc_ValueError, |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
84 "manifest entry has no separator"); |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
85 goto quit; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
86 } |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
87 |
11361
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
88 file = PyBytes_FromStringAndSize(start, zero - start); |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
89 |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
90 if (!file) |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
91 goto bail; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
92 |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
93 nlen = cur - zero - 1; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
94 |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
95 node = unhexlify(zero + 1, nlen > 40 ? 40 : nlen); |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
96 if (!node) |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
97 goto bail; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
98 |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
99 if (nlen > 40) { |
11361
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
100 flags = PyBytes_FromStringAndSize(zero + 41, |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
101 nlen - 40); |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
102 if (!flags) |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
103 goto bail; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
104 |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
105 if (PyDict_SetItem(fdict, file, flags) == -1) |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
106 goto bail; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
107 } |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
108 |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
109 if (PyDict_SetItem(mfdict, file, node) == -1) |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
110 goto bail; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
111 |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
112 start = cur + 1; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
113 zero = NULL; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
114 |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
115 Py_XDECREF(flags); |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
116 Py_XDECREF(node); |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
117 Py_XDECREF(file); |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
118 continue; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
119 bail: |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
120 Py_XDECREF(flags); |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
121 Py_XDECREF(node); |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
122 Py_XDECREF(file); |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
123 goto quit; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
124 } |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
125 |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
126 if (len > 0 && *(cur - 1) != '\n') { |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
127 PyErr_SetString(PyExc_ValueError, |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
128 "manifest contains trailing garbage"); |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
129 goto quit; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
130 } |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
131 |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
132 Py_INCREF(Py_None); |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
133 return Py_None; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
134 quit: |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
135 return NULL; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
136 } |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
137 |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
138 #ifdef _WIN32 |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
9427
diff
changeset
|
139 #ifdef _MSC_VER |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
140 /* msvc 6.0 has problems */ |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
9427
diff
changeset
|
141 #define inline __inline |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
142 typedef unsigned long uint32_t; |
7122
3cf699e89e48
Fix missing uint64_t definition in parsers.c under Windows
Dhruva Krishnamurthy <dhruvakm@gmail.com>
parents:
7108
diff
changeset
|
143 typedef unsigned __int64 uint64_t; |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
9427
diff
changeset
|
144 #else |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
9427
diff
changeset
|
145 #include <stdint.h> |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
9427
diff
changeset
|
146 #endif |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
147 static uint32_t ntohl(uint32_t x) |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
148 { |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
149 return ((x & 0x000000ffUL) << 24) | |
7190
aecea6934fdd
Some additional space/tab cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
7186
diff
changeset
|
150 ((x & 0x0000ff00UL) << 8) | |
aecea6934fdd
Some additional space/tab cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
7186
diff
changeset
|
151 ((x & 0x00ff0000UL) >> 8) | |
aecea6934fdd
Some additional space/tab cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
7186
diff
changeset
|
152 ((x & 0xff000000UL) >> 24); |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
153 } |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
154 #else |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
155 /* not windows */ |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
9427
diff
changeset
|
156 #include <sys/types.h> |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
9427
diff
changeset
|
157 #if defined __BEOS__ && !defined __HAIKU__ |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
9427
diff
changeset
|
158 #include <ByteOrder.h> |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
9427
diff
changeset
|
159 #else |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
9427
diff
changeset
|
160 #include <arpa/inet.h> |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
9427
diff
changeset
|
161 #endif |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
9427
diff
changeset
|
162 #include <inttypes.h> |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
163 #endif |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
164 |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
165 static PyObject *parse_dirstate(PyObject *self, PyObject *args) |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
166 { |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
167 PyObject *dmap, *cmap, *parents = NULL, *ret = NULL; |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
168 PyObject *fname = NULL, *cname = NULL, *entry = NULL; |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
169 char *str, *cur, *end, *cpos; |
7174
4da87407b845
parsers.c: fix integer overflows
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7168
diff
changeset
|
170 int state, mode, size, mtime; |
4da87407b845
parsers.c: fix integer overflows
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7168
diff
changeset
|
171 unsigned int flen; |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
172 int len; |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
173 char decode[16]; /* for alignment */ |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
174 |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
175 if (!PyArg_ParseTuple(args, "O!O!s#:parse_dirstate", |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
176 &PyDict_Type, &dmap, |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
177 &PyDict_Type, &cmap, |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
178 &str, &len)) |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
179 goto quit; |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
180 |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
181 /* read parents */ |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
182 if (len < 40) |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
183 goto quit; |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
184 |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
185 parents = Py_BuildValue("s#s#", str, 20, str + 20, 20); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
186 if (!parents) |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
187 goto quit; |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
188 |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
189 /* read filenames */ |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
190 cur = str + 40; |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
191 end = str + len; |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
192 |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
193 while (cur < end - 17) { |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
194 /* unpack header */ |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
195 state = *cur; |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
196 memcpy(decode, cur + 1, 16); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
197 mode = ntohl(*(uint32_t *)(decode)); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
198 size = ntohl(*(uint32_t *)(decode + 4)); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
199 mtime = ntohl(*(uint32_t *)(decode + 8)); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
200 flen = ntohl(*(uint32_t *)(decode + 12)); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
201 cur += 17; |
10449
7c8266c1d15a
parsers: fix some signed comparison issues
Matt Mackall <mpm@selenic.com>
parents:
10282
diff
changeset
|
202 if (cur + flen > end || cur + flen < cur) { |
7174
4da87407b845
parsers.c: fix integer overflows
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7168
diff
changeset
|
203 PyErr_SetString(PyExc_ValueError, "overflow in dirstate"); |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
204 goto quit; |
7174
4da87407b845
parsers.c: fix integer overflows
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7168
diff
changeset
|
205 } |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
206 |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
207 entry = Py_BuildValue("ciii", state, mode, size, mtime); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
208 if (!entry) |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
209 goto quit; |
7175
5d8626b2c1db
parsers.c: do not try to untrack after a failure
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7174
diff
changeset
|
210 PyObject_GC_UnTrack(entry); /* don't waste time with this */ |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
211 |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
212 cpos = memchr(cur, 0, flen); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
213 if (cpos) { |
11361
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
214 fname = PyBytes_FromStringAndSize(cur, cpos - cur); |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
215 cname = PyBytes_FromStringAndSize(cpos + 1, |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
216 flen - (cpos - cur) - 1); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
217 if (!fname || !cname || |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
218 PyDict_SetItem(cmap, fname, cname) == -1 || |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
219 PyDict_SetItem(dmap, fname, entry) == -1) |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
220 goto quit; |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
221 Py_DECREF(cname); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
222 } else { |
11361
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
223 fname = PyBytes_FromStringAndSize(cur, flen); |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
224 if (!fname || |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
225 PyDict_SetItem(dmap, fname, entry) == -1) |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
226 goto quit; |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
227 } |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
228 cur += flen; |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
229 Py_DECREF(fname); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
230 Py_DECREF(entry); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
231 fname = cname = entry = NULL; |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
232 } |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
233 |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
234 ret = parents; |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
235 Py_INCREF(ret); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
236 quit: |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
237 Py_XDECREF(fname); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
238 Py_XDECREF(cname); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
239 Py_XDECREF(entry); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
240 Py_XDECREF(parents); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
241 return ret; |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
242 } |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
243 |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
244 const char nullid[20]; |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
245 const int nullrev = -1; |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
246 |
7154
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
247 /* create an index tuple, insert into the nodemap */ |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
248 static PyObject * _build_idx_entry(PyObject *nodemap, int n, uint64_t offset_flags, |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
249 int comp_len, int uncomp_len, int base_rev, |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
250 int link_rev, int parent_1, int parent_2, |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
251 const char *c_node_id) |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
252 { |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
253 int err; |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
254 PyObject *entry, *node_id, *n_obj; |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
255 |
11361
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
256 node_id = PyBytes_FromStringAndSize(c_node_id, 20); |
7154
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
257 n_obj = PyInt_FromLong(n); |
11361
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
258 |
7154
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
259 if (!node_id || !n_obj) |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
260 err = -1; |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
261 else |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
262 err = PyDict_SetItem(nodemap, node_id, n_obj); |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
263 |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
264 Py_XDECREF(n_obj); |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
265 if (err) |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
266 goto error_dealloc; |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
267 |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
268 entry = Py_BuildValue("LiiiiiiN", offset_flags, comp_len, |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
269 uncomp_len, base_rev, link_rev, |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
270 parent_1, parent_2, node_id); |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
271 if (!entry) |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
272 goto error_dealloc; |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
273 PyObject_GC_UnTrack(entry); /* don't waste time with this */ |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
274 |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
275 return entry; |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
276 |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
277 error_dealloc: |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
278 Py_XDECREF(node_id); |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
279 return NULL; |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
280 } |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
281 |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
282 /* RevlogNG format (all in big endian, data may be inlined): |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
283 * 6 bytes: offset |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
284 * 2 bytes: flags |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
285 * 4 bytes: compressed length |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
286 * 4 bytes: uncompressed length |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
287 * 4 bytes: base revision |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
288 * 4 bytes: link revision |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
289 * 4 bytes: parent 1 revision |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
290 * 4 bytes: parent 2 revision |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
291 * 32 bytes: nodeid (only 20 bytes used) |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
292 */ |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
293 static int _parse_index_ng (const char *data, int size, int inlined, |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
294 PyObject *index, PyObject *nodemap) |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
295 { |
7154
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
296 PyObject *entry; |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
297 int n = 0, err; |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
298 uint64_t offset_flags; |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
299 int comp_len, uncomp_len, base_rev, link_rev, parent_1, parent_2; |
7154
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
300 const char *c_node_id; |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
301 const char *end = data + size; |
7169
6d28a399293e
Copy index before parsing to enforce alignment with inline data present.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
7154
diff
changeset
|
302 char decode[64]; /* to enforce alignment with inline data */ |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
303 |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
304 while (data < end) { |
7174
4da87407b845
parsers.c: fix integer overflows
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7168
diff
changeset
|
305 unsigned int step; |
7190
aecea6934fdd
Some additional space/tab cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
7186
diff
changeset
|
306 |
7169
6d28a399293e
Copy index before parsing to enforce alignment with inline data present.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
7154
diff
changeset
|
307 memcpy(decode, data, 64); |
7186
f77c8d8331ca
clean up trailing spaces, leading spaces in C
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7176
diff
changeset
|
308 offset_flags = ntohl(*((uint32_t *) (decode + 4))); |
f77c8d8331ca
clean up trailing spaces, leading spaces in C
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7176
diff
changeset
|
309 if (n == 0) /* mask out version number for the first entry */ |
f77c8d8331ca
clean up trailing spaces, leading spaces in C
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7176
diff
changeset
|
310 offset_flags &= 0xFFFF; |
f77c8d8331ca
clean up trailing spaces, leading spaces in C
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7176
diff
changeset
|
311 else { |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
9427
diff
changeset
|
312 uint32_t offset_high = ntohl(*((uint32_t *)decode)); |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
9427
diff
changeset
|
313 offset_flags |= ((uint64_t)offset_high) << 32; |
7133
42db22108d85
revlog parser: use ntohl() instead of ntohll() (fix endianness issues)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7108
diff
changeset
|
314 } |
42db22108d85
revlog parser: use ntohl() instead of ntohll() (fix endianness issues)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7108
diff
changeset
|
315 |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
9427
diff
changeset
|
316 comp_len = ntohl(*((uint32_t *)(decode + 8))); |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
9427
diff
changeset
|
317 uncomp_len = ntohl(*((uint32_t *)(decode + 12))); |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
9427
diff
changeset
|
318 base_rev = ntohl(*((uint32_t *)(decode + 16))); |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
9427
diff
changeset
|
319 link_rev = ntohl(*((uint32_t *)(decode + 20))); |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
9427
diff
changeset
|
320 parent_1 = ntohl(*((uint32_t *)(decode + 24))); |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
9427
diff
changeset
|
321 parent_2 = ntohl(*((uint32_t *)(decode + 28))); |
7169
6d28a399293e
Copy index before parsing to enforce alignment with inline data present.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
7154
diff
changeset
|
322 c_node_id = decode + 32; |
7154
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
323 |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
324 entry = _build_idx_entry(nodemap, n, offset_flags, |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
325 comp_len, uncomp_len, base_rev, |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
326 link_rev, parent_1, parent_2, |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
327 c_node_id); |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
328 if (!entry) |
7154
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
329 return 0; |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
330 |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
331 if (inlined) { |
7154
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
332 err = PyList_Append(index, entry); |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
333 Py_DECREF(entry); |
7154
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
334 if (err) |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
335 return 0; |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
336 } else |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
337 PyList_SET_ITEM(index, n, entry); /* steals reference */ |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
338 |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
339 n++; |
7174
4da87407b845
parsers.c: fix integer overflows
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7168
diff
changeset
|
340 step = 64 + (inlined ? comp_len : 0); |
10449
7c8266c1d15a
parsers: fix some signed comparison issues
Matt Mackall <mpm@selenic.com>
parents:
10282
diff
changeset
|
341 if (data + step > end || data + step < data) |
7174
4da87407b845
parsers.c: fix integer overflows
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7168
diff
changeset
|
342 break; |
4da87407b845
parsers.c: fix integer overflows
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7168
diff
changeset
|
343 data += step; |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
344 } |
7174
4da87407b845
parsers.c: fix integer overflows
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7168
diff
changeset
|
345 if (data != end) { |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
346 if (!PyErr_Occurred()) |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
347 PyErr_SetString(PyExc_ValueError, "corrupt index file"); |
7154
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
348 return 0; |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
349 } |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
350 |
7190
aecea6934fdd
Some additional space/tab cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
7186
diff
changeset
|
351 /* create the nullid/nullrev entry in the nodemap and the |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
352 * magic nullid entry in the index at [-1] */ |
7190
aecea6934fdd
Some additional space/tab cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
7186
diff
changeset
|
353 entry = _build_idx_entry(nodemap, |
7154
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
354 nullrev, 0, 0, 0, -1, -1, -1, -1, nullid); |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
355 if (!entry) |
7154
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
356 return 0; |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
357 if (inlined) { |
7154
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
358 err = PyList_Append(index, entry); |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
359 Py_DECREF(entry); |
7154
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
360 if (err) |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
361 return 0; |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
362 } else |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
363 PyList_SET_ITEM(index, n, entry); /* steals reference */ |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
364 |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
365 return 1; |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
366 } |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
367 |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
368 /* This function parses a index file and returns a Python tuple of the |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
369 * following format: (index, nodemap, cache) |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
370 * |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
371 * index: a list of tuples containing the RevlogNG records |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
372 * nodemap: a dict mapping node ids to indices in the index list |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
373 * cache: if data is inlined, a tuple (index_file_content, 0) else None |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
374 */ |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
375 static PyObject *parse_index(PyObject *self, PyObject *args) |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
376 { |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
377 const char *data; |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
378 int size, inlined; |
7190
aecea6934fdd
Some additional space/tab cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
7186
diff
changeset
|
379 PyObject *rval = NULL, *index = NULL, *nodemap = NULL, *cache = NULL; |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
380 PyObject *data_obj = NULL, *inlined_obj; |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
381 |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
382 if (!PyArg_ParseTuple(args, "s#O", &data, &size, &inlined_obj)) |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
383 return NULL; |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
384 inlined = inlined_obj && PyObject_IsTrue(inlined_obj); |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
385 |
7190
aecea6934fdd
Some additional space/tab cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
7186
diff
changeset
|
386 /* If no data is inlined, we know the size of the index list in |
aecea6934fdd
Some additional space/tab cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
7186
diff
changeset
|
387 * advance: size divided by size of one one revlog record (64 bytes) |
aecea6934fdd
Some additional space/tab cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
7186
diff
changeset
|
388 * plus one for the nullid */ |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
389 index = inlined ? PyList_New(0) : PyList_New(size / 64 + 1); |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
390 if (!index) |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
391 goto quit; |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
392 |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
393 nodemap = PyDict_New(); |
7154
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
394 if (!nodemap) |
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
395 goto quit; |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
396 |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
397 /* set up the cache return value */ |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
398 if (inlined) { |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
399 /* Note that the reference to data_obj is only borrowed */ |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
400 data_obj = PyTuple_GET_ITEM(args, 0); |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
401 cache = Py_BuildValue("iO", 0, data_obj); |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
402 if (!cache) |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
403 goto quit; |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
404 } else { |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
405 cache = Py_None; |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
406 Py_INCREF(Py_None); |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
407 } |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
408 |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
409 /* actually populate the index and the nodemap with data */ |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
410 if (!_parse_index_ng (data, size, inlined, index, nodemap)) |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
411 goto quit; |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
412 |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
413 rval = Py_BuildValue("NNN", index, nodemap, cache); |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
414 if (!rval) |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
415 goto quit; |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
416 return rval; |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
417 |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
418 quit: |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
419 Py_XDECREF(index); |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
420 Py_XDECREF(nodemap); |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
421 Py_XDECREF(cache); |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
422 Py_XDECREF(rval); |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
423 return NULL; |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
424 } |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
425 |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
426 |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
427 static char parsers_doc[] = "Efficient content parsing."; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
428 |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
429 static PyMethodDef methods[] = { |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
430 {"parse_manifest", parse_manifest, METH_VARARGS, "parse a manifest\n"}, |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
431 {"parse_dirstate", parse_dirstate, METH_VARARGS, "parse a dirstate\n"}, |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
432 {"parse_index", parse_index, METH_VARARGS, "parse a revlog index\n"}, |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
433 {NULL, NULL} |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
434 }; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
435 |
11361
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
436 #ifdef IS_PY3K |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
437 static struct PyModuleDef parsers_module = { |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
438 PyModuleDef_HEAD_INIT, |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
439 "parsers", |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
440 parsers_doc, |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
441 -1, |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
442 methods |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
443 }; |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
444 |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
445 PyMODINIT_FUNC PyInit_parsers(void) |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
446 { |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
447 return PyModule_Create(&parsers_module); |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
448 } |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
449 #else |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
450 PyMODINIT_FUNC initparsers(void) |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
451 { |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
452 Py_InitModule3("parsers", methods, parsers_doc); |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
453 } |
11361
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
454 #endif |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
455 |