示例#1
0
PyObject *
Repository_listall_references(Repository *self, PyObject *args)
{
    unsigned list_flags=GIT_REF_LISTALL;
    git_strarray c_result;
    PyObject *py_result, *py_string;
    unsigned index;
    int err;

    /* 1- Get list_flags */
    if (!PyArg_ParseTuple(args, "|I", &list_flags))
        return NULL;

    /* 2- Get the C result */
    err = git_reference_list(&c_result, self->repo, list_flags);
    if (err < 0)
        return Error_set(err);

    /* 3- Create a new PyTuple */
    py_result = PyTuple_New(c_result.count);
    if (py_result == NULL)
        goto out;

    /* 4- Fill it */
    for (index=0; index < c_result.count; index++) {
        py_string = to_path((c_result.strings)[index]);
        if (py_string == NULL) {
            Py_CLEAR(py_result);
            goto out;
        }
        PyTuple_SET_ITEM(py_result, index, py_string);
    }

out:
    git_strarray_free(&c_result);
    return py_result;
}
示例#2
0
PyObject *
Reference_name__get__(Reference *self)
{
    CHECK_REFERENCE(self);
    return to_path(git_reference_name(self->reference));
}
示例#3
0
PyObject *
Repository_path__get__(Repository *self, void *closure)
{
    return to_path(git_repository_path(self->repo));
}
示例#4
0
PyObject *
TreeEntry_name__get__(TreeEntry *self)
{
    return to_path(git_tree_entry_name(self->entry));
}
示例#5
0
// -----------------------------------------------------------------------------
// Given a "base" directory, yield the relative path of this file in the package
// layout.
//
// Parameters:
//    base - The base directory to look for the relative path of this entry
//    str  - If the method returns true, contains the file path for this deps
//           entry relative to the "base" directory
//
// Returns:
//    If the file exists in the path relative to the "base" directory.
//
bool deps_entry_t::to_rel_path(const pal::string_t& base, pal::string_t* str) const
{
    return to_path(base, false, str);
}
示例#6
0
文件: rxtx.c 项目: lunixbochs/bladeRF
/* Create a temp (binary) file from a CSV so we don't have to waste time
 * parsing it in between sending samples.
 *
 * Preconditions:  Assumes CLI state's TX cfg data has a valid file descriptor
 *
 * Postconditions: TX cfg's file descriptor, filename, and format will be
 *                  changed.
 *
 * return 0 on success, CMD_RET_* on failure
 */
static int tx_csv_to_c16(struct cli_state *s)
{
    const char delim[] = " \r\n\t,.:";
    const size_t buff_size = 81;
    char buff[buff_size];
    enum rxtx_fmt fmt = RXTX_FMT_BINHOST_C16;
    struct tx_cfg *tx = &s->rxtx_data->tx;
    char *token, *saveptr;
    int tmp_int;
    int16_t tmp_iq[2];
    bool ok;
    int ret;
    FILE *bin;
    int bin_fd;
    char *bin_path;
    char bin_name[] = TMP_FILE_NAME;

    ret = 0;


    bin_fd = mkstemp(bin_name);
    if (!bin_fd) {
        return CMD_RET_FILEOP;
    }

    bin = fdopen(bin_fd, "wb");
    if (!bin) {
        return CMD_RET_FILEOP;
    }

    bin_path = to_path(bin);
    if (!bin_path) {
        return CMD_RET_FILEOP;
    }

    while (fgets(buff, buff_size, tx->common.file))
    {
        /* I */
        token = strtok_r(buff, delim, &saveptr);

        if (token) {
            tmp_int = str2int(token, INT16_MIN, INT16_MAX, &ok);

            if (ok) {
                tmp_iq[0] = tmp_int;
            } else {
                cli_err(s, "tx", "Invalid I value encountered in CSV file");
                ret = CMD_RET_INVPARAM;
                break;
            }

            /* Q */
            token = strtok_r(NULL, delim, &saveptr);

            if (token) {
                tmp_int = str2int(token, INT16_MIN, INT16_MAX, &ok);

                if (ok) {
                    tmp_iq[1] = tmp_int;
                } else {
                    cli_err(s, "tx", "Invalid Q value encountered in CSV file");
                    ret = CMD_RET_INVPARAM;
                    break;
                }

            } else {
                cli_err(s, "tx", "Missing Q value in CSV file");
                ret = CMD_RET_INVPARAM;
                break;
            }

            /* Check for extraneous tokens */
            token = strtok_r(NULL, delim, &saveptr);
            if (!token) {
                if (fwrite(tmp_iq, sizeof(tmp_iq[0]), 2, bin) != 2) {
                    ret = CMD_RET_FILEOP;
                    break;
                }
            } else {
                cli_err(s, "tx",
                        "Encountered extra token after Q value in CSV file");

                ret = CMD_RET_INVPARAM;
                break;
            }
        }
    }

    if (ret >= 0 && feof(tx->common.file)) {

        fclose(tx->common.file);
        tx->common.file = bin;
        tx->common.file_fmt = fmt;

        free(tx->common.file_path);
        tx->common.file_path = bin_path;

    } else {
        ret = -1;
        fclose(bin);
        free(bin_path);
    }

    return ret;
}
示例#7
0
文件: reference.c 项目: KINFOO/pygit2
PyObject *
Reference_shorthand__get__(Reference *self)
{
    CHECK_REFERENCE(self);
    return to_path(git_reference_shorthand(self->reference));
}
示例#8
0
文件: index.c 项目: flowroute/pygit2
PyObject *
IndexEntry_path__get__(IndexEntry *self)
{
    return to_path(self->entry.path);
}
示例#9
0
文件: tree.c 项目: ardumont/pygit2
PyObject *
TreeEntry_type__get__(TreeEntry *self)
{
    return to_path(git_object_type2string(git_tree_entry_type(self->entry)));
}
示例#10
0
文件: index.c 项目: guocb/pygit2
PyObject *
IndexEntry_get_path(IndexEntry *self)
{
    return to_path(self->entry->path);
}
示例#11
0
// -----------------------------------------------------------------------------
// Given a "base" directory, yield the local path of this file
//
// Parameters:
//    base - The base directory to look for the relative path of this entry
//    str  - If the method returns true, contains the file path for this deps
//           entry relative to the "base" directory
//
// Returns:
//    If the file exists in the path relative to the "base" directory.
//
bool deps_entry_t::to_dir_path(const pal::string_t& base, pal::string_t* str) const
{
    return to_path(base, true, str);
}