Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 38 additions & 18 deletions src/repository.c
Original file line number Diff line number Diff line change
Expand Up @@ -1096,33 +1096,53 @@ PyDoc_STRVAR(Repository_status__doc__,
"Reads the status of the repository and returns a dictionary with file\n"
"paths as keys and status flags as values. See pygit2.GIT_STATUS_*.");

int
read_status_cb(const char *path, unsigned int status_flags, void *payload)
PyObject *
Repository_status(Repository *self, PyObject *args)
{
/* This is the callback that will be called in git_status_foreach. It
* will be called for every path.*/
PyObject *flags;
PyObject *dict;
int err;
size_t len, i;
git_status_list *list;

flags = PyLong_FromLong((long) status_flags);
err = PyDict_SetItemString(payload, path, flags);
Py_CLEAR(flags);
dict = PyDict_New();
if (dict == NULL)
return NULL;

err = git_status_list_new(&list, self->repo, NULL);
if (err < 0)
return GIT_ERROR;
return Error_set(err);

return GIT_OK;
}
len = git_status_list_entrycount(list);
for (i = 0; i < len; i++) {
const git_status_entry *entry;
const char *path;
PyObject *status;

PyObject *
Repository_status(Repository *self, PyObject *args)
{
PyObject *payload_dict;
entry = git_status_byindex(list, i);
if (entry == NULL)
goto on_error;

/* We need to choose one of the strings */
path = entry->head_to_index ?
entry->head_to_index->old_file.path :
entry->index_to_workdir->old_file.path;
status = PyLong_FromLong((long) entry->status);

err = PyDict_SetItemString(dict, path, status);
Py_CLEAR(status);

if (err < 0)
goto on_error;

}

payload_dict = PyDict_New();
git_status_foreach(self->repo, read_status_cb, payload_dict);
git_status_list_free(list);
return dict;

return payload_dict;
on_error:
git_status_list_free(list);
Py_CLEAR(dict);
return NULL;
}


Expand Down