mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-29 13:52:17 +00:00
What has science done.
This commit is contained in:
parent
c4e91d4500
commit
8842c75f17
10
src/blob.c
10
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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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) \
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
21
src/odb.c
21
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;
|
||||
|
@ -29,7 +29,7 @@ typedef struct {
|
||||
/* EXPORT */
|
||||
struct git_odb_object {
|
||||
git_cached_obj cached;
|
||||
git_rawobj raw;
|
||||
void *buffer;
|
||||
};
|
||||
|
||||
/* EXPORT */
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user