summaryrefslogtreecommitdiff
path: root/src/index.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2018-12-01 01:16:25 +0100
committerPatrick Steinhardt <ps@pks.im>2019-02-15 13:16:48 +0100
commit661fc57b2cd4bcc1024aa3c6a7ffb3190571685e (patch)
tree423e59ea6b752c222436b61e3be79bc39f98f4f0 /src/index.c
parentd00c24a9dd1809a6211b00c366d986bc40934aaf (diff)
downloadlibgit2-661fc57b2cd4bcc1024aa3c6a7ffb3190571685e.tar.gz
idxmap: introduce high-level setter for key/value pairs
Currently, one would use the function `git_idxmap_insert` to insert key/value pairs into a map. This function has historically been a macro, which is why its syntax is kind of weird: instead of returning an error code directly, it instead has to be passed a pointer to where the return value shall be stored. This does not match libgit2's common idiom of directly returning error codes. Introduce a new function `git_idxmap_set`, which takes as parameters the map, key and value and directly returns an error code. Convert all callers of `git_idxmap_insert` to make use of it.
Diffstat (limited to 'src/index.c')
-rw-r--r--src/index.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/index.c b/src/index.c
index 06c5ca3a3..308b89a16 100644
--- a/src/index.c
+++ b/src/index.c
@@ -29,9 +29,9 @@
#define INSERT_IN_MAP_EX(idx, map, e, err) do { \
if ((idx)->ignore_case) \
- git_idxmap_icase_insert((git_idxmap_icase *) (map), (e), (e), (err)); \
+ (err) = git_idxmap_icase_set((git_idxmap_icase *) (map), (e), (e)); \
else \
- git_idxmap_insert((map), (e), (e), (err)); \
+ (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)
@@ -1402,7 +1402,7 @@ static int index_insert(
if ((error = git_vector_insert_sorted(&index->entries, entry, index_no_dups)) < 0)
goto out;
- INSERT_IN_MAP(index, entry, &error);
+ INSERT_IN_MAP(index, entry, error);
}
index->dirty = 1;
@@ -1635,7 +1635,7 @@ int git_index__fill(git_index *index, const git_vector *source_entries)
if ((ret = git_vector_insert(&index->entries, entry)) < 0)
break;
- INSERT_IN_MAP(index, entry, &ret);
+ INSERT_IN_MAP(index, entry, ret);
if (ret < 0)
break;
@@ -2628,7 +2628,7 @@ static int parse_index(git_index *index, const char *buffer, size_t buffer_size)
goto done;
}
- INSERT_IN_MAP(index, entry, &error);
+ INSERT_IN_MAP(index, entry, error);
if (error < 0) {
index_entry_free(entry);
@@ -3131,7 +3131,7 @@ int git_index_read_tree(git_index *index, const git_tree *tree)
git_idxmap_resize(entries_map, entries.length);
git_vector_foreach(&entries, i, e) {
- INSERT_IN_MAP_EX(index, entries_map, e, &error);
+ INSERT_IN_MAP_EX(index, entries_map, e, error);
if (error < 0) {
git_error_set(GIT_ERROR_INDEX, "failed to insert entry into map");
@@ -3252,7 +3252,7 @@ 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);
+ INSERT_IN_MAP_EX(index, new_entries_map, add_entry, error);
}
if (remove_entry && error >= 0)