6
6
#include "exec_cmd.h"
7
7
#include "parse-options.h"
8
8
#include "diff.h"
9
- #include "hash .h"
9
+ #include "hashmap .h"
10
10
#include "argv-array.h"
11
11
12
12
#define SEEN (1u<<0)
@@ -25,7 +25,7 @@ static int longformat;
25
25
static int first_parent ;
26
26
static int abbrev = -1 ; /* unspecified */
27
27
static int max_candidates = 10 ;
28
- static struct hash_table names ;
28
+ static struct hashmap names ;
29
29
static int have_util ;
30
30
static const char * pattern ;
31
31
static int always ;
@@ -38,7 +38,7 @@ static const char *diff_index_args[] = {
38
38
39
39
40
40
struct commit_name {
41
- struct commit_name * next ;
41
+ struct hashmap_entry entry ;
42
42
unsigned char peeled [20 ];
43
43
struct tag * tag ;
44
44
unsigned prio :2 ; /* annotated tag = 2, tag = 1, head = 0 */
@@ -50,6 +50,12 @@ static const char *prio_names[] = {
50
50
"head" , "lightweight" , "annotated" ,
51
51
};
52
52
53
+ static int commit_name_cmp (const struct commit_name * cn1 ,
54
+ const struct commit_name * cn2 , const void * peeled )
55
+ {
56
+ return hashcmp (cn1 -> peeled , peeled ? peeled : cn2 -> peeled );
57
+ }
58
+
53
59
static inline unsigned int hash_sha1 (const unsigned char * sha1 )
54
60
{
55
61
unsigned int hash ;
@@ -59,21 +65,9 @@ static inline unsigned int hash_sha1(const unsigned char *sha1)
59
65
60
66
static inline struct commit_name * find_commit_name (const unsigned char * peeled )
61
67
{
62
- struct commit_name * n = lookup_hash (hash_sha1 (peeled ), & names );
63
- while (n && !!hashcmp (peeled , n -> peeled ))
64
- n = n -> next ;
65
- return n ;
66
- }
67
-
68
- static int set_util (void * chain , void * data )
69
- {
70
- struct commit_name * n ;
71
- for (n = chain ; n ; n = n -> next ) {
72
- struct commit * c = lookup_commit_reference_gently (n -> peeled , 1 );
73
- if (c )
74
- c -> util = n ;
75
- }
76
- return 0 ;
68
+ struct commit_name key ;
69
+ hashmap_entry_init (& key , hash_sha1 (peeled ));
70
+ return hashmap_get (& names , & key , peeled );
77
71
}
78
72
79
73
static int replace_name (struct commit_name * e ,
@@ -118,16 +112,10 @@ static void add_to_known_names(const char *path,
118
112
struct tag * tag = NULL ;
119
113
if (replace_name (e , prio , sha1 , & tag )) {
120
114
if (!e ) {
121
- void * * pos ;
122
115
e = xmalloc (sizeof (struct commit_name ));
123
116
hashcpy (e -> peeled , peeled );
124
- pos = insert_hash (hash_sha1 (peeled ), e , & names );
125
- if (pos ) {
126
- e -> next = * pos ;
127
- * pos = e ;
128
- } else {
129
- e -> next = NULL ;
130
- }
117
+ hashmap_entry_init (e , hash_sha1 (peeled ));
118
+ hashmap_add (& names , e );
131
119
e -> path = NULL ;
132
120
}
133
121
e -> tag = tag ;
@@ -292,7 +280,14 @@ static void describe(const char *arg, int last_one)
292
280
fprintf (stderr , _ ("searching to describe %s\n" ), arg );
293
281
294
282
if (!have_util ) {
295
- for_each_hash (& names , set_util , NULL );
283
+ struct hashmap_iter iter ;
284
+ struct commit * c ;
285
+ struct commit_name * n = hashmap_iter_first (& names , & iter );
286
+ for (; n ; n = hashmap_iter_next (& iter )) {
287
+ c = lookup_commit_reference_gently (n -> peeled , 1 );
288
+ if (c )
289
+ c -> util = n ;
290
+ }
296
291
have_util = 1 ;
297
292
}
298
293
@@ -463,9 +458,9 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
463
458
return cmd_name_rev (args .argc , args .argv , prefix );
464
459
}
465
460
466
- init_hash (& names );
461
+ hashmap_init (& names , ( hashmap_cmp_fn ) commit_name_cmp , 0 );
467
462
for_each_rawref (get_name , NULL );
468
- if (!names .nr && !always )
463
+ if (!names .size && !always )
469
464
die (_ ("No names found, cannot describe anything." ));
470
465
471
466
if (argc == 0 ) {
0 commit comments