MCPcopy Create free account
hub / github.com/libgit2/pygit2 / Repository_status

Function Repository_status

src/repository.c:1736–1814  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1734 " Defaults to False.\n");
1735
1736PyObject *
1737Repository_status(Repository *self, PyObject *args, PyObject *kw)
1738{
1739 int err;
1740 size_t len, i;
1741 git_status_list *list;
1742
1743 char *untracked_files = "all";
1744 static char *kwlist[] = {"untracked_files", "ignored", NULL};
1745
1746 PyObject* ignored = Py_False;
1747
1748 if (!PyArg_ParseTupleAndKeywords(args, kw, "|sO", kwlist, &untracked_files, &ignored))
1749 return NULL;
1750
1751 git_status_options opts = GIT_STATUS_OPTIONS_INIT;
1752 opts.flags = GIT_STATUS_OPT_DEFAULTS;
1753
1754 if (!strcmp(untracked_files, "no")) {
1755 opts.flags &= ~(GIT_STATUS_OPT_INCLUDE_UNTRACKED | GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS);
1756 } else if (!strcmp(untracked_files, "normal")){
1757 opts.flags &= ~GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS;
1758 } else if (strcmp(untracked_files, "all") ){
1759 return PyErr_Format(
1760 PyExc_ValueError,
1761 "untracked_files must be one of \"all\", \"normal\" or \"one\"");
1762 };
1763
1764 if (!PyBool_Check(ignored)) {
1765 return PyErr_Format(PyExc_TypeError, "ignored must be True or False");
1766 }
1767 if (!PyObject_IsTrue(ignored)) {
1768 opts.flags &= ~GIT_STATUS_OPT_INCLUDE_IGNORED;
1769 }
1770
1771 err = git_status_list_new(&list, self->repo, &opts);
1772 if (err < 0)
1773 return Error_set(err);
1774
1775 PyObject *dict = PyDict_New();
1776 if (dict == NULL)
1777 goto error;
1778
1779 len = git_status_list_entrycount(list);
1780 for (i = 0; i < len; i++) {
1781 const git_status_entry *entry;
1782 const char *path;
1783 PyObject *status;
1784
1785 entry = git_status_byindex(list, i);
1786 if (entry == NULL)
1787 goto error;
1788
1789 /* We need to choose one of the strings */
1790 if (entry->head_to_index)
1791 path = entry->head_to_index->old_file.path;
1792 else
1793 path = entry->index_to_workdir->old_file.path;

Callers

nothing calls this directly

Calls 2

Error_setFunction · 0.85
pygit2_enumFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…