summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/blob.c10
-rw-r--r--src/cache.c4
-rw-r--r--src/cache.h5
-rw-r--r--src/checkout.c4
-rw-r--r--src/commit.c2
-rw-r--r--src/commit_list.c15
-rw-r--r--src/object.c9
-rw-r--r--src/odb.c21
-rw-r--r--src/odb.h2
-rw-r--r--src/tag.c4
-rw-r--r--src/tree.c4
-rw-r--r--tests-clar/diff/workdir.c3
-rw-r--r--tests-clar/object/raw/write.c8
-rw-r--r--tests-clar/odb/loose.c7
-rw-r--r--tests-clar/odb/packed.c8
-rw-r--r--tests-clar/odb/packed_one.c4
16 files changed, 66 insertions, 44 deletions
diff --git a/src/blob.c b/src/blob.c
index 11e1f4d77..7dce4f7ee 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -18,19 +18,19 @@
const void *git_blob_rawcontent(const git_blob *blob)
{
assert(blob);
- return blob->odb_object->raw.data;
+ return blob->odb_object->buffer;
}
git_off_t git_blob_rawsize(const git_blob *blob)
{
assert(blob);
- return (git_off_t)blob->odb_object->raw.len;
+ return (git_off_t)blob->odb_object->cached.size;
}
int git_blob__getbuf(git_buf *buffer, git_blob *blob)
{
return git_buf_set(
- buffer, blob->odb_object->raw.data, blob->odb_object->raw.len);
+ buffer, blob->odb_object->buffer, blob->odb_object->cached.size);
}
void git_blob__free(git_blob *blob)
@@ -315,8 +315,8 @@ int git_blob_is_binary(git_blob *blob)
assert(blob);
- content.ptr = blob->odb_object->raw.data;
- content.size = min(blob->odb_object->raw.len, 4000);
+ content.ptr = blob->odb_object->buffer;
+ content.size = min(blob->odb_object->cached.size, 4000);
return git_buf_text_is_binary(&content);
}
diff --git a/src/cache.c b/src/cache.c
index f49515ef3..316007bdf 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -144,7 +144,7 @@ void *git_cache_store_raw(git_cache *cache, git_odb_object *entry)
{
git_cached_obj_incref(entry);
- if (!cache_should_store(entry->raw.type, entry->raw.len))
+ if (!cache_should_store(entry->cached.type, entry->cached.size))
return entry;
entry->cached.flags = GIT_CACHE_STORE_RAW;
@@ -155,7 +155,7 @@ void *git_cache_store_parsed(git_cache *cache, git_object *entry)
{
git_cached_obj_incref(entry);
- if (!cache_should_store(entry->type, 0 /* TODO */))
+ if (!cache_should_store(entry->cached.type, entry->cached.size))
return entry;
entry->cached.flags = GIT_CACHE_STORE_PARSED;
diff --git a/src/cache.h b/src/cache.h
index f952830c5..3633f62a7 100644
--- a/src/cache.h
+++ b/src/cache.h
@@ -22,9 +22,10 @@ enum {
typedef struct {
git_oid oid;
- git_atomic refcount;
- uint32_t cache_size;
+ int32_t type;
+ size_t size;
uint32_t flags;
+ git_atomic refcount;
} git_cached_obj;
typedef struct {
diff --git a/src/checkout.c b/src/checkout.c
index 81dc5e3da..bb2f90606 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -710,8 +710,8 @@ static int blob_content_to_file(
git_vector filters = GIT_VECTOR_INIT;
/* Create a fake git_buf from the blob raw data... */
- filtered.ptr = blob->odb_object->raw.data;
- filtered.size = blob->odb_object->raw.len;
+ filtered.ptr = blob->odb_object->buffer;
+ filtered.size = blob->odb_object->cached.size;
/* ... and make sure it doesn't get unexpectedly freed */
dont_free_filtered = true;
diff --git a/src/commit.c b/src/commit.c
index dd416920d..2057364b5 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -244,7 +244,7 @@ bad_buffer:
int git_commit__parse(git_commit *commit, git_odb_object *obj)
{
assert(commit);
- return git_commit__parse_buffer(commit, obj->raw.data, obj->raw.len);
+ return git_commit__parse_buffer(commit, obj->buffer, obj->cached.size);
}
#define GIT_COMMIT_GETTER(_rvalue, _name, _return) \
diff --git a/src/commit_list.c b/src/commit_list.c
index 603dd754a..baabbbafb 100644
--- a/src/commit_list.c
+++ b/src/commit_list.c
@@ -100,12 +100,15 @@ git_commit_list_node *git_commit_list_pop(git_commit_list **stack)
return item;
}
-static int commit_quick_parse(git_revwalk *walk, git_commit_list_node *commit, git_rawobj *raw)
+static int commit_quick_parse(
+ git_revwalk *walk,
+ git_commit_list_node *commit,
+ uint8_t *buffer,
+ size_t buffer_len)
{
const size_t parent_len = strlen("parent ") + GIT_OID_HEXSZ + 1;
- unsigned char *buffer = raw->data;
- unsigned char *buffer_end = buffer + raw->len;
- unsigned char *parents_start, *committer_start;
+ uint8_t *buffer_end = buffer + buffer_len;
+ uint8_t *parents_start, *committer_start;
int i, parents = 0;
int commit_time;
@@ -182,11 +185,11 @@ int git_commit_list_parse(git_revwalk *walk, git_commit_list_node *commit)
if ((error = git_odb_read(&obj, walk->odb, &commit->oid)) < 0)
return error;
- if (obj->raw.type != GIT_OBJ_COMMIT) {
+ if (obj->cached.type != GIT_OBJ_COMMIT) {
giterr_set(GITERR_INVALID, "Object is no commit object");
error = -1;
} else
- error = commit_quick_parse(walk, commit, &obj->raw);
+ error = commit_quick_parse(walk, commit, obj->buffer, obj->cached.size);
git_odb_object_free(obj);
return error;
diff --git a/src/object.c b/src/object.c
index 54ceea33c..2667fcaf1 100644
--- a/src/object.c
+++ b/src/object.c
@@ -86,19 +86,20 @@ int git_object__from_odb_object(
int error;
git_object *object = NULL;
- if (type != GIT_OBJ_ANY && type != odb_obj->raw.type) {
- giterr_set(GITERR_INVALID, "The requested type does not match the type in the ODB");
+ if (type != GIT_OBJ_ANY && type != odb_obj->cached.type) {
+ giterr_set(GITERR_INVALID,
+ "The requested type does not match the type in the ODB");
return GIT_ENOTFOUND;
}
- type = odb_obj->raw.type;
+ type = odb_obj->cached.type;
if ((error = create_object(&object, type)) < 0)
return error;
/* Initialize parent object */
git_oid_cpy(&object->cached.oid, &odb_obj->cached.oid);
- object->cached.cache_size = (uint32_t)odb_obj->raw.len;
+ object->cached.size = odb_obj->cached.size;
object->repo = repo;
switch (type) {
diff --git a/src/odb.c b/src/odb.c
index 821fbd70c..16a842aa8 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -65,6 +65,7 @@ int git_odb__hashobj(git_oid *id, git_rawobj *obj)
if (!git_object_typeisloose(obj->type))
return -1;
+
if (!obj->data && obj->len != 0)
return -1;
@@ -87,7 +88,9 @@ static git_odb_object *new_odb_object(const git_oid *oid, git_rawobj *source)
memset(object, 0x0, sizeof(git_odb_object));
git_oid_cpy(&object->cached.oid, oid);
- memcpy(&object->raw, source, sizeof(git_rawobj));
+ object->cached.size = source->len;
+ object->cached.type = source->type;
+ object->buffer = source->data;
return object;
}
@@ -95,7 +98,7 @@ static git_odb_object *new_odb_object(const git_oid *oid, git_rawobj *source)
void git_odb_object__free(git_odb_object *object)
{
if (object != NULL) {
- git__free(object->raw.data);
+ git__free(object->buffer);
git__free(object);
}
}
@@ -107,17 +110,17 @@ const git_oid *git_odb_object_id(git_odb_object *object)
const void *git_odb_object_data(git_odb_object *object)
{
- return object->raw.data;
+ return object->buffer;
}
size_t git_odb_object_size(git_odb_object *object)
{
- return object->raw.len;
+ return object->cached.size;
}
git_otype git_odb_object_type(git_odb_object *object)
{
- return object->raw.type;
+ return object->cached.type;
}
void git_odb_object_free(git_odb_object *object)
@@ -637,8 +640,8 @@ int git_odb__read_header_or_object(
assert(db && id && out && len_p && type_p);
if ((object = git_cache_get_raw(odb_cache(db), id)) != NULL) {
- *len_p = object->raw.len;
- *type_p = object->raw.type;
+ *len_p = object->cached.size;
+ *type_p = object->cached.type;
*out = object;
return 0;
}
@@ -663,8 +666,8 @@ int git_odb__read_header_or_object(
if ((error = git_odb_read(&object, db, id)) < 0)
return error; /* error already set - pass along */
- *len_p = object->raw.len;
- *type_p = object->raw.type;
+ *len_p = object->cached.size;
+ *type_p = object->cached.type;
*out = object;
return 0;
diff --git a/src/odb.h b/src/odb.h
index 9abf594e8..22c6e1668 100644
--- a/src/odb.h
+++ b/src/odb.h
@@ -29,7 +29,7 @@ typedef struct {
/* EXPORT */
struct git_odb_object {
git_cached_obj cached;
- git_rawobj raw;
+ void *buffer;
};
/* EXPORT */
diff --git a/src/tag.c b/src/tag.c
index c82decbe3..3095d1287 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -324,7 +324,7 @@ int git_tag_create_frombuffer(git_oid *oid, git_repository *repo, const char *bu
if (git_odb_read(&target_obj, odb, &tag.target) < 0)
goto on_error;
- if (tag.type != target_obj->raw.type) {
+ if (tag.type != target_obj->cached.type) {
giterr_set(GITERR_TAG, "The type for the given target is invalid");
goto on_error;
}
@@ -397,7 +397,7 @@ int git_tag_delete(git_repository *repo, const char *tag_name)
int git_tag__parse(git_tag *tag, git_odb_object *obj)
{
assert(tag);
- return git_tag__parse_buffer(tag, obj->raw.data, obj->raw.len);
+ return git_tag__parse_buffer(tag, obj->buffer, obj->cached.size);
}
typedef struct {
diff --git a/src/tree.c b/src/tree.c
index d2db84055..6ffb07c69 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -419,7 +419,9 @@ 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)
{
assert(tree);
- return tree_parse_buffer(tree, (char *)obj->raw.data, (char *)obj->raw.data + obj->raw.len);
+ return tree_parse_buffer(tree,
+ (char *)obj->buffer,
+ (char *)obj->buffer + obj->cached.size);
}
static size_t find_next_dir(const char *dirname, git_index *index, size_t start)
diff --git a/tests-clar/diff/workdir.c b/tests-clar/diff/workdir.c
index 9d92d8d60..435bd4f2c 100644
--- a/tests-clar/diff/workdir.c
+++ b/tests-clar/diff/workdir.c
@@ -908,7 +908,6 @@ void test_diff_workdir__can_diff_empty_file(void)
/* baseline - make sure there are no outstanding diffs */
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, tree, &opts));
- git_tree_free(tree);
cl_assert_equal_i(2, (int)git_diff_num_deltas(diff));
git_diff_list_free(diff);
@@ -935,6 +934,8 @@ void test_diff_workdir__can_diff_empty_file(void)
cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 1));
git_diff_patch_free(patch);
git_diff_list_free(diff);
+
+ git_tree_free(tree);
}
void test_diff_workdir__to_index_issue_1397(void)
diff --git a/tests-clar/object/raw/write.c b/tests-clar/object/raw/write.c
index 60aa31f6a..9709c0302 100644
--- a/tests-clar/object/raw/write.c
+++ b/tests-clar/object/raw/write.c
@@ -63,6 +63,7 @@ void test_body(object_data *d, git_rawobj *o)
git_odb *db;
git_oid id1, id2;
git_odb_object *obj;
+ git_rawobj tmp;
make_odb_dir();
cl_git_pass(git_odb_open(&db, odb_dir));
@@ -73,7 +74,12 @@ void test_body(object_data *d, git_rawobj *o)
check_object_files(d);
cl_git_pass(git_odb_read(&obj, db, &id1));
- cmp_objects(&obj->raw, o);
+
+ tmp.data = obj->buffer;
+ tmp.len = obj->cached.size;
+ tmp.type = obj->cached.type;
+
+ cmp_objects(&tmp, o);
git_odb_object_free(obj);
git_odb_free(db);
diff --git a/tests-clar/odb/loose.c b/tests-clar/odb/loose.c
index f95dc28d4..9539bb24c 100644
--- a/tests-clar/odb/loose.c
+++ b/tests-clar/odb/loose.c
@@ -30,6 +30,7 @@ static void test_read_object(object_data *data)
git_oid id;
git_odb_object *obj;
git_odb *odb;
+ git_rawobj tmp;
write_object_files(data);
@@ -37,7 +38,11 @@ static void test_read_object(object_data *data)
cl_git_pass(git_oid_fromstr(&id, data->id));
cl_git_pass(git_odb_read(&obj, odb, &id));
- cmp_objects((git_rawobj *)&obj->raw, data);
+ tmp.data = obj->buffer;
+ tmp.len = obj->cached.size;
+ tmp.type = obj->cached.type;
+
+ cmp_objects(&tmp, data);
git_odb_object_free(obj);
git_odb_free(odb);
diff --git a/tests-clar/odb/packed.c b/tests-clar/odb/packed.c
index 90e9f3abd..b4f549b58 100644
--- a/tests-clar/odb/packed.c
+++ b/tests-clar/odb/packed.c
@@ -46,8 +46,8 @@ void test_odb_packed__read_header_0(void)
cl_git_pass(git_odb_read(&obj, _odb, &id));
cl_git_pass(git_odb_read_header(&len, &type, _odb, &id));
- cl_assert(obj->raw.len == len);
- cl_assert(obj->raw.type == type);
+ cl_assert(obj->cached.size == len);
+ cl_assert(obj->cached.type == type);
git_odb_object_free(obj);
}
@@ -70,8 +70,8 @@ void test_odb_packed__read_header_1(void)
cl_git_pass(git_odb_read(&obj, _odb, &id));
cl_git_pass(git_odb_read_header(&len, &type, _odb, &id));
- cl_assert(obj->raw.len == len);
- cl_assert(obj->raw.type == type);
+ cl_assert(obj->cached.size == len);
+ cl_assert(obj->cached.type == type);
git_odb_object_free(obj);
}
diff --git a/tests-clar/odb/packed_one.c b/tests-clar/odb/packed_one.c
index 4f9bde9ed..0c6ed387b 100644
--- a/tests-clar/odb/packed_one.c
+++ b/tests-clar/odb/packed_one.c
@@ -52,8 +52,8 @@ void test_odb_packed_one__read_header_0(void)
cl_git_pass(git_odb_read(&obj, _odb, &id));
cl_git_pass(git_odb_read_header(&len, &type, _odb, &id));
- cl_assert(obj->raw.len == len);
- cl_assert(obj->raw.type == type);
+ cl_assert(obj->cached.size == len);
+ cl_assert(obj->cached.type == type);
git_odb_object_free(obj);
}