@@ -79,14 +79,23 @@ static int parse_header(git_indexer *idx)
79
79
return GIT_SUCCESS ;
80
80
}
81
81
82
- int objects_cmp (const void * a , const void * b )
82
+ static int objects_cmp (const void * a , const void * b )
83
83
{
84
84
const struct entry * entrya = a ;
85
85
const struct entry * entryb = b ;
86
86
87
87
return git_oid_cmp (& entrya -> oid , & entryb -> oid );
88
88
}
89
89
90
+ static int cache_cmp (const void * a , const void * b )
91
+ {
92
+ const struct git_pack_entry * ea = a ;
93
+ const struct git_pack_entry * eb = b ;
94
+
95
+ return git_oid_cmp (& ea -> sha1 , & eb -> sha1 );
96
+ }
97
+
98
+
90
99
int git_indexer_new (git_indexer * * out , const char * packname )
91
100
{
92
101
git_indexer * idx ;
@@ -139,10 +148,14 @@ int git_indexer_new(git_indexer **out, const char *packname)
139
148
140
149
idx -> nr_objects = ntohl (idx -> hdr .hdr_entries );
141
150
151
+ error = git_vector_init (& idx -> pack -> cache , idx -> nr_objects , cache_cmp );
152
+ if (error < GIT_SUCCESS )
153
+ goto cleanup ;
154
+
155
+ idx -> pack -> has_cache = 1 ;
142
156
error = git_vector_init (& idx -> objects , idx -> nr_objects , objects_cmp );
143
- if (error < GIT_SUCCESS ) {
157
+ if (error < GIT_SUCCESS )
144
158
goto cleanup ;
145
- }
146
159
147
160
* out = idx ;
148
161
@@ -250,6 +263,7 @@ int git_indexer_write(git_indexer *idx)
250
263
/* Write out the packfile trailer */
251
264
252
265
packfile_hash = git_mwindow_open (& idx -> pack -> mwf , & w , idx -> st .st_size - GIT_OID_RAWSZ , GIT_OID_RAWSZ , & left );
266
+ git_mwindow_close (& w );
253
267
if (packfile_hash == NULL ) {
254
268
error = git__rethrow (GIT_ENOMEM , "Failed to open window to packfile hash" );
255
269
goto cleanup ;
@@ -276,6 +290,7 @@ int git_indexer_write(git_indexer *idx)
276
290
error = git_filebuf_commit_at (& idx -> file , filename );
277
291
278
292
cleanup :
293
+ git_mwindow_free_all (& idx -> pack -> mwf );
279
294
if (error < GIT_SUCCESS )
280
295
git_filebuf_cleanup (& idx -> file );
281
296
@@ -303,6 +318,7 @@ int git_indexer_run(git_indexer *idx, git_indexer_stats *stats)
303
318
while (processed < idx -> nr_objects ) {
304
319
git_rawobj obj ;
305
320
git_oid oid ;
321
+ struct git_pack_entry * pentry ;
306
322
git_mwindow * w = NULL ;
307
323
char hdr [512 ] = {0 }; /* FIXME: How long should this be? */
308
324
int i , hdr_len ;
@@ -326,12 +342,24 @@ int git_indexer_run(git_indexer *idx, git_indexer_stats *stats)
326
342
goto cleanup ;
327
343
}
328
344
345
+ /* FIXME: Parse the object instead of hashing it */
329
346
error = git_odb__hash_obj (& oid , hdr , sizeof (hdr ), & hdr_len , & obj );
330
347
if (error < GIT_SUCCESS ) {
331
348
error = git__rethrow (error , "Failed to hash object" );
332
349
goto cleanup ;
333
350
}
334
351
352
+ pentry = git__malloc (sizeof (struct git_pack_entry ));
353
+ if (pentry == NULL ) {
354
+ error = GIT_ENOMEM ;
355
+ goto cleanup ;
356
+ }
357
+ git_oid_cpy (& pentry -> sha1 , & oid );
358
+ pentry -> offset = entry_start ;
359
+ error = git_vector_insert (& idx -> pack -> cache , pentry );
360
+ if (error < GIT_SUCCESS )
361
+ goto cleanup ;
362
+
335
363
git_oid_cpy (& entry -> oid , & oid );
336
364
entry -> crc = crc32 (0L , Z_NULL , 0 );
337
365
@@ -371,11 +399,15 @@ void git_indexer_free(git_indexer *idx)
371
399
{
372
400
unsigned int i ;
373
401
struct entry * e ;
402
+ struct git_pack_entry * pe ;
374
403
375
404
p_close (idx -> pack -> mwf .fd );
376
405
git_vector_foreach (& idx -> objects , i , e )
377
406
free (e );
378
407
git_vector_free (& idx -> objects );
408
+ git_vector_foreach (& idx -> pack -> cache , i , pe )
409
+ free (pe );
410
+ git_vector_free (& idx -> pack -> cache );
379
411
free (idx -> pack );
380
412
free (idx );
381
413
}
0 commit comments