How to use the pygit2.ffi.ffi.NULL function in pygit2

To help you get started, we’ve selected a few pygit2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github libgit2 / pygit2 / pygit2 / config.py View on Github external
def _from_found_config(fn):
        buf = ffi.new('git_buf *', (ffi.NULL, 0))
        err = fn(buf)
        check_error(err, True)
        cpath = ffi.string(buf.ptr).decode('utf-8')
        C.git_buf_dispose(buf)

        return Config(cpath)
github libgit2 / pygit2 / pygit2 / repository.py View on Github external
def checkout_index(self, **kwargs):
        """Checkout the repository's index

        For arguments, see Repository.checkout().
        """
        copts, refs = Repository._checkout_args_to_options(**kwargs)
        check_error(C.git_checkout_index(self._repo, ffi.NULL, copts))
github libgit2 / pygit2 / pygit2 / py2.py View on Github external
def to_bytes(s, encoding='utf-8', errors='strict'):
    if s == ffi.NULL or s is None:
        return ffi.NULL

    if isinstance(s, unicode):
        encoding = encoding or 'utf-8'
        return s.encode(encoding, errors)

    return s
github libgit2 / pygit2 / pygit2 / utils.py View on Github external
def to_bytes(s, encoding='utf-8', errors='strict'):
    if s == ffi.NULL or s is None:
        return ffi.NULL

    if isinstance(s, bytes):
        return s

    return s.encode(encoding, errors)
github libgit2 / pygit2 / pygit2 / index.py View on Github external
def __getitem__(self, key):
        centry = ffi.NULL
        if isinstance(key, str):
            centry = C.git_index_get_bypath(self._index, to_bytes(key), 0)
        elif isinstance(key, int):
            if key >= 0:
                centry = C.git_index_get_byindex(self._index, key)
            else:
                raise ValueError(key)
        else:
            raise TypeError('Expected str or int, got %s' % type(key))

        if centry == ffi.NULL:
            raise KeyError(key)

        return IndexEntry._from_c(centry)
github libgit2 / pygit2 / pygit2 / errors.py View on Github external
def check_error(err, io=False):
    if err >= 0:
        return

    # Error message
    giterr = C.git_error_last()
    if giterr != ffi.NULL:
        message = ffi.string(giterr.message).decode('utf8')
    else:
        message = "err %d (no message provided)" % err

    # Translate to Python errors
    if err in value_errors:
        raise ValueError(message)

    if err == C.GIT_ENOTFOUND:
        if io:
            raise IOError(message)

        raise KeyError(message)

    if err == C.GIT_EINVALIDSPEC:
        raise ValueError(message)
github libgit2 / pygit2 / pygit2 / repository.py View on Github external
ancestor
            The index entry which will be used as a common
            ancestor.
        ours
            The index entry to take as "ours" or base.
        theirs
            The index entry which will be merged into "ours"
        """
        cmergeresult = ffi.new('git_merge_file_result *')

        cancestor, ancestor_str_ref = (
            ancestor._to_c() if ancestor is not None else (ffi.NULL, ffi.NULL))
        cours, ours_str_ref = (
            ours._to_c() if ours is not None else (ffi.NULL, ffi.NULL))
        ctheirs, theirs_str_ref = (
            theirs._to_c() if theirs is not None else (ffi.NULL, ffi.NULL))

        err = C.git_merge_file_from_index(
            cmergeresult, self._repo,
            cancestor, cours, ctheirs,
            ffi.NULL);
        check_error(err)

        ret = ffi.string(cmergeresult.ptr,
                         cmergeresult.len).decode('utf-8')
        C.git_merge_file_result_free(cmergeresult)

        return ret
github libgit2 / pygit2 / pygit2 / utils.py View on Github external
def to_bytes(s, encoding='utf-8', errors='strict'):
    if s == ffi.NULL or s is None:
        return ffi.NULL

    if isinstance(s, bytes):
        return s

    return s.encode(encoding, errors)