How to use the pygit2.ffi.ffi 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 / repository.py View on Github external
if favor == 'normal':
                return C.GIT_MERGE_FILE_FAVOR_NORMAL
            elif favor == 'ours':
                return C.GIT_MERGE_FILE_FAVOR_OURS
            elif favor == 'theirs':
                return C.GIT_MERGE_FILE_FAVOR_THEIRS
            elif favor == 'union':
                return C.GIT_MERGE_FILE_FAVOR_UNION
            else:
                return None

        favor_val = favor_to_enum(favor)
        if favor_val is None:
            raise ValueError("unkown favor value %s" % favor)

        opts = ffi.new('git_merge_options *')
        err = C.git_merge_init_options(opts, C.GIT_MERGE_OPTIONS_VERSION)
        check_error(err)

        opts.file_favor = favor_val

        return opts
github libgit2 / pygit2 / pygit2 / remote.py View on Github external
def connect(self, callbacks=None, direction=C.GIT_DIRECTION_FETCH):
        """Connect to the remote."""

        remote_callbacks = ffi.new('git_remote_callbacks *')
        C.git_remote_init_callbacks(remote_callbacks, C.GIT_REMOTE_CALLBACKS_VERSION)

        if callbacks is None:
            callbacks = RemoteCallbacks()

        callbacks._fill_connect_callbacks(remote_callbacks)
        err = C.git_remote_connect(self._remote, direction, remote_callbacks, ffi.NULL, ffi.NULL);
        check_error(err)
github libgit2 / pygit2 / pygit2 / refspec.py View on Github external
def _transform(self, ref, fn):
        buf = ffi.new('git_buf *', (ffi.NULL, 0))
        err = fn(buf, self._refspec, to_bytes(ref))
        check_error(err)

        try:
            return ffi.string(buf.ptr).decode('utf-8')
        finally:
            C.git_buf_dispose(buf)
github libgit2 / pygit2 / pygit2 / blame.py View on Github external
def boundary(self):
        """Tracked to a boundary commit"""
        # Casting directly to bool via cffi does not seem to work
        return int(ffi.cast('int', self._hunk.boundary)) != 0
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 / remote.py View on Github external
    @ffi.callback('git_transport_certificate_check_cb')
    def _certificate_cb(cert_i, valid, host, data):
        self = ffi.from_handle(data)

        # We want to simulate what should happen if libgit2 supported pass-through for
        # this callback. For SSH, 'valid' is always False, because it doesn't look
        # at known_hosts, but we do want to let it through in order to do what libgit2 would
        # if the callback were not set.
        try:
            is_ssh = cert_i.cert_type == C.GIT_CERT_HOSTKEY_LIBSSH2

            certificate_check = getattr(self, 'certificate_check', None)
            if not certificate_check:
                raise Passthrough

            # python's parsing is deep in the libraries and assumes an OpenSSL-owned cert
            val = certificate_check(None, bool(valid), ffi.string(host))
github libgit2 / pygit2 / pygit2 / remote.py View on Github external
def _update_tips_cb(refname, a, b, data):
        self = ffi.from_handle(data)

        update_tips = getattr(self, 'update_tips', None)
        if not update_tips:
            return 0

        try:
            s = maybe_string(refname)
            a = Oid(raw=bytes(ffi.buffer(a)[:]))
            b = Oid(raw=bytes(ffi.buffer(b)[:]))

            update_tips(s, a, b)
        except Exception as e:
            self._stored_exception = e
            return C.GIT_EUSER

        return 0
github libgit2 / pygit2 / pygit2 / config.py View on Github external
def _next_entry(self):
        centry = ffi.new('git_config_entry **')
        err = C.git_config_next(centry, self._iter)
        check_error(err)

        return ConfigEntry._from_c(centry[0], True)