Mercurial > hg
annotate mercurial/cext/parsers.c @ 47602:8f0c3533e28c
revert: use `set_untracked` when performing a revert
This is the new shiny API.
Differential Revision: https://phab.mercurial-scm.org/D11022
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Thu, 08 Jul 2021 04:47:36 +0200 |
parents | 84391ddf4c78 |
children | a4443f66be6a |
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 |
46819
d4ba4d51f85f
contributor: change mentions of mpm to olivia
Raphaël Gomès <rgomes@octobus.net>
parents:
46708
diff
changeset
|
4 Copyright 2008 Olivia Mackall <olivia@selenic.com> and others |
6389
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 |
42068
896b19d12c08
cext: make parsers.c PY_SSIZE_T_CLEAN
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41336
diff
changeset
|
10 #define PY_SSIZE_T_CLEAN |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
11 #include <Python.h> |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
12 #include <ctype.h> |
17356
511dfb34b412
parsers: fix an integer size warning issued by clang
Bryan O'Sullivan <bryano@fb.com>
parents:
17353
diff
changeset
|
13 #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
|
14 #include <string.h> |
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
15 |
34438
b90e8da190da
cext: reorder #include
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33926
diff
changeset
|
16 #include "bitmanipulation.h" |
33758
0f4ac3b6dee4
cext: factor out header for charencode.c
Yuya Nishihara <yuya@tcha.org>
parents:
33757
diff
changeset
|
17 #include "charencode.h" |
11361
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
18 #include "util.h" |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
19 |
30112
9b6ff0f940ed
parsers: move PyInt aliasing out of util.h
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30103
diff
changeset
|
20 #ifdef IS_PY3K |
9b6ff0f940ed
parsers: move PyInt aliasing out of util.h
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30103
diff
changeset
|
21 /* The mapping of Python types is meant to be temporary to get Python |
9b6ff0f940ed
parsers: move PyInt aliasing out of util.h
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30103
diff
changeset
|
22 * 3 to compile. We should remove this once Python 3 support is fully |
9b6ff0f940ed
parsers: move PyInt aliasing out of util.h
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30103
diff
changeset
|
23 * supported and proper types are used in the extensions themselves. */ |
30169
5f7151e6de85
parsers: alias more PyInt* symbols on Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30112
diff
changeset
|
24 #define PyInt_Check PyLong_Check |
30112
9b6ff0f940ed
parsers: move PyInt aliasing out of util.h
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30103
diff
changeset
|
25 #define PyInt_FromLong PyLong_FromLong |
30169
5f7151e6de85
parsers: alias more PyInt* symbols on Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30112
diff
changeset
|
26 #define PyInt_FromSsize_t PyLong_FromSsize_t |
30112
9b6ff0f940ed
parsers: move PyInt aliasing out of util.h
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30103
diff
changeset
|
27 #define PyInt_AsLong PyLong_AsLong |
9b6ff0f940ed
parsers: move PyInt aliasing out of util.h
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30103
diff
changeset
|
28 #endif |
9b6ff0f940ed
parsers: move PyInt aliasing out of util.h
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30103
diff
changeset
|
29 |
32386
7640584e697c
cext: mark constant variables
Yuya Nishihara <yuya@tcha.org>
parents:
32384
diff
changeset
|
30 static const char *const versionerrortext = "Python minor version mismatch"; |
20742
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
31 |
47514
559aee84b889
dirstate-entry: add a `from_p2` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47513
diff
changeset
|
32 static const int dirstate_v1_from_p2 = -2; |
47516
b8ffe85e399b
dirstate-entry: `merged_removed` and `from_p2_removed` properties
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47515
diff
changeset
|
33 static const int dirstate_v1_nonnormal = -1; |
47514
559aee84b889
dirstate-entry: add a `from_p2` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47513
diff
changeset
|
34 |
25584
72b2711f12ea
parsers: add an API to create a new presized dict
Siddharth Agarwal <sid0@fb.com>
parents:
25583
diff
changeset
|
35 static PyObject *dict_new_presized(PyObject *self, PyObject *args) |
72b2711f12ea
parsers: add an API to create a new presized dict
Siddharth Agarwal <sid0@fb.com>
parents:
25583
diff
changeset
|
36 { |
72b2711f12ea
parsers: add an API to create a new presized dict
Siddharth Agarwal <sid0@fb.com>
parents:
25583
diff
changeset
|
37 Py_ssize_t expected_size; |
72b2711f12ea
parsers: add an API to create a new presized dict
Siddharth Agarwal <sid0@fb.com>
parents:
25583
diff
changeset
|
38 |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
39 if (!PyArg_ParseTuple(args, "n:make_presized_dict", &expected_size)) { |
25584
72b2711f12ea
parsers: add an API to create a new presized dict
Siddharth Agarwal <sid0@fb.com>
parents:
25583
diff
changeset
|
40 return NULL; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
41 } |
25584
72b2711f12ea
parsers: add an API to create a new presized dict
Siddharth Agarwal <sid0@fb.com>
parents:
25583
diff
changeset
|
42 |
72b2711f12ea
parsers: add an API to create a new presized dict
Siddharth Agarwal <sid0@fb.com>
parents:
25583
diff
changeset
|
43 return _dict_new_presized(expected_size); |
72b2711f12ea
parsers: add an API to create a new presized dict
Siddharth Agarwal <sid0@fb.com>
parents:
25583
diff
changeset
|
44 } |
72b2711f12ea
parsers: add an API to create a new presized dict
Siddharth Agarwal <sid0@fb.com>
parents:
25583
diff
changeset
|
45 |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
46 static inline dirstateItemObject *make_dirstate_item(char state, int mode, |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
47 int size, int mtime) |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
48 { |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
49 dirstateItemObject *t = |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
50 PyObject_New(dirstateItemObject, &dirstateItemType); |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
51 if (!t) { |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
52 return NULL; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
53 } |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
54 t->state = state; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
55 t->mode = mode; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
56 t->size = size; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
57 t->mtime = mtime; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
58 return t; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
59 } |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
60 |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
61 static PyObject *dirstate_item_new(PyTypeObject *subtype, PyObject *args, |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
62 PyObject *kwds) |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
63 { |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
64 /* We do all the initialization here and not a tp_init function because |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
65 * dirstate_item is immutable. */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
66 dirstateItemObject *t; |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
67 char state; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
68 int size, mode, mtime; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
69 if (!PyArg_ParseTuple(args, "ciii", &state, &mode, &size, &mtime)) { |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
70 return NULL; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
71 } |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
72 |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
73 t = (dirstateItemObject *)subtype->tp_alloc(subtype, 1); |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
74 if (!t) { |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
75 return NULL; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
76 } |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
77 t->state = state; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
78 t->mode = mode; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
79 t->size = size; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
80 t->mtime = mtime; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
81 |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
82 return (PyObject *)t; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
83 } |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
84 |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
85 static void dirstate_item_dealloc(PyObject *o) |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
86 { |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
87 PyObject_Del(o); |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
88 } |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
89 |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
90 static Py_ssize_t dirstate_item_length(PyObject *o) |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
91 { |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
92 return 4; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
93 } |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
94 |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
95 static PyObject *dirstate_item_item(PyObject *o, Py_ssize_t i) |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
96 { |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
97 dirstateItemObject *t = (dirstateItemObject *)o; |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
98 switch (i) { |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
99 case 0: |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
100 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
|
101 case 1: |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
102 return PyInt_FromLong(t->mode); |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
103 case 2: |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
104 return PyInt_FromLong(t->size); |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
105 case 3: |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
106 return PyInt_FromLong(t->mtime); |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
107 default: |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
108 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
|
109 return NULL; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
110 } |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
111 } |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
112 |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
113 static PySequenceMethods dirstate_item_sq = { |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
114 dirstate_item_length, /* sq_length */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
115 0, /* sq_concat */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
116 0, /* sq_repeat */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
117 dirstate_item_item, /* sq_item */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
118 0, /* sq_ass_item */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
119 0, /* sq_contains */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
120 0, /* sq_inplace_concat */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
121 0 /* sq_inplace_repeat */ |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
122 }; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
123 |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
124 static PyObject *dirstate_item_v1_state(dirstateItemObject *self) |
47509
80dc1d452993
dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47268
diff
changeset
|
125 { |
80dc1d452993
dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47268
diff
changeset
|
126 return PyBytes_FromStringAndSize(&self->state, 1); |
80dc1d452993
dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47268
diff
changeset
|
127 }; |
80dc1d452993
dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47268
diff
changeset
|
128 |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
129 static PyObject *dirstate_item_v1_mode(dirstateItemObject *self) |
47509
80dc1d452993
dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47268
diff
changeset
|
130 { |
80dc1d452993
dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47268
diff
changeset
|
131 return PyInt_FromLong(self->mode); |
80dc1d452993
dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47268
diff
changeset
|
132 }; |
80dc1d452993
dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47268
diff
changeset
|
133 |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
134 static PyObject *dirstate_item_v1_size(dirstateItemObject *self) |
47509
80dc1d452993
dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47268
diff
changeset
|
135 { |
80dc1d452993
dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47268
diff
changeset
|
136 return PyInt_FromLong(self->size); |
80dc1d452993
dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47268
diff
changeset
|
137 }; |
80dc1d452993
dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47268
diff
changeset
|
138 |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
139 static PyObject *dirstate_item_v1_mtime(dirstateItemObject *self) |
47509
80dc1d452993
dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47268
diff
changeset
|
140 { |
80dc1d452993
dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47268
diff
changeset
|
141 return PyInt_FromLong(self->mtime); |
80dc1d452993
dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47268
diff
changeset
|
142 }; |
80dc1d452993
dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47268
diff
changeset
|
143 |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
144 static PyObject *dirstate_item_need_delay(dirstateItemObject *self, |
47532
ccbabaee5c36
dirstate-entry: add a `need_delay` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47531
diff
changeset
|
145 PyObject *value) |
ccbabaee5c36
dirstate-entry: add a `need_delay` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47531
diff
changeset
|
146 { |
ccbabaee5c36
dirstate-entry: add a `need_delay` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47531
diff
changeset
|
147 long now; |
ccbabaee5c36
dirstate-entry: add a `need_delay` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47531
diff
changeset
|
148 if (!pylong_to_long(value, &now)) { |
ccbabaee5c36
dirstate-entry: add a `need_delay` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47531
diff
changeset
|
149 return NULL; |
ccbabaee5c36
dirstate-entry: add a `need_delay` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47531
diff
changeset
|
150 } |
ccbabaee5c36
dirstate-entry: add a `need_delay` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47531
diff
changeset
|
151 if (self->state == 'n' && self->mtime == now) { |
ccbabaee5c36
dirstate-entry: add a `need_delay` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47531
diff
changeset
|
152 Py_RETURN_TRUE; |
ccbabaee5c36
dirstate-entry: add a `need_delay` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47531
diff
changeset
|
153 } else { |
ccbabaee5c36
dirstate-entry: add a `need_delay` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47531
diff
changeset
|
154 Py_RETURN_FALSE; |
ccbabaee5c36
dirstate-entry: add a `need_delay` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47531
diff
changeset
|
155 } |
ccbabaee5c36
dirstate-entry: add a `need_delay` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47531
diff
changeset
|
156 }; |
ccbabaee5c36
dirstate-entry: add a `need_delay` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47531
diff
changeset
|
157 |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
158 static PyMethodDef dirstate_item_methods[] = { |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
159 {"v1_state", (PyCFunction)dirstate_item_v1_state, METH_NOARGS, |
47509
80dc1d452993
dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47268
diff
changeset
|
160 "return a \"state\" suitable for v1 serialization"}, |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
161 {"v1_mode", (PyCFunction)dirstate_item_v1_mode, METH_NOARGS, |
47509
80dc1d452993
dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47268
diff
changeset
|
162 "return a \"mode\" suitable for v1 serialization"}, |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
163 {"v1_size", (PyCFunction)dirstate_item_v1_size, METH_NOARGS, |
47509
80dc1d452993
dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47268
diff
changeset
|
164 "return a \"size\" suitable for v1 serialization"}, |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
165 {"v1_mtime", (PyCFunction)dirstate_item_v1_mtime, METH_NOARGS, |
47509
80dc1d452993
dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47268
diff
changeset
|
166 "return a \"mtime\" suitable for v1 serialization"}, |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
167 {"need_delay", (PyCFunction)dirstate_item_need_delay, METH_O, |
47532
ccbabaee5c36
dirstate-entry: add a `need_delay` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47531
diff
changeset
|
168 "True if the stored mtime would be ambiguous with the current time"}, |
47509
80dc1d452993
dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47268
diff
changeset
|
169 {NULL} /* Sentinel */ |
80dc1d452993
dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47268
diff
changeset
|
170 }; |
80dc1d452993
dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47268
diff
changeset
|
171 |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
172 static PyObject *dirstate_item_get_mode(dirstateItemObject *self) |
47536
8e4b9fe31334
dirstate-entry: add a `mode` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47532
diff
changeset
|
173 { |
8e4b9fe31334
dirstate-entry: add a `mode` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47532
diff
changeset
|
174 return PyInt_FromLong(self->mode); |
8e4b9fe31334
dirstate-entry: add a `mode` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47532
diff
changeset
|
175 }; |
8e4b9fe31334
dirstate-entry: add a `mode` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47532
diff
changeset
|
176 |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
177 static PyObject *dirstate_item_get_size(dirstateItemObject *self) |
47537
0e5800c88eb4
dirstate-entry: add a `size` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47536
diff
changeset
|
178 { |
0e5800c88eb4
dirstate-entry: add a `size` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47536
diff
changeset
|
179 return PyInt_FromLong(self->size); |
0e5800c88eb4
dirstate-entry: add a `size` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47536
diff
changeset
|
180 }; |
0e5800c88eb4
dirstate-entry: add a `size` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47536
diff
changeset
|
181 |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
182 static PyObject *dirstate_item_get_mtime(dirstateItemObject *self) |
47538
77fce401a2bb
dirstate-entry: add a `mtime` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47537
diff
changeset
|
183 { |
77fce401a2bb
dirstate-entry: add a `mtime` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47537
diff
changeset
|
184 return PyInt_FromLong(self->mtime); |
77fce401a2bb
dirstate-entry: add a `mtime` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47537
diff
changeset
|
185 }; |
77fce401a2bb
dirstate-entry: add a `mtime` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47537
diff
changeset
|
186 |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
187 static PyObject *dirstate_item_get_state(dirstateItemObject *self) |
47512
769037a279ec
dirstate-entry: add a `state` property (and use it)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47509
diff
changeset
|
188 { |
769037a279ec
dirstate-entry: add a `state` property (and use it)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47509
diff
changeset
|
189 return PyBytes_FromStringAndSize(&self->state, 1); |
769037a279ec
dirstate-entry: add a `state` property (and use it)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47509
diff
changeset
|
190 }; |
769037a279ec
dirstate-entry: add a `state` property (and use it)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47509
diff
changeset
|
191 |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
192 static PyObject *dirstate_item_get_tracked(dirstateItemObject *self) |
47531
f5b8f0b9c129
dirstate-entry: add a `tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47526
diff
changeset
|
193 { |
f5b8f0b9c129
dirstate-entry: add a `tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47526
diff
changeset
|
194 if (self->state == 'a' || self->state == 'm' || self->state == 'n') { |
f5b8f0b9c129
dirstate-entry: add a `tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47526
diff
changeset
|
195 Py_RETURN_TRUE; |
f5b8f0b9c129
dirstate-entry: add a `tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47526
diff
changeset
|
196 } else { |
f5b8f0b9c129
dirstate-entry: add a `tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47526
diff
changeset
|
197 Py_RETURN_FALSE; |
f5b8f0b9c129
dirstate-entry: add a `tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47526
diff
changeset
|
198 } |
f5b8f0b9c129
dirstate-entry: add a `tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47526
diff
changeset
|
199 }; |
f5b8f0b9c129
dirstate-entry: add a `tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47526
diff
changeset
|
200 |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
201 static PyObject *dirstate_item_get_added(dirstateItemObject *self) |
47526
8bcae9bf9e8d
dirstate-entry: add a `added` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47517
diff
changeset
|
202 { |
8bcae9bf9e8d
dirstate-entry: add a `added` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47517
diff
changeset
|
203 if (self->state == 'a') { |
8bcae9bf9e8d
dirstate-entry: add a `added` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47517
diff
changeset
|
204 Py_RETURN_TRUE; |
8bcae9bf9e8d
dirstate-entry: add a `added` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47517
diff
changeset
|
205 } else { |
8bcae9bf9e8d
dirstate-entry: add a `added` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47517
diff
changeset
|
206 Py_RETURN_FALSE; |
8bcae9bf9e8d
dirstate-entry: add a `added` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47517
diff
changeset
|
207 } |
8bcae9bf9e8d
dirstate-entry: add a `added` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47517
diff
changeset
|
208 }; |
8bcae9bf9e8d
dirstate-entry: add a `added` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47517
diff
changeset
|
209 |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
210 static PyObject *dirstate_item_get_merged(dirstateItemObject *self) |
47513
10e740292dff
dirstate-entry: add a `merged` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47512
diff
changeset
|
211 { |
10e740292dff
dirstate-entry: add a `merged` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47512
diff
changeset
|
212 if (self->state == 'm') { |
10e740292dff
dirstate-entry: add a `merged` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47512
diff
changeset
|
213 Py_RETURN_TRUE; |
10e740292dff
dirstate-entry: add a `merged` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47512
diff
changeset
|
214 } else { |
10e740292dff
dirstate-entry: add a `merged` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47512
diff
changeset
|
215 Py_RETURN_FALSE; |
10e740292dff
dirstate-entry: add a `merged` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47512
diff
changeset
|
216 } |
10e740292dff
dirstate-entry: add a `merged` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47512
diff
changeset
|
217 }; |
10e740292dff
dirstate-entry: add a `merged` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47512
diff
changeset
|
218 |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
219 static PyObject *dirstate_item_get_merged_removed(dirstateItemObject *self) |
47516
b8ffe85e399b
dirstate-entry: `merged_removed` and `from_p2_removed` properties
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47515
diff
changeset
|
220 { |
b8ffe85e399b
dirstate-entry: `merged_removed` and `from_p2_removed` properties
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47515
diff
changeset
|
221 if (self->state == 'r' && self->size == dirstate_v1_nonnormal) { |
b8ffe85e399b
dirstate-entry: `merged_removed` and `from_p2_removed` properties
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47515
diff
changeset
|
222 Py_RETURN_TRUE; |
b8ffe85e399b
dirstate-entry: `merged_removed` and `from_p2_removed` properties
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47515
diff
changeset
|
223 } else { |
b8ffe85e399b
dirstate-entry: `merged_removed` and `from_p2_removed` properties
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47515
diff
changeset
|
224 Py_RETURN_FALSE; |
b8ffe85e399b
dirstate-entry: `merged_removed` and `from_p2_removed` properties
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47515
diff
changeset
|
225 } |
b8ffe85e399b
dirstate-entry: `merged_removed` and `from_p2_removed` properties
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47515
diff
changeset
|
226 }; |
b8ffe85e399b
dirstate-entry: `merged_removed` and `from_p2_removed` properties
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47515
diff
changeset
|
227 |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
228 static PyObject *dirstate_item_get_from_p2(dirstateItemObject *self) |
47514
559aee84b889
dirstate-entry: add a `from_p2` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47513
diff
changeset
|
229 { |
47517
28632eb3ca3e
dirstate-entry: restrict `from_p2` property to tracked file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47516
diff
changeset
|
230 if (self->state == 'n' && self->size == dirstate_v1_from_p2) { |
47514
559aee84b889
dirstate-entry: add a `from_p2` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47513
diff
changeset
|
231 Py_RETURN_TRUE; |
559aee84b889
dirstate-entry: add a `from_p2` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47513
diff
changeset
|
232 } else { |
559aee84b889
dirstate-entry: add a `from_p2` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47513
diff
changeset
|
233 Py_RETURN_FALSE; |
559aee84b889
dirstate-entry: add a `from_p2` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47513
diff
changeset
|
234 } |
559aee84b889
dirstate-entry: add a `from_p2` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47513
diff
changeset
|
235 }; |
559aee84b889
dirstate-entry: add a `from_p2` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47513
diff
changeset
|
236 |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
237 static PyObject *dirstate_item_get_from_p2_removed(dirstateItemObject *self) |
47516
b8ffe85e399b
dirstate-entry: `merged_removed` and `from_p2_removed` properties
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47515
diff
changeset
|
238 { |
b8ffe85e399b
dirstate-entry: `merged_removed` and `from_p2_removed` properties
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47515
diff
changeset
|
239 if (self->state == 'r' && self->size == dirstate_v1_from_p2) { |
b8ffe85e399b
dirstate-entry: `merged_removed` and `from_p2_removed` properties
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47515
diff
changeset
|
240 Py_RETURN_TRUE; |
b8ffe85e399b
dirstate-entry: `merged_removed` and `from_p2_removed` properties
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47515
diff
changeset
|
241 } else { |
b8ffe85e399b
dirstate-entry: `merged_removed` and `from_p2_removed` properties
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47515
diff
changeset
|
242 Py_RETURN_FALSE; |
b8ffe85e399b
dirstate-entry: `merged_removed` and `from_p2_removed` properties
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47515
diff
changeset
|
243 } |
b8ffe85e399b
dirstate-entry: `merged_removed` and `from_p2_removed` properties
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47515
diff
changeset
|
244 }; |
b8ffe85e399b
dirstate-entry: `merged_removed` and `from_p2_removed` properties
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47515
diff
changeset
|
245 |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
246 static PyObject *dirstate_item_get_removed(dirstateItemObject *self) |
47515
c94d3ff46fd5
dirstate-entry: add a `removed` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47514
diff
changeset
|
247 { |
c94d3ff46fd5
dirstate-entry: add a `removed` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47514
diff
changeset
|
248 if (self->state == 'r') { |
c94d3ff46fd5
dirstate-entry: add a `removed` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47514
diff
changeset
|
249 Py_RETURN_TRUE; |
c94d3ff46fd5
dirstate-entry: add a `removed` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47514
diff
changeset
|
250 } else { |
c94d3ff46fd5
dirstate-entry: add a `removed` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47514
diff
changeset
|
251 Py_RETURN_FALSE; |
c94d3ff46fd5
dirstate-entry: add a `removed` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47514
diff
changeset
|
252 } |
c94d3ff46fd5
dirstate-entry: add a `removed` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47514
diff
changeset
|
253 }; |
c94d3ff46fd5
dirstate-entry: add a `removed` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47514
diff
changeset
|
254 |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
255 static PyGetSetDef dirstate_item_getset[] = { |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
256 {"mode", (getter)dirstate_item_get_mode, NULL, "mode", NULL}, |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
257 {"size", (getter)dirstate_item_get_size, NULL, "size", NULL}, |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
258 {"mtime", (getter)dirstate_item_get_mtime, NULL, "mtime", NULL}, |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
259 {"state", (getter)dirstate_item_get_state, NULL, "state", NULL}, |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
260 {"tracked", (getter)dirstate_item_get_tracked, NULL, "tracked", NULL}, |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
261 {"added", (getter)dirstate_item_get_added, NULL, "added", NULL}, |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
262 {"merged_removed", (getter)dirstate_item_get_merged_removed, NULL, |
47516
b8ffe85e399b
dirstate-entry: `merged_removed` and `from_p2_removed` properties
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47515
diff
changeset
|
263 "merged_removed", NULL}, |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
264 {"merged", (getter)dirstate_item_get_merged, NULL, "merged", NULL}, |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
265 {"from_p2_removed", (getter)dirstate_item_get_from_p2_removed, NULL, |
47516
b8ffe85e399b
dirstate-entry: `merged_removed` and `from_p2_removed` properties
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47515
diff
changeset
|
266 "from_p2_removed", NULL}, |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
267 {"from_p2", (getter)dirstate_item_get_from_p2, NULL, "from_p2", NULL}, |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
268 {"removed", (getter)dirstate_item_get_removed, NULL, "removed", NULL}, |
47512
769037a279ec
dirstate-entry: add a `state` property (and use it)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47509
diff
changeset
|
269 {NULL} /* Sentinel */ |
769037a279ec
dirstate-entry: add a `state` property (and use it)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47509
diff
changeset
|
270 }; |
769037a279ec
dirstate-entry: add a `state` property (and use it)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47509
diff
changeset
|
271 |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
272 PyTypeObject dirstateItemType = { |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
273 PyVarObject_HEAD_INIT(NULL, 0) /* header */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
274 "dirstate_tuple", /* tp_name */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
275 sizeof(dirstateItemObject), /* tp_basicsize */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
276 0, /* tp_itemsize */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
277 (destructor)dirstate_item_dealloc, /* tp_dealloc */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
278 0, /* tp_print */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
279 0, /* tp_getattr */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
280 0, /* tp_setattr */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
281 0, /* tp_compare */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
282 0, /* tp_repr */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
283 0, /* tp_as_number */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
284 &dirstate_item_sq, /* tp_as_sequence */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
285 0, /* tp_as_mapping */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
286 0, /* tp_hash */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
287 0, /* tp_call */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
288 0, /* tp_str */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
289 0, /* tp_getattro */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
290 0, /* tp_setattro */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
291 0, /* tp_as_buffer */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
292 Py_TPFLAGS_DEFAULT, /* tp_flags */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
293 "dirstate tuple", /* tp_doc */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
294 0, /* tp_traverse */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
295 0, /* tp_clear */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
296 0, /* tp_richcompare */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
297 0, /* tp_weaklistoffset */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
298 0, /* tp_iter */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
299 0, /* tp_iternext */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
300 dirstate_item_methods, /* tp_methods */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
301 0, /* tp_members */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
302 dirstate_item_getset, /* tp_getset */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
303 0, /* tp_base */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
304 0, /* tp_dict */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
305 0, /* tp_descr_get */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
306 0, /* tp_descr_set */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
307 0, /* tp_dictoffset */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
308 0, /* tp_init */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
309 0, /* tp_alloc */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
310 dirstate_item_new, /* tp_new */ |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
311 }; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
312 |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
313 static PyObject *parse_dirstate(PyObject *self, PyObject *args) |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
314 { |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
315 PyObject *dmap, *cmap, *parents = NULL, *ret = NULL; |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
316 PyObject *fname = NULL, *cname = NULL, *entry = NULL; |
20167
09e41ac6289d
mpatch: rewrite pointer overflow checks
Matt Mackall <mpm@selenic.com>
parents:
20109
diff
changeset
|
317 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
|
318 int mode, size, mtime; |
42068
896b19d12c08
cext: make parsers.c PY_SSIZE_T_CLEAN
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41336
diff
changeset
|
319 unsigned int flen, pos = 40; |
896b19d12c08
cext: make parsers.c PY_SSIZE_T_CLEAN
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41336
diff
changeset
|
320 Py_ssize_t len = 40; |
896b19d12c08
cext: make parsers.c PY_SSIZE_T_CLEAN
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41336
diff
changeset
|
321 Py_ssize_t readlen; |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
322 |
36620
186c6df3a373
py3: bulk-replace 'const char*' format specifier passed to PyArg_ParseTuple*()
Yuya Nishihara <yuya@tcha.org>
parents:
36619
diff
changeset
|
323 if (!PyArg_ParseTuple( |
186c6df3a373
py3: bulk-replace 'const char*' format specifier passed to PyArg_ParseTuple*()
Yuya Nishihara <yuya@tcha.org>
parents:
36619
diff
changeset
|
324 args, PY23("O!O!s#:parse_dirstate", "O!O!y#:parse_dirstate"), |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
325 &PyDict_Type, &dmap, &PyDict_Type, &cmap, &str, &readlen)) { |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
326 goto quit; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
327 } |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
328 |
22403
41e9d58ec56f
parsers: avoid signed/unsigned comparison mismatch
Henrik Stuart <hg@hstuart.dk>
parents:
22402
diff
changeset
|
329 len = readlen; |
41e9d58ec56f
parsers: avoid signed/unsigned comparison mismatch
Henrik Stuart <hg@hstuart.dk>
parents:
22402
diff
changeset
|
330 |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
331 /* read parents */ |
26052
b970418bbafe
parsers: set exception when there's too little string data to extract parents
Augie Fackler <augie@google.com>
parents:
26051
diff
changeset
|
332 if (len < 40) { |
34862
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
333 PyErr_SetString(PyExc_ValueError, |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
334 "too little data for parents"); |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
335 goto quit; |
26052
b970418bbafe
parsers: set exception when there's too little string data to extract parents
Augie Fackler <augie@google.com>
parents:
26051
diff
changeset
|
336 } |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
337 |
42096
509a0477b3a6
cext: cast s# arguments of Py_BuildValue() to Py_ssize_t
Yuya Nishihara <yuya@tcha.org>
parents:
42068
diff
changeset
|
338 parents = Py_BuildValue(PY23("s#s#", "y#y#"), str, (Py_ssize_t)20, |
509a0477b3a6
cext: cast s# arguments of Py_BuildValue() to Py_ssize_t
Yuya Nishihara <yuya@tcha.org>
parents:
42068
diff
changeset
|
339 str + 20, (Py_ssize_t)20); |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
340 if (!parents) { |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
341 goto quit; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
342 } |
7093
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 /* read filenames */ |
20167
09e41ac6289d
mpatch: rewrite pointer overflow checks
Matt Mackall <mpm@selenic.com>
parents:
20109
diff
changeset
|
345 while (pos >= 40 && pos < len) { |
27226
f5e8cb813a4d
parsers: fix parse_dirstate to check len before unpacking header (issue4979)
Yuya Nishihara <yuya@tcha.org>
parents:
26872
diff
changeset
|
346 if (pos + 17 > len) { |
f5e8cb813a4d
parsers: fix parse_dirstate to check len before unpacking header (issue4979)
Yuya Nishihara <yuya@tcha.org>
parents:
26872
diff
changeset
|
347 PyErr_SetString(PyExc_ValueError, |
34862
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
348 "overflow in dirstate"); |
27226
f5e8cb813a4d
parsers: fix parse_dirstate to check len before unpacking header (issue4979)
Yuya Nishihara <yuya@tcha.org>
parents:
26872
diff
changeset
|
349 goto quit; |
f5e8cb813a4d
parsers: fix parse_dirstate to check len before unpacking header (issue4979)
Yuya Nishihara <yuya@tcha.org>
parents:
26872
diff
changeset
|
350 } |
20167
09e41ac6289d
mpatch: rewrite pointer overflow checks
Matt Mackall <mpm@selenic.com>
parents:
20109
diff
changeset
|
351 cur = str + pos; |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
352 /* unpack header */ |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
353 state = *cur; |
16437
d126a0d16856
util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents:
16414
diff
changeset
|
354 mode = getbe32(cur + 1); |
d126a0d16856
util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents:
16414
diff
changeset
|
355 size = getbe32(cur + 5); |
d126a0d16856
util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents:
16414
diff
changeset
|
356 mtime = getbe32(cur + 9); |
d126a0d16856
util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents:
16414
diff
changeset
|
357 flen = getbe32(cur + 13); |
20167
09e41ac6289d
mpatch: rewrite pointer overflow checks
Matt Mackall <mpm@selenic.com>
parents:
20109
diff
changeset
|
358 pos += 17; |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
359 cur += 17; |
20316
40f08c31844c
parsers: fix 'unsigned expression is always true' warning (issue4142)
David Soria Parra <davidsp@fb.com>
parents:
20169
diff
changeset
|
360 if (flen > len - pos) { |
34862
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
361 PyErr_SetString(PyExc_ValueError, |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
362 "overflow in dirstate"); |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
363 goto quit; |
7174
4da87407b845
parsers.c: fix integer overflows
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7168
diff
changeset
|
364 } |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
365 |
34862
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
366 entry = |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
367 (PyObject *)make_dirstate_item(state, mode, size, mtime); |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
368 cpos = memchr(cur, 0, flen); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
369 if (cpos) { |
11361
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
370 fname = PyBytes_FromStringAndSize(cur, cpos - cur); |
34862
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
371 cname = PyBytes_FromStringAndSize( |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
372 cpos + 1, flen - (cpos - cur) - 1); |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
373 if (!fname || !cname || |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
374 PyDict_SetItem(cmap, fname, cname) == -1 || |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
375 PyDict_SetItem(dmap, fname, entry) == -1) { |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
376 goto quit; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
377 } |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
378 Py_DECREF(cname); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
379 } else { |
11361
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
380 fname = PyBytes_FromStringAndSize(cur, flen); |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
381 if (!fname || |
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
382 PyDict_SetItem(dmap, fname, entry) == -1) { |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
383 goto quit; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
384 } |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
385 } |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
386 Py_DECREF(fname); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
387 Py_DECREF(entry); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
388 fname = cname = entry = NULL; |
20167
09e41ac6289d
mpatch: rewrite pointer overflow checks
Matt Mackall <mpm@selenic.com>
parents:
20109
diff
changeset
|
389 pos += flen; |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
390 } |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
391 |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
392 ret = parents; |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
393 Py_INCREF(ret); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
394 quit: |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
395 Py_XDECREF(fname); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
396 Py_XDECREF(cname); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
397 Py_XDECREF(entry); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
398 Py_XDECREF(parents); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
399 return ret; |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
400 } |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
401 |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
402 /* |
31278
1c97a91a18dc
dirstate: track otherparent files same as nonnormal
Durham Goode <durham@fb.com>
parents:
30577
diff
changeset
|
403 * Build a set of non-normal and other parent entries from the dirstate dmap |
34862
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
404 */ |
34440
7ed0750c71a1
cext: wrap before brace for functions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34438
diff
changeset
|
405 static PyObject *nonnormalotherparententries(PyObject *self, PyObject *args) |
7ed0750c71a1
cext: wrap before brace for functions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34438
diff
changeset
|
406 { |
31278
1c97a91a18dc
dirstate: track otherparent files same as nonnormal
Durham Goode <durham@fb.com>
parents:
30577
diff
changeset
|
407 PyObject *dmap, *fname, *v; |
1c97a91a18dc
dirstate: track otherparent files same as nonnormal
Durham Goode <durham@fb.com>
parents:
30577
diff
changeset
|
408 PyObject *nonnset = NULL, *otherpset = NULL, *result = NULL; |
27592
7c9eb2927879
dirstate: add a C implementation for nonnormalentries
Laurent Charignon <lcharignon@fb.com>
parents:
27410
diff
changeset
|
409 Py_ssize_t pos; |
7c9eb2927879
dirstate: add a C implementation for nonnormalentries
Laurent Charignon <lcharignon@fb.com>
parents:
27410
diff
changeset
|
410 |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
411 if (!PyArg_ParseTuple(args, "O!:nonnormalentries", &PyDict_Type, |
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
412 &dmap)) { |
27592
7c9eb2927879
dirstate: add a C implementation for nonnormalentries
Laurent Charignon <lcharignon@fb.com>
parents:
27410
diff
changeset
|
413 goto bail; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
414 } |
27592
7c9eb2927879
dirstate: add a C implementation for nonnormalentries
Laurent Charignon <lcharignon@fb.com>
parents:
27410
diff
changeset
|
415 |
7c9eb2927879
dirstate: add a C implementation for nonnormalentries
Laurent Charignon <lcharignon@fb.com>
parents:
27410
diff
changeset
|
416 nonnset = PySet_New(NULL); |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
417 if (nonnset == NULL) { |
27592
7c9eb2927879
dirstate: add a C implementation for nonnormalentries
Laurent Charignon <lcharignon@fb.com>
parents:
27410
diff
changeset
|
418 goto bail; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
419 } |
27592
7c9eb2927879
dirstate: add a C implementation for nonnormalentries
Laurent Charignon <lcharignon@fb.com>
parents:
27410
diff
changeset
|
420 |
31278
1c97a91a18dc
dirstate: track otherparent files same as nonnormal
Durham Goode <durham@fb.com>
parents:
30577
diff
changeset
|
421 otherpset = PySet_New(NULL); |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
422 if (otherpset == NULL) { |
31278
1c97a91a18dc
dirstate: track otherparent files same as nonnormal
Durham Goode <durham@fb.com>
parents:
30577
diff
changeset
|
423 goto bail; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
424 } |
31278
1c97a91a18dc
dirstate: track otherparent files same as nonnormal
Durham Goode <durham@fb.com>
parents:
30577
diff
changeset
|
425 |
27592
7c9eb2927879
dirstate: add a C implementation for nonnormalentries
Laurent Charignon <lcharignon@fb.com>
parents:
27410
diff
changeset
|
426 pos = 0; |
7c9eb2927879
dirstate: add a C implementation for nonnormalentries
Laurent Charignon <lcharignon@fb.com>
parents:
27410
diff
changeset
|
427 while (PyDict_Next(dmap, &pos, &fname, &v)) { |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
428 dirstateItemObject *t; |
27592
7c9eb2927879
dirstate: add a C implementation for nonnormalentries
Laurent Charignon <lcharignon@fb.com>
parents:
27410
diff
changeset
|
429 if (!dirstate_tuple_check(v)) { |
7c9eb2927879
dirstate: add a C implementation for nonnormalentries
Laurent Charignon <lcharignon@fb.com>
parents:
27410
diff
changeset
|
430 PyErr_SetString(PyExc_TypeError, |
34862
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
431 "expected a dirstate tuple"); |
27592
7c9eb2927879
dirstate: add a C implementation for nonnormalentries
Laurent Charignon <lcharignon@fb.com>
parents:
27410
diff
changeset
|
432 goto bail; |
7c9eb2927879
dirstate: add a C implementation for nonnormalentries
Laurent Charignon <lcharignon@fb.com>
parents:
27410
diff
changeset
|
433 } |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
434 t = (dirstateItemObject *)v; |
27592
7c9eb2927879
dirstate: add a C implementation for nonnormalentries
Laurent Charignon <lcharignon@fb.com>
parents:
27410
diff
changeset
|
435 |
31278
1c97a91a18dc
dirstate: track otherparent files same as nonnormal
Durham Goode <durham@fb.com>
parents:
30577
diff
changeset
|
436 if (t->state == 'n' && t->size == -2) { |
1c97a91a18dc
dirstate: track otherparent files same as nonnormal
Durham Goode <durham@fb.com>
parents:
30577
diff
changeset
|
437 if (PySet_Add(otherpset, fname) == -1) { |
1c97a91a18dc
dirstate: track otherparent files same as nonnormal
Durham Goode <durham@fb.com>
parents:
30577
diff
changeset
|
438 goto bail; |
1c97a91a18dc
dirstate: track otherparent files same as nonnormal
Durham Goode <durham@fb.com>
parents:
30577
diff
changeset
|
439 } |
1c97a91a18dc
dirstate: track otherparent files same as nonnormal
Durham Goode <durham@fb.com>
parents:
30577
diff
changeset
|
440 } |
1c97a91a18dc
dirstate: track otherparent files same as nonnormal
Durham Goode <durham@fb.com>
parents:
30577
diff
changeset
|
441 |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
442 if (t->state == 'n' && t->mtime != -1) { |
27592
7c9eb2927879
dirstate: add a C implementation for nonnormalentries
Laurent Charignon <lcharignon@fb.com>
parents:
27410
diff
changeset
|
443 continue; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
444 } |
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
445 if (PySet_Add(nonnset, fname) == -1) { |
27592
7c9eb2927879
dirstate: add a C implementation for nonnormalentries
Laurent Charignon <lcharignon@fb.com>
parents:
27410
diff
changeset
|
446 goto bail; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
447 } |
27592
7c9eb2927879
dirstate: add a C implementation for nonnormalentries
Laurent Charignon <lcharignon@fb.com>
parents:
27410
diff
changeset
|
448 } |
7c9eb2927879
dirstate: add a C implementation for nonnormalentries
Laurent Charignon <lcharignon@fb.com>
parents:
27410
diff
changeset
|
449 |
31278
1c97a91a18dc
dirstate: track otherparent files same as nonnormal
Durham Goode <durham@fb.com>
parents:
30577
diff
changeset
|
450 result = Py_BuildValue("(OO)", nonnset, otherpset); |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
451 if (result == NULL) { |
31278
1c97a91a18dc
dirstate: track otherparent files same as nonnormal
Durham Goode <durham@fb.com>
parents:
30577
diff
changeset
|
452 goto bail; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
453 } |
31291
fffd1abb1337
parsers: avoid leak of nonnset and otherpset
Augie Fackler <augie@google.com>
parents:
31278
diff
changeset
|
454 Py_DECREF(nonnset); |
fffd1abb1337
parsers: avoid leak of nonnset and otherpset
Augie Fackler <augie@google.com>
parents:
31278
diff
changeset
|
455 Py_DECREF(otherpset); |
31278
1c97a91a18dc
dirstate: track otherparent files same as nonnormal
Durham Goode <durham@fb.com>
parents:
30577
diff
changeset
|
456 return result; |
27592
7c9eb2927879
dirstate: add a C implementation for nonnormalentries
Laurent Charignon <lcharignon@fb.com>
parents:
27410
diff
changeset
|
457 bail: |
7c9eb2927879
dirstate: add a C implementation for nonnormalentries
Laurent Charignon <lcharignon@fb.com>
parents:
27410
diff
changeset
|
458 Py_XDECREF(nonnset); |
31278
1c97a91a18dc
dirstate: track otherparent files same as nonnormal
Durham Goode <durham@fb.com>
parents:
30577
diff
changeset
|
459 Py_XDECREF(otherpset); |
1c97a91a18dc
dirstate: track otherparent files same as nonnormal
Durham Goode <durham@fb.com>
parents:
30577
diff
changeset
|
460 Py_XDECREF(result); |
27592
7c9eb2927879
dirstate: add a C implementation for nonnormalentries
Laurent Charignon <lcharignon@fb.com>
parents:
27410
diff
changeset
|
461 return NULL; |
7c9eb2927879
dirstate: add a C implementation for nonnormalentries
Laurent Charignon <lcharignon@fb.com>
parents:
27410
diff
changeset
|
462 } |
7c9eb2927879
dirstate: add a C implementation for nonnormalentries
Laurent Charignon <lcharignon@fb.com>
parents:
27410
diff
changeset
|
463 |
7c9eb2927879
dirstate: add a C implementation for nonnormalentries
Laurent Charignon <lcharignon@fb.com>
parents:
27410
diff
changeset
|
464 /* |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
465 * 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
|
466 */ |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
467 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
|
468 { |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
469 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
|
470 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
|
471 Py_ssize_t nbytes, pos, l; |
23946
f3e94aa6e182
parsers: don't leak a tuple in pack_dirstate
Augie Fackler <augie@google.com>
parents:
23945
diff
changeset
|
472 PyObject *k, *v = NULL, *pn; |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
473 char *p, *s; |
26630
3111b45a2bbf
parsers: make pack_dirstate take now in integer for consistency
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26591
diff
changeset
|
474 int now; |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
475 |
39422
adacefb0b7ea
dirstate: use tuple interface to fix leak in pack_dirstate()
Yuya Nishihara <yuya@tcha.org>
parents:
37968
diff
changeset
|
476 if (!PyArg_ParseTuple(args, "O!O!O!i:pack_dirstate", &PyDict_Type, &map, |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
477 &PyDict_Type, ©map, &PyTuple_Type, &pl, |
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
478 &now)) { |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
479 return NULL; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
480 } |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
481 |
39422
adacefb0b7ea
dirstate: use tuple interface to fix leak in pack_dirstate()
Yuya Nishihara <yuya@tcha.org>
parents:
37968
diff
changeset
|
482 if (PyTuple_Size(pl) != 2) { |
adacefb0b7ea
dirstate: use tuple interface to fix leak in pack_dirstate()
Yuya Nishihara <yuya@tcha.org>
parents:
37968
diff
changeset
|
483 PyErr_SetString(PyExc_TypeError, "expected 2-element tuple"); |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
484 return NULL; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
485 } |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
486 |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
487 /* 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
|
488 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
|
489 PyObject *c; |
30100
c5afe5531709
parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30090
diff
changeset
|
490 if (!PyBytes_Check(k)) { |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
491 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
|
492 goto bail; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
493 } |
30100
c5afe5531709
parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30090
diff
changeset
|
494 nbytes += PyBytes_GET_SIZE(k) + 17; |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
495 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
|
496 if (c) { |
30100
c5afe5531709
parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30090
diff
changeset
|
497 if (!PyBytes_Check(c)) { |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
498 PyErr_SetString(PyExc_TypeError, |
34862
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
499 "expected string key"); |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
500 goto bail; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
501 } |
30100
c5afe5531709
parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30090
diff
changeset
|
502 nbytes += PyBytes_GET_SIZE(c) + 1; |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
503 } |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
504 } |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
505 |
30100
c5afe5531709
parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30090
diff
changeset
|
506 packobj = PyBytes_FromStringAndSize(NULL, nbytes); |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
507 if (packobj == NULL) { |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
508 goto bail; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
509 } |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
510 |
30100
c5afe5531709
parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30090
diff
changeset
|
511 p = PyBytes_AS_STRING(packobj); |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
512 |
39422
adacefb0b7ea
dirstate: use tuple interface to fix leak in pack_dirstate()
Yuya Nishihara <yuya@tcha.org>
parents:
37968
diff
changeset
|
513 pn = PyTuple_GET_ITEM(pl, 0); |
30100
c5afe5531709
parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30090
diff
changeset
|
514 if (PyBytes_AsStringAndSize(pn, &s, &l) == -1 || l != 20) { |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
515 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
|
516 goto bail; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
517 } |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
518 memcpy(p, s, l); |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
519 p += 20; |
39422
adacefb0b7ea
dirstate: use tuple interface to fix leak in pack_dirstate()
Yuya Nishihara <yuya@tcha.org>
parents:
37968
diff
changeset
|
520 pn = PyTuple_GET_ITEM(pl, 1); |
30100
c5afe5531709
parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30090
diff
changeset
|
521 if (PyBytes_AsStringAndSize(pn, &s, &l) == -1 || l != 20) { |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
522 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
|
523 goto bail; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
524 } |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
525 memcpy(p, s, l); |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
526 p += 20; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
527 |
34862
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
528 for (pos = 0; PyDict_Next(map, &pos, &k, &v);) { |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
529 dirstateItemObject *tuple; |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
530 char state; |
26774
04ab2348efd1
parsers: correct type of temporary variables for dirstate tuple fields
Yuya Nishihara <yuya@tcha.org>
parents:
26630
diff
changeset
|
531 int mode, size, mtime; |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
532 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
|
533 PyObject *o; |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
534 char *t; |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
535 |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
536 if (!dirstate_tuple_check(v)) { |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
537 PyErr_SetString(PyExc_TypeError, |
34862
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
538 "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
|
539 goto bail; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
540 } |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
541 tuple = (dirstateItemObject *)v; |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
542 |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
543 state = tuple->state; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
544 mode = tuple->mode; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
545 size = tuple->size; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
546 mtime = tuple->mtime; |
26630
3111b45a2bbf
parsers: make pack_dirstate take now in integer for consistency
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26591
diff
changeset
|
547 if (state == 'n' && mtime == now) { |
18567
194e63c1ccb9
dirstate: move pure python dirstate packing to pure/parsers.py
Siddharth Agarwal <sid0@fb.com>
parents:
18504
diff
changeset
|
548 /* 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
|
549 * 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
|
550 mtime = -1; |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
551 mtime_unset = (PyObject *)make_dirstate_item( |
34862
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
552 state, mode, size, mtime); |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
553 if (!mtime_unset) { |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
554 goto bail; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
555 } |
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
556 if (PyDict_SetItem(map, k, mtime_unset) == -1) { |
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
|
557 goto bail; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
558 } |
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
|
559 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
|
560 mtime_unset = NULL; |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
561 } |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
562 *p++ = state; |
26774
04ab2348efd1
parsers: correct type of temporary variables for dirstate tuple fields
Yuya Nishihara <yuya@tcha.org>
parents:
26630
diff
changeset
|
563 putbe32((uint32_t)mode, p); |
04ab2348efd1
parsers: correct type of temporary variables for dirstate tuple fields
Yuya Nishihara <yuya@tcha.org>
parents:
26630
diff
changeset
|
564 putbe32((uint32_t)size, p + 4); |
04ab2348efd1
parsers: correct type of temporary variables for dirstate tuple fields
Yuya Nishihara <yuya@tcha.org>
parents:
26630
diff
changeset
|
565 putbe32((uint32_t)mtime, p + 8); |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
566 t = p + 12; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
567 p += 16; |
30100
c5afe5531709
parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30090
diff
changeset
|
568 len = PyBytes_GET_SIZE(k); |
c5afe5531709
parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30090
diff
changeset
|
569 memcpy(p, PyBytes_AS_STRING(k), len); |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
570 p += len; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
571 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
|
572 if (o) { |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
573 *p++ = '\0'; |
30100
c5afe5531709
parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30090
diff
changeset
|
574 l = PyBytes_GET_SIZE(o); |
c5afe5531709
parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30090
diff
changeset
|
575 memcpy(p, PyBytes_AS_STRING(o), l); |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
576 p += l; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
577 len += l + 1; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
578 } |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
579 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
|
580 } |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
581 |
30100
c5afe5531709
parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30090
diff
changeset
|
582 pos = p - PyBytes_AS_STRING(packobj); |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
583 if (pos != nbytes) { |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
584 PyErr_Format(PyExc_SystemError, "bad dirstate size: %ld != %ld", |
34862
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
585 (long)pos, (long)nbytes); |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
586 goto bail; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
587 } |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
588 |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
589 return packobj; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
590 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
|
591 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
|
592 Py_XDECREF(packobj); |
23946
f3e94aa6e182
parsers: don't leak a tuple in pack_dirstate
Augie Fackler <augie@google.com>
parents:
23945
diff
changeset
|
593 Py_XDECREF(v); |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
594 return NULL; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
595 } |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
596 |
24017
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
597 #define BUMPED_FIX 1 |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
598 #define USING_SHA_256 2 |
26591
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
599 #define FM1_HEADER_SIZE (4 + 8 + 2 + 2 + 1 + 1 + 1) |
24017
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
600 |
34862
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
601 static PyObject *readshas(const char *source, unsigned char num, |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
602 Py_ssize_t hashwidth) |
24017
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
603 { |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
604 int i; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
605 PyObject *list = PyTuple_New(num); |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
606 if (list == NULL) { |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
607 return NULL; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
608 } |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
609 for (i = 0; i < num; i++) { |
30100
c5afe5531709
parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30090
diff
changeset
|
610 PyObject *hash = PyBytes_FromStringAndSize(source, hashwidth); |
24017
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
611 if (hash == NULL) { |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
612 Py_DECREF(list); |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
613 return NULL; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
614 } |
26213
4d6cdea33f37
parsers: use PyTuple_SET_ITEM() to fill new marker tuples
Yuya Nishihara <yuya@tcha.org>
parents:
26107
diff
changeset
|
615 PyTuple_SET_ITEM(list, i, hash); |
24017
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
616 source += hashwidth; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
617 } |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
618 return list; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
619 } |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
620 |
26591
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
621 static PyObject *fm1readmarker(const char *databegin, const char *dataend, |
34862
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
622 uint32_t *msize) |
24017
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
623 { |
26591
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
624 const char *data = databegin; |
24017
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
625 const char *meta; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
626 |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
627 double mtime; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
628 int16_t tz; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
629 uint16_t flags; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
630 unsigned char nsuccs, nparents, nmetadata; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
631 Py_ssize_t hashwidth = 20; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
632 |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
633 PyObject *prec = NULL, *parents = NULL, *succs = NULL; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
634 PyObject *metadata = NULL, *ret = NULL; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
635 int i; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
636 |
26591
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
637 if (data + FM1_HEADER_SIZE > dataend) { |
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
638 goto overflow; |
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
639 } |
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
640 |
24019
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
641 *msize = getbe32(data); |
24017
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
642 data += 4; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
643 mtime = getbefloat64(data); |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
644 data += 8; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
645 tz = getbeint16(data); |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
646 data += 2; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
647 flags = getbeuint16(data); |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
648 data += 2; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
649 |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
650 if (flags & USING_SHA_256) { |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
651 hashwidth = 32; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
652 } |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
653 |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
654 nsuccs = (unsigned char)(*data++); |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
655 nparents = (unsigned char)(*data++); |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
656 nmetadata = (unsigned char)(*data++); |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
657 |
26591
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
658 if (databegin + *msize > dataend) { |
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
659 goto overflow; |
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
660 } |
34862
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
661 dataend = databegin + *msize; /* narrow down to marker size */ |
26591
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
662 |
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
663 if (data + hashwidth > dataend) { |
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
664 goto overflow; |
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
665 } |
30100
c5afe5531709
parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30090
diff
changeset
|
666 prec = PyBytes_FromStringAndSize(data, hashwidth); |
24017
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
667 data += hashwidth; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
668 if (prec == NULL) { |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
669 goto bail; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
670 } |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
671 |
26591
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
672 if (data + nsuccs * hashwidth > dataend) { |
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
673 goto overflow; |
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
674 } |
24017
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
675 succs = readshas(data, nsuccs, hashwidth); |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
676 if (succs == NULL) { |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
677 goto bail; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
678 } |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
679 data += nsuccs * hashwidth; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
680 |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
681 if (nparents == 1 || nparents == 2) { |
26591
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
682 if (data + nparents * hashwidth > dataend) { |
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
683 goto overflow; |
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
684 } |
24017
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
685 parents = readshas(data, nparents, hashwidth); |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
686 if (parents == NULL) { |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
687 goto bail; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
688 } |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
689 data += nparents * hashwidth; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
690 } else { |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
691 parents = Py_None; |
31426
43a7dfbead0c
parsers: handle refcounting of "parents" consistently
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31292
diff
changeset
|
692 Py_INCREF(parents); |
24017
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
693 } |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
694 |
26591
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
695 if (data + 2 * nmetadata > dataend) { |
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
696 goto overflow; |
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
697 } |
24017
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
698 meta = data + (2 * nmetadata); |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
699 metadata = PyTuple_New(nmetadata); |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
700 if (metadata == NULL) { |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
701 goto bail; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
702 } |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
703 for (i = 0; i < nmetadata; i++) { |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
704 PyObject *tmp, *left = NULL, *right = NULL; |
26590
473a63c45394
parsers: read sizes of metadata pair of obsolete marker at once
Yuya Nishihara <yuya@tcha.org>
parents:
26214
diff
changeset
|
705 Py_ssize_t leftsize = (unsigned char)(*data++); |
473a63c45394
parsers: read sizes of metadata pair of obsolete marker at once
Yuya Nishihara <yuya@tcha.org>
parents:
26214
diff
changeset
|
706 Py_ssize_t rightsize = (unsigned char)(*data++); |
26591
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
707 if (meta + leftsize + rightsize > dataend) { |
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
708 goto overflow; |
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
709 } |
30100
c5afe5531709
parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30090
diff
changeset
|
710 left = PyBytes_FromStringAndSize(meta, leftsize); |
26590
473a63c45394
parsers: read sizes of metadata pair of obsolete marker at once
Yuya Nishihara <yuya@tcha.org>
parents:
26214
diff
changeset
|
711 meta += leftsize; |
30100
c5afe5531709
parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30090
diff
changeset
|
712 right = PyBytes_FromStringAndSize(meta, rightsize); |
26590
473a63c45394
parsers: read sizes of metadata pair of obsolete marker at once
Yuya Nishihara <yuya@tcha.org>
parents:
26214
diff
changeset
|
713 meta += rightsize; |
26214
46605888faf3
parsers: use PyTuple_New and SET_ITEM to construct metadata pair of markers
Yuya Nishihara <yuya@tcha.org>
parents:
26213
diff
changeset
|
714 tmp = PyTuple_New(2); |
46605888faf3
parsers: use PyTuple_New and SET_ITEM to construct metadata pair of markers
Yuya Nishihara <yuya@tcha.org>
parents:
26213
diff
changeset
|
715 if (!left || !right || !tmp) { |
24017
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
716 Py_XDECREF(left); |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
717 Py_XDECREF(right); |
26214
46605888faf3
parsers: use PyTuple_New and SET_ITEM to construct metadata pair of markers
Yuya Nishihara <yuya@tcha.org>
parents:
26213
diff
changeset
|
718 Py_XDECREF(tmp); |
24017
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
719 goto bail; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
720 } |
26214
46605888faf3
parsers: use PyTuple_New and SET_ITEM to construct metadata pair of markers
Yuya Nishihara <yuya@tcha.org>
parents:
26213
diff
changeset
|
721 PyTuple_SET_ITEM(tmp, 0, left); |
46605888faf3
parsers: use PyTuple_New and SET_ITEM to construct metadata pair of markers
Yuya Nishihara <yuya@tcha.org>
parents:
26213
diff
changeset
|
722 PyTuple_SET_ITEM(tmp, 1, right); |
26213
4d6cdea33f37
parsers: use PyTuple_SET_ITEM() to fill new marker tuples
Yuya Nishihara <yuya@tcha.org>
parents:
26107
diff
changeset
|
723 PyTuple_SET_ITEM(metadata, i, tmp); |
24017
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
724 } |
34862
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
725 ret = Py_BuildValue("(OOHO(di)O)", prec, succs, flags, metadata, mtime, |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
726 (int)tz * 60, parents); |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
727 goto bail; /* return successfully */ |
26591
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
728 |
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
729 overflow: |
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
730 PyErr_SetString(PyExc_ValueError, "overflow in obsstore"); |
24017
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
731 bail: |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
732 Py_XDECREF(prec); |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
733 Py_XDECREF(succs); |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
734 Py_XDECREF(metadata); |
31426
43a7dfbead0c
parsers: handle refcounting of "parents" consistently
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31292
diff
changeset
|
735 Py_XDECREF(parents); |
24017
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
736 return ret; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
737 } |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
738 |
34440
7ed0750c71a1
cext: wrap before brace for functions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34438
diff
changeset
|
739 static PyObject *fm1readmarkers(PyObject *self, PyObject *args) |
7ed0750c71a1
cext: wrap before brace for functions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34438
diff
changeset
|
740 { |
26591
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
741 const char *data, *dataend; |
42068
896b19d12c08
cext: make parsers.c PY_SSIZE_T_CLEAN
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41336
diff
changeset
|
742 Py_ssize_t datalen, offset, stop; |
24019
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
743 PyObject *markers = NULL; |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
744 |
36620
186c6df3a373
py3: bulk-replace 'const char*' format specifier passed to PyArg_ParseTuple*()
Yuya Nishihara <yuya@tcha.org>
parents:
36619
diff
changeset
|
745 if (!PyArg_ParseTuple(args, PY23("s#nn", "y#nn"), &data, &datalen, |
186c6df3a373
py3: bulk-replace 'const char*' format specifier passed to PyArg_ParseTuple*()
Yuya Nishihara <yuya@tcha.org>
parents:
36619
diff
changeset
|
746 &offset, &stop)) { |
24019
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
747 return NULL; |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
748 } |
41016
5c68b617ba24
parsers: better bounds checking in fm1readmarkers
Augie Fackler <augie@google.com>
parents:
41011
diff
changeset
|
749 if (offset < 0) { |
5c68b617ba24
parsers: better bounds checking in fm1readmarkers
Augie Fackler <augie@google.com>
parents:
41011
diff
changeset
|
750 PyErr_SetString(PyExc_ValueError, |
5c68b617ba24
parsers: better bounds checking in fm1readmarkers
Augie Fackler <augie@google.com>
parents:
41011
diff
changeset
|
751 "invalid negative offset in fm1readmarkers"); |
5c68b617ba24
parsers: better bounds checking in fm1readmarkers
Augie Fackler <augie@google.com>
parents:
41011
diff
changeset
|
752 return NULL; |
5c68b617ba24
parsers: better bounds checking in fm1readmarkers
Augie Fackler <augie@google.com>
parents:
41011
diff
changeset
|
753 } |
5c68b617ba24
parsers: better bounds checking in fm1readmarkers
Augie Fackler <augie@google.com>
parents:
41011
diff
changeset
|
754 if (stop > datalen) { |
5c68b617ba24
parsers: better bounds checking in fm1readmarkers
Augie Fackler <augie@google.com>
parents:
41011
diff
changeset
|
755 PyErr_SetString( |
5c68b617ba24
parsers: better bounds checking in fm1readmarkers
Augie Fackler <augie@google.com>
parents:
41011
diff
changeset
|
756 PyExc_ValueError, |
5c68b617ba24
parsers: better bounds checking in fm1readmarkers
Augie Fackler <augie@google.com>
parents:
41011
diff
changeset
|
757 "stop longer than data length in fm1readmarkers"); |
5c68b617ba24
parsers: better bounds checking in fm1readmarkers
Augie Fackler <augie@google.com>
parents:
41011
diff
changeset
|
758 return NULL; |
5c68b617ba24
parsers: better bounds checking in fm1readmarkers
Augie Fackler <augie@google.com>
parents:
41011
diff
changeset
|
759 } |
26591
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
760 dataend = data + datalen; |
24019
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
761 data += offset; |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
762 markers = PyList_New(0); |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
763 if (!markers) { |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
764 return NULL; |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
765 } |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
766 while (offset < stop) { |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
767 uint32_t msize; |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
768 int error; |
26591
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
769 PyObject *record = fm1readmarker(data, dataend, &msize); |
24019
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
770 if (!record) { |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
771 goto bail; |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
772 } |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
773 error = PyList_Append(markers, record); |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
774 Py_DECREF(record); |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
775 if (error) { |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
776 goto bail; |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
777 } |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
778 data += msize; |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
779 offset += msize; |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
780 } |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
781 return markers; |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
782 bail: |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
783 Py_DECREF(markers); |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
784 return NULL; |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
785 } |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
786 |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
787 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
|
788 |
17606
318fb32b980e
pathencode: new C module with fast encodedir() function
Adrian Buehlmann <adrian@cadifra.com>
parents:
17356
diff
changeset
|
789 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
|
790 PyObject *pathencode(PyObject *self, PyObject *args); |
18430
0459c6555f69
store: implement lowerencode in C
Bryan O'Sullivan <bryano@fb.com>
parents:
17616
diff
changeset
|
791 PyObject *lowerencode(PyObject *self, PyObject *args); |
46708
358737abeeef
cext: add support for revlogv2
Raphaël Gomès <rgomes@octobus.net>
parents:
45131
diff
changeset
|
792 PyObject *parse_index2(PyObject *self, PyObject *args, PyObject *kwargs); |
17606
318fb32b980e
pathencode: new C module with fast encodedir() function
Adrian Buehlmann <adrian@cadifra.com>
parents:
17356
diff
changeset
|
793 |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
794 static PyMethodDef methods[] = { |
34862
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
795 {"pack_dirstate", pack_dirstate, METH_VARARGS, "pack a dirstate\n"}, |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
796 {"nonnormalotherparententries", nonnormalotherparententries, METH_VARARGS, |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
797 "create a set containing non-normal and other parent entries of given " |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
798 "dirstate\n"}, |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
799 {"parse_dirstate", parse_dirstate, METH_VARARGS, "parse a dirstate\n"}, |
46708
358737abeeef
cext: add support for revlogv2
Raphaël Gomès <rgomes@octobus.net>
parents:
45131
diff
changeset
|
800 {"parse_index2", (PyCFunction)parse_index2, METH_VARARGS | METH_KEYWORDS, |
358737abeeef
cext: add support for revlogv2
Raphaël Gomès <rgomes@octobus.net>
parents:
45131
diff
changeset
|
801 "parse a revlog index\n"}, |
34862
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
802 {"isasciistr", isasciistr, METH_VARARGS, "check if an ASCII string\n"}, |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
803 {"asciilower", asciilower, METH_VARARGS, "lowercase an ASCII string\n"}, |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
804 {"asciiupper", asciiupper, METH_VARARGS, "uppercase an ASCII string\n"}, |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
805 {"dict_new_presized", dict_new_presized, METH_VARARGS, |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
806 "construct a dict with an expected size\n"}, |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
807 {"make_file_foldmap", make_file_foldmap, METH_VARARGS, |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
808 "make file foldmap\n"}, |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
809 {"jsonescapeu8fast", jsonescapeu8fast, METH_VARARGS, |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
810 "escape a UTF-8 byte string to JSON (fast path)\n"}, |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
811 {"encodedir", encodedir, METH_VARARGS, "encodedir a path\n"}, |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
812 {"pathencode", pathencode, METH_VARARGS, "fncache-encode a path\n"}, |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
813 {"lowerencode", lowerencode, METH_VARARGS, "lower-encode a path\n"}, |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
814 {"fm1readmarkers", fm1readmarkers, METH_VARARGS, |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
815 "parse v1 obsolete markers\n"}, |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
816 {NULL, NULL}}; |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
817 |
18900
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
18567
diff
changeset
|
818 void dirs_module_init(PyObject *mod); |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
24032
diff
changeset
|
819 void manifest_module_init(PyObject *mod); |
32378
7d0c69505a66
cext: extract revlog/index parsing code to own C file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32372
diff
changeset
|
820 void revlog_module_init(PyObject *mod); |
18900
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
18567
diff
changeset
|
821 |
47268
9d1a8829f959
revlog: signal which revlog index are compatible with Rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47249
diff
changeset
|
822 static const int version = 20; |
32360
af3ef002395d
parsers: add version to help detect breaking binary changes
Jun Wu <quark@fb.com>
parents:
31470
diff
changeset
|
823 |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
824 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
|
825 { |
42303
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
42096
diff
changeset
|
826 PyObject *capsule = NULL; |
32360
af3ef002395d
parsers: add version to help detect breaking binary changes
Jun Wu <quark@fb.com>
parents:
31470
diff
changeset
|
827 PyModule_AddIntConstant(mod, "version", version); |
af3ef002395d
parsers: add version to help detect breaking binary changes
Jun Wu <quark@fb.com>
parents:
31470
diff
changeset
|
828 |
20742
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
829 /* 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
|
830 * 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
|
831 * 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
|
832 * 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
|
833 * 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
|
834 * 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
|
835 * 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
|
836 * 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
|
837 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
|
838 |
18900
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
18567
diff
changeset
|
839 dirs_module_init(mod); |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
24032
diff
changeset
|
840 manifest_module_init(mod); |
32378
7d0c69505a66
cext: extract revlog/index parsing code to own C file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32372
diff
changeset
|
841 revlog_module_init(mod); |
18900
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
18567
diff
changeset
|
842 |
42303
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
42096
diff
changeset
|
843 capsule = PyCapsule_New( |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
844 make_dirstate_item, |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
845 "mercurial.cext.parsers.make_dirstate_item_CAPI", NULL); |
42303
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
42096
diff
changeset
|
846 if (capsule != NULL) |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
847 PyModule_AddObject(mod, "make_dirstate_item_CAPI", capsule); |
42303
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
42096
diff
changeset
|
848 |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
849 if (PyType_Ready(&dirstateItemType) < 0) { |
32384
2e5a476b2e46
cext: move back finalization of dirstateTupleType where it should be
Yuya Nishihara <yuya@tcha.org>
parents:
32378
diff
changeset
|
850 return; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
851 } |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
852 Py_INCREF(&dirstateItemType); |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
853 PyModule_AddObject(mod, "DirstateItem", (PyObject *)&dirstateItemType); |
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
854 } |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
855 |
20742
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
856 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
|
857 { |
23943
5fb44983a696
parsers: don't leak references to sys et al in check_python_version
Augie Fackler <augie@google.com>
parents:
23942
diff
changeset
|
858 PyObject *sys = PyImport_ImportModule("sys"), *ver; |
5fb44983a696
parsers: don't leak references to sys et al in check_python_version
Augie Fackler <augie@google.com>
parents:
23942
diff
changeset
|
859 long hexversion; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
860 if (!sys) { |
23943
5fb44983a696
parsers: don't leak references to sys et al in check_python_version
Augie Fackler <augie@google.com>
parents:
23942
diff
changeset
|
861 return -1; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
862 } |
23943
5fb44983a696
parsers: don't leak references to sys et al in check_python_version
Augie Fackler <augie@google.com>
parents:
23942
diff
changeset
|
863 ver = PyObject_GetAttrString(sys, "hexversion"); |
5fb44983a696
parsers: don't leak references to sys et al in check_python_version
Augie Fackler <augie@google.com>
parents:
23942
diff
changeset
|
864 Py_DECREF(sys); |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
865 if (!ver) { |
23943
5fb44983a696
parsers: don't leak references to sys et al in check_python_version
Augie Fackler <augie@google.com>
parents:
23942
diff
changeset
|
866 return -1; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
867 } |
23943
5fb44983a696
parsers: don't leak references to sys et al in check_python_version
Augie Fackler <augie@google.com>
parents:
23942
diff
changeset
|
868 hexversion = PyInt_AsLong(ver); |
5fb44983a696
parsers: don't leak references to sys et al in check_python_version
Augie Fackler <augie@google.com>
parents:
23942
diff
changeset
|
869 Py_DECREF(ver); |
20742
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
870 /* 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
|
871 * 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
|
872 * 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
|
873 if ((hexversion == -1) || (hexversion >> 16 != PY_VERSION_HEX >> 16)) { |
34862
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
874 PyErr_Format(PyExc_ImportError, |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
875 "%s: The Mercurial extension " |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
876 "modules were compiled with Python " PY_VERSION |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
877 ", but " |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
878 "Mercurial is currently using Python with " |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
879 "sys.hexversion=%ld: " |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
880 "Python %s\n at: %s", |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
881 versionerrortext, hexversion, Py_GetVersion(), |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
882 Py_GetProgramFullPath()); |
20742
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
883 return -1; |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
884 } |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
885 return 0; |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
886 } |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
887 |
11361
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
888 #ifdef IS_PY3K |
34862
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
889 static struct PyModuleDef parsers_module = {PyModuleDef_HEAD_INIT, "parsers", |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
890 parsers_doc, -1, methods}; |
11361
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
891 |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
892 PyMODINIT_FUNC PyInit_parsers(void) |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
893 { |
20797
e286ab22e461
parsers: fix compiler errors on MSVC 2008
Matt Harbison <matt_harbison@yahoo.com>
parents:
20742
diff
changeset
|
894 PyObject *mod; |
e286ab22e461
parsers: fix compiler errors on MSVC 2008
Matt Harbison <matt_harbison@yahoo.com>
parents:
20742
diff
changeset
|
895 |
20742
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
896 if (check_python_version() == -1) |
30090
8abe9264c73a
parsers: return NULL from PyInit_parsers on Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29444
diff
changeset
|
897 return NULL; |
20797
e286ab22e461
parsers: fix compiler errors on MSVC 2008
Matt Harbison <matt_harbison@yahoo.com>
parents:
20742
diff
changeset
|
898 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
|
899 module_init(mod); |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
900 return mod; |
11361
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
901 } |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
902 #else |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
903 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
|
904 { |
20797
e286ab22e461
parsers: fix compiler errors on MSVC 2008
Matt Harbison <matt_harbison@yahoo.com>
parents:
20742
diff
changeset
|
905 PyObject *mod; |
e286ab22e461
parsers: fix compiler errors on MSVC 2008
Matt Harbison <matt_harbison@yahoo.com>
parents:
20742
diff
changeset
|
906 |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
907 if (check_python_version() == -1) { |
20742
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
908 return; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
909 } |
20797
e286ab22e461
parsers: fix compiler errors on MSVC 2008
Matt Harbison <matt_harbison@yahoo.com>
parents:
20742
diff
changeset
|
910 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
|
911 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
|
912 } |
11361
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
913 #endif |