4
4
#include "cache.h"
5
5
#include "diff.h"
6
6
#include "diffcore.h"
7
- #include "hash .h"
7
+ #include "hashmap .h"
8
8
#include "progress.h"
9
9
10
10
/* Table of rename/copy destinations */
@@ -243,9 +243,9 @@ static int score_compare(const void *a_, const void *b_)
243
243
}
244
244
245
245
struct file_similarity {
246
+ struct hashmap_entry entry ;
246
247
int index ;
247
248
struct diff_filespec * filespec ;
248
- struct file_similarity * next ;
249
249
};
250
250
251
251
static unsigned int hash_filespec (struct diff_filespec * filespec )
@@ -260,21 +260,22 @@ static unsigned int hash_filespec(struct diff_filespec *filespec)
260
260
return hash ;
261
261
}
262
262
263
- static int find_identical_files (struct hash_table * srcs ,
263
+ static int find_identical_files (struct hashmap * srcs ,
264
264
int dst_index ,
265
265
struct diff_options * options )
266
266
{
267
267
int renames = 0 ;
268
268
269
269
struct diff_filespec * target = rename_dst [dst_index ].two ;
270
- struct file_similarity * p , * best ;
270
+ struct file_similarity * p , * best , dst ;
271
271
int i = 100 , best_score = -1 ;
272
272
273
273
/*
274
274
* Find the best source match for specified destination.
275
275
*/
276
276
best = NULL ;
277
- for (p = lookup_hash (hash_filespec (target ), srcs ); p ; p = p -> next ) {
277
+ hashmap_entry_init (& dst , hash_filespec (target ));
278
+ for (p = hashmap_get (srcs , & dst , NULL ); p ; p = hashmap_get_next (srcs , p )) {
278
279
int score ;
279
280
struct diff_filespec * source = p -> filespec ;
280
281
@@ -309,34 +310,15 @@ static int find_identical_files(struct hash_table *srcs,
309
310
return renames ;
310
311
}
311
312
312
- static int free_similarity_list ( void * p , void * unused )
313
+ static void insert_file_table ( struct hashmap * table , int index , struct diff_filespec * filespec )
313
314
{
314
- while (p ) {
315
- struct file_similarity * entry = p ;
316
- p = entry -> next ;
317
- free (entry );
318
- }
319
- return 0 ;
320
- }
321
-
322
- static void insert_file_table (struct hash_table * table , int index , struct diff_filespec * filespec )
323
- {
324
- void * * pos ;
325
- unsigned int hash ;
326
315
struct file_similarity * entry = xmalloc (sizeof (* entry ));
327
316
328
317
entry -> index = index ;
329
318
entry -> filespec = filespec ;
330
- entry -> next = NULL ;
331
-
332
- hash = hash_filespec (filespec );
333
- pos = insert_hash (hash , entry , table );
334
319
335
- /* We already had an entry there? */
336
- if (pos ) {
337
- entry -> next = * pos ;
338
- * pos = entry ;
339
- }
320
+ hashmap_entry_init (entry , hash_filespec (filespec ));
321
+ hashmap_add (table , entry );
340
322
}
341
323
342
324
/*
@@ -349,23 +331,19 @@ static void insert_file_table(struct hash_table *table, int index, struct diff_f
349
331
static int find_exact_renames (struct diff_options * options )
350
332
{
351
333
int i , renames = 0 ;
352
- struct hash_table file_table ;
334
+ struct hashmap file_table ;
353
335
354
336
/* Add all sources to the hash table */
355
- init_hash (& file_table );
356
- preallocate_hash (& file_table , rename_src_nr );
337
+ hashmap_init (& file_table , NULL , rename_src_nr );
357
338
for (i = 0 ; i < rename_src_nr ; i ++ )
358
339
insert_file_table (& file_table , i , rename_src [i ].p -> one );
359
340
360
341
/* Walk the destinations and find best source match */
361
342
for (i = 0 ; i < rename_dst_nr ; i ++ )
362
343
renames += find_identical_files (& file_table , i , options );
363
344
364
- /* Free source file_similarity chains */
365
- for_each_hash (& file_table , free_similarity_list , options );
366
-
367
- /* .. and free the hash data structure */
368
- free_hash (& file_table );
345
+ /* Free the hash data structure and entries */
346
+ hashmap_free (& file_table , 1 );
369
347
370
348
return renames ;
371
349
}
0 commit comments