Mercurial > hg-stable
annotate mercurial/parsers.c @ 21871:0feb41534421
parsers: remove unused getintat function
Warning detected by clang.
author | Siddharth Agarwal <sid0@fb.com> |
---|---|
date | Mon, 14 Jul 2014 15:42:31 -0700 |
parents | e250b8300e6e |
children | 9f490afcb067 |
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> |
17356
511dfb34b412
parsers: fix an integer size warning issued by clang
Bryan O'Sullivan <bryano@fb.com>
parents:
17353
diff
changeset
|
12 #include <stddef.h> |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
13 #include <string.h> |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
14 |
11361
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
15 #include "util.h" |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
16 |
20742
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
17 static char *versionerrortext = "Python minor version mismatch"; |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
18 |
19718
d69e06724b96
parsers: use a lookup table to convert hex to binary
Siddharth Agarwal <sid0@fb.com>
parents:
19652
diff
changeset
|
19 static int8_t hextable[256] = { |
d69e06724b96
parsers: use a lookup table to convert hex to binary
Siddharth Agarwal <sid0@fb.com>
parents:
19652
diff
changeset
|
20 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
d69e06724b96
parsers: use a lookup table to convert hex to binary
Siddharth Agarwal <sid0@fb.com>
parents:
19652
diff
changeset
|
21 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
d69e06724b96
parsers: use a lookup table to convert hex to binary
Siddharth Agarwal <sid0@fb.com>
parents:
19652
diff
changeset
|
22 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
d69e06724b96
parsers: use a lookup table to convert hex to binary
Siddharth Agarwal <sid0@fb.com>
parents:
19652
diff
changeset
|
23 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, /* 0-9 */ |
d69e06724b96
parsers: use a lookup table to convert hex to binary
Siddharth Agarwal <sid0@fb.com>
parents:
19652
diff
changeset
|
24 -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* A-F */ |
d69e06724b96
parsers: use a lookup table to convert hex to binary
Siddharth Agarwal <sid0@fb.com>
parents:
19652
diff
changeset
|
25 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
d69e06724b96
parsers: use a lookup table to convert hex to binary
Siddharth Agarwal <sid0@fb.com>
parents:
19652
diff
changeset
|
26 -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* a-f */ |
d69e06724b96
parsers: use a lookup table to convert hex to binary
Siddharth Agarwal <sid0@fb.com>
parents:
19652
diff
changeset
|
27 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
d69e06724b96
parsers: use a lookup table to convert hex to binary
Siddharth Agarwal <sid0@fb.com>
parents:
19652
diff
changeset
|
28 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
d69e06724b96
parsers: use a lookup table to convert hex to binary
Siddharth Agarwal <sid0@fb.com>
parents:
19652
diff
changeset
|
29 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
d69e06724b96
parsers: use a lookup table to convert hex to binary
Siddharth Agarwal <sid0@fb.com>
parents:
19652
diff
changeset
|
30 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
d69e06724b96
parsers: use a lookup table to convert hex to binary
Siddharth Agarwal <sid0@fb.com>
parents:
19652
diff
changeset
|
31 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
d69e06724b96
parsers: use a lookup table to convert hex to binary
Siddharth Agarwal <sid0@fb.com>
parents:
19652
diff
changeset
|
32 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
d69e06724b96
parsers: use a lookup table to convert hex to binary
Siddharth Agarwal <sid0@fb.com>
parents:
19652
diff
changeset
|
33 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
d69e06724b96
parsers: use a lookup table to convert hex to binary
Siddharth Agarwal <sid0@fb.com>
parents:
19652
diff
changeset
|
34 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
d69e06724b96
parsers: use a lookup table to convert hex to binary
Siddharth Agarwal <sid0@fb.com>
parents:
19652
diff
changeset
|
35 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 |
d69e06724b96
parsers: use a lookup table to convert hex to binary
Siddharth Agarwal <sid0@fb.com>
parents:
19652
diff
changeset
|
36 }; |
d69e06724b96
parsers: use a lookup table to convert hex to binary
Siddharth Agarwal <sid0@fb.com>
parents:
19652
diff
changeset
|
37 |
16617
4fb16743049d
parsers: change the type signature of hexdigit
Bryan O'Sullivan <bryano@fb.com>
parents:
16616
diff
changeset
|
38 static inline int hexdigit(const char *p, Py_ssize_t off) |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
39 { |
19718
d69e06724b96
parsers: use a lookup table to convert hex to binary
Siddharth Agarwal <sid0@fb.com>
parents:
19652
diff
changeset
|
40 int8_t val = hextable[(unsigned char)p[off]]; |
16617
4fb16743049d
parsers: change the type signature of hexdigit
Bryan O'Sullivan <bryano@fb.com>
parents:
16616
diff
changeset
|
41 |
19718
d69e06724b96
parsers: use a lookup table to convert hex to binary
Siddharth Agarwal <sid0@fb.com>
parents:
19652
diff
changeset
|
42 if (val >= 0) { |
d69e06724b96
parsers: use a lookup table to convert hex to binary
Siddharth Agarwal <sid0@fb.com>
parents:
19652
diff
changeset
|
43 return val; |
d69e06724b96
parsers: use a lookup table to convert hex to binary
Siddharth Agarwal <sid0@fb.com>
parents:
19652
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 |
7092
fb3fc27617a2
parsers: speed up hex decoding for manifests
Matt Mackall <mpm@selenic.com>
parents:
7091
diff
changeset
|
46 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
|
47 return 0; |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
48 } |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
49 |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
50 /* |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
51 * 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
|
52 */ |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
53 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
|
54 { |
7092
fb3fc27617a2
parsers: speed up hex decoding for manifests
Matt Mackall <mpm@selenic.com>
parents:
7091
diff
changeset
|
55 PyObject *ret; |
6395
3f0294536b24
fix const annotation warning
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6389
diff
changeset
|
56 char *d; |
16617
4fb16743049d
parsers: change the type signature of hexdigit
Bryan O'Sullivan <bryano@fb.com>
parents:
16616
diff
changeset
|
57 int i; |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
58 |
11361
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
59 ret = PyBytes_FromStringAndSize(NULL, len / 2); |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
60 |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
61 if (!ret) |
7092
fb3fc27617a2
parsers: speed up hex decoding for manifests
Matt Mackall <mpm@selenic.com>
parents:
7091
diff
changeset
|
62 return NULL; |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
63 |
11361
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
64 d = PyBytes_AsString(ret); |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
65 |
16617
4fb16743049d
parsers: change the type signature of hexdigit
Bryan O'Sullivan <bryano@fb.com>
parents:
16616
diff
changeset
|
66 for (i = 0; i < len;) { |
4fb16743049d
parsers: change the type signature of hexdigit
Bryan O'Sullivan <bryano@fb.com>
parents:
16616
diff
changeset
|
67 int hi = hexdigit(str, i++); |
4fb16743049d
parsers: change the type signature of hexdigit
Bryan O'Sullivan <bryano@fb.com>
parents:
16616
diff
changeset
|
68 int lo = hexdigit(str, i++); |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
69 *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
|
70 } |
7091
12b35ae03365
parsers: clean up whitespace
Matt Mackall <mpm@selenic.com>
parents:
6395
diff
changeset
|
71 |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
72 return ret; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
73 } |
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 /* |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
76 * 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
|
77 * ('\n') characters. |
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 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
|
80 { |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
81 PyObject *mfdict, *fdict; |
19728
3daabd2da78b
parse_manifest: rewrite to use memchr
Siddharth Agarwal <sid0@fb.com>
parents:
19727
diff
changeset
|
82 char *str, *start, *end; |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
83 int len; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
84 |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
85 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
|
86 &PyDict_Type, &mfdict, |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
87 &PyDict_Type, &fdict, |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
88 &str, &len)) |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
89 goto quit; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
90 |
19728
3daabd2da78b
parse_manifest: rewrite to use memchr
Siddharth Agarwal <sid0@fb.com>
parents:
19727
diff
changeset
|
91 start = str; |
3daabd2da78b
parse_manifest: rewrite to use memchr
Siddharth Agarwal <sid0@fb.com>
parents:
19727
diff
changeset
|
92 end = str + len; |
3daabd2da78b
parse_manifest: rewrite to use memchr
Siddharth Agarwal <sid0@fb.com>
parents:
19727
diff
changeset
|
93 while (start < end) { |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
94 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
|
95 PyObject *flags = NULL; |
19728
3daabd2da78b
parse_manifest: rewrite to use memchr
Siddharth Agarwal <sid0@fb.com>
parents:
19727
diff
changeset
|
96 char *zero = NULL, *newline = NULL; |
17356
511dfb34b412
parsers: fix an integer size warning issued by clang
Bryan O'Sullivan <bryano@fb.com>
parents:
17353
diff
changeset
|
97 ptrdiff_t nlen; |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
98 |
19728
3daabd2da78b
parse_manifest: rewrite to use memchr
Siddharth Agarwal <sid0@fb.com>
parents:
19727
diff
changeset
|
99 zero = memchr(start, '\0', end - start); |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
100 if (!zero) { |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
101 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
|
102 "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
|
103 goto quit; |
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 |
19728
3daabd2da78b
parse_manifest: rewrite to use memchr
Siddharth Agarwal <sid0@fb.com>
parents:
19727
diff
changeset
|
106 newline = memchr(zero + 1, '\n', end - (zero + 1)); |
3daabd2da78b
parse_manifest: rewrite to use memchr
Siddharth Agarwal <sid0@fb.com>
parents:
19727
diff
changeset
|
107 if (!newline) { |
3daabd2da78b
parse_manifest: rewrite to use memchr
Siddharth Agarwal <sid0@fb.com>
parents:
19727
diff
changeset
|
108 PyErr_SetString(PyExc_ValueError, |
3daabd2da78b
parse_manifest: rewrite to use memchr
Siddharth Agarwal <sid0@fb.com>
parents:
19727
diff
changeset
|
109 "manifest contains trailing garbage"); |
3daabd2da78b
parse_manifest: rewrite to use memchr
Siddharth Agarwal <sid0@fb.com>
parents:
19727
diff
changeset
|
110 goto quit; |
3daabd2da78b
parse_manifest: rewrite to use memchr
Siddharth Agarwal <sid0@fb.com>
parents:
19727
diff
changeset
|
111 } |
3daabd2da78b
parse_manifest: rewrite to use memchr
Siddharth Agarwal <sid0@fb.com>
parents:
19727
diff
changeset
|
112 |
11361
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
113 file = PyBytes_FromStringAndSize(start, zero - start); |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
114 |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
115 if (!file) |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
116 goto bail; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
117 |
19728
3daabd2da78b
parse_manifest: rewrite to use memchr
Siddharth Agarwal <sid0@fb.com>
parents:
19727
diff
changeset
|
118 nlen = newline - zero - 1; |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
119 |
17356
511dfb34b412
parsers: fix an integer size warning issued by clang
Bryan O'Sullivan <bryano@fb.com>
parents:
17353
diff
changeset
|
120 node = unhexlify(zero + 1, nlen > 40 ? 40 : (int)nlen); |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
121 if (!node) |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
122 goto bail; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
123 |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
124 if (nlen > 40) { |
11361
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
125 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
|
126 nlen - 40); |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
127 if (!flags) |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
128 goto bail; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
129 |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
130 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
|
131 goto bail; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
132 } |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
133 |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
134 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
|
135 goto bail; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
136 |
19728
3daabd2da78b
parse_manifest: rewrite to use memchr
Siddharth Agarwal <sid0@fb.com>
parents:
19727
diff
changeset
|
137 start = newline + 1; |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
138 |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
139 Py_XDECREF(flags); |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
140 Py_XDECREF(node); |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
141 Py_XDECREF(file); |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
142 continue; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
143 bail: |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
144 Py_XDECREF(flags); |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
145 Py_XDECREF(node); |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
146 Py_XDECREF(file); |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
147 goto quit; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
148 } |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
149 |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
150 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
|
151 return Py_None; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
152 quit: |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
153 return NULL; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
154 } |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
155 |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
156 static inline dirstateTupleObject *make_dirstate_tuple(char state, int mode, |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
157 int size, int mtime) |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
158 { |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
159 dirstateTupleObject *t = PyObject_New(dirstateTupleObject, |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
160 &dirstateTupleType); |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
161 if (!t) |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
162 return NULL; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
163 t->state = state; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
164 t->mode = mode; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
165 t->size = size; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
166 t->mtime = mtime; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
167 return t; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
168 } |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
169 |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
170 static PyObject *dirstate_tuple_new(PyTypeObject *subtype, PyObject *args, |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
171 PyObject *kwds) |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
172 { |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
173 /* We do all the initialization here and not a tp_init function because |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
174 * dirstate_tuple is immutable. */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
175 dirstateTupleObject *t; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
176 char state; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
177 int size, mode, mtime; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
178 if (!PyArg_ParseTuple(args, "ciii", &state, &mode, &size, &mtime)) |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
179 return NULL; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
180 |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
181 t = (dirstateTupleObject *)subtype->tp_alloc(subtype, 1); |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
182 if (!t) |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
183 return NULL; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
184 t->state = state; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
185 t->mode = mode; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
186 t->size = size; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
187 t->mtime = mtime; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
188 |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
189 return (PyObject *)t; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
190 } |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
191 |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
192 static void dirstate_tuple_dealloc(PyObject *o) |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
193 { |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
194 PyObject_Del(o); |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
195 } |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
196 |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
197 static Py_ssize_t dirstate_tuple_length(PyObject *o) |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
198 { |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
199 return 4; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
200 } |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
201 |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
202 static PyObject *dirstate_tuple_item(PyObject *o, Py_ssize_t i) |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
203 { |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
204 dirstateTupleObject *t = (dirstateTupleObject *)o; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
205 switch (i) { |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
206 case 0: |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
207 return PyBytes_FromStringAndSize(&t->state, 1); |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
208 case 1: |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
209 return PyInt_FromLong(t->mode); |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
210 case 2: |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
211 return PyInt_FromLong(t->size); |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
212 case 3: |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
213 return PyInt_FromLong(t->mtime); |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
214 default: |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
215 PyErr_SetString(PyExc_IndexError, "index out of range"); |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
216 return NULL; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
217 } |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
218 } |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
219 |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
220 static PySequenceMethods dirstate_tuple_sq = { |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
221 dirstate_tuple_length, /* sq_length */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
222 0, /* sq_concat */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
223 0, /* sq_repeat */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
224 dirstate_tuple_item, /* sq_item */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
225 0, /* sq_ass_item */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
226 0, /* sq_contains */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
227 0, /* sq_inplace_concat */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
228 0 /* sq_inplace_repeat */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
229 }; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
230 |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
231 PyTypeObject dirstateTupleType = { |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
232 PyVarObject_HEAD_INIT(NULL, 0) |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
233 "dirstate_tuple", /* tp_name */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
234 sizeof(dirstateTupleObject),/* tp_basicsize */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
235 0, /* tp_itemsize */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
236 (destructor)dirstate_tuple_dealloc, /* tp_dealloc */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
237 0, /* tp_print */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
238 0, /* tp_getattr */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
239 0, /* tp_setattr */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
240 0, /* tp_compare */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
241 0, /* tp_repr */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
242 0, /* tp_as_number */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
243 &dirstate_tuple_sq, /* tp_as_sequence */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
244 0, /* tp_as_mapping */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
245 0, /* tp_hash */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
246 0, /* tp_call */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
247 0, /* tp_str */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
248 0, /* tp_getattro */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
249 0, /* tp_setattro */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
250 0, /* tp_as_buffer */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
251 Py_TPFLAGS_DEFAULT, /* tp_flags */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
252 "dirstate tuple", /* tp_doc */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
253 0, /* tp_traverse */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
254 0, /* tp_clear */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
255 0, /* tp_richcompare */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
256 0, /* tp_weaklistoffset */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
257 0, /* tp_iter */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
258 0, /* tp_iternext */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
259 0, /* tp_methods */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
260 0, /* tp_members */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
261 0, /* tp_getset */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
262 0, /* tp_base */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
263 0, /* tp_dict */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
264 0, /* tp_descr_get */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
265 0, /* tp_descr_set */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
266 0, /* tp_dictoffset */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
267 0, /* tp_init */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
268 0, /* tp_alloc */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
269 dirstate_tuple_new, /* tp_new */ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
270 }; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
271 |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
272 static PyObject *parse_dirstate(PyObject *self, PyObject *args) |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
273 { |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
274 PyObject *dmap, *cmap, *parents = NULL, *ret = NULL; |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
275 PyObject *fname = NULL, *cname = NULL, *entry = NULL; |
20167
09e41ac6289d
mpatch: rewrite pointer overflow checks
Matt Mackall <mpm@selenic.com>
parents:
20109
diff
changeset
|
276 char state, *cur, *str, *cpos; |
19725
5e25d71a58cc
parsers: state is a char, not an int
Bryan O'Sullivan <bryano@fb.com>
parents:
19718
diff
changeset
|
277 int mode, size, mtime; |
7174
4da87407b845
parsers.c: fix integer overflows
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7168
diff
changeset
|
278 unsigned int flen; |
20167
09e41ac6289d
mpatch: rewrite pointer overflow checks
Matt Mackall <mpm@selenic.com>
parents:
20109
diff
changeset
|
279 int len, pos = 40; |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
280 |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
281 if (!PyArg_ParseTuple(args, "O!O!s#:parse_dirstate", |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
282 &PyDict_Type, &dmap, |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
283 &PyDict_Type, &cmap, |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
284 &str, &len)) |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
285 goto quit; |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
286 |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
287 /* read parents */ |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
288 if (len < 40) |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
289 goto quit; |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
290 |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
291 parents = Py_BuildValue("s#s#", str, 20, str + 20, 20); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
292 if (!parents) |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
293 goto quit; |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
294 |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
295 /* read filenames */ |
20167
09e41ac6289d
mpatch: rewrite pointer overflow checks
Matt Mackall <mpm@selenic.com>
parents:
20109
diff
changeset
|
296 while (pos >= 40 && pos < len) { |
09e41ac6289d
mpatch: rewrite pointer overflow checks
Matt Mackall <mpm@selenic.com>
parents:
20109
diff
changeset
|
297 cur = str + pos; |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
298 /* unpack header */ |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
299 state = *cur; |
16437
d126a0d16856
util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents:
16414
diff
changeset
|
300 mode = getbe32(cur + 1); |
d126a0d16856
util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents:
16414
diff
changeset
|
301 size = getbe32(cur + 5); |
d126a0d16856
util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents:
16414
diff
changeset
|
302 mtime = getbe32(cur + 9); |
d126a0d16856
util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents:
16414
diff
changeset
|
303 flen = getbe32(cur + 13); |
20167
09e41ac6289d
mpatch: rewrite pointer overflow checks
Matt Mackall <mpm@selenic.com>
parents:
20109
diff
changeset
|
304 pos += 17; |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
305 cur += 17; |
20316
40f08c31844c
parsers: fix 'unsigned expression is always true' warning (issue4142)
David Soria Parra <davidsp@fb.com>
parents:
20169
diff
changeset
|
306 if (flen > len - pos) { |
7174
4da87407b845
parsers.c: fix integer overflows
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7168
diff
changeset
|
307 PyErr_SetString(PyExc_ValueError, "overflow in dirstate"); |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
308 goto quit; |
7174
4da87407b845
parsers.c: fix integer overflows
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7168
diff
changeset
|
309 } |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
310 |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
311 entry = (PyObject *)make_dirstate_tuple(state, mode, size, |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
312 mtime); |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
313 cpos = memchr(cur, 0, flen); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
314 if (cpos) { |
11361
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
315 fname = PyBytes_FromStringAndSize(cur, cpos - cur); |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
316 cname = PyBytes_FromStringAndSize(cpos + 1, |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
317 flen - (cpos - cur) - 1); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
318 if (!fname || !cname || |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
319 PyDict_SetItem(cmap, fname, cname) == -1 || |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
320 PyDict_SetItem(dmap, fname, entry) == -1) |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
321 goto quit; |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
322 Py_DECREF(cname); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
323 } else { |
11361
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
324 fname = PyBytes_FromStringAndSize(cur, flen); |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
325 if (!fname || |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
326 PyDict_SetItem(dmap, fname, entry) == -1) |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
327 goto quit; |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
328 } |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
329 Py_DECREF(fname); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
330 Py_DECREF(entry); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
331 fname = cname = entry = NULL; |
20167
09e41ac6289d
mpatch: rewrite pointer overflow checks
Matt Mackall <mpm@selenic.com>
parents:
20109
diff
changeset
|
332 pos += flen; |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
333 } |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
334 |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
335 ret = parents; |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
336 Py_INCREF(ret); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
337 quit: |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
338 Py_XDECREF(fname); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
339 Py_XDECREF(cname); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
340 Py_XDECREF(entry); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
341 Py_XDECREF(parents); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
342 return ret; |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
343 } |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
344 |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
345 /* |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
346 * Efficiently pack a dirstate object into its on-disk format. |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
347 */ |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
348 static PyObject *pack_dirstate(PyObject *self, PyObject *args) |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
349 { |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
350 PyObject *packobj = NULL; |
21806
05bd2667df4d
pack_dirstate: in C version, for invalidation set dict to what we write to disk
Siddharth Agarwal <sid0@fb.com>
parents:
21730
diff
changeset
|
351 PyObject *map, *copymap, *pl, *mtime_unset = NULL; |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
352 Py_ssize_t nbytes, pos, l; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
353 PyObject *k, *v, *pn; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
354 char *p, *s; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
355 double now; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
356 |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
357 if (!PyArg_ParseTuple(args, "O!O!Od:pack_dirstate", |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
358 &PyDict_Type, &map, &PyDict_Type, ©map, |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
359 &pl, &now)) |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
360 return NULL; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
361 |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
362 if (!PySequence_Check(pl) || PySequence_Size(pl) != 2) { |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
363 PyErr_SetString(PyExc_TypeError, "expected 2-element sequence"); |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
364 return NULL; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
365 } |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
366 |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
367 /* Figure out how much we need to allocate. */ |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
368 for (nbytes = 40, pos = 0; PyDict_Next(map, &pos, &k, &v);) { |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
369 PyObject *c; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
370 if (!PyString_Check(k)) { |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
371 PyErr_SetString(PyExc_TypeError, "expected string key"); |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
372 goto bail; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
373 } |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
374 nbytes += PyString_GET_SIZE(k) + 17; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
375 c = PyDict_GetItem(copymap, k); |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
376 if (c) { |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
377 if (!PyString_Check(c)) { |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
378 PyErr_SetString(PyExc_TypeError, |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
379 "expected string key"); |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
380 goto bail; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
381 } |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
382 nbytes += PyString_GET_SIZE(c) + 1; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
383 } |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
384 } |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
385 |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
386 packobj = PyString_FromStringAndSize(NULL, nbytes); |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
387 if (packobj == NULL) |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
388 goto bail; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
389 |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
390 p = PyString_AS_STRING(packobj); |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
391 |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
392 pn = PySequence_ITEM(pl, 0); |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
393 if (PyString_AsStringAndSize(pn, &s, &l) == -1 || l != 20) { |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
394 PyErr_SetString(PyExc_TypeError, "expected a 20-byte hash"); |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
395 goto bail; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
396 } |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
397 memcpy(p, s, l); |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
398 p += 20; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
399 pn = PySequence_ITEM(pl, 1); |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
400 if (PyString_AsStringAndSize(pn, &s, &l) == -1 || l != 20) { |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
401 PyErr_SetString(PyExc_TypeError, "expected a 20-byte hash"); |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
402 goto bail; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
403 } |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
404 memcpy(p, s, l); |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
405 p += 20; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
406 |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
407 for (pos = 0; PyDict_Next(map, &pos, &k, &v); ) { |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
408 dirstateTupleObject *tuple; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
409 char state; |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
410 uint32_t mode, size, mtime; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
411 Py_ssize_t len, l; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
412 PyObject *o; |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
413 char *t; |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
414 |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
415 if (!dirstate_tuple_check(v)) { |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
416 PyErr_SetString(PyExc_TypeError, |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
417 "expected a dirstate tuple"); |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
418 goto bail; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
419 } |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
420 tuple = (dirstateTupleObject *)v; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
421 |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
422 state = tuple->state; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
423 mode = tuple->mode; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
424 size = tuple->size; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
425 mtime = tuple->mtime; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
426 if (state == 'n' && mtime == (uint32_t)now) { |
18567
194e63c1ccb9
dirstate: move pure python dirstate packing to pure/parsers.py
Siddharth Agarwal <sid0@fb.com>
parents:
18504
diff
changeset
|
427 /* See pure/parsers.py:pack_dirstate for why we do |
194e63c1ccb9
dirstate: move pure python dirstate packing to pure/parsers.py
Siddharth Agarwal <sid0@fb.com>
parents:
18504
diff
changeset
|
428 * this. */ |
21806
05bd2667df4d
pack_dirstate: in C version, for invalidation set dict to what we write to disk
Siddharth Agarwal <sid0@fb.com>
parents:
21730
diff
changeset
|
429 mtime = -1; |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
430 mtime_unset = (PyObject *)make_dirstate_tuple( |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
431 state, mode, size, mtime); |
21806
05bd2667df4d
pack_dirstate: in C version, for invalidation set dict to what we write to disk
Siddharth Agarwal <sid0@fb.com>
parents:
21730
diff
changeset
|
432 if (!mtime_unset) |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
433 goto bail; |
21806
05bd2667df4d
pack_dirstate: in C version, for invalidation set dict to what we write to disk
Siddharth Agarwal <sid0@fb.com>
parents:
21730
diff
changeset
|
434 if (PyDict_SetItem(map, k, mtime_unset) == -1) |
05bd2667df4d
pack_dirstate: in C version, for invalidation set dict to what we write to disk
Siddharth Agarwal <sid0@fb.com>
parents:
21730
diff
changeset
|
435 goto bail; |
05bd2667df4d
pack_dirstate: in C version, for invalidation set dict to what we write to disk
Siddharth Agarwal <sid0@fb.com>
parents:
21730
diff
changeset
|
436 Py_DECREF(mtime_unset); |
05bd2667df4d
pack_dirstate: in C version, for invalidation set dict to what we write to disk
Siddharth Agarwal <sid0@fb.com>
parents:
21730
diff
changeset
|
437 mtime_unset = NULL; |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
438 } |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
439 *p++ = state; |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
440 putbe32(mode, p); |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
441 putbe32(size, p + 4); |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
442 putbe32(mtime, p + 8); |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
443 t = p + 12; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
444 p += 16; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
445 len = PyString_GET_SIZE(k); |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
446 memcpy(p, PyString_AS_STRING(k), len); |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
447 p += len; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
448 o = PyDict_GetItem(copymap, k); |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
449 if (o) { |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
450 *p++ = '\0'; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
451 l = PyString_GET_SIZE(o); |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
452 memcpy(p, PyString_AS_STRING(o), l); |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
453 p += l; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
454 len += l + 1; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
455 } |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
456 putbe32((uint32_t)len, t); |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
457 } |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
458 |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
459 pos = p - PyString_AS_STRING(packobj); |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
460 if (pos != nbytes) { |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
461 PyErr_Format(PyExc_SystemError, "bad dirstate size: %ld != %ld", |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
462 (long)pos, (long)nbytes); |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
463 goto bail; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
464 } |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
465 |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
466 return packobj; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
467 bail: |
21806
05bd2667df4d
pack_dirstate: in C version, for invalidation set dict to what we write to disk
Siddharth Agarwal <sid0@fb.com>
parents:
21730
diff
changeset
|
468 Py_XDECREF(mtime_unset); |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
469 Py_XDECREF(packobj); |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
470 return NULL; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
471 } |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
472 |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
473 /* |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
474 * A base-16 trie for fast node->rev mapping. |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
475 * |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
476 * Positive value is index of the next node in the trie |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
477 * Negative value is a leaf: -(rev + 1) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
478 * Zero is empty |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
479 */ |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
480 typedef struct { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
481 int children[16]; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
482 } nodetree; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
483 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
484 /* |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
485 * This class has two behaviours. |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
486 * |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
487 * When used in a list-like way (with integer keys), we decode an |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
488 * entry in a RevlogNG index file on demand. Our last entry is a |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
489 * sentinel, always a nullid. We have limited support for |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
490 * integer-keyed insert and delete, only at elements right before the |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
491 * sentinel. |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
492 * |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
493 * With string keys, we lazily perform a reverse mapping from node to |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
494 * rev, using a base-16 trie. |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
495 */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
496 typedef struct { |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
497 PyObject_HEAD |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
498 /* Type-specific fields go here. */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
499 PyObject *data; /* raw bytes of index */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
500 PyObject **cache; /* cached tuples */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
501 const char **offsets; /* populated on demand */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
502 Py_ssize_t raw_length; /* original number of elements */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
503 Py_ssize_t length; /* current number of elements */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
504 PyObject *added; /* populated on demand */ |
16787
bda96ce993f9
parsers: cache the result of index_headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16786
diff
changeset
|
505 PyObject *headrevs; /* cache, invalidated on changes */ |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
506 nodetree *nt; /* base-16 trie */ |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
507 int ntlength; /* # nodes in use */ |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
508 int ntcapacity; /* # nodes allocated */ |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
509 int ntdepth; /* maximum depth of tree */ |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
510 int ntsplits; /* # splits performed */ |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
511 int ntrev; /* last rev scanned */ |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
512 int ntlookups; /* # lookups */ |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
513 int ntmisses; /* # lookups that miss the cache */ |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
514 int inlined; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
515 } indexObject; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
516 |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
517 static Py_ssize_t index_length(const indexObject *self) |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
518 { |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
519 if (self->added == NULL) |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
520 return self->length; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
521 return self->length + PyList_GET_SIZE(self->added); |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
522 } |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
523 |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
524 static PyObject *nullentry; |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
525 static const char nullid[20]; |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
526 |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
527 static long inline_scan(indexObject *self, const char **offsets); |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
528 |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
529 #if LONG_MAX == 0x7fffffffL |
16393
ee163a9cf37c
util.h: more Python 2.4 fixes
Matt Mackall <mpm@selenic.com>
parents:
16385
diff
changeset
|
530 static char *tuple_format = "Kiiiiiis#"; |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
531 #else |
16393
ee163a9cf37c
util.h: more Python 2.4 fixes
Matt Mackall <mpm@selenic.com>
parents:
16385
diff
changeset
|
532 static char *tuple_format = "kiiiiiis#"; |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
533 #endif |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
534 |
16863
bbedef66c6f3
parsers: replace magic number 64 with symbolic constant
Bryan O'Sullivan <bryano@fb.com>
parents:
16787
diff
changeset
|
535 /* A RevlogNG v1 index entry is 64 bytes long. */ |
bbedef66c6f3
parsers: replace magic number 64 with symbolic constant
Bryan O'Sullivan <bryano@fb.com>
parents:
16787
diff
changeset
|
536 static const long v1_hdrsize = 64; |
bbedef66c6f3
parsers: replace magic number 64 with symbolic constant
Bryan O'Sullivan <bryano@fb.com>
parents:
16787
diff
changeset
|
537 |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
538 /* |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
539 * Return a pointer to the beginning of a RevlogNG record. |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
540 */ |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
541 static const char *index_deref(indexObject *self, Py_ssize_t pos) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
542 { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
543 if (self->inlined && pos > 0) { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
544 if (self->offsets == NULL) { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
545 self->offsets = malloc(self->raw_length * |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
546 sizeof(*self->offsets)); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
547 if (self->offsets == NULL) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
548 return (const char *)PyErr_NoMemory(); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
549 inline_scan(self, self->offsets); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
550 } |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
551 return self->offsets[pos]; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
552 } |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
553 |
16863
bbedef66c6f3
parsers: replace magic number 64 with symbolic constant
Bryan O'Sullivan <bryano@fb.com>
parents:
16787
diff
changeset
|
554 return PyString_AS_STRING(self->data) + pos * v1_hdrsize; |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
555 } |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
556 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
557 /* |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
558 * RevlogNG format (all in big endian, data may be inlined): |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
559 * 6 bytes: offset |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
560 * 2 bytes: flags |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
561 * 4 bytes: compressed length |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
562 * 4 bytes: uncompressed length |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
563 * 4 bytes: base revision |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
564 * 4 bytes: link revision |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
565 * 4 bytes: parent 1 revision |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
566 * 4 bytes: parent 2 revision |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
567 * 32 bytes: nodeid (only 20 bytes used) |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
568 */ |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
569 static PyObject *index_get(indexObject *self, Py_ssize_t pos) |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
570 { |
7154
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
571 uint64_t offset_flags; |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
572 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
|
573 const char *c_node_id; |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
574 const char *data; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
575 Py_ssize_t length = index_length(self); |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
576 PyObject *entry; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
577 |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
578 if (pos < 0) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
579 pos += length; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
580 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
581 if (pos < 0 || pos >= length) { |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
582 PyErr_SetString(PyExc_IndexError, "revlog index out of range"); |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
583 return NULL; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
584 } |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
585 |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
586 if (pos == length - 1) { |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
587 Py_INCREF(nullentry); |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
588 return nullentry; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
589 } |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
590 |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
591 if (pos >= self->length - 1) { |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
592 PyObject *obj; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
593 obj = PyList_GET_ITEM(self->added, pos - self->length + 1); |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
594 Py_INCREF(obj); |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
595 return obj; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
596 } |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
597 |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
598 if (self->cache) { |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
599 if (self->cache[pos]) { |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
600 Py_INCREF(self->cache[pos]); |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
601 return self->cache[pos]; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
602 } |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
603 } else { |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
604 self->cache = calloc(self->raw_length, sizeof(PyObject *)); |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
605 if (self->cache == NULL) |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
606 return PyErr_NoMemory(); |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
607 } |
7190
aecea6934fdd
Some additional space/tab cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
7186
diff
changeset
|
608 |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
609 data = index_deref(self, pos); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
610 if (data == NULL) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
611 return NULL; |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
612 |
16437
d126a0d16856
util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents:
16414
diff
changeset
|
613 offset_flags = getbe32(data + 4); |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
614 if (pos == 0) /* mask out version number for the first entry */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
615 offset_flags &= 0xFFFF; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
616 else { |
16437
d126a0d16856
util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents:
16414
diff
changeset
|
617 uint32_t offset_high = getbe32(data); |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
618 offset_flags |= ((uint64_t)offset_high) << 32; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
619 } |
7154
7fdf7a0a41b7
index parser: fix refcounting in case of errors, refactor
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7135
diff
changeset
|
620 |
16437
d126a0d16856
util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents:
16414
diff
changeset
|
621 comp_len = getbe32(data + 8); |
d126a0d16856
util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents:
16414
diff
changeset
|
622 uncomp_len = getbe32(data + 12); |
d126a0d16856
util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents:
16414
diff
changeset
|
623 base_rev = getbe32(data + 16); |
d126a0d16856
util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents:
16414
diff
changeset
|
624 link_rev = getbe32(data + 20); |
d126a0d16856
util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents:
16414
diff
changeset
|
625 parent_1 = getbe32(data + 24); |
d126a0d16856
util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents:
16414
diff
changeset
|
626 parent_2 = getbe32(data + 28); |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
627 c_node_id = data + 32; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
628 |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
629 entry = Py_BuildValue(tuple_format, offset_flags, comp_len, |
13254
5ef5eb1f3515
revlog: only build the nodemap on demand
Matt Mackall <mpm@selenic.com>
parents:
11361
diff
changeset
|
630 uncomp_len, base_rev, link_rev, |
5ef5eb1f3515
revlog: only build the nodemap on demand
Matt Mackall <mpm@selenic.com>
parents:
11361
diff
changeset
|
631 parent_1, parent_2, c_node_id, 20); |
5ef5eb1f3515
revlog: only build the nodemap on demand
Matt Mackall <mpm@selenic.com>
parents:
11361
diff
changeset
|
632 |
19726
b3c8c6f2b5c1
parsers: use Py_INCREF safely
Bryan O'Sullivan <bryano@fb.com>
parents:
19725
diff
changeset
|
633 if (entry) { |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
634 PyObject_GC_UnTrack(entry); |
19726
b3c8c6f2b5c1
parsers: use Py_INCREF safely
Bryan O'Sullivan <bryano@fb.com>
parents:
19725
diff
changeset
|
635 Py_INCREF(entry); |
b3c8c6f2b5c1
parsers: use Py_INCREF safely
Bryan O'Sullivan <bryano@fb.com>
parents:
19725
diff
changeset
|
636 } |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
637 |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
638 self->cache[pos] = entry; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
639 |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
640 return entry; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
641 } |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
642 |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
643 /* |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
644 * Return the 20-byte SHA of the node corresponding to the given rev. |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
645 */ |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
646 static const char *index_node(indexObject *self, Py_ssize_t pos) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
647 { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
648 Py_ssize_t length = index_length(self); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
649 const char *data; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
650 |
16664
5bc6edf71b39
parsers: ensure that nullid is always present in the radix tree
Bryan O'Sullivan <bryano@fb.com>
parents:
16663
diff
changeset
|
651 if (pos == length - 1 || pos == INT_MAX) |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
652 return nullid; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
653 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
654 if (pos >= length) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
655 return NULL; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
656 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
657 if (pos >= self->length - 1) { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
658 PyObject *tuple, *str; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
659 tuple = PyList_GET_ITEM(self->added, pos - self->length + 1); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
660 str = PyTuple_GetItem(tuple, 7); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
661 return str ? PyString_AS_STRING(str) : NULL; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
662 } |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
663 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
664 data = index_deref(self, pos); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
665 return data ? data + 32 : NULL; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
666 } |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
667 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
668 static int nt_insert(indexObject *self, const char *node, int rev); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
669 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
670 static int node_check(PyObject *obj, char **node, Py_ssize_t *nodelen) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
671 { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
672 if (PyString_AsStringAndSize(obj, node, nodelen) == -1) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
673 return -1; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
674 if (*nodelen == 20) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
675 return 0; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
676 PyErr_SetString(PyExc_ValueError, "20-byte hash required"); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
677 return -1; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
678 } |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
679 |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
680 static PyObject *index_insert(indexObject *self, PyObject *args) |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
681 { |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
682 PyObject *obj; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
683 char *node; |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
684 long offset; |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
685 Py_ssize_t len, nodelen; |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
686 |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
687 if (!PyArg_ParseTuple(args, "lO", &offset, &obj)) |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
688 return NULL; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
689 |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
690 if (!PyTuple_Check(obj) || PyTuple_GET_SIZE(obj) != 8) { |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
691 PyErr_SetString(PyExc_TypeError, "8-tuple required"); |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
692 return NULL; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
693 } |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
694 |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
695 if (node_check(PyTuple_GET_ITEM(obj, 7), &node, &nodelen) == -1) |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
696 return NULL; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
697 |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
698 len = index_length(self); |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
699 |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
700 if (offset < 0) |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
701 offset += len; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
702 |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
703 if (offset != len - 1) { |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
704 PyErr_SetString(PyExc_IndexError, |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
705 "insert only supported at index -1"); |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
706 return NULL; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
707 } |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
708 |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
709 if (offset > INT_MAX) { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
710 PyErr_SetString(PyExc_ValueError, |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
711 "currently only 2**31 revs supported"); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
712 return NULL; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
713 } |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
714 |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
715 if (self->added == NULL) { |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
716 self->added = PyList_New(0); |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
717 if (self->added == NULL) |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
718 return NULL; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
719 } |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
720 |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
721 if (PyList_Append(self->added, obj) == -1) |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
722 return NULL; |
13254
5ef5eb1f3515
revlog: only build the nodemap on demand
Matt Mackall <mpm@selenic.com>
parents:
11361
diff
changeset
|
723 |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
724 if (self->nt) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
725 nt_insert(self, node, (int)offset); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
726 |
16787
bda96ce993f9
parsers: cache the result of index_headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16786
diff
changeset
|
727 Py_CLEAR(self->headrevs); |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
728 Py_RETURN_NONE; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
729 } |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
730 |
16370
28bb4daf070c
parsers: fix a memleak, and add a clearcaches method to the index
Bryan O'Sullivan <bryano@fb.com>
parents:
16363
diff
changeset
|
731 static void _index_clearcaches(indexObject *self) |
28bb4daf070c
parsers: fix a memleak, and add a clearcaches method to the index
Bryan O'Sullivan <bryano@fb.com>
parents:
16363
diff
changeset
|
732 { |
28bb4daf070c
parsers: fix a memleak, and add a clearcaches method to the index
Bryan O'Sullivan <bryano@fb.com>
parents:
16363
diff
changeset
|
733 if (self->cache) { |
28bb4daf070c
parsers: fix a memleak, and add a clearcaches method to the index
Bryan O'Sullivan <bryano@fb.com>
parents:
16363
diff
changeset
|
734 Py_ssize_t i; |
28bb4daf070c
parsers: fix a memleak, and add a clearcaches method to the index
Bryan O'Sullivan <bryano@fb.com>
parents:
16363
diff
changeset
|
735 |
16732
277e2acb7e5c
parsers: use Py_CLEAR where appropriate
Bryan O'Sullivan <bryano@fb.com>
parents:
16699
diff
changeset
|
736 for (i = 0; i < self->raw_length; i++) |
277e2acb7e5c
parsers: use Py_CLEAR where appropriate
Bryan O'Sullivan <bryano@fb.com>
parents:
16699
diff
changeset
|
737 Py_CLEAR(self->cache[i]); |
16370
28bb4daf070c
parsers: fix a memleak, and add a clearcaches method to the index
Bryan O'Sullivan <bryano@fb.com>
parents:
16363
diff
changeset
|
738 free(self->cache); |
28bb4daf070c
parsers: fix a memleak, and add a clearcaches method to the index
Bryan O'Sullivan <bryano@fb.com>
parents:
16363
diff
changeset
|
739 self->cache = NULL; |
28bb4daf070c
parsers: fix a memleak, and add a clearcaches method to the index
Bryan O'Sullivan <bryano@fb.com>
parents:
16363
diff
changeset
|
740 } |
28bb4daf070c
parsers: fix a memleak, and add a clearcaches method to the index
Bryan O'Sullivan <bryano@fb.com>
parents:
16363
diff
changeset
|
741 if (self->offsets) { |
28bb4daf070c
parsers: fix a memleak, and add a clearcaches method to the index
Bryan O'Sullivan <bryano@fb.com>
parents:
16363
diff
changeset
|
742 free(self->offsets); |
28bb4daf070c
parsers: fix a memleak, and add a clearcaches method to the index
Bryan O'Sullivan <bryano@fb.com>
parents:
16363
diff
changeset
|
743 self->offsets = NULL; |
28bb4daf070c
parsers: fix a memleak, and add a clearcaches method to the index
Bryan O'Sullivan <bryano@fb.com>
parents:
16363
diff
changeset
|
744 } |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
745 if (self->nt) { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
746 free(self->nt); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
747 self->nt = NULL; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
748 } |
16787
bda96ce993f9
parsers: cache the result of index_headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16786
diff
changeset
|
749 Py_CLEAR(self->headrevs); |
16370
28bb4daf070c
parsers: fix a memleak, and add a clearcaches method to the index
Bryan O'Sullivan <bryano@fb.com>
parents:
16363
diff
changeset
|
750 } |
28bb4daf070c
parsers: fix a memleak, and add a clearcaches method to the index
Bryan O'Sullivan <bryano@fb.com>
parents:
16363
diff
changeset
|
751 |
28bb4daf070c
parsers: fix a memleak, and add a clearcaches method to the index
Bryan O'Sullivan <bryano@fb.com>
parents:
16363
diff
changeset
|
752 static PyObject *index_clearcaches(indexObject *self) |
28bb4daf070c
parsers: fix a memleak, and add a clearcaches method to the index
Bryan O'Sullivan <bryano@fb.com>
parents:
16363
diff
changeset
|
753 { |
28bb4daf070c
parsers: fix a memleak, and add a clearcaches method to the index
Bryan O'Sullivan <bryano@fb.com>
parents:
16363
diff
changeset
|
754 _index_clearcaches(self); |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
755 self->ntlength = self->ntcapacity = 0; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
756 self->ntdepth = self->ntsplits = 0; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
757 self->ntrev = -1; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
758 self->ntlookups = self->ntmisses = 0; |
16370
28bb4daf070c
parsers: fix a memleak, and add a clearcaches method to the index
Bryan O'Sullivan <bryano@fb.com>
parents:
16363
diff
changeset
|
759 Py_RETURN_NONE; |
28bb4daf070c
parsers: fix a memleak, and add a clearcaches method to the index
Bryan O'Sullivan <bryano@fb.com>
parents:
16363
diff
changeset
|
760 } |
28bb4daf070c
parsers: fix a memleak, and add a clearcaches method to the index
Bryan O'Sullivan <bryano@fb.com>
parents:
16363
diff
changeset
|
761 |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
762 static PyObject *index_stats(indexObject *self) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
763 { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
764 PyObject *obj = PyDict_New(); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
765 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
766 if (obj == NULL) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
767 return NULL; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
768 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
769 #define istat(__n, __d) \ |
16629
1435866c1937
parser: use PyInt_FromSsize_t in index_stats
Adrian Buehlmann <adrian@cadifra.com>
parents:
16621
diff
changeset
|
770 if (PyDict_SetItemString(obj, __d, PyInt_FromSsize_t(self->__n)) == -1) \ |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
771 goto bail; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
772 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
773 if (self->added) { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
774 Py_ssize_t len = PyList_GET_SIZE(self->added); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
775 if (PyDict_SetItemString(obj, "index entries added", |
16629
1435866c1937
parser: use PyInt_FromSsize_t in index_stats
Adrian Buehlmann <adrian@cadifra.com>
parents:
16621
diff
changeset
|
776 PyInt_FromSsize_t(len)) == -1) |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
777 goto bail; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
778 } |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
779 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
780 if (self->raw_length != self->length - 1) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
781 istat(raw_length, "revs on disk"); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
782 istat(length, "revs in memory"); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
783 istat(ntcapacity, "node trie capacity"); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
784 istat(ntdepth, "node trie depth"); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
785 istat(ntlength, "node trie count"); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
786 istat(ntlookups, "node trie lookups"); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
787 istat(ntmisses, "node trie misses"); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
788 istat(ntrev, "node trie last rev scanned"); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
789 istat(ntsplits, "node trie splits"); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
790 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
791 #undef istat |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
792 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
793 return obj; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
794 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
795 bail: |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
796 Py_XDECREF(obj); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
797 return NULL; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
798 } |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
799 |
16787
bda96ce993f9
parsers: cache the result of index_headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16786
diff
changeset
|
800 /* |
bda96ce993f9
parsers: cache the result of index_headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16786
diff
changeset
|
801 * When we cache a list, we want to be sure the caller can't mutate |
bda96ce993f9
parsers: cache the result of index_headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16786
diff
changeset
|
802 * the cached copy. |
bda96ce993f9
parsers: cache the result of index_headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16786
diff
changeset
|
803 */ |
bda96ce993f9
parsers: cache the result of index_headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16786
diff
changeset
|
804 static PyObject *list_copy(PyObject *list) |
bda96ce993f9
parsers: cache the result of index_headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16786
diff
changeset
|
805 { |
bda96ce993f9
parsers: cache the result of index_headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16786
diff
changeset
|
806 Py_ssize_t len = PyList_GET_SIZE(list); |
bda96ce993f9
parsers: cache the result of index_headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16786
diff
changeset
|
807 PyObject *newlist = PyList_New(len); |
bda96ce993f9
parsers: cache the result of index_headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16786
diff
changeset
|
808 Py_ssize_t i; |
bda96ce993f9
parsers: cache the result of index_headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16786
diff
changeset
|
809 |
bda96ce993f9
parsers: cache the result of index_headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16786
diff
changeset
|
810 if (newlist == NULL) |
bda96ce993f9
parsers: cache the result of index_headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16786
diff
changeset
|
811 return NULL; |
bda96ce993f9
parsers: cache the result of index_headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16786
diff
changeset
|
812 |
bda96ce993f9
parsers: cache the result of index_headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16786
diff
changeset
|
813 for (i = 0; i < len; i++) { |
bda96ce993f9
parsers: cache the result of index_headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16786
diff
changeset
|
814 PyObject *obj = PyList_GET_ITEM(list, i); |
bda96ce993f9
parsers: cache the result of index_headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16786
diff
changeset
|
815 Py_INCREF(obj); |
bda96ce993f9
parsers: cache the result of index_headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16786
diff
changeset
|
816 PyList_SET_ITEM(newlist, i, obj); |
bda96ce993f9
parsers: cache the result of index_headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16786
diff
changeset
|
817 } |
bda96ce993f9
parsers: cache the result of index_headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16786
diff
changeset
|
818 |
bda96ce993f9
parsers: cache the result of index_headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16786
diff
changeset
|
819 return newlist; |
bda96ce993f9
parsers: cache the result of index_headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16786
diff
changeset
|
820 } |
bda96ce993f9
parsers: cache the result of index_headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16786
diff
changeset
|
821 |
16786
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
822 static PyObject *index_headrevs(indexObject *self) |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
823 { |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
824 Py_ssize_t i, len, addlen; |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
825 char *nothead = NULL; |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
826 PyObject *heads; |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
827 |
16787
bda96ce993f9
parsers: cache the result of index_headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16786
diff
changeset
|
828 if (self->headrevs) |
bda96ce993f9
parsers: cache the result of index_headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16786
diff
changeset
|
829 return list_copy(self->headrevs); |
bda96ce993f9
parsers: cache the result of index_headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16786
diff
changeset
|
830 |
16786
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
831 len = index_length(self) - 1; |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
832 heads = PyList_New(0); |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
833 if (heads == NULL) |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
834 goto bail; |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
835 if (len == 0) { |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
836 PyObject *nullid = PyInt_FromLong(-1); |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
837 if (nullid == NULL || PyList_Append(heads, nullid) == -1) { |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
838 Py_XDECREF(nullid); |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
839 goto bail; |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
840 } |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
841 goto done; |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
842 } |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
843 |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
844 nothead = calloc(len, 1); |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
845 if (nothead == NULL) |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
846 goto bail; |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
847 |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
848 for (i = 0; i < self->raw_length; i++) { |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
849 const char *data = index_deref(self, i); |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
850 int parent_1 = getbe32(data + 24); |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
851 int parent_2 = getbe32(data + 28); |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
852 if (parent_1 >= 0) |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
853 nothead[parent_1] = 1; |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
854 if (parent_2 >= 0) |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
855 nothead[parent_2] = 1; |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
856 } |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
857 |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
858 addlen = self->added ? PyList_GET_SIZE(self->added) : 0; |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
859 |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
860 for (i = 0; i < addlen; i++) { |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
861 PyObject *rev = PyList_GET_ITEM(self->added, i); |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
862 PyObject *p1 = PyTuple_GET_ITEM(rev, 5); |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
863 PyObject *p2 = PyTuple_GET_ITEM(rev, 6); |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
864 long parent_1, parent_2; |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
865 |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
866 if (!PyInt_Check(p1) || !PyInt_Check(p2)) { |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
867 PyErr_SetString(PyExc_TypeError, |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
868 "revlog parents are invalid"); |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
869 goto bail; |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
870 } |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
871 parent_1 = PyInt_AS_LONG(p1); |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
872 parent_2 = PyInt_AS_LONG(p2); |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
873 if (parent_1 >= 0) |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
874 nothead[parent_1] = 1; |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
875 if (parent_2 >= 0) |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
876 nothead[parent_2] = 1; |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
877 } |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
878 |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
879 for (i = 0; i < len; i++) { |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
880 PyObject *head; |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
881 |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
882 if (nothead[i]) |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
883 continue; |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
884 head = PyInt_FromLong(i); |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
885 if (head == NULL || PyList_Append(heads, head) == -1) { |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
886 Py_XDECREF(head); |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
887 goto bail; |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
888 } |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
889 } |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
890 |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
891 done: |
16787
bda96ce993f9
parsers: cache the result of index_headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16786
diff
changeset
|
892 self->headrevs = heads; |
16786
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
893 free(nothead); |
16787
bda96ce993f9
parsers: cache the result of index_headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16786
diff
changeset
|
894 return list_copy(self->headrevs); |
16786
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
895 bail: |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
896 Py_XDECREF(heads); |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
897 free(nothead); |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
898 return NULL; |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
899 } |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
900 |
16618
6bae941b58ad
parsers: change the type of nt_level
Bryan O'Sullivan <bryano@fb.com>
parents:
16617
diff
changeset
|
901 static inline int nt_level(const char *node, Py_ssize_t level) |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
902 { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
903 int v = node[level>>1]; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
904 if (!(level & 1)) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
905 v >>= 4; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
906 return v & 0xf; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
907 } |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
908 |
16616
8f79aabd96f6
parsers: allow nt_find to signal an ambiguous match
Bryan O'Sullivan <bryano@fb.com>
parents:
16615
diff
changeset
|
909 /* |
8f79aabd96f6
parsers: allow nt_find to signal an ambiguous match
Bryan O'Sullivan <bryano@fb.com>
parents:
16615
diff
changeset
|
910 * Return values: |
8f79aabd96f6
parsers: allow nt_find to signal an ambiguous match
Bryan O'Sullivan <bryano@fb.com>
parents:
16615
diff
changeset
|
911 * |
8f79aabd96f6
parsers: allow nt_find to signal an ambiguous match
Bryan O'Sullivan <bryano@fb.com>
parents:
16615
diff
changeset
|
912 * -4: match is ambiguous (multiple candidates) |
8f79aabd96f6
parsers: allow nt_find to signal an ambiguous match
Bryan O'Sullivan <bryano@fb.com>
parents:
16615
diff
changeset
|
913 * -2: not found |
8f79aabd96f6
parsers: allow nt_find to signal an ambiguous match
Bryan O'Sullivan <bryano@fb.com>
parents:
16615
diff
changeset
|
914 * rest: valid rev |
8f79aabd96f6
parsers: allow nt_find to signal an ambiguous match
Bryan O'Sullivan <bryano@fb.com>
parents:
16615
diff
changeset
|
915 */ |
16663 | 916 static int nt_find(indexObject *self, const char *node, Py_ssize_t nodelen, |
917 int hex) | |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
918 { |
16663 | 919 int (*getnybble)(const char *, Py_ssize_t) = hex ? hexdigit : nt_level; |
16641
e6dfbc5df76f
parsers: use the correct maximum radix tree depth
Bryan O'Sullivan <bryano@fb.com>
parents:
16604
diff
changeset
|
920 int level, maxlevel, off; |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
921 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
922 if (nodelen == 20 && node[0] == '\0' && memcmp(node, nullid, 20) == 0) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
923 return -1; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
924 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
925 if (self->nt == NULL) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
926 return -2; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
927 |
16663 | 928 if (hex) |
16665
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
929 maxlevel = nodelen > 40 ? 40 : (int)nodelen; |
16663 | 930 else |
931 maxlevel = nodelen > 20 ? 40 : ((int)nodelen * 2); | |
16641
e6dfbc5df76f
parsers: use the correct maximum radix tree depth
Bryan O'Sullivan <bryano@fb.com>
parents:
16604
diff
changeset
|
932 |
e6dfbc5df76f
parsers: use the correct maximum radix tree depth
Bryan O'Sullivan <bryano@fb.com>
parents:
16604
diff
changeset
|
933 for (level = off = 0; level < maxlevel; level++) { |
16663 | 934 int k = getnybble(node, level); |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
935 nodetree *n = &self->nt[off]; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
936 int v = n->children[k]; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
937 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
938 if (v < 0) { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
939 const char *n; |
16663 | 940 Py_ssize_t i; |
941 | |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
942 v = -v - 1; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
943 n = index_node(self, v); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
944 if (n == NULL) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
945 return -2; |
16663 | 946 for (i = level; i < maxlevel; i++) |
947 if (getnybble(node, i) != nt_level(n, i)) | |
948 return -2; | |
949 return v; | |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
950 } |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
951 if (v == 0) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
952 return -2; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
953 off = v; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
954 } |
16616
8f79aabd96f6
parsers: allow nt_find to signal an ambiguous match
Bryan O'Sullivan <bryano@fb.com>
parents:
16615
diff
changeset
|
955 /* multiple matches against an ambiguous prefix */ |
8f79aabd96f6
parsers: allow nt_find to signal an ambiguous match
Bryan O'Sullivan <bryano@fb.com>
parents:
16615
diff
changeset
|
956 return -4; |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
957 } |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
958 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
959 static int nt_new(indexObject *self) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
960 { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
961 if (self->ntlength == self->ntcapacity) { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
962 self->ntcapacity *= 2; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
963 self->nt = realloc(self->nt, |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
964 self->ntcapacity * sizeof(nodetree)); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
965 if (self->nt == NULL) { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
966 PyErr_SetString(PyExc_MemoryError, "out of memory"); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
967 return -1; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
968 } |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
969 memset(&self->nt[self->ntlength], 0, |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
970 sizeof(nodetree) * (self->ntcapacity - self->ntlength)); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
971 } |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
972 return self->ntlength++; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
973 } |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
974 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
975 static int nt_insert(indexObject *self, const char *node, int rev) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
976 { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
977 int level = 0; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
978 int off = 0; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
979 |
16641
e6dfbc5df76f
parsers: use the correct maximum radix tree depth
Bryan O'Sullivan <bryano@fb.com>
parents:
16604
diff
changeset
|
980 while (level < 40) { |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
981 int k = nt_level(node, level); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
982 nodetree *n; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
983 int v; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
984 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
985 n = &self->nt[off]; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
986 v = n->children[k]; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
987 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
988 if (v == 0) { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
989 n->children[k] = -rev - 1; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
990 return 0; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
991 } |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
992 if (v < 0) { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
993 const char *oldnode = index_node(self, -v - 1); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
994 int noff; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
995 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
996 if (!oldnode || !memcmp(oldnode, node, 20)) { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
997 n->children[k] = -rev - 1; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
998 return 0; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
999 } |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1000 noff = nt_new(self); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1001 if (noff == -1) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1002 return -1; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1003 /* self->nt may have been changed by realloc */ |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1004 self->nt[off].children[k] = noff; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1005 off = noff; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1006 n = &self->nt[off]; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1007 n->children[nt_level(oldnode, ++level)] = v; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1008 if (level > self->ntdepth) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1009 self->ntdepth = level; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1010 self->ntsplits += 1; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1011 } else { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1012 level += 1; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1013 off = v; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1014 } |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1015 } |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1016 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1017 return -1; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1018 } |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1019 |
16615
96fa9dd1db38
parsers: factor out radix tree initialization
Bryan O'Sullivan <bryano@fb.com>
parents:
16614
diff
changeset
|
1020 static int nt_init(indexObject *self) |
96fa9dd1db38
parsers: factor out radix tree initialization
Bryan O'Sullivan <bryano@fb.com>
parents:
16614
diff
changeset
|
1021 { |
96fa9dd1db38
parsers: factor out radix tree initialization
Bryan O'Sullivan <bryano@fb.com>
parents:
16614
diff
changeset
|
1022 if (self->nt == NULL) { |
20110
40b7c6e4b993
mercurial/parsers.c: fix compiler warning
Abhay Kadam <abhaykadam88@gmail.com>
parents:
19728
diff
changeset
|
1023 if (self->raw_length > INT_MAX) { |
40b7c6e4b993
mercurial/parsers.c: fix compiler warning
Abhay Kadam <abhaykadam88@gmail.com>
parents:
19728
diff
changeset
|
1024 PyErr_SetString(PyExc_ValueError, "overflow in nt_init"); |
40b7c6e4b993
mercurial/parsers.c: fix compiler warning
Abhay Kadam <abhaykadam88@gmail.com>
parents:
19728
diff
changeset
|
1025 return -1; |
40b7c6e4b993
mercurial/parsers.c: fix compiler warning
Abhay Kadam <abhaykadam88@gmail.com>
parents:
19728
diff
changeset
|
1026 } |
16615
96fa9dd1db38
parsers: factor out radix tree initialization
Bryan O'Sullivan <bryano@fb.com>
parents:
16614
diff
changeset
|
1027 self->ntcapacity = self->raw_length < 4 |
20110
40b7c6e4b993
mercurial/parsers.c: fix compiler warning
Abhay Kadam <abhaykadam88@gmail.com>
parents:
19728
diff
changeset
|
1028 ? 4 : (int)self->raw_length / 2; |
40b7c6e4b993
mercurial/parsers.c: fix compiler warning
Abhay Kadam <abhaykadam88@gmail.com>
parents:
19728
diff
changeset
|
1029 |
16615
96fa9dd1db38
parsers: factor out radix tree initialization
Bryan O'Sullivan <bryano@fb.com>
parents:
16614
diff
changeset
|
1030 self->nt = calloc(self->ntcapacity, sizeof(nodetree)); |
96fa9dd1db38
parsers: factor out radix tree initialization
Bryan O'Sullivan <bryano@fb.com>
parents:
16614
diff
changeset
|
1031 if (self->nt == NULL) { |
96fa9dd1db38
parsers: factor out radix tree initialization
Bryan O'Sullivan <bryano@fb.com>
parents:
16614
diff
changeset
|
1032 PyErr_NoMemory(); |
96fa9dd1db38
parsers: factor out radix tree initialization
Bryan O'Sullivan <bryano@fb.com>
parents:
16614
diff
changeset
|
1033 return -1; |
96fa9dd1db38
parsers: factor out radix tree initialization
Bryan O'Sullivan <bryano@fb.com>
parents:
16614
diff
changeset
|
1034 } |
96fa9dd1db38
parsers: factor out radix tree initialization
Bryan O'Sullivan <bryano@fb.com>
parents:
16614
diff
changeset
|
1035 self->ntlength = 1; |
96fa9dd1db38
parsers: factor out radix tree initialization
Bryan O'Sullivan <bryano@fb.com>
parents:
16614
diff
changeset
|
1036 self->ntrev = (int)index_length(self) - 1; |
96fa9dd1db38
parsers: factor out radix tree initialization
Bryan O'Sullivan <bryano@fb.com>
parents:
16614
diff
changeset
|
1037 self->ntlookups = 1; |
96fa9dd1db38
parsers: factor out radix tree initialization
Bryan O'Sullivan <bryano@fb.com>
parents:
16614
diff
changeset
|
1038 self->ntmisses = 0; |
16664
5bc6edf71b39
parsers: ensure that nullid is always present in the radix tree
Bryan O'Sullivan <bryano@fb.com>
parents:
16663
diff
changeset
|
1039 if (nt_insert(self, nullid, INT_MAX) == -1) |
5bc6edf71b39
parsers: ensure that nullid is always present in the radix tree
Bryan O'Sullivan <bryano@fb.com>
parents:
16663
diff
changeset
|
1040 return -1; |
16615
96fa9dd1db38
parsers: factor out radix tree initialization
Bryan O'Sullivan <bryano@fb.com>
parents:
16614
diff
changeset
|
1041 } |
96fa9dd1db38
parsers: factor out radix tree initialization
Bryan O'Sullivan <bryano@fb.com>
parents:
16614
diff
changeset
|
1042 return 0; |
96fa9dd1db38
parsers: factor out radix tree initialization
Bryan O'Sullivan <bryano@fb.com>
parents:
16614
diff
changeset
|
1043 } |
96fa9dd1db38
parsers: factor out radix tree initialization
Bryan O'Sullivan <bryano@fb.com>
parents:
16614
diff
changeset
|
1044 |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1045 /* |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1046 * Return values: |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1047 * |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1048 * -3: error (exception set) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1049 * -2: not found (no exception set) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1050 * rest: valid rev |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1051 */ |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1052 static int index_find_node(indexObject *self, |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1053 const char *node, Py_ssize_t nodelen) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1054 { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1055 int rev; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1056 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1057 self->ntlookups++; |
16663 | 1058 rev = nt_find(self, node, nodelen, 0); |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1059 if (rev >= -1) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1060 return rev; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1061 |
16615
96fa9dd1db38
parsers: factor out radix tree initialization
Bryan O'Sullivan <bryano@fb.com>
parents:
16614
diff
changeset
|
1062 if (nt_init(self) == -1) |
96fa9dd1db38
parsers: factor out radix tree initialization
Bryan O'Sullivan <bryano@fb.com>
parents:
16614
diff
changeset
|
1063 return -3; |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1064 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1065 /* |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1066 * For the first handful of lookups, we scan the entire index, |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1067 * and cache only the matching nodes. This optimizes for cases |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1068 * like "hg tip", where only a few nodes are accessed. |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1069 * |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1070 * After that, we cache every node we visit, using a single |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1071 * scan amortized over multiple lookups. This gives the best |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1072 * bulk performance, e.g. for "hg log". |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1073 */ |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1074 if (self->ntmisses++ < 4) { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1075 for (rev = self->ntrev - 1; rev >= 0; rev--) { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1076 const char *n = index_node(self, rev); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1077 if (n == NULL) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1078 return -2; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1079 if (memcmp(node, n, nodelen > 20 ? 20 : nodelen) == 0) { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1080 if (nt_insert(self, n, rev) == -1) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1081 return -3; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1082 break; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1083 } |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1084 } |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1085 } else { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1086 for (rev = self->ntrev - 1; rev >= 0; rev--) { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1087 const char *n = index_node(self, rev); |
16614
1d800eb9ba52
parsers: update ntrev when we stop scanning
Bryan O'Sullivan <bryano@fb.com>
parents:
16597
diff
changeset
|
1088 if (n == NULL) { |
1d800eb9ba52
parsers: update ntrev when we stop scanning
Bryan O'Sullivan <bryano@fb.com>
parents:
16597
diff
changeset
|
1089 self->ntrev = rev + 1; |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1090 return -2; |
16614
1d800eb9ba52
parsers: update ntrev when we stop scanning
Bryan O'Sullivan <bryano@fb.com>
parents:
16597
diff
changeset
|
1091 } |
1d800eb9ba52
parsers: update ntrev when we stop scanning
Bryan O'Sullivan <bryano@fb.com>
parents:
16597
diff
changeset
|
1092 if (nt_insert(self, n, rev) == -1) { |
1d800eb9ba52
parsers: update ntrev when we stop scanning
Bryan O'Sullivan <bryano@fb.com>
parents:
16597
diff
changeset
|
1093 self->ntrev = rev + 1; |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1094 return -3; |
16614
1d800eb9ba52
parsers: update ntrev when we stop scanning
Bryan O'Sullivan <bryano@fb.com>
parents:
16597
diff
changeset
|
1095 } |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1096 if (memcmp(node, n, nodelen > 20 ? 20 : nodelen) == 0) { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1097 break; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1098 } |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1099 } |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1100 self->ntrev = rev; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1101 } |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1102 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1103 if (rev >= 0) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1104 return rev; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1105 return -2; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1106 } |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1107 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1108 static PyObject *raise_revlog_error(void) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1109 { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1110 static PyObject *errclass; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1111 PyObject *mod = NULL, *errobj; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1112 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1113 if (errclass == NULL) { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1114 PyObject *dict; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1115 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1116 mod = PyImport_ImportModule("mercurial.error"); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1117 if (mod == NULL) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1118 goto classfail; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1119 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1120 dict = PyModule_GetDict(mod); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1121 if (dict == NULL) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1122 goto classfail; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1123 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1124 errclass = PyDict_GetItemString(dict, "RevlogError"); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1125 if (errclass == NULL) { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1126 PyErr_SetString(PyExc_SystemError, |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1127 "could not find RevlogError"); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1128 goto classfail; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1129 } |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1130 Py_INCREF(errclass); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1131 } |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1132 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1133 errobj = PyObject_CallFunction(errclass, NULL); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1134 if (errobj == NULL) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1135 return NULL; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1136 PyErr_SetObject(errclass, errobj); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1137 return errobj; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1138 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1139 classfail: |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1140 Py_XDECREF(mod); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1141 return NULL; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1142 } |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1143 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1144 static PyObject *index_getitem(indexObject *self, PyObject *value) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1145 { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1146 char *node; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1147 Py_ssize_t nodelen; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1148 int rev; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1149 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1150 if (PyInt_Check(value)) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1151 return index_get(self, PyInt_AS_LONG(value)); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1152 |
16679
2950d186a927
parsers: strictly check for 20-byte hashes where they're required
Bryan O'Sullivan <bryano@fb.com>
parents:
16641
diff
changeset
|
1153 if (node_check(value, &node, &nodelen) == -1) |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1154 return NULL; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1155 rev = index_find_node(self, node, nodelen); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1156 if (rev >= -1) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1157 return PyInt_FromLong(rev); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1158 if (rev == -2) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1159 raise_revlog_error(); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1160 return NULL; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1161 } |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1162 |
16665
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1163 static int nt_partialmatch(indexObject *self, const char *node, |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1164 Py_ssize_t nodelen) |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1165 { |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1166 int rev; |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1167 |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1168 if (nt_init(self) == -1) |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1169 return -3; |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1170 |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1171 if (self->ntrev > 0) { |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1172 /* ensure that the radix tree is fully populated */ |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1173 for (rev = self->ntrev - 1; rev >= 0; rev--) { |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1174 const char *n = index_node(self, rev); |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1175 if (n == NULL) |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1176 return -2; |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1177 if (nt_insert(self, n, rev) == -1) |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1178 return -3; |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1179 } |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1180 self->ntrev = rev; |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1181 } |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1182 |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1183 return nt_find(self, node, nodelen, 1); |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1184 } |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1185 |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1186 static PyObject *index_partialmatch(indexObject *self, PyObject *args) |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1187 { |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1188 const char *fullnode; |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1189 int nodelen; |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1190 char *node; |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1191 int rev, i; |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1192 |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1193 if (!PyArg_ParseTuple(args, "s#", &node, &nodelen)) |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1194 return NULL; |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1195 |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1196 if (nodelen < 4) { |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1197 PyErr_SetString(PyExc_ValueError, "key too short"); |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1198 return NULL; |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1199 } |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1200 |
17353
bde1185f406c
revlog: don't try to partialmatch strings those length > 40
sorcerer
parents:
17165
diff
changeset
|
1201 if (nodelen > 40) { |
bde1185f406c
revlog: don't try to partialmatch strings those length > 40
sorcerer
parents:
17165
diff
changeset
|
1202 PyErr_SetString(PyExc_ValueError, "key too long"); |
bde1185f406c
revlog: don't try to partialmatch strings those length > 40
sorcerer
parents:
17165
diff
changeset
|
1203 return NULL; |
bde1185f406c
revlog: don't try to partialmatch strings those length > 40
sorcerer
parents:
17165
diff
changeset
|
1204 } |
16665
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1205 |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1206 for (i = 0; i < nodelen; i++) |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1207 hexdigit(node, i); |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1208 if (PyErr_Occurred()) { |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1209 /* input contains non-hex characters */ |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1210 PyErr_Clear(); |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1211 Py_RETURN_NONE; |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1212 } |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1213 |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1214 rev = nt_partialmatch(self, node, nodelen); |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1215 |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1216 switch (rev) { |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1217 case -4: |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1218 raise_revlog_error(); |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1219 case -3: |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1220 return NULL; |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1221 case -2: |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1222 Py_RETURN_NONE; |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1223 case -1: |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1224 return PyString_FromStringAndSize(nullid, 20); |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1225 } |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1226 |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1227 fullnode = index_node(self, rev); |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1228 if (fullnode == NULL) { |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1229 PyErr_Format(PyExc_IndexError, |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1230 "could not access rev %d", rev); |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1231 return NULL; |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1232 } |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1233 return PyString_FromStringAndSize(fullnode, 20); |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1234 } |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1235 |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1236 static PyObject *index_m_get(indexObject *self, PyObject *args) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1237 { |
16679
2950d186a927
parsers: strictly check for 20-byte hashes where they're required
Bryan O'Sullivan <bryano@fb.com>
parents:
16641
diff
changeset
|
1238 Py_ssize_t nodelen; |
2950d186a927
parsers: strictly check for 20-byte hashes where they're required
Bryan O'Sullivan <bryano@fb.com>
parents:
16641
diff
changeset
|
1239 PyObject *val; |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1240 char *node; |
16679
2950d186a927
parsers: strictly check for 20-byte hashes where they're required
Bryan O'Sullivan <bryano@fb.com>
parents:
16641
diff
changeset
|
1241 int rev; |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1242 |
16679
2950d186a927
parsers: strictly check for 20-byte hashes where they're required
Bryan O'Sullivan <bryano@fb.com>
parents:
16641
diff
changeset
|
1243 if (!PyArg_ParseTuple(args, "O", &val)) |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1244 return NULL; |
16679
2950d186a927
parsers: strictly check for 20-byte hashes where they're required
Bryan O'Sullivan <bryano@fb.com>
parents:
16641
diff
changeset
|
1245 if (node_check(val, &node, &nodelen) == -1) |
2950d186a927
parsers: strictly check for 20-byte hashes where they're required
Bryan O'Sullivan <bryano@fb.com>
parents:
16641
diff
changeset
|
1246 return NULL; |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1247 rev = index_find_node(self, node, nodelen); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1248 if (rev == -3) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1249 return NULL; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1250 if (rev == -2) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1251 Py_RETURN_NONE; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1252 return PyInt_FromLong(rev); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1253 } |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1254 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1255 static int index_contains(indexObject *self, PyObject *value) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1256 { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1257 char *node; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1258 Py_ssize_t nodelen; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1259 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1260 if (PyInt_Check(value)) { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1261 long rev = PyInt_AS_LONG(value); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1262 return rev >= -1 && rev < index_length(self); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1263 } |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1264 |
16679
2950d186a927
parsers: strictly check for 20-byte hashes where they're required
Bryan O'Sullivan <bryano@fb.com>
parents:
16641
diff
changeset
|
1265 if (node_check(value, &node, &nodelen) == -1) |
2950d186a927
parsers: strictly check for 20-byte hashes where they're required
Bryan O'Sullivan <bryano@fb.com>
parents:
16641
diff
changeset
|
1266 return -1; |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1267 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1268 switch (index_find_node(self, node, nodelen)) { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1269 case -3: |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1270 return -1; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1271 case -2: |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1272 return 0; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1273 default: |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1274 return 1; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1275 } |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1276 } |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1277 |
18988
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1278 static inline void index_get_parents(indexObject *self, int rev, int *ps) |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1279 { |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1280 if (rev >= self->length - 1) { |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1281 PyObject *tuple = PyList_GET_ITEM(self->added, |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1282 rev - self->length + 1); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1283 ps[0] = (int)PyInt_AS_LONG(PyTuple_GET_ITEM(tuple, 5)); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1284 ps[1] = (int)PyInt_AS_LONG(PyTuple_GET_ITEM(tuple, 6)); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1285 } else { |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1286 const char *data = index_deref(self, rev); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1287 ps[0] = getbe32(data + 24); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1288 ps[1] = getbe32(data + 28); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1289 } |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1290 } |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1291 |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1292 typedef uint64_t bitmask; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1293 |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1294 /* |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1295 * Given a disjoint set of revs, return all candidates for the |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1296 * greatest common ancestor. In revset notation, this is the set |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1297 * "heads(::a and ::b and ...)" |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1298 */ |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1299 static PyObject *find_gca_candidates(indexObject *self, const int *revs, |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1300 int revcount) |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1301 { |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1302 const bitmask allseen = (1ull << revcount) - 1; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1303 const bitmask poison = 1ull << revcount; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1304 PyObject *gca = PyList_New(0); |
20555
4add43865a9b
ancestors: remove unnecessary handling of 'left'
Mads Kiilerich <madski@unity3d.com>
parents:
20554
diff
changeset
|
1305 int i, v, interesting; |
18988
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1306 int maxrev = -1; |
19030
48d6f436363e
parsers: fix variable declaration position issue
Matt Mackall <mpm@selenic.com>
parents:
18988
diff
changeset
|
1307 long sp; |
18988
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1308 bitmask *seen; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1309 |
19727
3d07b4a2f743
parsers: correctly handle a failed allocation
Bryan O'Sullivan <bryano@fb.com>
parents:
19726
diff
changeset
|
1310 if (gca == NULL) |
3d07b4a2f743
parsers: correctly handle a failed allocation
Bryan O'Sullivan <bryano@fb.com>
parents:
19726
diff
changeset
|
1311 return PyErr_NoMemory(); |
3d07b4a2f743
parsers: correctly handle a failed allocation
Bryan O'Sullivan <bryano@fb.com>
parents:
19726
diff
changeset
|
1312 |
18988
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1313 for (i = 0; i < revcount; i++) { |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1314 if (revs[i] > maxrev) |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1315 maxrev = revs[i]; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1316 } |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1317 |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1318 seen = calloc(sizeof(*seen), maxrev + 1); |
19727
3d07b4a2f743
parsers: correctly handle a failed allocation
Bryan O'Sullivan <bryano@fb.com>
parents:
19726
diff
changeset
|
1319 if (seen == NULL) { |
3d07b4a2f743
parsers: correctly handle a failed allocation
Bryan O'Sullivan <bryano@fb.com>
parents:
19726
diff
changeset
|
1320 Py_DECREF(gca); |
18988
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1321 return PyErr_NoMemory(); |
19727
3d07b4a2f743
parsers: correctly handle a failed allocation
Bryan O'Sullivan <bryano@fb.com>
parents:
19726
diff
changeset
|
1322 } |
18988
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1323 |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1324 for (i = 0; i < revcount; i++) |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1325 seen[revs[i]] = 1ull << i; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1326 |
20555
4add43865a9b
ancestors: remove unnecessary handling of 'left'
Mads Kiilerich <madski@unity3d.com>
parents:
20554
diff
changeset
|
1327 interesting = revcount; |
18988
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1328 |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1329 for (v = maxrev; v >= 0 && interesting; v--) { |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1330 long sv = seen[v]; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1331 int parents[2]; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1332 |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1333 if (!sv) |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1334 continue; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1335 |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1336 if (sv < poison) { |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1337 interesting -= 1; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1338 if (sv == allseen) { |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1339 PyObject *obj = PyInt_FromLong(v); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1340 if (obj == NULL) |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1341 goto bail; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1342 if (PyList_Append(gca, obj) == -1) { |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1343 Py_DECREF(obj); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1344 goto bail; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1345 } |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1346 sv |= poison; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1347 for (i = 0; i < revcount; i++) { |
20555
4add43865a9b
ancestors: remove unnecessary handling of 'left'
Mads Kiilerich <madski@unity3d.com>
parents:
20554
diff
changeset
|
1348 if (revs[i] == v) |
4add43865a9b
ancestors: remove unnecessary handling of 'left'
Mads Kiilerich <madski@unity3d.com>
parents:
20554
diff
changeset
|
1349 goto done; |
18988
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1350 } |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1351 } |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1352 } |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1353 index_get_parents(self, v, parents); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1354 |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1355 for (i = 0; i < 2; i++) { |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1356 int p = parents[i]; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1357 if (p == -1) |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1358 continue; |
19030
48d6f436363e
parsers: fix variable declaration position issue
Matt Mackall <mpm@selenic.com>
parents:
18988
diff
changeset
|
1359 sp = seen[p]; |
18988
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1360 if (sv < poison) { |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1361 if (sp == 0) { |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1362 seen[p] = sv; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1363 interesting++; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1364 } |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1365 else if (sp != sv) |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1366 seen[p] |= sv; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1367 } else { |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1368 if (sp && sp < poison) |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1369 interesting--; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1370 seen[p] = sv; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1371 } |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1372 } |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1373 } |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1374 |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1375 done: |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1376 free(seen); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1377 return gca; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1378 bail: |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1379 free(seen); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1380 Py_XDECREF(gca); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1381 return NULL; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1382 } |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1383 |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1384 /* |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1385 * Given a disjoint set of revs, return the subset with the longest |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1386 * path to the root. |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1387 */ |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1388 static PyObject *find_deepest(indexObject *self, PyObject *revs) |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1389 { |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1390 const Py_ssize_t revcount = PyList_GET_SIZE(revs); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1391 static const Py_ssize_t capacity = 24; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1392 int *depth, *interesting = NULL; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1393 int i, j, v, ninteresting; |
21730
8da100383dc3
parsers.c: fix a couple of memory leaks
Danek Duvall <danek.duvall@oracle.com>
parents:
21103
diff
changeset
|
1394 PyObject *dict = NULL, *keys = NULL; |
18988
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1395 long *seen = NULL; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1396 int maxrev = -1; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1397 long final; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1398 |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1399 if (revcount > capacity) { |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1400 PyErr_Format(PyExc_OverflowError, |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1401 "bitset size (%ld) > capacity (%ld)", |
19062
365b0de17c1c
parsers: remove warning: format ‘%ld’ expects argument of type ‘long int’
André Sintzoff <andre.sintzoff@gmail.com>
parents:
19030
diff
changeset
|
1402 (long)revcount, (long)capacity); |
18988
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1403 return NULL; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1404 } |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1405 |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1406 for (i = 0; i < revcount; i++) { |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1407 int n = (int)PyInt_AsLong(PyList_GET_ITEM(revs, i)); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1408 if (n > maxrev) |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1409 maxrev = n; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1410 } |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1411 |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1412 depth = calloc(sizeof(*depth), maxrev + 1); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1413 if (depth == NULL) |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1414 return PyErr_NoMemory(); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1415 |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1416 seen = calloc(sizeof(*seen), maxrev + 1); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1417 if (seen == NULL) { |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1418 PyErr_NoMemory(); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1419 goto bail; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1420 } |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1421 |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1422 interesting = calloc(sizeof(*interesting), 2 << revcount); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1423 if (interesting == NULL) { |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1424 PyErr_NoMemory(); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1425 goto bail; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1426 } |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1427 |
19502
8704477ad3b6
ancestor.deepest: sort revs in C version
Siddharth Agarwal <sid0@fb.com>
parents:
19062
diff
changeset
|
1428 if (PyList_Sort(revs) == -1) |
8704477ad3b6
ancestor.deepest: sort revs in C version
Siddharth Agarwal <sid0@fb.com>
parents:
19062
diff
changeset
|
1429 goto bail; |
8704477ad3b6
ancestor.deepest: sort revs in C version
Siddharth Agarwal <sid0@fb.com>
parents:
19062
diff
changeset
|
1430 |
18988
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1431 for (i = 0; i < revcount; i++) { |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1432 int n = (int)PyInt_AsLong(PyList_GET_ITEM(revs, i)); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1433 long b = 1l << i; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1434 depth[n] = 1; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1435 seen[n] = b; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1436 interesting[b] = 1; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1437 } |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1438 |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1439 ninteresting = (int)revcount; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1440 |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1441 for (v = maxrev; v >= 0 && ninteresting > 1; v--) { |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1442 int dv = depth[v]; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1443 int parents[2]; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1444 long sv; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1445 |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1446 if (dv == 0) |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1447 continue; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1448 |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1449 sv = seen[v]; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1450 index_get_parents(self, v, parents); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1451 |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1452 for (i = 0; i < 2; i++) { |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1453 int p = parents[i]; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1454 long nsp, sp; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1455 int dp; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1456 |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1457 if (p == -1) |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1458 continue; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1459 |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1460 dp = depth[p]; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1461 nsp = sp = seen[p]; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1462 if (dp <= dv) { |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1463 depth[p] = dv + 1; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1464 if (sp != sv) { |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1465 interesting[sv] += 1; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1466 nsp = seen[p] = sv; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1467 if (sp) { |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1468 interesting[sp] -= 1; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1469 if (interesting[sp] == 0) |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1470 ninteresting -= 1; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1471 } |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1472 } |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1473 } |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1474 else if (dv == dp - 1) { |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1475 nsp = sp | sv; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1476 if (nsp == sp) |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1477 continue; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1478 seen[p] = nsp; |
19503
f2dfda6ac152
ancestor.deepest: decrement ninteresting correctly (issue3984)
Wei, Elson <elson.wei@gmail.com>
parents:
19502
diff
changeset
|
1479 interesting[sp] -= 1; |
f2dfda6ac152
ancestor.deepest: decrement ninteresting correctly (issue3984)
Wei, Elson <elson.wei@gmail.com>
parents:
19502
diff
changeset
|
1480 if (interesting[sp] == 0 && interesting[nsp] > 0) |
f2dfda6ac152
ancestor.deepest: decrement ninteresting correctly (issue3984)
Wei, Elson <elson.wei@gmail.com>
parents:
19502
diff
changeset
|
1481 ninteresting -= 1; |
18988
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1482 interesting[nsp] += 1; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1483 } |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1484 } |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1485 interesting[sv] -= 1; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1486 if (interesting[sv] == 0) |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1487 ninteresting -= 1; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1488 } |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1489 |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1490 final = 0; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1491 j = ninteresting; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1492 for (i = 0; i < (int)(2 << revcount) && j > 0; i++) { |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1493 if (interesting[i] == 0) |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1494 continue; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1495 final |= i; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1496 j -= 1; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1497 } |
21730
8da100383dc3
parsers.c: fix a couple of memory leaks
Danek Duvall <danek.duvall@oracle.com>
parents:
21103
diff
changeset
|
1498 if (final == 0) { |
8da100383dc3
parsers.c: fix a couple of memory leaks
Danek Duvall <danek.duvall@oracle.com>
parents:
21103
diff
changeset
|
1499 keys = PyList_New(0); |
8da100383dc3
parsers.c: fix a couple of memory leaks
Danek Duvall <danek.duvall@oracle.com>
parents:
21103
diff
changeset
|
1500 goto bail; |
8da100383dc3
parsers.c: fix a couple of memory leaks
Danek Duvall <danek.duvall@oracle.com>
parents:
21103
diff
changeset
|
1501 } |
18988
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1502 |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1503 dict = PyDict_New(); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1504 if (dict == NULL) |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1505 goto bail; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1506 |
19504
2fa303619b4d
ancestor.deepest: ignore ninteresting while building result (issue3984)
Siddharth Agarwal <sid0@fb.com>
parents:
19503
diff
changeset
|
1507 for (i = 0; i < revcount; i++) { |
18988
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1508 PyObject *key; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1509 |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1510 if ((final & (1 << i)) == 0) |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1511 continue; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1512 |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1513 key = PyList_GET_ITEM(revs, i); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1514 Py_INCREF(key); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1515 Py_INCREF(Py_None); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1516 if (PyDict_SetItem(dict, key, Py_None) == -1) { |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1517 Py_DECREF(key); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1518 Py_DECREF(Py_None); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1519 goto bail; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1520 } |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1521 } |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1522 |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1523 keys = PyDict_Keys(dict); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1524 |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1525 bail: |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1526 free(depth); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1527 free(seen); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1528 free(interesting); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1529 Py_XDECREF(dict); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1530 |
21730
8da100383dc3
parsers.c: fix a couple of memory leaks
Danek Duvall <danek.duvall@oracle.com>
parents:
21103
diff
changeset
|
1531 return keys; |
18988
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1532 } |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1533 |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1534 /* |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1535 * Given a (possibly overlapping) set of revs, return the greatest |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1536 * common ancestors: those with the longest path to the root. |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1537 */ |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1538 static PyObject *index_ancestors(indexObject *self, PyObject *args) |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1539 { |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1540 PyObject *ret = NULL, *gca = NULL; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1541 Py_ssize_t argcount, i, len; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1542 bitmask repeat = 0; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1543 int revcount = 0; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1544 int *revs; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1545 |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1546 argcount = PySequence_Length(args); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1547 revs = malloc(argcount * sizeof(*revs)); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1548 if (argcount > 0 && revs == NULL) |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1549 return PyErr_NoMemory(); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1550 len = index_length(self) - 1; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1551 |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1552 for (i = 0; i < argcount; i++) { |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1553 static const int capacity = 24; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1554 PyObject *obj = PySequence_GetItem(args, i); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1555 bitmask x; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1556 long val; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1557 |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1558 if (!PyInt_Check(obj)) { |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1559 PyErr_SetString(PyExc_TypeError, |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1560 "arguments must all be ints"); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1561 goto bail; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1562 } |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1563 val = PyInt_AsLong(obj); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1564 if (val == -1) { |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1565 ret = PyList_New(0); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1566 goto done; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1567 } |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1568 if (val < 0 || val >= len) { |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1569 PyErr_SetString(PyExc_IndexError, |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1570 "index out of range"); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1571 goto bail; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1572 } |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1573 /* this cheesy bloom filter lets us avoid some more |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1574 * expensive duplicate checks in the common set-is-disjoint |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1575 * case */ |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1576 x = 1ull << (val & 0x3f); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1577 if (repeat & x) { |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1578 int k; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1579 for (k = 0; k < revcount; k++) { |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1580 if (val == revs[k]) |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1581 goto duplicate; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1582 } |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1583 } |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1584 else repeat |= x; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1585 if (revcount >= capacity) { |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1586 PyErr_Format(PyExc_OverflowError, |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1587 "bitset size (%d) > capacity (%d)", |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1588 revcount, capacity); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1589 goto bail; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1590 } |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1591 revs[revcount++] = (int)val; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1592 duplicate:; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1593 } |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1594 |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1595 if (revcount == 0) { |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1596 ret = PyList_New(0); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1597 goto done; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1598 } |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1599 if (revcount == 1) { |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1600 PyObject *obj; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1601 ret = PyList_New(1); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1602 if (ret == NULL) |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1603 goto bail; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1604 obj = PyInt_FromLong(revs[0]); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1605 if (obj == NULL) |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1606 goto bail; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1607 PyList_SET_ITEM(ret, 0, obj); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1608 goto done; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1609 } |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1610 |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1611 gca = find_gca_candidates(self, revs, revcount); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1612 if (gca == NULL) |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1613 goto bail; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1614 |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1615 if (PyList_GET_SIZE(gca) <= 1) { |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1616 ret = gca; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1617 Py_INCREF(gca); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1618 } |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1619 else ret = find_deepest(self, gca); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1620 |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1621 done: |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1622 free(revs); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1623 Py_XDECREF(gca); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1624 |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1625 return ret; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1626 |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1627 bail: |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1628 free(revs); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1629 Py_XDECREF(gca); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1630 Py_XDECREF(ret); |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1631 return NULL; |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1632 } |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1633 |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1634 /* |
21102
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1635 * Given a (possibly overlapping) set of revs, return all the |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1636 * common ancestors heads: heads(::args[0] and ::a[1] and ...) |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1637 */ |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1638 static PyObject *index_commonancestorsheads(indexObject *self, PyObject *args) |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1639 { |
21103
628c16489d1c
parsers: remove unnecessary gca variable in index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
21102
diff
changeset
|
1640 PyObject *ret = NULL; |
21102
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1641 Py_ssize_t argcount, i, len; |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1642 bitmask repeat = 0; |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1643 int revcount = 0; |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1644 int *revs; |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1645 |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1646 argcount = PySequence_Length(args); |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1647 revs = malloc(argcount * sizeof(*revs)); |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1648 if (argcount > 0 && revs == NULL) |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1649 return PyErr_NoMemory(); |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1650 len = index_length(self) - 1; |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1651 |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1652 for (i = 0; i < argcount; i++) { |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1653 static const int capacity = 24; |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1654 PyObject *obj = PySequence_GetItem(args, i); |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1655 bitmask x; |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1656 long val; |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1657 |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1658 if (!PyInt_Check(obj)) { |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1659 PyErr_SetString(PyExc_TypeError, |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1660 "arguments must all be ints"); |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1661 goto bail; |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1662 } |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1663 val = PyInt_AsLong(obj); |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1664 if (val == -1) { |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1665 ret = PyList_New(0); |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1666 goto done; |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1667 } |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1668 if (val < 0 || val >= len) { |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1669 PyErr_SetString(PyExc_IndexError, |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1670 "index out of range"); |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1671 goto bail; |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1672 } |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1673 /* this cheesy bloom filter lets us avoid some more |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1674 * expensive duplicate checks in the common set-is-disjoint |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1675 * case */ |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1676 x = 1ull << (val & 0x3f); |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1677 if (repeat & x) { |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1678 int k; |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1679 for (k = 0; k < revcount; k++) { |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1680 if (val == revs[k]) |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1681 goto duplicate; |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1682 } |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1683 } |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1684 else repeat |= x; |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1685 if (revcount >= capacity) { |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1686 PyErr_Format(PyExc_OverflowError, |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1687 "bitset size (%d) > capacity (%d)", |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1688 revcount, capacity); |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1689 goto bail; |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1690 } |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1691 revs[revcount++] = (int)val; |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1692 duplicate:; |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1693 } |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1694 |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1695 if (revcount == 0) { |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1696 ret = PyList_New(0); |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1697 goto done; |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1698 } |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1699 if (revcount == 1) { |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1700 PyObject *obj; |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1701 ret = PyList_New(1); |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1702 if (ret == NULL) |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1703 goto bail; |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1704 obj = PyInt_FromLong(revs[0]); |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1705 if (obj == NULL) |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1706 goto bail; |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1707 PyList_SET_ITEM(ret, 0, obj); |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1708 goto done; |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1709 } |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1710 |
21103
628c16489d1c
parsers: remove unnecessary gca variable in index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
21102
diff
changeset
|
1711 ret = find_gca_candidates(self, revs, revcount); |
628c16489d1c
parsers: remove unnecessary gca variable in index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
21102
diff
changeset
|
1712 if (ret == NULL) |
21102
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1713 goto bail; |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1714 |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1715 done: |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1716 free(revs); |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1717 return ret; |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1718 |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1719 bail: |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1720 free(revs); |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1721 Py_XDECREF(ret); |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1722 return NULL; |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1723 } |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1724 |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1725 /* |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1726 * Invalidate any trie entries introduced by added revs. |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1727 */ |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1728 static void nt_invalidate_added(indexObject *self, Py_ssize_t start) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1729 { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1730 Py_ssize_t i, len = PyList_GET_SIZE(self->added); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1731 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1732 for (i = start; i < len; i++) { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1733 PyObject *tuple = PyList_GET_ITEM(self->added, i); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1734 PyObject *node = PyTuple_GET_ITEM(tuple, 7); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1735 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1736 nt_insert(self, PyString_AS_STRING(node), -1); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1737 } |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1738 |
16732
277e2acb7e5c
parsers: use Py_CLEAR where appropriate
Bryan O'Sullivan <bryano@fb.com>
parents:
16699
diff
changeset
|
1739 if (start == 0) |
277e2acb7e5c
parsers: use Py_CLEAR where appropriate
Bryan O'Sullivan <bryano@fb.com>
parents:
16699
diff
changeset
|
1740 Py_CLEAR(self->added); |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1741 } |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1742 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1743 /* |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1744 * Delete a numeric range of revs, which must be at the end of the |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1745 * range, but exclude the sentinel nullid entry. |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1746 */ |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1747 static int index_slice_del(indexObject *self, PyObject *item) |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1748 { |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1749 Py_ssize_t start, stop, step, slicelength; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1750 Py_ssize_t length = index_length(self); |
16784
12a852c7c763
parsers: reduce raw_length when truncating
Bryan O'Sullivan <bryano@fb.com>
parents:
16732
diff
changeset
|
1751 int ret = 0; |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1752 |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1753 if (PySlice_GetIndicesEx((PySliceObject*)item, length, |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1754 &start, &stop, &step, &slicelength) < 0) |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1755 return -1; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1756 |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1757 if (slicelength <= 0) |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1758 return 0; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1759 |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1760 if ((step < 0 && start < stop) || (step > 0 && start > stop)) |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1761 stop = start; |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
1762 |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1763 if (step < 0) { |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1764 stop = start + 1; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1765 start = stop + step*(slicelength - 1) - 1; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1766 step = -step; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1767 } |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1768 |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1769 if (step != 1) { |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1770 PyErr_SetString(PyExc_ValueError, |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1771 "revlog index delete requires step size of 1"); |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1772 return -1; |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
1773 } |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1774 |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1775 if (stop != length - 1) { |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1776 PyErr_SetString(PyExc_IndexError, |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1777 "revlog index deletion indices are invalid"); |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1778 return -1; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1779 } |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1780 |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1781 if (start < self->length - 1) { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1782 if (self->nt) { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1783 Py_ssize_t i; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1784 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1785 for (i = start + 1; i < self->length - 1; i++) { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1786 const char *node = index_node(self, i); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1787 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1788 if (node) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1789 nt_insert(self, node, -1); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1790 } |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1791 if (self->added) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1792 nt_invalidate_added(self, 0); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1793 if (self->ntrev > start) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1794 self->ntrev = (int)start; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1795 } |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1796 self->length = start + 1; |
18504
d1d5fdcc2d46
parsers: fix memleak of revlog cache entries on strip
Yuya Nishihara <yuya@tcha.org>
parents:
18430
diff
changeset
|
1797 if (start < self->raw_length) { |
d1d5fdcc2d46
parsers: fix memleak of revlog cache entries on strip
Yuya Nishihara <yuya@tcha.org>
parents:
18430
diff
changeset
|
1798 if (self->cache) { |
d1d5fdcc2d46
parsers: fix memleak of revlog cache entries on strip
Yuya Nishihara <yuya@tcha.org>
parents:
18430
diff
changeset
|
1799 Py_ssize_t i; |
d1d5fdcc2d46
parsers: fix memleak of revlog cache entries on strip
Yuya Nishihara <yuya@tcha.org>
parents:
18430
diff
changeset
|
1800 for (i = start; i < self->raw_length; i++) |
d1d5fdcc2d46
parsers: fix memleak of revlog cache entries on strip
Yuya Nishihara <yuya@tcha.org>
parents:
18430
diff
changeset
|
1801 Py_CLEAR(self->cache[i]); |
d1d5fdcc2d46
parsers: fix memleak of revlog cache entries on strip
Yuya Nishihara <yuya@tcha.org>
parents:
18430
diff
changeset
|
1802 } |
16784
12a852c7c763
parsers: reduce raw_length when truncating
Bryan O'Sullivan <bryano@fb.com>
parents:
16732
diff
changeset
|
1803 self->raw_length = start; |
18504
d1d5fdcc2d46
parsers: fix memleak of revlog cache entries on strip
Yuya Nishihara <yuya@tcha.org>
parents:
18430
diff
changeset
|
1804 } |
16784
12a852c7c763
parsers: reduce raw_length when truncating
Bryan O'Sullivan <bryano@fb.com>
parents:
16732
diff
changeset
|
1805 goto done; |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
1806 } |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
1807 |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1808 if (self->nt) { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1809 nt_invalidate_added(self, start - self->length + 1); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1810 if (self->ntrev > start) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1811 self->ntrev = (int)start; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1812 } |
16784
12a852c7c763
parsers: reduce raw_length when truncating
Bryan O'Sullivan <bryano@fb.com>
parents:
16732
diff
changeset
|
1813 if (self->added) |
12a852c7c763
parsers: reduce raw_length when truncating
Bryan O'Sullivan <bryano@fb.com>
parents:
16732
diff
changeset
|
1814 ret = PyList_SetSlice(self->added, start - self->length + 1, |
12a852c7c763
parsers: reduce raw_length when truncating
Bryan O'Sullivan <bryano@fb.com>
parents:
16732
diff
changeset
|
1815 PyList_GET_SIZE(self->added), NULL); |
12a852c7c763
parsers: reduce raw_length when truncating
Bryan O'Sullivan <bryano@fb.com>
parents:
16732
diff
changeset
|
1816 done: |
16787
bda96ce993f9
parsers: cache the result of index_headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16786
diff
changeset
|
1817 Py_CLEAR(self->headrevs); |
16784
12a852c7c763
parsers: reduce raw_length when truncating
Bryan O'Sullivan <bryano@fb.com>
parents:
16732
diff
changeset
|
1818 return ret; |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1819 } |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1820 |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1821 /* |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1822 * Supported ops: |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1823 * |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1824 * slice deletion |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1825 * string assignment (extend node->rev mapping) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1826 * string deletion (shrink node->rev mapping) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1827 */ |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1828 static int index_assign_subscript(indexObject *self, PyObject *item, |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1829 PyObject *value) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1830 { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1831 char *node; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1832 Py_ssize_t nodelen; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1833 long rev; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1834 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1835 if (PySlice_Check(item) && value == NULL) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1836 return index_slice_del(self, item); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1837 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1838 if (node_check(item, &node, &nodelen) == -1) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1839 return -1; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1840 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1841 if (value == NULL) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1842 return self->nt ? nt_insert(self, node, -1) : 0; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1843 rev = PyInt_AsLong(value); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1844 if (rev > INT_MAX || rev < 0) { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1845 if (!PyErr_Occurred()) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1846 PyErr_SetString(PyExc_ValueError, "rev out of range"); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1847 return -1; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1848 } |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1849 return nt_insert(self, node, (int)rev); |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1850 } |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1851 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1852 /* |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1853 * Find all RevlogNG entries in an index that has inline data. Update |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1854 * the optional "offsets" table with those entries. |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1855 */ |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1856 static long inline_scan(indexObject *self, const char **offsets) |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1857 { |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1858 const char *data = PyString_AS_STRING(self->data); |
20167
09e41ac6289d
mpatch: rewrite pointer overflow checks
Matt Mackall <mpm@selenic.com>
parents:
20109
diff
changeset
|
1859 Py_ssize_t pos = 0; |
09e41ac6289d
mpatch: rewrite pointer overflow checks
Matt Mackall <mpm@selenic.com>
parents:
20109
diff
changeset
|
1860 Py_ssize_t end = PyString_GET_SIZE(self->data); |
16863
bbedef66c6f3
parsers: replace magic number 64 with symbolic constant
Bryan O'Sullivan <bryano@fb.com>
parents:
16787
diff
changeset
|
1861 long incr = v1_hdrsize; |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1862 Py_ssize_t len = 0; |
13254
5ef5eb1f3515
revlog: only build the nodemap on demand
Matt Mackall <mpm@selenic.com>
parents:
11361
diff
changeset
|
1863 |
20167
09e41ac6289d
mpatch: rewrite pointer overflow checks
Matt Mackall <mpm@selenic.com>
parents:
20109
diff
changeset
|
1864 while (pos + v1_hdrsize <= end && pos >= 0) { |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1865 uint32_t comp_len; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1866 /* 3rd element of header is length of compressed inline data */ |
20167
09e41ac6289d
mpatch: rewrite pointer overflow checks
Matt Mackall <mpm@selenic.com>
parents:
20109
diff
changeset
|
1867 comp_len = getbe32(data + pos + 8); |
16863
bbedef66c6f3
parsers: replace magic number 64 with symbolic constant
Bryan O'Sullivan <bryano@fb.com>
parents:
16787
diff
changeset
|
1868 incr = v1_hdrsize + comp_len; |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1869 if (offsets) |
20167
09e41ac6289d
mpatch: rewrite pointer overflow checks
Matt Mackall <mpm@selenic.com>
parents:
20109
diff
changeset
|
1870 offsets[len] = data + pos; |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1871 len++; |
20167
09e41ac6289d
mpatch: rewrite pointer overflow checks
Matt Mackall <mpm@selenic.com>
parents:
20109
diff
changeset
|
1872 pos += incr; |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1873 } |
13254
5ef5eb1f3515
revlog: only build the nodemap on demand
Matt Mackall <mpm@selenic.com>
parents:
11361
diff
changeset
|
1874 |
20167
09e41ac6289d
mpatch: rewrite pointer overflow checks
Matt Mackall <mpm@selenic.com>
parents:
20109
diff
changeset
|
1875 if (pos != end) { |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1876 if (!PyErr_Occurred()) |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1877 PyErr_SetString(PyExc_ValueError, "corrupt index file"); |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1878 return -1; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1879 } |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1880 |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1881 return len; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1882 } |
13254
5ef5eb1f3515
revlog: only build the nodemap on demand
Matt Mackall <mpm@selenic.com>
parents:
11361
diff
changeset
|
1883 |
16572
8d44b5a2974f
parsers: fix refcount leak, simplify init of index (issue3417)
Bryan O'Sullivan <bryano@fb.com>
parents:
16437
diff
changeset
|
1884 static int index_init(indexObject *self, PyObject *args) |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1885 { |
16572
8d44b5a2974f
parsers: fix refcount leak, simplify init of index (issue3417)
Bryan O'Sullivan <bryano@fb.com>
parents:
16437
diff
changeset
|
1886 PyObject *data_obj, *inlined_obj; |
8d44b5a2974f
parsers: fix refcount leak, simplify init of index (issue3417)
Bryan O'Sullivan <bryano@fb.com>
parents:
16437
diff
changeset
|
1887 Py_ssize_t size; |
8d44b5a2974f
parsers: fix refcount leak, simplify init of index (issue3417)
Bryan O'Sullivan <bryano@fb.com>
parents:
16437
diff
changeset
|
1888 |
20109
e57c532c3835
parse_index2: fix crash on bad argument type (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
19728
diff
changeset
|
1889 /* Initialize before argument-checking to avoid index_dealloc() crash. */ |
e57c532c3835
parse_index2: fix crash on bad argument type (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
19728
diff
changeset
|
1890 self->raw_length = 0; |
e57c532c3835
parse_index2: fix crash on bad argument type (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
19728
diff
changeset
|
1891 self->added = NULL; |
e57c532c3835
parse_index2: fix crash on bad argument type (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
19728
diff
changeset
|
1892 self->cache = NULL; |
e57c532c3835
parse_index2: fix crash on bad argument type (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
19728
diff
changeset
|
1893 self->data = NULL; |
e57c532c3835
parse_index2: fix crash on bad argument type (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
19728
diff
changeset
|
1894 self->headrevs = NULL; |
e57c532c3835
parse_index2: fix crash on bad argument type (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
19728
diff
changeset
|
1895 self->nt = NULL; |
e57c532c3835
parse_index2: fix crash on bad argument type (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
19728
diff
changeset
|
1896 self->offsets = NULL; |
e57c532c3835
parse_index2: fix crash on bad argument type (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
19728
diff
changeset
|
1897 |
16572
8d44b5a2974f
parsers: fix refcount leak, simplify init of index (issue3417)
Bryan O'Sullivan <bryano@fb.com>
parents:
16437
diff
changeset
|
1898 if (!PyArg_ParseTuple(args, "OO", &data_obj, &inlined_obj)) |
8d44b5a2974f
parsers: fix refcount leak, simplify init of index (issue3417)
Bryan O'Sullivan <bryano@fb.com>
parents:
16437
diff
changeset
|
1899 return -1; |
8d44b5a2974f
parsers: fix refcount leak, simplify init of index (issue3417)
Bryan O'Sullivan <bryano@fb.com>
parents:
16437
diff
changeset
|
1900 if (!PyString_Check(data_obj)) { |
8d44b5a2974f
parsers: fix refcount leak, simplify init of index (issue3417)
Bryan O'Sullivan <bryano@fb.com>
parents:
16437
diff
changeset
|
1901 PyErr_SetString(PyExc_TypeError, "data is not a string"); |
8d44b5a2974f
parsers: fix refcount leak, simplify init of index (issue3417)
Bryan O'Sullivan <bryano@fb.com>
parents:
16437
diff
changeset
|
1902 return -1; |
8d44b5a2974f
parsers: fix refcount leak, simplify init of index (issue3417)
Bryan O'Sullivan <bryano@fb.com>
parents:
16437
diff
changeset
|
1903 } |
8d44b5a2974f
parsers: fix refcount leak, simplify init of index (issue3417)
Bryan O'Sullivan <bryano@fb.com>
parents:
16437
diff
changeset
|
1904 size = PyString_GET_SIZE(data_obj); |
8d44b5a2974f
parsers: fix refcount leak, simplify init of index (issue3417)
Bryan O'Sullivan <bryano@fb.com>
parents:
16437
diff
changeset
|
1905 |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1906 self->inlined = inlined_obj && PyObject_IsTrue(inlined_obj); |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1907 self->data = data_obj; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1908 |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1909 self->ntlength = self->ntcapacity = 0; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1910 self->ntdepth = self->ntsplits = 0; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1911 self->ntlookups = self->ntmisses = 0; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1912 self->ntrev = -1; |
16597
b767382a8675
parsers: fix refcount bug on corrupt index
Matt Mackall <mpm@selenic.com>
parents:
16572
diff
changeset
|
1913 Py_INCREF(self->data); |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
1914 |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1915 if (self->inlined) { |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1916 long len = inline_scan(self, NULL); |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1917 if (len == -1) |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1918 goto bail; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1919 self->raw_length = len; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1920 self->length = len + 1; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1921 } else { |
16863
bbedef66c6f3
parsers: replace magic number 64 with symbolic constant
Bryan O'Sullivan <bryano@fb.com>
parents:
16787
diff
changeset
|
1922 if (size % v1_hdrsize) { |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1923 PyErr_SetString(PyExc_ValueError, "corrupt index file"); |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1924 goto bail; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1925 } |
16863
bbedef66c6f3
parsers: replace magic number 64 with symbolic constant
Bryan O'Sullivan <bryano@fb.com>
parents:
16787
diff
changeset
|
1926 self->raw_length = size / v1_hdrsize; |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1927 self->length = self->raw_length + 1; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1928 } |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1929 |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1930 return 0; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1931 bail: |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1932 return -1; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1933 } |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1934 |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1935 static PyObject *index_nodemap(indexObject *self) |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1936 { |
16572
8d44b5a2974f
parsers: fix refcount leak, simplify init of index (issue3417)
Bryan O'Sullivan <bryano@fb.com>
parents:
16437
diff
changeset
|
1937 Py_INCREF(self); |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1938 return (PyObject *)self; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1939 } |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1940 |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1941 static void index_dealloc(indexObject *self) |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1942 { |
16370
28bb4daf070c
parsers: fix a memleak, and add a clearcaches method to the index
Bryan O'Sullivan <bryano@fb.com>
parents:
16363
diff
changeset
|
1943 _index_clearcaches(self); |
20109
e57c532c3835
parse_index2: fix crash on bad argument type (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
19728
diff
changeset
|
1944 Py_XDECREF(self->data); |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1945 Py_XDECREF(self->added); |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1946 PyObject_Del(self); |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1947 } |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1948 |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1949 static PySequenceMethods index_sequence_methods = { |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1950 (lenfunc)index_length, /* sq_length */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1951 0, /* sq_concat */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1952 0, /* sq_repeat */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1953 (ssizeargfunc)index_get, /* sq_item */ |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1954 0, /* sq_slice */ |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1955 0, /* sq_ass_item */ |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1956 0, /* sq_ass_slice */ |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1957 (objobjproc)index_contains, /* sq_contains */ |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1958 }; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1959 |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1960 static PyMappingMethods index_mapping_methods = { |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1961 (lenfunc)index_length, /* mp_length */ |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1962 (binaryfunc)index_getitem, /* mp_subscript */ |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1963 (objobjargproc)index_assign_subscript, /* mp_ass_subscript */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1964 }; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1965 |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1966 static PyMethodDef index_methods[] = { |
18988
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1967 {"ancestors", (PyCFunction)index_ancestors, METH_VARARGS, |
5bae936764bb
parsers: a C implementation of the new ancestors algorithm
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
1968 "return the gca set of the given revs"}, |
21102
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1969 {"commonancestorsheads", (PyCFunction)index_commonancestorsheads, |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1970 METH_VARARGS, |
4eb6553789e1
parsers: introduce index_commonancestorsheads
Mads Kiilerich <madski@unity3d.com>
parents:
20797
diff
changeset
|
1971 "return the heads of the common ancestors of the given revs"}, |
16370
28bb4daf070c
parsers: fix a memleak, and add a clearcaches method to the index
Bryan O'Sullivan <bryano@fb.com>
parents:
16363
diff
changeset
|
1972 {"clearcaches", (PyCFunction)index_clearcaches, METH_NOARGS, |
28bb4daf070c
parsers: fix a memleak, and add a clearcaches method to the index
Bryan O'Sullivan <bryano@fb.com>
parents:
16363
diff
changeset
|
1973 "clear the index caches"}, |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1974 {"get", (PyCFunction)index_m_get, METH_VARARGS, |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1975 "get an index entry"}, |
16786
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
1976 {"headrevs", (PyCFunction)index_headrevs, METH_NOARGS, |
2631cd5dd244
revlog: switch to a C version of headrevs
Bryan O'Sullivan <bryano@fb.com>
parents:
16784
diff
changeset
|
1977 "get head revisions"}, |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1978 {"insert", (PyCFunction)index_insert, METH_VARARGS, |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1979 "insert an index entry"}, |
16665
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1980 {"partialmatch", (PyCFunction)index_partialmatch, METH_VARARGS, |
e410be860393
revlog: speed up prefix matching against nodes
Bryan O'Sullivan <bryano@fb.com>
parents:
16664
diff
changeset
|
1981 "match a potentially ambiguous node ID"}, |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1982 {"stats", (PyCFunction)index_stats, METH_NOARGS, |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1983 "stats for the index"}, |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1984 {NULL} /* Sentinel */ |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1985 }; |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1986 |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1987 static PyGetSetDef index_getset[] = { |
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
1988 {"nodemap", (getter)index_nodemap, NULL, "nodemap", NULL}, |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1989 {NULL} /* Sentinel */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1990 }; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1991 |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1992 static PyTypeObject indexType = { |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1993 PyObject_HEAD_INIT(NULL) |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1994 0, /* ob_size */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1995 "parsers.index", /* tp_name */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1996 sizeof(indexObject), /* tp_basicsize */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1997 0, /* tp_itemsize */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1998 (destructor)index_dealloc, /* tp_dealloc */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1999 0, /* tp_print */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2000 0, /* tp_getattr */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2001 0, /* tp_setattr */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2002 0, /* tp_compare */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2003 0, /* tp_repr */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2004 0, /* tp_as_number */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2005 &index_sequence_methods, /* tp_as_sequence */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2006 &index_mapping_methods, /* tp_as_mapping */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2007 0, /* tp_hash */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2008 0, /* tp_call */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2009 0, /* tp_str */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2010 0, /* tp_getattro */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2011 0, /* tp_setattro */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2012 0, /* tp_as_buffer */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2013 Py_TPFLAGS_DEFAULT, /* tp_flags */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2014 "revlog index", /* tp_doc */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2015 0, /* tp_traverse */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2016 0, /* tp_clear */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2017 0, /* tp_richcompare */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2018 0, /* tp_weaklistoffset */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2019 0, /* tp_iter */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2020 0, /* tp_iternext */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2021 index_methods, /* tp_methods */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2022 0, /* tp_members */ |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
2023 index_getset, /* tp_getset */ |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2024 0, /* tp_base */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2025 0, /* tp_dict */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2026 0, /* tp_descr_get */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2027 0, /* tp_descr_set */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2028 0, /* tp_dictoffset */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2029 (initproc)index_init, /* tp_init */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2030 0, /* tp_alloc */ |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2031 }; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2032 |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2033 /* |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
2034 * returns a tuple of the form (index, index, cache) with elements as |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2035 * follows: |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
2036 * |
16414
e8d37b78acfb
parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents:
16393
diff
changeset
|
2037 * index: an index object that lazily parses RevlogNG records |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2038 * cache: if data is inlined, a tuple (index_file_content, 0), else None |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2039 * |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2040 * added complications are for backwards compatibility |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
2041 */ |
13254
5ef5eb1f3515
revlog: only build the nodemap on demand
Matt Mackall <mpm@selenic.com>
parents:
11361
diff
changeset
|
2042 static PyObject *parse_index2(PyObject *self, PyObject *args) |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
2043 { |
16572
8d44b5a2974f
parsers: fix refcount leak, simplify init of index (issue3417)
Bryan O'Sullivan <bryano@fb.com>
parents:
16437
diff
changeset
|
2044 PyObject *tuple = NULL, *cache = NULL; |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2045 indexObject *idx; |
16572
8d44b5a2974f
parsers: fix refcount leak, simplify init of index (issue3417)
Bryan O'Sullivan <bryano@fb.com>
parents:
16437
diff
changeset
|
2046 int ret; |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2047 |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2048 idx = PyObject_New(indexObject, &indexType); |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2049 if (idx == NULL) |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2050 goto bail; |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
2051 |
16572
8d44b5a2974f
parsers: fix refcount leak, simplify init of index (issue3417)
Bryan O'Sullivan <bryano@fb.com>
parents:
16437
diff
changeset
|
2052 ret = index_init(idx, args); |
8d44b5a2974f
parsers: fix refcount leak, simplify init of index (issue3417)
Bryan O'Sullivan <bryano@fb.com>
parents:
16437
diff
changeset
|
2053 if (ret == -1) |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2054 goto bail; |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
2055 |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2056 if (idx->inlined) { |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2057 cache = Py_BuildValue("iO", 0, idx->data); |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2058 if (cache == NULL) |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2059 goto bail; |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
2060 } else { |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
2061 cache = Py_None; |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2062 Py_INCREF(cache); |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
2063 } |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
2064 |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2065 tuple = Py_BuildValue("NN", idx, cache); |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2066 if (!tuple) |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2067 goto bail; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2068 return tuple; |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
2069 |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2070 bail: |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2071 Py_XDECREF(idx); |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
2072 Py_XDECREF(cache); |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2073 Py_XDECREF(tuple); |
7108
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
2074 return NULL; |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
2075 } |
1ca878d7b849
C implementation of revlog index parsing
Bernhard Leiner <bleiner@gmail.com>
parents:
7093
diff
changeset
|
2076 |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
2077 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
|
2078 |
17606
318fb32b980e
pathencode: new C module with fast encodedir() function
Adrian Buehlmann <adrian@cadifra.com>
parents:
17356
diff
changeset
|
2079 PyObject *encodedir(PyObject *self, PyObject *args); |
17616
9535a0dc41f2
store: implement fncache basic path encoding in C
Bryan O'Sullivan <bryano@fb.com>
parents:
17606
diff
changeset
|
2080 PyObject *pathencode(PyObject *self, PyObject *args); |
18430
0459c6555f69
store: implement lowerencode in C
Bryan O'Sullivan <bryano@fb.com>
parents:
17616
diff
changeset
|
2081 PyObject *lowerencode(PyObject *self, PyObject *args); |
17606
318fb32b980e
pathencode: new C module with fast encodedir() function
Adrian Buehlmann <adrian@cadifra.com>
parents:
17356
diff
changeset
|
2082 |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
2083 static PyMethodDef methods[] = { |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
2084 {"pack_dirstate", pack_dirstate, METH_VARARGS, "pack a dirstate\n"}, |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
2085 {"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
|
2086 {"parse_dirstate", parse_dirstate, METH_VARARGS, "parse a dirstate\n"}, |
13254
5ef5eb1f3515
revlog: only build the nodemap on demand
Matt Mackall <mpm@selenic.com>
parents:
11361
diff
changeset
|
2087 {"parse_index2", parse_index2, METH_VARARGS, "parse a revlog index\n"}, |
17606
318fb32b980e
pathencode: new C module with fast encodedir() function
Adrian Buehlmann <adrian@cadifra.com>
parents:
17356
diff
changeset
|
2088 {"encodedir", encodedir, METH_VARARGS, "encodedir a path\n"}, |
17616
9535a0dc41f2
store: implement fncache basic path encoding in C
Bryan O'Sullivan <bryano@fb.com>
parents:
17606
diff
changeset
|
2089 {"pathencode", pathencode, METH_VARARGS, "fncache-encode a path\n"}, |
18430
0459c6555f69
store: implement lowerencode in C
Bryan O'Sullivan <bryano@fb.com>
parents:
17616
diff
changeset
|
2090 {"lowerencode", lowerencode, METH_VARARGS, "lower-encode a path\n"}, |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
2091 {NULL, NULL} |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
2092 }; |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
2093 |
18900
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
18567
diff
changeset
|
2094 void dirs_module_init(PyObject *mod); |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
18567
diff
changeset
|
2095 |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2096 static void module_init(PyObject *mod) |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2097 { |
20742
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
2098 /* This module constant has two purposes. First, it lets us unit test |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
2099 * the ImportError raised without hard-coding any error text. This |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
2100 * means we can change the text in the future without breaking tests, |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
2101 * even across changesets without a recompile. Second, its presence |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
2102 * can be used to determine whether the version-checking logic is |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
2103 * present, which also helps in testing across changesets without a |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
2104 * recompile. Note that this means the pure-Python version of parsers |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
2105 * should not have this module constant. */ |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
2106 PyModule_AddStringConstant(mod, "versionerrortext", versionerrortext); |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
2107 |
18900
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
18567
diff
changeset
|
2108 dirs_module_init(mod); |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
18567
diff
changeset
|
2109 |
16604
48e42f984074
parsers: statically initializing tp_new to PyType_GenericNew is not portable
Adrian Buehlmann <adrian@cadifra.com>
parents:
16597
diff
changeset
|
2110 indexType.tp_new = PyType_GenericNew; |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
2111 if (PyType_Ready(&indexType) < 0 || |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
2112 PyType_Ready(&dirstateTupleType) < 0) |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2113 return; |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2114 Py_INCREF(&indexType); |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2115 PyModule_AddObject(mod, "index", (PyObject *)&indexType); |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
2116 Py_INCREF(&dirstateTupleType); |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
2117 PyModule_AddObject(mod, "dirstatetuple", |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
2118 (PyObject *)&dirstateTupleType); |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2119 |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2120 nullentry = Py_BuildValue("iiiiiiis#", 0, 0, 0, |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2121 -1, -1, -1, -1, nullid, 20); |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2122 if (nullentry) |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2123 PyObject_GC_UnTrack(nullentry); |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2124 } |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2125 |
20742
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
2126 static int check_python_version(void) |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
2127 { |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
2128 PyObject *sys = PyImport_ImportModule("sys"); |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
2129 long hexversion = PyInt_AsLong(PyObject_GetAttrString(sys, "hexversion")); |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
2130 /* sys.hexversion is a 32-bit number by default, so the -1 case |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
2131 * should only occur in unusual circumstances (e.g. if sys.hexversion |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
2132 * is manually set to an invalid value). */ |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
2133 if ((hexversion == -1) || (hexversion >> 16 != PY_VERSION_HEX >> 16)) { |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
2134 PyErr_Format(PyExc_ImportError, "%s: The Mercurial extension " |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
2135 "modules were compiled with Python " PY_VERSION ", but " |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
2136 "Mercurial is currently using Python with sys.hexversion=%ld: " |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
2137 "Python %s\n at: %s", versionerrortext, hexversion, |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
2138 Py_GetVersion(), Py_GetProgramFullPath()); |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
2139 return -1; |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
2140 } |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
2141 return 0; |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
2142 } |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
2143 |
11361
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
2144 #ifdef IS_PY3K |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
2145 static struct PyModuleDef parsers_module = { |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
2146 PyModuleDef_HEAD_INIT, |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
2147 "parsers", |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
2148 parsers_doc, |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
2149 -1, |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
2150 methods |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
2151 }; |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
2152 |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
2153 PyMODINIT_FUNC PyInit_parsers(void) |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
2154 { |
20797
e286ab22e461
parsers: fix compiler errors on MSVC 2008
Matt Harbison <matt_harbison@yahoo.com>
parents:
20742
diff
changeset
|
2155 PyObject *mod; |
e286ab22e461
parsers: fix compiler errors on MSVC 2008
Matt Harbison <matt_harbison@yahoo.com>
parents:
20742
diff
changeset
|
2156 |
20742
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
2157 if (check_python_version() == -1) |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
2158 return; |
20797
e286ab22e461
parsers: fix compiler errors on MSVC 2008
Matt Harbison <matt_harbison@yahoo.com>
parents:
20742
diff
changeset
|
2159 mod = PyModule_Create(&parsers_module); |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2160 module_init(mod); |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2161 return mod; |
11361
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
2162 } |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
2163 #else |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
2164 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
|
2165 { |
20797
e286ab22e461
parsers: fix compiler errors on MSVC 2008
Matt Harbison <matt_harbison@yahoo.com>
parents:
20742
diff
changeset
|
2166 PyObject *mod; |
e286ab22e461
parsers: fix compiler errors on MSVC 2008
Matt Harbison <matt_harbison@yahoo.com>
parents:
20742
diff
changeset
|
2167 |
20742
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
2168 if (check_python_version() == -1) |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
2169 return; |
20797
e286ab22e461
parsers: fix compiler errors on MSVC 2008
Matt Harbison <matt_harbison@yahoo.com>
parents:
20742
diff
changeset
|
2170 mod = Py_InitModule3("parsers", methods, parsers_doc); |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
2171 module_init(mod); |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
2172 } |
11361
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
2173 #endif |