How to use the pygit2.utils.to_bytes 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
repo.describe(pattern='public/*', dirty_suffix='-dirty')
        """

        options = ffi.new('git_describe_options *')
        C.git_describe_init_options(options, C.GIT_DESCRIBE_OPTIONS_VERSION)

        if max_candidates_tags is not None:
            options.max_candidates_tags = max_candidates_tags
        if describe_strategy is not None:
            options.describe_strategy = describe_strategy
        if pattern:
            # The returned pointer object has ownership on the allocated
            # memory. Make sure it is kept alive until git_describe_commit() or
            # git_describe_workdir() are called below.
            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[:]
github libgit2 / pygit2 / pygit2 / config.py View on Github external
def _get(self, key):
        assert_string(key, "key")

        entry = ffi.new('git_config_entry **')
        err = C.git_config_get_entry(entry, self._config, to_bytes(key))

        return err, ConfigEntry._from_c(entry[0])
github libgit2 / pygit2 / pygit2 / config.py View on Github external
def get_multivar(self, name, regex=None):
        """Get each value of a multivar ''name'' as a list of strings.

        The optional ''regex'' parameter is expected to be a regular expression
        to filter the variables we're interested in.
        """
        assert_string(name, "name")

        citer = ffi.new('git_config_iterator **')
        err = C.git_config_multivar_iterator_new(citer, self._config,
                                                 to_bytes(name),
                                                 to_bytes(regex))
        check_error(err)

        return ConfigMultivarIterator(self, citer[0])
github libgit2 / pygit2 / pygit2 / remote.py View on Github external
if not (allowed & cred_type):
        raise TypeError("invalid credential type")

    ccred = ffi.new('git_cred **')
    if cred_type == C.GIT_CREDTYPE_USERPASS_PLAINTEXT:
        name, passwd = credential_tuple
        err = C.git_cred_userpass_plaintext_new(ccred, to_bytes(name),
                                                to_bytes(passwd))

    elif cred_type == C.GIT_CREDTYPE_SSH_KEY:
        name, pubkey, privkey, passphrase = credential_tuple
        if pubkey is None and privkey is None:
            err = C.git_cred_ssh_key_from_agent(ccred, to_bytes(name))
        else:
            err = C.git_cred_ssh_key_new(ccred, to_bytes(name),
                                         to_bytes(pubkey), to_bytes(privkey),
                                         to_bytes(passphrase))

    elif cred_type == C.GIT_CREDTYPE_USERNAME:
        name, = credential_tuple
        err = C.git_cred_username_new(ccred, to_bytes(name))

    elif cred_type == C.GIT_CREDTYPE_SSH_MEMORY:
        name, pubkey, privkey, passphrase = credential_tuple
        if pubkey is None and privkey is None:
            raise TypeError("SSH keys from memory are empty")
        err = C.git_cred_ssh_key_memory_new(ccred, to_bytes(name),
                                            to_bytes(pubkey), to_bytes(privkey),
                                            to_bytes(passphrase))
    else:
        raise TypeError("unsupported credential type")
github libgit2 / pygit2 / pygit2 / remote.py View on Github external
def create(self, name, url, fetch=None):
        """Create a new remote with the given name and url. Returns a 
        object.

        If 'fetch' is provided, this fetch refspec will be used instead of the default
        """

        cremote = ffi.new('git_remote **')

        if fetch:
            err = C.git_remote_create_with_fetchspec(cremote, self._repo._repo, to_bytes(name), to_bytes(url), to_bytes(fetch))
        else:
            err = C.git_remote_create(cremote, self._repo._repo, to_bytes(name), to_bytes(url))

        check_error(err)

        return Remote(self._repo, cremote[0])
github libgit2 / pygit2 / pygit2 / repository.py View on Github external
def set_ident(self, name, email):
        """Set the identity to be used for reference operations

        Updates to some references also append data to their
        reflog. You can use this method to set what identity will be
        used. If none is set, it will be read from the configuration.
        """

        err = C.git_repository_set_ident(self._repo, to_bytes(name), to_bytes(email))
        check_error(err)
github libgit2 / pygit2 / pygit2 / config.py View on Github external
def set_multivar(self, name, regex, value):
        """Set a multivar ''name'' to ''value''. ''regexp'' is a regular
        expression to indicate which values to replace.
        """
        assert_string(name, "name")
        assert_string(regex, "regex")
        assert_string(value, "value")

        err = C.git_config_set_multivar(self._config, to_bytes(name),
                                        to_bytes(regex), to_bytes(value))
        check_error(err)
github libgit2 / pygit2 / pygit2 / index.py View on Github external
def __contains__(self, path):
        err = C.git_index_find(ffi.NULL, self._index, to_bytes(path))
        if err == C.GIT_ENOTFOUND:
            return False

        check_error(err)
        return True
github libgit2 / pygit2 / pygit2 / remote.py View on Github external
creds = fn(url_str, username_str, allowed)

    credential_type = getattr(creds, 'credential_type', None)
    credential_tuple = getattr(creds, 'credential_tuple', None)
    if not credential_type or not credential_tuple:
        raise TypeError("credential does not implement interface")

    cred_type = credential_type

    if not (allowed & cred_type):
        raise TypeError("invalid credential type")

    ccred = ffi.new('git_cred **')
    if cred_type == C.GIT_CREDTYPE_USERPASS_PLAINTEXT:
        name, passwd = credential_tuple
        err = C.git_cred_userpass_plaintext_new(ccred, to_bytes(name),
                                                to_bytes(passwd))

    elif cred_type == C.GIT_CREDTYPE_SSH_KEY:
        name, pubkey, privkey, passphrase = credential_tuple
        if pubkey is None and privkey is None:
            err = C.git_cred_ssh_key_from_agent(ccred, to_bytes(name))
        else:
            err = C.git_cred_ssh_key_new(ccred, to_bytes(name),
                                         to_bytes(pubkey), to_bytes(privkey),
                                         to_bytes(passphrase))

    elif cred_type == C.GIT_CREDTYPE_USERNAME:
        name, = credential_tuple
        err = C.git_cred_username_new(ccred, to_bytes(name))

    elif cred_type == C.GIT_CREDTYPE_SSH_MEMORY: