How to use the pygit2.ffi.ffi.buffer 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
pattern_char = ffi.new('char[]', to_bytes(pattern))
            options.pattern = pattern_char
        if only_follow_first_parent is not None:
            options.only_follow_first_parent = only_follow_first_parent
        if show_commit_oid_as_fallback is not None:
            options.show_commit_oid_as_fallback = show_commit_oid_as_fallback

        result = ffi.new('git_describe_result **')
        if committish:
            if isinstance(committish, str):
                committish = self.revparse_single(committish)

            commit = committish.peel(Commit)

            cptr = ffi.new('git_object **')
            ffi.buffer(cptr)[:] = commit._pointer[:]

            err = C.git_describe_commit(result, cptr[0], options)
        else:
            err = C.git_describe_workdir(result, self._repo, options)
        check_error(err)

        try:
            format_options = ffi.new('git_describe_format_options *')
            C.git_describe_init_format_options(format_options, C.GIT_DESCRIBE_FORMAT_OPTIONS_VERSION)

            if abbreviated_size is not None:
                format_options.abbreviated_size = abbreviated_size
            if always_use_long_format is not None:
                format_options.always_use_long_format = always_use_long_format
            dirty_ptr = None
            if dirty_suffix:
github libgit2 / pygit2 / pygit2 / repository.py View on Github external
def _common_init(self):
        self.branches = Branches(self)
        self.references = References(self)
        self.remotes = RemoteCollection(self)

        # Get the pointer as the contents of a buffer and store it for
        # later access
        repo_cptr = ffi.new('git_repository **')
        ffi.buffer(repo_cptr)[:] = self._pointer[:]
        self._repo = repo_cptr[0]
github libgit2 / pygit2 / pygit2 / remote.py View on Github external
for i in range(int(refs_len[0])):

            local = bool(refs[0][i].local)

            if local:
                loid = Oid(raw=bytes(ffi.buffer(refs[0][i].loid.id)[:]))
            else:
                loid = None

            remote = {
                "local": local,
                "loid": loid,
                "name": maybe_string(refs[0][i].name),
                "symref_target": maybe_string(refs[0][i].symref_target),
                "oid": Oid(raw=bytes(ffi.buffer(refs[0][i].oid.id)[:])),
            }

            results.append(remote)

        return results
github libgit2 / pygit2 / pygit2 / submodule.py View on Github external
def head_id(self):
        """Head of the submodule."""
        head = C.git_submodule_head_id(self._subm)
        return Oid(raw=bytes(ffi.buffer(head)[:]))
github libgit2 / pygit2 / pygit2 / repository.py View on Github external
else:
            stash_msg = ffi.NULL

        flags = 0
        flags |= keep_index * C.GIT_STASH_KEEP_INDEX
        flags |= include_untracked * C.GIT_STASH_INCLUDE_UNTRACKED
        flags |= include_ignored * C.GIT_STASH_INCLUDE_IGNORED

        stasher_cptr = ffi.new('git_signature **')
        ffi.buffer(stasher_cptr)[:] = stasher._pointer[:]

        coid = ffi.new('git_oid *')
        err = C.git_stash_save(coid, self._repo, stasher_cptr[0], stash_msg, flags)
        check_error(err)

        return Oid(raw=bytes(ffi.buffer(coid)[:]))
github libgit2 / pygit2 / pygit2 / blame.py View on Github external
def final_commit_id(self):
        return Oid(raw=bytes(ffi.buffer(ffi.addressof(self._hunk, 'final_commit_id'))[:]))
github libgit2 / pygit2 / pygit2 / repository.py View on Github external
>>> repo = pygit2.Repository('.')
            >>> repo.stash(repo.default_signature(), 'WIP: stashing')
        """

        if message:
            stash_msg = ffi.new('char[]', to_bytes(message))
        else:
            stash_msg = ffi.NULL

        flags = 0
        flags |= keep_index * C.GIT_STASH_KEEP_INDEX
        flags |= include_untracked * C.GIT_STASH_INCLUDE_UNTRACKED
        flags |= include_ignored * C.GIT_STASH_INCLUDE_IGNORED

        stasher_cptr = ffi.new('git_signature **')
        ffi.buffer(stasher_cptr)[:] = stasher._pointer[:]

        coid = ffi.new('git_oid *')
        err = C.git_stash_save(coid, self._repo, stasher_cptr[0], stash_msg, flags)
        check_error(err)

        return Oid(raw=bytes(ffi.buffer(coid)[:]))
github libgit2 / pygit2 / pygit2 / repository.py View on Github external
def set_head(self, target):
        """
        Set HEAD to point to the given target.

        Parameters:

        target
            The new target for HEAD. Can be a string or Oid (to detach).
        """

        if isinstance(target, Oid):
            oid = ffi.new('git_oid *')
            ffi.buffer(oid)[:] = target.raw[:]
            err = C.git_repository_set_head_detached(self._repo, oid)
            check_error(err)
            return

        # if it's a string, then it's a reference name
        err = C.git_repository_set_head(self._repo, to_bytes(target))
        check_error(err)
github libgit2 / pygit2 / pygit2 / repository.py View on Github external
ours_ptr = ffi.new('git_commit **')
        theirs_ptr = ffi.new('git_commit **')
        cindex = ffi.new('git_index **')

        if isinstance(ours, (str, Oid)):
            ours = self[ours]
        if isinstance(theirs, (str, Oid)):
            theirs = self[theirs]

        ours = ours.peel(Commit)
        theirs = theirs.peel(Commit)

        opts = self._merge_options(favor)

        ffi.buffer(ours_ptr)[:] = ours._pointer[:]
        ffi.buffer(theirs_ptr)[:] = theirs._pointer[:]

        err = C.git_merge_commits(cindex, self._repo, ours_ptr[0], theirs_ptr[0], opts)
        check_error(err)

        return Index.from_c(self, cindex)
github libgit2 / pygit2 / pygit2 / repository.py View on Github external
local
            The commit which is considered the local or current state.

        upstream
            The commit which is considered the upstream.
        """

        if not isinstance(local, Oid):
            local = self.expand_id(local)

        if not isinstance(upstream, Oid):
            upstream = self.expand_id(upstream)

        ahead, behind = ffi.new('size_t*'), ffi.new('size_t*')
        oid1, oid2 = ffi.new('git_oid *'), ffi.new('git_oid *')
        ffi.buffer(oid1)[:] = local.raw[:]
        ffi.buffer(oid2)[:] = upstream.raw[:]
        err = C.git_graph_ahead_behind(ahead, behind, self._repo, oid1, oid2)
        check_error(err)

        return int(ahead[0]), int(behind[0])