2727#include "git2/config.h"
2828#include "git2/sys/index.h"
2929
30- #define INSERT_IN_MAP_EX (idx , map , e , err ) do { \
31- if ((idx)->ignore_case) \
32- (err) = git_idxmap_icase_set((git_idxmap_icase *) (map), (e), (e)); \
33- else \
34- (err) = git_idxmap_set((map), (e), (e)); \
35- } while (0)
36-
37- #define INSERT_IN_MAP (idx , e , err ) INSERT_IN_MAP_EX(idx, (idx)->entries_map, e, err)
38-
39- #define LOOKUP_IN_MAP (v , idx , k ) do { \
40- if ((idx)->ignore_case) \
41- (v) = git_idxmap_icase_get((git_idxmap_icase *) index->entries_map, (k)); \
42- else \
43- (v) = git_idxmap_get(index->entries_map, (k)); \
44- } while (0)
45-
46- #define DELETE_IN_MAP (idx , e ) do { \
47- if ((idx)->ignore_case) \
48- git_idxmap_icase_delete((git_idxmap_icase *) (idx)->entries_map, (e)); \
49- else \
50- git_idxmap_delete((idx)->entries_map, (e)); \
51- } while (0)
52-
5330static int index_apply_to_wd_diff (git_index * index , int action , const git_strarray * paths ,
5431 unsigned int flags ,
5532 git_index_matched_path_cb cb , void * payload );
@@ -148,6 +125,30 @@ static int write_index(git_oid *checksum, git_index *index, git_filebuf *file);
148125static void index_entry_free (git_index_entry * entry );
149126static void index_entry_reuc_free (git_index_reuc_entry * reuc );
150127
128+ GIT_INLINE (int ) index_map_set (git_idxmap * map , git_index_entry * e , bool ignore_case )
129+ {
130+ if (ignore_case )
131+ return git_idxmap_icase_set ((git_idxmap_icase * ) map , e , e );
132+ else
133+ return git_idxmap_set (map , e , e );
134+ }
135+
136+ GIT_INLINE (int ) index_map_delete (git_idxmap * map , git_index_entry * e , bool ignore_case )
137+ {
138+ if (ignore_case )
139+ return git_idxmap_icase_delete ((git_idxmap_icase * ) map , e );
140+ else
141+ return git_idxmap_delete (map , e );
142+ }
143+
144+ GIT_INLINE (int ) index_map_resize (git_idxmap * map , size_t count , bool ignore_case )
145+ {
146+ if (ignore_case )
147+ return git_idxmap_icase_resize ((git_idxmap_icase * ) map , count );
148+ else
149+ return git_idxmap_resize (map , count );
150+ }
151+
151152int git_index_entry_srch (const void * key , const void * array_member )
152153{
153154 const struct entry_srch_key * srch_key = key ;
@@ -507,7 +508,7 @@ static int index_remove_entry(git_index *index, size_t pos)
507508
508509 if (entry != NULL ) {
509510 git_tree_cache_invalidate_path (index -> tree , entry -> path );
510- DELETE_IN_MAP (index , entry );
511+ index_map_delete (index -> entries_map , entry , index -> ignore_case );
511512 }
512513
513514 error = git_vector_remove (& index -> entries , pos );
@@ -859,7 +860,10 @@ const git_index_entry *git_index_get_bypath(
859860 key .path = path ;
860861 GIT_INDEX_ENTRY_STAGE_SET (& key , stage );
861862
862- LOOKUP_IN_MAP (value , index , & key );
863+ if (index -> ignore_case )
864+ value = git_idxmap_icase_get ((git_idxmap_icase * ) index -> entries_map , & key );
865+ else
866+ value = git_idxmap_get (index -> entries_map , & key );
863867
864868 if (!value ) {
865869 git_error_set (GIT_ERROR_INDEX , "index does not contain '%s'" , path );
@@ -1399,10 +1403,9 @@ static int index_insert(
13991403 * at the sorted position. (Since we re-sort after each insert to
14001404 * check for dups, this is actually cheaper in the long run.)
14011405 */
1402- if ((error = git_vector_insert_sorted (& index -> entries , entry , index_no_dups )) < 0 )
1406+ if ((error = git_vector_insert_sorted (& index -> entries , entry , index_no_dups )) < 0 ||
1407+ (error = index_map_set (index -> entries_map , entry , index -> ignore_case )) < 0 )
14031408 goto out ;
1404-
1405- INSERT_IN_MAP (index , entry , error );
14061409 }
14071410
14081411 index -> dirty = 1 ;
@@ -1616,42 +1619,42 @@ int git_index_remove_bypath(git_index *index, const char *path)
16161619int git_index__fill (git_index * index , const git_vector * source_entries )
16171620{
16181621 const git_index_entry * source_entry = NULL ;
1622+ int error = 0 ;
16191623 size_t i ;
1620- int ret = 0 ;
16211624
16221625 assert (index );
16231626
16241627 if (!source_entries -> length )
16251628 return 0 ;
16261629
16271630 if (git_vector_size_hint (& index -> entries , source_entries -> length ) < 0 ||
1628- git_idxmap_resize (index -> entries_map , (size_t )(source_entries -> length * 1.3 )) < 0 )
1631+ index_map_resize (index -> entries_map , (size_t )(source_entries -> length * 1.3 ),
1632+ index -> ignore_case ) < 0 )
16291633 return -1 ;
16301634
16311635 git_vector_foreach (source_entries , i , source_entry ) {
16321636 git_index_entry * entry = NULL ;
16331637
1634- if ((ret = index_entry_dup (& entry , index , source_entry )) < 0 )
1638+ if ((error = index_entry_dup (& entry , index , source_entry )) < 0 )
16351639 break ;
16361640
16371641 index_entry_adjust_namemask (entry , ((struct entry_internal * )entry )-> pathlen );
16381642 entry -> flags_extended |= GIT_INDEX_ENTRY_UPTODATE ;
16391643 entry -> mode = git_index__create_mode (entry -> mode );
16401644
1641- if ((ret = git_vector_insert (& index -> entries , entry )) < 0 )
1645+ if ((error = git_vector_insert (& index -> entries , entry )) < 0 )
16421646 break ;
16431647
1644- INSERT_IN_MAP (index , entry , ret );
1645- if (ret < 0 )
1648+ if ((error = index_map_set (index -> entries_map , entry , index -> ignore_case )) < 0 )
16461649 break ;
16471650
16481651 index -> dirty = 1 ;
16491652 }
16501653
1651- if (!ret )
1654+ if (!error )
16521655 git_vector_sort (& index -> entries );
16531656
1654- return ret ;
1657+ return error ;
16551658}
16561659
16571660
@@ -1684,7 +1687,7 @@ int git_index_remove(git_index *index, const char *path, int stage)
16841687 remove_key .path = path ;
16851688 GIT_INDEX_ENTRY_STAGE_SET (& remove_key , stage );
16861689
1687- DELETE_IN_MAP (index , & remove_key );
1690+ index_map_delete (index -> entries_map , & remove_key , index -> ignore_case );
16881691
16891692 if (index_find (& position , index , path , 0 , stage ) < 0 ) {
16901693 git_error_set (
@@ -2614,11 +2617,7 @@ static int parse_index(git_index *index, const char *buffer, size_t buffer_size)
26142617
26152618 assert (!index -> entries .length );
26162619
2617- if (index -> ignore_case &&
2618- (error = git_idxmap_icase_resize ((git_idxmap_icase * ) index -> entries_map ,
2619- header .entry_count )) < 0 )
2620- return error ;
2621- else if ((error = git_idxmap_resize (index -> entries_map , header .entry_count )) < 0 )
2620+ if ((error = index_map_resize (index -> entries_map , header .entry_count , index -> ignore_case )) < 0 )
26222621 return error ;
26232622
26242623 /* Parse all the entries */
@@ -2636,9 +2635,7 @@ static int parse_index(git_index *index, const char *buffer, size_t buffer_size)
26362635 goto done ;
26372636 }
26382637
2639- INSERT_IN_MAP (index , entry , error );
2640-
2641- if (error < 0 ) {
2638+ if ((error = index_map_set (index -> entries_map , entry , index -> ignore_case )) < 0 ) {
26422639 index_entry_free (entry );
26432640 goto done ;
26442641 }
@@ -3133,17 +3130,11 @@ int git_index_read_tree(git_index *index, const git_tree *tree)
31333130 if ((error = git_tree_walk (tree , GIT_TREEWALK_POST , read_tree_cb , & data )) < 0 )
31343131 goto cleanup ;
31353132
3136- if (index -> ignore_case &&
3137- (error = git_idxmap_icase_resize ((git_idxmap_icase * ) entries_map ,
3138- entries .length )) < 0 )
3139- goto cleanup ;
3140- else if ((error = git_idxmap_resize (entries_map , entries .length )) < 0 )
3133+ if ((error = index_map_resize (entries_map , entries .length , index -> ignore_case )) < 0 )
31413134 goto cleanup ;
31423135
31433136 git_vector_foreach (& entries , i , e ) {
3144- INSERT_IN_MAP_EX (index , entries_map , e , error );
3145-
3146- if (error < 0 ) {
3137+ if ((error = index_map_set (entries_map , e , index -> ignore_case )) < 0 ) {
31473138 git_error_set (GIT_ERROR_INDEX , "failed to insert entry into map" );
31483139 return error ;
31493140 }
@@ -3195,12 +3186,8 @@ static int git_index_read_iterator(
31953186 (error = git_idxmap_new (& new_entries_map )) < 0 )
31963187 goto done ;
31973188
3198- if (index -> ignore_case && new_length_hint &&
3199- (error = git_idxmap_icase_resize ((git_idxmap_icase * ) new_entries_map ,
3200- new_length_hint )) < 0 )
3201- goto done ;
3202- else if (new_length_hint &&
3203- (error = git_idxmap_resize (new_entries_map , new_length_hint )) < 0 )
3189+ if (new_length_hint && (error = index_map_resize (new_entries_map , new_length_hint ,
3190+ index -> ignore_case )) < 0 )
32043191 goto done ;
32053192
32063193 opts .flags = GIT_ITERATOR_DONT_IGNORE_CASE |
@@ -3265,7 +3252,8 @@ static int git_index_read_iterator(
32653252
32663253 if (add_entry ) {
32673254 if ((error = git_vector_insert (& new_entries , add_entry )) == 0 )
3268- INSERT_IN_MAP_EX (index , new_entries_map , add_entry , error );
3255+ error = index_map_set (new_entries_map , add_entry ,
3256+ index -> ignore_case );
32693257 }
32703258
32713259 if (remove_entry && error >= 0 )
0 commit comments