Commit 61838295 by Edward Thomson

object: move oid header printing to object

parent b7a46fa8
......@@ -56,11 +56,13 @@ static int git_commit__create_buffer_internal(
GIT_ASSERT_ARG(out);
GIT_ASSERT_ARG(tree);
git_oid__writebuf(out, "tree ", tree);
if (git_object__write_oid_header(out, "tree ", tree) < 0)
goto on_error;
for (i = 0; i < git_array_size(*parents); i++) {
parent = git_array_get(*parents, i);
git_oid__writebuf(out, "parent ", parent);
if (git_object__write_oid_header(out, "parent ", parent) < 0)
goto on_error;
}
git_signature__writebuf(out, "author ", author);
......
......@@ -628,3 +628,18 @@ int git_object__parse_oid_header(
return 0;
}
int git_object__write_oid_header(
git_str *buf,
const char *header,
const git_oid *oid)
{
char hex_oid[GIT_OID_SHA1_HEXSIZE];
git_oid_fmt(hex_oid, oid);
git_str_puts(buf, header);
git_str_put(buf, hex_oid, GIT_OID_SHA1_HEXSIZE);
git_str_putc(buf, '\n');
return git_str_oom(buf) ? -1 : 0;
}
......@@ -51,7 +51,10 @@ int git_object__parse_oid_header(
const char *buffer_end,
const char *header);
void git_oid__writebuf(git_str *buf, const char *header, const git_oid *oid);
int git_object__write_oid_header(
git_str *buf,
const char *header,
const git_oid *oid);
bool git_object__is_valid(
git_repository *repo, const git_oid *id, git_object_t expected_type);
......
......@@ -143,16 +143,6 @@ char *git_oid_tostr(char *out, size_t n, const git_oid *oid)
return out;
}
void git_oid__writebuf(git_str *buf, const char *header, const git_oid *oid)
{
char hex_oid[GIT_OID_SHA1_HEXSIZE];
git_oid_fmt(hex_oid, oid);
git_str_puts(buf, header);
git_str_put(buf, hex_oid, GIT_OID_SHA1_HEXSIZE);
git_str_putc(buf, '\n');
}
int git_oid_fromraw(git_oid *out, const unsigned char *raw)
{
memcpy(out->id, raw, sizeof(out->id));
......
......@@ -221,7 +221,9 @@ static int write_tag_annotation(
git_str tag = GIT_STR_INIT;
git_odb *odb;
git_oid__writebuf(&tag, "object ", git_object_id(target));
if (git_object__write_oid_header(&tag, "object ", git_object_id(target)) < 0)
goto on_error;
git_str_printf(&tag, "type %s\n", git_object_type2string(git_object_type(target)));
git_str_printf(&tag, "tag %s\n", tag_name);
git_signature__writebuf(&tag, "tagger ", tagger);
......
......@@ -46,8 +46,8 @@ void cl_reflog_check_entry_(git_repository *repo, const char *reflog, size_t idx
git_object *obj = NULL;
if (git_revparse_single(&obj, repo, old_spec) == GIT_OK) {
if (git_oid_cmp(git_object_id(obj), git_reflog_entry_id_old(entry)) != 0) {
git_oid__writebuf(&result, "\tOld OID: \"", git_object_id(obj));
git_oid__writebuf(&result, "\" != \"", git_reflog_entry_id_old(entry));
git_object__write_oid_header(&result, "\tOld OID: \"", git_object_id(obj));
git_object__write_oid_header(&result, "\" != \"", git_reflog_entry_id_old(entry));
git_str_puts(&result, "\"\n");
}
git_object_free(obj);
......@@ -55,8 +55,8 @@ void cl_reflog_check_entry_(git_repository *repo, const char *reflog, size_t idx
git_oid *oid = git__calloc(1, sizeof(*oid));
git_oid_fromstr(oid, old_spec);
if (git_oid_cmp(oid, git_reflog_entry_id_old(entry)) != 0) {
git_oid__writebuf(&result, "\tOld OID: \"", oid);
git_oid__writebuf(&result, "\" != \"", git_reflog_entry_id_old(entry));
git_object__write_oid_header(&result, "\tOld OID: \"", oid);
git_object__write_oid_header(&result, "\" != \"", git_reflog_entry_id_old(entry));
git_str_puts(&result, "\"\n");
}
git__free(oid);
......@@ -66,8 +66,8 @@ void cl_reflog_check_entry_(git_repository *repo, const char *reflog, size_t idx
git_object *obj = NULL;
if (git_revparse_single(&obj, repo, new_spec) == GIT_OK) {
if (git_oid_cmp(git_object_id(obj), git_reflog_entry_id_new(entry)) != 0) {
git_oid__writebuf(&result, "\tNew OID: \"", git_object_id(obj));
git_oid__writebuf(&result, "\" != \"", git_reflog_entry_id_new(entry));
git_object__write_oid_header(&result, "\tNew OID: \"", git_object_id(obj));
git_object__write_oid_header(&result, "\" != \"", git_reflog_entry_id_new(entry));
git_str_puts(&result, "\"\n");
}
git_object_free(obj);
......@@ -75,8 +75,8 @@ void cl_reflog_check_entry_(git_repository *repo, const char *reflog, size_t idx
git_oid *oid = git__calloc(1, sizeof(*oid));
git_oid_fromstr(oid, new_spec);
if (git_oid_cmp(oid, git_reflog_entry_id_new(entry)) != 0) {
git_oid__writebuf(&result, "\tNew OID: \"", oid);
git_oid__writebuf(&result, "\" != \"", git_reflog_entry_id_new(entry));
git_object__write_oid_header(&result, "\tNew OID: \"", oid);
git_object__write_oid_header(&result, "\" != \"", git_reflog_entry_id_new(entry));
git_str_puts(&result, "\"\n");
}
git__free(oid);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment