コード例 #1
0
ファイル: diff.c プロジェクト: CODECOMMUNITY/pygit2
PyObject *
Diff_from_c(Diff *dummy, PyObject *args)
{
    PyObject *py_diff, *py_repository;
    git_diff *diff;
    char *buffer;
    Py_ssize_t length;

    if (!PyArg_ParseTuple(args, "OO!", &py_diff, &RepositoryType, &py_repository))
        return NULL;

    /* Here we need to do the opposite conversion from the _pointer getters */
    if (PyBytes_AsStringAndSize(py_diff, &buffer, &length))
        return NULL;

    if (length != sizeof(git_diff *)) {
        PyErr_SetString(PyExc_TypeError, "passed value is not a pointer");
        return NULL;
    }

    /* the "buffer" contains the pointer */
    diff = *((git_diff **) buffer);

    return wrap_diff(diff, (Repository *) py_repository);
}
コード例 #2
0
ファイル: tree.c プロジェクト: jflesch/pygit2-mariadb
PyObject *
Tree_diff_to_tree(Tree *self, PyObject *args, PyObject *kwds)
{
    git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
    git_diff *diff;
    git_tree *from, *to, *tmp;
    Repository *py_repo;
    int err, swap = 0;
    char *keywords[] = {"obj", "flags", "context_lines", "interhunk_lines",
                        "swap", NULL};

    Tree *py_tree = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!IHHi", keywords,
                                     &TreeType, &py_tree, &opts.flags,
                                     &opts.context_lines,
                                     &opts.interhunk_lines, &swap))
        return NULL;

    py_repo = self->repo;
    to = (py_tree == NULL) ? NULL : py_tree->tree;
    from = self->tree;
    if (swap > 0) {
        tmp = from;
        from = to;
        to = tmp;
    }

    err = git_diff_tree_to_tree(&diff, py_repo->repo, from, to, &opts);
    if (err < 0)
        return Error_set(err);

    return wrap_diff(diff, py_repo);
}
コード例 #3
0
ファイル: tree.c プロジェクト: jflesch/pygit2-mariadb
PyObject *
Tree_diff_to_index(Tree *self, PyObject *args, PyObject *kwds)
{
    git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
    git_diff *diff;
    git_index *index;
    char *buffer;
    Py_ssize_t length;
    Repository *py_repo;
    PyObject *py_idx, *py_idx_ptr;
    int err;

    if (!PyArg_ParseTuple(args, "O|IHH", &py_idx, &opts.flags,
                                        &opts.context_lines,
                                        &opts.interhunk_lines))
        return NULL;

    /*
     * This is a hack to check whether we're passed an index, as I
     * haven't found a good way to grab a type object for
     * pygit2.index.Index.
     */
    if (!PyObject_GetAttrString(py_idx, "_index")) {
        PyErr_SetString(PyExc_TypeError, "argument must be an Index");
        return NULL;
    }
    py_idx_ptr = PyObject_GetAttrString(py_idx, "_pointer");
    if (!py_idx_ptr)
        return NULL;

    /* Here we need to do the opposite conversion from the _pointer getters */
    if (PyBytes_AsStringAndSize(py_idx_ptr, &buffer, &length))
        return NULL;

    if (length != sizeof(git_index *)) {
        PyErr_SetString(PyExc_TypeError, "passed value is not a pointer");
        return NULL;
    }

    /* the "buffer" contains the pointer */
    index = *((git_index **) buffer);

    py_repo = self->repo;
    err = git_diff_tree_to_index(&diff, py_repo->repo, self->tree, index, &opts);
    if (err < 0)
        return Error_set(err);

    return wrap_diff(diff, py_repo);
}
コード例 #4
0
ファイル: tree.c プロジェクト: jflesch/pygit2-mariadb
PyObject *
Tree_diff_to_workdir(Tree *self, PyObject *args)
{
    git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
    git_diff *diff;
    Repository *py_repo;
    int err;

    if (!PyArg_ParseTuple(args, "|IHH", &opts.flags, &opts.context_lines,
                                        &opts.interhunk_lines))
        return NULL;

    py_repo = self->repo;
    err = git_diff_tree_to_workdir(&diff, py_repo->repo, self->tree, &opts);
    if (err < 0)
        return Error_set(err);

    return wrap_diff(diff, py_repo);
}
コード例 #5
0
ファイル: index.c プロジェクト: flowroute/pygit2
PyObject *
Index_diff_to_tree(Index *self, PyObject *args)
{
    Repository *py_repo;
    git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
    git_diff *diff;
    int err;

    Tree *py_tree = NULL;

    if (!PyArg_ParseTuple(args, "O!|IHH", &TreeType, &py_tree, &opts.flags,
                          &opts.context_lines, &opts.interhunk_lines))
        return NULL;

    py_repo = py_tree->repo;
    err = git_diff_tree_to_index(&diff, py_repo->repo, py_tree->tree,
                                 self->index, &opts);
    if (err < 0)
        return Error_set(err);

    return wrap_diff(diff, py_repo);
}
コード例 #6
0
ファイル: index.c プロジェクト: flowroute/pygit2
PyObject *
Index_diff_to_workdir(Index *self, PyObject *args)
{
    git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
    git_diff *diff;
    int err;

    if (!PyArg_ParseTuple(args, "|IHH", &opts.flags, &opts.context_lines,
                                        &opts.interhunk_lines))
        return NULL;

    err = git_diff_index_to_workdir(
            &diff,
            self->repo->repo,
            self->index,
            &opts);

    if (err < 0)
        return Error_set(err);

    return wrap_diff(diff, self->repo);
}
コード例 #7
0
ファイル: tree.c プロジェクト: Rekii008/pygit2
PyObject *
Tree_diff_to_index(Tree *self, PyObject *args, PyObject *kwds)
{
    git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
    git_diff *diff;
    Repository *py_repo;
    int err;

    Index *py_idx = NULL;

    if (!PyArg_ParseTuple(args, "O!|IHH", &IndexType, &py_idx, &opts.flags,
                                        &opts.context_lines,
                                        &opts.interhunk_lines))
        return NULL;

    py_repo = self->repo;
    err = git_diff_tree_to_index(&diff, py_repo->repo, self->tree,
                                 py_idx->index, &opts);
    if (err < 0)
        return Error_set(err);

    return wrap_diff(diff, py_repo);
}