Commit 8842c75f172ed94be4ad11521d4083e97d740785

Vicent Marti 2013-04-03T22:30:07

What has science done.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
diff --git a/src/blob.c b/src/blob.c
index 11e1f4d..7dce4f7 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 f49515e..316007b 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 f952830..3633f62 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 81dc5e3..bb2f906 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 dd41692..2057364 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 603dd75..baabbba 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 54ceea3..2667fca 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 821fbd7..16a842a 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 9abf594..22c6e16 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 c82decb..3095d12 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 d2db840..6ffb07c 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 9d92d8d..435bd4f 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 60aa31f..9709c03 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 f95dc28..9539bb2 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 90e9f3a..b4f549b 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 4f9bde9..0c6ed38 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);
 	}