author | Simon Sapin <simon.sapin@octobus.net> |
Thu, 30 Sep 2021 18:06:34 +0200 | |
changeset 48084 | 596510cd2b12 |
parent 48067 | d3eb5f50052c |
child 48086 | 80783e553bd5 |
permissions | -rw-r--r-- |
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; |
47666
e53256a9f9c5
dirstate-item: add a `set_possibly_dirty` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47665
diff
changeset
|
34 |
static const int ambiguous_time = -1; |
47514
559aee84b889
dirstate-entry: add a `from_p2` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47513
diff
changeset
|
35 |
|
25584
72b2711f12ea
parsers: add an API to create a new presized dict
Siddharth Agarwal <sid0@fb.com>
parents:
25583
diff
changeset
|
36 |
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
|
37 |
{ |
72b2711f12ea
parsers: add an API to create a new presized dict
Siddharth Agarwal <sid0@fb.com>
parents:
25583
diff
changeset
|
38 |
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
|
39 |
|
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
40 |
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
|
41 |
return NULL; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
42 |
} |
25584
72b2711f12ea
parsers: add an API to create a new presized dict
Siddharth Agarwal <sid0@fb.com>
parents:
25583
diff
changeset
|
43 |
|
72b2711f12ea
parsers: add an API to create a new presized dict
Siddharth Agarwal <sid0@fb.com>
parents:
25583
diff
changeset
|
44 |
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
|
45 |
} |
72b2711f12ea
parsers: add an API to create a new presized dict
Siddharth Agarwal <sid0@fb.com>
parents:
25583
diff
changeset
|
46 |
|
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
47 |
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
|
48 |
PyObject *kwds) |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
49 |
{ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
50 |
/* 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
|
51 |
* dirstate_item is immutable. */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
52 |
dirstateItemObject *t; |
47895
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
53 |
int wc_tracked; |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
54 |
int p1_tracked; |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
55 |
int p2_tracked; |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
56 |
int merged; |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
57 |
int clean_p1; |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
58 |
int clean_p2; |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
59 |
int possibly_dirty; |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
60 |
PyObject *parentfiledata; |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
61 |
static char *keywords_name[] = { |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
62 |
"wc_tracked", "p1_tracked", "p2_tracked", |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
63 |
"merged", "clean_p1", "clean_p2", |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
64 |
"possibly_dirty", "parentfiledata", NULL, |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
65 |
}; |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
66 |
wc_tracked = 0; |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
67 |
p1_tracked = 0; |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
68 |
p2_tracked = 0; |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
69 |
merged = 0; |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
70 |
clean_p1 = 0; |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
71 |
clean_p2 = 0; |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
72 |
possibly_dirty = 0; |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
73 |
parentfiledata = Py_None; |
48084
596510cd2b12
dirstate-item: Make constructor parameters optional
Simon Sapin <simon.sapin@octobus.net>
parents:
48067
diff
changeset
|
74 |
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|iiiiiiiO", keywords_name, |
47895
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
75 |
&wc_tracked, &p1_tracked, &p2_tracked, |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
76 |
&merged, &clean_p1, &clean_p2, |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
77 |
&possibly_dirty, &parentfiledata |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
78 |
|
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
79 |
)) { |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
80 |
return NULL; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
81 |
} |
47895
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
82 |
if (merged && (clean_p1 || clean_p2)) { |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
83 |
PyErr_SetString(PyExc_RuntimeError, |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
84 |
"`merged` argument incompatible with " |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
85 |
"`clean_p1`/`clean_p2`"); |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
86 |
return NULL; |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
87 |
} |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
88 |
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
|
89 |
if (!t) { |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
90 |
return NULL; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
91 |
} |
47948
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
92 |
|
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
93 |
t->flags = 0; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
94 |
if (wc_tracked) { |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
95 |
t->flags |= dirstate_flag_wc_tracked; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
96 |
} |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
97 |
if (p1_tracked) { |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
98 |
t->flags |= dirstate_flag_p1_tracked; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
99 |
} |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
100 |
if (p2_tracked) { |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
101 |
t->flags |= dirstate_flag_p2_tracked; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
102 |
} |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
103 |
if (possibly_dirty) { |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
104 |
t->flags |= dirstate_flag_possibly_dirty; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
105 |
} |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
106 |
if (merged) { |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
107 |
t->flags |= dirstate_flag_merged; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
108 |
} |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
109 |
if (clean_p1) { |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
110 |
t->flags |= dirstate_flag_clean_p1; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
111 |
} |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
112 |
if (clean_p2) { |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
113 |
t->flags |= dirstate_flag_clean_p2; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
114 |
} |
47895
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
115 |
t->mode = 0; |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
116 |
t->size = dirstate_v1_nonnormal; |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
117 |
t->mtime = ambiguous_time; |
47948
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
118 |
if (parentfiledata != Py_None) { |
47895
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
119 |
if (!PyTuple_CheckExact(parentfiledata)) { |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
120 |
PyErr_SetString( |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
121 |
PyExc_TypeError, |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
122 |
"parentfiledata should be a Tuple or None"); |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
123 |
return NULL; |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
124 |
} |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
125 |
t->mode = |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
126 |
(int)PyLong_AsLong(PyTuple_GetItem(parentfiledata, 0)); |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
127 |
t->size = |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
128 |
(int)PyLong_AsLong(PyTuple_GetItem(parentfiledata, 1)); |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
129 |
t->mtime = |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
130 |
(int)PyLong_AsLong(PyTuple_GetItem(parentfiledata, 2)); |
22c39f8acf78
dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47892
diff
changeset
|
131 |
} |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
132 |
return (PyObject *)t; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
133 |
} |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
134 |
|
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
135 |
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
|
136 |
{ |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
137 |
PyObject_Del(o); |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
138 |
} |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
139 |
|
47947
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
140 |
static inline bool dirstate_item_c_tracked(dirstateItemObject *self) |
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
141 |
{ |
47948
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
142 |
return (self->flags & dirstate_flag_wc_tracked); |
47947
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
143 |
} |
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
144 |
|
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
145 |
static inline bool dirstate_item_c_added(dirstateItemObject *self) |
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
146 |
{ |
47975
ec178161a8d1
dirstate: make dirstate flags char be unsigned
Martin von Zweigbergk <martinvonz@google.com>
parents:
47974
diff
changeset
|
147 |
unsigned char mask = |
ec178161a8d1
dirstate: make dirstate flags char be unsigned
Martin von Zweigbergk <martinvonz@google.com>
parents:
47974
diff
changeset
|
148 |
(dirstate_flag_wc_tracked | dirstate_flag_p1_tracked | |
ec178161a8d1
dirstate: make dirstate flags char be unsigned
Martin von Zweigbergk <martinvonz@google.com>
parents:
47974
diff
changeset
|
149 |
dirstate_flag_p2_tracked); |
ec178161a8d1
dirstate: make dirstate flags char be unsigned
Martin von Zweigbergk <martinvonz@google.com>
parents:
47974
diff
changeset
|
150 |
unsigned char target = dirstate_flag_wc_tracked; |
47948
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
151 |
return (self->flags & mask) == target; |
47947
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
152 |
} |
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
153 |
|
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
154 |
static inline bool dirstate_item_c_removed(dirstateItemObject *self) |
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
155 |
{ |
47948
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
156 |
if (self->flags & dirstate_flag_wc_tracked) { |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
157 |
return false; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
158 |
} |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
159 |
return (self->flags & |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
160 |
(dirstate_flag_p1_tracked | dirstate_flag_p2_tracked)); |
47947
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
161 |
} |
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
162 |
|
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
163 |
static inline bool dirstate_item_c_merged(dirstateItemObject *self) |
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
164 |
{ |
47948
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
165 |
return ((self->flags & dirstate_flag_wc_tracked) && |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
166 |
(self->flags & dirstate_flag_merged)); |
47947
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
167 |
} |
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
168 |
|
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
169 |
static inline bool dirstate_item_c_from_p2(dirstateItemObject *self) |
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
170 |
{ |
47948
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
171 |
if (!dirstate_item_c_tracked(self)) { |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
172 |
return false; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
173 |
} |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
174 |
return (self->flags & dirstate_flag_clean_p2); |
47947
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
175 |
} |
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
176 |
|
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
177 |
static inline char dirstate_item_c_v1_state(dirstateItemObject *self) |
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
178 |
{ |
48025
631f6b445a77
dirstate: Remove the `state == ' '` special case
Simon Sapin <simon.sapin@octobus.net>
parents:
47990
diff
changeset
|
179 |
if (dirstate_item_c_removed(self)) { |
47948
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
180 |
return 'r'; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
181 |
} else if (dirstate_item_c_merged(self)) { |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
182 |
return 'm'; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
183 |
} else if (dirstate_item_c_added(self)) { |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
184 |
return 'a'; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
185 |
} else { |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
186 |
return 'n'; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
187 |
} |
47947
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
188 |
} |
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
189 |
|
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
190 |
static inline int dirstate_item_c_v1_mode(dirstateItemObject *self) |
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
191 |
{ |
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
192 |
return self->mode; |
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
193 |
} |
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
194 |
|
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
195 |
static inline int dirstate_item_c_v1_size(dirstateItemObject *self) |
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
196 |
{ |
48064
2943955304b3
dirstate: inline the merged_removed logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48061
diff
changeset
|
197 |
if (dirstate_item_c_removed(self) && |
2943955304b3
dirstate: inline the merged_removed logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48061
diff
changeset
|
198 |
(self->flags & dirstate_flag_merged)) { |
47948
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
199 |
return dirstate_v1_nonnormal; |
48066
7a2de2bd9fcd
dirstate: inline the `from_p2_removed` logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48065
diff
changeset
|
200 |
} else if (dirstate_item_c_removed(self) && |
7a2de2bd9fcd
dirstate: inline the `from_p2_removed` logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48065
diff
changeset
|
201 |
(self->flags & dirstate_flag_clean_p2)) { |
47948
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
202 |
return dirstate_v1_from_p2; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
203 |
} else if (dirstate_item_c_removed(self)) { |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
204 |
return 0; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
205 |
} else if (dirstate_item_c_merged(self)) { |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
206 |
return dirstate_v1_from_p2; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
207 |
} else if (dirstate_item_c_added(self)) { |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
208 |
return dirstate_v1_nonnormal; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
209 |
} else if (dirstate_item_c_from_p2(self)) { |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
210 |
return dirstate_v1_from_p2; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
211 |
} else if (self->flags & dirstate_flag_possibly_dirty) { |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
212 |
return self->size; /* NON NORMAL ? */ |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
213 |
} else { |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
214 |
return self->size; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
215 |
} |
47947
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
216 |
} |
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
217 |
|
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
218 |
static inline int dirstate_item_c_v1_mtime(dirstateItemObject *self) |
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
219 |
{ |
48025
631f6b445a77
dirstate: Remove the `state == ' '` special case
Simon Sapin <simon.sapin@octobus.net>
parents:
47990
diff
changeset
|
220 |
if (dirstate_item_c_removed(self)) { |
47948
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
221 |
return 0; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
222 |
} else if (self->flags & dirstate_flag_possibly_dirty) { |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
223 |
return ambiguous_time; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
224 |
} else if (dirstate_item_c_merged(self)) { |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
225 |
return ambiguous_time; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
226 |
} else if (dirstate_item_c_added(self)) { |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
227 |
return ambiguous_time; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
228 |
} else if (dirstate_item_c_from_p2(self)) { |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
229 |
return ambiguous_time; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
230 |
} else { |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
231 |
return self->mtime; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
232 |
} |
47947
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
233 |
} |
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
234 |
|
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
235 |
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
|
236 |
{ |
47947
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
237 |
char state = dirstate_item_c_v1_state(self); |
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
238 |
return PyBytes_FromStringAndSize(&state, 1); |
47509
80dc1d452993
dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47268
diff
changeset
|
239 |
}; |
80dc1d452993
dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47268
diff
changeset
|
240 |
|
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
241 |
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
|
242 |
{ |
47947
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
243 |
return PyInt_FromLong(dirstate_item_c_v1_mode(self)); |
47509
80dc1d452993
dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47268
diff
changeset
|
244 |
}; |
80dc1d452993
dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47268
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_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
|
247 |
{ |
47947
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
248 |
return PyInt_FromLong(dirstate_item_c_v1_size(self)); |
47509
80dc1d452993
dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47268
diff
changeset
|
249 |
}; |
80dc1d452993
dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47268
diff
changeset
|
250 |
|
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
251 |
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
|
252 |
{ |
47947
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
253 |
return PyInt_FromLong(dirstate_item_c_v1_mtime(self)); |
47509
80dc1d452993
dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47268
diff
changeset
|
254 |
}; |
80dc1d452993
dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47268
diff
changeset
|
255 |
|
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
256 |
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
|
257 |
PyObject *value) |
ccbabaee5c36
dirstate-entry: add a `need_delay` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47531
diff
changeset
|
258 |
{ |
ccbabaee5c36
dirstate-entry: add a `need_delay` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47531
diff
changeset
|
259 |
long now; |
ccbabaee5c36
dirstate-entry: add a `need_delay` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47531
diff
changeset
|
260 |
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
|
261 |
return NULL; |
ccbabaee5c36
dirstate-entry: add a `need_delay` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47531
diff
changeset
|
262 |
} |
47947
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
263 |
if (dirstate_item_c_v1_state(self) == 'n' && |
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
264 |
dirstate_item_c_v1_mtime(self) == now) { |
47532
ccbabaee5c36
dirstate-entry: add a `need_delay` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47531
diff
changeset
|
265 |
Py_RETURN_TRUE; |
ccbabaee5c36
dirstate-entry: add a `need_delay` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47531
diff
changeset
|
266 |
} else { |
ccbabaee5c36
dirstate-entry: add a `need_delay` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47531
diff
changeset
|
267 |
Py_RETURN_FALSE; |
ccbabaee5c36
dirstate-entry: add a `need_delay` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47531
diff
changeset
|
268 |
} |
ccbabaee5c36
dirstate-entry: add a `need_delay` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47531
diff
changeset
|
269 |
}; |
ccbabaee5c36
dirstate-entry: add a `need_delay` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47531
diff
changeset
|
270 |
|
47945
3337eec29d5b
dirstate-item: `dirstate_item_from_v1_data` replaces make_dirstate_item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47925
diff
changeset
|
271 |
/* This will never change since it's bound to V1 |
47665
a4443f66be6a
dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47539
diff
changeset
|
272 |
*/ |
a4443f66be6a
dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47539
diff
changeset
|
273 |
static inline dirstateItemObject * |
a4443f66be6a
dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47539
diff
changeset
|
274 |
dirstate_item_from_v1_data(char state, int mode, int size, int mtime) |
a4443f66be6a
dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47539
diff
changeset
|
275 |
{ |
a4443f66be6a
dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47539
diff
changeset
|
276 |
dirstateItemObject *t = |
a4443f66be6a
dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47539
diff
changeset
|
277 |
PyObject_New(dirstateItemObject, &dirstateItemType); |
a4443f66be6a
dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47539
diff
changeset
|
278 |
if (!t) { |
a4443f66be6a
dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47539
diff
changeset
|
279 |
return NULL; |
a4443f66be6a
dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47539
diff
changeset
|
280 |
} |
47948
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
281 |
|
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
282 |
if (state == 'm') { |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
283 |
t->flags = |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
284 |
(dirstate_flag_wc_tracked | dirstate_flag_p1_tracked | |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
285 |
dirstate_flag_p2_tracked | dirstate_flag_merged); |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
286 |
t->mode = 0; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
287 |
t->size = dirstate_v1_from_p2; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
288 |
t->mtime = ambiguous_time; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
289 |
} else if (state == 'a') { |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
290 |
t->flags = dirstate_flag_wc_tracked; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
291 |
t->mode = 0; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
292 |
t->size = dirstate_v1_nonnormal; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
293 |
t->mtime = ambiguous_time; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
294 |
} else if (state == 'r') { |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
295 |
t->mode = 0; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
296 |
t->size = 0; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
297 |
t->mtime = 0; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
298 |
if (size == dirstate_v1_nonnormal) { |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
299 |
t->flags = |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
300 |
(dirstate_flag_p1_tracked | |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
301 |
dirstate_flag_p2_tracked | dirstate_flag_merged); |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
302 |
} else if (size == dirstate_v1_from_p2) { |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
303 |
t->flags = |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
304 |
(dirstate_flag_p2_tracked | dirstate_flag_clean_p2); |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
305 |
} else { |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
306 |
t->flags = dirstate_flag_p1_tracked; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
307 |
} |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
308 |
} else if (state == 'n') { |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
309 |
if (size == dirstate_v1_from_p2) { |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
310 |
t->flags = |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
311 |
(dirstate_flag_wc_tracked | |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
312 |
dirstate_flag_p2_tracked | dirstate_flag_clean_p2); |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
313 |
t->mode = 0; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
314 |
t->size = dirstate_v1_from_p2; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
315 |
t->mtime = ambiguous_time; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
316 |
} else if (size == dirstate_v1_nonnormal) { |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
317 |
t->flags = (dirstate_flag_wc_tracked | |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
318 |
dirstate_flag_p1_tracked | |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
319 |
dirstate_flag_possibly_dirty); |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
320 |
t->mode = 0; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
321 |
t->size = dirstate_v1_nonnormal; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
322 |
t->mtime = ambiguous_time; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
323 |
} else if (mtime == ambiguous_time) { |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
324 |
t->flags = (dirstate_flag_wc_tracked | |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
325 |
dirstate_flag_p1_tracked | |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
326 |
dirstate_flag_possibly_dirty); |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
327 |
t->mode = mode; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
328 |
t->size = size; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
329 |
t->mtime = 0; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
330 |
} else { |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
331 |
t->flags = (dirstate_flag_wc_tracked | |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
332 |
dirstate_flag_p1_tracked); |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
333 |
t->mode = mode; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
334 |
t->size = size; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
335 |
t->mtime = mtime; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
336 |
} |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
337 |
} else { |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
338 |
PyErr_Format(PyExc_RuntimeError, |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
339 |
"unknown state: `%c` (%d, %d, %d)", state, mode, |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
340 |
size, mtime, NULL); |
48028
448aff4e8dd4
dirstate: fix leak of entry object in dirstate_item_from_v1_data()
Yuya Nishihara <yuya@tcha.org>
parents:
48027
diff
changeset
|
341 |
Py_DECREF(t); |
47948
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
342 |
return NULL; |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
343 |
} |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
344 |
|
47665
a4443f66be6a
dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47539
diff
changeset
|
345 |
return t; |
a4443f66be6a
dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47539
diff
changeset
|
346 |
} |
a4443f66be6a
dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47539
diff
changeset
|
347 |
|
a4443f66be6a
dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47539
diff
changeset
|
348 |
/* This will never change since it's bound to V1, unlike `dirstate_item_new` */ |
a4443f66be6a
dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47539
diff
changeset
|
349 |
static PyObject *dirstate_item_from_v1_meth(PyTypeObject *subtype, |
a4443f66be6a
dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47539
diff
changeset
|
350 |
PyObject *args) |
a4443f66be6a
dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47539
diff
changeset
|
351 |
{ |
a4443f66be6a
dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47539
diff
changeset
|
352 |
/* We do all the initialization here and not a tp_init function because |
a4443f66be6a
dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47539
diff
changeset
|
353 |
* dirstate_item is immutable. */ |
a4443f66be6a
dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47539
diff
changeset
|
354 |
char state; |
a4443f66be6a
dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47539
diff
changeset
|
355 |
int size, mode, mtime; |
a4443f66be6a
dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47539
diff
changeset
|
356 |
if (!PyArg_ParseTuple(args, "ciii", &state, &mode, &size, &mtime)) { |
a4443f66be6a
dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47539
diff
changeset
|
357 |
return NULL; |
a4443f66be6a
dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47539
diff
changeset
|
358 |
} |
47946
0919d66e279a
dirstate-item: factor some code in the C implementation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47945
diff
changeset
|
359 |
return (PyObject *)dirstate_item_from_v1_data(state, mode, size, mtime); |
47665
a4443f66be6a
dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47539
diff
changeset
|
360 |
}; |
a4443f66be6a
dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47539
diff
changeset
|
361 |
|
47905
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
362 |
/* constructor to help legacy API to build a new "added" item |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
363 |
|
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
364 |
Should eventually be removed */ |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
365 |
static PyObject *dirstate_item_new_added(PyTypeObject *subtype) |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
366 |
{ |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
367 |
dirstateItemObject *t; |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
368 |
t = (dirstateItemObject *)subtype->tp_alloc(subtype, 1); |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
369 |
if (!t) { |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
370 |
return NULL; |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
371 |
} |
47948
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
372 |
t->flags = dirstate_flag_wc_tracked; |
47905
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
373 |
t->mode = 0; |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
374 |
t->size = dirstate_v1_nonnormal; |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
375 |
t->mtime = ambiguous_time; |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
376 |
return (PyObject *)t; |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
377 |
}; |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
378 |
|
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
379 |
/* constructor to help legacy API to build a new "merged" item |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
380 |
|
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
381 |
Should eventually be removed */ |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
382 |
static PyObject *dirstate_item_new_merged(PyTypeObject *subtype) |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
383 |
{ |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
384 |
dirstateItemObject *t; |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
385 |
t = (dirstateItemObject *)subtype->tp_alloc(subtype, 1); |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
386 |
if (!t) { |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
387 |
return NULL; |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
388 |
} |
47948
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
389 |
t->flags = (dirstate_flag_wc_tracked | dirstate_flag_p1_tracked | |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
390 |
dirstate_flag_p2_tracked | dirstate_flag_merged); |
47905
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
391 |
t->mode = 0; |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
392 |
t->size = dirstate_v1_from_p2; |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
393 |
t->mtime = ambiguous_time; |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
394 |
return (PyObject *)t; |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
395 |
}; |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
396 |
|
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
397 |
/* constructor to help legacy API to build a new "from_p2" item |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
398 |
|
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
399 |
Should eventually be removed */ |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
400 |
static PyObject *dirstate_item_new_from_p2(PyTypeObject *subtype) |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
401 |
{ |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
402 |
/* We do all the initialization here and not a tp_init function because |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
403 |
* dirstate_item is immutable. */ |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
404 |
dirstateItemObject *t; |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
405 |
t = (dirstateItemObject *)subtype->tp_alloc(subtype, 1); |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
406 |
if (!t) { |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
407 |
return NULL; |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
408 |
} |
47948
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
409 |
t->flags = (dirstate_flag_wc_tracked | dirstate_flag_p2_tracked | |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
410 |
dirstate_flag_clean_p2); |
47905
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
411 |
t->mode = 0; |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
412 |
t->size = dirstate_v1_from_p2; |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
413 |
t->mtime = ambiguous_time; |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
414 |
return (PyObject *)t; |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
415 |
}; |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
416 |
|
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
417 |
/* constructor to help legacy API to build a new "possibly" item |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
418 |
|
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
419 |
Should eventually be removed */ |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
420 |
static PyObject *dirstate_item_new_possibly_dirty(PyTypeObject *subtype) |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
421 |
{ |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
422 |
/* We do all the initialization here and not a tp_init function because |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
423 |
* dirstate_item is immutable. */ |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
424 |
dirstateItemObject *t; |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
425 |
t = (dirstateItemObject *)subtype->tp_alloc(subtype, 1); |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
426 |
if (!t) { |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
427 |
return NULL; |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
428 |
} |
47948
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
429 |
t->flags = (dirstate_flag_wc_tracked | dirstate_flag_p1_tracked | |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
430 |
dirstate_flag_possibly_dirty); |
47905
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
431 |
t->mode = 0; |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
432 |
t->size = dirstate_v1_nonnormal; |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
433 |
t->mtime = ambiguous_time; |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
434 |
return (PyObject *)t; |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
435 |
}; |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
436 |
|
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
437 |
/* constructor to help legacy API to build a new "normal" item |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
438 |
|
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
439 |
Should eventually be removed */ |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
440 |
static PyObject *dirstate_item_new_normal(PyTypeObject *subtype, PyObject *args) |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
441 |
{ |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
442 |
/* We do all the initialization here and not a tp_init function because |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
443 |
* dirstate_item is immutable. */ |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
444 |
dirstateItemObject *t; |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
445 |
int size, mode, mtime; |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
446 |
if (!PyArg_ParseTuple(args, "iii", &mode, &size, &mtime)) { |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
447 |
return NULL; |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
448 |
} |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
449 |
|
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
450 |
t = (dirstateItemObject *)subtype->tp_alloc(subtype, 1); |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
451 |
if (!t) { |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
452 |
return NULL; |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
453 |
} |
47948
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
454 |
t->flags = (dirstate_flag_wc_tracked | dirstate_flag_p1_tracked); |
47905
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
455 |
t->mode = mode; |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
456 |
t->size = size; |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
457 |
t->mtime = mtime; |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
458 |
return (PyObject *)t; |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
459 |
}; |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
460 |
|
47666
e53256a9f9c5
dirstate-item: add a `set_possibly_dirty` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47665
diff
changeset
|
461 |
/* This means the next status call will have to actually check its content |
e53256a9f9c5
dirstate-item: add a `set_possibly_dirty` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47665
diff
changeset
|
462 |
to make sure it is correct. */ |
e53256a9f9c5
dirstate-item: add a `set_possibly_dirty` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47665
diff
changeset
|
463 |
static PyObject *dirstate_item_set_possibly_dirty(dirstateItemObject *self) |
e53256a9f9c5
dirstate-item: add a `set_possibly_dirty` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47665
diff
changeset
|
464 |
{ |
47976
2018753014be
dirstate: fix compilation warnings in `dirstate_item_set_possibly_dirty()`
Martin von Zweigbergk <martinvonz@google.com>
parents:
47975
diff
changeset
|
465 |
self->flags |= dirstate_flag_possibly_dirty; |
2018753014be
dirstate: fix compilation warnings in `dirstate_item_set_possibly_dirty()`
Martin von Zweigbergk <martinvonz@google.com>
parents:
47975
diff
changeset
|
466 |
Py_RETURN_NONE; |
47666
e53256a9f9c5
dirstate-item: add a `set_possibly_dirty` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47665
diff
changeset
|
467 |
} |
e53256a9f9c5
dirstate-item: add a `set_possibly_dirty` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47665
diff
changeset
|
468 |
|
47974
4e6f27230aee
dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47948
diff
changeset
|
469 |
/* See docstring of the python implementation for details */ |
4e6f27230aee
dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47948
diff
changeset
|
470 |
static PyObject *dirstate_item_set_clean(dirstateItemObject *self, |
4e6f27230aee
dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47948
diff
changeset
|
471 |
PyObject *args) |
4e6f27230aee
dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47948
diff
changeset
|
472 |
{ |
4e6f27230aee
dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47948
diff
changeset
|
473 |
int size, mode, mtime; |
4e6f27230aee
dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47948
diff
changeset
|
474 |
if (!PyArg_ParseTuple(args, "iii", &mode, &size, &mtime)) { |
4e6f27230aee
dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47948
diff
changeset
|
475 |
return NULL; |
4e6f27230aee
dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47948
diff
changeset
|
476 |
} |
4e6f27230aee
dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47948
diff
changeset
|
477 |
self->flags = dirstate_flag_wc_tracked | dirstate_flag_p1_tracked; |
4e6f27230aee
dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47948
diff
changeset
|
478 |
self->mode = mode; |
4e6f27230aee
dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47948
diff
changeset
|
479 |
self->size = size; |
4e6f27230aee
dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47948
diff
changeset
|
480 |
self->mtime = mtime; |
4e6f27230aee
dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47948
diff
changeset
|
481 |
Py_RETURN_NONE; |
4e6f27230aee
dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47948
diff
changeset
|
482 |
} |
4e6f27230aee
dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47948
diff
changeset
|
483 |
|
47990
0d2a404f1932
dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47976
diff
changeset
|
484 |
static PyObject *dirstate_item_set_tracked(dirstateItemObject *self) |
0d2a404f1932
dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47976
diff
changeset
|
485 |
{ |
0d2a404f1932
dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47976
diff
changeset
|
486 |
self->flags |= dirstate_flag_wc_tracked; |
0d2a404f1932
dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47976
diff
changeset
|
487 |
self->flags |= dirstate_flag_possibly_dirty; |
0d2a404f1932
dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47976
diff
changeset
|
488 |
/* size = None on the python size turn into size = NON_NORMAL when |
0d2a404f1932
dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47976
diff
changeset
|
489 |
* accessed. So the next line is currently required, but a some future |
0d2a404f1932
dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47976
diff
changeset
|
490 |
* clean up would be welcome. */ |
0d2a404f1932
dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47976
diff
changeset
|
491 |
self->size = dirstate_v1_nonnormal; |
0d2a404f1932
dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47976
diff
changeset
|
492 |
Py_RETURN_NONE; |
0d2a404f1932
dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47976
diff
changeset
|
493 |
} |
0d2a404f1932
dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47976
diff
changeset
|
494 |
|
47890
3853e6ee160d
dirstatemap: replace `removefile` by an explicit `entry.set_untracked()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47686
diff
changeset
|
495 |
static PyObject *dirstate_item_set_untracked(dirstateItemObject *self) |
3853e6ee160d
dirstatemap: replace `removefile` by an explicit `entry.set_untracked()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47686
diff
changeset
|
496 |
{ |
47948
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
497 |
self->flags &= ~dirstate_flag_wc_tracked; |
47890
3853e6ee160d
dirstatemap: replace `removefile` by an explicit `entry.set_untracked()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47686
diff
changeset
|
498 |
self->mode = 0; |
3853e6ee160d
dirstatemap: replace `removefile` by an explicit `entry.set_untracked()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47686
diff
changeset
|
499 |
self->mtime = 0; |
47948
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
500 |
self->size = 0; |
47890
3853e6ee160d
dirstatemap: replace `removefile` by an explicit `entry.set_untracked()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47686
diff
changeset
|
501 |
Py_RETURN_NONE; |
3853e6ee160d
dirstatemap: replace `removefile` by an explicit `entry.set_untracked()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47686
diff
changeset
|
502 |
} |
3853e6ee160d
dirstatemap: replace `removefile` by an explicit `entry.set_untracked()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47686
diff
changeset
|
503 |
|
48060
a660d8a53267
dirstate: use a new `drop_merge_data` in `setparent`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48044
diff
changeset
|
504 |
static PyObject *dirstate_item_drop_merge_data(dirstateItemObject *self) |
a660d8a53267
dirstate: use a new `drop_merge_data` in `setparent`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48044
diff
changeset
|
505 |
{ |
a660d8a53267
dirstate: use a new `drop_merge_data` in `setparent`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48044
diff
changeset
|
506 |
if (dirstate_item_c_merged(self) || dirstate_item_c_from_p2(self)) { |
a660d8a53267
dirstate: use a new `drop_merge_data` in `setparent`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48044
diff
changeset
|
507 |
if (dirstate_item_c_merged(self)) { |
a660d8a53267
dirstate: use a new `drop_merge_data` in `setparent`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48044
diff
changeset
|
508 |
self->flags |= dirstate_flag_p1_tracked; |
a660d8a53267
dirstate: use a new `drop_merge_data` in `setparent`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48044
diff
changeset
|
509 |
} else { |
a660d8a53267
dirstate: use a new `drop_merge_data` in `setparent`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48044
diff
changeset
|
510 |
self->flags &= ~dirstate_flag_p1_tracked; |
a660d8a53267
dirstate: use a new `drop_merge_data` in `setparent`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48044
diff
changeset
|
511 |
} |
a660d8a53267
dirstate: use a new `drop_merge_data` in `setparent`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48044
diff
changeset
|
512 |
self->flags &= |
a660d8a53267
dirstate: use a new `drop_merge_data` in `setparent`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48044
diff
changeset
|
513 |
~(dirstate_flag_merged | dirstate_flag_clean_p1 | |
a660d8a53267
dirstate: use a new `drop_merge_data` in `setparent`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48044
diff
changeset
|
514 |
dirstate_flag_clean_p2 | dirstate_flag_p2_tracked); |
a660d8a53267
dirstate: use a new `drop_merge_data` in `setparent`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48044
diff
changeset
|
515 |
self->flags |= dirstate_flag_possibly_dirty; |
a660d8a53267
dirstate: use a new `drop_merge_data` in `setparent`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48044
diff
changeset
|
516 |
self->mode = 0; |
a660d8a53267
dirstate: use a new `drop_merge_data` in `setparent`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48044
diff
changeset
|
517 |
self->mtime = 0; |
a660d8a53267
dirstate: use a new `drop_merge_data` in `setparent`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48044
diff
changeset
|
518 |
/* size = None on the python size turn into size = NON_NORMAL |
a660d8a53267
dirstate: use a new `drop_merge_data` in `setparent`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48044
diff
changeset
|
519 |
* when accessed. So the next line is currently required, but a |
a660d8a53267
dirstate: use a new `drop_merge_data` in `setparent`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48044
diff
changeset
|
520 |
* some future clean up would be welcome. */ |
a660d8a53267
dirstate: use a new `drop_merge_data` in `setparent`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48044
diff
changeset
|
521 |
self->size = dirstate_v1_nonnormal; |
a660d8a53267
dirstate: use a new `drop_merge_data` in `setparent`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48044
diff
changeset
|
522 |
} |
a660d8a53267
dirstate: use a new `drop_merge_data` in `setparent`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48044
diff
changeset
|
523 |
Py_RETURN_NONE; |
a660d8a53267
dirstate: use a new `drop_merge_data` in `setparent`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48044
diff
changeset
|
524 |
} |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
525 |
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
|
526 |
{"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
|
527 |
"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
|
528 |
{"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
|
529 |
"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
|
530 |
{"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
|
531 |
"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
|
532 |
{"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
|
533 |
"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
|
534 |
{"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
|
535 |
"True if the stored mtime would be ambiguous with the current time"}, |
47892
32aa80a8d162
dirstate-item: fix the declaration of the Cext `from_v1_meth`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47891
diff
changeset
|
536 |
{"from_v1_data", (PyCFunction)dirstate_item_from_v1_meth, |
32aa80a8d162
dirstate-item: fix the declaration of the Cext `from_v1_meth`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47891
diff
changeset
|
537 |
METH_VARARGS | METH_CLASS, "build a new DirstateItem object from V1 data"}, |
47905
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
538 |
{"new_added", (PyCFunction)dirstate_item_new_added, |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
539 |
METH_NOARGS | METH_CLASS, |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
540 |
"constructor to help legacy API to build a new \"added\" item"}, |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
541 |
{"new_merged", (PyCFunction)dirstate_item_new_merged, |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
542 |
METH_NOARGS | METH_CLASS, |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
543 |
"constructor to help legacy API to build a new \"merged\" item"}, |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
544 |
{"new_from_p2", (PyCFunction)dirstate_item_new_from_p2, |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
545 |
METH_NOARGS | METH_CLASS, |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
546 |
"constructor to help legacy API to build a new \"from_p2\" item"}, |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
547 |
{"new_possibly_dirty", (PyCFunction)dirstate_item_new_possibly_dirty, |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
548 |
METH_NOARGS | METH_CLASS, |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
549 |
"constructor to help legacy API to build a new \"possibly_dirty\" item"}, |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
550 |
{"new_normal", (PyCFunction)dirstate_item_new_normal, |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
551 |
METH_VARARGS | METH_CLASS, |
c0d6a59a7704
dirstate-item: add dedicated "legacy" constructor for `addfile` case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47895
diff
changeset
|
552 |
"constructor to help legacy API to build a new \"normal\" item"}, |
47666
e53256a9f9c5
dirstate-item: add a `set_possibly_dirty` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47665
diff
changeset
|
553 |
{"set_possibly_dirty", (PyCFunction)dirstate_item_set_possibly_dirty, |
e53256a9f9c5
dirstate-item: add a `set_possibly_dirty` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47665
diff
changeset
|
554 |
METH_NOARGS, "mark a file as \"possibly dirty\""}, |
47974
4e6f27230aee
dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47948
diff
changeset
|
555 |
{"set_clean", (PyCFunction)dirstate_item_set_clean, METH_VARARGS, |
4e6f27230aee
dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47948
diff
changeset
|
556 |
"mark a file as \"clean\""}, |
47990
0d2a404f1932
dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47976
diff
changeset
|
557 |
{"set_tracked", (PyCFunction)dirstate_item_set_tracked, METH_NOARGS, |
0d2a404f1932
dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47976
diff
changeset
|
558 |
"mark a file as \"tracked\""}, |
47890
3853e6ee160d
dirstatemap: replace `removefile` by an explicit `entry.set_untracked()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47686
diff
changeset
|
559 |
{"set_untracked", (PyCFunction)dirstate_item_set_untracked, METH_NOARGS, |
3853e6ee160d
dirstatemap: replace `removefile` by an explicit `entry.set_untracked()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47686
diff
changeset
|
560 |
"mark a file as \"untracked\""}, |
48060
a660d8a53267
dirstate: use a new `drop_merge_data` in `setparent`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48044
diff
changeset
|
561 |
{"drop_merge_data", (PyCFunction)dirstate_item_drop_merge_data, METH_NOARGS, |
a660d8a53267
dirstate: use a new `drop_merge_data` in `setparent`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48044
diff
changeset
|
562 |
"remove all \"merge-only\" from a DirstateItem"}, |
47509
80dc1d452993
dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47268
diff
changeset
|
563 |
{NULL} /* Sentinel */ |
80dc1d452993
dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47268
diff
changeset
|
564 |
}; |
80dc1d452993
dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47268
diff
changeset
|
565 |
|
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
566 |
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
|
567 |
{ |
47947
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
568 |
return PyInt_FromLong(dirstate_item_c_v1_mode(self)); |
47536
8e4b9fe31334
dirstate-entry: add a `mode` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47532
diff
changeset
|
569 |
}; |
8e4b9fe31334
dirstate-entry: add a `mode` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47532
diff
changeset
|
570 |
|
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
571 |
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
|
572 |
{ |
47947
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
573 |
return PyInt_FromLong(dirstate_item_c_v1_size(self)); |
47537
0e5800c88eb4
dirstate-entry: add a `size` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47536
diff
changeset
|
574 |
}; |
0e5800c88eb4
dirstate-entry: add a `size` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47536
diff
changeset
|
575 |
|
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
576 |
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
|
577 |
{ |
47947
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
578 |
return PyInt_FromLong(dirstate_item_c_v1_mtime(self)); |
47538
77fce401a2bb
dirstate-entry: add a `mtime` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47537
diff
changeset
|
579 |
}; |
77fce401a2bb
dirstate-entry: add a `mtime` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47537
diff
changeset
|
580 |
|
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
581 |
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
|
582 |
{ |
47947
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
583 |
char state = dirstate_item_c_v1_state(self); |
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
584 |
return PyBytes_FromStringAndSize(&state, 1); |
47512
769037a279ec
dirstate-entry: add a `state` property (and use it)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47509
diff
changeset
|
585 |
}; |
769037a279ec
dirstate-entry: add a `state` property (and use it)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47509
diff
changeset
|
586 |
|
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
587 |
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
|
588 |
{ |
47947
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
589 |
if (dirstate_item_c_tracked(self)) { |
47531
f5b8f0b9c129
dirstate-entry: add a `tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47526
diff
changeset
|
590 |
Py_RETURN_TRUE; |
f5b8f0b9c129
dirstate-entry: add a `tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47526
diff
changeset
|
591 |
} else { |
f5b8f0b9c129
dirstate-entry: add a `tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47526
diff
changeset
|
592 |
Py_RETURN_FALSE; |
f5b8f0b9c129
dirstate-entry: add a `tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47526
diff
changeset
|
593 |
} |
f5b8f0b9c129
dirstate-entry: add a `tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47526
diff
changeset
|
594 |
}; |
f5b8f0b9c129
dirstate-entry: add a `tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47526
diff
changeset
|
595 |
|
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
596 |
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
|
597 |
{ |
47947
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
598 |
if (dirstate_item_c_added(self)) { |
47526
8bcae9bf9e8d
dirstate-entry: add a `added` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47517
diff
changeset
|
599 |
Py_RETURN_TRUE; |
8bcae9bf9e8d
dirstate-entry: add a `added` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47517
diff
changeset
|
600 |
} else { |
8bcae9bf9e8d
dirstate-entry: add a `added` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47517
diff
changeset
|
601 |
Py_RETURN_FALSE; |
8bcae9bf9e8d
dirstate-entry: add a `added` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47517
diff
changeset
|
602 |
} |
8bcae9bf9e8d
dirstate-entry: add a `added` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47517
diff
changeset
|
603 |
}; |
8bcae9bf9e8d
dirstate-entry: add a `added` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47517
diff
changeset
|
604 |
|
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
605 |
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
|
606 |
{ |
47947
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
607 |
if (dirstate_item_c_merged(self)) { |
47513
10e740292dff
dirstate-entry: add a `merged` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47512
diff
changeset
|
608 |
Py_RETURN_TRUE; |
10e740292dff
dirstate-entry: add a `merged` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47512
diff
changeset
|
609 |
} else { |
10e740292dff
dirstate-entry: add a `merged` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47512
diff
changeset
|
610 |
Py_RETURN_FALSE; |
10e740292dff
dirstate-entry: add a `merged` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47512
diff
changeset
|
611 |
} |
10e740292dff
dirstate-entry: add a `merged` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47512
diff
changeset
|
612 |
}; |
10e740292dff
dirstate-entry: add a `merged` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47512
diff
changeset
|
613 |
|
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
614 |
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
|
615 |
{ |
47947
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
616 |
if (dirstate_item_c_from_p2(self)) { |
47514
559aee84b889
dirstate-entry: add a `from_p2` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47513
diff
changeset
|
617 |
Py_RETURN_TRUE; |
559aee84b889
dirstate-entry: add a `from_p2` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47513
diff
changeset
|
618 |
} else { |
559aee84b889
dirstate-entry: add a `from_p2` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47513
diff
changeset
|
619 |
Py_RETURN_FALSE; |
559aee84b889
dirstate-entry: add a `from_p2` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47513
diff
changeset
|
620 |
} |
559aee84b889
dirstate-entry: add a `from_p2` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47513
diff
changeset
|
621 |
}; |
559aee84b889
dirstate-entry: add a `from_p2` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47513
diff
changeset
|
622 |
|
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
623 |
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
|
624 |
{ |
47947
154e4dcac68c
dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47946
diff
changeset
|
625 |
if (dirstate_item_c_removed(self)) { |
47515
c94d3ff46fd5
dirstate-entry: add a `removed` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47514
diff
changeset
|
626 |
Py_RETURN_TRUE; |
c94d3ff46fd5
dirstate-entry: add a `removed` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47514
diff
changeset
|
627 |
} else { |
c94d3ff46fd5
dirstate-entry: add a `removed` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47514
diff
changeset
|
628 |
Py_RETURN_FALSE; |
c94d3ff46fd5
dirstate-entry: add a `removed` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47514
diff
changeset
|
629 |
} |
c94d3ff46fd5
dirstate-entry: add a `removed` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47514
diff
changeset
|
630 |
}; |
c94d3ff46fd5
dirstate-entry: add a `removed` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47514
diff
changeset
|
631 |
|
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
632 |
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
|
633 |
{"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
|
634 |
{"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
|
635 |
{"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
|
636 |
{"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
|
637 |
{"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
|
638 |
{"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
|
639 |
{"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
|
640 |
{"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
|
641 |
{"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
|
642 |
{NULL} /* Sentinel */ |
769037a279ec
dirstate-entry: add a `state` property (and use it)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47509
diff
changeset
|
643 |
}; |
769037a279ec
dirstate-entry: add a `state` property (and use it)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47509
diff
changeset
|
644 |
|
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
645 |
PyTypeObject dirstateItemType = { |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
646 |
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
|
647 |
"dirstate_tuple", /* tp_name */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
648 |
sizeof(dirstateItemObject), /* tp_basicsize */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
649 |
0, /* tp_itemsize */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
650 |
(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
|
651 |
0, /* tp_print */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
652 |
0, /* tp_getattr */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
653 |
0, /* tp_setattr */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
654 |
0, /* tp_compare */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
655 |
0, /* tp_repr */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
656 |
0, /* tp_as_number */ |
47925
ba9491be5e0c
dirstate-item: drop the deprecated __getitem__ variante
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47905
diff
changeset
|
657 |
0, /* tp_as_sequence */ |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
658 |
0, /* tp_as_mapping */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
659 |
0, /* tp_hash */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
660 |
0, /* tp_call */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
661 |
0, /* tp_str */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
662 |
0, /* tp_getattro */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
663 |
0, /* tp_setattro */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
664 |
0, /* tp_as_buffer */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
665 |
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
|
666 |
"dirstate tuple", /* tp_doc */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
667 |
0, /* tp_traverse */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
668 |
0, /* tp_clear */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
669 |
0, /* tp_richcompare */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
670 |
0, /* tp_weaklistoffset */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
671 |
0, /* tp_iter */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
672 |
0, /* tp_iternext */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
673 |
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
|
674 |
0, /* tp_members */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
675 |
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
|
676 |
0, /* tp_base */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
677 |
0, /* tp_dict */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
678 |
0, /* tp_descr_get */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
679 |
0, /* tp_descr_set */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
680 |
0, /* tp_dictoffset */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
681 |
0, /* tp_init */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
682 |
0, /* tp_alloc */ |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
683 |
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
|
684 |
}; |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
685 |
|
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
686 |
static PyObject *parse_dirstate(PyObject *self, PyObject *args) |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
687 |
{ |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
688 |
PyObject *dmap, *cmap, *parents = NULL, *ret = NULL; |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
689 |
PyObject *fname = NULL, *cname = NULL, *entry = NULL; |
20167
09e41ac6289d
mpatch: rewrite pointer overflow checks
Matt Mackall <mpm@selenic.com>
parents:
20109
diff
changeset
|
690 |
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
|
691 |
int mode, size, mtime; |
42068
896b19d12c08
cext: make parsers.c PY_SSIZE_T_CLEAN
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41336
diff
changeset
|
692 |
unsigned int flen, pos = 40; |
896b19d12c08
cext: make parsers.c PY_SSIZE_T_CLEAN
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41336
diff
changeset
|
693 |
Py_ssize_t len = 40; |
896b19d12c08
cext: make parsers.c PY_SSIZE_T_CLEAN
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41336
diff
changeset
|
694 |
Py_ssize_t readlen; |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
695 |
|
36620
186c6df3a373
py3: bulk-replace 'const char*' format specifier passed to PyArg_ParseTuple*()
Yuya Nishihara <yuya@tcha.org>
parents:
36619
diff
changeset
|
696 |
if (!PyArg_ParseTuple( |
186c6df3a373
py3: bulk-replace 'const char*' format specifier passed to PyArg_ParseTuple*()
Yuya Nishihara <yuya@tcha.org>
parents:
36619
diff
changeset
|
697 |
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
|
698 |
&PyDict_Type, &dmap, &PyDict_Type, &cmap, &str, &readlen)) { |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
699 |
goto quit; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
700 |
} |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
701 |
|
22403
41e9d58ec56f
parsers: avoid signed/unsigned comparison mismatch
Henrik Stuart <hg@hstuart.dk>
parents:
22402
diff
changeset
|
702 |
len = readlen; |
41e9d58ec56f
parsers: avoid signed/unsigned comparison mismatch
Henrik Stuart <hg@hstuart.dk>
parents:
22402
diff
changeset
|
703 |
|
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
704 |
/* 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
|
705 |
if (len < 40) { |
34862
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
706 |
PyErr_SetString(PyExc_ValueError, |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
707 |
"too little data for parents"); |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
708 |
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
|
709 |
} |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
710 |
|
42096
509a0477b3a6
cext: cast s# arguments of Py_BuildValue() to Py_ssize_t
Yuya Nishihara <yuya@tcha.org>
parents:
42068
diff
changeset
|
711 |
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
|
712 |
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
|
713 |
if (!parents) { |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
714 |
goto quit; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
715 |
} |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
716 |
|
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
717 |
/* read filenames */ |
20167
09e41ac6289d
mpatch: rewrite pointer overflow checks
Matt Mackall <mpm@selenic.com>
parents:
20109
diff
changeset
|
718 |
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
|
719 |
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
|
720 |
PyErr_SetString(PyExc_ValueError, |
34862
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
721 |
"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
|
722 |
goto quit; |
f5e8cb813a4d
parsers: fix parse_dirstate to check len before unpacking header (issue4979)
Yuya Nishihara <yuya@tcha.org>
parents:
26872
diff
changeset
|
723 |
} |
20167
09e41ac6289d
mpatch: rewrite pointer overflow checks
Matt Mackall <mpm@selenic.com>
parents:
20109
diff
changeset
|
724 |
cur = str + pos; |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
725 |
/* unpack header */ |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
726 |
state = *cur; |
16437
d126a0d16856
util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents:
16414
diff
changeset
|
727 |
mode = getbe32(cur + 1); |
d126a0d16856
util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents:
16414
diff
changeset
|
728 |
size = getbe32(cur + 5); |
d126a0d16856
util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents:
16414
diff
changeset
|
729 |
mtime = getbe32(cur + 9); |
d126a0d16856
util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents:
16414
diff
changeset
|
730 |
flen = getbe32(cur + 13); |
20167
09e41ac6289d
mpatch: rewrite pointer overflow checks
Matt Mackall <mpm@selenic.com>
parents:
20109
diff
changeset
|
731 |
pos += 17; |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
732 |
cur += 17; |
20316
40f08c31844c
parsers: fix 'unsigned expression is always true' warning (issue4142)
David Soria Parra <davidsp@fb.com>
parents:
20169
diff
changeset
|
733 |
if (flen > len - pos) { |
34862
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
734 |
PyErr_SetString(PyExc_ValueError, |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
735 |
"overflow in dirstate"); |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
736 |
goto quit; |
7174
4da87407b845
parsers.c: fix integer overflows
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7168
diff
changeset
|
737 |
} |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
738 |
|
47665
a4443f66be6a
dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47539
diff
changeset
|
739 |
entry = (PyObject *)dirstate_item_from_v1_data(state, mode, |
a4443f66be6a
dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47539
diff
changeset
|
740 |
size, mtime); |
48027
13efd8fdc55f
dirstate: fix parse_dirstate() to error out if NULL entry created
Yuya Nishihara <yuya@tcha.org>
parents:
48025
diff
changeset
|
741 |
if (!entry) |
13efd8fdc55f
dirstate: fix parse_dirstate() to error out if NULL entry created
Yuya Nishihara <yuya@tcha.org>
parents:
48025
diff
changeset
|
742 |
goto quit; |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
743 |
cpos = memchr(cur, 0, flen); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
744 |
if (cpos) { |
11361
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
745 |
fname = PyBytes_FromStringAndSize(cur, cpos - cur); |
34862
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
746 |
cname = PyBytes_FromStringAndSize( |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
747 |
cpos + 1, flen - (cpos - cur) - 1); |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
748 |
if (!fname || !cname || |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
749 |
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
|
750 |
PyDict_SetItem(dmap, fname, entry) == -1) { |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
751 |
goto quit; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
752 |
} |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
753 |
Py_DECREF(cname); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
754 |
} else { |
11361
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
755 |
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
|
756 |
if (!fname || |
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
757 |
PyDict_SetItem(dmap, fname, entry) == -1) { |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
758 |
goto quit; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
759 |
} |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
760 |
} |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
761 |
Py_DECREF(fname); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
762 |
Py_DECREF(entry); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
763 |
fname = cname = entry = NULL; |
20167
09e41ac6289d
mpatch: rewrite pointer overflow checks
Matt Mackall <mpm@selenic.com>
parents:
20109
diff
changeset
|
764 |
pos += flen; |
7093
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
765 |
} |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
766 |
|
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
767 |
ret = parents; |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
768 |
Py_INCREF(ret); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
769 |
quit: |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
770 |
Py_XDECREF(fname); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
771 |
Py_XDECREF(cname); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
772 |
Py_XDECREF(entry); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
773 |
Py_XDECREF(parents); |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
774 |
return ret; |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
775 |
} |
16bafcebd3d1
dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents:
7092
diff
changeset
|
776 |
|
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
777 |
/* |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
778 |
* 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
|
779 |
*/ |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
780 |
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
|
781 |
{ |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
782 |
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
|
783 |
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
|
784 |
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
|
785 |
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
|
786 |
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
|
787 |
int now; |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
788 |
|
39422
adacefb0b7ea
dirstate: use tuple interface to fix leak in pack_dirstate()
Yuya Nishihara <yuya@tcha.org>
parents:
37968
diff
changeset
|
789 |
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
|
790 |
&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
|
791 |
&now)) { |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
792 |
return NULL; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
793 |
} |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
794 |
|
39422
adacefb0b7ea
dirstate: use tuple interface to fix leak in pack_dirstate()
Yuya Nishihara <yuya@tcha.org>
parents:
37968
diff
changeset
|
795 |
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
|
796 |
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
|
797 |
return NULL; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
798 |
} |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
799 |
|
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
800 |
/* 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
|
801 |
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
|
802 |
PyObject *c; |
30100
c5afe5531709
parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30090
diff
changeset
|
803 |
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
|
804 |
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
|
805 |
goto bail; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
806 |
} |
30100
c5afe5531709
parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30090
diff
changeset
|
807 |
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
|
808 |
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
|
809 |
if (c) { |
30100
c5afe5531709
parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30090
diff
changeset
|
810 |
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
|
811 |
PyErr_SetString(PyExc_TypeError, |
34862
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
812 |
"expected string key"); |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
813 |
goto bail; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
814 |
} |
30100
c5afe5531709
parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30090
diff
changeset
|
815 |
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
|
816 |
} |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
817 |
} |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
818 |
|
30100
c5afe5531709
parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30090
diff
changeset
|
819 |
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
|
820 |
if (packobj == NULL) { |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
821 |
goto bail; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
822 |
} |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
823 |
|
30100
c5afe5531709
parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30090
diff
changeset
|
824 |
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
|
825 |
|
39422
adacefb0b7ea
dirstate: use tuple interface to fix leak in pack_dirstate()
Yuya Nishihara <yuya@tcha.org>
parents:
37968
diff
changeset
|
826 |
pn = PyTuple_GET_ITEM(pl, 0); |
30100
c5afe5531709
parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30090
diff
changeset
|
827 |
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
|
828 |
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
|
829 |
goto bail; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
830 |
} |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
831 |
memcpy(p, s, l); |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
832 |
p += 20; |
39422
adacefb0b7ea
dirstate: use tuple interface to fix leak in pack_dirstate()
Yuya Nishihara <yuya@tcha.org>
parents:
37968
diff
changeset
|
833 |
pn = PyTuple_GET_ITEM(pl, 1); |
30100
c5afe5531709
parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30090
diff
changeset
|
834 |
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
|
835 |
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
|
836 |
goto bail; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
837 |
} |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
838 |
memcpy(p, s, l); |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
839 |
p += 20; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
840 |
|
34862
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
841 |
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
|
842 |
dirstateItemObject *tuple; |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
843 |
char state; |
26774
04ab2348efd1
parsers: correct type of temporary variables for dirstate tuple fields
Yuya Nishihara <yuya@tcha.org>
parents:
26630
diff
changeset
|
844 |
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
|
845 |
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
|
846 |
PyObject *o; |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
847 |
char *t; |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
848 |
|
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
849 |
if (!dirstate_tuple_check(v)) { |
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
850 |
PyErr_SetString(PyExc_TypeError, |
34862
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
851 |
"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
|
852 |
goto bail; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
853 |
} |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
854 |
tuple = (dirstateItemObject *)v; |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
855 |
|
47948
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
856 |
state = dirstate_item_c_v1_state(tuple); |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
857 |
mode = dirstate_item_c_v1_mode(tuple); |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
858 |
size = dirstate_item_c_v1_size(tuple); |
83f0e93ec34b
dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47947
diff
changeset
|
859 |
mtime = dirstate_item_c_v1_mtime(tuple); |
26630
3111b45a2bbf
parsers: make pack_dirstate take now in integer for consistency
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26591
diff
changeset
|
860 |
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
|
861 |
/* 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
|
862 |
* 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
|
863 |
mtime = -1; |
47945
3337eec29d5b
dirstate-item: `dirstate_item_from_v1_data` replaces make_dirstate_item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47925
diff
changeset
|
864 |
mtime_unset = (PyObject *)dirstate_item_from_v1_data( |
34862
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
865 |
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
|
866 |
if (!mtime_unset) { |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
867 |
goto bail; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
868 |
} |
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
869 |
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
|
870 |
goto bail; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
871 |
} |
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
|
872 |
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
|
873 |
mtime_unset = NULL; |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
874 |
} |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
21807
diff
changeset
|
875 |
*p++ = state; |
26774
04ab2348efd1
parsers: correct type of temporary variables for dirstate tuple fields
Yuya Nishihara <yuya@tcha.org>
parents:
26630
diff
changeset
|
876 |
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
|
877 |
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
|
878 |
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
|
879 |
t = p + 12; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
880 |
p += 16; |
30100
c5afe5531709
parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30090
diff
changeset
|
881 |
len = PyBytes_GET_SIZE(k); |
c5afe5531709
parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30090
diff
changeset
|
882 |
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
|
883 |
p += len; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
884 |
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
|
885 |
if (o) { |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
886 |
*p++ = '\0'; |
30100
c5afe5531709
parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30090
diff
changeset
|
887 |
l = PyBytes_GET_SIZE(o); |
c5afe5531709
parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30090
diff
changeset
|
888 |
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
|
889 |
p += l; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
890 |
len += l + 1; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
891 |
} |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
892 |
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
|
893 |
} |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
894 |
|
30100
c5afe5531709
parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30090
diff
changeset
|
895 |
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
|
896 |
if (pos != nbytes) { |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
897 |
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
|
898 |
(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
|
899 |
goto bail; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
900 |
} |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
901 |
|
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
902 |
return packobj; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
903 |
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
|
904 |
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
|
905 |
Py_XDECREF(packobj); |
23946
f3e94aa6e182
parsers: don't leak a tuple in pack_dirstate
Augie Fackler <augie@google.com>
parents:
23945
diff
changeset
|
906 |
Py_XDECREF(v); |
16955
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
907 |
return NULL; |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
908 |
} |
92e1c64ba0d4
parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents:
16863
diff
changeset
|
909 |
|
24017
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
910 |
#define BUMPED_FIX 1 |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
911 |
#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
|
912 |
#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
|
913 |
|
34862
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
914 |
static PyObject *readshas(const char *source, unsigned char num, |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
915 |
Py_ssize_t hashwidth) |
24017
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
916 |
{ |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
917 |
int i; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
918 |
PyObject *list = PyTuple_New(num); |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
919 |
if (list == NULL) { |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
920 |
return NULL; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
921 |
} |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
922 |
for (i = 0; i < num; i++) { |
30100
c5afe5531709
parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30090
diff
changeset
|
923 |
PyObject *hash = PyBytes_FromStringAndSize(source, hashwidth); |
24017
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
924 |
if (hash == NULL) { |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
925 |
Py_DECREF(list); |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
926 |
return NULL; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
927 |
} |
26213
4d6cdea33f37
parsers: use PyTuple_SET_ITEM() to fill new marker tuples
Yuya Nishihara <yuya@tcha.org>
parents:
26107
diff
changeset
|
928 |
PyTuple_SET_ITEM(list, i, hash); |
24017
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
929 |
source += hashwidth; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
930 |
} |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
931 |
return list; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
932 |
} |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
933 |
|
26591
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
934 |
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
|
935 |
uint32_t *msize) |
24017
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
936 |
{ |
26591
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
937 |
const char *data = databegin; |
24017
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
938 |
const char *meta; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
939 |
|
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
940 |
double mtime; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
941 |
int16_t tz; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
942 |
uint16_t flags; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
943 |
unsigned char nsuccs, nparents, nmetadata; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
944 |
Py_ssize_t hashwidth = 20; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
945 |
|
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
946 |
PyObject *prec = NULL, *parents = NULL, *succs = NULL; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
947 |
PyObject *metadata = NULL, *ret = NULL; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
948 |
int i; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
949 |
|
26591
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
950 |
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
|
951 |
goto overflow; |
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
952 |
} |
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
953 |
|
24019
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
954 |
*msize = getbe32(data); |
24017
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
955 |
data += 4; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
956 |
mtime = getbefloat64(data); |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
957 |
data += 8; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
958 |
tz = getbeint16(data); |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
959 |
data += 2; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
960 |
flags = getbeuint16(data); |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
961 |
data += 2; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
962 |
|
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
963 |
if (flags & USING_SHA_256) { |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
964 |
hashwidth = 32; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
965 |
} |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
966 |
|
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
967 |
nsuccs = (unsigned char)(*data++); |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
968 |
nparents = (unsigned char)(*data++); |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
969 |
nmetadata = (unsigned char)(*data++); |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
970 |
|
26591
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
971 |
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
|
972 |
goto overflow; |
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
973 |
} |
34862
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
974 |
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
|
975 |
|
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
976 |
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
|
977 |
goto overflow; |
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
978 |
} |
30100
c5afe5531709
parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30090
diff
changeset
|
979 |
prec = PyBytes_FromStringAndSize(data, hashwidth); |
24017
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
980 |
data += hashwidth; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
981 |
if (prec == NULL) { |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
982 |
goto bail; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
983 |
} |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
984 |
|
26591
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
985 |
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
|
986 |
goto overflow; |
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
987 |
} |
24017
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
988 |
succs = readshas(data, nsuccs, hashwidth); |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
989 |
if (succs == NULL) { |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
990 |
goto bail; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
991 |
} |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
992 |
data += nsuccs * hashwidth; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
993 |
|
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
994 |
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
|
995 |
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
|
996 |
goto overflow; |
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
997 |
} |
24017
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
998 |
parents = readshas(data, nparents, hashwidth); |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
999 |
if (parents == NULL) { |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
1000 |
goto bail; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
1001 |
} |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
1002 |
data += nparents * hashwidth; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
1003 |
} else { |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
1004 |
parents = Py_None; |
31426
43a7dfbead0c
parsers: handle refcounting of "parents" consistently
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31292
diff
changeset
|
1005 |
Py_INCREF(parents); |
24017
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
1006 |
} |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
1007 |
|
26591
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
1008 |
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
|
1009 |
goto overflow; |
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
1010 |
} |
24017
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
1011 |
meta = data + (2 * nmetadata); |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
1012 |
metadata = PyTuple_New(nmetadata); |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
1013 |
if (metadata == NULL) { |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
1014 |
goto bail; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
1015 |
} |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
1016 |
for (i = 0; i < nmetadata; i++) { |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
1017 |
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
|
1018 |
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
|
1019 |
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
|
1020 |
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
|
1021 |
goto overflow; |
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
1022 |
} |
30100
c5afe5531709
parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30090
diff
changeset
|
1023 |
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
|
1024 |
meta += leftsize; |
30100
c5afe5531709
parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30090
diff
changeset
|
1025 |
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
|
1026 |
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
|
1027 |
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
|
1028 |
if (!left || !right || !tmp) { |
24017
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
1029 |
Py_XDECREF(left); |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
1030 |
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
|
1031 |
Py_XDECREF(tmp); |
24017
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
1032 |
goto bail; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
1033 |
} |
26214
46605888faf3
parsers: use PyTuple_New and SET_ITEM to construct metadata pair of markers
Yuya Nishihara <yuya@tcha.org>
parents:
26213
diff
changeset
|
1034 |
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
|
1035 |
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
|
1036 |
PyTuple_SET_ITEM(metadata, i, tmp); |
24017
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
1037 |
} |
34862
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
1038 |
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
|
1039 |
(int)tz * 60, parents); |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
1040 |
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
|
1041 |
|
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
1042 |
overflow: |
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
1043 |
PyErr_SetString(PyExc_ValueError, "overflow in obsstore"); |
24017
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
1044 |
bail: |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
1045 |
Py_XDECREF(prec); |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
1046 |
Py_XDECREF(succs); |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
1047 |
Py_XDECREF(metadata); |
31426
43a7dfbead0c
parsers: handle refcounting of "parents" consistently
Gregory Szorc <gregory.szorc@gmail.com>
parents:
31292
diff
changeset
|
1048 |
Py_XDECREF(parents); |
24017
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
1049 |
return ret; |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
1050 |
} |
72c9b5ae7278
parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents:
24004
diff
changeset
|
1051 |
|
34440
7ed0750c71a1
cext: wrap before brace for functions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34438
diff
changeset
|
1052 |
static PyObject *fm1readmarkers(PyObject *self, PyObject *args) |
7ed0750c71a1
cext: wrap before brace for functions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34438
diff
changeset
|
1053 |
{ |
26591
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
1054 |
const char *data, *dataend; |
42068
896b19d12c08
cext: make parsers.c PY_SSIZE_T_CLEAN
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41336
diff
changeset
|
1055 |
Py_ssize_t datalen, offset, stop; |
24019
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
1056 |
PyObject *markers = NULL; |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
1057 |
|
36620
186c6df3a373
py3: bulk-replace 'const char*' format specifier passed to PyArg_ParseTuple*()
Yuya Nishihara <yuya@tcha.org>
parents:
36619
diff
changeset
|
1058 |
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
|
1059 |
&offset, &stop)) { |
24019
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
1060 |
return NULL; |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
1061 |
} |
41016
5c68b617ba24
parsers: better bounds checking in fm1readmarkers
Augie Fackler <augie@google.com>
parents:
41011
diff
changeset
|
1062 |
if (offset < 0) { |
5c68b617ba24
parsers: better bounds checking in fm1readmarkers
Augie Fackler <augie@google.com>
parents:
41011
diff
changeset
|
1063 |
PyErr_SetString(PyExc_ValueError, |
5c68b617ba24
parsers: better bounds checking in fm1readmarkers
Augie Fackler <augie@google.com>
parents:
41011
diff
changeset
|
1064 |
"invalid negative offset in fm1readmarkers"); |
5c68b617ba24
parsers: better bounds checking in fm1readmarkers
Augie Fackler <augie@google.com>
parents:
41011
diff
changeset
|
1065 |
return NULL; |
5c68b617ba24
parsers: better bounds checking in fm1readmarkers
Augie Fackler <augie@google.com>
parents:
41011
diff
changeset
|
1066 |
} |
5c68b617ba24
parsers: better bounds checking in fm1readmarkers
Augie Fackler <augie@google.com>
parents:
41011
diff
changeset
|
1067 |
if (stop > datalen) { |
5c68b617ba24
parsers: better bounds checking in fm1readmarkers
Augie Fackler <augie@google.com>
parents:
41011
diff
changeset
|
1068 |
PyErr_SetString( |
5c68b617ba24
parsers: better bounds checking in fm1readmarkers
Augie Fackler <augie@google.com>
parents:
41011
diff
changeset
|
1069 |
PyExc_ValueError, |
5c68b617ba24
parsers: better bounds checking in fm1readmarkers
Augie Fackler <augie@google.com>
parents:
41011
diff
changeset
|
1070 |
"stop longer than data length in fm1readmarkers"); |
5c68b617ba24
parsers: better bounds checking in fm1readmarkers
Augie Fackler <augie@google.com>
parents:
41011
diff
changeset
|
1071 |
return NULL; |
5c68b617ba24
parsers: better bounds checking in fm1readmarkers
Augie Fackler <augie@google.com>
parents:
41011
diff
changeset
|
1072 |
} |
26591
042344313939
parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents:
26590
diff
changeset
|
1073 |
dataend = data + datalen; |
24019
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
1074 |
data += offset; |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
1075 |
markers = PyList_New(0); |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
1076 |
if (!markers) { |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
1077 |
return NULL; |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
1078 |
} |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
1079 |
while (offset < stop) { |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
1080 |
uint32_t msize; |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
1081 |
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
|
1082 |
PyObject *record = fm1readmarker(data, dataend, &msize); |
24019
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
1083 |
if (!record) { |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
1084 |
goto bail; |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
1085 |
} |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
1086 |
error = PyList_Append(markers, record); |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
1087 |
Py_DECREF(record); |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
1088 |
if (error) { |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
1089 |
goto bail; |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
1090 |
} |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
1091 |
data += msize; |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
1092 |
offset += msize; |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
1093 |
} |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
1094 |
return markers; |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
1095 |
bail: |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
1096 |
Py_DECREF(markers); |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
1097 |
return NULL; |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
1098 |
} |
26fbf07482b2
_fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents:
24017
diff
changeset
|
1099 |
|
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
1100 |
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
|
1101 |
|
17606
318fb32b980e
pathencode: new C module with fast encodedir() function
Adrian Buehlmann <adrian@cadifra.com>
parents:
17356
diff
changeset
|
1102 |
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
|
1103 |
PyObject *pathencode(PyObject *self, PyObject *args); |
18430
0459c6555f69
store: implement lowerencode in C
Bryan O'Sullivan <bryano@fb.com>
parents:
17616
diff
changeset
|
1104 |
PyObject *lowerencode(PyObject *self, PyObject *args); |
46708
358737abeeef
cext: add support for revlogv2
Raphaël Gomès <rgomes@octobus.net>
parents:
45131
diff
changeset
|
1105 |
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
|
1106 |
|
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
1107 |
static PyMethodDef methods[] = { |
34862
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
1108 |
{"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
|
1109 |
{"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
|
1110 |
{"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
|
1111 |
"parse a revlog index\n"}, |
34862
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
1112 |
{"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
|
1113 |
{"asciilower", asciilower, METH_VARARGS, "lowercase an ASCII string\n"}, |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
1114 |
{"asciiupper", asciiupper, METH_VARARGS, "uppercase an ASCII string\n"}, |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
1115 |
{"dict_new_presized", dict_new_presized, METH_VARARGS, |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
1116 |
"construct a dict with an expected size\n"}, |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
1117 |
{"make_file_foldmap", make_file_foldmap, METH_VARARGS, |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
1118 |
"make file foldmap\n"}, |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
1119 |
{"jsonescapeu8fast", jsonescapeu8fast, METH_VARARGS, |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
1120 |
"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
|
1121 |
{"encodedir", encodedir, METH_VARARGS, "encodedir a path\n"}, |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
1122 |
{"pathencode", pathencode, METH_VARARGS, "fncache-encode a path\n"}, |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
1123 |
{"lowerencode", lowerencode, METH_VARARGS, "lower-encode a path\n"}, |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
1124 |
{"fm1readmarkers", fm1readmarkers, METH_VARARGS, |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
1125 |
"parse v1 obsolete markers\n"}, |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
1126 |
{NULL, NULL}}; |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
1127 |
|
18900
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
18567
diff
changeset
|
1128 |
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
|
1129 |
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
|
1130 |
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
|
1131 |
|
47268
9d1a8829f959
revlog: signal which revlog index are compatible with Rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47249
diff
changeset
|
1132 |
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
|
1133 |
|
16363
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1134 |
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
|
1135 |
{ |
32360
af3ef002395d
parsers: add version to help detect breaking binary changes
Jun Wu <quark@fb.com>
parents:
31470
diff
changeset
|
1136 |
PyModule_AddIntConstant(mod, "version", version); |
af3ef002395d
parsers: add version to help detect breaking binary changes
Jun Wu <quark@fb.com>
parents:
31470
diff
changeset
|
1137 |
|
20742
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
1138 |
/* 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
|
1139 |
* 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
|
1140 |
* 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
|
1141 |
* 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
|
1142 |
* 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
|
1143 |
* 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
|
1144 |
* 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
|
1145 |
* 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
|
1146 |
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
|
1147 |
|
18900
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
18567
diff
changeset
|
1148 |
dirs_module_init(mod); |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
24032
diff
changeset
|
1149 |
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
|
1150 |
revlog_module_init(mod); |
18900
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
18567
diff
changeset
|
1151 |
|
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
1152 |
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
|
1153 |
return; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
1154 |
} |
47539
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
1155 |
Py_INCREF(&dirstateItemType); |
84391ddf4c78
dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47538
diff
changeset
|
1156 |
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
|
1157 |
} |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1158 |
|
20742
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
1159 |
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
|
1160 |
{ |
23943
5fb44983a696
parsers: don't leak references to sys et al in check_python_version
Augie Fackler <augie@google.com>
parents:
23942
diff
changeset
|
1161 |
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
|
1162 |
long hexversion; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
1163 |
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
|
1164 |
return -1; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
1165 |
} |
23943
5fb44983a696
parsers: don't leak references to sys et al in check_python_version
Augie Fackler <augie@google.com>
parents:
23942
diff
changeset
|
1166 |
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
|
1167 |
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
|
1168 |
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
|
1169 |
return -1; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
1170 |
} |
23943
5fb44983a696
parsers: don't leak references to sys et al in check_python_version
Augie Fackler <augie@google.com>
parents:
23942
diff
changeset
|
1171 |
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
|
1172 |
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
|
1173 |
/* 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
|
1174 |
* 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
|
1175 |
* 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
|
1176 |
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
|
1177 |
PyErr_Format(PyExc_ImportError, |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
1178 |
"%s: The Mercurial extension " |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
1179 |
"modules were compiled with Python " PY_VERSION |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
1180 |
", but " |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
1181 |
"Mercurial is currently using Python with " |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
1182 |
"sys.hexversion=%ld: " |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
1183 |
"Python %s\n at: %s", |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
1184 |
versionerrortext, hexversion, Py_GetVersion(), |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
1185 |
Py_GetProgramFullPath()); |
20742
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
1186 |
return -1; |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
1187 |
} |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
1188 |
return 0; |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
1189 |
} |
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
1190 |
|
11361
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
1191 |
#ifdef IS_PY3K |
34862
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
1192 |
static struct PyModuleDef parsers_module = {PyModuleDef_HEAD_INIT, "parsers", |
d92dc725223b
parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents:
34861
diff
changeset
|
1193 |
parsers_doc, -1, methods}; |
11361
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
1194 |
|
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
1195 |
PyMODINIT_FUNC PyInit_parsers(void) |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
1196 |
{ |
20797
e286ab22e461
parsers: fix compiler errors on MSVC 2008
Matt Harbison <matt_harbison@yahoo.com>
parents:
20742
diff
changeset
|
1197 |
PyObject *mod; |
e286ab22e461
parsers: fix compiler errors on MSVC 2008
Matt Harbison <matt_harbison@yahoo.com>
parents:
20742
diff
changeset
|
1198 |
|
20742
3681de20b0a7
parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
20555
diff
changeset
|
1199 |
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
|
1200 |
return NULL; |
20797
e286ab22e461
parsers: fix compiler errors on MSVC 2008
Matt Harbison <matt_harbison@yahoo.com>
parents:
20742
diff
changeset
|
1201 |
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
|
1202 |
module_init(mod); |
2cdd7e63211b
parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents:
15033
diff
changeset
|
1203 |
return mod; |
11361
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
1204 |
} |
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
1205 |
#else |
6389
0231f763ebc8
manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
1206 |
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
|
1207 |
{ |
20797
e286ab22e461
parsers: fix compiler errors on MSVC 2008
Matt Harbison <matt_harbison@yahoo.com>
parents:
20742
diff
changeset
|
1208 |
PyObject *mod; |
e286ab22e461
parsers: fix compiler errors on MSVC 2008
Matt Harbison <matt_harbison@yahoo.com>
parents:
20742
diff
changeset
|
1209 |
|
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
1210 |
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
|
1211 |
return; |
41336
763b45bc4483
cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents:
41016
diff
changeset
|
1212 |
} |
20797
e286ab22e461
parsers: fix compiler errors on MSVC 2008
Matt Harbison <matt_harbison@yahoo.com>
parents:
20742
diff
changeset
|
1213 |
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
|
1214 |
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
|
1215 |
} |
11361
3de3d670d2b6
parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents:
10449
diff
changeset
|
1216 |
#endif |