mercurial/cext/parsers.c
author Simon Sapin <simon.sapin@octobus.net>
Tue, 09 Nov 2021 19:09:57 +0100
changeset 48339 a2e278b5e265
parent 48327 3620ab28882d
child 48378 3d6eb119200d
permissions -rw-r--r--
rhg: [encode] and [decode] config sections are not supported Differential Revision: https://phab.mercurial-scm.org/D11761
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
48327
3620ab28882d cext: define S_IFLNK on Python 2.7 and Windows
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48280
diff changeset
    28
#else
3620ab28882d cext: define S_IFLNK on Python 2.7 and Windows
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48280
diff changeset
    29
/* Windows on Python 2.7 doesn't define S_IFLNK. Python 3+ defines via
3620ab28882d cext: define S_IFLNK on Python 2.7 and Windows
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48280
diff changeset
    30
 * pyport.h. */
3620ab28882d cext: define S_IFLNK on Python 2.7 and Windows
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48280
diff changeset
    31
#ifndef S_IFLNK
3620ab28882d cext: define S_IFLNK on Python 2.7 and Windows
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48280
diff changeset
    32
#define S_IFLNK 0120000
3620ab28882d cext: define S_IFLNK on Python 2.7 and Windows
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48280
diff changeset
    33
#endif
30112
9b6ff0f940ed parsers: move PyInt aliasing out of util.h
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30103
diff changeset
    34
#endif
9b6ff0f940ed parsers: move PyInt aliasing out of util.h
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30103
diff changeset
    35
32386
7640584e697c cext: mark constant variables
Yuya Nishihara <yuya@tcha.org>
parents: 32384
diff changeset
    36
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
    37
47514
559aee84b889 dirstate-entry: add a `from_p2` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47513
diff changeset
    38
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
    39
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
    40
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
    41
25584
72b2711f12ea parsers: add an API to create a new presized dict
Siddharth Agarwal <sid0@fb.com>
parents: 25583
diff changeset
    42
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
    43
{
72b2711f12ea parsers: add an API to create a new presized dict
Siddharth Agarwal <sid0@fb.com>
parents: 25583
diff changeset
    44
	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
    45
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 41016
diff changeset
    46
	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
    47
		return NULL;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 41016
diff changeset
    48
	}
25584
72b2711f12ea parsers: add an API to create a new presized dict
Siddharth Agarwal <sid0@fb.com>
parents: 25583
diff changeset
    49
72b2711f12ea parsers: add an API to create a new presized dict
Siddharth Agarwal <sid0@fb.com>
parents: 25583
diff changeset
    50
	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
    51
}
72b2711f12ea parsers: add an API to create a new presized dict
Siddharth Agarwal <sid0@fb.com>
parents: 25583
diff changeset
    52
47539
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
    53
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
    54
                                   PyObject *kwds)
21809
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 21807
diff changeset
    55
{
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 21807
diff changeset
    56
	/* 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
    57
	 * dirstate_item is immutable. */
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
    58
	dirstateItemObject *t;
47895
22c39f8acf78 dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47892
diff changeset
    59
	int wc_tracked;
22c39f8acf78 dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47892
diff changeset
    60
	int p1_tracked;
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
    61
	int p2_info;
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
    62
	int has_meaningful_data;
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
    63
	int has_meaningful_mtime;
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
    64
	int mode;
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
    65
	int size;
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
    66
	int mtime_s;
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
    67
	int mtime_ns;
47895
22c39f8acf78 dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47892
diff changeset
    68
	PyObject *parentfiledata;
48253
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48252
diff changeset
    69
	PyObject *fallback_exec;
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48252
diff changeset
    70
	PyObject *fallback_symlink;
47895
22c39f8acf78 dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47892
diff changeset
    71
	static char *keywords_name[] = {
48253
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48252
diff changeset
    72
	    "wc_tracked",          "p1_tracked",           "p2_info",
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48252
diff changeset
    73
	    "has_meaningful_data", "has_meaningful_mtime", "parentfiledata",
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48252
diff changeset
    74
	    "fallback_exec",       "fallback_symlink",     NULL,
47895
22c39f8acf78 dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47892
diff changeset
    75
	};
22c39f8acf78 dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47892
diff changeset
    76
	wc_tracked = 0;
22c39f8acf78 dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47892
diff changeset
    77
	p1_tracked = 0;
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
    78
	p2_info = 0;
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
    79
	has_meaningful_mtime = 1;
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
    80
	has_meaningful_data = 1;
47895
22c39f8acf78 dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47892
diff changeset
    81
	parentfiledata = Py_None;
48253
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48252
diff changeset
    82
	fallback_exec = Py_None;
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48252
diff changeset
    83
	fallback_symlink = Py_None;
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48252
diff changeset
    84
	if (!PyArg_ParseTupleAndKeywords(args, kwds, "|iiiiiOOO", keywords_name,
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48252
diff changeset
    85
	                                 &wc_tracked, &p1_tracked, &p2_info,
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48252
diff changeset
    86
	                                 &has_meaningful_data,
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48252
diff changeset
    87
	                                 &has_meaningful_mtime, &parentfiledata,
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48252
diff changeset
    88
	                                 &fallback_exec, &fallback_symlink)) {
47895
22c39f8acf78 dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47892
diff changeset
    89
		return NULL;
22c39f8acf78 dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47892
diff changeset
    90
	}
47539
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
    91
	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
    92
	if (!t) {
21809
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 21807
diff changeset
    93
		return NULL;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 41016
diff changeset
    94
	}
47948
83f0e93ec34b dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47947
diff changeset
    95
83f0e93ec34b dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47947
diff changeset
    96
	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
    97
	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
    98
		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
    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 (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
   101
		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
   102
	}
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   103
	if (p2_info) {
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   104
		t->flags |= dirstate_flag_p2_info;
47948
83f0e93ec34b dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47947
diff changeset
   105
	}
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   106
48253
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48252
diff changeset
   107
	if (fallback_exec != Py_None) {
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48252
diff changeset
   108
		t->flags |= dirstate_flag_has_fallback_exec;
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48252
diff changeset
   109
		if (PyObject_IsTrue(fallback_exec)) {
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48252
diff changeset
   110
			t->flags |= dirstate_flag_fallback_exec;
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48252
diff changeset
   111
		}
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48252
diff changeset
   112
	}
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48252
diff changeset
   113
	if (fallback_symlink != Py_None) {
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48252
diff changeset
   114
		t->flags |= dirstate_flag_has_fallback_symlink;
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48252
diff changeset
   115
		if (PyObject_IsTrue(fallback_symlink)) {
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48252
diff changeset
   116
			t->flags |= dirstate_flag_fallback_symlink;
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48252
diff changeset
   117
		}
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48252
diff changeset
   118
	}
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48252
diff changeset
   119
47948
83f0e93ec34b dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47947
diff changeset
   120
	if (parentfiledata != Py_None) {
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   121
		if (!PyArg_ParseTuple(parentfiledata, "ii(ii)", &mode, &size,
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   122
		                      &mtime_s, &mtime_ns)) {
47895
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
		}
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   125
	} else {
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   126
		has_meaningful_data = 0;
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   127
		has_meaningful_mtime = 0;
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   128
	}
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   129
	if (has_meaningful_data) {
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   130
		t->flags |= dirstate_flag_has_meaningful_data;
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   131
		t->mode = mode;
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   132
		t->size = size;
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   133
	} else {
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   134
		t->mode = 0;
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   135
		t->size = 0;
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   136
	}
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   137
	if (has_meaningful_mtime) {
48264
bb240915f69f dirstate-v2: adjust the meaning of directory flags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48262
diff changeset
   138
		t->flags |= dirstate_flag_has_mtime;
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   139
		t->mtime_s = mtime_s;
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   140
		t->mtime_ns = mtime_ns;
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   141
	} else {
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   142
		t->mtime_s = 0;
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   143
		t->mtime_ns = 0;
47895
22c39f8acf78 dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47892
diff changeset
   144
	}
21809
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 21807
diff changeset
   145
	return (PyObject *)t;
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 21807
diff changeset
   146
}
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 21807
diff changeset
   147
47539
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   148
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
   149
{
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 21807
diff changeset
   150
	PyObject_Del(o);
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 21807
diff changeset
   151
}
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 21807
diff changeset
   152
47947
154e4dcac68c dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
   153
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
   154
{
47948
83f0e93ec34b dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47947
diff changeset
   155
	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
   156
}
154e4dcac68c dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
   157
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   158
static inline bool dirstate_item_c_any_tracked(dirstateItemObject *self)
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   159
{
48250
1730b2fceaa1 dirstate-v2: adds a flag to mark a file as modified
Simon Sapin <simon.sapin@octobus.net>
parents: 48232
diff changeset
   160
	const int mask = dirstate_flag_wc_tracked | dirstate_flag_p1_tracked |
1730b2fceaa1 dirstate-v2: adds a flag to mark a file as modified
Simon Sapin <simon.sapin@octobus.net>
parents: 48232
diff changeset
   161
	                 dirstate_flag_p2_info;
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   162
	return (self->flags & mask);
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   163
}
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   164
47947
154e4dcac68c dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
   165
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
   166
{
48250
1730b2fceaa1 dirstate-v2: adds a flag to mark a file as modified
Simon Sapin <simon.sapin@octobus.net>
parents: 48232
diff changeset
   167
	const int mask = (dirstate_flag_wc_tracked | dirstate_flag_p1_tracked |
1730b2fceaa1 dirstate-v2: adds a flag to mark a file as modified
Simon Sapin <simon.sapin@octobus.net>
parents: 48232
diff changeset
   168
	                  dirstate_flag_p2_info);
1730b2fceaa1 dirstate-v2: adds a flag to mark a file as modified
Simon Sapin <simon.sapin@octobus.net>
parents: 48232
diff changeset
   169
	const int 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
   170
	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
   171
}
154e4dcac68c dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
   172
154e4dcac68c dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
   173
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
   174
{
47948
83f0e93ec34b dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47947
diff changeset
   175
	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
   176
		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
   177
	}
83f0e93ec34b dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47947
diff changeset
   178
	return (self->flags &
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   179
	        (dirstate_flag_p1_tracked | dirstate_flag_p2_info));
47947
154e4dcac68c dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
   180
}
154e4dcac68c dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
   181
154e4dcac68c dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
   182
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
   183
{
47948
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 ((self->flags & dirstate_flag_wc_tracked) &&
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   185
	        (self->flags & dirstate_flag_p1_tracked) &&
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   186
	        (self->flags & dirstate_flag_p2_info));
47947
154e4dcac68c dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
   187
}
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
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
   190
{
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   191
	return ((self->flags & dirstate_flag_wc_tracked) &&
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   192
	        !(self->flags & dirstate_flag_p1_tracked) &&
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   193
	        (self->flags & dirstate_flag_p2_info));
47947
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
154e4dcac68c dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
   196
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
   197
{
48025
631f6b445a77 dirstate: Remove the `state == ' '` special case
Simon Sapin <simon.sapin@octobus.net>
parents: 47990
diff changeset
   198
	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
   199
		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
   200
	} 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
   201
		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
   202
	} 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
   203
		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
   204
	} else {
83f0e93ec34b dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47947
diff changeset
   205
		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
   206
	}
47947
154e4dcac68c dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
   207
}
154e4dcac68c dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
   208
48252
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   209
static inline bool dirstate_item_c_has_fallback_exec(dirstateItemObject *self)
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   210
{
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   211
	return (bool)self->flags & dirstate_flag_has_fallback_exec;
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   212
}
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   213
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   214
static inline bool
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   215
dirstate_item_c_has_fallback_symlink(dirstateItemObject *self)
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   216
{
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   217
	return (bool)self->flags & dirstate_flag_has_fallback_symlink;
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   218
}
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   219
47947
154e4dcac68c dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
   220
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
   221
{
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   222
	if (self->flags & dirstate_flag_has_meaningful_data) {
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   223
		return self->mode;
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   224
	} else {
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   225
		return 0;
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   226
	}
47947
154e4dcac68c dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
   227
}
154e4dcac68c dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
   228
154e4dcac68c dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
   229
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
   230
{
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   231
	if (!(self->flags & dirstate_flag_wc_tracked) &&
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   232
	    (self->flags & dirstate_flag_p2_info)) {
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   233
		if (self->flags & dirstate_flag_p1_tracked) {
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   234
			return dirstate_v1_nonnormal;
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   235
		} else {
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   236
			return dirstate_v1_from_p2;
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   237
		}
47948
83f0e93ec34b dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47947
diff changeset
   238
	} 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
   239
		return 0;
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   240
	} else if (self->flags & dirstate_flag_p2_info) {
47948
83f0e93ec34b dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47947
diff changeset
   241
		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
   242
	} 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
   243
		return dirstate_v1_nonnormal;
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   244
	} else if (self->flags & dirstate_flag_has_meaningful_data) {
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   245
		return self->size;
47948
83f0e93ec34b dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47947
diff changeset
   246
	} else {
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   247
		return dirstate_v1_nonnormal;
47948
83f0e93ec34b dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47947
diff changeset
   248
	}
47947
154e4dcac68c dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
   249
}
154e4dcac68c dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
   250
154e4dcac68c dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
   251
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
   252
{
48025
631f6b445a77 dirstate: Remove the `state == ' '` special case
Simon Sapin <simon.sapin@octobus.net>
parents: 47990
diff changeset
   253
	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
   254
		return 0;
48264
bb240915f69f dirstate-v2: adjust the meaning of directory flags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48262
diff changeset
   255
	} else if (!(self->flags & dirstate_flag_has_mtime) ||
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   256
	           !(self->flags & dirstate_flag_p1_tracked) ||
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   257
	           !(self->flags & dirstate_flag_wc_tracked) ||
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   258
	           (self->flags & dirstate_flag_p2_info)) {
47948
83f0e93ec34b dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47947
diff changeset
   259
		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
   260
	} else {
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   261
		return self->mtime_s;
47948
83f0e93ec34b dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47947
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
}
154e4dcac68c dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
   264
48222
7e78c72ee3ea dirstate-v2: Initial Python serializer
Raphaël Gomès <rgomes@octobus.net>
parents: 48221
diff changeset
   265
static PyObject *dirstate_item_v2_data(dirstateItemObject *self)
7e78c72ee3ea dirstate-v2: Initial Python serializer
Raphaël Gomès <rgomes@octobus.net>
parents: 48221
diff changeset
   266
{
48250
1730b2fceaa1 dirstate-v2: adds a flag to mark a file as modified
Simon Sapin <simon.sapin@octobus.net>
parents: 48232
diff changeset
   267
	int flags = self->flags;
48222
7e78c72ee3ea dirstate-v2: Initial Python serializer
Raphaël Gomès <rgomes@octobus.net>
parents: 48221
diff changeset
   268
	int mode = dirstate_item_c_v1_mode(self);
48279
249d1888e9d8 parsers: don't ask about the exec bit on platforms that don't have it
Raphaël Gomès <rgomes@octobus.net>
parents: 48264
diff changeset
   269
#ifdef S_IXUSR
249d1888e9d8 parsers: don't ask about the exec bit on platforms that don't have it
Raphaël Gomès <rgomes@octobus.net>
parents: 48264
diff changeset
   270
	/* This is for platforms with an exec bit */
48222
7e78c72ee3ea dirstate-v2: Initial Python serializer
Raphaël Gomès <rgomes@octobus.net>
parents: 48221
diff changeset
   271
	if ((mode & S_IXUSR) != 0) {
7e78c72ee3ea dirstate-v2: Initial Python serializer
Raphaël Gomès <rgomes@octobus.net>
parents: 48221
diff changeset
   272
		flags |= dirstate_flag_mode_exec_perm;
7e78c72ee3ea dirstate-v2: Initial Python serializer
Raphaël Gomès <rgomes@octobus.net>
parents: 48221
diff changeset
   273
	} else {
7e78c72ee3ea dirstate-v2: Initial Python serializer
Raphaël Gomès <rgomes@octobus.net>
parents: 48221
diff changeset
   274
		flags &= ~dirstate_flag_mode_exec_perm;
7e78c72ee3ea dirstate-v2: Initial Python serializer
Raphaël Gomès <rgomes@octobus.net>
parents: 48221
diff changeset
   275
	}
48279
249d1888e9d8 parsers: don't ask about the exec bit on platforms that don't have it
Raphaël Gomès <rgomes@octobus.net>
parents: 48264
diff changeset
   276
#else
249d1888e9d8 parsers: don't ask about the exec bit on platforms that don't have it
Raphaël Gomès <rgomes@octobus.net>
parents: 48264
diff changeset
   277
	flags &= ~dirstate_flag_mode_exec_perm;
249d1888e9d8 parsers: don't ask about the exec bit on platforms that don't have it
Raphaël Gomès <rgomes@octobus.net>
parents: 48264
diff changeset
   278
#endif
48280
126feb805247 parsers: don't ask about symlinks on platforms that don't support them
Raphaël Gomès <rgomes@octobus.net>
parents: 48279
diff changeset
   279
#ifdef S_ISLNK
126feb805247 parsers: don't ask about symlinks on platforms that don't support them
Raphaël Gomès <rgomes@octobus.net>
parents: 48279
diff changeset
   280
	/* This is for platforms with support for symlinks */
48222
7e78c72ee3ea dirstate-v2: Initial Python serializer
Raphaël Gomès <rgomes@octobus.net>
parents: 48221
diff changeset
   281
	if (S_ISLNK(mode)) {
7e78c72ee3ea dirstate-v2: Initial Python serializer
Raphaël Gomès <rgomes@octobus.net>
parents: 48221
diff changeset
   282
		flags |= dirstate_flag_mode_is_symlink;
7e78c72ee3ea dirstate-v2: Initial Python serializer
Raphaël Gomès <rgomes@octobus.net>
parents: 48221
diff changeset
   283
	} else {
7e78c72ee3ea dirstate-v2: Initial Python serializer
Raphaël Gomès <rgomes@octobus.net>
parents: 48221
diff changeset
   284
		flags &= ~dirstate_flag_mode_is_symlink;
7e78c72ee3ea dirstate-v2: Initial Python serializer
Raphaël Gomès <rgomes@octobus.net>
parents: 48221
diff changeset
   285
	}
48280
126feb805247 parsers: don't ask about symlinks on platforms that don't support them
Raphaël Gomès <rgomes@octobus.net>
parents: 48279
diff changeset
   286
#else
126feb805247 parsers: don't ask about symlinks on platforms that don't support them
Raphaël Gomès <rgomes@octobus.net>
parents: 48279
diff changeset
   287
	flags &= ~dirstate_flag_mode_is_symlink;
126feb805247 parsers: don't ask about symlinks on platforms that don't support them
Raphaël Gomès <rgomes@octobus.net>
parents: 48279
diff changeset
   288
#endif
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   289
	return Py_BuildValue("iiii", flags, self->size, self->mtime_s,
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   290
	                     self->mtime_ns);
48222
7e78c72ee3ea dirstate-v2: Initial Python serializer
Raphaël Gomès <rgomes@octobus.net>
parents: 48221
diff changeset
   291
};
7e78c72ee3ea dirstate-v2: Initial Python serializer
Raphaël Gomès <rgomes@octobus.net>
parents: 48221
diff changeset
   292
47539
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   293
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
   294
{
47947
154e4dcac68c dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
   295
	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
   296
	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
   297
};
80dc1d452993 dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47268
diff changeset
   298
47539
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   299
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
   300
{
47947
154e4dcac68c dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
   301
	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
   302
};
80dc1d452993 dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47268
diff changeset
   303
47539
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   304
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
   305
{
47947
154e4dcac68c dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
   306
	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
   307
};
80dc1d452993 dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47268
diff changeset
   308
47539
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   309
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
   310
{
47947
154e4dcac68c dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
   311
	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
   312
};
80dc1d452993 dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47268
diff changeset
   313
47539
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   314
static PyObject *dirstate_item_need_delay(dirstateItemObject *self,
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   315
                                          PyObject *now)
47532
ccbabaee5c36 dirstate-entry: add a `need_delay` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47531
diff changeset
   316
{
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   317
	int now_s;
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   318
	int now_ns;
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   319
	if (!PyArg_ParseTuple(now, "ii", &now_s, &now_ns)) {
47532
ccbabaee5c36 dirstate-entry: add a `need_delay` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47531
diff changeset
   320
		return NULL;
ccbabaee5c36 dirstate-entry: add a `need_delay` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47531
diff changeset
   321
	}
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   322
	if (dirstate_item_c_v1_state(self) == 'n' && self->mtime_s == now_s) {
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   323
		Py_RETURN_TRUE;
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   324
	} else {
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   325
		Py_RETURN_FALSE;
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   326
	}
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   327
};
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   328
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   329
static PyObject *dirstate_item_mtime_likely_equal_to(dirstateItemObject *self,
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   330
                                                     PyObject *other)
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   331
{
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   332
	int other_s;
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   333
	int other_ns;
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   334
	if (!PyArg_ParseTuple(other, "ii", &other_s, &other_ns)) {
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   335
		return NULL;
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   336
	}
48264
bb240915f69f dirstate-v2: adjust the meaning of directory flags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48262
diff changeset
   337
	if ((self->flags & dirstate_flag_has_mtime) &&
48262
68bb472aee9c dirstate: ignore sub-second component when either is zero in mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 48261
diff changeset
   338
	    self->mtime_s == other_s &&
68bb472aee9c dirstate: ignore sub-second component when either is zero in mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 48261
diff changeset
   339
	    (self->mtime_ns == other_ns || self->mtime_ns == 0 ||
68bb472aee9c dirstate: ignore sub-second component when either is zero in mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 48261
diff changeset
   340
	     other_ns == 0)) {
47532
ccbabaee5c36 dirstate-entry: add a `need_delay` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47531
diff changeset
   341
		Py_RETURN_TRUE;
ccbabaee5c36 dirstate-entry: add a `need_delay` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47531
diff changeset
   342
	} else {
ccbabaee5c36 dirstate-entry: add a `need_delay` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47531
diff changeset
   343
		Py_RETURN_FALSE;
ccbabaee5c36 dirstate-entry: add a `need_delay` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47531
diff changeset
   344
	}
ccbabaee5c36 dirstate-entry: add a `need_delay` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47531
diff changeset
   345
};
ccbabaee5c36 dirstate-entry: add a `need_delay` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47531
diff changeset
   346
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
   347
/* 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
   348
 */
a4443f66be6a dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47539
diff changeset
   349
static inline dirstateItemObject *
a4443f66be6a dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47539
diff changeset
   350
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
   351
{
a4443f66be6a dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47539
diff changeset
   352
	dirstateItemObject *t =
a4443f66be6a dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47539
diff changeset
   353
	    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
   354
	if (!t) {
a4443f66be6a dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47539
diff changeset
   355
		return NULL;
a4443f66be6a dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47539
diff changeset
   356
	}
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   357
	t->flags = 0;
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   358
	t->mode = 0;
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   359
	t->size = 0;
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   360
	t->mtime_s = 0;
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   361
	t->mtime_ns = 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
   362
83f0e93ec34b dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47947
diff changeset
   363
	if (state == 'm') {
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   364
		t->flags = (dirstate_flag_wc_tracked |
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   365
		            dirstate_flag_p1_tracked | dirstate_flag_p2_info);
47948
83f0e93ec34b dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47947
diff changeset
   366
	} 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
   367
		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
   368
	} 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
   369
		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
   370
			t->flags =
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   371
			    dirstate_flag_p1_tracked | dirstate_flag_p2_info;
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
		} else if (size == dirstate_v1_from_p2) {
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   373
			t->flags = dirstate_flag_p2_info;
47948
83f0e93ec34b dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47947
diff changeset
   374
		} else {
83f0e93ec34b dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47947
diff changeset
   375
			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
   376
		}
83f0e93ec34b dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47947
diff changeset
   377
	} 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
   378
		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
   379
			t->flags =
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   380
			    dirstate_flag_wc_tracked | dirstate_flag_p2_info;
47948
83f0e93ec34b dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47947
diff changeset
   381
		} else if (size == dirstate_v1_nonnormal) {
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   382
			t->flags =
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   383
			    dirstate_flag_wc_tracked | dirstate_flag_p1_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
   384
		} 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
   385
			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
   386
			            dirstate_flag_p1_tracked |
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   387
			            dirstate_flag_has_meaningful_data);
47948
83f0e93ec34b dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47947
diff changeset
   388
			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
   389
			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
   390
		} else {
83f0e93ec34b dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47947
diff changeset
   391
			t->flags = (dirstate_flag_wc_tracked |
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   392
			            dirstate_flag_p1_tracked |
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   393
			            dirstate_flag_has_meaningful_data |
48264
bb240915f69f dirstate-v2: adjust the meaning of directory flags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48262
diff changeset
   394
			            dirstate_flag_has_mtime);
47948
83f0e93ec34b dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47947
diff changeset
   395
			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
   396
			t->size = size;
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   397
			t->mtime_s = mtime;
47948
83f0e93ec34b dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47947
diff changeset
   398
		}
83f0e93ec34b dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47947
diff changeset
   399
	} else {
83f0e93ec34b dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47947
diff changeset
   400
		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
   401
		             "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
   402
		             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
   403
		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
   404
		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
   405
	}
83f0e93ec34b dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47947
diff changeset
   406
47665
a4443f66be6a dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47539
diff changeset
   407
	return t;
a4443f66be6a dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47539
diff changeset
   408
}
a4443f66be6a dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47539
diff changeset
   409
a4443f66be6a dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47539
diff changeset
   410
/* 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
   411
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
   412
                                            PyObject *args)
a4443f66be6a dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47539
diff changeset
   413
{
a4443f66be6a dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47539
diff changeset
   414
	/* 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
   415
	 * 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
   416
	char state;
a4443f66be6a dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47539
diff changeset
   417
	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
   418
	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
   419
		return NULL;
a4443f66be6a dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47539
diff changeset
   420
	}
47946
0919d66e279a dirstate-item: factor some code in the C implementation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47945
diff changeset
   421
	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
   422
};
a4443f66be6a dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47539
diff changeset
   423
48221
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48164
diff changeset
   424
static PyObject *dirstate_item_from_v2_meth(PyTypeObject *subtype,
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48164
diff changeset
   425
                                            PyObject *args)
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48164
diff changeset
   426
{
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48164
diff changeset
   427
	dirstateItemObject *t =
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48164
diff changeset
   428
	    PyObject_New(dirstateItemObject, &dirstateItemType);
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48164
diff changeset
   429
	if (!t) {
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48164
diff changeset
   430
		return NULL;
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48164
diff changeset
   431
	}
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   432
	if (!PyArg_ParseTuple(args, "iiii", &t->flags, &t->size, &t->mtime_s,
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   433
	                      &t->mtime_ns)) {
48221
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48164
diff changeset
   434
		return NULL;
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48164
diff changeset
   435
	}
48250
1730b2fceaa1 dirstate-v2: adds a flag to mark a file as modified
Simon Sapin <simon.sapin@octobus.net>
parents: 48232
diff changeset
   436
	if (t->flags & dirstate_flag_expected_state_is_modified) {
1730b2fceaa1 dirstate-v2: adds a flag to mark a file as modified
Simon Sapin <simon.sapin@octobus.net>
parents: 48232
diff changeset
   437
		t->flags &= ~(dirstate_flag_expected_state_is_modified |
1730b2fceaa1 dirstate-v2: adds a flag to mark a file as modified
Simon Sapin <simon.sapin@octobus.net>
parents: 48232
diff changeset
   438
		              dirstate_flag_has_meaningful_data |
48264
bb240915f69f dirstate-v2: adjust the meaning of directory flags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48262
diff changeset
   439
		              dirstate_flag_has_mtime);
48250
1730b2fceaa1 dirstate-v2: adds a flag to mark a file as modified
Simon Sapin <simon.sapin@octobus.net>
parents: 48232
diff changeset
   440
	}
48261
9205d9be8b41 dirstate-v2: add a new MTIME_SECOND_AMBIGUOUS flags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48260
diff changeset
   441
	if (t->flags & dirstate_flag_mtime_second_ambiguous) {
9205d9be8b41 dirstate-v2: add a new MTIME_SECOND_AMBIGUOUS flags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48260
diff changeset
   442
		/* The current code is not able to do the more subtle comparison
9205d9be8b41 dirstate-v2: add a new MTIME_SECOND_AMBIGUOUS flags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48260
diff changeset
   443
		 * that the MTIME_SECOND_AMBIGUOUS requires. So we ignore the
9205d9be8b41 dirstate-v2: add a new MTIME_SECOND_AMBIGUOUS flags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48260
diff changeset
   444
		 * mtime */
9205d9be8b41 dirstate-v2: add a new MTIME_SECOND_AMBIGUOUS flags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48260
diff changeset
   445
		t->flags &= ~(dirstate_flag_mtime_second_ambiguous |
9205d9be8b41 dirstate-v2: add a new MTIME_SECOND_AMBIGUOUS flags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48260
diff changeset
   446
		              dirstate_flag_has_meaningful_data |
48264
bb240915f69f dirstate-v2: adjust the meaning of directory flags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48262
diff changeset
   447
		              dirstate_flag_has_mtime);
48261
9205d9be8b41 dirstate-v2: add a new MTIME_SECOND_AMBIGUOUS flags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48260
diff changeset
   448
	}
48221
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48164
diff changeset
   449
	t->mode = 0;
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48164
diff changeset
   450
	if (t->flags & dirstate_flag_has_meaningful_data) {
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48164
diff changeset
   451
		if (t->flags & dirstate_flag_mode_exec_perm) {
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48164
diff changeset
   452
			t->mode = 0755;
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48164
diff changeset
   453
		} else {
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48164
diff changeset
   454
			t->mode = 0644;
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48164
diff changeset
   455
		}
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48164
diff changeset
   456
		if (t->flags & dirstate_flag_mode_is_symlink) {
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48164
diff changeset
   457
			t->mode |= S_IFLNK;
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48164
diff changeset
   458
		} else {
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48164
diff changeset
   459
			t->mode |= S_IFREG;
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48164
diff changeset
   460
		}
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48164
diff changeset
   461
	}
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48164
diff changeset
   462
	return (PyObject *)t;
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48164
diff changeset
   463
};
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48164
diff changeset
   464
47666
e53256a9f9c5 dirstate-item: add a `set_possibly_dirty` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47665
diff changeset
   465
/* 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
   466
   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
   467
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
   468
{
48264
bb240915f69f dirstate-v2: adjust the meaning of directory flags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48262
diff changeset
   469
	self->flags &= ~dirstate_flag_has_mtime;
47976
2018753014be dirstate: fix compilation warnings in `dirstate_item_set_possibly_dirty()`
Martin von Zweigbergk <martinvonz@google.com>
parents: 47975
diff changeset
   470
	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
   471
}
e53256a9f9c5 dirstate-item: add a `set_possibly_dirty` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47665
diff changeset
   472
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
   473
/* 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
   474
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
   475
                                         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
   476
{
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   477
	int size, mode, mtime_s, mtime_ns;
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   478
	if (!PyArg_ParseTuple(args, "ii(ii)", &mode, &size, &mtime_s,
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   479
	                      &mtime_ns)) {
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
   480
		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
   481
	}
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   482
	self->flags = dirstate_flag_wc_tracked | dirstate_flag_p1_tracked |
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   483
	              dirstate_flag_has_meaningful_data |
48264
bb240915f69f dirstate-v2: adjust the meaning of directory flags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48262
diff changeset
   484
	              dirstate_flag_has_mtime;
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
   485
	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
   486
	self->size = size;
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   487
	self->mtime_s = mtime_s;
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   488
	self->mtime_ns = mtime_ns;
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
   489
	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
   490
}
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
   491
47990
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47976
diff changeset
   492
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
   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
	self->flags |= dirstate_flag_wc_tracked;
48264
bb240915f69f dirstate-v2: adjust the meaning of directory flags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48262
diff changeset
   495
	self->flags &= ~dirstate_flag_has_mtime;
47990
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47976
diff changeset
   496
	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
   497
}
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47976
diff changeset
   498
47890
3853e6ee160d dirstatemap: replace `removefile` by an explicit `entry.set_untracked()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47686
diff changeset
   499
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
   500
{
47948
83f0e93ec34b dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47947
diff changeset
   501
	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
   502
	self->mode = 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
   503
	self->size = 0;
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   504
	self->mtime_s = 0;
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   505
	self->mtime_ns = 0;
47890
3853e6ee160d dirstatemap: replace `removefile` by an explicit `entry.set_untracked()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47686
diff changeset
   506
	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
   507
}
3853e6ee160d dirstatemap: replace `removefile` by an explicit `entry.set_untracked()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47686
diff changeset
   508
48060
a660d8a53267 dirstate: use a new `drop_merge_data` in `setparent`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48044
diff changeset
   509
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
   510
{
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   511
	if (self->flags & dirstate_flag_p2_info) {
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   512
		self->flags &= ~(dirstate_flag_p2_info |
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   513
		                 dirstate_flag_has_meaningful_data |
48264
bb240915f69f dirstate-v2: adjust the meaning of directory flags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48262
diff changeset
   514
		                 dirstate_flag_has_mtime);
48060
a660d8a53267 dirstate: use a new `drop_merge_data` in `setparent`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48044
diff changeset
   515
		self->mode = 0;
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   516
		self->size = 0;
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   517
		self->mtime_s = 0;
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   518
		self->mtime_ns = 0;
48060
a660d8a53267 dirstate: use a new `drop_merge_data` in `setparent`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48044
diff changeset
   519
	}
a660d8a53267 dirstate: use a new `drop_merge_data` in `setparent`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48044
diff changeset
   520
	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
   521
}
47539
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   522
static PyMethodDef dirstate_item_methods[] = {
48222
7e78c72ee3ea dirstate-v2: Initial Python serializer
Raphaël Gomès <rgomes@octobus.net>
parents: 48221
diff changeset
   523
    {"v2_data", (PyCFunction)dirstate_item_v2_data, METH_NOARGS,
7e78c72ee3ea dirstate-v2: Initial Python serializer
Raphaël Gomès <rgomes@octobus.net>
parents: 48221
diff changeset
   524
     "return data suitable for v2 serialization"},
47539
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   525
    {"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
   526
     "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
   527
    {"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
   528
     "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
   529
    {"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
   530
     "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
   531
    {"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
   532
     "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
   533
    {"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
   534
     "True if the stored mtime would be ambiguous with the current time"},
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   535
    {"mtime_likely_equal_to", (PyCFunction)dirstate_item_mtime_likely_equal_to,
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   536
     METH_O, "True if the stored mtime is likely equal to the given mtime"},
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
   537
    {"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
   538
     METH_VARARGS | METH_CLASS, "build a new DirstateItem object from V1 data"},
48221
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48164
diff changeset
   539
    {"from_v2_data", (PyCFunction)dirstate_item_from_v2_meth,
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48164
diff changeset
   540
     METH_VARARGS | METH_CLASS, "build a new DirstateItem object from V2 data"},
47666
e53256a9f9c5 dirstate-item: add a `set_possibly_dirty` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47665
diff changeset
   541
    {"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
   542
     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
   543
    {"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
   544
     "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
   545
    {"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
   546
     "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
   547
    {"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
   548
     "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
   549
    {"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
   550
     "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
   551
    {NULL} /* Sentinel */
80dc1d452993 dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47268
diff changeset
   552
};
80dc1d452993 dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47268
diff changeset
   553
47539
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   554
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
   555
{
47947
154e4dcac68c dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
   556
	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
   557
};
8e4b9fe31334 dirstate-entry: add a `mode` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47532
diff changeset
   558
47539
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   559
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
   560
{
47947
154e4dcac68c dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
   561
	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
   562
};
0e5800c88eb4 dirstate-entry: add a `size` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47536
diff changeset
   563
47539
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   564
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
   565
{
47947
154e4dcac68c dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
   566
	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
   567
};
77fce401a2bb dirstate-entry: add a `mtime` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47537
diff changeset
   568
47539
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   569
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
   570
{
47947
154e4dcac68c dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
   571
	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
   572
	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
   573
};
769037a279ec dirstate-entry: add a `state` property (and use it)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47509
diff changeset
   574
48252
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   575
static PyObject *dirstate_item_get_has_fallback_exec(dirstateItemObject *self)
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   576
{
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   577
	if (dirstate_item_c_has_fallback_exec(self)) {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   578
		Py_RETURN_TRUE;
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   579
	} else {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   580
		Py_RETURN_FALSE;
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   581
	}
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   582
};
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   583
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   584
static PyObject *dirstate_item_get_fallback_exec(dirstateItemObject *self)
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   585
{
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   586
	if (dirstate_item_c_has_fallback_exec(self)) {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   587
		if (self->flags & dirstate_flag_fallback_exec) {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   588
			Py_RETURN_TRUE;
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   589
		} else {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   590
			Py_RETURN_FALSE;
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   591
		}
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   592
	} else {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   593
		Py_RETURN_NONE;
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   594
	}
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   595
};
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   596
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   597
static int dirstate_item_set_fallback_exec(dirstateItemObject *self,
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   598
                                           PyObject *value)
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   599
{
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   600
	if ((value == Py_None) || (value == NULL)) {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   601
		self->flags &= ~dirstate_flag_has_fallback_exec;
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   602
	} else {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   603
		self->flags |= dirstate_flag_has_fallback_exec;
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   604
		if (PyObject_IsTrue(value)) {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   605
			self->flags |= dirstate_flag_fallback_exec;
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   606
		} else {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   607
			self->flags &= ~dirstate_flag_fallback_exec;
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   608
		}
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   609
	}
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   610
	return 0;
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   611
};
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   612
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   613
static PyObject *
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   614
dirstate_item_get_has_fallback_symlink(dirstateItemObject *self)
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   615
{
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   616
	if (dirstate_item_c_has_fallback_symlink(self)) {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   617
		Py_RETURN_TRUE;
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   618
	} else {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   619
		Py_RETURN_FALSE;
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   620
	}
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   621
};
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   622
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   623
static PyObject *dirstate_item_get_fallback_symlink(dirstateItemObject *self)
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   624
{
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   625
	if (dirstate_item_c_has_fallback_symlink(self)) {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   626
		if (self->flags & dirstate_flag_fallback_symlink) {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   627
			Py_RETURN_TRUE;
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   628
		} else {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   629
			Py_RETURN_FALSE;
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   630
		}
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   631
	} else {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   632
		Py_RETURN_NONE;
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   633
	}
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   634
};
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   635
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   636
static int dirstate_item_set_fallback_symlink(dirstateItemObject *self,
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   637
                                              PyObject *value)
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   638
{
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   639
	if ((value == Py_None) || (value == NULL)) {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   640
		self->flags &= ~dirstate_flag_has_fallback_symlink;
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   641
	} else {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   642
		self->flags |= dirstate_flag_has_fallback_symlink;
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   643
		if (PyObject_IsTrue(value)) {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   644
			self->flags |= dirstate_flag_fallback_symlink;
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   645
		} else {
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   646
			self->flags &= ~dirstate_flag_fallback_symlink;
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   647
		}
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   648
	}
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   649
	return 0;
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   650
};
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   651
47539
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   652
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
   653
{
47947
154e4dcac68c dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
   654
	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
   655
		Py_RETURN_TRUE;
f5b8f0b9c129 dirstate-entry: add a `tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47526
diff changeset
   656
	} else {
f5b8f0b9c129 dirstate-entry: add a `tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47526
diff changeset
   657
		Py_RETURN_FALSE;
f5b8f0b9c129 dirstate-entry: add a `tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47526
diff changeset
   658
	}
f5b8f0b9c129 dirstate-entry: add a `tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47526
diff changeset
   659
};
48143
21542d4cb568 dirstate-item: introduce a `p1_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48142
diff changeset
   660
static PyObject *dirstate_item_get_p1_tracked(dirstateItemObject *self)
21542d4cb568 dirstate-item: introduce a `p1_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48142
diff changeset
   661
{
21542d4cb568 dirstate-item: introduce a `p1_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48142
diff changeset
   662
	if (self->flags & dirstate_flag_p1_tracked) {
21542d4cb568 dirstate-item: introduce a `p1_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48142
diff changeset
   663
		Py_RETURN_TRUE;
21542d4cb568 dirstate-item: introduce a `p1_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48142
diff changeset
   664
	} else {
21542d4cb568 dirstate-item: introduce a `p1_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48142
diff changeset
   665
		Py_RETURN_FALSE;
21542d4cb568 dirstate-item: introduce a `p1_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48142
diff changeset
   666
	}
21542d4cb568 dirstate-item: introduce a `p1_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48142
diff changeset
   667
};
47531
f5b8f0b9c129 dirstate-entry: add a `tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47526
diff changeset
   668
47539
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   669
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
   670
{
47947
154e4dcac68c dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
   671
	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
   672
		Py_RETURN_TRUE;
8bcae9bf9e8d dirstate-entry: add a `added` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47517
diff changeset
   673
	} else {
8bcae9bf9e8d dirstate-entry: add a `added` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47517
diff changeset
   674
		Py_RETURN_FALSE;
8bcae9bf9e8d dirstate-entry: add a `added` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47517
diff changeset
   675
	}
8bcae9bf9e8d dirstate-entry: add a `added` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47517
diff changeset
   676
};
8bcae9bf9e8d dirstate-entry: add a `added` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47517
diff changeset
   677
48142
fb3b41d583c2 dirstate-item: introduce a `p2_info` property that combine two others
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48138
diff changeset
   678
static PyObject *dirstate_item_get_p2_info(dirstateItemObject *self)
fb3b41d583c2 dirstate-item: introduce a `p2_info` property that combine two others
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48138
diff changeset
   679
{
fb3b41d583c2 dirstate-item: introduce a `p2_info` property that combine two others
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48138
diff changeset
   680
	if (self->flags & dirstate_flag_wc_tracked &&
fb3b41d583c2 dirstate-item: introduce a `p2_info` property that combine two others
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48138
diff changeset
   681
	    self->flags & dirstate_flag_p2_info) {
fb3b41d583c2 dirstate-item: introduce a `p2_info` property that combine two others
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48138
diff changeset
   682
		Py_RETURN_TRUE;
fb3b41d583c2 dirstate-item: introduce a `p2_info` property that combine two others
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48138
diff changeset
   683
	} else {
fb3b41d583c2 dirstate-item: introduce a `p2_info` property that combine two others
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48138
diff changeset
   684
		Py_RETURN_FALSE;
fb3b41d583c2 dirstate-item: introduce a `p2_info` property that combine two others
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48138
diff changeset
   685
	}
fb3b41d583c2 dirstate-item: introduce a `p2_info` property that combine two others
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48138
diff changeset
   686
};
fb3b41d583c2 dirstate-item: introduce a `p2_info` property that combine two others
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48138
diff changeset
   687
47539
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   688
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
   689
{
47947
154e4dcac68c dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
   690
	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
   691
		Py_RETURN_TRUE;
10e740292dff dirstate-entry: add a `merged` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47512
diff changeset
   692
	} else {
10e740292dff dirstate-entry: add a `merged` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47512
diff changeset
   693
		Py_RETURN_FALSE;
10e740292dff dirstate-entry: add a `merged` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47512
diff changeset
   694
	}
10e740292dff dirstate-entry: add a `merged` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47512
diff changeset
   695
};
10e740292dff dirstate-entry: add a `merged` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47512
diff changeset
   696
47539
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   697
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
   698
{
47947
154e4dcac68c dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
   699
	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
   700
		Py_RETURN_TRUE;
559aee84b889 dirstate-entry: add a `from_p2` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47513
diff changeset
   701
	} else {
559aee84b889 dirstate-entry: add a `from_p2` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47513
diff changeset
   702
		Py_RETURN_FALSE;
559aee84b889 dirstate-entry: add a `from_p2` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47513
diff changeset
   703
	}
559aee84b889 dirstate-entry: add a `from_p2` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47513
diff changeset
   704
};
559aee84b889 dirstate-entry: add a `from_p2` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47513
diff changeset
   705
48086
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48084
diff changeset
   706
static PyObject *dirstate_item_get_maybe_clean(dirstateItemObject *self)
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48084
diff changeset
   707
{
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48084
diff changeset
   708
	if (!(self->flags & dirstate_flag_wc_tracked)) {
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48084
diff changeset
   709
		Py_RETURN_FALSE;
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   710
	} else if (!(self->flags & dirstate_flag_p1_tracked)) {
48086
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48084
diff changeset
   711
		Py_RETURN_FALSE;
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   712
	} else if (self->flags & dirstate_flag_p2_info) {
48086
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48084
diff changeset
   713
		Py_RETURN_FALSE;
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48084
diff changeset
   714
	} else {
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48084
diff changeset
   715
		Py_RETURN_TRUE;
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48084
diff changeset
   716
	}
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48084
diff changeset
   717
};
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48084
diff changeset
   718
48087
79bc60ca5946 dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48086
diff changeset
   719
static PyObject *dirstate_item_get_any_tracked(dirstateItemObject *self)
79bc60ca5946 dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48086
diff changeset
   720
{
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   721
	if (dirstate_item_c_any_tracked(self)) {
48087
79bc60ca5946 dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48086
diff changeset
   722
		Py_RETURN_TRUE;
79bc60ca5946 dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48086
diff changeset
   723
	} else {
79bc60ca5946 dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48086
diff changeset
   724
		Py_RETURN_FALSE;
79bc60ca5946 dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48086
diff changeset
   725
	}
79bc60ca5946 dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48086
diff changeset
   726
};
79bc60ca5946 dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48086
diff changeset
   727
47539
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   728
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
   729
{
47947
154e4dcac68c dirstate-item: introduce low level C function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
   730
	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
   731
		Py_RETURN_TRUE;
c94d3ff46fd5 dirstate-entry: add a `removed` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47514
diff changeset
   732
	} else {
c94d3ff46fd5 dirstate-entry: add a `removed` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47514
diff changeset
   733
		Py_RETURN_FALSE;
c94d3ff46fd5 dirstate-entry: add a `removed` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47514
diff changeset
   734
	}
c94d3ff46fd5 dirstate-entry: add a `removed` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47514
diff changeset
   735
};
c94d3ff46fd5 dirstate-entry: add a `removed` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47514
diff changeset
   736
47539
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   737
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
   738
    {"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
   739
    {"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
   740
    {"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
   741
    {"state", (getter)dirstate_item_get_state, NULL, "state", NULL},
48252
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   742
    {"has_fallback_exec", (getter)dirstate_item_get_has_fallback_exec, NULL,
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   743
     "has_fallback_exec", NULL},
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   744
    {"fallback_exec", (getter)dirstate_item_get_fallback_exec,
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   745
     (setter)dirstate_item_set_fallback_exec, "fallback_exec", NULL},
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   746
    {"has_fallback_symlink", (getter)dirstate_item_get_has_fallback_symlink,
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   747
     NULL, "has_fallback_symlink", NULL},
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   748
    {"fallback_symlink", (getter)dirstate_item_get_fallback_symlink,
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   749
     (setter)dirstate_item_set_fallback_symlink, "fallback_symlink", NULL},
47539
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   750
    {"tracked", (getter)dirstate_item_get_tracked, NULL, "tracked", NULL},
48143
21542d4cb568 dirstate-item: introduce a `p1_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48142
diff changeset
   751
    {"p1_tracked", (getter)dirstate_item_get_p1_tracked, NULL, "p1_tracked",
21542d4cb568 dirstate-item: introduce a `p1_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48142
diff changeset
   752
     NULL},
47539
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   753
    {"added", (getter)dirstate_item_get_added, NULL, "added", NULL},
48142
fb3b41d583c2 dirstate-item: introduce a `p2_info` property that combine two others
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48138
diff changeset
   754
    {"p2_info", (getter)dirstate_item_get_p2_info, NULL, "p2_info", NULL},
47539
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   755
    {"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
   756
    {"from_p2", (getter)dirstate_item_get_from_p2, NULL, "from_p2", NULL},
48086
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48084
diff changeset
   757
    {"maybe_clean", (getter)dirstate_item_get_maybe_clean, NULL, "maybe_clean",
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48084
diff changeset
   758
     NULL},
48087
79bc60ca5946 dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48086
diff changeset
   759
    {"any_tracked", (getter)dirstate_item_get_any_tracked, NULL, "any_tracked",
79bc60ca5946 dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48086
diff changeset
   760
     NULL},
47539
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   761
    {"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
   762
    {NULL} /* Sentinel */
769037a279ec dirstate-entry: add a `state` property (and use it)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47509
diff changeset
   763
};
769037a279ec dirstate-entry: add a `state` property (and use it)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47509
diff changeset
   764
47539
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   765
PyTypeObject dirstateItemType = {
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   766
    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
   767
    "dirstate_tuple",                  /* tp_name */
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   768
    sizeof(dirstateItemObject),        /* tp_basicsize */
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   769
    0,                                 /* tp_itemsize */
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   770
    (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
   771
    0,                                 /* tp_print */
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   772
    0,                                 /* tp_getattr */
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   773
    0,                                 /* tp_setattr */
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   774
    0,                                 /* tp_compare */
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   775
    0,                                 /* tp_repr */
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   776
    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
   777
    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
   778
    0,                                 /* tp_as_mapping */
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   779
    0,                                 /* tp_hash  */
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   780
    0,                                 /* tp_call */
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   781
    0,                                 /* tp_str */
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   782
    0,                                 /* tp_getattro */
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   783
    0,                                 /* tp_setattro */
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   784
    0,                                 /* tp_as_buffer */
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   785
    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
   786
    "dirstate tuple",                  /* tp_doc */
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   787
    0,                                 /* tp_traverse */
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   788
    0,                                 /* tp_clear */
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   789
    0,                                 /* tp_richcompare */
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   790
    0,                                 /* tp_weaklistoffset */
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   791
    0,                                 /* tp_iter */
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   792
    0,                                 /* tp_iternext */
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   793
    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
   794
    0,                                 /* tp_members */
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   795
    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
   796
    0,                                 /* tp_base */
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   797
    0,                                 /* tp_dict */
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   798
    0,                                 /* tp_descr_get */
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   799
    0,                                 /* tp_descr_set */
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   800
    0,                                 /* tp_dictoffset */
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   801
    0,                                 /* tp_init */
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   802
    0,                                 /* tp_alloc */
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   803
    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
   804
};
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 21807
diff changeset
   805
7093
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   806
static PyObject *parse_dirstate(PyObject *self, PyObject *args)
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   807
{
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   808
	PyObject *dmap, *cmap, *parents = NULL, *ret = NULL;
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   809
	PyObject *fname = NULL, *cname = NULL, *entry = NULL;
20167
09e41ac6289d mpatch: rewrite pointer overflow checks
Matt Mackall <mpm@selenic.com>
parents: 20109
diff changeset
   810
	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
   811
	int mode, size, mtime;
42068
896b19d12c08 cext: make parsers.c PY_SSIZE_T_CLEAN
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41336
diff changeset
   812
	unsigned int flen, pos = 40;
896b19d12c08 cext: make parsers.c PY_SSIZE_T_CLEAN
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41336
diff changeset
   813
	Py_ssize_t len = 40;
896b19d12c08 cext: make parsers.c PY_SSIZE_T_CLEAN
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41336
diff changeset
   814
	Py_ssize_t readlen;
7093
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   815
36620
186c6df3a373 py3: bulk-replace 'const char*' format specifier passed to PyArg_ParseTuple*()
Yuya Nishihara <yuya@tcha.org>
parents: 36619
diff changeset
   816
	if (!PyArg_ParseTuple(
186c6df3a373 py3: bulk-replace 'const char*' format specifier passed to PyArg_ParseTuple*()
Yuya Nishihara <yuya@tcha.org>
parents: 36619
diff changeset
   817
	        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
   818
	        &PyDict_Type, &dmap, &PyDict_Type, &cmap, &str, &readlen)) {
7093
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   819
		goto quit;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 41016
diff changeset
   820
	}
7093
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   821
22403
41e9d58ec56f parsers: avoid signed/unsigned comparison mismatch
Henrik Stuart <hg@hstuart.dk>
parents: 22402
diff changeset
   822
	len = readlen;
41e9d58ec56f parsers: avoid signed/unsigned comparison mismatch
Henrik Stuart <hg@hstuart.dk>
parents: 22402
diff changeset
   823
7093
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   824
	/* 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
   825
	if (len < 40) {
34862
d92dc725223b parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents: 34861
diff changeset
   826
		PyErr_SetString(PyExc_ValueError,
d92dc725223b parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents: 34861
diff changeset
   827
		                "too little data for parents");
7093
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   828
		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
   829
	}
7093
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   830
42096
509a0477b3a6 cext: cast s# arguments of Py_BuildValue() to Py_ssize_t
Yuya Nishihara <yuya@tcha.org>
parents: 42068
diff changeset
   831
	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
   832
	                        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
   833
	if (!parents) {
7093
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   834
		goto quit;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 41016
diff changeset
   835
	}
7093
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   836
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   837
	/* read filenames */
20167
09e41ac6289d mpatch: rewrite pointer overflow checks
Matt Mackall <mpm@selenic.com>
parents: 20109
diff changeset
   838
	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
   839
		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
   840
			PyErr_SetString(PyExc_ValueError,
34862
d92dc725223b parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents: 34861
diff changeset
   841
			                "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
   842
			goto quit;
f5e8cb813a4d parsers: fix parse_dirstate to check len before unpacking header (issue4979)
Yuya Nishihara <yuya@tcha.org>
parents: 26872
diff changeset
   843
		}
20167
09e41ac6289d mpatch: rewrite pointer overflow checks
Matt Mackall <mpm@selenic.com>
parents: 20109
diff changeset
   844
		cur = str + pos;
7093
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   845
		/* unpack header */
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   846
		state = *cur;
16437
d126a0d16856 util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents: 16414
diff changeset
   847
		mode = getbe32(cur + 1);
d126a0d16856 util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents: 16414
diff changeset
   848
		size = getbe32(cur + 5);
d126a0d16856 util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents: 16414
diff changeset
   849
		mtime = getbe32(cur + 9);
d126a0d16856 util.h: replace ntohl/htonl with get/putbe32
Matt Mackall <mpm@selenic.com>
parents: 16414
diff changeset
   850
		flen = getbe32(cur + 13);
20167
09e41ac6289d mpatch: rewrite pointer overflow checks
Matt Mackall <mpm@selenic.com>
parents: 20109
diff changeset
   851
		pos += 17;
7093
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   852
		cur += 17;
20316
40f08c31844c parsers: fix 'unsigned expression is always true' warning (issue4142)
David Soria Parra <davidsp@fb.com>
parents: 20169
diff changeset
   853
		if (flen > len - pos) {
34862
d92dc725223b parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents: 34861
diff changeset
   854
			PyErr_SetString(PyExc_ValueError,
d92dc725223b parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents: 34861
diff changeset
   855
			                "overflow in dirstate");
7093
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   856
			goto quit;
7174
4da87407b845 parsers.c: fix integer overflows
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 7168
diff changeset
   857
		}
7093
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   858
47665
a4443f66be6a dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47539
diff changeset
   859
		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
   860
		                                               size, mtime);
48027
13efd8fdc55f dirstate: fix parse_dirstate() to error out if NULL entry created
Yuya Nishihara <yuya@tcha.org>
parents: 48025
diff changeset
   861
		if (!entry)
13efd8fdc55f dirstate: fix parse_dirstate() to error out if NULL entry created
Yuya Nishihara <yuya@tcha.org>
parents: 48025
diff changeset
   862
			goto quit;
7093
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   863
		cpos = memchr(cur, 0, flen);
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   864
		if (cpos) {
11361
3de3d670d2b6 parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents: 10449
diff changeset
   865
			fname = PyBytes_FromStringAndSize(cur, cpos - cur);
34862
d92dc725223b parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents: 34861
diff changeset
   866
			cname = PyBytes_FromStringAndSize(
d92dc725223b parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents: 34861
diff changeset
   867
			    cpos + 1, flen - (cpos - cur) - 1);
7093
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   868
			if (!fname || !cname ||
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   869
			    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
   870
			    PyDict_SetItem(dmap, fname, entry) == -1) {
7093
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   871
				goto quit;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 41016
diff changeset
   872
			}
7093
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   873
			Py_DECREF(cname);
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   874
		} else {
11361
3de3d670d2b6 parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents: 10449
diff changeset
   875
			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
   876
			if (!fname ||
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 41016
diff changeset
   877
			    PyDict_SetItem(dmap, fname, entry) == -1) {
7093
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   878
				goto quit;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 41016
diff changeset
   879
			}
7093
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   880
		}
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   881
		Py_DECREF(fname);
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   882
		Py_DECREF(entry);
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   883
		fname = cname = entry = NULL;
20167
09e41ac6289d mpatch: rewrite pointer overflow checks
Matt Mackall <mpm@selenic.com>
parents: 20109
diff changeset
   884
		pos += flen;
7093
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   885
	}
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   886
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   887
	ret = parents;
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   888
	Py_INCREF(ret);
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   889
quit:
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   890
	Py_XDECREF(fname);
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   891
	Py_XDECREF(cname);
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   892
	Py_XDECREF(entry);
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   893
	Py_XDECREF(parents);
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   894
	return ret;
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   895
}
16bafcebd3d1 dirstate: C parsing extension
Matt Mackall <mpm@selenic.com>
parents: 7092
diff changeset
   896
16955
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
   897
/*
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
   898
 * 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
   899
 */
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
   900
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
   901
{
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
   902
	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
   903
	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
   904
	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
   905
	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
   906
	char *p, *s;
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   907
	int now_s;
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   908
	int now_ns;
16955
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
   909
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   910
	if (!PyArg_ParseTuple(args, "O!O!O!(ii):pack_dirstate", &PyDict_Type,
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   911
	                      &map, &PyDict_Type, &copymap, &PyTuple_Type, &pl,
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   912
	                      &now_s, &now_ns)) {
16955
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
   913
		return NULL;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 41016
diff changeset
   914
	}
16955
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
   915
39422
adacefb0b7ea dirstate: use tuple interface to fix leak in pack_dirstate()
Yuya Nishihara <yuya@tcha.org>
parents: 37968
diff changeset
   916
	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
   917
		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
   918
		return NULL;
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
   919
	}
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
   920
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
   921
	/* 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
   922
	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
   923
		PyObject *c;
30100
c5afe5531709 parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30090
diff changeset
   924
		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
   925
			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
   926
			goto bail;
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
   927
		}
30100
c5afe5531709 parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30090
diff changeset
   928
		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
   929
		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
   930
		if (c) {
30100
c5afe5531709 parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30090
diff changeset
   931
			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
   932
				PyErr_SetString(PyExc_TypeError,
34862
d92dc725223b parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents: 34861
diff changeset
   933
				                "expected string key");
16955
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
   934
				goto bail;
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
   935
			}
30100
c5afe5531709 parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30090
diff changeset
   936
			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
   937
		}
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
   938
	}
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
   939
30100
c5afe5531709 parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30090
diff changeset
   940
	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
   941
	if (packobj == NULL) {
16955
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
   942
		goto bail;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 41016
diff changeset
   943
	}
16955
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
   944
30100
c5afe5531709 parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30090
diff changeset
   945
	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
   946
39422
adacefb0b7ea dirstate: use tuple interface to fix leak in pack_dirstate()
Yuya Nishihara <yuya@tcha.org>
parents: 37968
diff changeset
   947
	pn = PyTuple_GET_ITEM(pl, 0);
30100
c5afe5531709 parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30090
diff changeset
   948
	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
   949
		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
   950
		goto bail;
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
   951
	}
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
   952
	memcpy(p, s, l);
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
   953
	p += 20;
39422
adacefb0b7ea dirstate: use tuple interface to fix leak in pack_dirstate()
Yuya Nishihara <yuya@tcha.org>
parents: 37968
diff changeset
   954
	pn = PyTuple_GET_ITEM(pl, 1);
30100
c5afe5531709 parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30090
diff changeset
   955
	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
   956
		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
   957
		goto bail;
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
   958
	}
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
   959
	memcpy(p, s, l);
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
   960
	p += 20;
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
   961
34862
d92dc725223b parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents: 34861
diff changeset
   962
	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
   963
		dirstateItemObject *tuple;
21809
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 21807
diff changeset
   964
		char state;
26774
04ab2348efd1 parsers: correct type of temporary variables for dirstate tuple fields
Yuya Nishihara <yuya@tcha.org>
parents: 26630
diff changeset
   965
		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
   966
		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
   967
		PyObject *o;
21809
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 21807
diff changeset
   968
		char *t;
16955
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
   969
21809
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 21807
diff changeset
   970
		if (!dirstate_tuple_check(v)) {
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 21807
diff changeset
   971
			PyErr_SetString(PyExc_TypeError,
34862
d92dc725223b parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents: 34861
diff changeset
   972
			                "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
   973
			goto bail;
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
   974
		}
47539
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
   975
		tuple = (dirstateItemObject *)v;
21809
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 21807
diff changeset
   976
47948
83f0e93ec34b dirstate-item: move the C implementation to the same logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47947
diff changeset
   977
		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
   978
		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
   979
		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
   980
		mtime = dirstate_item_c_v1_mtime(tuple);
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48253
diff changeset
   981
		if (state == 'n' && tuple->mtime_s == now_s) {
18567
194e63c1ccb9 dirstate: move pure python dirstate packing to pure/parsers.py
Siddharth Agarwal <sid0@fb.com>
parents: 18504
diff changeset
   982
			/* 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
   983
			 * 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
   984
			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
   985
			mtime_unset = (PyObject *)dirstate_item_from_v1_data(
34862
d92dc725223b parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents: 34861
diff changeset
   986
			    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
   987
			if (!mtime_unset) {
16955
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
   988
				goto bail;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 41016
diff changeset
   989
			}
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 41016
diff changeset
   990
			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
   991
				goto bail;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 41016
diff changeset
   992
			}
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
   993
			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
   994
			mtime_unset = NULL;
16955
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
   995
		}
21809
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 21807
diff changeset
   996
		*p++ = state;
26774
04ab2348efd1 parsers: correct type of temporary variables for dirstate tuple fields
Yuya Nishihara <yuya@tcha.org>
parents: 26630
diff changeset
   997
		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
   998
		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
   999
		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
  1000
		t = p + 12;
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
  1001
		p += 16;
30100
c5afe5531709 parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30090
diff changeset
  1002
		len = PyBytes_GET_SIZE(k);
c5afe5531709 parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30090
diff changeset
  1003
		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
  1004
		p += len;
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
  1005
		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
  1006
		if (o) {
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
  1007
			*p++ = '\0';
30100
c5afe5531709 parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30090
diff changeset
  1008
			l = PyBytes_GET_SIZE(o);
c5afe5531709 parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30090
diff changeset
  1009
			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
  1010
			p += l;
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
  1011
			len += l + 1;
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
  1012
		}
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
  1013
		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
  1014
	}
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
  1015
30100
c5afe5531709 parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30090
diff changeset
  1016
	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
  1017
	if (pos != nbytes) {
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
  1018
		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
  1019
		             (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
  1020
		goto bail;
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
  1021
	}
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
  1022
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
  1023
	return packobj;
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
  1024
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
  1025
	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
  1026
	Py_XDECREF(packobj);
23946
f3e94aa6e182 parsers: don't leak a tuple in pack_dirstate
Augie Fackler <augie@google.com>
parents: 23945
diff changeset
  1027
	Py_XDECREF(v);
16955
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
  1028
	return NULL;
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
  1029
}
92e1c64ba0d4 parsers: add a C function to pack the dirstate
Bryan O'Sullivan <bryano@fb.com>
parents: 16863
diff changeset
  1030
24017
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1031
#define BUMPED_FIX 1
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1032
#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
  1033
#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
  1034
34862
d92dc725223b parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents: 34861
diff changeset
  1035
static PyObject *readshas(const char *source, unsigned char num,
d92dc725223b parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents: 34861
diff changeset
  1036
                          Py_ssize_t hashwidth)
24017
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1037
{
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1038
	int i;
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1039
	PyObject *list = PyTuple_New(num);
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1040
	if (list == NULL) {
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1041
		return NULL;
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1042
	}
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1043
	for (i = 0; i < num; i++) {
30100
c5afe5531709 parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30090
diff changeset
  1044
		PyObject *hash = PyBytes_FromStringAndSize(source, hashwidth);
24017
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1045
		if (hash == NULL) {
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1046
			Py_DECREF(list);
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1047
			return NULL;
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1048
		}
26213
4d6cdea33f37 parsers: use PyTuple_SET_ITEM() to fill new marker tuples
Yuya Nishihara <yuya@tcha.org>
parents: 26107
diff changeset
  1049
		PyTuple_SET_ITEM(list, i, hash);
24017
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1050
		source += hashwidth;
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1051
	}
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1052
	return list;
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1053
}
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1054
26591
042344313939 parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents: 26590
diff changeset
  1055
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
  1056
                               uint32_t *msize)
24017
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1057
{
26591
042344313939 parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents: 26590
diff changeset
  1058
	const char *data = databegin;
24017
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1059
	const char *meta;
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1060
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1061
	double mtime;
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1062
	int16_t tz;
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1063
	uint16_t flags;
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1064
	unsigned char nsuccs, nparents, nmetadata;
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1065
	Py_ssize_t hashwidth = 20;
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1066
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1067
	PyObject *prec = NULL, *parents = NULL, *succs = NULL;
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1068
	PyObject *metadata = NULL, *ret = NULL;
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1069
	int i;
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1070
26591
042344313939 parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents: 26590
diff changeset
  1071
	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
  1072
		goto overflow;
042344313939 parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents: 26590
diff changeset
  1073
	}
042344313939 parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents: 26590
diff changeset
  1074
24019
26fbf07482b2 _fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents: 24017
diff changeset
  1075
	*msize = getbe32(data);
24017
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1076
	data += 4;
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1077
	mtime = getbefloat64(data);
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1078
	data += 8;
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1079
	tz = getbeint16(data);
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1080
	data += 2;
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1081
	flags = getbeuint16(data);
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1082
	data += 2;
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1083
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1084
	if (flags & USING_SHA_256) {
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1085
		hashwidth = 32;
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1086
	}
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1087
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1088
	nsuccs = (unsigned char)(*data++);
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1089
	nparents = (unsigned char)(*data++);
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1090
	nmetadata = (unsigned char)(*data++);
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1091
26591
042344313939 parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents: 26590
diff changeset
  1092
	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
  1093
		goto overflow;
042344313939 parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents: 26590
diff changeset
  1094
	}
34862
d92dc725223b parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents: 34861
diff changeset
  1095
	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
  1096
042344313939 parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents: 26590
diff changeset
  1097
	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
  1098
		goto overflow;
042344313939 parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents: 26590
diff changeset
  1099
	}
30100
c5afe5531709 parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30090
diff changeset
  1100
	prec = PyBytes_FromStringAndSize(data, hashwidth);
24017
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1101
	data += hashwidth;
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1102
	if (prec == NULL) {
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1103
		goto bail;
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1104
	}
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1105
26591
042344313939 parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents: 26590
diff changeset
  1106
	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
  1107
		goto overflow;
042344313939 parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents: 26590
diff changeset
  1108
	}
24017
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1109
	succs = readshas(data, nsuccs, hashwidth);
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1110
	if (succs == NULL) {
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1111
		goto bail;
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1112
	}
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1113
	data += nsuccs * hashwidth;
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1114
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1115
	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
  1116
		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
  1117
			goto overflow;
042344313939 parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents: 26590
diff changeset
  1118
		}
24017
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1119
		parents = readshas(data, nparents, hashwidth);
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1120
		if (parents == NULL) {
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1121
			goto bail;
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1122
		}
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1123
		data += nparents * hashwidth;
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1124
	} else {
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1125
		parents = Py_None;
31426
43a7dfbead0c parsers: handle refcounting of "parents" consistently
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31292
diff changeset
  1126
		Py_INCREF(parents);
24017
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1127
	}
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1128
26591
042344313939 parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents: 26590
diff changeset
  1129
	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
  1130
		goto overflow;
042344313939 parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents: 26590
diff changeset
  1131
	}
24017
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1132
	meta = data + (2 * nmetadata);
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1133
	metadata = PyTuple_New(nmetadata);
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1134
	if (metadata == NULL) {
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1135
		goto bail;
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1136
	}
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1137
	for (i = 0; i < nmetadata; i++) {
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1138
		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
  1139
		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
  1140
		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
  1141
		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
  1142
			goto overflow;
042344313939 parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents: 26590
diff changeset
  1143
		}
30100
c5afe5531709 parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30090
diff changeset
  1144
		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
  1145
		meta += leftsize;
30100
c5afe5531709 parsers: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30090
diff changeset
  1146
		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
  1147
		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
  1148
		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
  1149
		if (!left || !right || !tmp) {
24017
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1150
			Py_XDECREF(left);
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1151
			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
  1152
			Py_XDECREF(tmp);
24017
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1153
			goto bail;
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1154
		}
26214
46605888faf3 parsers: use PyTuple_New and SET_ITEM to construct metadata pair of markers
Yuya Nishihara <yuya@tcha.org>
parents: 26213
diff changeset
  1155
		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
  1156
		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
  1157
		PyTuple_SET_ITEM(metadata, i, tmp);
24017
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1158
	}
34862
d92dc725223b parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents: 34861
diff changeset
  1159
	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
  1160
	                    (int)tz * 60, parents);
d92dc725223b parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents: 34861
diff changeset
  1161
	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
  1162
042344313939 parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents: 26590
diff changeset
  1163
overflow:
042344313939 parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents: 26590
diff changeset
  1164
	PyErr_SetString(PyExc_ValueError, "overflow in obsstore");
24017
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1165
bail:
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1166
	Py_XDECREF(prec);
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1167
	Py_XDECREF(succs);
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1168
	Py_XDECREF(metadata);
31426
43a7dfbead0c parsers: handle refcounting of "parents" consistently
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31292
diff changeset
  1169
	Py_XDECREF(parents);
24017
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1170
	return ret;
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1171
}
72c9b5ae7278 parsers: add fm1readmarker
Augie Fackler <augie@google.com>
parents: 24004
diff changeset
  1172
34440
7ed0750c71a1 cext: wrap before brace for functions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 34438
diff changeset
  1173
static PyObject *fm1readmarkers(PyObject *self, PyObject *args)
7ed0750c71a1 cext: wrap before brace for functions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 34438
diff changeset
  1174
{
26591
042344313939 parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents: 26590
diff changeset
  1175
	const char *data, *dataend;
42068
896b19d12c08 cext: make parsers.c PY_SSIZE_T_CLEAN
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41336
diff changeset
  1176
	Py_ssize_t datalen, offset, stop;
24019
26fbf07482b2 _fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents: 24017
diff changeset
  1177
	PyObject *markers = NULL;
26fbf07482b2 _fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents: 24017
diff changeset
  1178
36620
186c6df3a373 py3: bulk-replace 'const char*' format specifier passed to PyArg_ParseTuple*()
Yuya Nishihara <yuya@tcha.org>
parents: 36619
diff changeset
  1179
	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
  1180
	                      &offset, &stop)) {
24019
26fbf07482b2 _fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents: 24017
diff changeset
  1181
		return NULL;
26fbf07482b2 _fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents: 24017
diff changeset
  1182
	}
41016
5c68b617ba24 parsers: better bounds checking in fm1readmarkers
Augie Fackler <augie@google.com>
parents: 41011
diff changeset
  1183
	if (offset < 0) {
5c68b617ba24 parsers: better bounds checking in fm1readmarkers
Augie Fackler <augie@google.com>
parents: 41011
diff changeset
  1184
		PyErr_SetString(PyExc_ValueError,
5c68b617ba24 parsers: better bounds checking in fm1readmarkers
Augie Fackler <augie@google.com>
parents: 41011
diff changeset
  1185
		                "invalid negative offset in fm1readmarkers");
5c68b617ba24 parsers: better bounds checking in fm1readmarkers
Augie Fackler <augie@google.com>
parents: 41011
diff changeset
  1186
		return NULL;
5c68b617ba24 parsers: better bounds checking in fm1readmarkers
Augie Fackler <augie@google.com>
parents: 41011
diff changeset
  1187
	}
5c68b617ba24 parsers: better bounds checking in fm1readmarkers
Augie Fackler <augie@google.com>
parents: 41011
diff changeset
  1188
	if (stop > datalen) {
5c68b617ba24 parsers: better bounds checking in fm1readmarkers
Augie Fackler <augie@google.com>
parents: 41011
diff changeset
  1189
		PyErr_SetString(
5c68b617ba24 parsers: better bounds checking in fm1readmarkers
Augie Fackler <augie@google.com>
parents: 41011
diff changeset
  1190
		    PyExc_ValueError,
5c68b617ba24 parsers: better bounds checking in fm1readmarkers
Augie Fackler <augie@google.com>
parents: 41011
diff changeset
  1191
		    "stop longer than data length in fm1readmarkers");
5c68b617ba24 parsers: better bounds checking in fm1readmarkers
Augie Fackler <augie@google.com>
parents: 41011
diff changeset
  1192
		return NULL;
5c68b617ba24 parsers: better bounds checking in fm1readmarkers
Augie Fackler <augie@google.com>
parents: 41011
diff changeset
  1193
	}
26591
042344313939 parsers: fix infinite loop or out-of-bound read in fm1readmarkers (issue4888)
Yuya Nishihara <yuya@tcha.org>
parents: 26590
diff changeset
  1194
	dataend = data + datalen;
24019
26fbf07482b2 _fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents: 24017
diff changeset
  1195
	data += offset;
26fbf07482b2 _fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents: 24017
diff changeset
  1196
	markers = PyList_New(0);
26fbf07482b2 _fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents: 24017
diff changeset
  1197
	if (!markers) {
26fbf07482b2 _fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents: 24017
diff changeset
  1198
		return NULL;
26fbf07482b2 _fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents: 24017
diff changeset
  1199
	}
26fbf07482b2 _fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents: 24017
diff changeset
  1200
	while (offset < stop) {
26fbf07482b2 _fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents: 24017
diff changeset
  1201
		uint32_t msize;
26fbf07482b2 _fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents: 24017
diff changeset
  1202
		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
  1203
		PyObject *record = fm1readmarker(data, dataend, &msize);
24019
26fbf07482b2 _fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents: 24017
diff changeset
  1204
		if (!record) {
26fbf07482b2 _fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents: 24017
diff changeset
  1205
			goto bail;
26fbf07482b2 _fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents: 24017
diff changeset
  1206
		}
26fbf07482b2 _fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents: 24017
diff changeset
  1207
		error = PyList_Append(markers, record);
26fbf07482b2 _fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents: 24017
diff changeset
  1208
		Py_DECREF(record);
26fbf07482b2 _fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents: 24017
diff changeset
  1209
		if (error) {
26fbf07482b2 _fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents: 24017
diff changeset
  1210
			goto bail;
26fbf07482b2 _fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents: 24017
diff changeset
  1211
		}
26fbf07482b2 _fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents: 24017
diff changeset
  1212
		data += msize;
26fbf07482b2 _fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents: 24017
diff changeset
  1213
		offset += msize;
26fbf07482b2 _fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents: 24017
diff changeset
  1214
	}
26fbf07482b2 _fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents: 24017
diff changeset
  1215
	return markers;
26fbf07482b2 _fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents: 24017
diff changeset
  1216
bail:
26fbf07482b2 _fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents: 24017
diff changeset
  1217
	Py_DECREF(markers);
26fbf07482b2 _fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents: 24017
diff changeset
  1218
	return NULL;
26fbf07482b2 _fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents: 24017
diff changeset
  1219
}
26fbf07482b2 _fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents: 24017
diff changeset
  1220
6389
0231f763ebc8 manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
  1221
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
  1222
17606
318fb32b980e pathencode: new C module with fast encodedir() function
Adrian Buehlmann <adrian@cadifra.com>
parents: 17356
diff changeset
  1223
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
  1224
PyObject *pathencode(PyObject *self, PyObject *args);
18430
0459c6555f69 store: implement lowerencode in C
Bryan O'Sullivan <bryano@fb.com>
parents: 17616
diff changeset
  1225
PyObject *lowerencode(PyObject *self, PyObject *args);
46708
358737abeeef cext: add support for revlogv2
Raphaël Gomès <rgomes@octobus.net>
parents: 45131
diff changeset
  1226
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
  1227
6389
0231f763ebc8 manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
  1228
static PyMethodDef methods[] = {
34862
d92dc725223b parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents: 34861
diff changeset
  1229
    {"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
  1230
    {"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
  1231
    {"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
  1232
     "parse a revlog index\n"},
34862
d92dc725223b parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents: 34861
diff changeset
  1233
    {"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
  1234
    {"asciilower", asciilower, METH_VARARGS, "lowercase an ASCII string\n"},
d92dc725223b parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents: 34861
diff changeset
  1235
    {"asciiupper", asciiupper, METH_VARARGS, "uppercase an ASCII string\n"},
d92dc725223b parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents: 34861
diff changeset
  1236
    {"dict_new_presized", dict_new_presized, METH_VARARGS,
d92dc725223b parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents: 34861
diff changeset
  1237
     "construct a dict with an expected size\n"},
d92dc725223b parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents: 34861
diff changeset
  1238
    {"make_file_foldmap", make_file_foldmap, METH_VARARGS,
d92dc725223b parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents: 34861
diff changeset
  1239
     "make file foldmap\n"},
d92dc725223b parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents: 34861
diff changeset
  1240
    {"jsonescapeu8fast", jsonescapeu8fast, METH_VARARGS,
d92dc725223b parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents: 34861
diff changeset
  1241
     "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
  1242
    {"encodedir", encodedir, METH_VARARGS, "encodedir a path\n"},
d92dc725223b parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents: 34861
diff changeset
  1243
    {"pathencode", pathencode, METH_VARARGS, "fncache-encode a path\n"},
d92dc725223b parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents: 34861
diff changeset
  1244
    {"lowerencode", lowerencode, METH_VARARGS, "lower-encode a path\n"},
d92dc725223b parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents: 34861
diff changeset
  1245
    {"fm1readmarkers", fm1readmarkers, METH_VARARGS,
d92dc725223b parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents: 34861
diff changeset
  1246
     "parse v1 obsolete markers\n"},
d92dc725223b parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents: 34861
diff changeset
  1247
    {NULL, NULL}};
6389
0231f763ebc8 manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
  1248
18900
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents: 18567
diff changeset
  1249
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
  1250
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
  1251
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
  1252
47268
9d1a8829f959 revlog: signal which revlog index are compatible with Rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47249
diff changeset
  1253
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
  1254
16363
2cdd7e63211b parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents: 15033
diff changeset
  1255
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
  1256
{
32360
af3ef002395d parsers: add version to help detect breaking binary changes
Jun Wu <quark@fb.com>
parents: 31470
diff changeset
  1257
	PyModule_AddIntConstant(mod, "version", version);
af3ef002395d parsers: add version to help detect breaking binary changes
Jun Wu <quark@fb.com>
parents: 31470
diff changeset
  1258
20742
3681de20b0a7 parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents: 20555
diff changeset
  1259
	/* 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
  1260
	 * 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
  1261
	 * 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
  1262
	 * 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
  1263
	 * 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
  1264
	 * 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
  1265
	 * 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
  1266
	 * 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
  1267
	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
  1268
18900
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents: 18567
diff changeset
  1269
	dirs_module_init(mod);
24214
a5f1bccd2996 manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents: 24032
diff changeset
  1270
	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
  1271
	revlog_module_init(mod);
18900
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents: 18567
diff changeset
  1272
47539
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
  1273
	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
  1274
		return;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 41016
diff changeset
  1275
	}
47539
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
  1276
	Py_INCREF(&dirstateItemType);
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
  1277
	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
  1278
}
2cdd7e63211b parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents: 15033
diff changeset
  1279
20742
3681de20b0a7 parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents: 20555
diff changeset
  1280
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
  1281
{
23943
5fb44983a696 parsers: don't leak references to sys et al in check_python_version
Augie Fackler <augie@google.com>
parents: 23942
diff changeset
  1282
	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
  1283
	long hexversion;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 41016
diff changeset
  1284
	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
  1285
		return -1;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 41016
diff changeset
  1286
	}
23943
5fb44983a696 parsers: don't leak references to sys et al in check_python_version
Augie Fackler <augie@google.com>
parents: 23942
diff changeset
  1287
	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
  1288
	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
  1289
	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
  1290
		return -1;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 41016
diff changeset
  1291
	}
23943
5fb44983a696 parsers: don't leak references to sys et al in check_python_version
Augie Fackler <augie@google.com>
parents: 23942
diff changeset
  1292
	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
  1293
	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
  1294
	/* 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
  1295
	 * 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
  1296
	 * 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
  1297
	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
  1298
		PyErr_Format(PyExc_ImportError,
d92dc725223b parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents: 34861
diff changeset
  1299
		             "%s: The Mercurial extension "
d92dc725223b parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents: 34861
diff changeset
  1300
		             "modules were compiled with Python " PY_VERSION
d92dc725223b parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents: 34861
diff changeset
  1301
		             ", but "
d92dc725223b parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents: 34861
diff changeset
  1302
		             "Mercurial is currently using Python with "
d92dc725223b parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents: 34861
diff changeset
  1303
		             "sys.hexversion=%ld: "
d92dc725223b parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents: 34861
diff changeset
  1304
		             "Python %s\n at: %s",
d92dc725223b parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents: 34861
diff changeset
  1305
		             versionerrortext, hexversion, Py_GetVersion(),
d92dc725223b parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents: 34861
diff changeset
  1306
		             Py_GetProgramFullPath());
20742
3681de20b0a7 parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents: 20555
diff changeset
  1307
		return -1;
3681de20b0a7 parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents: 20555
diff changeset
  1308
	}
3681de20b0a7 parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents: 20555
diff changeset
  1309
	return 0;
3681de20b0a7 parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents: 20555
diff changeset
  1310
}
3681de20b0a7 parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents: 20555
diff changeset
  1311
11361
3de3d670d2b6 parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents: 10449
diff changeset
  1312
#ifdef IS_PY3K
34862
d92dc725223b parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents: 34861
diff changeset
  1313
static struct PyModuleDef parsers_module = {PyModuleDef_HEAD_INIT, "parsers",
d92dc725223b parsers: allow clang-format here
Augie Fackler <augie@google.com>
parents: 34861
diff changeset
  1314
                                            parsers_doc, -1, methods};
11361
3de3d670d2b6 parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents: 10449
diff changeset
  1315
3de3d670d2b6 parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents: 10449
diff changeset
  1316
PyMODINIT_FUNC PyInit_parsers(void)
3de3d670d2b6 parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents: 10449
diff changeset
  1317
{
20797
e286ab22e461 parsers: fix compiler errors on MSVC 2008
Matt Harbison <matt_harbison@yahoo.com>
parents: 20742
diff changeset
  1318
	PyObject *mod;
e286ab22e461 parsers: fix compiler errors on MSVC 2008
Matt Harbison <matt_harbison@yahoo.com>
parents: 20742
diff changeset
  1319
20742
3681de20b0a7 parsers: fail fast if Python has wrong minor version (issue4110)
Chris Jerdonek <chris.jerdonek@gmail.com>
parents: 20555
diff changeset
  1320
	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
  1321
		return NULL;
20797
e286ab22e461 parsers: fix compiler errors on MSVC 2008
Matt Harbison <matt_harbison@yahoo.com>
parents: 20742
diff changeset
  1322
	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
  1323
	module_init(mod);
2cdd7e63211b parsers: incrementally parse the revlog index in C
Bryan O'Sullivan <bryano@fb.com>
parents: 15033
diff changeset
  1324
	return mod;
11361
3de3d670d2b6 parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents: 10449
diff changeset
  1325
}
3de3d670d2b6 parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents: 10449
diff changeset
  1326
#else
6389
0231f763ebc8 manifest: improve parsing performance by 8x via a new C extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
  1327
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
  1328
{
20797
e286ab22e461 parsers: fix compiler errors on MSVC 2008
Matt Harbison <matt_harbison@yahoo.com>
parents: 20742
diff changeset
  1329
	PyObject *mod;
e286ab22e461 parsers: fix compiler errors on MSVC 2008
Matt Harbison <matt_harbison@yahoo.com>
parents: 20742
diff changeset
  1330
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 41016
diff changeset
  1331
	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
  1332
		return;
41336
763b45bc4483 cleanup: use clang-tidy to add missing {} around one-line statements
Augie Fackler <augie@google.com>
parents: 41016
diff changeset
  1333
	}
20797
e286ab22e461 parsers: fix compiler errors on MSVC 2008
Matt Harbison <matt_harbison@yahoo.com>
parents: 20742
diff changeset
  1334
	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
  1335
	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
  1336
}
11361
3de3d670d2b6 parsers.c: Added support for py3k.
Renato Cunha <renatoc@gmail.com>
parents: 10449
diff changeset
  1337
#endif