]> git.proxmox.com Git - libgit2.git/commitdiff
What has science done.
authorVicent Marti <tanoku@gmail.com>
Wed, 3 Apr 2013 20:30:07 +0000 (22:30 +0200)
committerVicent Marti <tanoku@gmail.com>
Mon, 22 Apr 2013 14:50:50 +0000 (16:50 +0200)
16 files changed:
src/blob.c
src/cache.c
src/cache.h
src/checkout.c
src/commit.c
src/commit_list.c
src/object.c
src/odb.c
src/odb.h
src/tag.c
src/tree.c
tests-clar/diff/workdir.c
tests-clar/object/raw/write.c
tests-clar/odb/loose.c
tests-clar/odb/packed.c
tests-clar/odb/packed_one.c

index 11e1f4d77503676482f565aa0bb1f388471ecd88..7dce4f7eec7c619dbde4e926994e1ee009fc60f4 100644 (file)
 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);
 }
index f49515ef34ca1f734dba9b30a8aaf8e3d439e738..316007bdf97aaff2b27a2eb535622e67cdf14404 100644 (file)
@@ -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;
index f952830c5194edfe3a9911b5356be88ee2336f88..3633f62a7879033dd6fd03fdbc3937240b7aea1c 100644 (file)
@@ -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 {
index 81dc5e3da85a12e34c1eb33aeacf2ae5f1c35062..bb2f9060690dccb77600f6ec6bf923d28f766f50 100644 (file)
@@ -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;
 
index dd416920d9b19e18b48ccd5b2d98b18462b502e7..2057364b501c53e0e45e4305fdf60905b904e7dc 100644 (file)
@@ -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) \
index 603dd754a3504414d496c55c03c421cc1603df76..baabbbafb8a3cb666d23690e2ec8dfa6b282d349 100644 (file)
@@ -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;
index 54ceea33cbe9f5688a10162ba8144825fad025c5..2667fcaf1468179eb3d0d8959e50281b07f5f7d2 100644 (file)
@@ -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) {
index 821fbd70c0752966ded72330cb6db0766cb59b4c..16a842aa8aa23f3ad6254cd67d5729a17ace7c8e 100644 (file)
--- 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;
index 9abf594e8fe68058ab23de273880148365f1eb0a..22c6e16685154e2a18f54be6d51984d09ebdd44a 100644 (file)
--- 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 */
index c82decbe36ef63e0cbce1121631edcf03caae01d..3095d1287ada6a984142bc80dcb58a7565dba83e 100644 (file)
--- 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 {
index d2db8405502cc12d194652db2d0f6f38ce18191a..6ffb07c6945caa5f195d4eaca92b0b870d64d4cb 100644 (file)
@@ -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)
index 9d92d8d601f8da6b3c384e58483b2a1bb28609b8..435bd4f2c09520b66f4995fbea75849d1d44be9f 100644 (file)
@@ -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)
index 60aa31f6a2ebb55dc61889a0041ddfc08bd35fc9..9709c0302cd57f17f89cbb73a39f28208dbf87c2 100644 (file)
@@ -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);
index f95dc28d4db1ee6822b1e92d910df1dc462491a3..9539bb24c7a45d590e952b9c77ff3ec5dddd5e55 100644 (file)
@@ -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);
index 90e9f3abdabc932197fc4f2789c40f69cb88d955..b4f549b58f9c1b0fc18e3583e821bfdb1b77c45a 100644 (file)
@@ -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);
        }
index 4f9bde9ed1d951a2330b7bf797a3e19e639c1466..0c6ed387b4d1fd56777bceafe1aff9694edbfe10 100644 (file)
@@ -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);
        }