Git-Raw
view release on metacpan or search on metacpan
deps/libgit2/src/libgit2/commit.c view on Meta::CPAN
git_str_put(out, buf, eol - buf);
}
if (git_str_oom(out))
goto oom;
return 0;
}
git_error_set(GIT_ERROR_OBJECT, "no such field '%s'", field);
return GIT_ENOTFOUND;
malformed:
git_error_set(GIT_ERROR_OBJECT, "malformed header");
return -1;
oom:
git_error_set_oom();
return -1;
}
int git_commit_extract_signature(
git_buf *signature_out,
git_buf *signed_data_out,
git_repository *repo,
git_oid *commit_id,
const char *field)
{
git_str signature = GIT_STR_INIT, signed_data = GIT_STR_INIT;
int error;
if ((error = git_buf_tostr(&signature, signature_out)) < 0 ||
(error = git_buf_tostr(&signed_data, signed_data_out)) < 0 ||
(error = git_commit__extract_signature(&signature, &signed_data, repo, commit_id, field)) < 0 ||
(error = git_buf_fromstr(signature_out, &signature)) < 0 ||
(error = git_buf_fromstr(signed_data_out, &signed_data)) < 0)
goto done;
done:
git_str_dispose(&signature);
git_str_dispose(&signed_data);
return error;
}
int git_commit__extract_signature(
git_str *signature,
git_str *signed_data,
git_repository *repo,
git_oid *commit_id,
const char *field)
{
git_odb_object *obj;
git_odb *odb;
const char *buf;
const char *h, *eol;
int error;
git_str_clear(signature);
git_str_clear(signed_data);
if (!field)
field = "gpgsig";
if ((error = git_repository_odb__weakptr(&odb, repo)) < 0)
return error;
if ((error = git_odb_read(&obj, odb, commit_id)) < 0)
return error;
if (obj->cached.type != GIT_OBJECT_COMMIT) {
git_error_set(GIT_ERROR_INVALID, "the requested type does not match the type in the ODB");
error = GIT_ENOTFOUND;
goto cleanup;
}
buf = git_odb_object_data(obj);
while ((h = strchr(buf, '\n')) && h[1] != '\0') {
h++;
if (git__prefixcmp(buf, field)) {
if (git_str_put(signed_data, buf, h - buf) < 0)
return -1;
buf = h;
continue;
}
h = buf;
h += strlen(field);
eol = strchr(h, '\n');
if (h[0] != ' ') {
buf = h;
continue;
}
if (!eol)
goto malformed;
h++; /* skip the SP */
git_str_put(signature, h, eol - h);
if (git_str_oom(signature))
goto oom;
/* If the next line starts with SP, it's multi-line, we must continue */
while (eol[1] == ' ') {
git_str_putc(signature, '\n');
h = eol + 2;
eol = strchr(h, '\n');
if (!eol)
goto malformed;
git_str_put(signature, h, eol - h);
}
if (git_str_oom(signature))
goto oom;
error = git_str_puts(signed_data, eol+1);
git_odb_object_free(obj);
return error;
}
deps/libgit2/src/libgit2/commit.c view on Meta::CPAN
git_str_put(out, content, lf - content);
git_str_puts(out, "\n ");
content = lf + 1;
}
git_str_puts(out, content);
git_str_putc(out, '\n');
return git_str_oom(out) ? -1 : 0;
}
static const git_oid *commit_parent_from_commit(size_t n, void *payload)
{
const git_commit *commit = (const git_commit *) payload;
return git_array_get(commit->parent_ids, n);
}
int git_commit_create_with_signature(
git_oid *out,
git_repository *repo,
const char *commit_content,
const char *signature,
const char *signature_field)
{
git_odb *odb;
int error = 0;
const char *field;
const char *header_end;
git_str commit = GIT_STR_INIT;
git_commit *parsed;
git_array_oid_t parents = GIT_ARRAY_INIT;
/* The first step is to verify that all the tree and parents exist */
parsed = git__calloc(1, sizeof(git_commit));
GIT_ERROR_CHECK_ALLOC(parsed);
if (commit_parse(parsed, commit_content, strlen(commit_content), 0) < 0) {
error = -1;
goto cleanup;
}
if ((error = validate_tree_and_parents(&parents, repo, &parsed->tree_id, commit_parent_from_commit, parsed, NULL, true)) < 0)
goto cleanup;
git_array_clear(parents);
/* Then we start appending by identifying the end of the commit header */
header_end = strstr(commit_content, "\n\n");
if (!header_end) {
git_error_set(GIT_ERROR_INVALID, "malformed commit contents");
error = -1;
goto cleanup;
}
/* The header ends after the first LF */
header_end++;
git_str_put(&commit, commit_content, header_end - commit_content);
if (signature != NULL) {
field = signature_field ? signature_field : "gpgsig";
if ((error = format_header_field(&commit, field, signature)) < 0)
goto cleanup;
}
git_str_puts(&commit, header_end);
if (git_str_oom(&commit))
return -1;
if ((error = git_repository_odb__weakptr(&odb, repo)) < 0)
goto cleanup;
if ((error = git_odb_write(out, odb, commit.ptr, commit.size, GIT_OBJECT_COMMIT)) < 0)
goto cleanup;
cleanup:
git_commit__free(parsed);
git_str_dispose(&commit);
return error;
}
int git_commit_committer_with_mailmap(
git_signature **out, const git_commit *commit, const git_mailmap *mailmap)
{
return git_mailmap_resolve_signature(out, mailmap, commit->committer);
}
int git_commit_author_with_mailmap(
git_signature **out, const git_commit *commit, const git_mailmap *mailmap)
{
return git_mailmap_resolve_signature(out, mailmap, commit->author);
}
( run in 0.682 second using v1.01-cache-2.11-cpan-df04353d9ac )