Commit badd85a6 by Russell Belfer Committed by Vicent Marti

Use git_odb_object_data/_size whereever possible

This uses the odb object accessors so we can change the internals
more easily...
parent ee12272d
...@@ -18,19 +18,21 @@ ...@@ -18,19 +18,21 @@
const void *git_blob_rawcontent(const git_blob *blob) const void *git_blob_rawcontent(const git_blob *blob)
{ {
assert(blob); assert(blob);
return blob->odb_object->buffer; return git_odb_object_data(blob->odb_object);
} }
git_off_t git_blob_rawsize(const git_blob *blob) git_off_t git_blob_rawsize(const git_blob *blob)
{ {
assert(blob); assert(blob);
return (git_off_t)blob->odb_object->cached.size; return (git_off_t)git_odb_object_size(blob->odb_object);
} }
int git_blob__getbuf(git_buf *buffer, git_blob *blob) int git_blob__getbuf(git_buf *buffer, git_blob *blob)
{ {
return git_buf_set( return git_buf_set(
buffer, blob->odb_object->buffer, blob->odb_object->cached.size); buffer,
git_odb_object_data(blob->odb_object),
git_odb_object_size(blob->odb_object));
} }
void git_blob__free(git_blob *blob) void git_blob__free(git_blob *blob)
......
...@@ -710,8 +710,8 @@ static int blob_content_to_file( ...@@ -710,8 +710,8 @@ static int blob_content_to_file(
git_vector filters = GIT_VECTOR_INIT; git_vector filters = GIT_VECTOR_INIT;
/* Create a fake git_buf from the blob raw data... */ /* Create a fake git_buf from the blob raw data... */
filtered.ptr = blob->odb_object->buffer; filtered.ptr = (void *)git_blob_rawcontent(blob);
filtered.size = blob->odb_object->cached.size; filtered.size = (size_t)git_blob_rawsize(blob);
/* ... and make sure it doesn't get unexpectedly freed */ /* ... and make sure it doesn't get unexpectedly freed */
dont_free_filtered = true; dont_free_filtered = true;
......
...@@ -244,7 +244,8 @@ bad_buffer: ...@@ -244,7 +244,8 @@ bad_buffer:
int git_commit__parse(git_commit *commit, git_odb_object *obj) int git_commit__parse(git_commit *commit, git_odb_object *obj)
{ {
assert(commit); assert(commit);
return git_commit__parse_buffer(commit, obj->buffer, obj->cached.size); return git_commit__parse_buffer(
commit, git_odb_object_data(obj), git_odb_object_size(obj));
} }
#define GIT_COMMIT_GETTER(_rvalue, _name, _return) \ #define GIT_COMMIT_GETTER(_rvalue, _name, _return) \
......
...@@ -103,12 +103,12 @@ git_commit_list_node *git_commit_list_pop(git_commit_list **stack) ...@@ -103,12 +103,12 @@ git_commit_list_node *git_commit_list_pop(git_commit_list **stack)
static int commit_quick_parse( static int commit_quick_parse(
git_revwalk *walk, git_revwalk *walk,
git_commit_list_node *commit, git_commit_list_node *commit,
uint8_t *buffer, const uint8_t *buffer,
size_t buffer_len) size_t buffer_len)
{ {
const size_t parent_len = strlen("parent ") + GIT_OID_HEXSZ + 1; const size_t parent_len = strlen("parent ") + GIT_OID_HEXSZ + 1;
uint8_t *buffer_end = buffer + buffer_len; const uint8_t *buffer_end = buffer + buffer_len;
uint8_t *parents_start, *committer_start; const uint8_t *parents_start, *committer_start;
int i, parents = 0; int i, parents = 0;
int commit_time; int commit_time;
...@@ -127,7 +127,7 @@ static int commit_quick_parse( ...@@ -127,7 +127,7 @@ static int commit_quick_parse(
for (i = 0; i < parents; ++i) { for (i = 0; i < parents; ++i) {
git_oid oid; git_oid oid;
if (git_oid_fromstr(&oid, (char *)buffer + strlen("parent ")) < 0) if (git_oid_fromstr(&oid, (const char *)buffer + strlen("parent ")) < 0)
return -1; return -1;
commit->parents[i] = git_revwalk__commit_lookup(walk, &oid); commit->parents[i] = git_revwalk__commit_lookup(walk, &oid);
...@@ -189,7 +189,10 @@ int git_commit_list_parse(git_revwalk *walk, git_commit_list_node *commit) ...@@ -189,7 +189,10 @@ int git_commit_list_parse(git_revwalk *walk, git_commit_list_node *commit)
giterr_set(GITERR_INVALID, "Object is no commit object"); giterr_set(GITERR_INVALID, "Object is no commit object");
error = -1; error = -1;
} else } else
error = commit_quick_parse(walk, commit, obj->buffer, obj->cached.size); error = commit_quick_parse(
walk, commit,
(const uint8_t *)git_odb_object_data(obj),
git_odb_object_size(obj));
git_odb_object_free(obj); git_odb_object_free(obj);
return error; return error;
......
...@@ -397,7 +397,8 @@ int git_tag_delete(git_repository *repo, const char *tag_name) ...@@ -397,7 +397,8 @@ int git_tag_delete(git_repository *repo, const char *tag_name)
int git_tag__parse(git_tag *tag, git_odb_object *obj) int git_tag__parse(git_tag *tag, git_odb_object *obj)
{ {
assert(tag); assert(tag);
return git_tag__parse_buffer(tag, obj->buffer, obj->cached.size); return git_tag__parse_buffer(
tag, git_odb_object_data(obj), git_odb_object_size(obj));
} }
typedef struct { typedef struct {
......
...@@ -371,7 +371,8 @@ static int tree_error(const char *str, const char *path) ...@@ -371,7 +371,8 @@ static int tree_error(const char *str, const char *path)
return -1; return -1;
} }
static int tree_parse_buffer(git_tree *tree, const char *buffer, const char *buffer_end) static int tree_parse_buffer(
git_tree *tree, const char *buffer, const char *buffer_end)
{ {
if (git_vector_init(&tree->entries, DEFAULT_TREE_SIZE, entry_sort_cmp) < 0) if (git_vector_init(&tree->entries, DEFAULT_TREE_SIZE, entry_sort_cmp) < 0)
return -1; return -1;
...@@ -418,10 +419,13 @@ static int tree_parse_buffer(git_tree *tree, const char *buffer, const char *buf ...@@ -418,10 +419,13 @@ static int tree_parse_buffer(git_tree *tree, const char *buffer, const char *buf
int git_tree__parse(git_tree *tree, git_odb_object *obj) int git_tree__parse(git_tree *tree, git_odb_object *obj)
{ {
assert(tree); const char *buf;
return tree_parse_buffer(tree,
(char *)obj->buffer, assert(tree && obj);
(char *)obj->buffer + obj->cached.size);
buf = (const char *)git_odb_object_data(obj);
return tree_parse_buffer(tree, buf, buf + git_odb_object_size(obj));
} }
static size_t find_next_dir(const char *dirname, git_index *index, size_t start) static size_t find_next_dir(const char *dirname, git_index *index, size_t start)
......
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