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)
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);
}
{
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;
{
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;
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 {
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;
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) \
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;
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;
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) {
if (!git_object_typeisloose(obj->type))
return -1;
+
if (!obj->data && obj->len != 0)
return -1;
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;
}
void git_odb_object__free(git_odb_object *object)
{
if (object != NULL) {
- git__free(object->raw.data);
+ git__free(object->buffer);
git__free(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)
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;
}
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;
/* EXPORT */
struct git_odb_object {
git_cached_obj cached;
- git_rawobj raw;
+ void *buffer;
};
/* EXPORT */
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;
}
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 {
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)
/* 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);
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)
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));
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);
git_oid id;
git_odb_object *obj;
git_odb *odb;
+ git_rawobj tmp;
write_object_files(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);
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);
}
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);
}
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);
}