Mercurial > hg
diff mercurial/cext/dirs.c @ 47944:e02f9af7aed1
pathutil: replace the `skip` argument of `dirs` with a boolean
It is ever only used for `r` file. So we make it a boolean this will give use
more versatility later as we will stop storing the state explicitly.
Differential Revision: https://phab.mercurial-scm.org/D11383
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Mon, 30 Aug 2021 18:45:54 +0200 |
parents | 84391ddf4c78 |
children | 83f0e93ec34b |
line wrap: on
line diff
--- a/mercurial/cext/dirs.c Thu Sep 02 00:16:37 2021 +0200 +++ b/mercurial/cext/dirs.c Mon Aug 30 18:45:54 2021 +0200 @@ -161,7 +161,7 @@ return ret; } -static int dirs_fromdict(PyObject *dirs, PyObject *source, char skipchar) +static int dirs_fromdict(PyObject *dirs, PyObject *source, bool only_tracked) { PyObject *key, *value; Py_ssize_t pos = 0; @@ -171,13 +171,13 @@ PyErr_SetString(PyExc_TypeError, "expected string key"); return -1; } - if (skipchar) { + if (only_tracked) { if (!dirstate_tuple_check(value)) { PyErr_SetString(PyExc_TypeError, "expected a dirstate tuple"); return -1; } - if (((dirstateItemObject *)value)->state == skipchar) + if (((dirstateItemObject *)value)->state == 'r') continue; } @@ -218,15 +218,17 @@ * Calculate a refcounted set of directory names for the files in a * dirstate. */ -static int dirs_init(dirsObject *self, PyObject *args) +static int dirs_init(dirsObject *self, PyObject *args, PyObject *kwargs) { PyObject *dirs = NULL, *source = NULL; - char skipchar = 0; + int only_tracked = 0; int ret = -1; + static char *keywords_name[] = {"map", "only_tracked", NULL}; self->dict = NULL; - if (!PyArg_ParseTuple(args, "|Oc:__init__", &source, &skipchar)) + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|Oi:__init__", + keywords_name, &source, &only_tracked)) return -1; dirs = PyDict_New(); @@ -237,10 +239,10 @@ if (source == NULL) ret = 0; else if (PyDict_Check(source)) - ret = dirs_fromdict(dirs, source, skipchar); - else if (skipchar) + ret = dirs_fromdict(dirs, source, (bool)only_tracked); + else if (only_tracked) PyErr_SetString(PyExc_ValueError, - "skip character is only supported " + "`only_tracked` is only supported " "with a dict source"); else ret = dirs_fromiter(dirs, source);