Git-Raw
view release on metacpan or search on metacpan
LEAVE;
return 0;
}
STATIC int git_remote_create_cbb(git_remote **out, git_repository *r,
const char *name, const char *url, void *cb) {
dSP;
int rv = 0;
SV *repo_sv = NULL;
Repository repo = NULL;
Newxz(repo, 1, git_raw_repository);
repo -> repository = r;
repo -> owned = 0;
GIT_NEW_OBJ(repo_sv,
"Git::Raw::Repository",
(void * ) repo
);
ENTER;
SAVETMPS;
PUSHMARK(SP);
mXPUSHs(repo_sv);
mXPUSHs(newSVpv(name, 0));
mXPUSHs(newSVpv(url, 0));
PUTBACK;
call_sv((SV *) cb, G_EVAL|G_SCALAR);
SPAGAIN;
if (SvTRUE(ERRSV)) {
rv = -1;
(void) POPs;
*out = NULL;
} else {
SV *r = POPs;
if (SvOK(r)) {
Remote remote = GIT_SV_TO_PTR(Remote, r);
*out = remote -> remote;
/* The remote created in the callback is owned by libgit2 */
remote -> owned = 0;
} else {
*out = NULL;
rv = -1;
}
}
PUTBACK;
FREETMPS;
LEAVE;
return rv;
}
STATIC int git_credentials_cbb(git_cred **cred, const char *url,
const char *usr_from_url, unsigned int allow, void *cbs) {
dSP;
int rv = 0;
AV *types = newAV();
Cred creds;
if (allow & GIT_CREDTYPE_USERPASS_PLAINTEXT)
av_push(types, newSVpv("userpass_plaintext", 0));
if (allow & GIT_CREDTYPE_SSH_KEY)
av_push(types, newSVpv("ssh_key", 0));
if (allow & GIT_CREDTYPE_SSH_CUSTOM)
av_push(types, newSVpv("ssh_custom", 0));
if (allow & GIT_CREDTYPE_DEFAULT)
av_push(types, newSVpv("default", 0));
if (allow & GIT_CREDTYPE_SSH_INTERACTIVE)
av_push(types, newSVpv("ssh_interactive", 0));
if (allow & GIT_CREDTYPE_USERNAME)
av_push(types, newSVpv("username", 0));
if (allow & GIT_CREDTYPE_SSH_MEMORY)
av_push(types, newSVpv("ssh_memory", 0));
ENTER;
SAVETMPS;
PUSHMARK(SP);
mXPUSHs(newSVpv(url, 0));
mXPUSHs(newSVpv(usr_from_url, 0));
mXPUSHs(newRV_noinc((SV *)types));
PUTBACK;
call_sv(git_hv_code_entry((HV *)cbs, "credentials"), G_EVAL|G_SCALAR);
SPAGAIN;
if (SvTRUE(ERRSV)) {
rv = GIT_PASSTHROUGH;
(void) POPs;
} else {
SV *c = POPs;
if (SvOK(c)) {
creds = GIT_SV_TO_PTR(Cred, c);
*cred = creds -> cred;
} else
rv = GIT_PASSTHROUGH;
}
PUTBACK;
FREETMPS;
LEAVE;
return rv;
}
STATIC int git_certificate_check_cbb(git_cert *cert, int valid, const char *host, void *cbs) {
dSP;
int rv = 0;
SV *obj = NULL;
if (cert -> cert_type == GIT_CERT_X509) {
git_cert_x509 *x509 = (git_cert_x509 *) cert;
GIT_NEW_OBJ(
obj, "Git::Raw::Cert::X509", (void *) x509
);
} else if (cert -> cert_type == GIT_CERT_HOSTKEY_LIBSSH2) {
git_cert_hostkey *ssh = (git_cert_hostkey *) cert;
GIT_NEW_OBJ(
obj, "Git::Raw::Cert::HostKey", (void *) ssh
);
}
ENTER;
SAVETMPS;
PUSHMARK(SP);
mXPUSHs(obj);
mXPUSHs(newSViv(valid));
mXPUSHs(newSVpv(host, 0));
PUTBACK;
call_sv(git_hv_code_entry((HV *)cbs, "certificate_check"), G_EVAL|G_SCALAR);
SPAGAIN;
if (SvTRUE(ERRSV)) {
rv = -1;
(void) POPs;
} else
rv = POPi;
if ((ab = git_hv_string_entry(hopt, "a")))
diff_options->old_prefix = SvPVbyte_nolen(ab);
if ((ab = git_hv_string_entry(hopt, "b")))
diff_options->new_prefix = SvPVbyte_nolen(ab);
}
if ((opt = git_hv_int_entry(opts, "context_lines")))
diff_options->context_lines = (uint16_t) SvIV(opt);
if ((opt = git_hv_int_entry(opts, "interhunk_lines")))
diff_options->interhunk_lines = (uint16_t) SvIV(opt);
if ((lopt = git_hv_list_entry(opts, "paths"))) {
SV **path;
char **paths = NULL;
size_t i = 0, count = 0;
while ((path = av_fetch(lopt, i++, 0))) {
if (!SvOK(*path))
continue;
Renew(paths, count + 1, char *);
paths[count++] = SvPVbyte_nolen(*path);
}
if (count > 0) {
diff_options->flags |= GIT_DIFF_DISABLE_PATHSPEC_MATCH;
diff_options->pathspec.strings = paths;
diff_options->pathspec.count = count;
}
}
}
STATIC void git_hv_to_stash_apply_opts(HV *opts, git_stash_apply_options *stash_opts) {
HV *hopt;
if ((hopt = git_hv_hash_entry(opts, "checkout_opts")))
git_hv_to_checkout_opts(hopt, &stash_opts->checkout_options);
if ((hopt = git_hv_hash_entry(opts, "flags"))) {
unsigned flags = 0;
git_flag_opt(hopt, "reinstate_index", GIT_STASH_APPLY_REINSTATE_INDEX, &flags);
stash_opts->flags = flags;
}
if ((hopt = git_hv_hash_entry(opts, "callbacks"))) {
if ((stash_opts->progress_payload = get_callback_option(hopt, "apply_progress")))
stash_opts->progress_cb = git_stash_apply_progress_cbb;
SAVEFREESV(MUTABLE_SV(stash_opts->progress_payload));
}
}
STATIC void git_hv_to_remote_callbacks(HV *opts, git_remote_callbacks *callbacks) {
callbacks->payload = (void *)opts;
if (get_callback_option(opts, "credentials"))
callbacks->credentials = git_credentials_cbb;
if (get_callback_option(opts, "certificate_check"))
callbacks->certificate_check = git_certificate_check_cbb;
if (get_callback_option(opts, "sideband_progress"))
callbacks->sideband_progress = git_sideband_progress_cbb;
if (get_callback_option(opts, "transfer_progress"))
callbacks->transfer_progress = git_transfer_progress_cbb;
if (get_callback_option(opts, "update_tips"))
callbacks->update_tips = git_update_tips_cbb;
if (get_callback_option(opts, "pack_progress"))
callbacks->pack_progress = git_packbuilder_progress_cbb;
if (get_callback_option(opts, "push_transfer_progress"))
callbacks->push_transfer_progress = git_push_transfer_progress_cbb;
if (get_callback_option(opts, "push_update_reference"))
callbacks->push_update_reference = git_push_update_reference_cbb;
if (get_callback_option(opts, "push_negotiation"))
callbacks->push_negotiation = git_push_negotiation_cbb;
if (get_callback_option(opts, "transport"))
callbacks->transport = git_transport_cbb;
}
STATIC void git_hv_to_fetch_opts(HV *opts, git_fetch_options *fetch_opts) {
HV *hopt;
if ((hopt = git_hv_hash_entry(opts, "callbacks")))
git_hv_to_remote_callbacks(hopt, &fetch_opts->callbacks);
}
STATIC void git_hv_to_push_opts(HV *opts, git_push_options *push_opts) {
HV *hopt;
if ((hopt = git_hv_hash_entry(opts, "callbacks")))
git_hv_to_remote_callbacks(hopt, &push_opts->callbacks);
}
STATIC unsigned git_hv_to_merge_flag(HV *flags) {
unsigned out = 0;
git_flag_opt(flags, "find_renames", GIT_MERGE_FIND_RENAMES, &out);
return out;
}
STATIC unsigned git_hv_to_merge_file_flag(HV *flags) {
unsigned out = 0;
git_flag_opt(flags, "merge", GIT_MERGE_FILE_STYLE_MERGE, &out);
git_flag_opt(flags, "diff3", GIT_MERGE_FILE_STYLE_DIFF3, &out);
git_flag_opt(flags, "simplify_alnum", GIT_MERGE_FILE_SIMPLIFY_ALNUM, &out);
git_flag_opt(flags, "ignore_whitespace", GIT_MERGE_FILE_IGNORE_WHITESPACE, &out);
git_flag_opt(flags, "ignore_whitespace_change", GIT_MERGE_FILE_IGNORE_WHITESPACE_CHANGE, &out);
( run in 2.388 seconds using v1.01-cache-2.11-cpan-75ffa21a3d4 )