mercurial/dirs.c
author Martin von Zweigbergk <martinvonz@google.com>
Fri, 27 Mar 2015 16:19:44 -0700
changeset 24526 cd50f3717639
parent 24486 1a9efc312700
child 24624 6f0e6fa9fdd7
permissions -rw-r--r--
manifestv2: add (unused) config option With tree manifests, hashes will change anyway, so now is a good time to also take up the old plans of a new manifest format. While there should be little or no reason to use tree manifests with the current manifest format (v1) once the new format (v2) is supported, we'll try to keep the two dimensions (flat/tree and v1/v2) separate. In preparation for adding a the new format, let's add configuration for it and propagate that configuration to the manifest revlog subclass. The new configuration ("experimental.manifestv2") says in what format to write the manifest data. We may later add other configuration to choose how to hash it, either keeping the v1 hash for BC or hashing the v2 content. See http://mercurial.selenic.com/wiki/ManifestV2Plan for more details.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18900
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
     1
/*
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
     2
 dirs.c - dynamic directory diddling for dirstates
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
     3
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
     4
 Copyright 2013 Facebook
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
     5
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
     6
 This software may be used and distributed according to the terms of
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
     7
 the GNU General Public License, incorporated herein by reference.
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
     8
*/
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
     9
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
    10
#define PY_SSIZE_T_CLEAN
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
    11
#include <Python.h>
24486
1a9efc312700 dirs.addpath: rework algorithm to search forward
Siddharth Agarwal <sid0@fb.com>
parents: 23960
diff changeset
    12
#include <string.h>
18900
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
    13
#include "util.h"
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
    14
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
    15
/*
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
    16
 * This is a multiset of directory names, built from the files that
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
    17
 * appear in a dirstate or manifest.
18901
66d3aebe2d95 dirs: use mutable integers internally
Bryan O'Sullivan <bryano@fb.com>
parents: 18900
diff changeset
    18
 *
66d3aebe2d95 dirs: use mutable integers internally
Bryan O'Sullivan <bryano@fb.com>
parents: 18900
diff changeset
    19
 * A few implementation notes:
66d3aebe2d95 dirs: use mutable integers internally
Bryan O'Sullivan <bryano@fb.com>
parents: 18900
diff changeset
    20
 *
66d3aebe2d95 dirs: use mutable integers internally
Bryan O'Sullivan <bryano@fb.com>
parents: 18900
diff changeset
    21
 * We modify Python integers for refcounting, but those integers are
66d3aebe2d95 dirs: use mutable integers internally
Bryan O'Sullivan <bryano@fb.com>
parents: 18900
diff changeset
    22
 * never visible to Python code.
18902
8c0a7eeda06d dirs: use mutable strings internally
Bryan O'Sullivan <bryano@fb.com>
parents: 18901
diff changeset
    23
 *
8c0a7eeda06d dirs: use mutable strings internally
Bryan O'Sullivan <bryano@fb.com>
parents: 18901
diff changeset
    24
 * We mutate strings in-place, but leave them immutable once they can
8c0a7eeda06d dirs: use mutable strings internally
Bryan O'Sullivan <bryano@fb.com>
parents: 18901
diff changeset
    25
 * be seen by Python code.
18900
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
    26
 */
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
    27
typedef struct {
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
    28
	PyObject_HEAD
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
    29
	PyObject *dict;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
    30
} dirsObject;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
    31
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
    32
static inline Py_ssize_t _finddir(PyObject *path, Py_ssize_t pos)
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
    33
{
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
    34
	const char *s = PyString_AS_STRING(path);
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
    35
24486
1a9efc312700 dirs.addpath: rework algorithm to search forward
Siddharth Agarwal <sid0@fb.com>
parents: 23960
diff changeset
    36
	const char *ret = strchr(s + pos, '/');
1a9efc312700 dirs.addpath: rework algorithm to search forward
Siddharth Agarwal <sid0@fb.com>
parents: 23960
diff changeset
    37
	return (ret != NULL) ? (ret - s) : -1;
18900
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
    38
}
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
    39
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
    40
static int _addpath(PyObject *dirs, PyObject *path)
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
    41
{
24486
1a9efc312700 dirs.addpath: rework algorithm to search forward
Siddharth Agarwal <sid0@fb.com>
parents: 23960
diff changeset
    42
	char *cpath = PyString_AS_STRING(path);
1a9efc312700 dirs.addpath: rework algorithm to search forward
Siddharth Agarwal <sid0@fb.com>
parents: 23960
diff changeset
    43
	Py_ssize_t len = PyString_GET_SIZE(path);
1a9efc312700 dirs.addpath: rework algorithm to search forward
Siddharth Agarwal <sid0@fb.com>
parents: 23960
diff changeset
    44
	Py_ssize_t pos = -1;
18901
66d3aebe2d95 dirs: use mutable integers internally
Bryan O'Sullivan <bryano@fb.com>
parents: 18900
diff changeset
    45
	PyObject *key = NULL;
18900
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
    46
	int ret = -1;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
    47
24486
1a9efc312700 dirs.addpath: rework algorithm to search forward
Siddharth Agarwal <sid0@fb.com>
parents: 23960
diff changeset
    48
	while ((pos = _finddir(path, pos + 1)) != -1) {
18900
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
    49
		PyObject *val;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
    50
18902
8c0a7eeda06d dirs: use mutable strings internally
Bryan O'Sullivan <bryano@fb.com>
parents: 18901
diff changeset
    51
		/* It's likely that every prefix already has an entry
8c0a7eeda06d dirs: use mutable strings internally
Bryan O'Sullivan <bryano@fb.com>
parents: 18901
diff changeset
    52
		   in our dict. Try to avoid allocating and
8c0a7eeda06d dirs: use mutable strings internally
Bryan O'Sullivan <bryano@fb.com>
parents: 18901
diff changeset
    53
		   deallocating a string for each prefix we check. */
8c0a7eeda06d dirs: use mutable strings internally
Bryan O'Sullivan <bryano@fb.com>
parents: 18901
diff changeset
    54
		if (key != NULL)
8c0a7eeda06d dirs: use mutable strings internally
Bryan O'Sullivan <bryano@fb.com>
parents: 18901
diff changeset
    55
			((PyStringObject *)key)->ob_shash = -1;
24486
1a9efc312700 dirs.addpath: rework algorithm to search forward
Siddharth Agarwal <sid0@fb.com>
parents: 23960
diff changeset
    56
		else if (pos != 0) {
1a9efc312700 dirs.addpath: rework algorithm to search forward
Siddharth Agarwal <sid0@fb.com>
parents: 23960
diff changeset
    57
			/* pos >= 1, which means that len >= 2. This is
1a9efc312700 dirs.addpath: rework algorithm to search forward
Siddharth Agarwal <sid0@fb.com>
parents: 23960
diff changeset
    58
			   guaranteed to produce a non-interned string. */
1a9efc312700 dirs.addpath: rework algorithm to search forward
Siddharth Agarwal <sid0@fb.com>
parents: 23960
diff changeset
    59
			key = PyString_FromStringAndSize(cpath, len);
1a9efc312700 dirs.addpath: rework algorithm to search forward
Siddharth Agarwal <sid0@fb.com>
parents: 23960
diff changeset
    60
			if (key == NULL)
1a9efc312700 dirs.addpath: rework algorithm to search forward
Siddharth Agarwal <sid0@fb.com>
parents: 23960
diff changeset
    61
				goto bail;
1a9efc312700 dirs.addpath: rework algorithm to search forward
Siddharth Agarwal <sid0@fb.com>
parents: 23960
diff changeset
    62
		} else {
1a9efc312700 dirs.addpath: rework algorithm to search forward
Siddharth Agarwal <sid0@fb.com>
parents: 23960
diff changeset
    63
			/* pos == 0, which means we need to increment the dir
1a9efc312700 dirs.addpath: rework algorithm to search forward
Siddharth Agarwal <sid0@fb.com>
parents: 23960
diff changeset
    64
			   count for the empty string. We need to make sure we
1a9efc312700 dirs.addpath: rework algorithm to search forward
Siddharth Agarwal <sid0@fb.com>
parents: 23960
diff changeset
    65
			   don't muck around with interned strings, so throw it
1a9efc312700 dirs.addpath: rework algorithm to search forward
Siddharth Agarwal <sid0@fb.com>
parents: 23960
diff changeset
    66
			   away later. */
1a9efc312700 dirs.addpath: rework algorithm to search forward
Siddharth Agarwal <sid0@fb.com>
parents: 23960
diff changeset
    67
			key = PyString_FromString("");
18902
8c0a7eeda06d dirs: use mutable strings internally
Bryan O'Sullivan <bryano@fb.com>
parents: 18901
diff changeset
    68
			if (key == NULL)
8c0a7eeda06d dirs: use mutable strings internally
Bryan O'Sullivan <bryano@fb.com>
parents: 18901
diff changeset
    69
				goto bail;
8c0a7eeda06d dirs: use mutable strings internally
Bryan O'Sullivan <bryano@fb.com>
parents: 18901
diff changeset
    70
		}
8c0a7eeda06d dirs: use mutable strings internally
Bryan O'Sullivan <bryano@fb.com>
parents: 18901
diff changeset
    71
		PyString_GET_SIZE(key) = pos;
8c0a7eeda06d dirs: use mutable strings internally
Bryan O'Sullivan <bryano@fb.com>
parents: 18901
diff changeset
    72
		PyString_AS_STRING(key)[pos] = '\0';
18900
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
    73
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
    74
		val = PyDict_GetItem(dirs, key);
18901
66d3aebe2d95 dirs: use mutable integers internally
Bryan O'Sullivan <bryano@fb.com>
parents: 18900
diff changeset
    75
		if (val != NULL) {
66d3aebe2d95 dirs: use mutable integers internally
Bryan O'Sullivan <bryano@fb.com>
parents: 18900
diff changeset
    76
			PyInt_AS_LONG(val) += 1;
24486
1a9efc312700 dirs.addpath: rework algorithm to search forward
Siddharth Agarwal <sid0@fb.com>
parents: 23960
diff changeset
    77
			if (pos != 0)
1a9efc312700 dirs.addpath: rework algorithm to search forward
Siddharth Agarwal <sid0@fb.com>
parents: 23960
diff changeset
    78
				PyString_AS_STRING(key)[pos] = '/';
1a9efc312700 dirs.addpath: rework algorithm to search forward
Siddharth Agarwal <sid0@fb.com>
parents: 23960
diff changeset
    79
			else
1a9efc312700 dirs.addpath: rework algorithm to search forward
Siddharth Agarwal <sid0@fb.com>
parents: 23960
diff changeset
    80
				key = NULL;
18901
66d3aebe2d95 dirs: use mutable integers internally
Bryan O'Sullivan <bryano@fb.com>
parents: 18900
diff changeset
    81
			continue;
66d3aebe2d95 dirs: use mutable integers internally
Bryan O'Sullivan <bryano@fb.com>
parents: 18900
diff changeset
    82
		}
18900
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
    83
18901
66d3aebe2d95 dirs: use mutable integers internally
Bryan O'Sullivan <bryano@fb.com>
parents: 18900
diff changeset
    84
		/* Force Python to not reuse a small shared int. */
66d3aebe2d95 dirs: use mutable integers internally
Bryan O'Sullivan <bryano@fb.com>
parents: 18900
diff changeset
    85
		val = PyInt_FromLong(0x1eadbeef);
18900
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
    86
18901
66d3aebe2d95 dirs: use mutable integers internally
Bryan O'Sullivan <bryano@fb.com>
parents: 18900
diff changeset
    87
		if (val == NULL)
18900
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
    88
			goto bail;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
    89
18901
66d3aebe2d95 dirs: use mutable integers internally
Bryan O'Sullivan <bryano@fb.com>
parents: 18900
diff changeset
    90
		PyInt_AS_LONG(val) = 1;
66d3aebe2d95 dirs: use mutable integers internally
Bryan O'Sullivan <bryano@fb.com>
parents: 18900
diff changeset
    91
		ret = PyDict_SetItem(dirs, key, val);
66d3aebe2d95 dirs: use mutable integers internally
Bryan O'Sullivan <bryano@fb.com>
parents: 18900
diff changeset
    92
		Py_DECREF(val);
18900
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
    93
		if (ret == -1)
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
    94
			goto bail;
24486
1a9efc312700 dirs.addpath: rework algorithm to search forward
Siddharth Agarwal <sid0@fb.com>
parents: 23960
diff changeset
    95
1a9efc312700 dirs.addpath: rework algorithm to search forward
Siddharth Agarwal <sid0@fb.com>
parents: 23960
diff changeset
    96
		if (pos != 0)
1a9efc312700 dirs.addpath: rework algorithm to search forward
Siddharth Agarwal <sid0@fb.com>
parents: 23960
diff changeset
    97
			PyString_AS_STRING(key)[pos] = '/';
1a9efc312700 dirs.addpath: rework algorithm to search forward
Siddharth Agarwal <sid0@fb.com>
parents: 23960
diff changeset
    98
		else
1a9efc312700 dirs.addpath: rework algorithm to search forward
Siddharth Agarwal <sid0@fb.com>
parents: 23960
diff changeset
    99
			key = NULL;
18900
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   100
		Py_CLEAR(key);
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   101
	}
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   102
	ret = 0;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   103
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   104
bail:
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   105
	Py_XDECREF(key);
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   106
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   107
	return ret;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   108
}
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   109
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   110
static int _delpath(PyObject *dirs, PyObject *path)
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   111
{
24486
1a9efc312700 dirs.addpath: rework algorithm to search forward
Siddharth Agarwal <sid0@fb.com>
parents: 23960
diff changeset
   112
	Py_ssize_t pos = -1;
18901
66d3aebe2d95 dirs: use mutable integers internally
Bryan O'Sullivan <bryano@fb.com>
parents: 18900
diff changeset
   113
	PyObject *key = NULL;
18900
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   114
	int ret = -1;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   115
24486
1a9efc312700 dirs.addpath: rework algorithm to search forward
Siddharth Agarwal <sid0@fb.com>
parents: 23960
diff changeset
   116
	while ((pos = _finddir(path, pos + 1)) != -1) {
18900
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   117
		PyObject *val;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   118
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   119
		key = PyString_FromStringAndSize(PyString_AS_STRING(path), pos);
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   120
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   121
		if (key == NULL)
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   122
			goto bail;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   123
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   124
		val = PyDict_GetItem(dirs, key);
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   125
		if (val == NULL) {
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   126
			PyErr_SetString(PyExc_ValueError,
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   127
					"expected a value, found none");
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   128
			goto bail;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   129
		}
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   130
18901
66d3aebe2d95 dirs: use mutable integers internally
Bryan O'Sullivan <bryano@fb.com>
parents: 18900
diff changeset
   131
		if (--PyInt_AS_LONG(val) <= 0 &&
66d3aebe2d95 dirs: use mutable integers internally
Bryan O'Sullivan <bryano@fb.com>
parents: 18900
diff changeset
   132
		    PyDict_DelItem(dirs, key) == -1)
18900
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   133
			goto bail;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   134
		Py_CLEAR(key);
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   135
	}
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   136
	ret = 0;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   137
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   138
bail:
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   139
	Py_XDECREF(key);
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   140
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   141
	return ret;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   142
}
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   143
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   144
static int dirs_fromdict(PyObject *dirs, PyObject *source, char skipchar)
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   145
{
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   146
	PyObject *key, *value;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   147
	Py_ssize_t pos = 0;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   148
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   149
	while (PyDict_Next(source, &pos, &key, &value)) {
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   150
		if (!PyString_Check(key)) {
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   151
			PyErr_SetString(PyExc_TypeError, "expected string key");
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   152
			return -1;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   153
		}
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   154
		if (skipchar) {
21809
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 18902
diff changeset
   155
			if (!dirstate_tuple_check(value)) {
18900
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   156
				PyErr_SetString(PyExc_TypeError,
21809
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 18902
diff changeset
   157
						"expected a dirstate tuple");
18900
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   158
				return -1;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   159
			}
21809
e250b8300e6e parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents: 18902
diff changeset
   160
			if (((dirstateTupleObject *)value)->state == skipchar)
18900
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   161
				continue;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   162
		}
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   163
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   164
		if (_addpath(dirs, key) == -1)
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   165
			return -1;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   166
	}
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   167
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   168
	return 0;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   169
}
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   170
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   171
static int dirs_fromiter(PyObject *dirs, PyObject *source)
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   172
{
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   173
	PyObject *iter, *item = NULL;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   174
	int ret;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   175
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   176
	iter = PyObject_GetIter(source);
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   177
	if (iter == NULL)
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   178
		return -1;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   179
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   180
	while ((item = PyIter_Next(iter)) != NULL) {
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   181
		if (!PyString_Check(item)) {
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   182
			PyErr_SetString(PyExc_TypeError, "expected string");
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   183
			break;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   184
		}
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   185
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   186
		if (_addpath(dirs, item) == -1)
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   187
			break;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   188
		Py_CLEAR(item);
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   189
	}
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   190
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   191
	ret = PyErr_Occurred() ? -1 : 0;
23960
bca4b6f126f2 dirs: fix leak of iterator in dirs_fromiter
Augie Fackler <augie@google.com>
parents: 21809
diff changeset
   192
	Py_DECREF(iter);
18900
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   193
	Py_XDECREF(item);
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   194
	return ret;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   195
}
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   196
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   197
/*
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   198
 * Calculate a refcounted set of directory names for the files in a
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   199
 * dirstate.
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   200
 */
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   201
static int dirs_init(dirsObject *self, PyObject *args)
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   202
{
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   203
	PyObject *dirs = NULL, *source = NULL;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   204
	char skipchar = 0;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   205
	int ret = -1;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   206
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   207
	self->dict = NULL;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   208
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   209
	if (!PyArg_ParseTuple(args, "|Oc:__init__", &source, &skipchar))
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   210
		return -1;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   211
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   212
	dirs = PyDict_New();
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   213
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   214
	if (dirs == NULL)
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   215
		return -1;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   216
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   217
	if (source == NULL)
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   218
		ret = 0;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   219
	else if (PyDict_Check(source))
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   220
		ret = dirs_fromdict(dirs, source, skipchar);
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   221
	else if (skipchar)
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   222
		PyErr_SetString(PyExc_ValueError,
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   223
				"skip character is only supported "
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   224
				"with a dict source");
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   225
	else
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   226
		ret = dirs_fromiter(dirs, source);
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   227
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   228
	if (ret == -1)
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   229
		Py_XDECREF(dirs);
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   230
	else
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   231
		self->dict = dirs;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   232
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   233
	return ret;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   234
}
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   235
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   236
PyObject *dirs_addpath(dirsObject *self, PyObject *args)
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   237
{
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   238
	PyObject *path;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   239
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   240
	if (!PyArg_ParseTuple(args, "O!:addpath", &PyString_Type, &path))
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   241
		return NULL;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   242
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   243
	if (_addpath(self->dict, path) == -1)
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   244
		return NULL;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   245
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   246
	Py_RETURN_NONE;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   247
}
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   248
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   249
static PyObject *dirs_delpath(dirsObject *self, PyObject *args)
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   250
{
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   251
	PyObject *path;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   252
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   253
	if (!PyArg_ParseTuple(args, "O!:delpath", &PyString_Type, &path))
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   254
		return NULL;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   255
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   256
	if (_delpath(self->dict, path) == -1)
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   257
		return NULL;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   258
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   259
	Py_RETURN_NONE;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   260
}
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   261
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   262
static int dirs_contains(dirsObject *self, PyObject *value)
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   263
{
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   264
	return PyString_Check(value) ? PyDict_Contains(self->dict, value) : 0;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   265
}
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   266
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   267
static void dirs_dealloc(dirsObject *self)
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   268
{
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   269
	Py_XDECREF(self->dict);
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   270
	PyObject_Del(self);
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   271
}
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   272
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   273
static PyObject *dirs_iter(dirsObject *self)
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   274
{
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   275
	return PyObject_GetIter(self->dict);
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   276
}
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   277
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   278
static PySequenceMethods dirs_sequence_methods;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   279
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   280
static PyMethodDef dirs_methods[] = {
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   281
	{"addpath", (PyCFunction)dirs_addpath, METH_VARARGS, "add a path"},
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   282
	{"delpath", (PyCFunction)dirs_delpath, METH_VARARGS, "remove a path"},
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   283
	{NULL} /* Sentinel */
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   284
};
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   285
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   286
static PyTypeObject dirsType = { PyObject_HEAD_INIT(NULL) };
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   287
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   288
void dirs_module_init(PyObject *mod)
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   289
{
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   290
	dirs_sequence_methods.sq_contains = (objobjproc)dirs_contains;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   291
	dirsType.tp_name = "parsers.dirs";
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   292
	dirsType.tp_new = PyType_GenericNew;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   293
	dirsType.tp_basicsize = sizeof(dirsObject);
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   294
	dirsType.tp_dealloc = (destructor)dirs_dealloc;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   295
	dirsType.tp_as_sequence = &dirs_sequence_methods;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   296
	dirsType.tp_flags = Py_TPFLAGS_DEFAULT;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   297
	dirsType.tp_doc = "dirs";
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   298
	dirsType.tp_iter = (getiterfunc)dirs_iter;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   299
	dirsType.tp_methods = dirs_methods;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   300
	dirsType.tp_init = (initproc)dirs_init;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   301
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   302
	if (PyType_Ready(&dirsType) < 0)
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   303
		return;
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   304
	Py_INCREF(&dirsType);
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   305
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   306
	PyModule_AddObject(mod, "dirs", (PyObject *)&dirsType);
02ee846b246a scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff changeset
   307
}