Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
a129941a
Unverified
Commit
a129941a
authored
Jan 16, 2020
by
Edward Thomson
Committed by
GitHub
Jan 16, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5351 from pks-t/pks/index-map-macros
index: replace map macros with inline functions
parents
dea5ce3d
7fc97eb3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
60 deletions
+48
-60
src/index.c
+48
-60
No files found.
src/index.c
View file @
a129941a
...
...
@@ -27,29 +27,6 @@
#include "git2/config.h"
#include "git2/sys/index.h"
#define INSERT_IN_MAP_EX(idx, map, e, err) do { \
if ((idx)->ignore_case) \
(err) = git_idxmap_icase_set((git_idxmap_icase *) (map), (e), (e)); \
else \
(err) = git_idxmap_set((map), (e), (e)); \
} while (0)
#define INSERT_IN_MAP(idx, e, err) INSERT_IN_MAP_EX(idx, (idx)->entries_map, e, err)
#define LOOKUP_IN_MAP(v, idx, k) do { \
if ((idx)->ignore_case) \
(v) = git_idxmap_icase_get((git_idxmap_icase *) index->entries_map, (k)); \
else \
(v) = git_idxmap_get(index->entries_map, (k)); \
} while (0)
#define DELETE_IN_MAP(idx, e) do { \
if ((idx)->ignore_case) \
git_idxmap_icase_delete((git_idxmap_icase *) (idx)->entries_map, (e)); \
else \
git_idxmap_delete((idx)->entries_map, (e)); \
} while (0)
static
int
index_apply_to_wd_diff
(
git_index
*
index
,
int
action
,
const
git_strarray
*
paths
,
unsigned
int
flags
,
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);
static
void
index_entry_free
(
git_index_entry
*
entry
);
static
void
index_entry_reuc_free
(
git_index_reuc_entry
*
reuc
);
GIT_INLINE
(
int
)
index_map_set
(
git_idxmap
*
map
,
git_index_entry
*
e
,
bool
ignore_case
)
{
if
(
ignore_case
)
return
git_idxmap_icase_set
((
git_idxmap_icase
*
)
map
,
e
,
e
);
else
return
git_idxmap_set
(
map
,
e
,
e
);
}
GIT_INLINE
(
int
)
index_map_delete
(
git_idxmap
*
map
,
git_index_entry
*
e
,
bool
ignore_case
)
{
if
(
ignore_case
)
return
git_idxmap_icase_delete
((
git_idxmap_icase
*
)
map
,
e
);
else
return
git_idxmap_delete
(
map
,
e
);
}
GIT_INLINE
(
int
)
index_map_resize
(
git_idxmap
*
map
,
size_t
count
,
bool
ignore_case
)
{
if
(
ignore_case
)
return
git_idxmap_icase_resize
((
git_idxmap_icase
*
)
map
,
count
);
else
return
git_idxmap_resize
(
map
,
count
);
}
int
git_index_entry_srch
(
const
void
*
key
,
const
void
*
array_member
)
{
const
struct
entry_srch_key
*
srch_key
=
key
;
...
...
@@ -507,7 +508,7 @@ static int index_remove_entry(git_index *index, size_t pos)
if
(
entry
!=
NULL
)
{
git_tree_cache_invalidate_path
(
index
->
tree
,
entry
->
path
);
DELETE_IN_MAP
(
index
,
entry
);
index_map_delete
(
index
->
entries_map
,
entry
,
index
->
ignore_case
);
}
error
=
git_vector_remove
(
&
index
->
entries
,
pos
);
...
...
@@ -859,7 +860,10 @@ const git_index_entry *git_index_get_bypath(
key
.
path
=
path
;
GIT_INDEX_ENTRY_STAGE_SET
(
&
key
,
stage
);
LOOKUP_IN_MAP
(
value
,
index
,
&
key
);
if
(
index
->
ignore_case
)
value
=
git_idxmap_icase_get
((
git_idxmap_icase
*
)
index
->
entries_map
,
&
key
);
else
value
=
git_idxmap_get
(
index
->
entries_map
,
&
key
);
if
(
!
value
)
{
git_error_set
(
GIT_ERROR_INDEX
,
"index does not contain '%s'"
,
path
);
...
...
@@ -1399,10 +1403,9 @@ static int index_insert(
* at the sorted position. (Since we re-sort after each insert to
* check for dups, this is actually cheaper in the long run.)
*/
if
((
error
=
git_vector_insert_sorted
(
&
index
->
entries
,
entry
,
index_no_dups
))
<
0
)
if
((
error
=
git_vector_insert_sorted
(
&
index
->
entries
,
entry
,
index_no_dups
))
<
0
||
(
error
=
index_map_set
(
index
->
entries_map
,
entry
,
index
->
ignore_case
))
<
0
)
goto
out
;
INSERT_IN_MAP
(
index
,
entry
,
error
);
}
index
->
dirty
=
1
;
...
...
@@ -1616,8 +1619,8 @@ int git_index_remove_bypath(git_index *index, const char *path)
int
git_index__fill
(
git_index
*
index
,
const
git_vector
*
source_entries
)
{
const
git_index_entry
*
source_entry
=
NULL
;
int
error
=
0
;
size_t
i
;
int
ret
=
0
;
assert
(
index
);
...
...
@@ -1625,33 +1628,33 @@ int git_index__fill(git_index *index, const git_vector *source_entries)
return
0
;
if
(
git_vector_size_hint
(
&
index
->
entries
,
source_entries
->
length
)
<
0
||
git_idxmap_resize
(
index
->
entries_map
,
(
size_t
)(
source_entries
->
length
*
1
.
3
))
<
0
)
index_map_resize
(
index
->
entries_map
,
(
size_t
)(
source_entries
->
length
*
1
.
3
),
index
->
ignore_case
)
<
0
)
return
-
1
;
git_vector_foreach
(
source_entries
,
i
,
source_entry
)
{
git_index_entry
*
entry
=
NULL
;
if
((
ret
=
index_entry_dup
(
&
entry
,
index
,
source_entry
))
<
0
)
if
((
error
=
index_entry_dup
(
&
entry
,
index
,
source_entry
))
<
0
)
break
;
index_entry_adjust_namemask
(
entry
,
((
struct
entry_internal
*
)
entry
)
->
pathlen
);
entry
->
flags_extended
|=
GIT_INDEX_ENTRY_UPTODATE
;
entry
->
mode
=
git_index__create_mode
(
entry
->
mode
);
if
((
ret
=
git_vector_insert
(
&
index
->
entries
,
entry
))
<
0
)
if
((
error
=
git_vector_insert
(
&
index
->
entries
,
entry
))
<
0
)
break
;
INSERT_IN_MAP
(
index
,
entry
,
ret
);
if
(
ret
<
0
)
if
((
error
=
index_map_set
(
index
->
entries_map
,
entry
,
index
->
ignore_case
))
<
0
)
break
;
index
->
dirty
=
1
;
}
if
(
!
ret
)
if
(
!
error
)
git_vector_sort
(
&
index
->
entries
);
return
ret
;
return
error
;
}
...
...
@@ -1684,7 +1687,7 @@ int git_index_remove(git_index *index, const char *path, int stage)
remove_key
.
path
=
path
;
GIT_INDEX_ENTRY_STAGE_SET
(
&
remove_key
,
stage
);
DELETE_IN_MAP
(
index
,
&
remove_key
);
index_map_delete
(
index
->
entries_map
,
&
remove_key
,
index
->
ignore_case
);
if
(
index_find
(
&
position
,
index
,
path
,
0
,
stage
)
<
0
)
{
git_error_set
(
...
...
@@ -2614,11 +2617,7 @@ static int parse_index(git_index *index, const char *buffer, size_t buffer_size)
assert
(
!
index
->
entries
.
length
);
if
(
index
->
ignore_case
&&
(
error
=
git_idxmap_icase_resize
((
git_idxmap_icase
*
)
index
->
entries_map
,
header
.
entry_count
))
<
0
)
return
error
;
else
if
((
error
=
git_idxmap_resize
(
index
->
entries_map
,
header
.
entry_count
))
<
0
)
if
((
error
=
index_map_resize
(
index
->
entries_map
,
header
.
entry_count
,
index
->
ignore_case
))
<
0
)
return
error
;
/* Parse all the entries */
...
...
@@ -2636,9 +2635,7 @@ static int parse_index(git_index *index, const char *buffer, size_t buffer_size)
goto
done
;
}
INSERT_IN_MAP
(
index
,
entry
,
error
);
if
(
error
<
0
)
{
if
((
error
=
index_map_set
(
index
->
entries_map
,
entry
,
index
->
ignore_case
))
<
0
)
{
index_entry_free
(
entry
);
goto
done
;
}
...
...
@@ -3133,17 +3130,11 @@ int git_index_read_tree(git_index *index, const git_tree *tree)
if
((
error
=
git_tree_walk
(
tree
,
GIT_TREEWALK_POST
,
read_tree_cb
,
&
data
))
<
0
)
goto
cleanup
;
if
(
index
->
ignore_case
&&
(
error
=
git_idxmap_icase_resize
((
git_idxmap_icase
*
)
entries_map
,
entries
.
length
))
<
0
)
goto
cleanup
;
else
if
((
error
=
git_idxmap_resize
(
entries_map
,
entries
.
length
))
<
0
)
if
((
error
=
index_map_resize
(
entries_map
,
entries
.
length
,
index
->
ignore_case
))
<
0
)
goto
cleanup
;
git_vector_foreach
(
&
entries
,
i
,
e
)
{
INSERT_IN_MAP_EX
(
index
,
entries_map
,
e
,
error
);
if
(
error
<
0
)
{
if
((
error
=
index_map_set
(
entries_map
,
e
,
index
->
ignore_case
))
<
0
)
{
git_error_set
(
GIT_ERROR_INDEX
,
"failed to insert entry into map"
);
return
error
;
}
...
...
@@ -3195,12 +3186,8 @@ static int git_index_read_iterator(
(
error
=
git_idxmap_new
(
&
new_entries_map
))
<
0
)
goto
done
;
if
(
index
->
ignore_case
&&
new_length_hint
&&
(
error
=
git_idxmap_icase_resize
((
git_idxmap_icase
*
)
new_entries_map
,
new_length_hint
))
<
0
)
goto
done
;
else
if
(
new_length_hint
&&
(
error
=
git_idxmap_resize
(
new_entries_map
,
new_length_hint
))
<
0
)
if
(
new_length_hint
&&
(
error
=
index_map_resize
(
new_entries_map
,
new_length_hint
,
index
->
ignore_case
))
<
0
)
goto
done
;
opts
.
flags
=
GIT_ITERATOR_DONT_IGNORE_CASE
|
...
...
@@ -3265,7 +3252,8 @@ static int git_index_read_iterator(
if
(
add_entry
)
{
if
((
error
=
git_vector_insert
(
&
new_entries
,
add_entry
))
==
0
)
INSERT_IN_MAP_EX
(
index
,
new_entries_map
,
add_entry
,
error
);
error
=
index_map_set
(
new_entries_map
,
add_entry
,
index
->
ignore_case
);
}
if
(
remove_entry
&&
error
>=
0
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment