Commit ab265a35 by Patrick Steinhardt

commit: implement function to parse raw data

Currently, parsing objects is strictly tied to having an ODB object
available. This makes it hard to parse an object when all that is
available is its raw object and size. Furthermore, hacking around that
limitation by directly creating an ODB structure either on stack or on
heap does not really work that well due to ODB objects being reference
counted and then automatically free'd when reaching a reference count of
zero.

Implement a function `git_commit__parse_raw` to parse a commit object
from a pair of `data` and `size`.
parent 9ac79ecc
......@@ -383,11 +383,11 @@ int git_commit_amend(
return error;
}
int git_commit__parse(void *_commit, git_odb_object *odb_obj)
int git_commit__parse_raw(void *_commit, const char *data, size_t size)
{
git_commit *commit = _commit;
const char *buffer_start = git_odb_object_data(odb_obj), *buffer;
const char *buffer_end = buffer_start + git_odb_object_size(odb_obj);
const char *buffer_start = data, *buffer;
const char *buffer_end = buffer_start + size;
git_oid parent_id;
size_t header_len;
git_signature dummy_sig;
......@@ -477,6 +477,13 @@ bad_buffer:
return -1;
}
int git_commit__parse(void *_commit, git_odb_object *odb_obj)
{
return git_commit__parse_raw(_commit,
git_odb_object_data(odb_obj),
git_odb_object_size(odb_obj));
}
#define GIT_COMMIT_GETTER(_rvalue, _name, _return) \
_rvalue git_commit_##_name(const git_commit *commit) \
{\
......
......@@ -35,5 +35,6 @@ struct git_commit {
void git_commit__free(void *commit);
int git_commit__parse(void *commit, git_odb_object *obj);
int git_commit__parse_raw(void *commit, const char *data, size_t size);
#endif
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