|
25 | 25 | * Boston, MA 02110-1301, USA. |
26 | 26 | */ |
27 | 27 |
|
| 28 | +#include <git2/status.h> |
28 | 29 | #define PY_SSIZE_T_CLEAN |
29 | 30 | #include <Python.h> |
30 | 31 | #include "error.h" |
@@ -1771,20 +1772,62 @@ Repository_compress_references(Repository *self) |
1771 | 1772 | } |
1772 | 1773 |
|
1773 | 1774 | PyDoc_STRVAR(Repository_status__doc__, |
1774 | | - "status() -> dict[str, int]\n" |
| 1775 | + "status(untracked_files: str = \"all\", ignored: bool = False) -> dict[str, int]\n" |
1775 | 1776 | "\n" |
1776 | 1777 | "Reads the status of the repository and returns a dictionary with file\n" |
1777 | | - "paths as keys and status flags as values. See pygit2.GIT_STATUS_*."); |
| 1778 | + "paths as keys and status flags as values. See pygit2.GIT_STATUS_*.\n" |
| 1779 | + "\n" |
| 1780 | + "Parameters:\n" |
| 1781 | + "\n" |
| 1782 | + "untracked_files\n" |
| 1783 | + " How to handle untracked files, defaults to \"all\"\n" |
| 1784 | + " \"no\": do not return untracked files\n" |
| 1785 | + " \"normal\": include untracked files/directories but no dot recurse subdirectories\n" |
| 1786 | + " \"all\": include all files in untracked directories\n" |
| 1787 | + " Using `untracked_files=\"no\"` or \"normal\"can be faster than \"all\" when the worktree\n" |
| 1788 | + "ignored\n" |
| 1789 | + " Whether to show ignored files with untracked files. Ignored when untracked_files == \"no\"\n" |
| 1790 | + " Defaults to False.\n" |
| 1791 | + "contains many untracked files/directories."); |
1778 | 1792 |
|
1779 | 1793 | PyObject * |
1780 | | -Repository_status(Repository *self) |
| 1794 | +Repository_status(Repository *self, PyObject *args, PyObject *kw) |
1781 | 1795 | { |
1782 | 1796 | PyObject *dict; |
1783 | 1797 | int err; |
1784 | 1798 | size_t len, i; |
1785 | 1799 | git_status_list *list; |
1786 | 1800 |
|
1787 | | - err = git_status_list_new(&list, self->repo, NULL); |
| 1801 | + char *untracked_files = "all"; |
| 1802 | + static char *kwlist[] = {"untracked_files", "ignored", NULL}; |
| 1803 | + |
| 1804 | + PyObject* ignored = Py_False; |
| 1805 | + |
| 1806 | + if (!PyArg_ParseTupleAndKeywords(args, kw, "|sO", kwlist, |
| 1807 | + &untracked_files, &ignored)) |
| 1808 | + goto error; |
| 1809 | + |
| 1810 | + git_status_options opts = GIT_STATUS_OPTIONS_INIT; |
| 1811 | + opts.flags = GIT_STATUS_OPT_DEFAULTS; |
| 1812 | + |
| 1813 | + if (!strcmp(untracked_files, "no")) { |
| 1814 | + opts.flags &= ~(GIT_STATUS_OPT_INCLUDE_UNTRACKED | GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS); |
| 1815 | + } else if (!strcmp(untracked_files, "normal")){ |
| 1816 | + opts.flags &= ~GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS; |
| 1817 | + } else if (strcmp(untracked_files, "all") ){ |
| 1818 | + return PyErr_Format( |
| 1819 | + PyExc_ValueError, |
| 1820 | + "untracked_files must be one of \"all\", \"normal\" or \"one\""); |
| 1821 | + }; |
| 1822 | + |
| 1823 | + if (!PyBool_Check(ignored)) { |
| 1824 | + return PyErr_Format(PyExc_TypeError, "ignored must be True or False"); |
| 1825 | + } |
| 1826 | + if (!PyObject_IsTrue(ignored)) { |
| 1827 | + opts.flags &= ~GIT_STATUS_OPT_INCLUDE_IGNORED; |
| 1828 | + } |
| 1829 | + |
| 1830 | + err = git_status_list_new(&list, self->repo, &opts); |
1788 | 1831 | if (err < 0) |
1789 | 1832 | return Error_set(err); |
1790 | 1833 |
|
@@ -2413,7 +2456,7 @@ PyMethodDef Repository_methods[] = { |
2413 | 2456 | METHOD(Repository, revparse_single, METH_O), |
2414 | 2457 | METHOD(Repository, revparse_ext, METH_O), |
2415 | 2458 | METHOD(Repository, revparse, METH_O), |
2416 | | - METHOD(Repository, status, METH_NOARGS), |
| 2459 | + METHOD(Repository, status, METH_VARARGS | METH_KEYWORDS), |
2417 | 2460 | METHOD(Repository, status_file, METH_O), |
2418 | 2461 | METHOD(Repository, notes, METH_VARARGS), |
2419 | 2462 | METHOD(Repository, create_note, METH_VARARGS), |
|
0 commit comments