8
8
#include "object-store.h"
9
9
#include "packfile.h"
10
10
11
- static struct object * * obj_hash ;
12
- static int nr_objs , obj_hash_size ;
13
-
14
11
unsigned int get_max_object_index (void )
15
12
{
16
- return obj_hash_size ;
13
+ return the_repository -> parsed_objects -> obj_hash_size ;
17
14
}
18
15
19
16
struct object * get_indexed_object (unsigned int idx )
20
17
{
21
- return obj_hash [idx ];
18
+ return the_repository -> parsed_objects -> obj_hash [idx ];
22
19
}
23
20
24
21
static const char * object_type_strings [] = {
@@ -90,15 +87,16 @@ struct object *lookup_object(const unsigned char *sha1)
90
87
unsigned int i , first ;
91
88
struct object * obj ;
92
89
93
- if (!obj_hash )
90
+ if (!the_repository -> parsed_objects -> obj_hash )
94
91
return NULL ;
95
92
96
- first = i = hash_obj (sha1 , obj_hash_size );
97
- while ((obj = obj_hash [i ]) != NULL ) {
93
+ first = i = hash_obj (sha1 ,
94
+ the_repository -> parsed_objects -> obj_hash_size );
95
+ while ((obj = the_repository -> parsed_objects -> obj_hash [i ]) != NULL ) {
98
96
if (!hashcmp (sha1 , obj -> oid .hash ))
99
97
break ;
100
98
i ++ ;
101
- if (i == obj_hash_size )
99
+ if (i == the_repository -> parsed_objects -> obj_hash_size )
102
100
i = 0 ;
103
101
}
104
102
if (obj && i != first ) {
@@ -107,7 +105,8 @@ struct object *lookup_object(const unsigned char *sha1)
107
105
* that we do not need to walk the hash table the next
108
106
* time we look for it.
109
107
*/
110
- SWAP (obj_hash [i ], obj_hash [first ]);
108
+ SWAP (the_repository -> parsed_objects -> obj_hash [i ],
109
+ the_repository -> parsed_objects -> obj_hash [first ]);
111
110
}
112
111
return obj ;
113
112
}
@@ -124,19 +123,19 @@ static void grow_object_hash(void)
124
123
* Note that this size must always be power-of-2 to match hash_obj
125
124
* above.
126
125
*/
127
- int new_hash_size = obj_hash_size < 32 ? 32 : 2 * obj_hash_size ;
126
+ int new_hash_size = the_repository -> parsed_objects -> obj_hash_size < 32 ? 32 : 2 * the_repository -> parsed_objects -> obj_hash_size ;
128
127
struct object * * new_hash ;
129
128
130
129
new_hash = xcalloc (new_hash_size , sizeof (struct object * ));
131
- for (i = 0 ; i < obj_hash_size ; i ++ ) {
132
- struct object * obj = obj_hash [i ];
130
+ for (i = 0 ; i < the_repository -> parsed_objects -> obj_hash_size ; i ++ ) {
131
+ struct object * obj = the_repository -> parsed_objects -> obj_hash [i ];
133
132
if (!obj )
134
133
continue ;
135
134
insert_obj_hash (obj , new_hash , new_hash_size );
136
135
}
137
- free (obj_hash );
138
- obj_hash = new_hash ;
139
- obj_hash_size = new_hash_size ;
136
+ free (the_repository -> parsed_objects -> obj_hash );
137
+ the_repository -> parsed_objects -> obj_hash = new_hash ;
138
+ the_repository -> parsed_objects -> obj_hash_size = new_hash_size ;
140
139
}
141
140
142
141
void * create_object (const unsigned char * sha1 , void * o )
@@ -147,11 +146,12 @@ void *create_object(const unsigned char *sha1, void *o)
147
146
obj -> flags = 0 ;
148
147
hashcpy (obj -> oid .hash , sha1 );
149
148
150
- if (obj_hash_size - 1 <= nr_objs * 2 )
149
+ if (the_repository -> parsed_objects -> obj_hash_size - 1 <= the_repository -> parsed_objects -> nr_objs * 2 )
151
150
grow_object_hash ();
152
151
153
- insert_obj_hash (obj , obj_hash , obj_hash_size );
154
- nr_objs ++ ;
152
+ insert_obj_hash (obj , the_repository -> parsed_objects -> obj_hash ,
153
+ the_repository -> parsed_objects -> obj_hash_size );
154
+ the_repository -> parsed_objects -> nr_objs ++ ;
155
155
return obj ;
156
156
}
157
157
@@ -431,8 +431,8 @@ void clear_object_flags(unsigned flags)
431
431
{
432
432
int i ;
433
433
434
- for (i = 0 ; i < obj_hash_size ; i ++ ) {
435
- struct object * obj = obj_hash [i ];
434
+ for (i = 0 ; i < the_repository -> parsed_objects -> obj_hash_size ; i ++ ) {
435
+ struct object * obj = the_repository -> parsed_objects -> obj_hash [i ];
436
436
if (obj )
437
437
obj -> flags &= ~flags ;
438
438
}
@@ -442,13 +442,20 @@ void clear_commit_marks_all(unsigned int flags)
442
442
{
443
443
int i ;
444
444
445
- for (i = 0 ; i < obj_hash_size ; i ++ ) {
446
- struct object * obj = obj_hash [i ];
445
+ for (i = 0 ; i < the_repository -> parsed_objects -> obj_hash_size ; i ++ ) {
446
+ struct object * obj = the_repository -> parsed_objects -> obj_hash [i ];
447
447
if (obj && obj -> type == OBJ_COMMIT )
448
448
obj -> flags &= ~flags ;
449
449
}
450
450
}
451
451
452
+ struct parsed_object_pool * parsed_object_pool_new (void )
453
+ {
454
+ struct parsed_object_pool * o = xmalloc (sizeof (* o ));
455
+ memset (o , 0 , sizeof (* o ));
456
+ return o ;
457
+ }
458
+
452
459
struct raw_object_store * raw_object_store_new (void )
453
460
{
454
461
struct raw_object_store * o = xmalloc (sizeof (* o ));
@@ -488,3 +495,13 @@ void raw_object_store_clear(struct raw_object_store *o)
488
495
close_all_packs (o );
489
496
o -> packed_git = NULL ;
490
497
}
498
+
499
+ void parsed_object_pool_clear (struct parsed_object_pool * o )
500
+ {
501
+ /*
502
+ * TOOD free objects in o->obj_hash.
503
+ *
504
+ * As objects are allocated in slabs (see alloc.c), we do
505
+ * not need to free each object, but each slab instead.
506
+ */
507
+ }
0 commit comments