Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Beller <sbeller@google.com>2017-06-30 22:14:05 +0300
committerJunio C Hamano <gitster@pobox.com>2017-06-30 22:49:28 +0300
commit7663cdc86c860d5b5293a1dd4b0fb6c4e006d08e (patch)
tree19a347bfc7b3eb59f2f30c581c8408679001d764 /builtin/difftool.c
parente0aaa1b6532cfce93d87af9bc813fb2e7a7ce9d7 (diff)
hashmap.h: compare function has access to a data field
When using the hashmap a common need is to have access to caller provided data in the compare function. A couple of times we abuse the keydata field to pass in the data needed. This happens for example in patch-ids.c. This patch changes the function signature of the compare function to have one more void pointer available. The pointer given for each invocation of the compare function must be defined in the init function of the hashmap and is just passed through. Documentation of this new feature is deferred to a later patch. This is a rather mechanical conversion, just adding the new pass-through parameter. However while at it improve the naming of the fields of all compare functions used by hashmaps by ensuring unused parameters are prefixed with 'unused_' and naming the parameters what they are (instead of 'unused' make it 'unused_keydata'). Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/difftool.c')
-rw-r--r--builtin/difftool.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/builtin/difftool.c b/builtin/difftool.c
index 9199227f6e9..a1a26ba8912 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -130,8 +130,10 @@ struct working_tree_entry {
char path[FLEX_ARRAY];
};
-static int working_tree_entry_cmp(struct working_tree_entry *a,
- struct working_tree_entry *b, void *keydata)
+static int working_tree_entry_cmp(const void *unused_cmp_data,
+ struct working_tree_entry *a,
+ struct working_tree_entry *b,
+ void *unused_keydata)
{
return strcmp(a->path, b->path);
}
@@ -146,7 +148,9 @@ struct pair_entry {
const char path[FLEX_ARRAY];
};
-static int pair_cmp(struct pair_entry *a, struct pair_entry *b, void *keydata)
+static int pair_cmp(const void *unused_cmp_data,
+ struct pair_entry *a, struct pair_entry *b,
+ void *unused_keydata)
{
return strcmp(a->path, b->path);
}
@@ -174,7 +178,9 @@ struct path_entry {
char path[FLEX_ARRAY];
};
-static int path_entry_cmp(struct path_entry *a, struct path_entry *b, void *key)
+static int path_entry_cmp(const void *unused_cmp_data,
+ struct path_entry *a, struct path_entry *b,
+ void *key)
{
return strcmp(a->path, key ? key : b->path);
}
@@ -367,9 +373,9 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
wtdir_len = wtdir.len;
hashmap_init(&working_tree_dups,
- (hashmap_cmp_fn)working_tree_entry_cmp, 0);
- hashmap_init(&submodules, (hashmap_cmp_fn)pair_cmp, 0);
- hashmap_init(&symlinks2, (hashmap_cmp_fn)pair_cmp, 0);
+ (hashmap_cmp_fn)working_tree_entry_cmp, NULL, 0);
+ hashmap_init(&submodules, (hashmap_cmp_fn)pair_cmp, NULL, 0);
+ hashmap_init(&symlinks2, (hashmap_cmp_fn)pair_cmp, NULL, 0);
child.no_stdin = 1;
child.git_cmd = 1;
@@ -580,9 +586,9 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
* files through the symlink.
*/
hashmap_init(&wt_modified, (hashmap_cmp_fn)path_entry_cmp,
- wtindex.cache_nr);
+ NULL, wtindex.cache_nr);
hashmap_init(&tmp_modified, (hashmap_cmp_fn)path_entry_cmp,
- wtindex.cache_nr);
+ NULL, wtindex.cache_nr);
for (i = 0; i < wtindex.cache_nr; i++) {
struct hashmap_entry dummy;