From: Stefan Beller <sbeller@google.com>
To: sbeller@google.com
Cc: git@jeffhostetler.com, git@vger.kernel.org, gitster@pobox.com,
jrnieder@gmail.com
Subject: [PATCHv3 2/3] patch-ids.c: use hashmap correctly
Date: Fri, 30 Jun 2017 12:14:06 -0700 [thread overview]
Message-ID: <20170630191407.5381-3-sbeller@google.com> (raw)
In-Reply-To: <20170630191407.5381-1-sbeller@google.com>
As eluded to in the previous patch, the code in patch-ids.c is using
the hashmaps API wrong.
Luckily we do not have a bug, as all hashmap functionality that we use
here (hashmap_get) passes through the keydata. If hashmap_get_next were
to be used, a bug would occur as that passes NULL for the key_data.
So instead use the hashmap API correctly and provide the caller required
data in the compare function via the first argument that always gets
passed and was setup via the hashmap_init function.
Signed-off-by: Stefan Beller <sbeller@google.com>
---
patch-ids.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/patch-ids.c b/patch-ids.c
index 815c115811..b4166b0f38 100644
--- a/patch-ids.c
+++ b/patch-ids.c
@@ -35,10 +35,10 @@ int commit_patch_id(struct commit *commit, struct diff_options *options,
* the side of safety. The actual value being negative does not have
* any significance; only that it is non-zero matters.
*/
-static int patch_id_cmp(const void *unused_cmp_data,
+static int patch_id_cmp(struct diff_options *opt,
struct patch_id *a,
struct patch_id *b,
- struct diff_options *opt)
+ const void *unused_keydata)
{
if (is_null_oid(&a->patch_id) &&
commit_patch_id(a->commit, opt, &a->patch_id, 0))
@@ -59,7 +59,7 @@ int init_patch_ids(struct patch_ids *ids)
DIFF_OPT_SET(&ids->diffopts, RECURSIVE);
diff_setup_done(&ids->diffopts);
hashmap_init(&ids->patches, (hashmap_cmp_fn)patch_id_cmp,
- NULL, 256);
+ &ids->diffopts, 256);
return 0;
}
@@ -95,7 +95,7 @@ struct patch_id *has_commit_patch_id(struct commit *commit,
if (init_patch_id_entry(&patch, commit, ids))
return NULL;
- return hashmap_get(&ids->patches, &patch, &ids->diffopts);
+ return hashmap_get(&ids->patches, &patch, NULL);
}
struct patch_id *add_commit_patch_id(struct commit *commit,
--
2.13.0.31.g9b732c453e
next prev parent reply other threads:[~2017-06-30 19:14 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-29 1:13 [PATCH 0/2] Introduce data field in hashmap and migrate docs to header Stefan Beller
2017-06-29 1:13 ` [PATCH 1/2] hashmap.h: compare function has access to a data field Stefan Beller
2017-06-29 18:06 ` Junio C Hamano
2017-06-29 18:11 ` Junio C Hamano
2017-06-29 18:20 ` Stefan Beller
2017-06-30 17:26 ` Junio C Hamano
2017-06-29 1:13 ` [PATCH 2/2] hashmap: migrate documentation from Documentation/technical into header Stefan Beller
2017-06-29 13:25 ` Jeff Hostetler
2017-06-29 21:18 ` Jonathan Nieder
2017-06-29 23:41 ` Stefan Beller
2017-06-29 23:53 ` [PATCHv2 0/2] Introduce data field in hashmap and migrate docs to header Stefan Beller
2017-06-29 23:53 ` [PATCHv2 1/2] hashmap.h: compare function has access to a data field Stefan Beller
2017-06-30 17:34 ` Junio C Hamano
2017-06-30 17:41 ` Stefan Beller
2017-06-30 18:47 ` Junio C Hamano
2017-06-30 18:57 ` Stefan Beller
2017-06-30 17:39 ` Junio C Hamano
2017-06-30 18:00 ` Stefan Beller
2017-06-30 18:40 ` Junio C Hamano
2017-06-29 23:53 ` [PATCHv2 2/2] hashmap: migrate documentation from Documentation/technical into header Stefan Beller
2017-06-30 19:14 ` [PATCHv3 0/3] Introduce data field in hashmap and migrate docs to header Stefan Beller
2017-06-30 19:14 ` [PATCHv3 1/3] hashmap.h: compare function has access to a data field Stefan Beller
2017-06-30 19:14 ` Stefan Beller [this message]
2017-06-30 19:50 ` [PATCHv3 2/3] patch-ids.c: use hashmap correctly Junio C Hamano
2017-07-05 9:00 ` Jeff King
2017-06-30 19:14 ` [PATCHv3 3/3] hashmap: migrate documentation from Documentation/technical into header Stefan Beller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170630191407.5381-3-sbeller@google.com \
--to=sbeller@google.com \
--cc=git@jeffhostetler.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jrnieder@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).