示例#1
0
文件: config.c 项目: carlosmn/pygit2
int
Config_init(Config *self, PyObject *args, PyObject *kwds)
{
    char *path = NULL;
    int err;

    if (kwds && PyDict_Size(kwds) > 0) {
        PyErr_SetString(PyExc_TypeError,
                        "Config takes no keyword arguments");
        return -1;
    }

    if (!PyArg_ParseTuple(args, "|s", &path))
        return -1;

    if (path == NULL)
        err = git_config_new(&self->config);
    else
        err = git_config_open_ondisk(&self->config, path);

    if (err < 0) {
        git_config_free(self->config);

        if (err == GIT_ENOTFOUND)
            Error_set_exc(PyExc_IOError);
        else
            Error_set(err);

        return -1;
    }

    return 0;
}
示例#2
0
文件: error.c 项目: feisuzhu/pygit2
PyObject *
Error_set(int err)
{
    assert(err < 0);

    return Error_set_exc(Error_type(err));
}
示例#3
0
文件: config.c 项目: cboos/pygit2
int
Config_init(Config *self, PyObject *args, PyObject *kwds)
{
    char *path;
    int err;

    if (kwds) {
        PyErr_SetString(PyExc_TypeError,
                        "Repository takes no keyword arguments");
        return -1;
    }

    if (PySequence_Length(args) > 0) {
        if (!PyArg_ParseTuple(args, "s", &path)) {
            return -1;
        }

        err = git_config_open_ondisk(&self->config, path);

    } else {
        err = git_config_new(&self->config);
    }

    if (err < 0) {
        if (err == GIT_ENOTFOUND) {
            Error_set_exc(PyExc_IOError);
        } else {
            Error_set(err);
        }

        return -1;
    }

    return 0;
}
示例#4
0
文件: remote.c 项目: cholin/pygit2
int
Remote_fetchspec__set__(Remote *self, PyObject* py_tuple)
{
    int err;
    size_t length = 0;
    char* src = NULL, *dst = NULL, *buf = NULL;

    if (!PyArg_ParseTuple(py_tuple, "ss", &src, &dst))
        return -1;

    /* length is strlen('+' + src + ':' + dst) and Null-Byte */
    length = strlen(src) + strlen(dst) + 3;
    buf = (char*) calloc(length, sizeof(char));
    if (buf != NULL) {
        sprintf(buf, "+%s:%s", src, dst);
        err = git_remote_set_fetchspec(self->remote, buf);
        free(buf);

        if (err == GIT_OK)
            return 0;

        Error_set_exc(PyExc_ValueError);
    }

    return -1;
}