{"thread":{"id":"49212","subject":"[PATCH 0/9] introducing oideq()","startedAt":"2018-08-25T08:00:36Z","lastAt":"2018-08-29T00:08:14Z","messageCount":30,"participants":["Jeff King","Eric Sunshine","Andrei Rybak","brian m. carlson","Derrick Stolee"],"isPatch":true,"patchVersion":1,"patchTotal":9},"messages":[{"id":"356502","messageId":"20180825080031.GA32139@sigill.intra.peff.net","threadId":"49212","inReplyTo":null,"subject":"[PATCH 0/9] introducing oideq()","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2018-08-25T08:00:31Z","receivedAt":"2018-08-25T08:00:36Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"This is a follow-up to the discussion in:\n\n  https://public-inbox.org/git/20180822030344.GA14684@sigill.intra.peff.net/\n\nThe general idea is that the majority of callers don't care about actual\nplus/minus ordering from oidcmp() and hashcmp(); they just want to know\nif two oids are equal. The stricter equality check can be optimized\nbetter by the compiler.\n\nDue to the simplicity of the current code and our inlining, the compiler\ncan usually figure this out for now. So I wouldn't expect this patch to\nactually improve performance right away. But as that discussion shows,\nwe are likely to take a performance hit as we move to more runtime\ndetermination of the_hash_algo parameters. Having these callers use the\nmore strict form will potentially help us recover that.\n\nSo in that sense we _could_ simply punt on this series until then (and\nit's certainly post-v2.19 material). But I think it's worth doing now,\nsimply from a readability/annotation standpoint. IMHO the resulting code\nis more clear (though I've long since taught myself to read !foocmp() as\nequality).\n\nIf we do punt, patch 1 could still be picked up now, as it's a related\ncleanup that stands on its own.\n\nThe diffstat is scary, but the vast majority of that is purely\nmechanical via coccinelle. There's some discussion in the individual\npatches.\n\nWe also don't _have_ to convert all sites now. I strongly suspect that\nonly a few calls are actual measurable bottlenecks (the one in\nlookup_object() is the one I was primarily interested in).  But it's\njust as easy to do it all at once with coccinelle, rather than try to\nmeasure each one (and once we add the coccinelle patches, we have to\nconvert everything, or \"make coccicheck\" will nag people to do so).\n\nI didn't bother to hold back changes for any topics in flight.  There\nare a handful of conflicts with \"pu\", but they're mostly trivial.  The\nonly big one is due to some code movement in ds/reachable. But though\nthe conflict is big, the resolution is still easy (you can even just\ntake the other side and \"make coccicheck\" to do it automatically).\n\n  [1/9]: coccinelle: use <...> for function exclusion\n  [2/9]: introduce hasheq() and oideq()\n  [3/9]: convert \"oidcmp() == 0\" to oideq()\n  [4/9]: convert \"hashcmp() == 0\" to hasheq()\n  [5/9]: convert \"oidcmp() != 0\" to \"!oideq()\"\n  [6/9]: convert \"hashcmp() != 0\" to \"!hasheq()\"\n  [7/9]: convert hashmap comparison functions to oideq()\n  [8/9]: read-cache: use oideq() in ce_compare functions\n  [9/9]: show_dirstat: simplify same-content check\n\n bisect.c                           |  6 ++--\n blame.c                            |  8 ++---\n builtin/am.c                       |  2 +-\n builtin/checkout.c                 |  2 +-\n builtin/describe.c                 | 10 +++---\n builtin/diff.c                     |  2 +-\n builtin/difftool.c                 |  4 +--\n builtin/fast-export.c              |  2 +-\n builtin/fetch.c                    |  6 ++--\n builtin/fmt-merge-msg.c            |  6 ++--\n builtin/index-pack.c               |  8 ++---\n builtin/log.c                      |  6 ++--\n builtin/merge-tree.c               |  2 +-\n builtin/merge.c                    |  6 ++--\n builtin/pack-objects.c             |  4 +--\n builtin/pull.c                     |  4 +--\n builtin/receive-pack.c             |  4 +--\n builtin/remote.c                   |  2 +-\n builtin/replace.c                  |  6 ++--\n builtin/rm.c                       |  2 +-\n builtin/show-branch.c              |  6 ++--\n builtin/tag.c                      |  2 +-\n builtin/unpack-objects.c           |  4 +--\n builtin/update-index.c             |  4 +--\n bulk-checkin.c                     |  2 +-\n bundle.c                           |  2 +-\n cache-tree.c                       |  2 +-\n cache.h                            | 22 +++++++++----\n combine-diff.c                     |  4 +--\n commit-graph.c                     | 10 +++---\n commit.c                           |  2 +-\n connect.c                          |  2 +-\n contrib/coccinelle/commit.cocci    |  4 +--\n contrib/coccinelle/object_id.cocci | 50 ++++++++++++++++++++++++------\n diff-lib.c                         |  4 +--\n diff.c                             | 23 ++++++--------\n diffcore-break.c                   |  2 +-\n diffcore-rename.c                  |  2 +-\n dir.c                              |  6 ++--\n fast-import.c                      | 10 +++---\n fetch-pack.c                       |  2 +-\n http-push.c                        |  2 +-\n http-walker.c                      |  4 +--\n http.c                             |  2 +-\n log-tree.c                         |  6 ++--\n match-trees.c                      |  2 +-\n merge-recursive.c                  |  4 +--\n notes-merge.c                      | 24 +++++++-------\n notes.c                            |  8 ++---\n object.c                           |  2 +-\n oidmap.c                           | 12 +++----\n pack-check.c                       |  6 ++--\n pack-objects.c                     |  2 +-\n pack-write.c                       |  4 +--\n packfile.c                         | 12 +++----\n patch-ids.c                        |  8 ++---\n read-cache.c                       | 12 +++----\n ref-filter.c                       |  2 +-\n refs.c                             |  8 ++---\n refs/files-backend.c               |  6 ++--\n refs/packed-backend.c              |  2 +-\n refs/ref-cache.c                   |  2 +-\n remote.c                           |  8 ++---\n revision.c                         |  2 +-\n sequencer.c                        | 40 ++++++++++++------------\n sha1-array.c                       |  2 +-\n sha1-file.c                        | 12 +++----\n sha1-name.c                        |  2 +-\n submodule-config.c                 |  4 +--\n submodule.c                        |  2 +-\n t/helper/test-dump-cache-tree.c    |  2 +-\n transport.c                        |  2 +-\n tree-diff.c                        |  2 +-\n unpack-trees.c                     |  6 ++--\n wt-status.c                        | 10 +++---\n xdiff-interface.c                  |  2 +-\n 76 files changed, 259 insertions(+), 224 deletions(-)\n\n"},{"id":"356503","messageId":"20180825080346.GA737@sigill.intra.peff.net","threadId":"49212","inReplyTo":"20180825080031.GA32139@sigill.intra.peff.net","subject":"[PATCH 1/9] coccinelle: use <...> for function exclusion","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2018-08-25T08:03:46Z","receivedAt":"2018-08-25T08:03:49Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"Sometimes we want to suppress a coccinelle transformation\ninside a particular function. For example, in finding\nconversions of hashcmp() to oidcmp(), we should not convert\nthe call in oidcmp() itself, since that would cause infinite\nrecursion. We write that like this:\n\n  @@\n  identifier f != oidcmp;\n  expression E1, E2;\n  @@\n    f(...) {...\n  - hashcmp(E1->hash, E2->hash)\n  + oidcmp(E1, E2)\n    ...}\n\nto match the interior of any function _except_ oidcmp().\n\nUnfortunately, this doesn't catch all cases (e.g., the one\nin sequencer.c that this patch fixes). The problem, as\nexplained by one of the Coccinelle developers in [1], is:\n\n  For transformation, A ... B requires that B occur on every\n  execution path starting with A, unless that execution path\n  ends up in error handling code.  (eg, if (...) { ...\n  return; }).  Here your A is the start of the function.  So\n  you need a call to hashcmp on every path through the\n  function, which fails when you add ifs.\n\n  [...]\n\n  Another issue with A ... B is that by default A and B\n  should not appear in the matched region.  So your original\n  rule matches only the case where every execution path\n  contains exactly one call to hashcmp, not more than one.\n\nOne way to solve this is to put the pattern inside an\nangle-bracket pattern like \"<... P ...>\", which allows zero\nor more matches of P. That works (and is what this patch\ndoes), but it has one drawback: it matches more than we care\nabout, and Coccinelle uses extra CPU. Here are timings for\n\"make coccicheck\" before and after this patch:\n\n  [before]\n  real\t1m27.122s\n  user\t7m34.451s\n  sys\t0m37.330s\n\n  [after]\n  real\t2m18.040s\n  user\t10m58.310s\n  sys\t0m41.549s\n\nThat's not ideal, but it's more important for this to be\ncorrect than to be fast. And coccicheck is already fairly\nslow (and people don't run it for every single patch). So\nit's an acceptable tradeoff.\n\nThere _is_ a better way to do it, which is to record the\nposition at which we find hashcmp(), and then check it\nagainst the forbidden function list. Like:\n\n  @@\n  position p : script:python() { p[0].current_element != \"oidcmp\" };\n  expression E1,E2;\n  @@\n  - hashcmp@p(E1->hash, E2->hash)\n  + oidcmp(E1, E2)\n\nThis is only a little slower than the current code, and does\nthe right thing in all cases. Unfortunately, not all builds\nof Coccinelle include python support (including the ones in\nDebian). Requiring it may mean that fewer people can easily\nrun the tool, which is worse than it simply being a little\nslower.\n\nWe may want to revisit this decision in the future if:\n\n  - builds with python become more common\n\n  - we find more uses for python support that tip the\n    cost-benefit analysis\n\nBut for now this patch sticks with the angle-bracket\nsolution, and converts all existing cocci patches. This\nfixes only one missed case in the current code, though it\nmakes a much better difference for some new rules I'm adding\n(converting \"!hashcmp()\" to \"hasheq()\" misses over half the\npossible conversions using the old form).\n\n[1] https://public-inbox.org/git/alpine.DEB.2.21.1808240652370.2344@hadrien/\n\nHelped-by: Julia Lawall <julia.lawall@lip6.fr>\nSigned-off-by: Jeff King <peff@peff.net>\n---\n contrib/coccinelle/commit.cocci    |  4 ++--\n contrib/coccinelle/object_id.cocci | 20 ++++++++++----------\n sequencer.c                        |  2 +-\n 3 files changed, 13 insertions(+), 13 deletions(-)\n\ndiff --git a/contrib/coccinelle/commit.cocci b/contrib/coccinelle/commit.cocci\nindex aec3345adb..c49aa558f0 100644\n--- a/contrib/coccinelle/commit.cocci\n+++ b/contrib/coccinelle/commit.cocci\n@@ -15,10 +15,10 @@ expression c;\n identifier f !~ \"^(get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$\";\n expression c;\n @@\n-  f(...) {...\n+  f(...) {<...\n - c->maybe_tree\n + get_commit_tree(c)\n-  ...}\n+  ...>}\n \n @@\n expression c;\ndiff --git a/contrib/coccinelle/object_id.cocci b/contrib/coccinelle/object_id.cocci\nindex 09afdbf994..5869979be7 100644\n--- a/contrib/coccinelle/object_id.cocci\n+++ b/contrib/coccinelle/object_id.cocci\n@@ -20,10 +20,10 @@ expression E1;\n identifier f != oid_to_hex;\n expression E1;\n @@\n-  f(...) {...\n+  f(...) {<...\n - sha1_to_hex(E1->hash)\n + oid_to_hex(E1)\n-  ...}\n+  ...>}\n \n @@\n expression E1, E2;\n@@ -35,10 +35,10 @@ expression E1, E2;\n identifier f != oid_to_hex_r;\n expression E1, E2;\n @@\n-   f(...) {...\n+   f(...) {<...\n - sha1_to_hex_r(E1, E2->hash)\n + oid_to_hex_r(E1, E2)\n-  ...}\n+  ...>}\n \n @@\n expression E1;\n@@ -50,10 +50,10 @@ expression E1;\n identifier f != oidclr;\n expression E1;\n @@\n-  f(...) {...\n+  f(...) {<...\n - hashclr(E1->hash)\n + oidclr(E1)\n-  ...}\n+  ...>}\n \n @@\n expression E1, E2;\n@@ -65,10 +65,10 @@ expression E1, E2;\n identifier f != oidcmp;\n expression E1, E2;\n @@\n-  f(...) {...\n+  f(...) {<...\n - hashcmp(E1->hash, E2->hash)\n + oidcmp(E1, E2)\n-  ...}\n+  ...>}\n \n @@\n expression E1, E2;\n@@ -92,10 +92,10 @@ expression E1, E2;\n identifier f != oidcpy;\n expression E1, E2;\n @@\n-  f(...) {...\n+  f(...) {<...\n - hashcpy(E1->hash, E2->hash)\n + oidcpy(E1, E2)\n-  ...}\n+  ...>}\n \n @@\n expression E1, E2;\ndiff --git a/sequencer.c b/sequencer.c\nindex 65d371c746..6a11f49651 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -4545,7 +4545,7 @@ int skip_unnecessary_picks(void)\n \t\tif (item->commit->parents->next)\n \t\t\tbreak; /* merge commit */\n \t\tparent_oid = &item->commit->parents->item->object.oid;\n-\t\tif (hashcmp(parent_oid->hash, oid->hash))\n+\t\tif (oidcmp(parent_oid, oid))\n \t\t\tbreak;\n \t\toid = &item->commit->object.oid;\n \t}\n-- \n2.19.0.rc0.412.g7005db4e88\n\n"},{"id":"356504","messageId":"20180825080543.GB737@sigill.intra.peff.net","threadId":"49212","inReplyTo":"20180825080031.GA32139@sigill.intra.peff.net","subject":"[PATCH 2/9] introduce hasheq() and oideq()","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2018-08-25T08:05:44Z","receivedAt":"2018-08-25T08:05:47Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"The main comparison functions we provide for comparing\nobject ids are hashcmp() and oidcmp(). These are more\nflexible than a strict equality check, since they also\nexpress ordering. That makes them them useful for sorting\nand binary searching. However, it also makes them\npotentially slower than a strict equality check. Consider\nthis C code, which is traditionally what our hashcmp has\nlooked like:\n\n  #include <string.h>\n  int hashcmp(const unsigned char *a, const unsigned char *b)\n  {\n          return memcmp(a, b, 20);\n  }\n\nCompiling with \"gcc -O2 -S -fverbose-asm\", the generated\nassembly shows that we actually call memcmp(). But if we\nchange this to a strict equality check:\n\n          return !memcmp(a, b, 20);\n\nwe get a faster inline version:\n\n          movq    (%rdi), %rax    # MEM[(void *)a_4(D)], MEM[(void *)a_4(D)]\n          movq    8(%rdi), %rdx   # MEM[(void *)a_4(D)], tmp101\n          xorq    (%rsi), %rax    # MEM[(void *)b_5(D)], tmp94\n          xorq    8(%rsi), %rdx   # MEM[(void *)b_5(D)], tmp93\n          orq     %rax, %rdx      # tmp94, tmp93\n          jne     .L2     #,\n          movl    16(%rsi), %eax  # MEM[(void *)b_5(D)], tmp104\n          cmpl    %eax, 16(%rdi)  # tmp104, MEM[(void *)a_4(D)]\n          je      .L5     #,\n\nObviously our hashcmp() doesn't include the \"!\". But because\nit's an inline function, optimizing compilers are able to\nsee \"!hashcmp(a,b)\" in calling code and take advantage of\nthis case. So there has been no value thus far in\nintroducing a more restricted interface for doing strict\nequality checks.\n\nBut as Git learns about more values for the_hash_algo, our\nhashcmp() will grow more complicated and may even delegate\nat runtime to functions optimized specifically for that hash\nsize. That breaks the inline connection we have, and the\ncompiler will have to assume that the caller really cares\nabout the sign and magnitude of the memcmp() result, even\nthough the vast majority don't.\n\nWe can solve that by introducing a hasheq() function (and\nmatching oideq() wrapper), which callers can use to make\nclear that they only care about equality. For now, the\nimplementation will literally be \"!hashcmp()\", but it frees\nus up later to introduce code optimized specifically for the\nequality check.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n cache.h | 10 ++++++++++\n 1 file changed, 10 insertions(+)\n\ndiff --git a/cache.h b/cache.h\nindex 4d014541ab..f6d227fac7 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1041,6 +1041,16 @@ static inline int oidcmp(const struct object_id *oid1, const struct object_id *o\n \treturn hashcmp(oid1->hash, oid2->hash);\n }\n \n+static inline int hasheq(const unsigned char *sha1, const unsigned char *sha2)\n+{\n+\treturn !hashcmp(sha1, sha2);\n+}\n+\n+static inline int oideq(const struct object_id *oid1, const struct object_id *oid2)\n+{\n+\treturn hasheq(oid1->hash, oid2->hash);\n+}\n+\n static inline int is_null_sha1(const unsigned char *sha1)\n {\n \treturn !hashcmp(sha1, null_sha1);\n-- \n2.19.0.rc0.412.g7005db4e88\n\n"},{"id":"356505","messageId":"20180825080715.GC737@sigill.intra.peff.net","threadId":"49212","inReplyTo":"20180825080031.GA32139@sigill.intra.peff.net","subject":"[PATCH 3/9] convert \"oidcmp() == 0\" to oideq()","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2018-08-25T08:07:15Z","receivedAt":"2018-08-25T08:07:30Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"Using the more restrictive oideq() should, in the long run,\ngive the compiler more opportunities to optimize these\ncallsites. For now, this conversion should be a complete\nnoop with respect to the generated code.\n\nThe result is also perhaps a little more readable, as it\navoids the \"zero is equal\" idiom. Since it's so prevalent in\nC, I think seasoned programmers tend not to even notice it\nanymore, but it can sometimes make for awkward double\nnegations (e.g., we can drop a few !!oidcmp() instances\nhere).\n\nThis patch was generated almost entirely by the included\ncoccinelle patch. This mechanical conversion should be\ncompletely safe, because we check explicitly for cases where\noidcmp() is compared to 0, which is what oideq() is doing\nunder the hood. Note that we don't have to catch \"!oidcmp()\"\nseparately; coccinelle's standard isomorphisms make sure the\ntwo are treated equivalently.\n\nI say \"almost\" because I did hand-edit the coccinelle output\nto fix up a few style violations (it mostly keeps the\noriginal formatting, but sometimes unwraps long lines).\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n bisect.c                           |  4 ++--\n blame.c                            |  4 ++--\n builtin/am.c                       |  2 +-\n builtin/checkout.c                 |  2 +-\n builtin/describe.c                 |  4 ++--\n builtin/diff.c                     |  2 +-\n builtin/difftool.c                 |  4 ++--\n builtin/fast-export.c              |  2 +-\n builtin/fetch.c                    |  4 ++--\n builtin/fmt-merge-msg.c            |  2 +-\n builtin/index-pack.c               |  4 ++--\n builtin/log.c                      |  6 +++---\n builtin/merge-tree.c               |  2 +-\n builtin/merge.c                    |  4 ++--\n builtin/pack-objects.c             |  4 ++--\n builtin/pull.c                     |  2 +-\n builtin/receive-pack.c             |  4 ++--\n builtin/remote.c                   |  2 +-\n builtin/replace.c                  |  6 +++---\n builtin/unpack-objects.c           |  2 +-\n builtin/update-index.c             |  4 ++--\n bulk-checkin.c                     |  2 +-\n cache-tree.c                       |  2 +-\n cache.h                            |  4 ++--\n combine-diff.c                     |  4 ++--\n commit-graph.c                     |  2 +-\n connect.c                          |  2 +-\n contrib/coccinelle/object_id.cocci |  6 ++++++\n diff-lib.c                         |  2 +-\n diff.c                             |  6 +++---\n diffcore-break.c                   |  2 +-\n fast-import.c                      |  6 +++---\n http-push.c                        |  2 +-\n log-tree.c                         |  6 +++---\n merge-recursive.c                  |  4 ++--\n notes-merge.c                      | 24 +++++++++++-----------\n notes.c                            |  4 ++--\n pack-write.c                       |  2 +-\n read-cache.c                       |  2 +-\n ref-filter.c                       |  2 +-\n refs/files-backend.c               |  4 ++--\n remote.c                           |  6 +++---\n revision.c                         |  2 +-\n sequencer.c                        | 32 +++++++++++++++---------------\n sha1-array.c                       |  2 +-\n sha1-file.c                        |  4 ++--\n sha1-name.c                        |  2 +-\n submodule.c                        |  2 +-\n transport.c                        |  2 +-\n unpack-trees.c                     |  6 +++---\n wt-status.c                        | 10 +++++-----\n xdiff-interface.c                  |  2 +-\n 52 files changed, 117 insertions(+), 111 deletions(-)\n\ndiff --git a/bisect.c b/bisect.c\nindex e1275ba79e..41c56a665e 100644\n--- a/bisect.c\n+++ b/bisect.c\n@@ -807,7 +807,7 @@ static void check_merge_bases(int rev_nr, struct commit **rev, int no_checkout)\n \n \tfor (; result; result = result->next) {\n \t\tconst struct object_id *mb = &result->item->object.oid;\n-\t\tif (!oidcmp(mb, current_bad_oid)) {\n+\t\tif (oideq(mb, current_bad_oid)) {\n \t\t\thandle_bad_merge_base();\n \t\t} else if (0 <= oid_array_lookup(&good_revs, mb)) {\n \t\t\tcontinue;\n@@ -988,7 +988,7 @@ int bisect_next_all(const char *prefix, int no_checkout)\n \n \tbisect_rev = &revs.commits->item->object.oid;\n \n-\tif (!oidcmp(bisect_rev, current_bad_oid)) {\n+\tif (oideq(bisect_rev, current_bad_oid)) {\n \t\texit_if_skipped_commits(tried, current_bad_oid);\n \t\tprintf(\"%s is the first %s commit\\n\", oid_to_hex(bisect_rev),\n \t\t\tterm_bad);\ndiff --git a/blame.c b/blame.c\nindex 08c0c6cf73..10d72e36dd 100644\n--- a/blame.c\n+++ b/blame.c\n@@ -1459,14 +1459,14 @@ static void pass_blame(struct blame_scoreboard *sb, struct blame_origin *origin,\n \t\t\tporigin = find(p, origin);\n \t\t\tif (!porigin)\n \t\t\t\tcontinue;\n-\t\t\tif (!oidcmp(&porigin->blob_oid, &origin->blob_oid)) {\n+\t\t\tif (oideq(&porigin->blob_oid, &origin->blob_oid)) {\n \t\t\t\tpass_whole_blame(sb, origin, porigin);\n \t\t\t\tblame_origin_decref(porigin);\n \t\t\t\tgoto finish;\n \t\t\t}\n \t\t\tfor (j = same = 0; j < i; j++)\n \t\t\t\tif (sg_origin[j] &&\n-\t\t\t\t    !oidcmp(&sg_origin[j]->blob_oid, &porigin->blob_oid)) {\n+\t\t\t\t    oideq(&sg_origin[j]->blob_oid, &porigin->blob_oid)) {\n \t\t\t\t\tsame = 1;\n \t\t\t\t\tbreak;\n \t\t\t\t}\ndiff --git a/builtin/am.c b/builtin/am.c\nindex 9f7ecf6ecb..e54110d474 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -2077,7 +2077,7 @@ static int safe_to_abort(const struct am_state *state)\n \tif (get_oid(\"HEAD\", &head))\n \t\toidclr(&head);\n \n-\tif (!oidcmp(&head, &abort_safety))\n+\tif (oideq(&head, &abort_safety))\n \t\treturn 1;\n \n \twarning(_(\"You seem to have moved HEAD since the last 'am' failure.\\n\"\ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex 29ef50013d..082e3a9f19 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -96,7 +96,7 @@ static int update_some(const struct object_id *oid, struct strbuf *base,\n \tif (pos >= 0) {\n \t\tstruct cache_entry *old = active_cache[pos];\n \t\tif (ce->ce_mode == old->ce_mode &&\n-\t\t    !oidcmp(&ce->oid, &old->oid)) {\n+\t\t    oideq(&ce->oid, &old->oid)) {\n \t\t\told->ce_flags |= CE_UPDATE;\n \t\t\tdiscard_cache_entry(ce);\n \t\t\treturn 0;\ndiff --git a/builtin/describe.c b/builtin/describe.c\nindex 41606c8a90..1e7c75ba82 100644\n--- a/builtin/describe.c\n+++ b/builtin/describe.c\n@@ -190,7 +190,7 @@ static int get_name(const char *path, const struct object_id *oid, int flag, voi\n \n \t/* Is it annotated? */\n \tif (!peel_ref(path, &peeled)) {\n-\t\tis_annotated = !!oidcmp(oid, &peeled);\n+\t\tis_annotated = !oideq(oid, &peeled);\n \t} else {\n \t\toidcpy(&peeled, oid);\n \t\tis_annotated = 0;\n@@ -469,7 +469,7 @@ static void process_object(struct object *obj, const char *path, void *data)\n {\n \tstruct process_commit_data *pcd = data;\n \n-\tif (!oidcmp(&pcd->looking_for, &obj->oid) && !pcd->dst->len) {\n+\tif (oideq(&pcd->looking_for, &obj->oid) && !pcd->dst->len) {\n \t\treset_revision_walk();\n \t\tdescribe_commit(&pcd->current_commit, pcd->dst);\n \t\tstrbuf_addf(pcd->dst, \":%s\", path);\ndiff --git a/builtin/diff.c b/builtin/diff.c\nindex 361a3c3ed3..b3a8ba488f 100644\n--- a/builtin/diff.c\n+++ b/builtin/diff.c\n@@ -41,7 +41,7 @@ static void stuff_change(struct diff_options *opt,\n \tstruct diff_filespec *one, *two;\n \n \tif (!is_null_oid(old_oid) && !is_null_oid(new_oid) &&\n-\t    !oidcmp(old_oid, new_oid) && (old_mode == new_mode))\n+\t    oideq(old_oid, new_oid) && (old_mode == new_mode))\n \t\treturn;\n \n \tif (opt->flags.reverse_diff) {\ndiff --git a/builtin/difftool.c b/builtin/difftool.c\nindex cdd585ca76..b41a9199ff 100644\n--- a/builtin/difftool.c\n+++ b/builtin/difftool.c\n@@ -116,7 +116,7 @@ static int use_wt_file(const char *workdir, const char *name,\n \t\t\tif (is_null_oid(oid)) {\n \t\t\t\toidcpy(oid, &wt_oid);\n \t\t\t\tuse = 1;\n-\t\t\t} else if (!oidcmp(oid, &wt_oid))\n+\t\t\t} else if (oideq(oid, &wt_oid))\n \t\t\t\tuse = 1;\n \t\t}\n \t}\n@@ -438,7 +438,7 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,\n \t\t\tstrbuf_reset(&buf);\n \t\t\tstrbuf_addf(&buf, \"Subproject commit %s\",\n \t\t\t\t    oid_to_hex(&roid));\n-\t\t\tif (!oidcmp(&loid, &roid))\n+\t\t\tif (oideq(&loid, &roid))\n \t\t\t\tstrbuf_addstr(&buf, \"-dirty\");\n \t\t\tadd_left_or_right(&submodules, dst_path, buf.buf, 1);\n \t\t\tcontinue;\ndiff --git a/builtin/fast-export.c b/builtin/fast-export.c\nindex 9bd8a14b57..74f3bf5c96 100644\n--- a/builtin/fast-export.c\n+++ b/builtin/fast-export.c\n@@ -384,7 +384,7 @@ static void show_filemodify(struct diff_queue_struct *q,\n \t\t\t\tstring_list_insert(changed, spec->path);\n \t\t\t\tputchar('\\n');\n \n-\t\t\t\tif (!oidcmp(&ospec->oid, &spec->oid) &&\n+\t\t\t\tif (oideq(&ospec->oid, &spec->oid) &&\n \t\t\t\t    ospec->mode == spec->mode)\n \t\t\t\t\tbreak;\n \t\t\t}\ndiff --git a/builtin/fetch.c b/builtin/fetch.c\nindex 61bec5d213..32b1d5d383 100644\n--- a/builtin/fetch.c\n+++ b/builtin/fetch.c\n@@ -507,7 +507,7 @@ static void adjust_refcol_width(const struct ref *ref)\n \tint max, rlen, llen, len;\n \n \t/* uptodate lines are only shown on high verbosity level */\n-\tif (!verbosity && !oidcmp(&ref->peer_ref->old_oid, &ref->old_oid))\n+\tif (!verbosity && oideq(&ref->peer_ref->old_oid, &ref->old_oid))\n \t\treturn;\n \n \tmax    = term_columns();\n@@ -644,7 +644,7 @@ static int update_local_ref(struct ref *ref,\n \tif (type < 0)\n \t\tdie(_(\"object %s not found\"), oid_to_hex(&ref->new_oid));\n \n-\tif (!oidcmp(&ref->old_oid, &ref->new_oid)) {\n+\tif (oideq(&ref->old_oid, &ref->new_oid)) {\n \t\tif (verbosity > 0)\n \t\t\tformat_display(display, '=', _(\"[up to date]\"), NULL,\n \t\t\t\t       remote, pretty_ref, summary_width);\ndiff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c\nindex f35ff1612b..4c82c234cb 100644\n--- a/builtin/fmt-merge-msg.c\n+++ b/builtin/fmt-merge-msg.c\n@@ -582,7 +582,7 @@ static void find_merge_parents(struct merge_parents *result,\n \twhile (parents) {\n \t\tstruct commit *cmit = pop_commit(&parents);\n \t\tfor (i = 0; i < result->nr; i++)\n-\t\t\tif (!oidcmp(&result->item[i].commit, &cmit->object.oid))\n+\t\t\tif (oideq(&result->item[i].commit, &cmit->object.oid))\n \t\t\t\tresult->item[i].used = 1;\n \t}\n \ndiff --git a/builtin/index-pack.c b/builtin/index-pack.c\nindex 9582ead950..edcb0a3dca 100644\n--- a/builtin/index-pack.c\n+++ b/builtin/index-pack.c\n@@ -719,9 +719,9 @@ static void find_ref_delta_children(const struct object_id *oid,\n \t\t*last_index = -1;\n \t\treturn;\n \t}\n-\twhile (first > 0 && !oidcmp(&ref_deltas[first - 1].oid, oid))\n+\twhile (first > 0 && oideq(&ref_deltas[first - 1].oid, oid))\n \t\t--first;\n-\twhile (last < end && !oidcmp(&ref_deltas[last + 1].oid, oid))\n+\twhile (last < end && oideq(&ref_deltas[last + 1].oid, oid))\n \t\t++last;\n \t*first_index = first;\n \t*last_index = last;\ndiff --git a/builtin/log.c b/builtin/log.c\nindex e094560d9a..98d668b56f 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -992,7 +992,7 @@ static char *find_branch_name(struct rev_info *rev)\n \ttip_oid = &rev->cmdline.rev[positive].item->oid;\n \tif (dwim_ref(ref, strlen(ref), &branch_oid, &full_ref) &&\n \t    skip_prefix(full_ref, \"refs/heads/\", &v) &&\n-\t    !oidcmp(tip_oid, &branch_oid))\n+\t    oideq(tip_oid, &branch_oid))\n \t\tbranch = xstrdup(v);\n \tfree(full_ref);\n \treturn branch;\n@@ -1703,7 +1703,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t\t/* Don't say anything if head and upstream are the same. */\n \t\tif (rev.pending.nr == 2) {\n \t\t\tstruct object_array_entry *o = rev.pending.objects;\n-\t\t\tif (oidcmp(&o[0].item->oid, &o[1].item->oid) == 0)\n+\t\t\tif (oideq(&o[0].item->oid, &o[1].item->oid))\n \t\t\t\treturn 0;\n \t\t}\n \t\tget_patch_ids(&rev, &ids);\n@@ -1949,7 +1949,7 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)\n \t/* Don't say anything if head and upstream are the same. */\n \tif (revs.pending.nr == 2) {\n \t\tstruct object_array_entry *o = revs.pending.objects;\n-\t\tif (oidcmp(&o[0].item->oid, &o[1].item->oid) == 0)\n+\t\tif (oideq(&o[0].item->oid, &o[1].item->oid))\n \t\t\treturn 0;\n \t}\n \ndiff --git a/builtin/merge-tree.c b/builtin/merge-tree.c\nindex f8023bae1e..8cea8a74f2 100644\n--- a/builtin/merge-tree.c\n+++ b/builtin/merge-tree.c\n@@ -155,7 +155,7 @@ static int same_entry(struct name_entry *a, struct name_entry *b)\n {\n \treturn\ta->oid &&\n \t\tb->oid &&\n-\t\t!oidcmp(a->oid, b->oid) &&\n+\t\toideq(a->oid, b->oid) &&\n \t\ta->mode == b->mode;\n }\n \ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex 8f4a5065c2..57abff999b 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -1189,7 +1189,7 @@ static int merging_a_throwaway_tag(struct commit *commit)\n \ttag_ref = xstrfmt(\"refs/tags/%s\",\n \t\t\t  ((struct tag *)merge_remote_util(commit)->obj)->tag);\n \tif (!read_ref(tag_ref, &oid) &&\n-\t    !oidcmp(&oid, &merge_remote_util(commit)->obj->oid))\n+\t    oideq(&oid, &merge_remote_util(commit)->obj->oid))\n \t\tis_throwaway_tag = 0;\n \telse\n \t\tis_throwaway_tag = 1;\n@@ -1448,7 +1448,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \t\tgoto done;\n \t} else if (fast_forward != FF_NO && !remoteheads->next &&\n \t\t\t!common->next &&\n-\t\t\t!oidcmp(&common->item->object.oid, &head_commit->object.oid)) {\n+\t\t\toideq(&common->item->object.oid, &head_commit->object.oid)) {\n \t\t/* Again the most common case of merging one remote. */\n \t\tstruct strbuf msg = STRBUF_INIT;\n \t\tstruct commit *commit;\ndiff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\nindex d1144a8f7e..64156f676b 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -1202,7 +1202,7 @@ static struct pbase_tree_cache *pbase_tree_get(const struct object_id *oid)\n \t */\n \tfor (neigh = 0; neigh < 8; neigh++) {\n \t\tent = pbase_tree_cache[my_ix];\n-\t\tif (ent && !oidcmp(&ent->oid, oid)) {\n+\t\tif (ent && oideq(&ent->oid, oid)) {\n \t\t\tent->ref++;\n \t\t\treturn ent;\n \t\t}\n@@ -1384,7 +1384,7 @@ static void add_preferred_base(struct object_id *oid)\n \t\treturn;\n \n \tfor (it = pbase_tree; it; it = it->next) {\n-\t\tif (!oidcmp(&it->pcache.oid, &tree_oid)) {\n+\t\tif (oideq(&it->pcache.oid, &tree_oid)) {\n \t\t\tfree(data);\n \t\t\treturn;\n \t\t}\ndiff --git a/builtin/pull.c b/builtin/pull.c\nindex 53bc5facfd..27db0c69eb 100644\n--- a/builtin/pull.c\n+++ b/builtin/pull.c\n@@ -799,7 +799,7 @@ static int run_rebase(const struct object_id *curr_head,\n \tstruct argv_array args = ARGV_ARRAY_INIT;\n \n \tif (!get_octopus_merge_base(&oct_merge_base, curr_head, merge_head, fork_point))\n-\t\tif (!is_null_oid(fork_point) && !oidcmp(&oct_merge_base, fork_point))\n+\t\tif (!is_null_oid(fork_point) && oideq(&oct_merge_base, fork_point))\n \t\t\tfork_point = NULL;\n \n \targv_array_push(&args, \"rebase\");\ndiff --git a/builtin/receive-pack.c b/builtin/receive-pack.c\nindex c17ce94e12..5bb163d4d2 100644\n--- a/builtin/receive-pack.c\n+++ b/builtin/receive-pack.c\n@@ -1222,8 +1222,8 @@ static void check_aliased_update(struct command *cmd, struct string_list *list)\n \n \tdst_cmd = (struct command *) item->util;\n \n-\tif (!oidcmp(&cmd->old_oid, &dst_cmd->old_oid) &&\n-\t    !oidcmp(&cmd->new_oid, &dst_cmd->new_oid))\n+\tif (oideq(&cmd->old_oid, &dst_cmd->old_oid) &&\n+\t    oideq(&cmd->new_oid, &dst_cmd->new_oid))\n \t\treturn;\n \n \tdst_cmd->skip_update = 1;\ndiff --git a/builtin/remote.c b/builtin/remote.c\nindex 07bd51f8eb..54a763cf90 100644\n--- a/builtin/remote.c\n+++ b/builtin/remote.c\n@@ -412,7 +412,7 @@ static int get_push_ref_states(const struct ref *remote_refs,\n \n \t\tif (is_null_oid(&ref->new_oid)) {\n \t\t\tinfo->status = PUSH_STATUS_DELETE;\n-\t\t} else if (!oidcmp(&ref->old_oid, &ref->new_oid))\n+\t\t} else if (oideq(&ref->old_oid, &ref->new_oid))\n \t\t\tinfo->status = PUSH_STATUS_UPTODATE;\n \t\telse if (is_null_oid(&ref->old_oid))\n \t\t\tinfo->status = PUSH_STATUS_CREATE;\ndiff --git a/builtin/replace.c b/builtin/replace.c\nindex 4f05791f3e..8e67e09819 100644\n--- a/builtin/replace.c\n+++ b/builtin/replace.c\n@@ -343,7 +343,7 @@ static int edit_and_replace(const char *object_ref, int force, int raw)\n \t}\n \tfree(tmpfile);\n \n-\tif (!oidcmp(&old_oid, &new_oid))\n+\tif (oideq(&old_oid, &new_oid))\n \t\treturn error(_(\"new object is the same as the old one: '%s'\"), oid_to_hex(&old_oid));\n \n \treturn replace_object_oid(object_ref, &old_oid, \"replacement\", &new_oid, force);\n@@ -414,7 +414,7 @@ static int check_one_mergetag(struct commit *commit,\n \t\tif (get_oid(mergetag_data->argv[i], &oid) < 0)\n \t\t\treturn error(_(\"not a valid object name: '%s'\"),\n \t\t\t\t     mergetag_data->argv[i]);\n-\t\tif (!oidcmp(&tag->tagged->oid, &oid))\n+\t\tif (oideq(&tag->tagged->oid, &oid))\n \t\t\treturn 0; /* found */\n \t}\n \n@@ -474,7 +474,7 @@ static int create_graft(int argc, const char **argv, int force, int gentle)\n \n \tstrbuf_release(&buf);\n \n-\tif (!oidcmp(&old_oid, &new_oid)) {\n+\tif (oideq(&old_oid, &new_oid)) {\n \t\tif (gentle) {\n \t\t\twarning(_(\"graft for '%s' unnecessary\"), oid_to_hex(&old_oid));\n \t\t\treturn 0;\ndiff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c\nindex 30d9413b4b..ad438f5b41 100644\n--- a/builtin/unpack-objects.c\n+++ b/builtin/unpack-objects.c\n@@ -303,7 +303,7 @@ static void added_object(unsigned nr, enum object_type type,\n \tstruct delta_info *info;\n \n \twhile ((info = *p) != NULL) {\n-\t\tif (!oidcmp(&info->base_oid, &obj_list[nr].oid) ||\n+\t\tif (oideq(&info->base_oid, &obj_list[nr].oid) ||\n \t\t    info->base_offset == obj_list[nr].offset) {\n \t\t\t*p = info->next;\n \t\t\tp = &delta_list;\ndiff --git a/builtin/update-index.c b/builtin/update-index.c\nindex fe84003b4f..e7fab78b3b 100644\n--- a/builtin/update-index.c\n+++ b/builtin/update-index.c\n@@ -669,7 +669,7 @@ static int unresolve_one(const char *path)\n \t\tret = -1;\n \t\tgoto free_return;\n \t}\n-\tif (!oidcmp(&ce_2->oid, &ce_3->oid) &&\n+\tif (oideq(&ce_2->oid, &ce_3->oid) &&\n \t    ce_2->ce_mode == ce_3->ce_mode) {\n \t\tfprintf(stderr, \"%s: identical in both, skipping.\\n\",\n \t\t\tpath);\n@@ -754,7 +754,7 @@ static int do_reupdate(int ac, const char **av,\n \t\t\told = read_one_ent(NULL, &head_oid,\n \t\t\t\t\t   ce->name, ce_namelen(ce), 0);\n \t\tif (old && ce->ce_mode == old->ce_mode &&\n-\t\t    !oidcmp(&ce->oid, &old->oid)) {\n+\t\t    oideq(&ce->oid, &old->oid)) {\n \t\t\tdiscard_cache_entry(old);\n \t\t\tcontinue; /* unchanged */\n \t\t}\ndiff --git a/bulk-checkin.c b/bulk-checkin.c\nindex 9f3b644811..409ecb566b 100644\n--- a/bulk-checkin.c\n+++ b/bulk-checkin.c\n@@ -72,7 +72,7 @@ static int already_written(struct bulk_checkin_state *state, struct object_id *o\n \n \t/* Might want to keep the list sorted */\n \tfor (i = 0; i < state->nr_written; i++)\n-\t\tif (!oidcmp(&state->written[i]->oid, oid))\n+\t\tif (oideq(&state->written[i]->oid, oid))\n \t\t\treturn 1;\n \n \t/* This is a new object we need to keep */\ndiff --git a/cache-tree.c b/cache-tree.c\nindex 16ea022c46..b49bb5c5be 100644\n--- a/cache-tree.c\n+++ b/cache-tree.c\n@@ -714,7 +714,7 @@ int cache_tree_matches_traversal(struct cache_tree *root,\n \n \tit = find_cache_tree_from_traversal(root, info);\n \tit = cache_tree_find(it, ent->path);\n-\tif (it && it->entry_count > 0 && !oidcmp(ent->oid, &it->oid))\n+\tif (it && it->entry_count > 0 && oideq(ent->oid, &it->oid))\n \t\treturn it->entry_count;\n \treturn 0;\n }\ndiff --git a/cache.h b/cache.h\nindex f6d227fac7..d090f71706 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1100,7 +1100,7 @@ static inline int is_empty_blob_sha1(const unsigned char *sha1)\n \n static inline int is_empty_blob_oid(const struct object_id *oid)\n {\n-\treturn !oidcmp(oid, the_hash_algo->empty_blob);\n+\treturn oideq(oid, the_hash_algo->empty_blob);\n }\n \n static inline int is_empty_tree_sha1(const unsigned char *sha1)\n@@ -1110,7 +1110,7 @@ static inline int is_empty_tree_sha1(const unsigned char *sha1)\n \n static inline int is_empty_tree_oid(const struct object_id *oid)\n {\n-\treturn !oidcmp(oid, the_hash_algo->empty_tree);\n+\treturn oideq(oid, the_hash_algo->empty_tree);\n }\n \n const char *empty_tree_oid_hex(void);\ndiff --git a/combine-diff.c b/combine-diff.c\nindex de7695e728..0fed4ca529 100644\n--- a/combine-diff.c\n+++ b/combine-diff.c\n@@ -1138,8 +1138,8 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,\n \tfor (i = 0; i < num_parent; i++) {\n \t\tint j;\n \t\tfor (j = 0; j < i; j++) {\n-\t\t\tif (!oidcmp(&elem->parent[i].oid,\n-\t\t\t\t     &elem->parent[j].oid)) {\n+\t\t\tif (oideq(&elem->parent[i].oid,\n+\t\t\t\t  &elem->parent[j].oid)) {\n \t\t\t\treuse_combine_diff(sline, cnt, i, j);\n \t\t\t\tbreak;\n \t\t\t}\ndiff --git a/commit-graph.c b/commit-graph.c\nindex 8a1bec7b8a..050c516b0d 100644\n--- a/commit-graph.c\n+++ b/commit-graph.c\n@@ -779,7 +779,7 @@ void write_commit_graph(const char *obj_dir,\n \tnum_extra_edges = 0;\n \tfor (i = 0; i < oids.nr; i++) {\n \t\tint num_parents = 0;\n-\t\tif (i > 0 && !oidcmp(&oids.list[i-1], &oids.list[i]))\n+\t\tif (i > 0 && oideq(&oids.list[i - 1], &oids.list[i]))\n \t\t\tcontinue;\n \n \t\tcommits.list[commits.nr] = lookup_commit(the_repository, &oids.list[i]);\ndiff --git a/connect.c b/connect.c\nindex 94547e5056..24281b6082 100644\n--- a/connect.c\n+++ b/connect.c\n@@ -224,7 +224,7 @@ static int process_dummy_ref(const char *line)\n \t\treturn 0;\n \tname++;\n \n-\treturn !oidcmp(&null_oid, &oid) && !strcmp(name, \"capabilities^{}\");\n+\treturn oideq(&null_oid, &oid) && !strcmp(name, \"capabilities^{}\");\n }\n \n static void check_no_capabilities(const char *line, int len)\ndiff --git a/contrib/coccinelle/object_id.cocci b/contrib/coccinelle/object_id.cocci\nindex 5869979be7..548c02336d 100644\n--- a/contrib/coccinelle/object_id.cocci\n+++ b/contrib/coccinelle/object_id.cocci\n@@ -108,3 +108,9 @@ expression E1, E2;\n @@\n - hashcpy(E1.hash, E2->hash)\n + oidcpy(&E1, E2)\n+\n+@@\n+expression E1, E2;\n+@@\n+- oidcmp(E1, E2) == 0\n++ oideq(E1, E2)\ndiff --git a/diff-lib.c b/diff-lib.c\nindex 88a98b1c06..c1f5a52654 100644\n--- a/diff-lib.c\n+++ b/diff-lib.c\n@@ -366,7 +366,7 @@ static int show_modified(struct rev_info *revs,\n \t}\n \n \toldmode = old_entry->ce_mode;\n-\tif (mode == oldmode && !oidcmp(oid, &old_entry->oid) && !dirty_submodule &&\n+\tif (mode == oldmode && oideq(oid, &old_entry->oid) && !dirty_submodule &&\n \t    !revs->diffopt.flags.find_copies_harder)\n \t\treturn 0;\n \ndiff --git a/diff.c b/diff.c\nindex 145cfbae59..5cada68267 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -3404,7 +3404,7 @@ static void builtin_diff(const char *name_a,\n \t\tif (!one->data && !two->data &&\n \t\t    S_ISREG(one->mode) && S_ISREG(two->mode) &&\n \t\t    !o->flags.binary) {\n-\t\t\tif (!oidcmp(&one->oid, &two->oid)) {\n+\t\t\tif (oideq(&one->oid, &two->oid)) {\n \t\t\t\tif (must_show_header)\n \t\t\t\t\temit_diff_symbol(o, DIFF_SYMBOL_HEADER,\n \t\t\t\t\t\t\t header.buf, header.len,\n@@ -3569,7 +3569,7 @@ static void builtin_diffstat(const char *name_a, const char *name_b,\n \t\treturn;\n \t}\n \n-\tsame_contents = !oidcmp(&one->oid, &two->oid);\n+\tsame_contents = oideq(&one->oid, &two->oid);\n \n \tif (diff_filespec_is_binary(one) || diff_filespec_is_binary(two)) {\n \t\tdata->is_binary = 1;\n@@ -5323,7 +5323,7 @@ int diff_unmodified_pair(struct diff_filepair *p)\n \t * dealing with a change.\n \t */\n \tif (one->oid_valid && two->oid_valid &&\n-\t    !oidcmp(&one->oid, &two->oid) &&\n+\t    oideq(&one->oid, &two->oid) &&\n \t    !one->dirty_submodule && !two->dirty_submodule)\n \t\treturn 1; /* no change */\n \tif (!one->oid_valid && !two->oid_valid)\ndiff --git a/diffcore-break.c b/diffcore-break.c\nindex c64359f489..e11fcfdb39 100644\n--- a/diffcore-break.c\n+++ b/diffcore-break.c\n@@ -58,7 +58,7 @@ static int should_break(struct diff_filespec *src,\n \t}\n \n \tif (src->oid_valid && dst->oid_valid &&\n-\t    !oidcmp(&src->oid, &dst->oid))\n+\t    oideq(&src->oid, &dst->oid))\n \t\treturn 0; /* they are the same */\n \n \tif (diff_populate_filespec(src, 0) || diff_populate_filespec(dst, 0))\ndiff --git a/fast-import.c b/fast-import.c\nindex 89bb0c9db3..a731088f96 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -572,7 +572,7 @@ static struct object_entry *find_object(struct object_id *oid)\n \tunsigned int h = oid->hash[0] << 8 | oid->hash[1];\n \tstruct object_entry *e;\n \tfor (e = object_table[h]; e; e = e->next)\n-\t\tif (!oidcmp(oid, &e->idx.oid))\n+\t\tif (oideq(oid, &e->idx.oid))\n \t\t\treturn e;\n \treturn NULL;\n }\n@@ -583,7 +583,7 @@ static struct object_entry *insert_object(struct object_id *oid)\n \tstruct object_entry *e = object_table[h];\n \n \twhile (e) {\n-\t\tif (!oidcmp(oid, &e->idx.oid))\n+\t\tif (oideq(oid, &e->idx.oid))\n \t\t\treturn e;\n \t\te = e->next;\n \t}\n@@ -1533,7 +1533,7 @@ static int tree_content_set(\n \t\t\tif (!*slash1) {\n \t\t\t\tif (!S_ISDIR(mode)\n \t\t\t\t\t\t&& e->versions[1].mode == mode\n-\t\t\t\t\t\t&& !oidcmp(&e->versions[1].oid, oid))\n+\t\t\t\t\t\t&& oideq(&e->versions[1].oid, oid))\n \t\t\t\t\treturn 0;\n \t\t\t\te->versions[1].mode = mode;\n \t\t\t\toidcpy(&e->versions[1].oid, oid);\ndiff --git a/http-push.c b/http-push.c\nindex 5eaf551b51..283495c18a 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -1859,7 +1859,7 @@ int cmd_main(int argc, const char **argv)\n \t\t\tcontinue;\n \t\t}\n \n-\t\tif (!oidcmp(&ref->old_oid, &ref->peer_ref->new_oid)) {\n+\t\tif (oideq(&ref->old_oid, &ref->peer_ref->new_oid)) {\n \t\t\tif (push_verbosely)\n \t\t\t\tfprintf(stderr, \"'%s': up-to-date\\n\", ref->name);\n \t\t\tif (helper_status)\ndiff --git a/log-tree.c b/log-tree.c\nindex 7443e5fcc7..2edff78cff 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -472,7 +472,7 @@ static int which_parent(const struct object_id *oid, const struct commit *commit\n \tconst struct commit_list *parent;\n \n \tfor (nth = 0, parent = commit->parents; parent; parent = parent->next) {\n-\t\tif (!oidcmp(&parent->item->object.oid, oid))\n+\t\tif (oideq(&parent->item->object.oid, oid))\n \t\t\treturn nth;\n \t\tnth++;\n \t}\n@@ -506,8 +506,8 @@ static int show_one_mergetag(struct commit *commit,\n \tif (parse_tag_buffer(the_repository, tag, extra->value, extra->len))\n \t\tstrbuf_addstr(&verify_message, \"malformed mergetag\\n\");\n \telse if (is_common_merge(commit) &&\n-\t\t !oidcmp(&tag->tagged->oid,\n-\t\t\t  &commit->parents->next->item->object.oid))\n+\t\t oideq(&tag->tagged->oid,\n+\t\t       &commit->parents->next->item->object.oid))\n \t\tstrbuf_addf(&verify_message,\n \t\t\t    \"merged tag '%s'\\n\", tag->tag);\n \telse if ((nth = which_parent(&tag->tagged->oid, commit)) < 0)\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex dcdc93019c..2904cb825e 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -156,7 +156,7 @@ static struct tree *shift_tree_object(struct tree *one, struct tree *two,\n \t\tshift_tree_by(&one->object.oid, &two->object.oid, &shifted,\n \t\t\t      subtree_shift);\n \t}\n-\tif (!oidcmp(&two->object.oid, &shifted))\n+\tif (oideq(&two->object.oid, &shifted))\n \t\treturn two;\n \treturn lookup_tree(the_repository, &shifted);\n }\n@@ -179,7 +179,7 @@ static int oid_eq(const struct object_id *a, const struct object_id *b)\n {\n \tif (!a && !b)\n \t\treturn 2;\n-\treturn a && b && oidcmp(a, b) == 0;\n+\treturn a && b && oideq(a, b);\n }\n \n enum rename_type {\ndiff --git a/notes-merge.c b/notes-merge.c\nindex 76ab19e702..0a47e54cf8 100644\n--- a/notes-merge.c\n+++ b/notes-merge.c\n@@ -151,7 +151,7 @@ static struct notes_merge_pair *diff_tree_remote(struct notes_merge_options *o,\n \t\tmp = find_notes_merge_pair_pos(changes, len, &obj, 1, &occupied);\n \t\tif (occupied) {\n \t\t\t/* We've found an addition/deletion pair */\n-\t\t\tassert(!oidcmp(&mp->obj, &obj));\n+\t\t\tassert(oideq(&mp->obj, &obj));\n \t\t\tif (is_null_oid(&p->one->oid)) { /* addition */\n \t\t\t\tassert(is_null_oid(&mp->remote));\n \t\t\t\toidcpy(&mp->remote, &p->two->oid);\n@@ -218,7 +218,7 @@ static void diff_tree_local(struct notes_merge_options *o,\n \t\t\tcontinue;\n \t\t}\n \n-\t\tassert(!oidcmp(&mp->obj, &obj));\n+\t\tassert(oideq(&mp->obj, &obj));\n \t\tif (is_null_oid(&p->two->oid)) { /* deletion */\n \t\t\t/*\n \t\t\t * Either this is a true deletion (1), or it is part\n@@ -229,7 +229,7 @@ static void diff_tree_local(struct notes_merge_options *o,\n \t\t\t * (3) mp->local is uninitialized; set it to null_sha1\n \t\t\t *     (will be overwritten by following addition)\n \t\t\t */\n-\t\t\tif (!oidcmp(&mp->local, &uninitialized))\n+\t\t\tif (oideq(&mp->local, &uninitialized))\n \t\t\t\toidclr(&mp->local);\n \t\t} else if (is_null_oid(&p->one->oid)) { /* addition */\n \t\t\t/*\n@@ -241,7 +241,7 @@ static void diff_tree_local(struct notes_merge_options *o,\n \t\t\t * (3) mp->local is null_sha1;     set to p->two->sha1\n \t\t\t */\n \t\t\tassert(is_null_oid(&mp->local) ||\n-\t\t\t       !oidcmp(&mp->local, &uninitialized));\n+\t\t\t       oideq(&mp->local, &uninitialized));\n \t\t\toidcpy(&mp->local, &p->two->oid);\n \t\t} else { /* modification */\n \t\t\t/*\n@@ -249,8 +249,8 @@ static void diff_tree_local(struct notes_merge_options *o,\n \t\t\t * match mp->base, and mp->local shall be uninitialized.\n \t\t\t * Set mp->local to p->two->sha1.\n \t\t\t */\n-\t\t\tassert(!oidcmp(&p->one->oid, &mp->base));\n-\t\t\tassert(!oidcmp(&mp->local, &uninitialized));\n+\t\t\tassert(oideq(&p->one->oid, &mp->base));\n+\t\t\tassert(oideq(&mp->local, &uninitialized));\n \t\t\toidcpy(&mp->local, &p->two->oid);\n \t\t}\n \t\ttrace_printf(\"\\t\\tStored local change for %s: %.7s -> %.7s\\n\",\n@@ -480,14 +480,14 @@ static int merge_changes(struct notes_merge_options *o,\n \t\t       oid_to_hex(&p->local),\n \t\t       oid_to_hex(&p->remote));\n \n-\t\tif (!oidcmp(&p->base, &p->remote)) {\n+\t\tif (oideq(&p->base, &p->remote)) {\n \t\t\t/* no remote change; nothing to do */\n \t\t\ttrace_printf(\"\\t\\t\\tskipping (no remote change)\\n\");\n-\t\t} else if (!oidcmp(&p->local, &p->remote)) {\n+\t\t} else if (oideq(&p->local, &p->remote)) {\n \t\t\t/* same change in local and remote; nothing to do */\n \t\t\ttrace_printf(\"\\t\\t\\tskipping (local == remote)\\n\");\n-\t\t} else if (!oidcmp(&p->local, &uninitialized) ||\n-\t\t\t   !oidcmp(&p->local, &p->base)) {\n+\t\t} else if (oideq(&p->local, &uninitialized) ||\n+\t\t\t   oideq(&p->local, &p->base)) {\n \t\t\t/* no local change; adopt remote change */\n \t\t\ttrace_printf(\"\\t\\t\\tno local change, adopted remote\\n\");\n \t\t\tif (add_note(t, &p->obj, &p->remote,\n@@ -621,14 +621,14 @@ int notes_merge(struct notes_merge_options *o,\n \t\t\toid_to_hex(&local->object.oid),\n \t\t\toid_to_hex(base_oid));\n \n-\tif (!oidcmp(&remote->object.oid, base_oid)) {\n+\tif (oideq(&remote->object.oid, base_oid)) {\n \t\t/* Already merged; result == local commit */\n \t\tif (o->verbosity >= 2)\n \t\t\tprintf(\"Already up to date!\\n\");\n \t\toidcpy(result_oid, &local->object.oid);\n \t\tgoto found_result;\n \t}\n-\tif (!oidcmp(&local->object.oid, base_oid)) {\n+\tif (oideq(&local->object.oid, base_oid)) {\n \t\t/* Fast-forward; result == remote commit */\n \t\tif (o->verbosity >= 2)\n \t\t\tprintf(\"Fast-forward\\n\");\ndiff --git a/notes.c b/notes.c\nindex 32d3dbcc1e..b3386d6c36 100644\n--- a/notes.c\n+++ b/notes.c\n@@ -266,9 +266,9 @@ static int note_tree_insert(struct notes_tree *t, struct int_node *tree,\n \tcase PTR_TYPE_NOTE:\n \t\tswitch (type) {\n \t\tcase PTR_TYPE_NOTE:\n-\t\t\tif (!oidcmp(&l->key_oid, &entry->key_oid)) {\n+\t\t\tif (oideq(&l->key_oid, &entry->key_oid)) {\n \t\t\t\t/* skip concatenation if l == entry */\n-\t\t\t\tif (!oidcmp(&l->val_oid, &entry->val_oid))\n+\t\t\t\tif (oideq(&l->val_oid, &entry->val_oid))\n \t\t\t\t\treturn 0;\n \n \t\t\t\tret = combine_notes(&l->val_oid,\ndiff --git a/pack-write.c b/pack-write.c\nindex a9d46bc03f..7d14716c40 100644\n--- a/pack-write.c\n+++ b/pack-write.c\n@@ -124,7 +124,7 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec\n \t\t}\n \t\thashwrite(f, obj->oid.hash, the_hash_algo->rawsz);\n \t\tif ((opts->flags & WRITE_IDX_STRICT) &&\n-\t\t    (i && !oidcmp(&list[-2]->oid, &obj->oid)))\n+\t\t    (i && oideq(&list[-2]->oid, &obj->oid)))\n \t\t\tdie(\"The same object %s appears twice in the pack\",\n \t\t\t    oid_to_hex(&obj->oid));\n \t}\ndiff --git a/read-cache.c b/read-cache.c\nindex 7b1354d759..eb4919e77f 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -767,7 +767,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,\n \t/* It was suspected to be racily clean, but it turns out to be Ok */\n \twas_same = (alias &&\n \t\t    !ce_stage(alias) &&\n-\t\t    !oidcmp(&alias->oid, &ce->oid) &&\n+\t\t    oideq(&alias->oid, &ce->oid) &&\n \t\t    ce->ce_mode == alias->ce_mode);\n \n \tif (pretend)\ndiff --git a/ref-filter.c b/ref-filter.c\nindex 0bccfceff2..ccca317ce1 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -1710,7 +1710,7 @@ struct contains_stack {\n static int in_commit_list(const struct commit_list *want, struct commit *c)\n {\n \tfor (; want; want = want->next)\n-\t\tif (!oidcmp(&want->item->object.oid, &c->object.oid))\n+\t\tif (oideq(&want->item->object.oid, &c->object.oid))\n \t\t\treturn 1;\n \treturn 0;\n }\ndiff --git a/refs/files-backend.c b/refs/files-backend.c\nindex 1f1a98e4cb..aa45f5317f 100644\n--- a/refs/files-backend.c\n+++ b/refs/files-backend.c\n@@ -2307,7 +2307,7 @@ static int check_old_oid(struct ref_update *update, struct object_id *oid,\n \t\t\t struct strbuf *err)\n {\n \tif (!(update->flags & REF_HAVE_OLD) ||\n-\t\t   !oidcmp(oid, &update->old_oid))\n+\t\t   oideq(oid, &update->old_oid))\n \t\treturn 0;\n \n \tif (is_null_oid(&update->old_oid))\n@@ -2443,7 +2443,7 @@ static int lock_ref_for_update(struct files_ref_store *refs,\n \t    !(update->flags & REF_DELETING) &&\n \t    !(update->flags & REF_LOG_ONLY)) {\n \t\tif (!(update->type & REF_ISSYMREF) &&\n-\t\t    !oidcmp(&lock->old_oid, &update->new_oid)) {\n+\t\t    oideq(&lock->old_oid, &update->new_oid)) {\n \t\t\t/*\n \t\t\t * The reference already has the desired\n \t\t\t * value, so we don't need to write it.\ndiff --git a/remote.c b/remote.c\nindex 7f6277a145..6f1ee9d640 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -1388,7 +1388,7 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,\n \n \t\tref->deletion = is_null_oid(&ref->new_oid);\n \t\tif (!ref->deletion &&\n-\t\t\t!oidcmp(&ref->old_oid, &ref->new_oid)) {\n+\t\t\toideq(&ref->old_oid, &ref->new_oid)) {\n \t\t\tref->status = REF_STATUS_UPTODATE;\n \t\t\tcontinue;\n \t\t}\n@@ -2049,7 +2049,7 @@ struct ref *guess_remote_head(const struct ref *head,\n \t/* If refs/heads/master could be right, it is. */\n \tif (!all) {\n \t\tr = find_ref_by_name(refs, \"refs/heads/master\");\n-\t\tif (r && !oidcmp(&r->old_oid, &head->old_oid))\n+\t\tif (r && oideq(&r->old_oid, &head->old_oid))\n \t\t\treturn copy_ref(r);\n \t}\n \n@@ -2057,7 +2057,7 @@ struct ref *guess_remote_head(const struct ref *head,\n \tfor (r = refs; r; r = r->next) {\n \t\tif (r != head &&\n \t\t    starts_with(r->name, \"refs/heads/\") &&\n-\t\t    !oidcmp(&r->old_oid, &head->old_oid)) {\n+\t\t    oideq(&r->old_oid, &head->old_oid)) {\n \t\t\t*tail = copy_ref(r);\n \t\t\ttail = &((*tail)->next);\n \t\t\tif (!all)\ndiff --git a/revision.c b/revision.c\nindex de4dce600d..a2a569bb3b 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -3238,7 +3238,7 @@ static void track_linear(struct rev_info *revs, struct commit *commit)\n \t\tstruct commit_list *p;\n \t\tfor (p = revs->previous_parents; p; p = p->next)\n \t\t\tif (p->item == NULL || /* first commit */\n-\t\t\t    !oidcmp(&p->item->object.oid, &commit->object.oid))\n+\t\t\t    oideq(&p->item->object.oid, &commit->object.oid))\n \t\t\t\tbreak;\n \t\trevs->linear = p != NULL;\n \t}\ndiff --git a/sequencer.c b/sequencer.c\nindex 6a11f49651..66ed7c7b28 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -610,7 +610,7 @@ static int is_index_unchanged(void)\n \tif (!(cache_tree_oid = get_cache_tree_oid()))\n \t\treturn -1;\n \n-\treturn !oidcmp(cache_tree_oid, get_commit_tree_oid(head_commit));\n+\treturn oideq(cache_tree_oid, get_commit_tree_oid(head_commit));\n }\n \n static int write_author_script(const char *message)\n@@ -1258,9 +1258,9 @@ static int try_to_commit(struct strbuf *msg, const char *author,\n \t\tgoto out;\n \t}\n \n-\tif (!(flags & ALLOW_EMPTY) && !oidcmp(current_head ?\n-\t\t\t\t\t      get_commit_tree_oid(current_head) :\n-\t\t\t\t\t      the_hash_algo->empty_tree, &tree)) {\n+\tif (!(flags & ALLOW_EMPTY) && oideq(current_head ?\n+\t\t\t\t\t    get_commit_tree_oid(current_head) :\n+\t\t\t\t\t    the_hash_algo->empty_tree, &tree)) {\n \t\tres = 1; /* run 'git commit' to display error message */\n \t\tgoto out;\n \t}\n@@ -1365,7 +1365,7 @@ static int is_original_commit_empty(struct commit *commit)\n \t\tptree_oid = the_hash_algo->empty_tree; /* commit is root */\n \t}\n \n-\treturn !oidcmp(ptree_oid, get_commit_tree_oid(commit));\n+\treturn oideq(ptree_oid, get_commit_tree_oid(commit));\n }\n \n /*\n@@ -1645,7 +1645,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,\n \t\tunborn = get_oid(\"HEAD\", &head);\n \t\t/* Do we want to generate a root commit? */\n \t\tif (is_pick_or_similar(command) && opts->have_squash_onto &&\n-\t\t    !oidcmp(&head, &opts->squash_onto)) {\n+\t\t    oideq(&head, &opts->squash_onto)) {\n \t\t\tif (is_fixup(command))\n \t\t\t\treturn error(_(\"cannot fixup root commit\"));\n \t\t\tflags |= CREATE_ROOT_COMMIT;\n@@ -1688,7 +1688,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,\n \t\t\toid_to_hex(&commit->object.oid));\n \n \tif (opts->allow_ff && !is_fixup(command) &&\n-\t    ((parent && !oidcmp(&parent->object.oid, &head)) ||\n+\t    ((parent && oideq(&parent->object.oid, &head)) ||\n \t     (!parent && unborn))) {\n \t\tif (is_rebase_i(opts))\n \t\t\twrite_author_script(msg.message);\n@@ -2393,7 +2393,7 @@ static int rollback_is_safe(void)\n \tif (get_oid(\"HEAD\", &actual_head))\n \t\toidclr(&actual_head);\n \n-\treturn !oidcmp(&actual_head, &expected_head);\n+\treturn oideq(&actual_head, &expected_head);\n }\n \n static int reset_for_rollback(const struct object_id *oid)\n@@ -2954,7 +2954,7 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,\n \t}\n \n \tif (opts->have_squash_onto &&\n-\t    !oidcmp(&head_commit->object.oid, &opts->squash_onto)) {\n+\t    oideq(&head_commit->object.oid, &opts->squash_onto)) {\n \t\t/*\n \t\t * When the user tells us to \"merge\" something into a\n \t\t * \"[new root]\", let's simply fast-forward to the merge head.\n@@ -3023,8 +3023,8 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,\n \t * commit, we cannot fast-forward.\n \t */\n \tcan_fast_forward = opts->allow_ff && commit && commit->parents &&\n-\t\t!oidcmp(&commit->parents->item->object.oid,\n-\t\t\t&head_commit->object.oid);\n+\t\toideq(&commit->parents->item->object.oid,\n+\t\t      &head_commit->object.oid);\n \n \t/*\n \t * If any merge head is different from the original one, we cannot\n@@ -3102,8 +3102,8 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,\n \twrite_message(\"no-ff\", 5, git_path_merge_mode(the_repository), 0);\n \n \tbases = get_merge_bases(head_commit, merge_commit);\n-\tif (bases && !oidcmp(&merge_commit->object.oid,\n-\t\t\t     &bases->item->object.oid)) {\n+\tif (bases && oideq(&merge_commit->object.oid,\n+\t\t\t   &bases->item->object.oid)) {\n \t\tret = 0;\n \t\t/* skip merging an ancestor of HEAD */\n \t\tgoto leave_merge;\n@@ -3349,9 +3349,9 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)\n \t\t\t\t */\n \t\t\t\tif (item->command == TODO_REWORD &&\n \t\t\t\t    !get_oid(\"HEAD\", &oid) &&\n-\t\t\t\t    (!oidcmp(&item->commit->object.oid, &oid) ||\n+\t\t\t\t    (oideq(&item->commit->object.oid, &oid) ||\n \t\t\t\t     (opts->have_squash_onto &&\n-\t\t\t\t      !oidcmp(&opts->squash_onto, &oid))))\n+\t\t\t\t      oideq(&opts->squash_onto, &oid))))\n \t\t\t\t\tto_amend = 1;\n \n \t\t\t\treturn res | error_with_patch(item->commit,\n@@ -3578,7 +3578,7 @@ static int commit_staged_changes(struct replay_opts *opts,\n \t\t * the commit message and if there was a squash, let the user\n \t\t * edit it.\n \t\t */\n-\t\tif (is_clean && !oidcmp(&head, &to_amend) &&\n+\t\tif (is_clean && oideq(&head, &to_amend) &&\n \t\t    opts->current_fixup_count > 0 &&\n \t\t    file_exists(rebase_path_stopped_sha())) {\n \t\t\tconst char *p = opts->current_fixups.buf;\ndiff --git a/sha1-array.c b/sha1-array.c\nindex 265941fbf4..b94e0ec0f5 100644\n--- a/sha1-array.c\n+++ b/sha1-array.c\n@@ -69,7 +69,7 @@ int oid_array_for_each_unique(struct oid_array *array,\n \n \tfor (i = 0; i < array->nr; i++) {\n \t\tint ret;\n-\t\tif (i > 0 && !oidcmp(array->oid + i, array->oid + i - 1))\n+\t\tif (i > 0 && oideq(array->oid + i, array->oid + i - 1))\n \t\t\tcontinue;\n \t\tret = fn(array->oid + i, data);\n \t\tif (ret)\ndiff --git a/sha1-file.c b/sha1-file.c\nindex 97b7423848..71f49ee56d 100644\n--- a/sha1-file.c\n+++ b/sha1-file.c\n@@ -149,10 +149,10 @@ static struct cached_object *find_cached_object(const struct object_id *oid)\n \tstruct cached_object *co = cached_objects;\n \n \tfor (i = 0; i < cached_object_nr; i++, co++) {\n-\t\tif (!oidcmp(&co->oid, oid))\n+\t\tif (oideq(&co->oid, oid))\n \t\t\treturn co;\n \t}\n-\tif (!oidcmp(oid, the_hash_algo->empty_tree))\n+\tif (oideq(oid, the_hash_algo->empty_tree))\n \t\treturn &empty_tree;\n \treturn NULL;\n }\ndiff --git a/sha1-name.c b/sha1-name.c\nindex c9cc1318b7..a0c8451d55 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -44,7 +44,7 @@ static void update_candidates(struct disambiguate_state *ds, const struct object\n \t\toidcpy(&ds->candidate, current);\n \t\tds->candidate_exists = 1;\n \t\treturn;\n-\t} else if (!oidcmp(&ds->candidate, current)) {\n+\t} else if (oideq(&ds->candidate, current)) {\n \t\t/* the same as what we already have seen */\n \t\treturn;\n \t}\ndiff --git a/submodule.c b/submodule.c\nindex 50cbf5f13e..a2ce58e9e7 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -536,7 +536,7 @@ static void show_submodule_header(struct diff_options *o, const char *path,\n \t\t\tfast_backward = 1;\n \t}\n \n-\tif (!oidcmp(one, two)) {\n+\tif (oideq(one, two)) {\n \t\tstrbuf_release(&sb);\n \t\treturn;\n \t}\ndiff --git a/transport.c b/transport.c\nindex 06ffea2774..1c76d64aba 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -1228,7 +1228,7 @@ int transport_fetch_refs(struct transport *transport, struct ref *refs)\n \t\tnr_refs++;\n \t\tif (rm->peer_ref &&\n \t\t    !is_null_oid(&rm->old_oid) &&\n-\t\t    !oidcmp(&rm->peer_ref->old_oid, &rm->old_oid))\n+\t\t    oideq(&rm->peer_ref->old_oid, &rm->old_oid))\n \t\t\tcontinue;\n \t\tALLOC_GROW(heads, nr_heads + 1, nr_alloc);\n \t\theads[nr_heads++] = rm;\ndiff --git a/unpack-trees.c b/unpack-trees.c\nindex f25089b878..4056a92d55 100644\n--- a/unpack-trees.c\n+++ b/unpack-trees.c\n@@ -630,7 +630,7 @@ static int switch_cache_bottom(struct traverse_info *info)\n \n static inline int are_same_oid(struct name_entry *name_j, struct name_entry *name_k)\n {\n-\treturn name_j->oid && name_k->oid && !oidcmp(name_j->oid, name_k->oid);\n+\treturn name_j->oid && name_k->oid && oideq(name_j->oid, name_k->oid);\n }\n \n static int traverse_trees_recursive(int n, unsigned long dirmask,\n@@ -1484,7 +1484,7 @@ static int same(const struct cache_entry *a, const struct cache_entry *b)\n \tif ((a->ce_flags | b->ce_flags) & CE_CONFLICTED)\n \t\treturn 0;\n \treturn a->ce_mode == b->ce_mode &&\n-\t       !oidcmp(&a->oid, &b->oid);\n+\t       oideq(&a->oid, &b->oid);\n }\n \n \n@@ -1616,7 +1616,7 @@ static int verify_clean_subdirectory(const struct cache_entry *ce,\n \t\t * If we are not going to update the submodule, then\n \t\t * we don't care.\n \t\t */\n-\t\tif (!sub_head && !oidcmp(&oid, &ce->oid))\n+\t\tif (!sub_head && oideq(&oid, &ce->oid))\n \t\t\treturn 0;\n \t\treturn verify_clean_submodule(sub_head ? NULL : oid_to_hex(&oid),\n \t\t\t\t\t      ce, error_type, o);\ndiff --git a/wt-status.c b/wt-status.c\nindex 5ffab61015..1c8746d0ea 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -453,8 +453,8 @@ static void wt_status_collect_changed_cb(struct diff_queue_struct *q,\n \t\t\td->worktree_status = p->status;\n \t\tif (S_ISGITLINK(p->two->mode)) {\n \t\t\td->dirty_submodule = p->two->dirty_submodule;\n-\t\t\td->new_submodule_commits = !!oidcmp(&p->one->oid,\n-\t\t\t\t\t\t\t    &p->two->oid);\n+\t\t\td->new_submodule_commits = !oideq(&p->one->oid,\n+\t\t\t\t\t\t\t  &p->two->oid);\n \t\t\tif (s->status_format == STATUS_FORMAT_SHORT)\n \t\t\t\td->worktree_status = short_submodule_status(d);\n \t\t}\n@@ -1487,10 +1487,10 @@ static void wt_status_get_detached_from(struct wt_status_state *state)\n \n \tif (dwim_ref(cb.buf.buf, cb.buf.len, &oid, &ref) == 1 &&\n \t    /* sha1 is a commit? match without further lookup */\n-\t    (!oidcmp(&cb.noid, &oid) ||\n+\t    (oideq(&cb.noid, &oid) ||\n \t     /* perhaps sha1 is a tag, try to dereference to a commit */\n \t     ((commit = lookup_commit_reference_gently(the_repository, &oid, 1)) != NULL &&\n-\t      !oidcmp(&cb.noid, &commit->object.oid)))) {\n+\t      oideq(&cb.noid, &commit->object.oid)))) {\n \t\tconst char *from = ref;\n \t\tif (!skip_prefix(from, \"refs/tags/\", &from))\n \t\t\tskip_prefix(from, \"refs/remotes/\", &from);\n@@ -1500,7 +1500,7 @@ static void wt_status_get_detached_from(struct wt_status_state *state)\n \t\t\txstrdup(find_unique_abbrev(&cb.noid, DEFAULT_ABBREV));\n \toidcpy(&state->detached_oid, &cb.noid);\n \tstate->detached_at = !get_oid(\"HEAD\", &oid) &&\n-\t\t\t     !oidcmp(&oid, &state->detached_oid);\n+\t\t\t     oideq(&oid, &state->detached_oid);\n \n \tfree(ref);\n \tstrbuf_release(&cb.buf);\ndiff --git a/xdiff-interface.c b/xdiff-interface.c\nindex ec6e574e4a..e7af95db86 100644\n--- a/xdiff-interface.c\n+++ b/xdiff-interface.c\n@@ -186,7 +186,7 @@ void read_mmblob(mmfile_t *ptr, const struct object_id *oid)\n \tunsigned long size;\n \tenum object_type type;\n \n-\tif (!oidcmp(oid, &null_oid)) {\n+\tif (oideq(oid, &null_oid)) {\n \t\tptr->ptr = xstrdup(\"\");\n \t\tptr->size = 0;\n \t\treturn;\n-- \n2.19.0.rc0.412.g7005db4e88\n\n"},{"id":"356506","messageId":"20180825080814.GD737@sigill.intra.peff.net","threadId":"49212","inReplyTo":"20180825080031.GA32139@sigill.intra.peff.net","subject":"[PATCH 4/9] convert \"hashcmp() == 0\" to hasheq()","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2018-08-25T08:08:15Z","receivedAt":"2018-08-25T08:08:19Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"This is the partner patch to the previous one, but covering\nthe \"hash\" variants instead of \"oid\".  Note that our\ncoccinelle rule is slightly more complex to avoid triggering\nthe call in hasheq().\n\nI didn't bother to add a new rule to convert:\n\n  - hasheq(E1->hash, E2->hash)\n  + oideq(E1, E2)\n\nSince these are new functions, there won't be any such\nexisting callers. And since most of the code is already\nusing oideq, we're not likely to introduce new ones.\n\nWe might still see \"!hashcmp(E1->hash, E2->hash)\" from topics\nin flight. But because our new rule comes after the existing\nones, that should first get converted to \"!oidcmp(E1, E2)\"\nand then to \"oideq(E1, E2)\".\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n builtin/fetch.c                    |  2 +-\n cache.h                            |  8 ++++----\n contrib/coccinelle/object_id.cocci |  9 +++++++++\n http-walker.c                      |  2 +-\n notes.c                            |  2 +-\n object.c                           |  2 +-\n pack-objects.c                     |  2 +-\n packfile.c                         | 10 +++++-----\n 8 files changed, 23 insertions(+), 14 deletions(-)\n\ndiff --git a/builtin/fetch.c b/builtin/fetch.c\nindex 32b1d5d383..84e0e8080f 100644\n--- a/builtin/fetch.c\n+++ b/builtin/fetch.c\n@@ -238,7 +238,7 @@ static int will_fetch(struct ref **head, const unsigned char *sha1)\n {\n \tstruct ref *rm = *head;\n \twhile (rm) {\n-\t\tif (!hashcmp(rm->old_oid.hash, sha1))\n+\t\tif (hasheq(rm->old_oid.hash, sha1))\n \t\t\treturn 1;\n \t\trm = rm->next;\n \t}\ndiff --git a/cache.h b/cache.h\nindex d090f71706..d97db26bb6 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1053,12 +1053,12 @@ static inline int oideq(const struct object_id *oid1, const struct object_id *oi\n \n static inline int is_null_sha1(const unsigned char *sha1)\n {\n-\treturn !hashcmp(sha1, null_sha1);\n+\treturn hasheq(sha1, null_sha1);\n }\n \n static inline int is_null_oid(const struct object_id *oid)\n {\n-\treturn !hashcmp(oid->hash, null_sha1);\n+\treturn hasheq(oid->hash, null_sha1);\n }\n \n static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src)\n@@ -1095,7 +1095,7 @@ static inline void oidread(struct object_id *oid, const unsigned char *hash)\n \n static inline int is_empty_blob_sha1(const unsigned char *sha1)\n {\n-\treturn !hashcmp(sha1, the_hash_algo->empty_blob->hash);\n+\treturn hasheq(sha1, the_hash_algo->empty_blob->hash);\n }\n \n static inline int is_empty_blob_oid(const struct object_id *oid)\n@@ -1105,7 +1105,7 @@ static inline int is_empty_blob_oid(const struct object_id *oid)\n \n static inline int is_empty_tree_sha1(const unsigned char *sha1)\n {\n-\treturn !hashcmp(sha1, the_hash_algo->empty_tree->hash);\n+\treturn hasheq(sha1, the_hash_algo->empty_tree->hash);\n }\n \n static inline int is_empty_tree_oid(const struct object_id *oid)\ndiff --git a/contrib/coccinelle/object_id.cocci b/contrib/coccinelle/object_id.cocci\nindex 548c02336d..d90ba8a040 100644\n--- a/contrib/coccinelle/object_id.cocci\n+++ b/contrib/coccinelle/object_id.cocci\n@@ -114,3 +114,12 @@ expression E1, E2;\n @@\n - oidcmp(E1, E2) == 0\n + oideq(E1, E2)\n+\n+@@\n+identifier f != hasheq;\n+expression E1, E2;\n+@@\n+  f(...) {<...\n+- hashcmp(E1, E2) == 0\n++ hasheq(E1, E2)\n+  ...>}\ndiff --git a/http-walker.c b/http-walker.c\nindex 7cdfb2f24c..3a8edc7f2f 100644\n--- a/http-walker.c\n+++ b/http-walker.c\n@@ -483,7 +483,7 @@ static int fetch_object(struct walker *walker, unsigned char *sha1)\n \n \tlist_for_each(pos, head) {\n \t\tobj_req = list_entry(pos, struct object_request, node);\n-\t\tif (!hashcmp(obj_req->oid.hash, sha1))\n+\t\tif (hasheq(obj_req->oid.hash, sha1))\n \t\t\tbreak;\n \t}\n \tif (obj_req == NULL)\ndiff --git a/notes.c b/notes.c\nindex b3386d6c36..33d16c1ec3 100644\n--- a/notes.c\n+++ b/notes.c\n@@ -147,7 +147,7 @@ static struct leaf_node *note_tree_find(struct notes_tree *t,\n \tvoid **p = note_tree_search(t, &tree, &n, key_sha1);\n \tif (GET_PTR_TYPE(*p) == PTR_TYPE_NOTE) {\n \t\tstruct leaf_node *l = (struct leaf_node *) CLR_PTR_TYPE(*p);\n-\t\tif (!hashcmp(key_sha1, l->key_oid.hash))\n+\t\tif (hasheq(key_sha1, l->key_oid.hash))\n \t\t\treturn l;\n \t}\n \treturn NULL;\ndiff --git a/object.c b/object.c\nindex 51c4594515..e54160550c 100644\n--- a/object.c\n+++ b/object.c\n@@ -95,7 +95,7 @@ struct object *lookup_object(struct repository *r, const unsigned char *sha1)\n \n \tfirst = i = hash_obj(sha1, r->parsed_objects->obj_hash_size);\n \twhile ((obj = r->parsed_objects->obj_hash[i]) != NULL) {\n-\t\tif (!hashcmp(sha1, obj->oid.hash))\n+\t\tif (hasheq(sha1, obj->oid.hash))\n \t\t\tbreak;\n \t\ti++;\n \t\tif (i == r->parsed_objects->obj_hash_size)\ndiff --git a/pack-objects.c b/pack-objects.c\nindex 6ef87e5683..2bc7626997 100644\n--- a/pack-objects.c\n+++ b/pack-objects.c\n@@ -16,7 +16,7 @@ static uint32_t locate_object_entry_hash(struct packing_data *pdata,\n \twhile (pdata->index[i] > 0) {\n \t\tuint32_t pos = pdata->index[i] - 1;\n \n-\t\tif (!hashcmp(sha1, pdata->objects[pos].idx.oid.hash)) {\n+\t\tif (hasheq(sha1, pdata->objects[pos].idx.oid.hash)) {\n \t\t\t*found = 1;\n \t\t\treturn i;\n \t\t}\ndiff --git a/packfile.c b/packfile.c\nindex ebcb5742ec..c2e96293ad 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -1015,7 +1015,7 @@ void mark_bad_packed_object(struct packed_git *p, const unsigned char *sha1)\n {\n \tunsigned i;\n \tfor (i = 0; i < p->num_bad_objects; i++)\n-\t\tif (!hashcmp(sha1, p->bad_object_sha1 + GIT_SHA1_RAWSZ * i))\n+\t\tif (hasheq(sha1, p->bad_object_sha1 + GIT_SHA1_RAWSZ * i))\n \t\t\treturn;\n \tp->bad_object_sha1 = xrealloc(p->bad_object_sha1,\n \t\t\t\t      st_mult(GIT_MAX_RAWSZ,\n@@ -1031,8 +1031,8 @@ const struct packed_git *has_packed_and_bad(const unsigned char *sha1)\n \n \tfor (p = the_repository->objects->packed_git; p; p = p->next)\n \t\tfor (i = 0; i < p->num_bad_objects; i++)\n-\t\t\tif (!hashcmp(sha1,\n-\t\t\t\t     p->bad_object_sha1 + the_hash_algo->rawsz * i))\n+\t\t\tif (hasheq(sha1,\n+\t\t\t\t   p->bad_object_sha1 + the_hash_algo->rawsz * i))\n \t\t\t\treturn p;\n \treturn NULL;\n }\n@@ -1830,8 +1830,8 @@ static int fill_pack_entry(const struct object_id *oid,\n \tif (p->num_bad_objects) {\n \t\tunsigned i;\n \t\tfor (i = 0; i < p->num_bad_objects; i++)\n-\t\t\tif (!hashcmp(oid->hash,\n-\t\t\t\t     p->bad_object_sha1 + the_hash_algo->rawsz * i))\n+\t\t\tif (hasheq(oid->hash,\n+\t\t\t\t   p->bad_object_sha1 + the_hash_algo->rawsz * i))\n \t\t\t\treturn 0;\n \t}\n \n-- \n2.19.0.rc0.412.g7005db4e88\n\n"},{"id":"356507","messageId":"20180825080943.GE737@sigill.intra.peff.net","threadId":"49212","inReplyTo":"20180825080031.GA32139@sigill.intra.peff.net","subject":"[PATCH 5/9] convert \"oidcmp() != 0\" to \"!oideq()\"","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2018-08-25T08:09:44Z","receivedAt":"2018-08-25T08:09:50Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"This is the flip side of the previous two patches: checking\nfor a non-zero oidcmp() can be more strictly expressed as\ninequality. Like those patches, we write \"!= 0\" in the\ncoccinelle transformation, which covers by isomorphism the\nmore common:\n\n  if (oidcmp(E1, E2))\n\nAs with the previous two patches, this patch can be achieved\nalmost entirely by running \"make coccicheck\"; the only\ndifferences are manual line-wrap fixes to match the original\ncode.\n\nThere is one thing to note for anybody replicating this,\nthough: coccinelle 1.0.4 seems to miss the case in\nbuiltin/tag.c, even though it's basically the same as all\nthe others. Running with 1.0.7 does catch this, so\npresumably it's just a coccinelle bug that was fixed in the\ninterim.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n bisect.c                           | 2 +-\n blame.c                            | 4 ++--\n builtin/fmt-merge-msg.c            | 4 ++--\n builtin/merge.c                    | 2 +-\n builtin/pull.c                     | 2 +-\n builtin/rm.c                       | 2 +-\n builtin/show-branch.c              | 4 ++--\n builtin/tag.c                      | 2 +-\n bundle.c                           | 2 +-\n commit-graph.c                     | 6 +++---\n commit.c                           | 2 +-\n contrib/coccinelle/object_id.cocci | 6 ++++++\n diff-lib.c                         | 2 +-\n diff.c                             | 6 +++---\n diffcore-rename.c                  | 2 +-\n dir.c                              | 6 +++---\n fast-import.c                      | 4 ++--\n fetch-pack.c                       | 2 +-\n match-trees.c                      | 2 +-\n notes.c                            | 2 +-\n read-cache.c                       | 2 +-\n refs.c                             | 8 ++++----\n refs/files-backend.c               | 2 +-\n refs/packed-backend.c              | 2 +-\n refs/ref-cache.c                   | 2 +-\n remote.c                           | 2 +-\n sequencer.c                        | 8 ++++----\n sha1-file.c                        | 6 +++---\n submodule-config.c                 | 4 ++--\n t/helper/test-dump-cache-tree.c    | 2 +-\n tree-diff.c                        | 2 +-\n 31 files changed, 55 insertions(+), 49 deletions(-)\n\ndiff --git a/bisect.c b/bisect.c\nindex 41c56a665e..7c1d8f1a6d 100644\n--- a/bisect.c\n+++ b/bisect.c\n@@ -595,7 +595,7 @@ static struct commit_list *skip_away(struct commit_list *list, int count)\n \n \tfor (i = 0; cur; cur = cur->next, i++) {\n \t\tif (i == index) {\n-\t\t\tif (oidcmp(&cur->item->object.oid, current_bad_oid))\n+\t\t\tif (!oideq(&cur->item->object.oid, current_bad_oid))\n \t\t\t\treturn cur;\n \t\t\tif (previous)\n \t\t\t\treturn previous;\ndiff --git a/blame.c b/blame.c\nindex 10d72e36dd..538d0ab1aa 100644\n--- a/blame.c\n+++ b/blame.c\n@@ -1834,7 +1834,7 @@ void setup_scoreboard(struct blame_scoreboard *sb,\n \n \t\tsb->revs->children.name = \"children\";\n \t\twhile (c->parents &&\n-\t\t       oidcmp(&c->object.oid, &sb->final->object.oid)) {\n+\t\t       !oideq(&c->object.oid, &sb->final->object.oid)) {\n \t\t\tstruct commit_list *l = xcalloc(1, sizeof(*l));\n \n \t\t\tl->item = c;\n@@ -1844,7 +1844,7 @@ void setup_scoreboard(struct blame_scoreboard *sb,\n \t\t\tc = c->parents->item;\n \t\t}\n \n-\t\tif (oidcmp(&c->object.oid, &sb->final->object.oid))\n+\t\tif (!oideq(&c->object.oid, &sb->final->object.oid))\n \t\t\tdie(_(\"--reverse --first-parent together require range along first-parent chain\"));\n \t}\n \ndiff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c\nindex 4c82c234cb..268f0c20ca 100644\n--- a/builtin/fmt-merge-msg.c\n+++ b/builtin/fmt-merge-msg.c\n@@ -78,9 +78,9 @@ static struct merge_parent *find_merge_parent(struct merge_parents *table,\n {\n \tint i;\n \tfor (i = 0; i < table->nr; i++) {\n-\t\tif (given && oidcmp(&table->item[i].given, given))\n+\t\tif (given && !oideq(&table->item[i].given, given))\n \t\t\tcontinue;\n-\t\tif (commit && oidcmp(&table->item[i].commit, commit))\n+\t\tif (commit && !oideq(&table->item[i].commit, commit))\n \t\t\tcontinue;\n \t\treturn &table->item[i];\n \t}\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex 57abff999b..8d85d31a61 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -1521,7 +1521,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \t\t\t * HEAD^^\" would be missed.\n \t\t\t */\n \t\t\tcommon_one = get_merge_bases(head_commit, j->item);\n-\t\t\tif (oidcmp(&common_one->item->object.oid, &j->item->object.oid)) {\n+\t\t\tif (!oideq(&common_one->item->object.oid, &j->item->object.oid)) {\n \t\t\t\tup_to_date = 0;\n \t\t\t\tbreak;\n \t\t\t}\ndiff --git a/builtin/pull.c b/builtin/pull.c\nindex 27db0c69eb..58c23a374c 100644\n--- a/builtin/pull.c\n+++ b/builtin/pull.c\n@@ -902,7 +902,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)\n \t\toidclr(&curr_head);\n \n \tif (!is_null_oid(&orig_head) && !is_null_oid(&curr_head) &&\n-\t\t\toidcmp(&orig_head, &curr_head)) {\n+\t\t\t!oideq(&orig_head, &curr_head)) {\n \t\t/*\n \t\t * The fetch involved updating the current branch.\n \t\t *\ndiff --git a/builtin/rm.c b/builtin/rm.c\nindex 2cbe89e0ae..17086d3d97 100644\n--- a/builtin/rm.c\n+++ b/builtin/rm.c\n@@ -180,7 +180,7 @@ static int check_local_mod(struct object_id *head, int index_only)\n \t\tif (no_head\n \t\t     || get_tree_entry(head, name, &oid, &mode)\n \t\t     || ce->ce_mode != create_ce_mode(mode)\n-\t\t     || oidcmp(&ce->oid, &oid))\n+\t\t     || !oideq(&ce->oid, &oid))\n \t\t\tstaged_changes = 1;\n \n \t\t/*\ndiff --git a/builtin/show-branch.c b/builtin/show-branch.c\nindex 363cf8509a..5f9432861b 100644\n--- a/builtin/show-branch.c\n+++ b/builtin/show-branch.c\n@@ -412,7 +412,7 @@ static int append_head_ref(const char *refname, const struct object_id *oid,\n \t/* If both heads/foo and tags/foo exists, get_sha1 would\n \t * get confused.\n \t */\n-\tif (get_oid(refname + ofs, &tmp) || oidcmp(&tmp, oid))\n+\tif (get_oid(refname + ofs, &tmp) || !oideq(&tmp, oid))\n \t\tofs = 5;\n \treturn append_ref(refname + ofs, oid, 0);\n }\n@@ -427,7 +427,7 @@ static int append_remote_ref(const char *refname, const struct object_id *oid,\n \t/* If both heads/foo and tags/foo exists, get_sha1 would\n \t * get confused.\n \t */\n-\tif (get_oid(refname + ofs, &tmp) || oidcmp(&tmp, oid))\n+\tif (get_oid(refname + ofs, &tmp) || !oideq(&tmp, oid))\n \t\tofs = 5;\n \treturn append_ref(refname + ofs, oid, 0);\n }\ndiff --git a/builtin/tag.c b/builtin/tag.c\nindex 9a19ffb49f..f623632186 100644\n--- a/builtin/tag.c\n+++ b/builtin/tag.c\n@@ -559,7 +559,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)\n \t    ref_transaction_commit(transaction, &err))\n \t\tdie(\"%s\", err.buf);\n \tref_transaction_free(transaction);\n-\tif (force && !is_null_oid(&prev) && oidcmp(&prev, &object))\n+\tif (force && !is_null_oid(&prev) && !oideq(&prev, &object))\n \t\tprintf(_(\"Updated tag '%s' (was %s)\\n\"), tag,\n \t\t       find_unique_abbrev(&prev, DEFAULT_ABBREV));\n \ndiff --git a/bundle.c b/bundle.c\nindex 24cbe40986..14f2cfc248 100644\n--- a/bundle.c\n+++ b/bundle.c\n@@ -369,7 +369,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)\n \t\t * commit that is referenced by the tag, and not the tag\n \t\t * itself.\n \t\t */\n-\t\tif (oidcmp(&oid, &e->item->oid)) {\n+\t\tif (!oideq(&oid, &e->item->oid)) {\n \t\t\t/*\n \t\t\t * Is this the positive end of a range expressed\n \t\t\t * in terms of a tag (e.g. v2.0 from the range\ndiff --git a/commit-graph.c b/commit-graph.c\nindex 050c516b0d..7aed9f5371 100644\n--- a/commit-graph.c\n+++ b/commit-graph.c\n@@ -765,7 +765,7 @@ void write_commit_graph(const char *obj_dir,\n \n \tcount_distinct = 1;\n \tfor (i = 1; i < oids.nr; i++) {\n-\t\tif (oidcmp(&oids.list[i-1], &oids.list[i]))\n+\t\tif (!oideq(&oids.list[i - 1], &oids.list[i]))\n \t\t\tcount_distinct++;\n \t}\n \n@@ -960,7 +960,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g)\n \t\t\tcontinue;\n \t\t}\n \n-\t\tif (oidcmp(&get_commit_tree_in_graph_one(g, graph_commit)->object.oid,\n+\t\tif (!oideq(&get_commit_tree_in_graph_one(g, graph_commit)->object.oid,\n \t\t\t   get_commit_tree_oid(odb_commit)))\n \t\t\tgraph_report(\"root tree OID for commit %s in commit-graph is %s != %s\",\n \t\t\t\t     oid_to_hex(&cur_oid),\n@@ -977,7 +977,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g)\n \t\t\t\tbreak;\n \t\t\t}\n \n-\t\t\tif (oidcmp(&graph_parents->item->object.oid, &odb_parents->item->object.oid))\n+\t\t\tif (!oideq(&graph_parents->item->object.oid, &odb_parents->item->object.oid))\n \t\t\t\tgraph_report(\"commit-graph parent for %s is %s != %s\",\n \t\t\t\t\t     oid_to_hex(&cur_oid),\n \t\t\t\t\t     oid_to_hex(&graph_parents->item->object.oid),\ndiff --git a/commit.c b/commit.c\nindex 30d1af2b20..347f09722d 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -46,7 +46,7 @@ struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref\n \tstruct commit *c = lookup_commit_reference(the_repository, oid);\n \tif (!c)\n \t\tdie(_(\"could not parse %s\"), ref_name);\n-\tif (oidcmp(oid, &c->object.oid)) {\n+\tif (!oideq(oid, &c->object.oid)) {\n \t\twarning(_(\"%s %s is not a commit!\"),\n \t\t\tref_name, oid_to_hex(oid));\n \t}\ndiff --git a/contrib/coccinelle/object_id.cocci b/contrib/coccinelle/object_id.cocci\nindex d90ba8a040..4e1f1a7431 100644\n--- a/contrib/coccinelle/object_id.cocci\n+++ b/contrib/coccinelle/object_id.cocci\n@@ -123,3 +123,9 @@ expression E1, E2;\n - hashcmp(E1, E2) == 0\n + hasheq(E1, E2)\n   ...>}\n+\n+@@\n+expression E1, E2;\n+@@\n+- oidcmp(E1, E2) != 0\n++ !oideq(E1, E2)\ndiff --git a/diff-lib.c b/diff-lib.c\nindex c1f5a52654..8866b1d60c 100644\n--- a/diff-lib.c\n+++ b/diff-lib.c\n@@ -342,7 +342,7 @@ static int show_modified(struct rev_info *revs,\n \t}\n \n \tif (revs->combine_merges && !cached &&\n-\t    (oidcmp(oid, &old_entry->oid) || oidcmp(&old_entry->oid, &new_entry->oid))) {\n+\t    (!oideq(oid, &old_entry->oid) || !oideq(&old_entry->oid, &new_entry->oid))) {\n \t\tstruct combine_diff_path *p;\n \t\tint pathlen = ce_namelen(new_entry);\n \ndiff --git a/diff.c b/diff.c\nindex 5cada68267..5d3219b600 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -3765,7 +3765,7 @@ static int reuse_worktree_file(const char *name, const struct object_id *oid, in\n \t * This is not the sha1 we are looking for, or\n \t * unreusable because it is not a regular file.\n \t */\n-\tif (oidcmp(oid, &ce->oid) || !S_ISREG(ce->ce_mode))\n+\tif (!oideq(oid, &ce->oid) || !S_ISREG(ce->ce_mode))\n \t\treturn 0;\n \n \t/*\n@@ -4170,7 +4170,7 @@ static void fill_metainfo(struct strbuf *msg,\n \tdefault:\n \t\t*must_show_header = 0;\n \t}\n-\tif (one && two && oidcmp(&one->oid, &two->oid)) {\n+\tif (one && two && !oideq(&one->oid, &two->oid)) {\n \t\tconst unsigned hexsz = the_hash_algo->hexsz;\n \t\tint abbrev = o->flags.full_index ? hexsz : DEFAULT_ABBREV;\n \n@@ -5457,7 +5457,7 @@ static void diff_resolve_rename_copy(void)\n \t\t\telse\n \t\t\t\tp->status = DIFF_STATUS_RENAMED;\n \t\t}\n-\t\telse if (oidcmp(&p->one->oid, &p->two->oid) ||\n+\t\telse if (!oideq(&p->one->oid, &p->two->oid) ||\n \t\t\t p->one->mode != p->two->mode ||\n \t\t\t p->one->dirty_submodule ||\n \t\t\t p->two->dirty_submodule ||\ndiff --git a/diffcore-rename.c b/diffcore-rename.c\nindex d775183c2f..daddd9b28a 100644\n--- a/diffcore-rename.c\n+++ b/diffcore-rename.c\n@@ -286,7 +286,7 @@ static int find_identical_files(struct hashmap *srcs,\n \t\tstruct diff_filespec *source = p->filespec;\n \n \t\t/* False hash collision? */\n-\t\tif (oidcmp(&source->oid, &target->oid))\n+\t\tif (!oideq(&source->oid, &target->oid))\n \t\t\tcontinue;\n \t\t/* Non-regular files? If so, the modes must match! */\n \t\tif (!S_ISREG(source->mode) || !S_ISREG(target->mode)) {\ndiff --git a/dir.c b/dir.c\nindex aceb0d4869..8ee9fe81b4 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -1282,7 +1282,7 @@ static void prep_exclude(struct dir_struct *dir,\n \t\t * order, though, if you do that.\n \t\t */\n \t\tif (untracked &&\n-\t\t    oidcmp(&oid_stat.oid, &untracked->exclude_oid)) {\n+\t\t    !oideq(&oid_stat.oid, &untracked->exclude_oid)) {\n \t\t\tinvalidate_gitignore(dir->untracked, untracked);\n \t\t\toidcpy(&untracked->exclude_oid, &oid_stat.oid);\n \t\t}\n@@ -2248,12 +2248,12 @@ static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *d\n \n \t/* Validate $GIT_DIR/info/exclude and core.excludesfile */\n \troot = dir->untracked->root;\n-\tif (oidcmp(&dir->ss_info_exclude.oid,\n+\tif (!oideq(&dir->ss_info_exclude.oid,\n \t\t   &dir->untracked->ss_info_exclude.oid)) {\n \t\tinvalidate_gitignore(dir->untracked, root);\n \t\tdir->untracked->ss_info_exclude = dir->ss_info_exclude;\n \t}\n-\tif (oidcmp(&dir->ss_excludes_file.oid,\n+\tif (!oideq(&dir->ss_excludes_file.oid,\n \t\t   &dir->untracked->ss_excludes_file.oid)) {\n \t\tinvalidate_gitignore(dir->untracked, root);\n \t\tdir->untracked->ss_excludes_file = dir->ss_excludes_file;\ndiff --git a/fast-import.c b/fast-import.c\nindex a731088f96..67a53b79cb 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -2649,7 +2649,7 @@ static int parse_from(struct branch *b)\n \t\tstruct object_entry *oe = find_mark(idnum);\n \t\tif (oe->type != OBJ_COMMIT)\n \t\t\tdie(\"Mark :%\" PRIuMAX \" not a commit\", idnum);\n-\t\tif (oidcmp(&b->oid, &oe->idx.oid)) {\n+\t\tif (!oideq(&b->oid, &oe->idx.oid)) {\n \t\t\toidcpy(&b->oid, &oe->idx.oid);\n \t\t\tif (oe->pack_id != MAX_PACK_ID) {\n \t\t\t\tunsigned long size;\n@@ -2667,7 +2667,7 @@ static int parse_from(struct branch *b)\n \telse\n \t\tdie(\"Invalid ref name or SHA1 expression: %s\", from);\n \n-\tif (b->branch_tree.tree && oidcmp(&oid, &b->branch_tree.versions[1].oid)) {\n+\tif (b->branch_tree.tree && !oideq(&oid, &b->branch_tree.versions[1].oid)) {\n \t\trelease_tree_content_recursive(b->branch_tree.tree);\n \t\tb->branch_tree.tree = NULL;\n \t}\ndiff --git a/fetch-pack.c b/fetch-pack.c\nindex 88a078e9be..75047a4b2a 100644\n--- a/fetch-pack.c\n+++ b/fetch-pack.c\n@@ -599,7 +599,7 @@ static void filter_refs(struct fetch_pack_args *args,\n \t\t\tcontinue;\n \t\tif (parse_oid_hex(ref->name, &oid, &p) ||\n \t\t    *p != '\\0' ||\n-\t\t    oidcmp(&oid, &ref->old_oid))\n+\t\t    !oideq(&oid, &ref->old_oid))\n \t\t\tcontinue;\n \n \t\tif ((allow_unadvertised_object_request &\ndiff --git a/match-trees.c b/match-trees.c\nindex 37653308d3..2b6d31ef9d 100644\n--- a/match-trees.c\n+++ b/match-trees.c\n@@ -106,7 +106,7 @@ static int score_trees(const struct object_id *hash1, const struct object_id *ha\n \t\t\tupdate_tree_entry(&two);\n \t\t} else {\n \t\t\t/* path appears in both */\n-\t\t\tif (oidcmp(one.entry.oid, two.entry.oid)) {\n+\t\t\tif (!oideq(one.entry.oid, two.entry.oid)) {\n \t\t\t\t/* they are different */\n \t\t\t\tscore += score_differs(one.entry.mode,\n \t\t\t\t\t\t       two.entry.mode,\ndiff --git a/notes.c b/notes.c\nindex 33d16c1ec3..25cdce28b7 100644\n--- a/notes.c\n+++ b/notes.c\n@@ -206,7 +206,7 @@ static void note_tree_remove(struct notes_tree *t,\n \tif (GET_PTR_TYPE(*p) != PTR_TYPE_NOTE)\n \t\treturn; /* type mismatch, nothing to remove */\n \tl = (struct leaf_node *) CLR_PTR_TYPE(*p);\n-\tif (oidcmp(&l->key_oid, &entry->key_oid))\n+\tif (!oideq(&l->key_oid, &entry->key_oid))\n \t\treturn; /* key mismatch, nothing to remove */\n \n \t/* we have found a matching entry */\ndiff --git a/read-cache.c b/read-cache.c\nindex eb4919e77f..88bb80326b 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -2029,7 +2029,7 @@ int read_index_from(struct index_state *istate, const char *path,\n \tbase_oid_hex = oid_to_hex(&split_index->base_oid);\n \tbase_path = xstrfmt(\"%s/sharedindex.%s\", gitdir, base_oid_hex);\n \tret = do_read_index(split_index->base, base_path, 1);\n-\tif (oidcmp(&split_index->base_oid, &split_index->base->oid))\n+\tif (!oideq(&split_index->base_oid, &split_index->base->oid))\n \t\tdie(\"broken index, expect %s in %s, got %s\",\n \t\t    base_oid_hex, base_path,\n \t\t    oid_to_hex(&split_index->base->oid));\ndiff --git a/refs.c b/refs.c\nindex de81c7be7c..a7a75b4cc0 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -702,7 +702,7 @@ static int write_pseudoref(const char *pseudoref, const struct object_id *oid,\n \t\t\t\t    pseudoref);\n \t\t\trollback_lock_file(&lock);\n \t\t\tgoto done;\n-\t\t} else if (oidcmp(&actual_old_oid, old_oid)) {\n+\t\t} else if (!oideq(&actual_old_oid, old_oid)) {\n \t\t\tstrbuf_addf(err, _(\"unexpected object ID when writing '%s'\"),\n \t\t\t\t    pseudoref);\n \t\t\trollback_lock_file(&lock);\n@@ -744,7 +744,7 @@ static int delete_pseudoref(const char *pseudoref, const struct object_id *old_o\n \t\t}\n \t\tif (read_ref(pseudoref, &actual_old_oid))\n \t\t\tdie(_(\"could not read ref '%s'\"), pseudoref);\n-\t\tif (oidcmp(&actual_old_oid, old_oid)) {\n+\t\tif (!oideq(&actual_old_oid, old_oid)) {\n \t\t\terror(_(\"unexpected object ID when deleting '%s'\"),\n \t\t\t      pseudoref);\n \t\t\trollback_lock_file(&lock);\n@@ -875,13 +875,13 @@ static int read_ref_at_ent(struct object_id *ooid, struct object_id *noid,\n \t\t */\n \t\tif (!is_null_oid(&cb->ooid)) {\n \t\t\toidcpy(cb->oid, noid);\n-\t\t\tif (oidcmp(&cb->ooid, noid))\n+\t\t\tif (!oideq(&cb->ooid, noid))\n \t\t\t\twarning(_(\"log for ref %s has gap after %s\"),\n \t\t\t\t\tcb->refname, show_date(cb->date, cb->tz, DATE_MODE(RFC2822)));\n \t\t}\n \t\telse if (cb->date == cb->at_time)\n \t\t\toidcpy(cb->oid, noid);\n-\t\telse if (oidcmp(noid, cb->oid))\n+\t\telse if (!oideq(noid, cb->oid))\n \t\t\twarning(_(\"log for ref %s unexpectedly ended on %s\"),\n \t\t\t\tcb->refname, show_date(cb->date, cb->tz,\n \t\t\t\t\t\t       DATE_MODE(RFC2822)));\ndiff --git a/refs/files-backend.c b/refs/files-backend.c\nindex aa45f5317f..16ef9325e0 100644\n--- a/refs/files-backend.c\n+++ b/refs/files-backend.c\n@@ -841,7 +841,7 @@ static int verify_lock(struct ref_store *ref_store, struct ref_lock *lock,\n \t\t\treturn 0;\n \t\t}\n \t}\n-\tif (old_oid && oidcmp(&lock->old_oid, old_oid)) {\n+\tif (old_oid && !oideq(&lock->old_oid, old_oid)) {\n \t\tstrbuf_addf(err, \"ref '%s' is at %s but expected %s\",\n \t\t\t    lock->ref_name,\n \t\t\t    oid_to_hex(&lock->old_oid),\ndiff --git a/refs/packed-backend.c b/refs/packed-backend.c\nindex d447a731da..74e2996e93 100644\n--- a/refs/packed-backend.c\n+++ b/refs/packed-backend.c\n@@ -1160,7 +1160,7 @@ static int write_with_updates(struct packed_ref_store *refs,\n \t\t\t\t\t\t    \"reference already exists\",\n \t\t\t\t\t\t    update->refname);\n \t\t\t\t\tgoto error;\n-\t\t\t\t} else if (oidcmp(&update->old_oid, iter->oid)) {\n+\t\t\t\t} else if (!oideq(&update->old_oid, iter->oid)) {\n \t\t\t\t\tstrbuf_addf(err, \"cannot update ref '%s': \"\n \t\t\t\t\t\t    \"is at %s but expected %s\",\n \t\t\t\t\t\t    update->refname,\ndiff --git a/refs/ref-cache.c b/refs/ref-cache.c\nindex 9b110c8494..b7052f72e2 100644\n--- a/refs/ref-cache.c\n+++ b/refs/ref-cache.c\n@@ -272,7 +272,7 @@ static int is_dup_ref(const struct ref_entry *ref1, const struct ref_entry *ref2\n \t\t/* This is impossible by construction */\n \t\tdie(\"Reference directory conflict: %s\", ref1->name);\n \n-\tif (oidcmp(&ref1->u.value.oid, &ref2->u.value.oid))\n+\tif (!oideq(&ref1->u.value.oid, &ref2->u.value.oid))\n \t\tdie(\"Duplicated ref, and SHA1s don't match: %s\", ref1->name);\n \n \twarning(\"Duplicated ref: %s\", ref1->name);\ndiff --git a/remote.c b/remote.c\nindex 6f1ee9d640..e23b7675c8 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -1403,7 +1403,7 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,\n \t\t * branch.\n \t\t */\n \t\tif (ref->expect_old_sha1) {\n-\t\t\tif (oidcmp(&ref->old_oid, &ref->old_oid_expect))\n+\t\t\tif (!oideq(&ref->old_oid, &ref->old_oid_expect))\n \t\t\t\treject_reason = REF_STATUS_REJECT_STALE;\n \t\t\telse\n \t\t\t\t/* If the ref isn't stale then force the update. */\ndiff --git a/sequencer.c b/sequencer.c\nindex 66ed7c7b28..b0ae6755b0 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -1188,7 +1188,7 @@ static int parse_head(struct commit **head)\n \t\tcurrent_head = lookup_commit_reference(the_repository, &oid);\n \t\tif (!current_head)\n \t\t\treturn error(_(\"could not parse HEAD\"));\n-\t\tif (oidcmp(&oid, &current_head->object.oid)) {\n+\t\tif (!oideq(&oid, &current_head->object.oid)) {\n \t\t\twarning(_(\"HEAD %s is not a commit!\"),\n \t\t\t\toid_to_hex(&oid));\n \t\t}\n@@ -3034,7 +3034,7 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,\n \t\tstruct commit_list *p = commit->parents->next;\n \n \t\tfor (j = to_merge; j && p; j = j->next, p = p->next)\n-\t\t\tif (oidcmp(&j->item->object.oid,\n+\t\t\tif (!oideq(&j->item->object.oid,\n \t\t\t\t   &p->item->object.oid)) {\n \t\t\t\tcan_fast_forward = 0;\n \t\t\t\tbreak;\n@@ -3566,7 +3566,7 @@ static int commit_staged_changes(struct replay_opts *opts,\n \t\tif (get_oid_hex(rev.buf, &to_amend))\n \t\t\treturn error(_(\"invalid contents: '%s'\"),\n \t\t\t\trebase_path_amend());\n-\t\tif (!is_clean && oidcmp(&head, &to_amend))\n+\t\tif (!is_clean && !oideq(&head, &to_amend))\n \t\t\treturn error(_(\"\\nYou have uncommitted changes in your \"\n \t\t\t\t       \"working tree. Please, commit them\\n\"\n \t\t\t\t       \"first and then run 'git rebase \"\n@@ -4545,7 +4545,7 @@ int skip_unnecessary_picks(void)\n \t\tif (item->commit->parents->next)\n \t\t\tbreak; /* merge commit */\n \t\tparent_oid = &item->commit->parents->item->object.oid;\n-\t\tif (oidcmp(parent_oid, oid))\n+\t\tif (!oideq(parent_oid, oid))\n \t\t\tbreak;\n \t\toid = &item->commit->object.oid;\n \t}\ndiff --git a/sha1-file.c b/sha1-file.c\nindex 71f49ee56d..cc8a196349 100644\n--- a/sha1-file.c\n+++ b/sha1-file.c\n@@ -825,7 +825,7 @@ int check_object_signature(const struct object_id *oid, void *map,\n \n \tif (map) {\n \t\thash_object_file(map, size, type, &real_oid);\n-\t\treturn oidcmp(oid, &real_oid) ? -1 : 0;\n+\t\treturn !oideq(oid, &real_oid) ? -1 : 0;\n \t}\n \n \tst = open_istream(oid, &obj_type, &size, NULL);\n@@ -852,7 +852,7 @@ int check_object_signature(const struct object_id *oid, void *map,\n \t}\n \tthe_hash_algo->final_fn(real_oid.hash, &c);\n \tclose_istream(st);\n-\treturn oidcmp(oid, &real_oid) ? -1 : 0;\n+\treturn !oideq(oid, &real_oid) ? -1 : 0;\n }\n \n int git_open_cloexec(const char *name, int flags)\n@@ -1671,7 +1671,7 @@ static int write_loose_object(const struct object_id *oid, char *hdr,\n \t\tdie(_(\"deflateEnd on object %s failed (%d)\"), oid_to_hex(oid),\n \t\t    ret);\n \tthe_hash_algo->final_fn(parano_oid.hash, &c);\n-\tif (oidcmp(oid, &parano_oid) != 0)\n+\tif (!oideq(oid, &parano_oid))\n \t\tdie(_(\"confused by unstable object source data for %s\"),\n \t\t    oid_to_hex(oid));\n \ndiff --git a/submodule-config.c b/submodule-config.c\nindex fc2c41b947..e04ba756d9 100644\n--- a/submodule-config.c\n+++ b/submodule-config.c\n@@ -45,7 +45,7 @@ static int config_path_cmp(const void *unused_cmp_data,\n \tconst struct submodule_entry *b = entry_or_key;\n \n \treturn strcmp(a->config->path, b->config->path) ||\n-\t       oidcmp(&a->config->gitmodules_oid, &b->config->gitmodules_oid);\n+\t       !oideq(&a->config->gitmodules_oid, &b->config->gitmodules_oid);\n }\n \n static int config_name_cmp(const void *unused_cmp_data,\n@@ -57,7 +57,7 @@ static int config_name_cmp(const void *unused_cmp_data,\n \tconst struct submodule_entry *b = entry_or_key;\n \n \treturn strcmp(a->config->name, b->config->name) ||\n-\t       oidcmp(&a->config->gitmodules_oid, &b->config->gitmodules_oid);\n+\t       !oideq(&a->config->gitmodules_oid, &b->config->gitmodules_oid);\n }\n \n static struct submodule_cache *submodule_cache_alloc(void)\ndiff --git a/t/helper/test-dump-cache-tree.c b/t/helper/test-dump-cache-tree.c\nindex 98a4891f1d..6a3f88f5f5 100644\n--- a/t/helper/test-dump-cache-tree.c\n+++ b/t/helper/test-dump-cache-tree.c\n@@ -33,7 +33,7 @@ static int dump_cache_tree(struct cache_tree *it,\n \t}\n \telse {\n \t\tdump_one(it, pfx, \"\");\n-\t\tif (oidcmp(&it->oid, &ref->oid) ||\n+\t\tif (!oideq(&it->oid, &ref->oid) ||\n \t\t    ref->entry_count != it->entry_count ||\n \t\t    ref->subtree_nr != it->subtree_nr) {\n \t\t\t/* claims to be valid but is lying */\ndiff --git a/tree-diff.c b/tree-diff.c\nindex fe2e466ac1..0c962a4510 100644\n--- a/tree-diff.c\n+++ b/tree-diff.c\n@@ -491,7 +491,7 @@ static struct combine_diff_path *ll_diff_tree_paths(\n \t\t\t\t\t\tcontinue;\n \n \t\t\t\t\t/* diff(t,pi) != ø */\n-\t\t\t\t\tif (oidcmp(t.entry.oid, tp[i].entry.oid) ||\n+\t\t\t\t\tif (!oideq(t.entry.oid, tp[i].entry.oid) ||\n \t\t\t\t\t    (t.entry.mode != tp[i].entry.mode))\n \t\t\t\t\t\tcontinue;\n \n-- \n2.19.0.rc0.412.g7005db4e88\n\n"},{"id":"356508","messageId":"20180825081040.GF737@sigill.intra.peff.net","threadId":"49212","inReplyTo":"20180825080031.GA32139@sigill.intra.peff.net","subject":"[PATCH 6/9] convert \"hashcmp() != 0\" to \"!hasheq()\"","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2018-08-25T08:10:41Z","receivedAt":"2018-08-25T08:10:45Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"This rounds out the previous three patches, covering the\ninequality logic for the \"hash\" variant of the functions.\n\nAs with the previous three, the accompanying code changes\nare the mechanical result of applying the coccinelle patch;\nsee those patches for more discussion.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\nObviously all of these patches are basically \"see the last one\". I can\nsquash them together if people prefer, but they are so unwieldy I\nthought it best to break it down.\n\n builtin/index-pack.c               | 4 ++--\n builtin/show-branch.c              | 2 +-\n builtin/unpack-objects.c           | 2 +-\n commit-graph.c                     | 2 +-\n contrib/coccinelle/object_id.cocci | 9 +++++++++\n http-walker.c                      | 2 +-\n http.c                             | 2 +-\n pack-check.c                       | 6 +++---\n pack-write.c                       | 2 +-\n packfile.c                         | 2 +-\n read-cache.c                       | 4 ++--\n sha1-file.c                        | 2 +-\n 12 files changed, 24 insertions(+), 15 deletions(-)\n\ndiff --git a/builtin/index-pack.c b/builtin/index-pack.c\nindex edcb0a3dca..2004e25da2 100644\n--- a/builtin/index-pack.c\n+++ b/builtin/index-pack.c\n@@ -1166,7 +1166,7 @@ static void parse_pack_objects(unsigned char *hash)\n \t/* Check pack integrity */\n \tflush();\n \tthe_hash_algo->final_fn(hash, &input_ctx);\n-\tif (hashcmp(fill(the_hash_algo->rawsz), hash))\n+\tif (!hasheq(fill(the_hash_algo->rawsz), hash))\n \t\tdie(_(\"pack is corrupted (SHA1 mismatch)\"));\n \tuse(the_hash_algo->rawsz);\n \n@@ -1280,7 +1280,7 @@ static void conclude_pack(int fix_thin_pack, const char *curr_pack, unsigned cha\n \t\tfixup_pack_header_footer(output_fd, pack_hash,\n \t\t\t\t\t curr_pack, nr_objects,\n \t\t\t\t\t read_hash, consumed_bytes-the_hash_algo->rawsz);\n-\t\tif (hashcmp(read_hash, tail_hash) != 0)\n+\t\tif (!hasheq(read_hash, tail_hash))\n \t\t\tdie(_(\"Unexpected tail checksum for %s \"\n \t\t\t      \"(disk corruption?)\"), curr_pack);\n \t}\ndiff --git a/builtin/show-branch.c b/builtin/show-branch.c\nindex 5f9432861b..65f4a4c83c 100644\n--- a/builtin/show-branch.c\n+++ b/builtin/show-branch.c\n@@ -485,7 +485,7 @@ static void snarf_refs(int head, int remotes)\n static int rev_is_head(const char *head, const char *name,\n \t\t       unsigned char *head_sha1, unsigned char *sha1)\n {\n-\tif (!head || (head_sha1 && sha1 && hashcmp(head_sha1, sha1)))\n+\tif (!head || (head_sha1 && sha1 && !hasheq(head_sha1, sha1)))\n \t\treturn 0;\n \tskip_prefix(head, \"refs/heads/\", &head);\n \tif (!skip_prefix(name, \"refs/heads/\", &name))\ndiff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c\nindex ad438f5b41..80478808b3 100644\n--- a/builtin/unpack-objects.c\n+++ b/builtin/unpack-objects.c\n@@ -579,7 +579,7 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix)\n \t\tif (fsck_finish(&fsck_options))\n \t\t\tdie(_(\"fsck error in pack objects\"));\n \t}\n-\tif (hashcmp(fill(the_hash_algo->rawsz), oid.hash))\n+\tif (!hasheq(fill(the_hash_algo->rawsz), oid.hash))\n \t\tdie(\"final sha1 did not match\");\n \tuse(the_hash_algo->rawsz);\n \ndiff --git a/commit-graph.c b/commit-graph.c\nindex 7aed9f5371..64ce79420d 100644\n--- a/commit-graph.c\n+++ b/commit-graph.c\n@@ -900,7 +900,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g)\n \tf = hashfd(devnull, NULL);\n \thashwrite(f, g->data, g->data_len - g->hash_len);\n \tfinalize_hashfile(f, checksum.hash, CSUM_CLOSE);\n-\tif (hashcmp(checksum.hash, g->data + g->data_len - g->hash_len)) {\n+\tif (!hasheq(checksum.hash, g->data + g->data_len - g->hash_len)) {\n \t\tgraph_report(_(\"the commit-graph file has incorrect checksum and is likely corrupt\"));\n \t\tverify_commit_graph_error = VERIFY_COMMIT_GRAPH_ERROR_HASH;\n \t}\ndiff --git a/contrib/coccinelle/object_id.cocci b/contrib/coccinelle/object_id.cocci\nindex 4e1f1a7431..d8bdb48712 100644\n--- a/contrib/coccinelle/object_id.cocci\n+++ b/contrib/coccinelle/object_id.cocci\n@@ -129,3 +129,12 @@ expression E1, E2;\n @@\n - oidcmp(E1, E2) != 0\n + !oideq(E1, E2)\n+\n+@@\n+identifier f != hasheq;\n+expression E1, E2;\n+@@\n+  f(...) {<...\n+- hashcmp(E1, E2) != 0\n++ !hasheq(E1, E2)\n+  ...>}\ndiff --git a/http-walker.c b/http-walker.c\nindex 3a8edc7f2f..b3334bf657 100644\n--- a/http-walker.c\n+++ b/http-walker.c\n@@ -543,7 +543,7 @@ static int fetch_object(struct walker *walker, unsigned char *sha1)\n \t} else if (req->zret != Z_STREAM_END) {\n \t\twalker->corrupt_object_found++;\n \t\tret = error(\"File %s (%s) corrupt\", hex, req->url);\n-\t} else if (hashcmp(obj_req->oid.hash, req->real_sha1)) {\n+\t} else if (!hasheq(obj_req->oid.hash, req->real_sha1)) {\n \t\tret = error(\"File %s has bad hash\", hex);\n \t} else if (req->rename < 0) {\n \t\tstruct strbuf buf = STRBUF_INIT;\ndiff --git a/http.c b/http.c\nindex b4bfbceaeb..e32a34a7d1 100644\n--- a/http.c\n+++ b/http.c\n@@ -2394,7 +2394,7 @@ int finish_http_object_request(struct http_object_request *freq)\n \t\tunlink_or_warn(freq->tmpfile.buf);\n \t\treturn -1;\n \t}\n-\tif (hashcmp(freq->sha1, freq->real_sha1)) {\n+\tif (!hasheq(freq->sha1, freq->real_sha1)) {\n \t\tunlink_or_warn(freq->tmpfile.buf);\n \t\treturn -1;\n \t}\ndiff --git a/pack-check.c b/pack-check.c\nindex d3a57df34f..fa5f0ff8fa 100644\n--- a/pack-check.c\n+++ b/pack-check.c\n@@ -79,10 +79,10 @@ static int verify_packfile(struct packed_git *p,\n \t} while (offset < pack_sig_ofs);\n \tthe_hash_algo->final_fn(hash, &ctx);\n \tpack_sig = use_pack(p, w_curs, pack_sig_ofs, NULL);\n-\tif (hashcmp(hash, pack_sig))\n+\tif (!hasheq(hash, pack_sig))\n \t\terr = error(\"%s pack checksum mismatch\",\n \t\t\t    p->pack_name);\n-\tif (hashcmp(index_base + index_size - the_hash_algo->hexsz, pack_sig))\n+\tif (!hasheq(index_base + index_size - the_hash_algo->hexsz, pack_sig))\n \t\terr = error(\"%s pack checksum does not match its index\",\n \t\t\t    p->pack_name);\n \tunuse_pack(w_curs);\n@@ -180,7 +180,7 @@ int verify_pack_index(struct packed_git *p)\n \tthe_hash_algo->init_fn(&ctx);\n \tthe_hash_algo->update_fn(&ctx, index_base, (unsigned int)(index_size - the_hash_algo->rawsz));\n \tthe_hash_algo->final_fn(hash, &ctx);\n-\tif (hashcmp(hash, index_base + index_size - the_hash_algo->rawsz))\n+\tif (!hasheq(hash, index_base + index_size - the_hash_algo->rawsz))\n \t\terr = error(\"Packfile index for %s hash mismatch\",\n \t\t\t    p->pack_name);\n \treturn err;\ndiff --git a/pack-write.c b/pack-write.c\nindex 7d14716c40..29d17a9bec 100644\n--- a/pack-write.c\n+++ b/pack-write.c\n@@ -260,7 +260,7 @@ void fixup_pack_header_footer(int pack_fd,\n \t\tif (partial_pack_offset == 0) {\n \t\t\tunsigned char hash[GIT_MAX_RAWSZ];\n \t\t\tthe_hash_algo->final_fn(hash, &old_hash_ctx);\n-\t\t\tif (hashcmp(hash, partial_pack_hash) != 0)\n+\t\t\tif (!hasheq(hash, partial_pack_hash))\n \t\t\t\tdie(\"Unexpected checksum for %s \"\n \t\t\t\t    \"(disk corruption?)\", pack_name);\n \t\t\t/*\ndiff --git a/packfile.c b/packfile.c\nindex c2e96293ad..1e9eacd9b3 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -517,7 +517,7 @@ static int open_packed_git_1(struct packed_git *p)\n \tif (read_result != hashsz)\n \t\treturn error(\"packfile %s signature is unavailable\", p->pack_name);\n \tidx_hash = ((unsigned char *)p->index_data) + p->index_size - hashsz * 2;\n-\tif (hashcmp(hash, idx_hash))\n+\tif (!hasheq(hash, idx_hash))\n \t\treturn error(\"packfile %s does not match index\", p->pack_name);\n \treturn 0;\n }\ndiff --git a/read-cache.c b/read-cache.c\nindex 88bb80326b..421a7f4953 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -1668,7 +1668,7 @@ static int verify_hdr(struct cache_header *hdr, unsigned long size)\n \tthe_hash_algo->init_fn(&c);\n \tthe_hash_algo->update_fn(&c, hdr, size - the_hash_algo->rawsz);\n \tthe_hash_algo->final_fn(hash, &c);\n-\tif (hashcmp(hash, (unsigned char *)hdr + size - the_hash_algo->rawsz))\n+\tif (!hasheq(hash, (unsigned char *)hdr + size - the_hash_algo->rawsz))\n \t\treturn error(\"bad index file sha1 signature\");\n \treturn 0;\n }\n@@ -2395,7 +2395,7 @@ static int verify_index_from(const struct index_state *istate, const char *path)\n \tif (n != the_hash_algo->rawsz)\n \t\tgoto out;\n \n-\tif (hashcmp(istate->oid.hash, hash))\n+\tif (!hasheq(istate->oid.hash, hash))\n \t\tgoto out;\n \n \tclose(fd);\ndiff --git a/sha1-file.c b/sha1-file.c\nindex cc8a196349..d85f4e93e1 100644\n--- a/sha1-file.c\n+++ b/sha1-file.c\n@@ -2213,7 +2213,7 @@ static int check_stream_sha1(git_zstream *stream,\n \t}\n \n \tthe_hash_algo->final_fn(real_sha1, &c);\n-\tif (hashcmp(expected_sha1, real_sha1)) {\n+\tif (!hasheq(expected_sha1, real_sha1)) {\n \t\terror(_(\"sha1 mismatch for %s (expected %s)\"), path,\n \t\t      sha1_to_hex(expected_sha1));\n \t\treturn -1;\n-- \n2.19.0.rc0.412.g7005db4e88\n\n"},{"id":"356509","messageId":"20180825081409.GG737@sigill.intra.peff.net","threadId":"49212","inReplyTo":"20180825080031.GA32139@sigill.intra.peff.net","subject":"[PATCH 7/9] convert hashmap comparison functions to oideq()","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2018-08-25T08:14:09Z","receivedAt":"2018-08-25T08:14:13Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"The comparison functions used for hashmaps don't care about\nstrict ordering; they only want to compare entries for\nequality. Let's use the oideq() function instead, which can\npotentially be better optimized. Note that unlike the\nprevious patches mass-converting calls like \"!oidcmp()\",\nthis patch could actually provide an improvement even with\nthe current implementation. Those comparison functions are\npassed around as function pointers, so at compile-time the\ncompiler cannot realize that the caller (which is in another\nfile completely) will treat the return value as a boolean.\n\nNote that this does change the return values in quite a\nsubtle way (it's still an int, but now the sign bit is\nirrelevant for ordering). Because of their funny\nhashmap-specific signature, it's unlikely that any of these\nstatic functions would be reused for more generic ordering.\nBut to be double-sure, let's stop using \"cmp\" in their\nnames.\n\nCalling them \"eq\" doesn't quite work either, because the\nhashmap convention is actually _inverted_. \"0\" means \"same\",\nand non-zero means \"different\". So I've called them \"neq\" by\nconvention here.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\nI actually think the hashmap inversion is vaguely insane\nand I'd be happy to see it flipped. But that's definitely\noutside the scope of this patch. It would take some care to\ndo so in a way that the compiler would catch topics in\nflight, since the signature would not change (and nor would\nchanging the name \"cmpfn\" in the hash struct help, because\nit is usually filled in by passing to hashmap_init()).\n\n builtin/describe.c |  6 +++---\n oidmap.c           | 12 ++++++------\n patch-ids.c        |  8 ++++----\n 3 files changed, 13 insertions(+), 13 deletions(-)\n\ndiff --git a/builtin/describe.c b/builtin/describe.c\nindex 1e7c75ba82..22c0541da5 100644\n--- a/builtin/describe.c\n+++ b/builtin/describe.c\n@@ -62,7 +62,7 @@ static const char *prio_names[] = {\n \tN_(\"head\"), N_(\"lightweight\"), N_(\"annotated\"),\n };\n \n-static int commit_name_cmp(const void *unused_cmp_data,\n+static int commit_name_neq(const void *unused_cmp_data,\n \t\t\t   const void *entry,\n \t\t\t   const void *entry_or_key,\n \t\t\t   const void *peeled)\n@@ -70,7 +70,7 @@ static int commit_name_cmp(const void *unused_cmp_data,\n \tconst struct commit_name *cn1 = entry;\n \tconst struct commit_name *cn2 = entry_or_key;\n \n-\treturn oidcmp(&cn1->peeled, peeled ? peeled : &cn2->peeled);\n+\treturn !oideq(&cn1->peeled, peeled ? peeled : &cn2->peeled);\n }\n \n static inline struct commit_name *find_commit_name(const struct object_id *peeled)\n@@ -596,7 +596,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)\n \t\treturn cmd_name_rev(args.argc, args.argv, prefix);\n \t}\n \n-\thashmap_init(&names, commit_name_cmp, NULL, 0);\n+\thashmap_init(&names, commit_name_neq, NULL, 0);\n \tfor_each_rawref(get_name, NULL);\n \tif (!hashmap_get_size(&names) && !always)\n \t\tdie(_(\"No names found, cannot describe anything.\"));\ndiff --git a/oidmap.c b/oidmap.c\nindex d9fb19ba6a..b0841a0f58 100644\n--- a/oidmap.c\n+++ b/oidmap.c\n@@ -1,14 +1,14 @@\n #include \"cache.h\"\n #include \"oidmap.h\"\n \n-static int cmpfn(const void *hashmap_cmp_fn_data,\n-\t\t const void *entry, const void *entry_or_key,\n-\t\t const void *keydata)\n+static int oidmap_neq(const void *hashmap_cmp_fn_data,\n+\t\t      const void *entry, const void *entry_or_key,\n+\t\t      const void *keydata)\n {\n \tconst struct oidmap_entry *entry_ = entry;\n \tif (keydata)\n-\t\treturn oidcmp(&entry_->oid, (const struct object_id *) keydata);\n-\treturn oidcmp(&entry_->oid,\n+\t\treturn !oideq(&entry_->oid, (const struct object_id *) keydata);\n+\treturn !oideq(&entry_->oid,\n \t\t      &((const struct oidmap_entry *) entry_or_key)->oid);\n }\n \n@@ -21,7 +21,7 @@ static int hash(const struct object_id *oid)\n \n void oidmap_init(struct oidmap *map, size_t initial_size)\n {\n-\thashmap_init(&map->map, cmpfn, NULL, initial_size);\n+\thashmap_init(&map->map, oidmap_neq, NULL, initial_size);\n }\n \n void oidmap_free(struct oidmap *map, int free_entries)\ndiff --git a/patch-ids.c b/patch-ids.c\nindex 8f7c25d5db..960ea24054 100644\n--- a/patch-ids.c\n+++ b/patch-ids.c\n@@ -28,14 +28,14 @@ int commit_patch_id(struct commit *commit, struct diff_options *options,\n /*\n  * When we cannot load the full patch-id for both commits for whatever\n  * reason, the function returns -1 (i.e. return error(...)). Despite\n- * the \"cmp\" in the name of this function, the caller only cares about\n+ * the \"neq\" in the name of this function, the caller only cares about\n  * the return value being zero (a and b are equivalent) or non-zero (a\n  * and b are different), and returning non-zero would keep both in the\n  * result, even if they actually were equivalent, in order to err on\n  * the side of safety.  The actual value being negative does not have\n  * any significance; only that it is non-zero matters.\n  */\n-static int patch_id_cmp(const void *cmpfn_data,\n+static int patch_id_neq(const void *cmpfn_data,\n \t\t\tconst void *entry,\n \t\t\tconst void *entry_or_key,\n \t\t\tconst void *unused_keydata)\n@@ -53,7 +53,7 @@ static int patch_id_cmp(const void *cmpfn_data,\n \t    commit_patch_id(b->commit, opt, &b->patch_id, 0))\n \t\treturn error(\"Could not get patch ID for %s\",\n \t\t\toid_to_hex(&b->commit->object.oid));\n-\treturn oidcmp(&a->patch_id, &b->patch_id);\n+\treturn !oideq(&a->patch_id, &b->patch_id);\n }\n \n int init_patch_ids(struct patch_ids *ids)\n@@ -63,7 +63,7 @@ int init_patch_ids(struct patch_ids *ids)\n \tids->diffopts.detect_rename = 0;\n \tids->diffopts.flags.recursive = 1;\n \tdiff_setup_done(&ids->diffopts);\n-\thashmap_init(&ids->patches, patch_id_cmp, &ids->diffopts, 256);\n+\thashmap_init(&ids->patches, patch_id_neq, &ids->diffopts, 256);\n \treturn 0;\n }\n \n-- \n2.19.0.rc0.412.g7005db4e88\n\n"},{"id":"356510","messageId":"20180825081525.GH737@sigill.intra.peff.net","threadId":"49212","inReplyTo":"20180825080031.GA32139@sigill.intra.peff.net","subject":"[PATCH 8/9] read-cache: use oideq() in ce_compare functions","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2018-08-25T08:15:25Z","receivedAt":"2018-08-25T08:15:29Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"These functions return the full oidcmp() value, but the\ncallers really only care whether it is non-zero. We can use\nthe more strict !oideq(), which a compiler may be able to\noptimize further.\n\nThis does change the meaning of the return value subtly, but\nit's unlikely that anybody would try to use them for\nordering. They're static-local in this file, and they\nalready return other error values that would confuse an\nordering (e.g., open() failure gives -1).\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n read-cache.c | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/read-cache.c b/read-cache.c\nindex 421a7f4953..eb7cea6272 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -213,7 +213,7 @@ static int ce_compare_data(const struct cache_entry *ce, struct stat *st)\n \tif (fd >= 0) {\n \t\tstruct object_id oid;\n \t\tif (!index_fd(&oid, fd, st, OBJ_BLOB, ce->name, 0))\n-\t\t\tmatch = oidcmp(&oid, &ce->oid);\n+\t\t\tmatch = !oideq(&oid, &ce->oid);\n \t\t/* index_fd() closed the file descriptor already */\n \t}\n \treturn match;\n@@ -254,7 +254,7 @@ static int ce_compare_gitlink(const struct cache_entry *ce)\n \t */\n \tif (resolve_gitlink_ref(ce->name, \"HEAD\", &oid) < 0)\n \t\treturn 0;\n-\treturn oidcmp(&oid, &ce->oid);\n+\treturn !oideq(&oid, &ce->oid);\n }\n \n static int ce_modified_check_fs(const struct cache_entry *ce, struct stat *st)\n-- \n2.19.0.rc0.412.g7005db4e88\n\n"},{"id":"356511","messageId":"20180825081731.GI737@sigill.intra.peff.net","threadId":"49212","inReplyTo":"20180825080031.GA32139@sigill.intra.peff.net","subject":"[PATCH 9/9] show_dirstat: simplify same-content check","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2018-08-25T08:17:32Z","receivedAt":"2018-08-25T08:17:35Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"We two nested conditionals to store a content_changed\nvariable, but only bother to look at the result once,\ndirectly after we set it. We can drop the variable entirely\nand just use a single \"if\".\n\nThis needless complexity is the result of 2ff3a80334 (Teach\n--dirstat not to completely ignore rearranged lines within a\nfile, 2011-04-11). Before that, we held onto the\ncontent_changed variable much longer.\n\nWhile we're touching the condition, we can swap out oidcmp()\nfor !oideq(). Our coccinelle patches didn't previously find\nthis case because of the intermediate variable, but now it's\na simple boolean in a conditional.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n diff.c | 11 +++--------\n 1 file changed, 3 insertions(+), 8 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 5d3219b600..605ba4b6b8 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -2933,16 +2933,11 @@ static void show_dirstat(struct diff_options *options)\n \t\tstruct diff_filepair *p = q->queue[i];\n \t\tconst char *name;\n \t\tunsigned long copied, added, damage;\n-\t\tint content_changed;\n \n \t\tname = p->two->path ? p->two->path : p->one->path;\n \n-\t\tif (p->one->oid_valid && p->two->oid_valid)\n-\t\t\tcontent_changed = oidcmp(&p->one->oid, &p->two->oid);\n-\t\telse\n-\t\t\tcontent_changed = 1;\n-\n-\t\tif (!content_changed) {\n+\t\tif (p->one->oid_valid && p->two->oid_valid &&\n+\t\t    oideq(&p->one->oid, &p->two->oid)) {\n \t\t\t/*\n \t\t\t * The SHA1 has not changed, so pre-/post-content is\n \t\t\t * identical. We can therefore skip looking at the\n@@ -2989,7 +2984,7 @@ static void show_dirstat(struct diff_options *options)\n \t\t * made to the preimage.\n \t\t * If the resulting damage is zero, we know that\n \t\t * diffcore_count_changes() considers the two entries to\n-\t\t * be identical, but since content_changed is true, we\n+\t\t * be identical, but since the oid changed, we\n \t\t * know that there must have been _some_ kind of change,\n \t\t * so we force all entries to have damage > 0.\n \t\t */\n-- \n2.19.0.rc0.412.g7005db4e88\n"},{"id":"356512","messageId":"CAPig+cTBEWxJsqtAQW0=1-mPZMk4FPXuK0Zj2hdrFzrbjry3-g@mail.gmail.com","threadId":"49212","inReplyTo":"20180825081731.GI737@sigill.intra.peff.net","subject":"Re: [PATCH 9/9] show_dirstat: simplify same-content check","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-08-25T08:20:33Z","receivedAt":"2018-08-25T08:20:47Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Sat, Aug 25, 2018 at 4:17 AM Jeff King <peff@peff.net> wrote:\n> We two nested conditionals to store a content_changed\n\ngrammo...\n\n> variable, but only bother to look at the result once,\n> directly after we set it. We can drop the variable entirely\n> and just use a single \"if\".\n>\n> This needless complexity is the result of 2ff3a80334 (Teach\n> --dirstat not to completely ignore rearranged lines within a\n> file, 2011-04-11). Before that, we held onto the\n> content_changed variable much longer.\n>\n> While we're touching the condition, we can swap out oidcmp()\n> for !oideq(). Our coccinelle patches didn't previously find\n> this case because of the intermediate variable, but now it's\n> a simple boolean in a conditional.\n>\n> Signed-off-by: Jeff King <peff@peff.net>\n"},{"id":"356513","messageId":"20180825082339.GB1672@sigill.intra.peff.net","threadId":"49212","inReplyTo":"CAPig+cTBEWxJsqtAQW0=1-mPZMk4FPXuK0Zj2hdrFzrbjry3-g@mail.gmail.com","subject":"Re: [PATCH 9/9] show_dirstat: simplify same-content check","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2018-08-25T08:23:39Z","receivedAt":"2018-08-25T08:23:42Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Aug 25, 2018 at 04:20:33AM -0400, Eric Sunshine wrote:\n\n> On Sat, Aug 25, 2018 at 4:17 AM Jeff King <peff@peff.net> wrote:\n> > We two nested conditionals to store a content_changed\n> \n> grammo...\n\nHeh. Edited in my MUA while proof-reading, of course. ;)\n\nIt should be \"We use two...\".\n\n-Peff\n"},{"id":"356515","messageId":"20180825083602.GA2251@sigill.intra.peff.net","threadId":"49212","inReplyTo":"20180825080715.GC737@sigill.intra.peff.net","subject":"Re: [PATCH 3/9] convert \"oidcmp() == 0\" to oideq()","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2018-08-25T08:36:03Z","receivedAt":"2018-08-25T08:36:07Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Aug 25, 2018 at 04:07:15AM -0400, Jeff King wrote:\n\n> diff --git a/contrib/coccinelle/object_id.cocci b/contrib/coccinelle/object_id.cocci\n> index 5869979be7..548c02336d 100644\n> --- a/contrib/coccinelle/object_id.cocci\n> +++ b/contrib/coccinelle/object_id.cocci\n> @@ -108,3 +108,9 @@ expression E1, E2;\n>  @@\n>  - hashcpy(E1.hash, E2->hash)\n>  + oidcpy(&E1, E2)\n> +\n> +@@\n> +expression E1, E2;\n> +@@\n> +- oidcmp(E1, E2) == 0\n> ++ oideq(E1, E2)\n>\n> [...]\n>\n> diff --git a/cache.h b/cache.h\n> index f6d227fac7..d090f71706 100644\n> --- a/cache.h\n> +++ b/cache.h\n> @@ -1100,7 +1100,7 @@ static inline int is_empty_blob_sha1(const unsigned char *sha1)\n>  \n>  static inline int is_empty_blob_oid(const struct object_id *oid)\n>  {\n> -\treturn !oidcmp(oid, the_hash_algo->empty_blob);\n> +\treturn oideq(oid, the_hash_algo->empty_blob);\n>  }\n\nBy the way, one interesting thing I noticed is that coccinelle generates\nthe hunk for cache.h for _every_ file that includes it, and the\nresulting patch is annoying to apply. I think this is related to the\ndiscussion we were having in:\n\n  https://public-inbox.org/git/20180802115522.16107-1-szeder.dev@gmail.com/\n\nNamely that we might do better to invoke one big spatch (and let it\nparallelize internally) instead of one perfile. Presumably that would\nalso avoid looking at the headers repeatedly (which would be both faster\nand produce better output).\n\nI'm not planning to pursue that immediately, so just food for thought at\nthis point.\n\n-Peff\n"},{"id":"356516","messageId":"d8cc6d0e-d713-2387-6bde-072f208a87c6@gmail.com","threadId":"49212","inReplyTo":"20180825080543.GB737@sigill.intra.peff.net","subject":"Re: [PATCH 2/9] introduce hasheq() and oideq()","fromName":"Andrei Rybak","fromEmail":"rybak.a.v@gmail.com","sentAt":"2018-08-25T10:58:14Z","receivedAt":"2018-08-25T10:58:20Z","isPatch":true,"sender":{"key":"rybak.a.v@gmail.com","avatar":"https://avatars.githubusercontent.com/u/624072?v=4"},"body":"On 25/08/18 10:05, Jeff King wrote:\n> The main comparison functions we provide for comparing\n> object ids are hashcmp() and oidcmp(). These are more\n> flexible than a strict equality check, since they also\n> express ordering. That makes them them useful for sorting\n\ns/them them/them/\n\n> We can solve that by introducing a hasheq() function (and\n> matching oideq() wrapper), which callers can use to make\n\ns/make/& it/\n\n> clear that they only care about equality. For now, the\n> implementation will literally be \"!hashcmp()\", but it frees\n> us up later to introduce code optimized specifically for the\n> equality check.\n> \n> Signed-off-by: Jeff King <peff@peff.net>\n\n"},{"id":"356566","messageId":"20180826205620.GC873448@genre.crustytoothpaste.net","threadId":"49212","inReplyTo":"20180825080031.GA32139@sigill.intra.peff.net","subject":"Re: [PATCH 0/9] introducing oideq()","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-08-26T20:56:21Z","receivedAt":"2018-08-26T20:56:30Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Sat, Aug 25, 2018 at 04:00:31AM -0400, Jeff King wrote:\n> This is a follow-up to the discussion in:\n> \n>   https://public-inbox.org/git/20180822030344.GA14684@sigill.intra.peff.net/\n> \n> The general idea is that the majority of callers don't care about actual\n> plus/minus ordering from oidcmp() and hashcmp(); they just want to know\n> if two oids are equal. The stricter equality check can be optimized\n> better by the compiler.\n> \n> Due to the simplicity of the current code and our inlining, the compiler\n> can usually figure this out for now. So I wouldn't expect this patch to\n> actually improve performance right away. But as that discussion shows,\n> we are likely to take a performance hit as we move to more runtime\n> determination of the_hash_algo parameters. Having these callers use the\n> more strict form will potentially help us recover that.\n> \n> So in that sense we _could_ simply punt on this series until then (and\n> it's certainly post-v2.19 material). But I think it's worth doing now,\n> simply from a readability/annotation standpoint. IMHO the resulting code\n> is more clear (though I've long since taught myself to read !foocmp() as\n> equality).\n\nI would quite like to see this series picked up for v2.20.  If we want\nto minimize performance regressions with the SHA-256 work, I think it's\nimportant.\n\nApplying the following patch on top of this series causes gcc to inline\nboth branches, which is pretty much the best we can expect.  I haven't\nbenchmarked it, though, so I can't say what the actual performance\nconsequence is.\n\nAs for this series itself, other than the typos people have pointed out,\nit looks good to me.\n\ndiff --git a/cache.h b/cache.h\nindex 3bb88ac6d0..1c182c6ef6 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1033,7 +1033,10 @@ static inline int oidcmp(const struct object_id *oid1, const struct object_id *o\n \n static inline int hasheq(const unsigned char *sha1, const unsigned char *sha2)\n {\n-\treturn !hashcmp(sha1, sha2);\n+\tif (the_hash_algo->rawsz == 32) {\n+\t\treturn !memcmp(sha1, sha2, 32);\n+\t}\n+\treturn !memcmp(sha1, sha2, 20);\n }\n \n static inline int oideq(const struct object_id *oid1, const struct object_id *oid2)\n-- \nbrian m. carlson: Houston, Texas, US\nOpenPGP: https://keybase.io/bk2204\n"},{"id":"356574","messageId":"62172db4-15b2-eac3-8591-246300db3948@gmail.com","threadId":"49212","inReplyTo":"20180825083602.GA2251@sigill.intra.peff.net","subject":"Re: [PATCH 3/9] convert \"oidcmp() == 0\" to oideq()","fromName":"Derrick Stolee","fromEmail":"stolee@gmail.com","sentAt":"2018-08-27T12:31:46Z","receivedAt":"2018-08-27T12:31:49Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 8/25/2018 4:36 AM, Jeff King wrote:\n> On Sat, Aug 25, 2018 at 04:07:15AM -0400, Jeff King wrote:\n>\n>> diff --git a/contrib/coccinelle/object_id.cocci b/contrib/coccinelle/object_id.cocci\n>> index 5869979be7..548c02336d 100644\n>> --- a/contrib/coccinelle/object_id.cocci\n>> +++ b/contrib/coccinelle/object_id.cocci\n>> @@ -108,3 +108,9 @@ expression E1, E2;\n>>   @@\n>>   - hashcpy(E1.hash, E2->hash)\n>>   + oidcpy(&E1, E2)\n\nIs this change intended? It doesn't seem to match the intention of the \nrest of the patch.\n\n>> +\n>> +@@\n>> +expression E1, E2;\n>> +@@\n>> +- oidcmp(E1, E2) == 0\n>> ++ oideq(E1, E2)\n>>\n>> [...]\n>>\n>> diff --git a/cache.h b/cache.h\n>> index f6d227fac7..d090f71706 100644\n>> --- a/cache.h\n>> +++ b/cache.h\n>> @@ -1100,7 +1100,7 @@ static inline int is_empty_blob_sha1(const unsigned char *sha1)\n>>   \n>>   static inline int is_empty_blob_oid(const struct object_id *oid)\n>>   {\n>> -\treturn !oidcmp(oid, the_hash_algo->empty_blob);\n>> +\treturn oideq(oid, the_hash_algo->empty_blob);\n>>   }\n> By the way, one interesting thing I noticed is that coccinelle generates\n> the hunk for cache.h for _every_ file that includes it, and the\n> resulting patch is annoying to apply. I think this is related to the\n> discussion we were having in:\n>\n>    https://public-inbox.org/git/20180802115522.16107-1-szeder.dev@gmail.com/\n>\n> Namely that we might do better to invoke one big spatch (and let it\n> parallelize internally) instead of one perfile. Presumably that would\n> also avoid looking at the headers repeatedly (which would be both faster\n> and produce better output).\n>\n> I'm not planning to pursue that immediately, so just food for thought at\n> this point.\n\nThe more we use Coccinelle, the more we will learn how to improve the \nworkflow.\n\nThanks,\n\n-Stolee\n\n"},{"id":"356575","messageId":"909de6f4-0b30-b9d9-637c-a86497f86d8e@gmail.com","threadId":"49212","inReplyTo":"62172db4-15b2-eac3-8591-246300db3948@gmail.com","subject":"Re: [PATCH 3/9] convert \"oidcmp() == 0\" to oideq()","fromName":"Derrick Stolee","fromEmail":"stolee@gmail.com","sentAt":"2018-08-27T12:33:25Z","receivedAt":"2018-08-27T12:33:28Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 8/27/2018 8:31 AM, Derrick Stolee wrote:\n> On 8/25/2018 4:36 AM, Jeff King wrote:\n>> On Sat, Aug 25, 2018 at 04:07:15AM -0400, Jeff King wrote:\n>>\n>>> diff --git a/contrib/coccinelle/object_id.cocci \n>>> b/contrib/coccinelle/object_id.cocci\n>>> index 5869979be7..548c02336d 100644\n>>> --- a/contrib/coccinelle/object_id.cocci\n>>> +++ b/contrib/coccinelle/object_id.cocci\n>>> @@ -108,3 +108,9 @@ expression E1, E2;\n>>>   @@\n>>>   - hashcpy(E1.hash, E2->hash)\n>>>   + oidcpy(&E1, E2)\n>\n> Is this change intended? It doesn't seem to match the intention of the \n> rest of the patch.\n\nIgnore me. It's just confusing to read the +/- notation from a cocci \nscript alongside the file diff.\n\n"},{"id":"356576","messageId":"dd26d177-7e37-83ac-7275-03db962a282c@gmail.com","threadId":"49212","inReplyTo":"20180826205620.GC873448@genre.crustytoothpaste.net","subject":"Re: [PATCH 0/9] introducing oideq()","fromName":"Derrick Stolee","fromEmail":"stolee@gmail.com","sentAt":"2018-08-27T12:41:32Z","receivedAt":"2018-08-27T12:41:35Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 8/26/2018 4:56 PM, brian m. carlson wrote:\n> On Sat, Aug 25, 2018 at 04:00:31AM -0400, Jeff King wrote:\n>> This is a follow-up to the discussion in:\n>>\n>>    https://public-inbox.org/git/20180822030344.GA14684@sigill.intra.peff.net/\n>>\n>> The general idea is that the majority of callers don't care about actual\n>> plus/minus ordering from oidcmp() and hashcmp(); they just want to know\n>> if two oids are equal. The stricter equality check can be optimized\n>> better by the compiler.\n>>\n>> Due to the simplicity of the current code and our inlining, the compiler\n>> can usually figure this out for now. So I wouldn't expect this patch to\n>> actually improve performance right away. But as that discussion shows,\n>> we are likely to take a performance hit as we move to more runtime\n>> determination of the_hash_algo parameters. Having these callers use the\n>> more strict form will potentially help us recover that.\n>>\n>> So in that sense we _could_ simply punt on this series until then (and\n>> it's certainly post-v2.19 material). But I think it's worth doing now,\n>> simply from a readability/annotation standpoint. IMHO the resulting code\n>> is more clear (though I've long since taught myself to read !foocmp() as\n>> equality).\n> I would quite like to see this series picked up for v2.20.  If we want\n> to minimize performance regressions with the SHA-256 work, I think it's\n> important.\n\nSeconded.\n\n> Applying the following patch on top of this series causes gcc to inline\n> both branches, which is pretty much the best we can expect.  I haven't\n> benchmarked it, though, so I can't say what the actual performance\n> consequence is.\n\nWe should definitely measure the cost here, but when we have the option \nto move to newhash, that cost should be acceptable.\n\nThanks,\n\n-Stolee\n\n"},{"id":"356751","messageId":"20180828212126.GA7039@sigill.intra.peff.net","threadId":"49212","inReplyTo":"20180826205620.GC873448@genre.crustytoothpaste.net","subject":"Re: [PATCH 0/9] introducing oideq()","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2018-08-28T21:21:27Z","receivedAt":"2018-08-28T21:21:31Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Aug 26, 2018 at 08:56:21PM +0000, brian m. carlson wrote:\n\n> > Due to the simplicity of the current code and our inlining, the compiler\n> > can usually figure this out for now. So I wouldn't expect this patch to\n> > actually improve performance right away. But as that discussion shows,\n> > we are likely to take a performance hit as we move to more runtime\n> > determination of the_hash_algo parameters. Having these callers use the\n> > more strict form will potentially help us recover that.\n> > \n> > So in that sense we _could_ simply punt on this series until then (and\n> > it's certainly post-v2.19 material). But I think it's worth doing now,\n> > simply from a readability/annotation standpoint. IMHO the resulting code\n> > is more clear (though I've long since taught myself to read !foocmp() as\n> > equality).\n> \n> I would quite like to see this series picked up for v2.20.  If we want\n> to minimize performance regressions with the SHA-256 work, I think it's\n> important.\n\nThanks. One of the things I was worried about was causing unnecessary\nconflicts with existing topics, including your work. But if everybody is\non board, I'd be happy to see this go in early in the next release cycle\n(the longer we wait, the more annoying conflicts Junio has to resolve).\n\n> Applying the following patch on top of this series causes gcc to inline\n> both branches, which is pretty much the best we can expect.  I haven't\n> benchmarked it, though, so I can't say what the actual performance\n> consequence is.\n> [...]\n> diff --git a/cache.h b/cache.h\n> index 3bb88ac6d0..1c182c6ef6 100644\n> --- a/cache.h\n> +++ b/cache.h\n> @@ -1033,7 +1033,10 @@ static inline int oidcmp(const struct object_id *oid1, const struct object_id *o\n>  \n>  static inline int hasheq(const unsigned char *sha1, const unsigned char *sha2)\n>  {\n> -\treturn !hashcmp(sha1, sha2);\n> +\tif (the_hash_algo->rawsz == 32) {\n> +\t\treturn !memcmp(sha1, sha2, 32);\n> +\t}\n> +\treturn !memcmp(sha1, sha2, 20);\n>  }\n\nYeah, I can reproduce that, too.  I'm actually surprised that's enough\nto convince the compiler to inline, based on my earlier tests. I wonder\nif it is because it is more able to see the boolean nature of the\nmemcmp() (i.e., in the earlier versions it was not willing to carry that\ninformation across the conditional boundary for some reason). Or perhaps\nit is that this is written slightly differently from my earlier case,\nwhere the fallback did not say \"32\" explicitly, but rather:\n\n  return memcmp(sha1, sha2, the_hash_algo->rawsz);\n\nFor your form, we'd probably want to add a third case arm with a BUG(),\njust in case.\n\n> As for this series itself, other than the typos people have pointed out,\n> it looks good to me.\n\nThanks. Here it is again with those typos fixed, but no changes to the\npatches themselves.\n\n 1:  7bcf611959 =  1:  7bcf611959 coccinelle: use <...> for function exclusion\n 2:  6025ebe5d1 !  2:  0e90944f5a introduce hasheq() and oideq()\n    @@ -5,11 +5,10 @@\n         The main comparison functions we provide for comparing\n         object ids are hashcmp() and oidcmp(). These are more\n         flexible than a strict equality check, since they also\n    -    express ordering. That makes them them useful for sorting\n    -    and binary searching. However, it also makes them\n    -    potentially slower than a strict equality check. Consider\n    -    this C code, which is traditionally what our hashcmp has\n    -    looked like:\n    +    express ordering. That makes them useful for sorting and\n    +    binary searching. However, it also makes them potentially\n    +    slower than a strict equality check. Consider this C code,\n    +    which is traditionally what our hashcmp has looked like:\n     \n           #include <string.h>\n           int hashcmp(const unsigned char *a, const unsigned char *b)\n    @@ -51,7 +50,7 @@\n         though the vast majority don't.\n     \n         We can solve that by introducing a hasheq() function (and\n    -    matching oideq() wrapper), which callers can use to make\n    +    matching oideq() wrapper), which callers can use to make it\n         clear that they only care about equality. For now, the\n         implementation will literally be \"!hashcmp()\", but it frees\n         us up later to introduce code optimized specifically for the\n 3:  35a05a7e5c =  3:  4f1ea17e79 convert \"oidcmp() == 0\" to oideq()\n 4:  b18fc3994d =  4:  6614cc71e4 convert \"hashcmp() == 0\" to hasheq()\n 5:  0fbcfcf7cc =  5:  c3dd2b2c80 convert \"oidcmp() != 0\" to \"!oideq()\"\n 6:  32e169b886 =  6:  c94914f1ef convert \"hashcmp() != 0\" to \"!hasheq()\"\n 7:  b90051c38b =  7:  c773fa9ca4 convert hashmap comparison functions to oideq()\n 8:  b1e6ad80f0 =  8:  ada5809fab read-cache: use oideq() in ce_compare functions\n 9:  18be86e078 !  9:  62f24d63a4 show_dirstat: simplify same-content check\n    @@ -2,7 +2,7 @@\n     \n         show_dirstat: simplify same-content check\n     \n    -    We two nested conditionals to store a content_changed\n    +    We use two nested conditionals to store a content_changed\n         variable, but only bother to look at the result once,\n         directly after we set it. We can drop the variable entirely\n         and just use a single \"if\".\n"},{"id":"356752","messageId":"20180828212232.GA11036@sigill.intra.peff.net","threadId":"49212","inReplyTo":"20180828212126.GA7039@sigill.intra.peff.net","subject":"[PATCH v2 1/9] coccinelle: use <...> for function exclusion","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2018-08-28T21:22:32Z","receivedAt":"2018-08-28T21:22:35Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"Sometimes we want to suppress a coccinelle transformation\ninside a particular function. For example, in finding\nconversions of hashcmp() to oidcmp(), we should not convert\nthe call in oidcmp() itself, since that would cause infinite\nrecursion. We write that like this:\n\n  @@\n  identifier f != oidcmp;\n  expression E1, E2;\n  @@\n    f(...) {...\n  - hashcmp(E1->hash, E2->hash)\n  + oidcmp(E1, E2)\n    ...}\n\nto match the interior of any function _except_ oidcmp().\n\nUnfortunately, this doesn't catch all cases (e.g., the one\nin sequencer.c that this patch fixes). The problem, as\nexplained by one of the Coccinelle developers in [1], is:\n\n  For transformation, A ... B requires that B occur on every\n  execution path starting with A, unless that execution path\n  ends up in error handling code.  (eg, if (...) { ...\n  return; }).  Here your A is the start of the function.  So\n  you need a call to hashcmp on every path through the\n  function, which fails when you add ifs.\n\n  [...]\n\n  Another issue with A ... B is that by default A and B\n  should not appear in the matched region.  So your original\n  rule matches only the case where every execution path\n  contains exactly one call to hashcmp, not more than one.\n\nOne way to solve this is to put the pattern inside an\nangle-bracket pattern like \"<... P ...>\", which allows zero\nor more matches of P. That works (and is what this patch\ndoes), but it has one drawback: it matches more than we care\nabout, and Coccinelle uses extra CPU. Here are timings for\n\"make coccicheck\" before and after this patch:\n\n  [before]\n  real\t1m27.122s\n  user\t7m34.451s\n  sys\t0m37.330s\n\n  [after]\n  real\t2m18.040s\n  user\t10m58.310s\n  sys\t0m41.549s\n\nThat's not ideal, but it's more important for this to be\ncorrect than to be fast. And coccicheck is already fairly\nslow (and people don't run it for every single patch). So\nit's an acceptable tradeoff.\n\nThere _is_ a better way to do it, which is to record the\nposition at which we find hashcmp(), and then check it\nagainst the forbidden function list. Like:\n\n  @@\n  position p : script:python() { p[0].current_element != \"oidcmp\" };\n  expression E1,E2;\n  @@\n  - hashcmp@p(E1->hash, E2->hash)\n  + oidcmp(E1, E2)\n\nThis is only a little slower than the current code, and does\nthe right thing in all cases. Unfortunately, not all builds\nof Coccinelle include python support (including the ones in\nDebian). Requiring it may mean that fewer people can easily\nrun the tool, which is worse than it simply being a little\nslower.\n\nWe may want to revisit this decision in the future if:\n\n  - builds with python become more common\n\n  - we find more uses for python support that tip the\n    cost-benefit analysis\n\nBut for now this patch sticks with the angle-bracket\nsolution, and converts all existing cocci patches. This\nfixes only one missed case in the current code, though it\nmakes a much better difference for some new rules I'm adding\n(converting \"!hashcmp()\" to \"hasheq()\" misses over half the\npossible conversions using the old form).\n\n[1] https://public-inbox.org/git/alpine.DEB.2.21.1808240652370.2344@hadrien/\n\nHelped-by: Julia Lawall <julia.lawall@lip6.fr>\nSigned-off-by: Jeff King <peff@peff.net>\n---\n contrib/coccinelle/commit.cocci    |  4 ++--\n contrib/coccinelle/object_id.cocci | 20 ++++++++++----------\n sequencer.c                        |  2 +-\n 3 files changed, 13 insertions(+), 13 deletions(-)\n\ndiff --git a/contrib/coccinelle/commit.cocci b/contrib/coccinelle/commit.cocci\nindex aec3345adb..c49aa558f0 100644\n--- a/contrib/coccinelle/commit.cocci\n+++ b/contrib/coccinelle/commit.cocci\n@@ -15,10 +15,10 @@ expression c;\n identifier f !~ \"^(get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$\";\n expression c;\n @@\n-  f(...) {...\n+  f(...) {<...\n - c->maybe_tree\n + get_commit_tree(c)\n-  ...}\n+  ...>}\n \n @@\n expression c;\ndiff --git a/contrib/coccinelle/object_id.cocci b/contrib/coccinelle/object_id.cocci\nindex 09afdbf994..5869979be7 100644\n--- a/contrib/coccinelle/object_id.cocci\n+++ b/contrib/coccinelle/object_id.cocci\n@@ -20,10 +20,10 @@ expression E1;\n identifier f != oid_to_hex;\n expression E1;\n @@\n-  f(...) {...\n+  f(...) {<...\n - sha1_to_hex(E1->hash)\n + oid_to_hex(E1)\n-  ...}\n+  ...>}\n \n @@\n expression E1, E2;\n@@ -35,10 +35,10 @@ expression E1, E2;\n identifier f != oid_to_hex_r;\n expression E1, E2;\n @@\n-   f(...) {...\n+   f(...) {<...\n - sha1_to_hex_r(E1, E2->hash)\n + oid_to_hex_r(E1, E2)\n-  ...}\n+  ...>}\n \n @@\n expression E1;\n@@ -50,10 +50,10 @@ expression E1;\n identifier f != oidclr;\n expression E1;\n @@\n-  f(...) {...\n+  f(...) {<...\n - hashclr(E1->hash)\n + oidclr(E1)\n-  ...}\n+  ...>}\n \n @@\n expression E1, E2;\n@@ -65,10 +65,10 @@ expression E1, E2;\n identifier f != oidcmp;\n expression E1, E2;\n @@\n-  f(...) {...\n+  f(...) {<...\n - hashcmp(E1->hash, E2->hash)\n + oidcmp(E1, E2)\n-  ...}\n+  ...>}\n \n @@\n expression E1, E2;\n@@ -92,10 +92,10 @@ expression E1, E2;\n identifier f != oidcpy;\n expression E1, E2;\n @@\n-  f(...) {...\n+  f(...) {<...\n - hashcpy(E1->hash, E2->hash)\n + oidcpy(E1, E2)\n-  ...}\n+  ...>}\n \n @@\n expression E1, E2;\ndiff --git a/sequencer.c b/sequencer.c\nindex 84bf598c3e..305de743a0 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -4545,7 +4545,7 @@ int skip_unnecessary_picks(void)\n \t\tif (item->commit->parents->next)\n \t\t\tbreak; /* merge commit */\n \t\tparent_oid = &item->commit->parents->item->object.oid;\n-\t\tif (hashcmp(parent_oid->hash, oid->hash))\n+\t\tif (oidcmp(parent_oid, oid))\n \t\t\tbreak;\n \t\toid = &item->commit->object.oid;\n \t}\n-- \n2.19.0.rc0.584.g84d5b2a847\n\n"},{"id":"356753","messageId":"20180828212235.GB11036@sigill.intra.peff.net","threadId":"49212","inReplyTo":"20180828212126.GA7039@sigill.intra.peff.net","subject":"[PATCH v2 2/9] introduce hasheq() and oideq()","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2018-08-28T21:22:35Z","receivedAt":"2018-08-28T21:22:38Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"The main comparison functions we provide for comparing\nobject ids are hashcmp() and oidcmp(). These are more\nflexible than a strict equality check, since they also\nexpress ordering. That makes them useful for sorting and\nbinary searching. However, it also makes them potentially\nslower than a strict equality check. Consider this C code,\nwhich is traditionally what our hashcmp has looked like:\n\n  #include <string.h>\n  int hashcmp(const unsigned char *a, const unsigned char *b)\n  {\n          return memcmp(a, b, 20);\n  }\n\nCompiling with \"gcc -O2 -S -fverbose-asm\", the generated\nassembly shows that we actually call memcmp(). But if we\nchange this to a strict equality check:\n\n          return !memcmp(a, b, 20);\n\nwe get a faster inline version:\n\n          movq    (%rdi), %rax    # MEM[(void *)a_4(D)], MEM[(void *)a_4(D)]\n          movq    8(%rdi), %rdx   # MEM[(void *)a_4(D)], tmp101\n          xorq    (%rsi), %rax    # MEM[(void *)b_5(D)], tmp94\n          xorq    8(%rsi), %rdx   # MEM[(void *)b_5(D)], tmp93\n          orq     %rax, %rdx      # tmp94, tmp93\n          jne     .L2     #,\n          movl    16(%rsi), %eax  # MEM[(void *)b_5(D)], tmp104\n          cmpl    %eax, 16(%rdi)  # tmp104, MEM[(void *)a_4(D)]\n          je      .L5     #,\n\nObviously our hashcmp() doesn't include the \"!\". But because\nit's an inline function, optimizing compilers are able to\nsee \"!hashcmp(a,b)\" in calling code and take advantage of\nthis case. So there has been no value thus far in\nintroducing a more restricted interface for doing strict\nequality checks.\n\nBut as Git learns about more values for the_hash_algo, our\nhashcmp() will grow more complicated and may even delegate\nat runtime to functions optimized specifically for that hash\nsize. That breaks the inline connection we have, and the\ncompiler will have to assume that the caller really cares\nabout the sign and magnitude of the memcmp() result, even\nthough the vast majority don't.\n\nWe can solve that by introducing a hasheq() function (and\nmatching oideq() wrapper), which callers can use to make it\nclear that they only care about equality. For now, the\nimplementation will literally be \"!hashcmp()\", but it frees\nus up later to introduce code optimized specifically for the\nequality check.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n cache.h | 10 ++++++++++\n 1 file changed, 10 insertions(+)\n\ndiff --git a/cache.h b/cache.h\nindex 4d014541ab..f6d227fac7 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1041,6 +1041,16 @@ static inline int oidcmp(const struct object_id *oid1, const struct object_id *o\n \treturn hashcmp(oid1->hash, oid2->hash);\n }\n \n+static inline int hasheq(const unsigned char *sha1, const unsigned char *sha2)\n+{\n+\treturn !hashcmp(sha1, sha2);\n+}\n+\n+static inline int oideq(const struct object_id *oid1, const struct object_id *oid2)\n+{\n+\treturn hasheq(oid1->hash, oid2->hash);\n+}\n+\n static inline int is_null_sha1(const unsigned char *sha1)\n {\n \treturn !hashcmp(sha1, null_sha1);\n-- \n2.19.0.rc0.584.g84d5b2a847\n\n"},{"id":"356754","messageId":"20180828212240.GC11036@sigill.intra.peff.net","threadId":"49212","inReplyTo":"20180828212126.GA7039@sigill.intra.peff.net","subject":"[PATCH v2 3/9] convert \"oidcmp() == 0\" to oideq()","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2018-08-28T21:22:40Z","receivedAt":"2018-08-28T21:22:46Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"Using the more restrictive oideq() should, in the long run,\ngive the compiler more opportunities to optimize these\ncallsites. For now, this conversion should be a complete\nnoop with respect to the generated code.\n\nThe result is also perhaps a little more readable, as it\navoids the \"zero is equal\" idiom. Since it's so prevalent in\nC, I think seasoned programmers tend not to even notice it\nanymore, but it can sometimes make for awkward double\nnegations (e.g., we can drop a few !!oidcmp() instances\nhere).\n\nThis patch was generated almost entirely by the included\ncoccinelle patch. This mechanical conversion should be\ncompletely safe, because we check explicitly for cases where\noidcmp() is compared to 0, which is what oideq() is doing\nunder the hood. Note that we don't have to catch \"!oidcmp()\"\nseparately; coccinelle's standard isomorphisms make sure the\ntwo are treated equivalently.\n\nI say \"almost\" because I did hand-edit the coccinelle output\nto fix up a few style violations (it mostly keeps the\noriginal formatting, but sometimes unwraps long lines).\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n bisect.c                           |  4 ++--\n blame.c                            |  4 ++--\n builtin/am.c                       |  2 +-\n builtin/checkout.c                 |  2 +-\n builtin/describe.c                 |  4 ++--\n builtin/diff.c                     |  2 +-\n builtin/difftool.c                 |  4 ++--\n builtin/fast-export.c              |  2 +-\n builtin/fetch.c                    |  4 ++--\n builtin/fmt-merge-msg.c            |  2 +-\n builtin/index-pack.c               |  4 ++--\n builtin/log.c                      |  6 +++---\n builtin/merge-tree.c               |  2 +-\n builtin/merge.c                    |  4 ++--\n builtin/pack-objects.c             |  4 ++--\n builtin/pull.c                     |  2 +-\n builtin/receive-pack.c             |  4 ++--\n builtin/remote.c                   |  2 +-\n builtin/replace.c                  |  6 +++---\n builtin/unpack-objects.c           |  2 +-\n builtin/update-index.c             |  4 ++--\n bulk-checkin.c                     |  2 +-\n cache-tree.c                       |  2 +-\n cache.h                            |  4 ++--\n combine-diff.c                     |  4 ++--\n commit-graph.c                     |  2 +-\n connect.c                          |  2 +-\n contrib/coccinelle/object_id.cocci |  6 ++++++\n diff-lib.c                         |  2 +-\n diff.c                             |  6 +++---\n diffcore-break.c                   |  2 +-\n fast-import.c                      |  6 +++---\n http-push.c                        |  2 +-\n log-tree.c                         |  6 +++---\n merge-recursive.c                  |  4 ++--\n notes-merge.c                      | 24 +++++++++++-----------\n notes.c                            |  4 ++--\n pack-write.c                       |  2 +-\n read-cache.c                       |  2 +-\n ref-filter.c                       |  2 +-\n refs/files-backend.c               |  4 ++--\n remote.c                           |  6 +++---\n revision.c                         |  2 +-\n sequencer.c                        | 32 +++++++++++++++---------------\n sha1-array.c                       |  2 +-\n sha1-file.c                        |  4 ++--\n sha1-name.c                        |  2 +-\n submodule.c                        |  2 +-\n transport.c                        |  2 +-\n unpack-trees.c                     |  6 +++---\n wt-status.c                        | 10 +++++-----\n xdiff-interface.c                  |  2 +-\n 52 files changed, 117 insertions(+), 111 deletions(-)\n\ndiff --git a/bisect.c b/bisect.c\nindex e1275ba79e..41c56a665e 100644\n--- a/bisect.c\n+++ b/bisect.c\n@@ -807,7 +807,7 @@ static void check_merge_bases(int rev_nr, struct commit **rev, int no_checkout)\n \n \tfor (; result; result = result->next) {\n \t\tconst struct object_id *mb = &result->item->object.oid;\n-\t\tif (!oidcmp(mb, current_bad_oid)) {\n+\t\tif (oideq(mb, current_bad_oid)) {\n \t\t\thandle_bad_merge_base();\n \t\t} else if (0 <= oid_array_lookup(&good_revs, mb)) {\n \t\t\tcontinue;\n@@ -988,7 +988,7 @@ int bisect_next_all(const char *prefix, int no_checkout)\n \n \tbisect_rev = &revs.commits->item->object.oid;\n \n-\tif (!oidcmp(bisect_rev, current_bad_oid)) {\n+\tif (oideq(bisect_rev, current_bad_oid)) {\n \t\texit_if_skipped_commits(tried, current_bad_oid);\n \t\tprintf(\"%s is the first %s commit\\n\", oid_to_hex(bisect_rev),\n \t\t\tterm_bad);\ndiff --git a/blame.c b/blame.c\nindex aca06f4b12..c47d7050d9 100644\n--- a/blame.c\n+++ b/blame.c\n@@ -1457,14 +1457,14 @@ static void pass_blame(struct blame_scoreboard *sb, struct blame_origin *origin,\n \t\t\tporigin = find(p, origin);\n \t\t\tif (!porigin)\n \t\t\t\tcontinue;\n-\t\t\tif (!oidcmp(&porigin->blob_oid, &origin->blob_oid)) {\n+\t\t\tif (oideq(&porigin->blob_oid, &origin->blob_oid)) {\n \t\t\t\tpass_whole_blame(sb, origin, porigin);\n \t\t\t\tblame_origin_decref(porigin);\n \t\t\t\tgoto finish;\n \t\t\t}\n \t\t\tfor (j = same = 0; j < i; j++)\n \t\t\t\tif (sg_origin[j] &&\n-\t\t\t\t    !oidcmp(&sg_origin[j]->blob_oid, &porigin->blob_oid)) {\n+\t\t\t\t    oideq(&sg_origin[j]->blob_oid, &porigin->blob_oid)) {\n \t\t\t\t\tsame = 1;\n \t\t\t\t\tbreak;\n \t\t\t\t}\ndiff --git a/builtin/am.c b/builtin/am.c\nindex 9f7ecf6ecb..e54110d474 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -2077,7 +2077,7 @@ static int safe_to_abort(const struct am_state *state)\n \tif (get_oid(\"HEAD\", &head))\n \t\toidclr(&head);\n \n-\tif (!oidcmp(&head, &abort_safety))\n+\tif (oideq(&head, &abort_safety))\n \t\treturn 1;\n \n \twarning(_(\"You seem to have moved HEAD since the last 'am' failure.\\n\"\ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex 29ef50013d..082e3a9f19 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -96,7 +96,7 @@ static int update_some(const struct object_id *oid, struct strbuf *base,\n \tif (pos >= 0) {\n \t\tstruct cache_entry *old = active_cache[pos];\n \t\tif (ce->ce_mode == old->ce_mode &&\n-\t\t    !oidcmp(&ce->oid, &old->oid)) {\n+\t\t    oideq(&ce->oid, &old->oid)) {\n \t\t\told->ce_flags |= CE_UPDATE;\n \t\t\tdiscard_cache_entry(ce);\n \t\t\treturn 0;\ndiff --git a/builtin/describe.c b/builtin/describe.c\nindex 41606c8a90..1e7c75ba82 100644\n--- a/builtin/describe.c\n+++ b/builtin/describe.c\n@@ -190,7 +190,7 @@ static int get_name(const char *path, const struct object_id *oid, int flag, voi\n \n \t/* Is it annotated? */\n \tif (!peel_ref(path, &peeled)) {\n-\t\tis_annotated = !!oidcmp(oid, &peeled);\n+\t\tis_annotated = !oideq(oid, &peeled);\n \t} else {\n \t\toidcpy(&peeled, oid);\n \t\tis_annotated = 0;\n@@ -469,7 +469,7 @@ static void process_object(struct object *obj, const char *path, void *data)\n {\n \tstruct process_commit_data *pcd = data;\n \n-\tif (!oidcmp(&pcd->looking_for, &obj->oid) && !pcd->dst->len) {\n+\tif (oideq(&pcd->looking_for, &obj->oid) && !pcd->dst->len) {\n \t\treset_revision_walk();\n \t\tdescribe_commit(&pcd->current_commit, pcd->dst);\n \t\tstrbuf_addf(pcd->dst, \":%s\", path);\ndiff --git a/builtin/diff.c b/builtin/diff.c\nindex 361a3c3ed3..b3a8ba488f 100644\n--- a/builtin/diff.c\n+++ b/builtin/diff.c\n@@ -41,7 +41,7 @@ static void stuff_change(struct diff_options *opt,\n \tstruct diff_filespec *one, *two;\n \n \tif (!is_null_oid(old_oid) && !is_null_oid(new_oid) &&\n-\t    !oidcmp(old_oid, new_oid) && (old_mode == new_mode))\n+\t    oideq(old_oid, new_oid) && (old_mode == new_mode))\n \t\treturn;\n \n \tif (opt->flags.reverse_diff) {\ndiff --git a/builtin/difftool.c b/builtin/difftool.c\nindex cdd585ca76..b41a9199ff 100644\n--- a/builtin/difftool.c\n+++ b/builtin/difftool.c\n@@ -116,7 +116,7 @@ static int use_wt_file(const char *workdir, const char *name,\n \t\t\tif (is_null_oid(oid)) {\n \t\t\t\toidcpy(oid, &wt_oid);\n \t\t\t\tuse = 1;\n-\t\t\t} else if (!oidcmp(oid, &wt_oid))\n+\t\t\t} else if (oideq(oid, &wt_oid))\n \t\t\t\tuse = 1;\n \t\t}\n \t}\n@@ -438,7 +438,7 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,\n \t\t\tstrbuf_reset(&buf);\n \t\t\tstrbuf_addf(&buf, \"Subproject commit %s\",\n \t\t\t\t    oid_to_hex(&roid));\n-\t\t\tif (!oidcmp(&loid, &roid))\n+\t\t\tif (oideq(&loid, &roid))\n \t\t\t\tstrbuf_addstr(&buf, \"-dirty\");\n \t\t\tadd_left_or_right(&submodules, dst_path, buf.buf, 1);\n \t\t\tcontinue;\ndiff --git a/builtin/fast-export.c b/builtin/fast-export.c\nindex 9bd8a14b57..74f3bf5c96 100644\n--- a/builtin/fast-export.c\n+++ b/builtin/fast-export.c\n@@ -384,7 +384,7 @@ static void show_filemodify(struct diff_queue_struct *q,\n \t\t\t\tstring_list_insert(changed, spec->path);\n \t\t\t\tputchar('\\n');\n \n-\t\t\t\tif (!oidcmp(&ospec->oid, &spec->oid) &&\n+\t\t\t\tif (oideq(&ospec->oid, &spec->oid) &&\n \t\t\t\t    ospec->mode == spec->mode)\n \t\t\t\t\tbreak;\n \t\t\t}\ndiff --git a/builtin/fetch.c b/builtin/fetch.c\nindex 61bec5d213..32b1d5d383 100644\n--- a/builtin/fetch.c\n+++ b/builtin/fetch.c\n@@ -507,7 +507,7 @@ static void adjust_refcol_width(const struct ref *ref)\n \tint max, rlen, llen, len;\n \n \t/* uptodate lines are only shown on high verbosity level */\n-\tif (!verbosity && !oidcmp(&ref->peer_ref->old_oid, &ref->old_oid))\n+\tif (!verbosity && oideq(&ref->peer_ref->old_oid, &ref->old_oid))\n \t\treturn;\n \n \tmax    = term_columns();\n@@ -644,7 +644,7 @@ static int update_local_ref(struct ref *ref,\n \tif (type < 0)\n \t\tdie(_(\"object %s not found\"), oid_to_hex(&ref->new_oid));\n \n-\tif (!oidcmp(&ref->old_oid, &ref->new_oid)) {\n+\tif (oideq(&ref->old_oid, &ref->new_oid)) {\n \t\tif (verbosity > 0)\n \t\t\tformat_display(display, '=', _(\"[up to date]\"), NULL,\n \t\t\t\t       remote, pretty_ref, summary_width);\ndiff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c\nindex f35ff1612b..4c82c234cb 100644\n--- a/builtin/fmt-merge-msg.c\n+++ b/builtin/fmt-merge-msg.c\n@@ -582,7 +582,7 @@ static void find_merge_parents(struct merge_parents *result,\n \twhile (parents) {\n \t\tstruct commit *cmit = pop_commit(&parents);\n \t\tfor (i = 0; i < result->nr; i++)\n-\t\t\tif (!oidcmp(&result->item[i].commit, &cmit->object.oid))\n+\t\t\tif (oideq(&result->item[i].commit, &cmit->object.oid))\n \t\t\t\tresult->item[i].used = 1;\n \t}\n \ndiff --git a/builtin/index-pack.c b/builtin/index-pack.c\nindex 9582ead950..edcb0a3dca 100644\n--- a/builtin/index-pack.c\n+++ b/builtin/index-pack.c\n@@ -719,9 +719,9 @@ static void find_ref_delta_children(const struct object_id *oid,\n \t\t*last_index = -1;\n \t\treturn;\n \t}\n-\twhile (first > 0 && !oidcmp(&ref_deltas[first - 1].oid, oid))\n+\twhile (first > 0 && oideq(&ref_deltas[first - 1].oid, oid))\n \t\t--first;\n-\twhile (last < end && !oidcmp(&ref_deltas[last + 1].oid, oid))\n+\twhile (last < end && oideq(&ref_deltas[last + 1].oid, oid))\n \t\t++last;\n \t*first_index = first;\n \t*last_index = last;\ndiff --git a/builtin/log.c b/builtin/log.c\nindex e094560d9a..98d668b56f 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -992,7 +992,7 @@ static char *find_branch_name(struct rev_info *rev)\n \ttip_oid = &rev->cmdline.rev[positive].item->oid;\n \tif (dwim_ref(ref, strlen(ref), &branch_oid, &full_ref) &&\n \t    skip_prefix(full_ref, \"refs/heads/\", &v) &&\n-\t    !oidcmp(tip_oid, &branch_oid))\n+\t    oideq(tip_oid, &branch_oid))\n \t\tbranch = xstrdup(v);\n \tfree(full_ref);\n \treturn branch;\n@@ -1703,7 +1703,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t\t/* Don't say anything if head and upstream are the same. */\n \t\tif (rev.pending.nr == 2) {\n \t\t\tstruct object_array_entry *o = rev.pending.objects;\n-\t\t\tif (oidcmp(&o[0].item->oid, &o[1].item->oid) == 0)\n+\t\t\tif (oideq(&o[0].item->oid, &o[1].item->oid))\n \t\t\t\treturn 0;\n \t\t}\n \t\tget_patch_ids(&rev, &ids);\n@@ -1949,7 +1949,7 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)\n \t/* Don't say anything if head and upstream are the same. */\n \tif (revs.pending.nr == 2) {\n \t\tstruct object_array_entry *o = revs.pending.objects;\n-\t\tif (oidcmp(&o[0].item->oid, &o[1].item->oid) == 0)\n+\t\tif (oideq(&o[0].item->oid, &o[1].item->oid))\n \t\t\treturn 0;\n \t}\n \ndiff --git a/builtin/merge-tree.c b/builtin/merge-tree.c\nindex f8023bae1e..8cea8a74f2 100644\n--- a/builtin/merge-tree.c\n+++ b/builtin/merge-tree.c\n@@ -155,7 +155,7 @@ static int same_entry(struct name_entry *a, struct name_entry *b)\n {\n \treturn\ta->oid &&\n \t\tb->oid &&\n-\t\t!oidcmp(a->oid, b->oid) &&\n+\t\toideq(a->oid, b->oid) &&\n \t\ta->mode == b->mode;\n }\n \ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex 8f4a5065c2..57abff999b 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -1189,7 +1189,7 @@ static int merging_a_throwaway_tag(struct commit *commit)\n \ttag_ref = xstrfmt(\"refs/tags/%s\",\n \t\t\t  ((struct tag *)merge_remote_util(commit)->obj)->tag);\n \tif (!read_ref(tag_ref, &oid) &&\n-\t    !oidcmp(&oid, &merge_remote_util(commit)->obj->oid))\n+\t    oideq(&oid, &merge_remote_util(commit)->obj->oid))\n \t\tis_throwaway_tag = 0;\n \telse\n \t\tis_throwaway_tag = 1;\n@@ -1448,7 +1448,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \t\tgoto done;\n \t} else if (fast_forward != FF_NO && !remoteheads->next &&\n \t\t\t!common->next &&\n-\t\t\t!oidcmp(&common->item->object.oid, &head_commit->object.oid)) {\n+\t\t\toideq(&common->item->object.oid, &head_commit->object.oid)) {\n \t\t/* Again the most common case of merging one remote. */\n \t\tstruct strbuf msg = STRBUF_INIT;\n \t\tstruct commit *commit;\ndiff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\nindex d1144a8f7e..64156f676b 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -1202,7 +1202,7 @@ static struct pbase_tree_cache *pbase_tree_get(const struct object_id *oid)\n \t */\n \tfor (neigh = 0; neigh < 8; neigh++) {\n \t\tent = pbase_tree_cache[my_ix];\n-\t\tif (ent && !oidcmp(&ent->oid, oid)) {\n+\t\tif (ent && oideq(&ent->oid, oid)) {\n \t\t\tent->ref++;\n \t\t\treturn ent;\n \t\t}\n@@ -1384,7 +1384,7 @@ static void add_preferred_base(struct object_id *oid)\n \t\treturn;\n \n \tfor (it = pbase_tree; it; it = it->next) {\n-\t\tif (!oidcmp(&it->pcache.oid, &tree_oid)) {\n+\t\tif (oideq(&it->pcache.oid, &tree_oid)) {\n \t\t\tfree(data);\n \t\t\treturn;\n \t\t}\ndiff --git a/builtin/pull.c b/builtin/pull.c\nindex 681c127a07..a720f58a96 100644\n--- a/builtin/pull.c\n+++ b/builtin/pull.c\n@@ -799,7 +799,7 @@ static int run_rebase(const struct object_id *curr_head,\n \tstruct argv_array args = ARGV_ARRAY_INIT;\n \n \tif (!get_octopus_merge_base(&oct_merge_base, curr_head, merge_head, fork_point))\n-\t\tif (!is_null_oid(fork_point) && !oidcmp(&oct_merge_base, fork_point))\n+\t\tif (!is_null_oid(fork_point) && oideq(&oct_merge_base, fork_point))\n \t\t\tfork_point = NULL;\n \n \targv_array_push(&args, \"rebase\");\ndiff --git a/builtin/receive-pack.c b/builtin/receive-pack.c\nindex c17ce94e12..5bb163d4d2 100644\n--- a/builtin/receive-pack.c\n+++ b/builtin/receive-pack.c\n@@ -1222,8 +1222,8 @@ static void check_aliased_update(struct command *cmd, struct string_list *list)\n \n \tdst_cmd = (struct command *) item->util;\n \n-\tif (!oidcmp(&cmd->old_oid, &dst_cmd->old_oid) &&\n-\t    !oidcmp(&cmd->new_oid, &dst_cmd->new_oid))\n+\tif (oideq(&cmd->old_oid, &dst_cmd->old_oid) &&\n+\t    oideq(&cmd->new_oid, &dst_cmd->new_oid))\n \t\treturn;\n \n \tdst_cmd->skip_update = 1;\ndiff --git a/builtin/remote.c b/builtin/remote.c\nindex 7876db1c20..c171323e0e 100644\n--- a/builtin/remote.c\n+++ b/builtin/remote.c\n@@ -412,7 +412,7 @@ static int get_push_ref_states(const struct ref *remote_refs,\n \n \t\tif (is_null_oid(&ref->new_oid)) {\n \t\t\tinfo->status = PUSH_STATUS_DELETE;\n-\t\t} else if (!oidcmp(&ref->old_oid, &ref->new_oid))\n+\t\t} else if (oideq(&ref->old_oid, &ref->new_oid))\n \t\t\tinfo->status = PUSH_STATUS_UPTODATE;\n \t\telse if (is_null_oid(&ref->old_oid))\n \t\t\tinfo->status = PUSH_STATUS_CREATE;\ndiff --git a/builtin/replace.c b/builtin/replace.c\nindex 4f05791f3e..8e67e09819 100644\n--- a/builtin/replace.c\n+++ b/builtin/replace.c\n@@ -343,7 +343,7 @@ static int edit_and_replace(const char *object_ref, int force, int raw)\n \t}\n \tfree(tmpfile);\n \n-\tif (!oidcmp(&old_oid, &new_oid))\n+\tif (oideq(&old_oid, &new_oid))\n \t\treturn error(_(\"new object is the same as the old one: '%s'\"), oid_to_hex(&old_oid));\n \n \treturn replace_object_oid(object_ref, &old_oid, \"replacement\", &new_oid, force);\n@@ -414,7 +414,7 @@ static int check_one_mergetag(struct commit *commit,\n \t\tif (get_oid(mergetag_data->argv[i], &oid) < 0)\n \t\t\treturn error(_(\"not a valid object name: '%s'\"),\n \t\t\t\t     mergetag_data->argv[i]);\n-\t\tif (!oidcmp(&tag->tagged->oid, &oid))\n+\t\tif (oideq(&tag->tagged->oid, &oid))\n \t\t\treturn 0; /* found */\n \t}\n \n@@ -474,7 +474,7 @@ static int create_graft(int argc, const char **argv, int force, int gentle)\n \n \tstrbuf_release(&buf);\n \n-\tif (!oidcmp(&old_oid, &new_oid)) {\n+\tif (oideq(&old_oid, &new_oid)) {\n \t\tif (gentle) {\n \t\t\twarning(_(\"graft for '%s' unnecessary\"), oid_to_hex(&old_oid));\n \t\t\treturn 0;\ndiff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c\nindex 30d9413b4b..ad438f5b41 100644\n--- a/builtin/unpack-objects.c\n+++ b/builtin/unpack-objects.c\n@@ -303,7 +303,7 @@ static void added_object(unsigned nr, enum object_type type,\n \tstruct delta_info *info;\n \n \twhile ((info = *p) != NULL) {\n-\t\tif (!oidcmp(&info->base_oid, &obj_list[nr].oid) ||\n+\t\tif (oideq(&info->base_oid, &obj_list[nr].oid) ||\n \t\t    info->base_offset == obj_list[nr].offset) {\n \t\t\t*p = info->next;\n \t\t\tp = &delta_list;\ndiff --git a/builtin/update-index.c b/builtin/update-index.c\nindex fe84003b4f..e7fab78b3b 100644\n--- a/builtin/update-index.c\n+++ b/builtin/update-index.c\n@@ -669,7 +669,7 @@ static int unresolve_one(const char *path)\n \t\tret = -1;\n \t\tgoto free_return;\n \t}\n-\tif (!oidcmp(&ce_2->oid, &ce_3->oid) &&\n+\tif (oideq(&ce_2->oid, &ce_3->oid) &&\n \t    ce_2->ce_mode == ce_3->ce_mode) {\n \t\tfprintf(stderr, \"%s: identical in both, skipping.\\n\",\n \t\t\tpath);\n@@ -754,7 +754,7 @@ static int do_reupdate(int ac, const char **av,\n \t\t\told = read_one_ent(NULL, &head_oid,\n \t\t\t\t\t   ce->name, ce_namelen(ce), 0);\n \t\tif (old && ce->ce_mode == old->ce_mode &&\n-\t\t    !oidcmp(&ce->oid, &old->oid)) {\n+\t\t    oideq(&ce->oid, &old->oid)) {\n \t\t\tdiscard_cache_entry(old);\n \t\t\tcontinue; /* unchanged */\n \t\t}\ndiff --git a/bulk-checkin.c b/bulk-checkin.c\nindex 9f3b644811..409ecb566b 100644\n--- a/bulk-checkin.c\n+++ b/bulk-checkin.c\n@@ -72,7 +72,7 @@ static int already_written(struct bulk_checkin_state *state, struct object_id *o\n \n \t/* Might want to keep the list sorted */\n \tfor (i = 0; i < state->nr_written; i++)\n-\t\tif (!oidcmp(&state->written[i]->oid, oid))\n+\t\tif (oideq(&state->written[i]->oid, oid))\n \t\t\treturn 1;\n \n \t/* This is a new object we need to keep */\ndiff --git a/cache-tree.c b/cache-tree.c\nindex 16ea022c46..b49bb5c5be 100644\n--- a/cache-tree.c\n+++ b/cache-tree.c\n@@ -714,7 +714,7 @@ int cache_tree_matches_traversal(struct cache_tree *root,\n \n \tit = find_cache_tree_from_traversal(root, info);\n \tit = cache_tree_find(it, ent->path);\n-\tif (it && it->entry_count > 0 && !oidcmp(ent->oid, &it->oid))\n+\tif (it && it->entry_count > 0 && oideq(ent->oid, &it->oid))\n \t\treturn it->entry_count;\n \treturn 0;\n }\ndiff --git a/cache.h b/cache.h\nindex f6d227fac7..d090f71706 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1100,7 +1100,7 @@ static inline int is_empty_blob_sha1(const unsigned char *sha1)\n \n static inline int is_empty_blob_oid(const struct object_id *oid)\n {\n-\treturn !oidcmp(oid, the_hash_algo->empty_blob);\n+\treturn oideq(oid, the_hash_algo->empty_blob);\n }\n \n static inline int is_empty_tree_sha1(const unsigned char *sha1)\n@@ -1110,7 +1110,7 @@ static inline int is_empty_tree_sha1(const unsigned char *sha1)\n \n static inline int is_empty_tree_oid(const struct object_id *oid)\n {\n-\treturn !oidcmp(oid, the_hash_algo->empty_tree);\n+\treturn oideq(oid, the_hash_algo->empty_tree);\n }\n \n const char *empty_tree_oid_hex(void);\ndiff --git a/combine-diff.c b/combine-diff.c\nindex de7695e728..0fed4ca529 100644\n--- a/combine-diff.c\n+++ b/combine-diff.c\n@@ -1138,8 +1138,8 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,\n \tfor (i = 0; i < num_parent; i++) {\n \t\tint j;\n \t\tfor (j = 0; j < i; j++) {\n-\t\t\tif (!oidcmp(&elem->parent[i].oid,\n-\t\t\t\t     &elem->parent[j].oid)) {\n+\t\t\tif (oideq(&elem->parent[i].oid,\n+\t\t\t\t  &elem->parent[j].oid)) {\n \t\t\t\treuse_combine_diff(sline, cnt, i, j);\n \t\t\t\tbreak;\n \t\t\t}\ndiff --git a/commit-graph.c b/commit-graph.c\nindex 8a1bec7b8a..050c516b0d 100644\n--- a/commit-graph.c\n+++ b/commit-graph.c\n@@ -779,7 +779,7 @@ void write_commit_graph(const char *obj_dir,\n \tnum_extra_edges = 0;\n \tfor (i = 0; i < oids.nr; i++) {\n \t\tint num_parents = 0;\n-\t\tif (i > 0 && !oidcmp(&oids.list[i-1], &oids.list[i]))\n+\t\tif (i > 0 && oideq(&oids.list[i - 1], &oids.list[i]))\n \t\t\tcontinue;\n \n \t\tcommits.list[commits.nr] = lookup_commit(the_repository, &oids.list[i]);\ndiff --git a/connect.c b/connect.c\nindex 94547e5056..24281b6082 100644\n--- a/connect.c\n+++ b/connect.c\n@@ -224,7 +224,7 @@ static int process_dummy_ref(const char *line)\n \t\treturn 0;\n \tname++;\n \n-\treturn !oidcmp(&null_oid, &oid) && !strcmp(name, \"capabilities^{}\");\n+\treturn oideq(&null_oid, &oid) && !strcmp(name, \"capabilities^{}\");\n }\n \n static void check_no_capabilities(const char *line, int len)\ndiff --git a/contrib/coccinelle/object_id.cocci b/contrib/coccinelle/object_id.cocci\nindex 5869979be7..548c02336d 100644\n--- a/contrib/coccinelle/object_id.cocci\n+++ b/contrib/coccinelle/object_id.cocci\n@@ -108,3 +108,9 @@ expression E1, E2;\n @@\n - hashcpy(E1.hash, E2->hash)\n + oidcpy(&E1, E2)\n+\n+@@\n+expression E1, E2;\n+@@\n+- oidcmp(E1, E2) == 0\n++ oideq(E1, E2)\ndiff --git a/diff-lib.c b/diff-lib.c\nindex 88a98b1c06..c1f5a52654 100644\n--- a/diff-lib.c\n+++ b/diff-lib.c\n@@ -366,7 +366,7 @@ static int show_modified(struct rev_info *revs,\n \t}\n \n \toldmode = old_entry->ce_mode;\n-\tif (mode == oldmode && !oidcmp(oid, &old_entry->oid) && !dirty_submodule &&\n+\tif (mode == oldmode && oideq(oid, &old_entry->oid) && !dirty_submodule &&\n \t    !revs->diffopt.flags.find_copies_harder)\n \t\treturn 0;\n \ndiff --git a/diff.c b/diff.c\nindex 145cfbae59..5cada68267 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -3404,7 +3404,7 @@ static void builtin_diff(const char *name_a,\n \t\tif (!one->data && !two->data &&\n \t\t    S_ISREG(one->mode) && S_ISREG(two->mode) &&\n \t\t    !o->flags.binary) {\n-\t\t\tif (!oidcmp(&one->oid, &two->oid)) {\n+\t\t\tif (oideq(&one->oid, &two->oid)) {\n \t\t\t\tif (must_show_header)\n \t\t\t\t\temit_diff_symbol(o, DIFF_SYMBOL_HEADER,\n \t\t\t\t\t\t\t header.buf, header.len,\n@@ -3569,7 +3569,7 @@ static void builtin_diffstat(const char *name_a, const char *name_b,\n \t\treturn;\n \t}\n \n-\tsame_contents = !oidcmp(&one->oid, &two->oid);\n+\tsame_contents = oideq(&one->oid, &two->oid);\n \n \tif (diff_filespec_is_binary(one) || diff_filespec_is_binary(two)) {\n \t\tdata->is_binary = 1;\n@@ -5323,7 +5323,7 @@ int diff_unmodified_pair(struct diff_filepair *p)\n \t * dealing with a change.\n \t */\n \tif (one->oid_valid && two->oid_valid &&\n-\t    !oidcmp(&one->oid, &two->oid) &&\n+\t    oideq(&one->oid, &two->oid) &&\n \t    !one->dirty_submodule && !two->dirty_submodule)\n \t\treturn 1; /* no change */\n \tif (!one->oid_valid && !two->oid_valid)\ndiff --git a/diffcore-break.c b/diffcore-break.c\nindex c64359f489..e11fcfdb39 100644\n--- a/diffcore-break.c\n+++ b/diffcore-break.c\n@@ -58,7 +58,7 @@ static int should_break(struct diff_filespec *src,\n \t}\n \n \tif (src->oid_valid && dst->oid_valid &&\n-\t    !oidcmp(&src->oid, &dst->oid))\n+\t    oideq(&src->oid, &dst->oid))\n \t\treturn 0; /* they are the same */\n \n \tif (diff_populate_filespec(src, 0) || diff_populate_filespec(dst, 0))\ndiff --git a/fast-import.c b/fast-import.c\nindex 89bb0c9db3..a731088f96 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -572,7 +572,7 @@ static struct object_entry *find_object(struct object_id *oid)\n \tunsigned int h = oid->hash[0] << 8 | oid->hash[1];\n \tstruct object_entry *e;\n \tfor (e = object_table[h]; e; e = e->next)\n-\t\tif (!oidcmp(oid, &e->idx.oid))\n+\t\tif (oideq(oid, &e->idx.oid))\n \t\t\treturn e;\n \treturn NULL;\n }\n@@ -583,7 +583,7 @@ static struct object_entry *insert_object(struct object_id *oid)\n \tstruct object_entry *e = object_table[h];\n \n \twhile (e) {\n-\t\tif (!oidcmp(oid, &e->idx.oid))\n+\t\tif (oideq(oid, &e->idx.oid))\n \t\t\treturn e;\n \t\te = e->next;\n \t}\n@@ -1533,7 +1533,7 @@ static int tree_content_set(\n \t\t\tif (!*slash1) {\n \t\t\t\tif (!S_ISDIR(mode)\n \t\t\t\t\t\t&& e->versions[1].mode == mode\n-\t\t\t\t\t\t&& !oidcmp(&e->versions[1].oid, oid))\n+\t\t\t\t\t\t&& oideq(&e->versions[1].oid, oid))\n \t\t\t\t\treturn 0;\n \t\t\t\te->versions[1].mode = mode;\n \t\t\t\toidcpy(&e->versions[1].oid, oid);\ndiff --git a/http-push.c b/http-push.c\nindex 5eaf551b51..283495c18a 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -1859,7 +1859,7 @@ int cmd_main(int argc, const char **argv)\n \t\t\tcontinue;\n \t\t}\n \n-\t\tif (!oidcmp(&ref->old_oid, &ref->peer_ref->new_oid)) {\n+\t\tif (oideq(&ref->old_oid, &ref->peer_ref->new_oid)) {\n \t\t\tif (push_verbosely)\n \t\t\t\tfprintf(stderr, \"'%s': up-to-date\\n\", ref->name);\n \t\t\tif (helper_status)\ndiff --git a/log-tree.c b/log-tree.c\nindex 7443e5fcc7..2edff78cff 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -472,7 +472,7 @@ static int which_parent(const struct object_id *oid, const struct commit *commit\n \tconst struct commit_list *parent;\n \n \tfor (nth = 0, parent = commit->parents; parent; parent = parent->next) {\n-\t\tif (!oidcmp(&parent->item->object.oid, oid))\n+\t\tif (oideq(&parent->item->object.oid, oid))\n \t\t\treturn nth;\n \t\tnth++;\n \t}\n@@ -506,8 +506,8 @@ static int show_one_mergetag(struct commit *commit,\n \tif (parse_tag_buffer(the_repository, tag, extra->value, extra->len))\n \t\tstrbuf_addstr(&verify_message, \"malformed mergetag\\n\");\n \telse if (is_common_merge(commit) &&\n-\t\t !oidcmp(&tag->tagged->oid,\n-\t\t\t  &commit->parents->next->item->object.oid))\n+\t\t oideq(&tag->tagged->oid,\n+\t\t       &commit->parents->next->item->object.oid))\n \t\tstrbuf_addf(&verify_message,\n \t\t\t    \"merged tag '%s'\\n\", tag->tag);\n \telse if ((nth = which_parent(&tag->tagged->oid, commit)) < 0)\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex dcdc93019c..2904cb825e 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -156,7 +156,7 @@ static struct tree *shift_tree_object(struct tree *one, struct tree *two,\n \t\tshift_tree_by(&one->object.oid, &two->object.oid, &shifted,\n \t\t\t      subtree_shift);\n \t}\n-\tif (!oidcmp(&two->object.oid, &shifted))\n+\tif (oideq(&two->object.oid, &shifted))\n \t\treturn two;\n \treturn lookup_tree(the_repository, &shifted);\n }\n@@ -179,7 +179,7 @@ static int oid_eq(const struct object_id *a, const struct object_id *b)\n {\n \tif (!a && !b)\n \t\treturn 2;\n-\treturn a && b && oidcmp(a, b) == 0;\n+\treturn a && b && oideq(a, b);\n }\n \n enum rename_type {\ndiff --git a/notes-merge.c b/notes-merge.c\nindex 76ab19e702..0a47e54cf8 100644\n--- a/notes-merge.c\n+++ b/notes-merge.c\n@@ -151,7 +151,7 @@ static struct notes_merge_pair *diff_tree_remote(struct notes_merge_options *o,\n \t\tmp = find_notes_merge_pair_pos(changes, len, &obj, 1, &occupied);\n \t\tif (occupied) {\n \t\t\t/* We've found an addition/deletion pair */\n-\t\t\tassert(!oidcmp(&mp->obj, &obj));\n+\t\t\tassert(oideq(&mp->obj, &obj));\n \t\t\tif (is_null_oid(&p->one->oid)) { /* addition */\n \t\t\t\tassert(is_null_oid(&mp->remote));\n \t\t\t\toidcpy(&mp->remote, &p->two->oid);\n@@ -218,7 +218,7 @@ static void diff_tree_local(struct notes_merge_options *o,\n \t\t\tcontinue;\n \t\t}\n \n-\t\tassert(!oidcmp(&mp->obj, &obj));\n+\t\tassert(oideq(&mp->obj, &obj));\n \t\tif (is_null_oid(&p->two->oid)) { /* deletion */\n \t\t\t/*\n \t\t\t * Either this is a true deletion (1), or it is part\n@@ -229,7 +229,7 @@ static void diff_tree_local(struct notes_merge_options *o,\n \t\t\t * (3) mp->local is uninitialized; set it to null_sha1\n \t\t\t *     (will be overwritten by following addition)\n \t\t\t */\n-\t\t\tif (!oidcmp(&mp->local, &uninitialized))\n+\t\t\tif (oideq(&mp->local, &uninitialized))\n \t\t\t\toidclr(&mp->local);\n \t\t} else if (is_null_oid(&p->one->oid)) { /* addition */\n \t\t\t/*\n@@ -241,7 +241,7 @@ static void diff_tree_local(struct notes_merge_options *o,\n \t\t\t * (3) mp->local is null_sha1;     set to p->two->sha1\n \t\t\t */\n \t\t\tassert(is_null_oid(&mp->local) ||\n-\t\t\t       !oidcmp(&mp->local, &uninitialized));\n+\t\t\t       oideq(&mp->local, &uninitialized));\n \t\t\toidcpy(&mp->local, &p->two->oid);\n \t\t} else { /* modification */\n \t\t\t/*\n@@ -249,8 +249,8 @@ static void diff_tree_local(struct notes_merge_options *o,\n \t\t\t * match mp->base, and mp->local shall be uninitialized.\n \t\t\t * Set mp->local to p->two->sha1.\n \t\t\t */\n-\t\t\tassert(!oidcmp(&p->one->oid, &mp->base));\n-\t\t\tassert(!oidcmp(&mp->local, &uninitialized));\n+\t\t\tassert(oideq(&p->one->oid, &mp->base));\n+\t\t\tassert(oideq(&mp->local, &uninitialized));\n \t\t\toidcpy(&mp->local, &p->two->oid);\n \t\t}\n \t\ttrace_printf(\"\\t\\tStored local change for %s: %.7s -> %.7s\\n\",\n@@ -480,14 +480,14 @@ static int merge_changes(struct notes_merge_options *o,\n \t\t       oid_to_hex(&p->local),\n \t\t       oid_to_hex(&p->remote));\n \n-\t\tif (!oidcmp(&p->base, &p->remote)) {\n+\t\tif (oideq(&p->base, &p->remote)) {\n \t\t\t/* no remote change; nothing to do */\n \t\t\ttrace_printf(\"\\t\\t\\tskipping (no remote change)\\n\");\n-\t\t} else if (!oidcmp(&p->local, &p->remote)) {\n+\t\t} else if (oideq(&p->local, &p->remote)) {\n \t\t\t/* same change in local and remote; nothing to do */\n \t\t\ttrace_printf(\"\\t\\t\\tskipping (local == remote)\\n\");\n-\t\t} else if (!oidcmp(&p->local, &uninitialized) ||\n-\t\t\t   !oidcmp(&p->local, &p->base)) {\n+\t\t} else if (oideq(&p->local, &uninitialized) ||\n+\t\t\t   oideq(&p->local, &p->base)) {\n \t\t\t/* no local change; adopt remote change */\n \t\t\ttrace_printf(\"\\t\\t\\tno local change, adopted remote\\n\");\n \t\t\tif (add_note(t, &p->obj, &p->remote,\n@@ -621,14 +621,14 @@ int notes_merge(struct notes_merge_options *o,\n \t\t\toid_to_hex(&local->object.oid),\n \t\t\toid_to_hex(base_oid));\n \n-\tif (!oidcmp(&remote->object.oid, base_oid)) {\n+\tif (oideq(&remote->object.oid, base_oid)) {\n \t\t/* Already merged; result == local commit */\n \t\tif (o->verbosity >= 2)\n \t\t\tprintf(\"Already up to date!\\n\");\n \t\toidcpy(result_oid, &local->object.oid);\n \t\tgoto found_result;\n \t}\n-\tif (!oidcmp(&local->object.oid, base_oid)) {\n+\tif (oideq(&local->object.oid, base_oid)) {\n \t\t/* Fast-forward; result == remote commit */\n \t\tif (o->verbosity >= 2)\n \t\t\tprintf(\"Fast-forward\\n\");\ndiff --git a/notes.c b/notes.c\nindex 32d3dbcc1e..b3386d6c36 100644\n--- a/notes.c\n+++ b/notes.c\n@@ -266,9 +266,9 @@ static int note_tree_insert(struct notes_tree *t, struct int_node *tree,\n \tcase PTR_TYPE_NOTE:\n \t\tswitch (type) {\n \t\tcase PTR_TYPE_NOTE:\n-\t\t\tif (!oidcmp(&l->key_oid, &entry->key_oid)) {\n+\t\t\tif (oideq(&l->key_oid, &entry->key_oid)) {\n \t\t\t\t/* skip concatenation if l == entry */\n-\t\t\t\tif (!oidcmp(&l->val_oid, &entry->val_oid))\n+\t\t\t\tif (oideq(&l->val_oid, &entry->val_oid))\n \t\t\t\t\treturn 0;\n \n \t\t\t\tret = combine_notes(&l->val_oid,\ndiff --git a/pack-write.c b/pack-write.c\nindex a9d46bc03f..7d14716c40 100644\n--- a/pack-write.c\n+++ b/pack-write.c\n@@ -124,7 +124,7 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec\n \t\t}\n \t\thashwrite(f, obj->oid.hash, the_hash_algo->rawsz);\n \t\tif ((opts->flags & WRITE_IDX_STRICT) &&\n-\t\t    (i && !oidcmp(&list[-2]->oid, &obj->oid)))\n+\t\t    (i && oideq(&list[-2]->oid, &obj->oid)))\n \t\t\tdie(\"The same object %s appears twice in the pack\",\n \t\t\t    oid_to_hex(&obj->oid));\n \t}\ndiff --git a/read-cache.c b/read-cache.c\nindex 7b1354d759..eb4919e77f 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -767,7 +767,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,\n \t/* It was suspected to be racily clean, but it turns out to be Ok */\n \twas_same = (alias &&\n \t\t    !ce_stage(alias) &&\n-\t\t    !oidcmp(&alias->oid, &ce->oid) &&\n+\t\t    oideq(&alias->oid, &ce->oid) &&\n \t\t    ce->ce_mode == alias->ce_mode);\n \n \tif (pretend)\ndiff --git a/ref-filter.c b/ref-filter.c\nindex 0bccfceff2..ccca317ce1 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -1710,7 +1710,7 @@ struct contains_stack {\n static int in_commit_list(const struct commit_list *want, struct commit *c)\n {\n \tfor (; want; want = want->next)\n-\t\tif (!oidcmp(&want->item->object.oid, &c->object.oid))\n+\t\tif (oideq(&want->item->object.oid, &c->object.oid))\n \t\t\treturn 1;\n \treturn 0;\n }\ndiff --git a/refs/files-backend.c b/refs/files-backend.c\nindex 1f1a98e4cb..aa45f5317f 100644\n--- a/refs/files-backend.c\n+++ b/refs/files-backend.c\n@@ -2307,7 +2307,7 @@ static int check_old_oid(struct ref_update *update, struct object_id *oid,\n \t\t\t struct strbuf *err)\n {\n \tif (!(update->flags & REF_HAVE_OLD) ||\n-\t\t   !oidcmp(oid, &update->old_oid))\n+\t\t   oideq(oid, &update->old_oid))\n \t\treturn 0;\n \n \tif (is_null_oid(&update->old_oid))\n@@ -2443,7 +2443,7 @@ static int lock_ref_for_update(struct files_ref_store *refs,\n \t    !(update->flags & REF_DELETING) &&\n \t    !(update->flags & REF_LOG_ONLY)) {\n \t\tif (!(update->type & REF_ISSYMREF) &&\n-\t\t    !oidcmp(&lock->old_oid, &update->new_oid)) {\n+\t\t    oideq(&lock->old_oid, &update->new_oid)) {\n \t\t\t/*\n \t\t\t * The reference already has the desired\n \t\t\t * value, so we don't need to write it.\ndiff --git a/remote.c b/remote.c\nindex 7f6277a145..6f1ee9d640 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -1388,7 +1388,7 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,\n \n \t\tref->deletion = is_null_oid(&ref->new_oid);\n \t\tif (!ref->deletion &&\n-\t\t\t!oidcmp(&ref->old_oid, &ref->new_oid)) {\n+\t\t\toideq(&ref->old_oid, &ref->new_oid)) {\n \t\t\tref->status = REF_STATUS_UPTODATE;\n \t\t\tcontinue;\n \t\t}\n@@ -2049,7 +2049,7 @@ struct ref *guess_remote_head(const struct ref *head,\n \t/* If refs/heads/master could be right, it is. */\n \tif (!all) {\n \t\tr = find_ref_by_name(refs, \"refs/heads/master\");\n-\t\tif (r && !oidcmp(&r->old_oid, &head->old_oid))\n+\t\tif (r && oideq(&r->old_oid, &head->old_oid))\n \t\t\treturn copy_ref(r);\n \t}\n \n@@ -2057,7 +2057,7 @@ struct ref *guess_remote_head(const struct ref *head,\n \tfor (r = refs; r; r = r->next) {\n \t\tif (r != head &&\n \t\t    starts_with(r->name, \"refs/heads/\") &&\n-\t\t    !oidcmp(&r->old_oid, &head->old_oid)) {\n+\t\t    oideq(&r->old_oid, &head->old_oid)) {\n \t\t\t*tail = copy_ref(r);\n \t\t\ttail = &((*tail)->next);\n \t\t\tif (!all)\ndiff --git a/revision.c b/revision.c\nindex de4dce600d..a2a569bb3b 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -3238,7 +3238,7 @@ static void track_linear(struct rev_info *revs, struct commit *commit)\n \t\tstruct commit_list *p;\n \t\tfor (p = revs->previous_parents; p; p = p->next)\n \t\t\tif (p->item == NULL || /* first commit */\n-\t\t\t    !oidcmp(&p->item->object.oid, &commit->object.oid))\n+\t\t\t    oideq(&p->item->object.oid, &commit->object.oid))\n \t\t\t\tbreak;\n \t\trevs->linear = p != NULL;\n \t}\ndiff --git a/sequencer.c b/sequencer.c\nindex 305de743a0..5f823c9ec7 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -610,7 +610,7 @@ static int is_index_unchanged(void)\n \tif (!(cache_tree_oid = get_cache_tree_oid()))\n \t\treturn -1;\n \n-\treturn !oidcmp(cache_tree_oid, get_commit_tree_oid(head_commit));\n+\treturn oideq(cache_tree_oid, get_commit_tree_oid(head_commit));\n }\n \n static int write_author_script(const char *message)\n@@ -1258,9 +1258,9 @@ static int try_to_commit(struct strbuf *msg, const char *author,\n \t\tgoto out;\n \t}\n \n-\tif (!(flags & ALLOW_EMPTY) && !oidcmp(current_head ?\n-\t\t\t\t\t      get_commit_tree_oid(current_head) :\n-\t\t\t\t\t      the_hash_algo->empty_tree, &tree)) {\n+\tif (!(flags & ALLOW_EMPTY) && oideq(current_head ?\n+\t\t\t\t\t    get_commit_tree_oid(current_head) :\n+\t\t\t\t\t    the_hash_algo->empty_tree, &tree)) {\n \t\tres = 1; /* run 'git commit' to display error message */\n \t\tgoto out;\n \t}\n@@ -1365,7 +1365,7 @@ static int is_original_commit_empty(struct commit *commit)\n \t\tptree_oid = the_hash_algo->empty_tree; /* commit is root */\n \t}\n \n-\treturn !oidcmp(ptree_oid, get_commit_tree_oid(commit));\n+\treturn oideq(ptree_oid, get_commit_tree_oid(commit));\n }\n \n /*\n@@ -1645,7 +1645,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,\n \t\tunborn = get_oid(\"HEAD\", &head);\n \t\t/* Do we want to generate a root commit? */\n \t\tif (is_pick_or_similar(command) && opts->have_squash_onto &&\n-\t\t    !oidcmp(&head, &opts->squash_onto)) {\n+\t\t    oideq(&head, &opts->squash_onto)) {\n \t\t\tif (is_fixup(command))\n \t\t\t\treturn error(_(\"cannot fixup root commit\"));\n \t\t\tflags |= CREATE_ROOT_COMMIT;\n@@ -1688,7 +1688,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,\n \t\t\toid_to_hex(&commit->object.oid));\n \n \tif (opts->allow_ff && !is_fixup(command) &&\n-\t    ((parent && !oidcmp(&parent->object.oid, &head)) ||\n+\t    ((parent && oideq(&parent->object.oid, &head)) ||\n \t     (!parent && unborn))) {\n \t\tif (is_rebase_i(opts))\n \t\t\twrite_author_script(msg.message);\n@@ -2393,7 +2393,7 @@ static int rollback_is_safe(void)\n \tif (get_oid(\"HEAD\", &actual_head))\n \t\toidclr(&actual_head);\n \n-\treturn !oidcmp(&actual_head, &expected_head);\n+\treturn oideq(&actual_head, &expected_head);\n }\n \n static int reset_for_rollback(const struct object_id *oid)\n@@ -2954,7 +2954,7 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,\n \t}\n \n \tif (opts->have_squash_onto &&\n-\t    !oidcmp(&head_commit->object.oid, &opts->squash_onto)) {\n+\t    oideq(&head_commit->object.oid, &opts->squash_onto)) {\n \t\t/*\n \t\t * When the user tells us to \"merge\" something into a\n \t\t * \"[new root]\", let's simply fast-forward to the merge head.\n@@ -3023,8 +3023,8 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,\n \t * commit, we cannot fast-forward.\n \t */\n \tcan_fast_forward = opts->allow_ff && commit && commit->parents &&\n-\t\t!oidcmp(&commit->parents->item->object.oid,\n-\t\t\t&head_commit->object.oid);\n+\t\toideq(&commit->parents->item->object.oid,\n+\t\t      &head_commit->object.oid);\n \n \t/*\n \t * If any merge head is different from the original one, we cannot\n@@ -3102,8 +3102,8 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,\n \twrite_message(\"no-ff\", 5, git_path_merge_mode(the_repository), 0);\n \n \tbases = get_merge_bases(head_commit, merge_commit);\n-\tif (bases && !oidcmp(&merge_commit->object.oid,\n-\t\t\t     &bases->item->object.oid)) {\n+\tif (bases && oideq(&merge_commit->object.oid,\n+\t\t\t   &bases->item->object.oid)) {\n \t\tret = 0;\n \t\t/* skip merging an ancestor of HEAD */\n \t\tgoto leave_merge;\n@@ -3349,9 +3349,9 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)\n \t\t\t\t */\n \t\t\t\tif (item->command == TODO_REWORD &&\n \t\t\t\t    !get_oid(\"HEAD\", &oid) &&\n-\t\t\t\t    (!oidcmp(&item->commit->object.oid, &oid) ||\n+\t\t\t\t    (oideq(&item->commit->object.oid, &oid) ||\n \t\t\t\t     (opts->have_squash_onto &&\n-\t\t\t\t      !oidcmp(&opts->squash_onto, &oid))))\n+\t\t\t\t      oideq(&opts->squash_onto, &oid))))\n \t\t\t\t\tto_amend = 1;\n \n \t\t\t\treturn res | error_with_patch(item->commit,\n@@ -3578,7 +3578,7 @@ static int commit_staged_changes(struct replay_opts *opts,\n \t\t * the commit message and if there was a squash, let the user\n \t\t * edit it.\n \t\t */\n-\t\tif (is_clean && !oidcmp(&head, &to_amend) &&\n+\t\tif (is_clean && oideq(&head, &to_amend) &&\n \t\t    opts->current_fixup_count > 0 &&\n \t\t    file_exists(rebase_path_stopped_sha())) {\n \t\t\tconst char *p = opts->current_fixups.buf;\ndiff --git a/sha1-array.c b/sha1-array.c\nindex 265941fbf4..b94e0ec0f5 100644\n--- a/sha1-array.c\n+++ b/sha1-array.c\n@@ -69,7 +69,7 @@ int oid_array_for_each_unique(struct oid_array *array,\n \n \tfor (i = 0; i < array->nr; i++) {\n \t\tint ret;\n-\t\tif (i > 0 && !oidcmp(array->oid + i, array->oid + i - 1))\n+\t\tif (i > 0 && oideq(array->oid + i, array->oid + i - 1))\n \t\t\tcontinue;\n \t\tret = fn(array->oid + i, data);\n \t\tif (ret)\ndiff --git a/sha1-file.c b/sha1-file.c\nindex 97b7423848..71f49ee56d 100644\n--- a/sha1-file.c\n+++ b/sha1-file.c\n@@ -149,10 +149,10 @@ static struct cached_object *find_cached_object(const struct object_id *oid)\n \tstruct cached_object *co = cached_objects;\n \n \tfor (i = 0; i < cached_object_nr; i++, co++) {\n-\t\tif (!oidcmp(&co->oid, oid))\n+\t\tif (oideq(&co->oid, oid))\n \t\t\treturn co;\n \t}\n-\tif (!oidcmp(oid, the_hash_algo->empty_tree))\n+\tif (oideq(oid, the_hash_algo->empty_tree))\n \t\treturn &empty_tree;\n \treturn NULL;\n }\ndiff --git a/sha1-name.c b/sha1-name.c\nindex c9cc1318b7..a0c8451d55 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -44,7 +44,7 @@ static void update_candidates(struct disambiguate_state *ds, const struct object\n \t\toidcpy(&ds->candidate, current);\n \t\tds->candidate_exists = 1;\n \t\treturn;\n-\t} else if (!oidcmp(&ds->candidate, current)) {\n+\t} else if (oideq(&ds->candidate, current)) {\n \t\t/* the same as what we already have seen */\n \t\treturn;\n \t}\ndiff --git a/submodule.c b/submodule.c\nindex 50cbf5f13e..a2ce58e9e7 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -536,7 +536,7 @@ static void show_submodule_header(struct diff_options *o, const char *path,\n \t\t\tfast_backward = 1;\n \t}\n \n-\tif (!oidcmp(one, two)) {\n+\tif (oideq(one, two)) {\n \t\tstrbuf_release(&sb);\n \t\treturn;\n \t}\ndiff --git a/transport.c b/transport.c\nindex 06ffea2774..1c76d64aba 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -1228,7 +1228,7 @@ int transport_fetch_refs(struct transport *transport, struct ref *refs)\n \t\tnr_refs++;\n \t\tif (rm->peer_ref &&\n \t\t    !is_null_oid(&rm->old_oid) &&\n-\t\t    !oidcmp(&rm->peer_ref->old_oid, &rm->old_oid))\n+\t\t    oideq(&rm->peer_ref->old_oid, &rm->old_oid))\n \t\t\tcontinue;\n \t\tALLOC_GROW(heads, nr_heads + 1, nr_alloc);\n \t\theads[nr_heads++] = rm;\ndiff --git a/unpack-trees.c b/unpack-trees.c\nindex f25089b878..4056a92d55 100644\n--- a/unpack-trees.c\n+++ b/unpack-trees.c\n@@ -630,7 +630,7 @@ static int switch_cache_bottom(struct traverse_info *info)\n \n static inline int are_same_oid(struct name_entry *name_j, struct name_entry *name_k)\n {\n-\treturn name_j->oid && name_k->oid && !oidcmp(name_j->oid, name_k->oid);\n+\treturn name_j->oid && name_k->oid && oideq(name_j->oid, name_k->oid);\n }\n \n static int traverse_trees_recursive(int n, unsigned long dirmask,\n@@ -1484,7 +1484,7 @@ static int same(const struct cache_entry *a, const struct cache_entry *b)\n \tif ((a->ce_flags | b->ce_flags) & CE_CONFLICTED)\n \t\treturn 0;\n \treturn a->ce_mode == b->ce_mode &&\n-\t       !oidcmp(&a->oid, &b->oid);\n+\t       oideq(&a->oid, &b->oid);\n }\n \n \n@@ -1616,7 +1616,7 @@ static int verify_clean_subdirectory(const struct cache_entry *ce,\n \t\t * If we are not going to update the submodule, then\n \t\t * we don't care.\n \t\t */\n-\t\tif (!sub_head && !oidcmp(&oid, &ce->oid))\n+\t\tif (!sub_head && oideq(&oid, &ce->oid))\n \t\t\treturn 0;\n \t\treturn verify_clean_submodule(sub_head ? NULL : oid_to_hex(&oid),\n \t\t\t\t\t      ce, error_type, o);\ndiff --git a/wt-status.c b/wt-status.c\nindex 5ffab61015..1c8746d0ea 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -453,8 +453,8 @@ static void wt_status_collect_changed_cb(struct diff_queue_struct *q,\n \t\t\td->worktree_status = p->status;\n \t\tif (S_ISGITLINK(p->two->mode)) {\n \t\t\td->dirty_submodule = p->two->dirty_submodule;\n-\t\t\td->new_submodule_commits = !!oidcmp(&p->one->oid,\n-\t\t\t\t\t\t\t    &p->two->oid);\n+\t\t\td->new_submodule_commits = !oideq(&p->one->oid,\n+\t\t\t\t\t\t\t  &p->two->oid);\n \t\t\tif (s->status_format == STATUS_FORMAT_SHORT)\n \t\t\t\td->worktree_status = short_submodule_status(d);\n \t\t}\n@@ -1487,10 +1487,10 @@ static void wt_status_get_detached_from(struct wt_status_state *state)\n \n \tif (dwim_ref(cb.buf.buf, cb.buf.len, &oid, &ref) == 1 &&\n \t    /* sha1 is a commit? match without further lookup */\n-\t    (!oidcmp(&cb.noid, &oid) ||\n+\t    (oideq(&cb.noid, &oid) ||\n \t     /* perhaps sha1 is a tag, try to dereference to a commit */\n \t     ((commit = lookup_commit_reference_gently(the_repository, &oid, 1)) != NULL &&\n-\t      !oidcmp(&cb.noid, &commit->object.oid)))) {\n+\t      oideq(&cb.noid, &commit->object.oid)))) {\n \t\tconst char *from = ref;\n \t\tif (!skip_prefix(from, \"refs/tags/\", &from))\n \t\t\tskip_prefix(from, \"refs/remotes/\", &from);\n@@ -1500,7 +1500,7 @@ static void wt_status_get_detached_from(struct wt_status_state *state)\n \t\t\txstrdup(find_unique_abbrev(&cb.noid, DEFAULT_ABBREV));\n \toidcpy(&state->detached_oid, &cb.noid);\n \tstate->detached_at = !get_oid(\"HEAD\", &oid) &&\n-\t\t\t     !oidcmp(&oid, &state->detached_oid);\n+\t\t\t     oideq(&oid, &state->detached_oid);\n \n \tfree(ref);\n \tstrbuf_release(&cb.buf);\ndiff --git a/xdiff-interface.c b/xdiff-interface.c\nindex ec6e574e4a..e7af95db86 100644\n--- a/xdiff-interface.c\n+++ b/xdiff-interface.c\n@@ -186,7 +186,7 @@ void read_mmblob(mmfile_t *ptr, const struct object_id *oid)\n \tunsigned long size;\n \tenum object_type type;\n \n-\tif (!oidcmp(oid, &null_oid)) {\n+\tif (oideq(oid, &null_oid)) {\n \t\tptr->ptr = xstrdup(\"\");\n \t\tptr->size = 0;\n \t\treturn;\n-- \n2.19.0.rc0.584.g84d5b2a847\n\n"},{"id":"356755","messageId":"20180828212244.GD11036@sigill.intra.peff.net","threadId":"49212","inReplyTo":"20180828212126.GA7039@sigill.intra.peff.net","subject":"[PATCH v2 4/9] convert \"hashcmp() == 0\" to hasheq()","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2018-08-28T21:22:44Z","receivedAt":"2018-08-28T21:22:48Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"This is the partner patch to the previous one, but covering\nthe \"hash\" variants instead of \"oid\".  Note that our\ncoccinelle rule is slightly more complex to avoid triggering\nthe call in hasheq().\n\nI didn't bother to add a new rule to convert:\n\n  - hasheq(E1->hash, E2->hash)\n  + oideq(E1, E2)\n\nSince these are new functions, there won't be any such\nexisting callers. And since most of the code is already\nusing oideq, we're not likely to introduce new ones.\n\nWe might still see \"!hashcmp(E1->hash, E2->hash)\" from topics\nin flight. But because our new rule comes after the existing\nones, that should first get converted to \"!oidcmp(E1, E2)\"\nand then to \"oideq(E1, E2)\".\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n builtin/fetch.c                    |  2 +-\n cache.h                            |  8 ++++----\n contrib/coccinelle/object_id.cocci |  9 +++++++++\n http-walker.c                      |  2 +-\n notes.c                            |  2 +-\n object.c                           |  2 +-\n pack-objects.c                     |  2 +-\n packfile.c                         | 10 +++++-----\n 8 files changed, 23 insertions(+), 14 deletions(-)\n\ndiff --git a/builtin/fetch.c b/builtin/fetch.c\nindex 32b1d5d383..84e0e8080f 100644\n--- a/builtin/fetch.c\n+++ b/builtin/fetch.c\n@@ -238,7 +238,7 @@ static int will_fetch(struct ref **head, const unsigned char *sha1)\n {\n \tstruct ref *rm = *head;\n \twhile (rm) {\n-\t\tif (!hashcmp(rm->old_oid.hash, sha1))\n+\t\tif (hasheq(rm->old_oid.hash, sha1))\n \t\t\treturn 1;\n \t\trm = rm->next;\n \t}\ndiff --git a/cache.h b/cache.h\nindex d090f71706..d97db26bb6 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1053,12 +1053,12 @@ static inline int oideq(const struct object_id *oid1, const struct object_id *oi\n \n static inline int is_null_sha1(const unsigned char *sha1)\n {\n-\treturn !hashcmp(sha1, null_sha1);\n+\treturn hasheq(sha1, null_sha1);\n }\n \n static inline int is_null_oid(const struct object_id *oid)\n {\n-\treturn !hashcmp(oid->hash, null_sha1);\n+\treturn hasheq(oid->hash, null_sha1);\n }\n \n static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src)\n@@ -1095,7 +1095,7 @@ static inline void oidread(struct object_id *oid, const unsigned char *hash)\n \n static inline int is_empty_blob_sha1(const unsigned char *sha1)\n {\n-\treturn !hashcmp(sha1, the_hash_algo->empty_blob->hash);\n+\treturn hasheq(sha1, the_hash_algo->empty_blob->hash);\n }\n \n static inline int is_empty_blob_oid(const struct object_id *oid)\n@@ -1105,7 +1105,7 @@ static inline int is_empty_blob_oid(const struct object_id *oid)\n \n static inline int is_empty_tree_sha1(const unsigned char *sha1)\n {\n-\treturn !hashcmp(sha1, the_hash_algo->empty_tree->hash);\n+\treturn hasheq(sha1, the_hash_algo->empty_tree->hash);\n }\n \n static inline int is_empty_tree_oid(const struct object_id *oid)\ndiff --git a/contrib/coccinelle/object_id.cocci b/contrib/coccinelle/object_id.cocci\nindex 548c02336d..d90ba8a040 100644\n--- a/contrib/coccinelle/object_id.cocci\n+++ b/contrib/coccinelle/object_id.cocci\n@@ -114,3 +114,12 @@ expression E1, E2;\n @@\n - oidcmp(E1, E2) == 0\n + oideq(E1, E2)\n+\n+@@\n+identifier f != hasheq;\n+expression E1, E2;\n+@@\n+  f(...) {<...\n+- hashcmp(E1, E2) == 0\n++ hasheq(E1, E2)\n+  ...>}\ndiff --git a/http-walker.c b/http-walker.c\nindex 7cdfb2f24c..3a8edc7f2f 100644\n--- a/http-walker.c\n+++ b/http-walker.c\n@@ -483,7 +483,7 @@ static int fetch_object(struct walker *walker, unsigned char *sha1)\n \n \tlist_for_each(pos, head) {\n \t\tobj_req = list_entry(pos, struct object_request, node);\n-\t\tif (!hashcmp(obj_req->oid.hash, sha1))\n+\t\tif (hasheq(obj_req->oid.hash, sha1))\n \t\t\tbreak;\n \t}\n \tif (obj_req == NULL)\ndiff --git a/notes.c b/notes.c\nindex b3386d6c36..33d16c1ec3 100644\n--- a/notes.c\n+++ b/notes.c\n@@ -147,7 +147,7 @@ static struct leaf_node *note_tree_find(struct notes_tree *t,\n \tvoid **p = note_tree_search(t, &tree, &n, key_sha1);\n \tif (GET_PTR_TYPE(*p) == PTR_TYPE_NOTE) {\n \t\tstruct leaf_node *l = (struct leaf_node *) CLR_PTR_TYPE(*p);\n-\t\tif (!hashcmp(key_sha1, l->key_oid.hash))\n+\t\tif (hasheq(key_sha1, l->key_oid.hash))\n \t\t\treturn l;\n \t}\n \treturn NULL;\ndiff --git a/object.c b/object.c\nindex 51c4594515..e54160550c 100644\n--- a/object.c\n+++ b/object.c\n@@ -95,7 +95,7 @@ struct object *lookup_object(struct repository *r, const unsigned char *sha1)\n \n \tfirst = i = hash_obj(sha1, r->parsed_objects->obj_hash_size);\n \twhile ((obj = r->parsed_objects->obj_hash[i]) != NULL) {\n-\t\tif (!hashcmp(sha1, obj->oid.hash))\n+\t\tif (hasheq(sha1, obj->oid.hash))\n \t\t\tbreak;\n \t\ti++;\n \t\tif (i == r->parsed_objects->obj_hash_size)\ndiff --git a/pack-objects.c b/pack-objects.c\nindex 6ef87e5683..2bc7626997 100644\n--- a/pack-objects.c\n+++ b/pack-objects.c\n@@ -16,7 +16,7 @@ static uint32_t locate_object_entry_hash(struct packing_data *pdata,\n \twhile (pdata->index[i] > 0) {\n \t\tuint32_t pos = pdata->index[i] - 1;\n \n-\t\tif (!hashcmp(sha1, pdata->objects[pos].idx.oid.hash)) {\n+\t\tif (hasheq(sha1, pdata->objects[pos].idx.oid.hash)) {\n \t\t\t*found = 1;\n \t\t\treturn i;\n \t\t}\ndiff --git a/packfile.c b/packfile.c\nindex ebcb5742ec..c2e96293ad 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -1015,7 +1015,7 @@ void mark_bad_packed_object(struct packed_git *p, const unsigned char *sha1)\n {\n \tunsigned i;\n \tfor (i = 0; i < p->num_bad_objects; i++)\n-\t\tif (!hashcmp(sha1, p->bad_object_sha1 + GIT_SHA1_RAWSZ * i))\n+\t\tif (hasheq(sha1, p->bad_object_sha1 + GIT_SHA1_RAWSZ * i))\n \t\t\treturn;\n \tp->bad_object_sha1 = xrealloc(p->bad_object_sha1,\n \t\t\t\t      st_mult(GIT_MAX_RAWSZ,\n@@ -1031,8 +1031,8 @@ const struct packed_git *has_packed_and_bad(const unsigned char *sha1)\n \n \tfor (p = the_repository->objects->packed_git; p; p = p->next)\n \t\tfor (i = 0; i < p->num_bad_objects; i++)\n-\t\t\tif (!hashcmp(sha1,\n-\t\t\t\t     p->bad_object_sha1 + the_hash_algo->rawsz * i))\n+\t\t\tif (hasheq(sha1,\n+\t\t\t\t   p->bad_object_sha1 + the_hash_algo->rawsz * i))\n \t\t\t\treturn p;\n \treturn NULL;\n }\n@@ -1830,8 +1830,8 @@ static int fill_pack_entry(const struct object_id *oid,\n \tif (p->num_bad_objects) {\n \t\tunsigned i;\n \t\tfor (i = 0; i < p->num_bad_objects; i++)\n-\t\t\tif (!hashcmp(oid->hash,\n-\t\t\t\t     p->bad_object_sha1 + the_hash_algo->rawsz * i))\n+\t\t\tif (hasheq(oid->hash,\n+\t\t\t\t   p->bad_object_sha1 + the_hash_algo->rawsz * i))\n \t\t\t\treturn 0;\n \t}\n \n-- \n2.19.0.rc0.584.g84d5b2a847\n\n"},{"id":"356756","messageId":"20180828212248.GE11036@sigill.intra.peff.net","threadId":"49212","inReplyTo":"20180828212126.GA7039@sigill.intra.peff.net","subject":"[PATCH v2 5/9] convert \"oidcmp() != 0\" to \"!oideq()\"","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2018-08-28T21:22:48Z","receivedAt":"2018-08-28T21:22:54Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"This is the flip side of the previous two patches: checking\nfor a non-zero oidcmp() can be more strictly expressed as\ninequality. Like those patches, we write \"!= 0\" in the\ncoccinelle transformation, which covers by isomorphism the\nmore common:\n\n  if (oidcmp(E1, E2))\n\nAs with the previous two patches, this patch can be achieved\nalmost entirely by running \"make coccicheck\"; the only\ndifferences are manual line-wrap fixes to match the original\ncode.\n\nThere is one thing to note for anybody replicating this,\nthough: coccinelle 1.0.4 seems to miss the case in\nbuiltin/tag.c, even though it's basically the same as all\nthe others. Running with 1.0.7 does catch this, so\npresumably it's just a coccinelle bug that was fixed in the\ninterim.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n bisect.c                           | 2 +-\n blame.c                            | 4 ++--\n builtin/fmt-merge-msg.c            | 4 ++--\n builtin/merge.c                    | 2 +-\n builtin/pull.c                     | 2 +-\n builtin/rm.c                       | 2 +-\n builtin/show-branch.c              | 4 ++--\n builtin/tag.c                      | 2 +-\n bundle.c                           | 2 +-\n commit-graph.c                     | 6 +++---\n commit.c                           | 2 +-\n contrib/coccinelle/object_id.cocci | 6 ++++++\n diff-lib.c                         | 2 +-\n diff.c                             | 6 +++---\n diffcore-rename.c                  | 2 +-\n dir.c                              | 6 +++---\n fast-import.c                      | 4 ++--\n fetch-pack.c                       | 2 +-\n match-trees.c                      | 2 +-\n notes.c                            | 2 +-\n read-cache.c                       | 2 +-\n refs.c                             | 8 ++++----\n refs/files-backend.c               | 2 +-\n refs/packed-backend.c              | 2 +-\n refs/ref-cache.c                   | 2 +-\n remote.c                           | 2 +-\n sequencer.c                        | 8 ++++----\n sha1-file.c                        | 6 +++---\n submodule-config.c                 | 4 ++--\n t/helper/test-dump-cache-tree.c    | 2 +-\n tree-diff.c                        | 2 +-\n 31 files changed, 55 insertions(+), 49 deletions(-)\n\ndiff --git a/bisect.c b/bisect.c\nindex 41c56a665e..7c1d8f1a6d 100644\n--- a/bisect.c\n+++ b/bisect.c\n@@ -595,7 +595,7 @@ static struct commit_list *skip_away(struct commit_list *list, int count)\n \n \tfor (i = 0; cur; cur = cur->next, i++) {\n \t\tif (i == index) {\n-\t\t\tif (oidcmp(&cur->item->object.oid, current_bad_oid))\n+\t\t\tif (!oideq(&cur->item->object.oid, current_bad_oid))\n \t\t\t\treturn cur;\n \t\t\tif (previous)\n \t\t\t\treturn previous;\ndiff --git a/blame.c b/blame.c\nindex c47d7050d9..d5f7b7237c 100644\n--- a/blame.c\n+++ b/blame.c\n@@ -1832,7 +1832,7 @@ void setup_scoreboard(struct blame_scoreboard *sb,\n \n \t\tsb->revs->children.name = \"children\";\n \t\twhile (c->parents &&\n-\t\t       oidcmp(&c->object.oid, &sb->final->object.oid)) {\n+\t\t       !oideq(&c->object.oid, &sb->final->object.oid)) {\n \t\t\tstruct commit_list *l = xcalloc(1, sizeof(*l));\n \n \t\t\tl->item = c;\n@@ -1842,7 +1842,7 @@ void setup_scoreboard(struct blame_scoreboard *sb,\n \t\t\tc = c->parents->item;\n \t\t}\n \n-\t\tif (oidcmp(&c->object.oid, &sb->final->object.oid))\n+\t\tif (!oideq(&c->object.oid, &sb->final->object.oid))\n \t\t\tdie(_(\"--reverse --first-parent together require range along first-parent chain\"));\n \t}\n \ndiff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c\nindex 4c82c234cb..268f0c20ca 100644\n--- a/builtin/fmt-merge-msg.c\n+++ b/builtin/fmt-merge-msg.c\n@@ -78,9 +78,9 @@ static struct merge_parent *find_merge_parent(struct merge_parents *table,\n {\n \tint i;\n \tfor (i = 0; i < table->nr; i++) {\n-\t\tif (given && oidcmp(&table->item[i].given, given))\n+\t\tif (given && !oideq(&table->item[i].given, given))\n \t\t\tcontinue;\n-\t\tif (commit && oidcmp(&table->item[i].commit, commit))\n+\t\tif (commit && !oideq(&table->item[i].commit, commit))\n \t\t\tcontinue;\n \t\treturn &table->item[i];\n \t}\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex 57abff999b..8d85d31a61 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -1521,7 +1521,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \t\t\t * HEAD^^\" would be missed.\n \t\t\t */\n \t\t\tcommon_one = get_merge_bases(head_commit, j->item);\n-\t\t\tif (oidcmp(&common_one->item->object.oid, &j->item->object.oid)) {\n+\t\t\tif (!oideq(&common_one->item->object.oid, &j->item->object.oid)) {\n \t\t\t\tup_to_date = 0;\n \t\t\t\tbreak;\n \t\t\t}\ndiff --git a/builtin/pull.c b/builtin/pull.c\nindex a720f58a96..09b02695de 100644\n--- a/builtin/pull.c\n+++ b/builtin/pull.c\n@@ -902,7 +902,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)\n \t\toidclr(&curr_head);\n \n \tif (!is_null_oid(&orig_head) && !is_null_oid(&curr_head) &&\n-\t\t\toidcmp(&orig_head, &curr_head)) {\n+\t\t\t!oideq(&orig_head, &curr_head)) {\n \t\t/*\n \t\t * The fetch involved updating the current branch.\n \t\t *\ndiff --git a/builtin/rm.c b/builtin/rm.c\nindex 2cbe89e0ae..17086d3d97 100644\n--- a/builtin/rm.c\n+++ b/builtin/rm.c\n@@ -180,7 +180,7 @@ static int check_local_mod(struct object_id *head, int index_only)\n \t\tif (no_head\n \t\t     || get_tree_entry(head, name, &oid, &mode)\n \t\t     || ce->ce_mode != create_ce_mode(mode)\n-\t\t     || oidcmp(&ce->oid, &oid))\n+\t\t     || !oideq(&ce->oid, &oid))\n \t\t\tstaged_changes = 1;\n \n \t\t/*\ndiff --git a/builtin/show-branch.c b/builtin/show-branch.c\nindex 363cf8509a..5f9432861b 100644\n--- a/builtin/show-branch.c\n+++ b/builtin/show-branch.c\n@@ -412,7 +412,7 @@ static int append_head_ref(const char *refname, const struct object_id *oid,\n \t/* If both heads/foo and tags/foo exists, get_sha1 would\n \t * get confused.\n \t */\n-\tif (get_oid(refname + ofs, &tmp) || oidcmp(&tmp, oid))\n+\tif (get_oid(refname + ofs, &tmp) || !oideq(&tmp, oid))\n \t\tofs = 5;\n \treturn append_ref(refname + ofs, oid, 0);\n }\n@@ -427,7 +427,7 @@ static int append_remote_ref(const char *refname, const struct object_id *oid,\n \t/* If both heads/foo and tags/foo exists, get_sha1 would\n \t * get confused.\n \t */\n-\tif (get_oid(refname + ofs, &tmp) || oidcmp(&tmp, oid))\n+\tif (get_oid(refname + ofs, &tmp) || !oideq(&tmp, oid))\n \t\tofs = 5;\n \treturn append_ref(refname + ofs, oid, 0);\n }\ndiff --git a/builtin/tag.c b/builtin/tag.c\nindex 9a19ffb49f..f623632186 100644\n--- a/builtin/tag.c\n+++ b/builtin/tag.c\n@@ -559,7 +559,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)\n \t    ref_transaction_commit(transaction, &err))\n \t\tdie(\"%s\", err.buf);\n \tref_transaction_free(transaction);\n-\tif (force && !is_null_oid(&prev) && oidcmp(&prev, &object))\n+\tif (force && !is_null_oid(&prev) && !oideq(&prev, &object))\n \t\tprintf(_(\"Updated tag '%s' (was %s)\\n\"), tag,\n \t\t       find_unique_abbrev(&prev, DEFAULT_ABBREV));\n \ndiff --git a/bundle.c b/bundle.c\nindex 24cbe40986..14f2cfc248 100644\n--- a/bundle.c\n+++ b/bundle.c\n@@ -369,7 +369,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)\n \t\t * commit that is referenced by the tag, and not the tag\n \t\t * itself.\n \t\t */\n-\t\tif (oidcmp(&oid, &e->item->oid)) {\n+\t\tif (!oideq(&oid, &e->item->oid)) {\n \t\t\t/*\n \t\t\t * Is this the positive end of a range expressed\n \t\t\t * in terms of a tag (e.g. v2.0 from the range\ndiff --git a/commit-graph.c b/commit-graph.c\nindex 050c516b0d..7aed9f5371 100644\n--- a/commit-graph.c\n+++ b/commit-graph.c\n@@ -765,7 +765,7 @@ void write_commit_graph(const char *obj_dir,\n \n \tcount_distinct = 1;\n \tfor (i = 1; i < oids.nr; i++) {\n-\t\tif (oidcmp(&oids.list[i-1], &oids.list[i]))\n+\t\tif (!oideq(&oids.list[i - 1], &oids.list[i]))\n \t\t\tcount_distinct++;\n \t}\n \n@@ -960,7 +960,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g)\n \t\t\tcontinue;\n \t\t}\n \n-\t\tif (oidcmp(&get_commit_tree_in_graph_one(g, graph_commit)->object.oid,\n+\t\tif (!oideq(&get_commit_tree_in_graph_one(g, graph_commit)->object.oid,\n \t\t\t   get_commit_tree_oid(odb_commit)))\n \t\t\tgraph_report(\"root tree OID for commit %s in commit-graph is %s != %s\",\n \t\t\t\t     oid_to_hex(&cur_oid),\n@@ -977,7 +977,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g)\n \t\t\t\tbreak;\n \t\t\t}\n \n-\t\t\tif (oidcmp(&graph_parents->item->object.oid, &odb_parents->item->object.oid))\n+\t\t\tif (!oideq(&graph_parents->item->object.oid, &odb_parents->item->object.oid))\n \t\t\t\tgraph_report(\"commit-graph parent for %s is %s != %s\",\n \t\t\t\t\t     oid_to_hex(&cur_oid),\n \t\t\t\t\t     oid_to_hex(&graph_parents->item->object.oid),\ndiff --git a/commit.c b/commit.c\nindex 1a6e632185..1b94a8c96f 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -46,7 +46,7 @@ struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref\n \tstruct commit *c = lookup_commit_reference(the_repository, oid);\n \tif (!c)\n \t\tdie(_(\"could not parse %s\"), ref_name);\n-\tif (oidcmp(oid, &c->object.oid)) {\n+\tif (!oideq(oid, &c->object.oid)) {\n \t\twarning(_(\"%s %s is not a commit!\"),\n \t\t\tref_name, oid_to_hex(oid));\n \t}\ndiff --git a/contrib/coccinelle/object_id.cocci b/contrib/coccinelle/object_id.cocci\nindex d90ba8a040..4e1f1a7431 100644\n--- a/contrib/coccinelle/object_id.cocci\n+++ b/contrib/coccinelle/object_id.cocci\n@@ -123,3 +123,9 @@ expression E1, E2;\n - hashcmp(E1, E2) == 0\n + hasheq(E1, E2)\n   ...>}\n+\n+@@\n+expression E1, E2;\n+@@\n+- oidcmp(E1, E2) != 0\n++ !oideq(E1, E2)\ndiff --git a/diff-lib.c b/diff-lib.c\nindex c1f5a52654..8866b1d60c 100644\n--- a/diff-lib.c\n+++ b/diff-lib.c\n@@ -342,7 +342,7 @@ static int show_modified(struct rev_info *revs,\n \t}\n \n \tif (revs->combine_merges && !cached &&\n-\t    (oidcmp(oid, &old_entry->oid) || oidcmp(&old_entry->oid, &new_entry->oid))) {\n+\t    (!oideq(oid, &old_entry->oid) || !oideq(&old_entry->oid, &new_entry->oid))) {\n \t\tstruct combine_diff_path *p;\n \t\tint pathlen = ce_namelen(new_entry);\n \ndiff --git a/diff.c b/diff.c\nindex 5cada68267..5d3219b600 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -3765,7 +3765,7 @@ static int reuse_worktree_file(const char *name, const struct object_id *oid, in\n \t * This is not the sha1 we are looking for, or\n \t * unreusable because it is not a regular file.\n \t */\n-\tif (oidcmp(oid, &ce->oid) || !S_ISREG(ce->ce_mode))\n+\tif (!oideq(oid, &ce->oid) || !S_ISREG(ce->ce_mode))\n \t\treturn 0;\n \n \t/*\n@@ -4170,7 +4170,7 @@ static void fill_metainfo(struct strbuf *msg,\n \tdefault:\n \t\t*must_show_header = 0;\n \t}\n-\tif (one && two && oidcmp(&one->oid, &two->oid)) {\n+\tif (one && two && !oideq(&one->oid, &two->oid)) {\n \t\tconst unsigned hexsz = the_hash_algo->hexsz;\n \t\tint abbrev = o->flags.full_index ? hexsz : DEFAULT_ABBREV;\n \n@@ -5457,7 +5457,7 @@ static void diff_resolve_rename_copy(void)\n \t\t\telse\n \t\t\t\tp->status = DIFF_STATUS_RENAMED;\n \t\t}\n-\t\telse if (oidcmp(&p->one->oid, &p->two->oid) ||\n+\t\telse if (!oideq(&p->one->oid, &p->two->oid) ||\n \t\t\t p->one->mode != p->two->mode ||\n \t\t\t p->one->dirty_submodule ||\n \t\t\t p->two->dirty_submodule ||\ndiff --git a/diffcore-rename.c b/diffcore-rename.c\nindex d775183c2f..daddd9b28a 100644\n--- a/diffcore-rename.c\n+++ b/diffcore-rename.c\n@@ -286,7 +286,7 @@ static int find_identical_files(struct hashmap *srcs,\n \t\tstruct diff_filespec *source = p->filespec;\n \n \t\t/* False hash collision? */\n-\t\tif (oidcmp(&source->oid, &target->oid))\n+\t\tif (!oideq(&source->oid, &target->oid))\n \t\t\tcontinue;\n \t\t/* Non-regular files? If so, the modes must match! */\n \t\tif (!S_ISREG(source->mode) || !S_ISREG(target->mode)) {\ndiff --git a/dir.c b/dir.c\nindex aceb0d4869..8ee9fe81b4 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -1282,7 +1282,7 @@ static void prep_exclude(struct dir_struct *dir,\n \t\t * order, though, if you do that.\n \t\t */\n \t\tif (untracked &&\n-\t\t    oidcmp(&oid_stat.oid, &untracked->exclude_oid)) {\n+\t\t    !oideq(&oid_stat.oid, &untracked->exclude_oid)) {\n \t\t\tinvalidate_gitignore(dir->untracked, untracked);\n \t\t\toidcpy(&untracked->exclude_oid, &oid_stat.oid);\n \t\t}\n@@ -2248,12 +2248,12 @@ static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *d\n \n \t/* Validate $GIT_DIR/info/exclude and core.excludesfile */\n \troot = dir->untracked->root;\n-\tif (oidcmp(&dir->ss_info_exclude.oid,\n+\tif (!oideq(&dir->ss_info_exclude.oid,\n \t\t   &dir->untracked->ss_info_exclude.oid)) {\n \t\tinvalidate_gitignore(dir->untracked, root);\n \t\tdir->untracked->ss_info_exclude = dir->ss_info_exclude;\n \t}\n-\tif (oidcmp(&dir->ss_excludes_file.oid,\n+\tif (!oideq(&dir->ss_excludes_file.oid,\n \t\t   &dir->untracked->ss_excludes_file.oid)) {\n \t\tinvalidate_gitignore(dir->untracked, root);\n \t\tdir->untracked->ss_excludes_file = dir->ss_excludes_file;\ndiff --git a/fast-import.c b/fast-import.c\nindex a731088f96..67a53b79cb 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -2649,7 +2649,7 @@ static int parse_from(struct branch *b)\n \t\tstruct object_entry *oe = find_mark(idnum);\n \t\tif (oe->type != OBJ_COMMIT)\n \t\t\tdie(\"Mark :%\" PRIuMAX \" not a commit\", idnum);\n-\t\tif (oidcmp(&b->oid, &oe->idx.oid)) {\n+\t\tif (!oideq(&b->oid, &oe->idx.oid)) {\n \t\t\toidcpy(&b->oid, &oe->idx.oid);\n \t\t\tif (oe->pack_id != MAX_PACK_ID) {\n \t\t\t\tunsigned long size;\n@@ -2667,7 +2667,7 @@ static int parse_from(struct branch *b)\n \telse\n \t\tdie(\"Invalid ref name or SHA1 expression: %s\", from);\n \n-\tif (b->branch_tree.tree && oidcmp(&oid, &b->branch_tree.versions[1].oid)) {\n+\tif (b->branch_tree.tree && !oideq(&oid, &b->branch_tree.versions[1].oid)) {\n \t\trelease_tree_content_recursive(b->branch_tree.tree);\n \t\tb->branch_tree.tree = NULL;\n \t}\ndiff --git a/fetch-pack.c b/fetch-pack.c\nindex 88a078e9be..75047a4b2a 100644\n--- a/fetch-pack.c\n+++ b/fetch-pack.c\n@@ -599,7 +599,7 @@ static void filter_refs(struct fetch_pack_args *args,\n \t\t\tcontinue;\n \t\tif (parse_oid_hex(ref->name, &oid, &p) ||\n \t\t    *p != '\\0' ||\n-\t\t    oidcmp(&oid, &ref->old_oid))\n+\t\t    !oideq(&oid, &ref->old_oid))\n \t\t\tcontinue;\n \n \t\tif ((allow_unadvertised_object_request &\ndiff --git a/match-trees.c b/match-trees.c\nindex 37653308d3..2b6d31ef9d 100644\n--- a/match-trees.c\n+++ b/match-trees.c\n@@ -106,7 +106,7 @@ static int score_trees(const struct object_id *hash1, const struct object_id *ha\n \t\t\tupdate_tree_entry(&two);\n \t\t} else {\n \t\t\t/* path appears in both */\n-\t\t\tif (oidcmp(one.entry.oid, two.entry.oid)) {\n+\t\t\tif (!oideq(one.entry.oid, two.entry.oid)) {\n \t\t\t\t/* they are different */\n \t\t\t\tscore += score_differs(one.entry.mode,\n \t\t\t\t\t\t       two.entry.mode,\ndiff --git a/notes.c b/notes.c\nindex 33d16c1ec3..25cdce28b7 100644\n--- a/notes.c\n+++ b/notes.c\n@@ -206,7 +206,7 @@ static void note_tree_remove(struct notes_tree *t,\n \tif (GET_PTR_TYPE(*p) != PTR_TYPE_NOTE)\n \t\treturn; /* type mismatch, nothing to remove */\n \tl = (struct leaf_node *) CLR_PTR_TYPE(*p);\n-\tif (oidcmp(&l->key_oid, &entry->key_oid))\n+\tif (!oideq(&l->key_oid, &entry->key_oid))\n \t\treturn; /* key mismatch, nothing to remove */\n \n \t/* we have found a matching entry */\ndiff --git a/read-cache.c b/read-cache.c\nindex eb4919e77f..88bb80326b 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -2029,7 +2029,7 @@ int read_index_from(struct index_state *istate, const char *path,\n \tbase_oid_hex = oid_to_hex(&split_index->base_oid);\n \tbase_path = xstrfmt(\"%s/sharedindex.%s\", gitdir, base_oid_hex);\n \tret = do_read_index(split_index->base, base_path, 1);\n-\tif (oidcmp(&split_index->base_oid, &split_index->base->oid))\n+\tif (!oideq(&split_index->base_oid, &split_index->base->oid))\n \t\tdie(\"broken index, expect %s in %s, got %s\",\n \t\t    base_oid_hex, base_path,\n \t\t    oid_to_hex(&split_index->base->oid));\ndiff --git a/refs.c b/refs.c\nindex de81c7be7c..a7a75b4cc0 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -702,7 +702,7 @@ static int write_pseudoref(const char *pseudoref, const struct object_id *oid,\n \t\t\t\t    pseudoref);\n \t\t\trollback_lock_file(&lock);\n \t\t\tgoto done;\n-\t\t} else if (oidcmp(&actual_old_oid, old_oid)) {\n+\t\t} else if (!oideq(&actual_old_oid, old_oid)) {\n \t\t\tstrbuf_addf(err, _(\"unexpected object ID when writing '%s'\"),\n \t\t\t\t    pseudoref);\n \t\t\trollback_lock_file(&lock);\n@@ -744,7 +744,7 @@ static int delete_pseudoref(const char *pseudoref, const struct object_id *old_o\n \t\t}\n \t\tif (read_ref(pseudoref, &actual_old_oid))\n \t\t\tdie(_(\"could not read ref '%s'\"), pseudoref);\n-\t\tif (oidcmp(&actual_old_oid, old_oid)) {\n+\t\tif (!oideq(&actual_old_oid, old_oid)) {\n \t\t\terror(_(\"unexpected object ID when deleting '%s'\"),\n \t\t\t      pseudoref);\n \t\t\trollback_lock_file(&lock);\n@@ -875,13 +875,13 @@ static int read_ref_at_ent(struct object_id *ooid, struct object_id *noid,\n \t\t */\n \t\tif (!is_null_oid(&cb->ooid)) {\n \t\t\toidcpy(cb->oid, noid);\n-\t\t\tif (oidcmp(&cb->ooid, noid))\n+\t\t\tif (!oideq(&cb->ooid, noid))\n \t\t\t\twarning(_(\"log for ref %s has gap after %s\"),\n \t\t\t\t\tcb->refname, show_date(cb->date, cb->tz, DATE_MODE(RFC2822)));\n \t\t}\n \t\telse if (cb->date == cb->at_time)\n \t\t\toidcpy(cb->oid, noid);\n-\t\telse if (oidcmp(noid, cb->oid))\n+\t\telse if (!oideq(noid, cb->oid))\n \t\t\twarning(_(\"log for ref %s unexpectedly ended on %s\"),\n \t\t\t\tcb->refname, show_date(cb->date, cb->tz,\n \t\t\t\t\t\t       DATE_MODE(RFC2822)));\ndiff --git a/refs/files-backend.c b/refs/files-backend.c\nindex aa45f5317f..16ef9325e0 100644\n--- a/refs/files-backend.c\n+++ b/refs/files-backend.c\n@@ -841,7 +841,7 @@ static int verify_lock(struct ref_store *ref_store, struct ref_lock *lock,\n \t\t\treturn 0;\n \t\t}\n \t}\n-\tif (old_oid && oidcmp(&lock->old_oid, old_oid)) {\n+\tif (old_oid && !oideq(&lock->old_oid, old_oid)) {\n \t\tstrbuf_addf(err, \"ref '%s' is at %s but expected %s\",\n \t\t\t    lock->ref_name,\n \t\t\t    oid_to_hex(&lock->old_oid),\ndiff --git a/refs/packed-backend.c b/refs/packed-backend.c\nindex d447a731da..74e2996e93 100644\n--- a/refs/packed-backend.c\n+++ b/refs/packed-backend.c\n@@ -1160,7 +1160,7 @@ static int write_with_updates(struct packed_ref_store *refs,\n \t\t\t\t\t\t    \"reference already exists\",\n \t\t\t\t\t\t    update->refname);\n \t\t\t\t\tgoto error;\n-\t\t\t\t} else if (oidcmp(&update->old_oid, iter->oid)) {\n+\t\t\t\t} else if (!oideq(&update->old_oid, iter->oid)) {\n \t\t\t\t\tstrbuf_addf(err, \"cannot update ref '%s': \"\n \t\t\t\t\t\t    \"is at %s but expected %s\",\n \t\t\t\t\t\t    update->refname,\ndiff --git a/refs/ref-cache.c b/refs/ref-cache.c\nindex 9b110c8494..b7052f72e2 100644\n--- a/refs/ref-cache.c\n+++ b/refs/ref-cache.c\n@@ -272,7 +272,7 @@ static int is_dup_ref(const struct ref_entry *ref1, const struct ref_entry *ref2\n \t\t/* This is impossible by construction */\n \t\tdie(\"Reference directory conflict: %s\", ref1->name);\n \n-\tif (oidcmp(&ref1->u.value.oid, &ref2->u.value.oid))\n+\tif (!oideq(&ref1->u.value.oid, &ref2->u.value.oid))\n \t\tdie(\"Duplicated ref, and SHA1s don't match: %s\", ref1->name);\n \n \twarning(\"Duplicated ref: %s\", ref1->name);\ndiff --git a/remote.c b/remote.c\nindex 6f1ee9d640..e23b7675c8 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -1403,7 +1403,7 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,\n \t\t * branch.\n \t\t */\n \t\tif (ref->expect_old_sha1) {\n-\t\t\tif (oidcmp(&ref->old_oid, &ref->old_oid_expect))\n+\t\t\tif (!oideq(&ref->old_oid, &ref->old_oid_expect))\n \t\t\t\treject_reason = REF_STATUS_REJECT_STALE;\n \t\t\telse\n \t\t\t\t/* If the ref isn't stale then force the update. */\ndiff --git a/sequencer.c b/sequencer.c\nindex 5f823c9ec7..b14e5dc13c 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -1188,7 +1188,7 @@ static int parse_head(struct commit **head)\n \t\tcurrent_head = lookup_commit_reference(the_repository, &oid);\n \t\tif (!current_head)\n \t\t\treturn error(_(\"could not parse HEAD\"));\n-\t\tif (oidcmp(&oid, &current_head->object.oid)) {\n+\t\tif (!oideq(&oid, &current_head->object.oid)) {\n \t\t\twarning(_(\"HEAD %s is not a commit!\"),\n \t\t\t\toid_to_hex(&oid));\n \t\t}\n@@ -3034,7 +3034,7 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,\n \t\tstruct commit_list *p = commit->parents->next;\n \n \t\tfor (j = to_merge; j && p; j = j->next, p = p->next)\n-\t\t\tif (oidcmp(&j->item->object.oid,\n+\t\t\tif (!oideq(&j->item->object.oid,\n \t\t\t\t   &p->item->object.oid)) {\n \t\t\t\tcan_fast_forward = 0;\n \t\t\t\tbreak;\n@@ -3566,7 +3566,7 @@ static int commit_staged_changes(struct replay_opts *opts,\n \t\tif (get_oid_hex(rev.buf, &to_amend))\n \t\t\treturn error(_(\"invalid contents: '%s'\"),\n \t\t\t\trebase_path_amend());\n-\t\tif (!is_clean && oidcmp(&head, &to_amend))\n+\t\tif (!is_clean && !oideq(&head, &to_amend))\n \t\t\treturn error(_(\"\\nYou have uncommitted changes in your \"\n \t\t\t\t       \"working tree. Please, commit them\\n\"\n \t\t\t\t       \"first and then run 'git rebase \"\n@@ -4545,7 +4545,7 @@ int skip_unnecessary_picks(void)\n \t\tif (item->commit->parents->next)\n \t\t\tbreak; /* merge commit */\n \t\tparent_oid = &item->commit->parents->item->object.oid;\n-\t\tif (oidcmp(parent_oid, oid))\n+\t\tif (!oideq(parent_oid, oid))\n \t\t\tbreak;\n \t\toid = &item->commit->object.oid;\n \t}\ndiff --git a/sha1-file.c b/sha1-file.c\nindex 71f49ee56d..cc8a196349 100644\n--- a/sha1-file.c\n+++ b/sha1-file.c\n@@ -825,7 +825,7 @@ int check_object_signature(const struct object_id *oid, void *map,\n \n \tif (map) {\n \t\thash_object_file(map, size, type, &real_oid);\n-\t\treturn oidcmp(oid, &real_oid) ? -1 : 0;\n+\t\treturn !oideq(oid, &real_oid) ? -1 : 0;\n \t}\n \n \tst = open_istream(oid, &obj_type, &size, NULL);\n@@ -852,7 +852,7 @@ int check_object_signature(const struct object_id *oid, void *map,\n \t}\n \tthe_hash_algo->final_fn(real_oid.hash, &c);\n \tclose_istream(st);\n-\treturn oidcmp(oid, &real_oid) ? -1 : 0;\n+\treturn !oideq(oid, &real_oid) ? -1 : 0;\n }\n \n int git_open_cloexec(const char *name, int flags)\n@@ -1671,7 +1671,7 @@ static int write_loose_object(const struct object_id *oid, char *hdr,\n \t\tdie(_(\"deflateEnd on object %s failed (%d)\"), oid_to_hex(oid),\n \t\t    ret);\n \tthe_hash_algo->final_fn(parano_oid.hash, &c);\n-\tif (oidcmp(oid, &parano_oid) != 0)\n+\tif (!oideq(oid, &parano_oid))\n \t\tdie(_(\"confused by unstable object source data for %s\"),\n \t\t    oid_to_hex(oid));\n \ndiff --git a/submodule-config.c b/submodule-config.c\nindex fc2c41b947..e04ba756d9 100644\n--- a/submodule-config.c\n+++ b/submodule-config.c\n@@ -45,7 +45,7 @@ static int config_path_cmp(const void *unused_cmp_data,\n \tconst struct submodule_entry *b = entry_or_key;\n \n \treturn strcmp(a->config->path, b->config->path) ||\n-\t       oidcmp(&a->config->gitmodules_oid, &b->config->gitmodules_oid);\n+\t       !oideq(&a->config->gitmodules_oid, &b->config->gitmodules_oid);\n }\n \n static int config_name_cmp(const void *unused_cmp_data,\n@@ -57,7 +57,7 @@ static int config_name_cmp(const void *unused_cmp_data,\n \tconst struct submodule_entry *b = entry_or_key;\n \n \treturn strcmp(a->config->name, b->config->name) ||\n-\t       oidcmp(&a->config->gitmodules_oid, &b->config->gitmodules_oid);\n+\t       !oideq(&a->config->gitmodules_oid, &b->config->gitmodules_oid);\n }\n \n static struct submodule_cache *submodule_cache_alloc(void)\ndiff --git a/t/helper/test-dump-cache-tree.c b/t/helper/test-dump-cache-tree.c\nindex 98a4891f1d..6a3f88f5f5 100644\n--- a/t/helper/test-dump-cache-tree.c\n+++ b/t/helper/test-dump-cache-tree.c\n@@ -33,7 +33,7 @@ static int dump_cache_tree(struct cache_tree *it,\n \t}\n \telse {\n \t\tdump_one(it, pfx, \"\");\n-\t\tif (oidcmp(&it->oid, &ref->oid) ||\n+\t\tif (!oideq(&it->oid, &ref->oid) ||\n \t\t    ref->entry_count != it->entry_count ||\n \t\t    ref->subtree_nr != it->subtree_nr) {\n \t\t\t/* claims to be valid but is lying */\ndiff --git a/tree-diff.c b/tree-diff.c\nindex 553bc0e63a..425668e1e0 100644\n--- a/tree-diff.c\n+++ b/tree-diff.c\n@@ -491,7 +491,7 @@ static struct combine_diff_path *ll_diff_tree_paths(\n \t\t\t\t\t\tcontinue;\n \n \t\t\t\t\t/* diff(t,pi) != ø */\n-\t\t\t\t\tif (oidcmp(t.entry.oid, tp[i].entry.oid) ||\n+\t\t\t\t\tif (!oideq(t.entry.oid, tp[i].entry.oid) ||\n \t\t\t\t\t    (t.entry.mode != tp[i].entry.mode))\n \t\t\t\t\t\tcontinue;\n \n-- \n2.19.0.rc0.584.g84d5b2a847\n\n"},{"id":"356757","messageId":"20180828212252.GF11036@sigill.intra.peff.net","threadId":"49212","inReplyTo":"20180828212126.GA7039@sigill.intra.peff.net","subject":"[PATCH v2 6/9] convert \"hashcmp() != 0\" to \"!hasheq()\"","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2018-08-28T21:22:52Z","receivedAt":"2018-08-28T21:22:56Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"This rounds out the previous three patches, covering the\ninequality logic for the \"hash\" variant of the functions.\n\nAs with the previous three, the accompanying code changes\nare the mechanical result of applying the coccinelle patch;\nsee those patches for more discussion.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n builtin/index-pack.c               | 4 ++--\n builtin/show-branch.c              | 2 +-\n builtin/unpack-objects.c           | 2 +-\n commit-graph.c                     | 2 +-\n contrib/coccinelle/object_id.cocci | 9 +++++++++\n http-walker.c                      | 2 +-\n http.c                             | 2 +-\n pack-check.c                       | 6 +++---\n pack-write.c                       | 2 +-\n packfile.c                         | 2 +-\n read-cache.c                       | 4 ++--\n sha1-file.c                        | 2 +-\n 12 files changed, 24 insertions(+), 15 deletions(-)\n\ndiff --git a/builtin/index-pack.c b/builtin/index-pack.c\nindex edcb0a3dca..2004e25da2 100644\n--- a/builtin/index-pack.c\n+++ b/builtin/index-pack.c\n@@ -1166,7 +1166,7 @@ static void parse_pack_objects(unsigned char *hash)\n \t/* Check pack integrity */\n \tflush();\n \tthe_hash_algo->final_fn(hash, &input_ctx);\n-\tif (hashcmp(fill(the_hash_algo->rawsz), hash))\n+\tif (!hasheq(fill(the_hash_algo->rawsz), hash))\n \t\tdie(_(\"pack is corrupted (SHA1 mismatch)\"));\n \tuse(the_hash_algo->rawsz);\n \n@@ -1280,7 +1280,7 @@ static void conclude_pack(int fix_thin_pack, const char *curr_pack, unsigned cha\n \t\tfixup_pack_header_footer(output_fd, pack_hash,\n \t\t\t\t\t curr_pack, nr_objects,\n \t\t\t\t\t read_hash, consumed_bytes-the_hash_algo->rawsz);\n-\t\tif (hashcmp(read_hash, tail_hash) != 0)\n+\t\tif (!hasheq(read_hash, tail_hash))\n \t\t\tdie(_(\"Unexpected tail checksum for %s \"\n \t\t\t      \"(disk corruption?)\"), curr_pack);\n \t}\ndiff --git a/builtin/show-branch.c b/builtin/show-branch.c\nindex 5f9432861b..65f4a4c83c 100644\n--- a/builtin/show-branch.c\n+++ b/builtin/show-branch.c\n@@ -485,7 +485,7 @@ static void snarf_refs(int head, int remotes)\n static int rev_is_head(const char *head, const char *name,\n \t\t       unsigned char *head_sha1, unsigned char *sha1)\n {\n-\tif (!head || (head_sha1 && sha1 && hashcmp(head_sha1, sha1)))\n+\tif (!head || (head_sha1 && sha1 && !hasheq(head_sha1, sha1)))\n \t\treturn 0;\n \tskip_prefix(head, \"refs/heads/\", &head);\n \tif (!skip_prefix(name, \"refs/heads/\", &name))\ndiff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c\nindex ad438f5b41..80478808b3 100644\n--- a/builtin/unpack-objects.c\n+++ b/builtin/unpack-objects.c\n@@ -579,7 +579,7 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix)\n \t\tif (fsck_finish(&fsck_options))\n \t\t\tdie(_(\"fsck error in pack objects\"));\n \t}\n-\tif (hashcmp(fill(the_hash_algo->rawsz), oid.hash))\n+\tif (!hasheq(fill(the_hash_algo->rawsz), oid.hash))\n \t\tdie(\"final sha1 did not match\");\n \tuse(the_hash_algo->rawsz);\n \ndiff --git a/commit-graph.c b/commit-graph.c\nindex 7aed9f5371..64ce79420d 100644\n--- a/commit-graph.c\n+++ b/commit-graph.c\n@@ -900,7 +900,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g)\n \tf = hashfd(devnull, NULL);\n \thashwrite(f, g->data, g->data_len - g->hash_len);\n \tfinalize_hashfile(f, checksum.hash, CSUM_CLOSE);\n-\tif (hashcmp(checksum.hash, g->data + g->data_len - g->hash_len)) {\n+\tif (!hasheq(checksum.hash, g->data + g->data_len - g->hash_len)) {\n \t\tgraph_report(_(\"the commit-graph file has incorrect checksum and is likely corrupt\"));\n \t\tverify_commit_graph_error = VERIFY_COMMIT_GRAPH_ERROR_HASH;\n \t}\ndiff --git a/contrib/coccinelle/object_id.cocci b/contrib/coccinelle/object_id.cocci\nindex 4e1f1a7431..d8bdb48712 100644\n--- a/contrib/coccinelle/object_id.cocci\n+++ b/contrib/coccinelle/object_id.cocci\n@@ -129,3 +129,12 @@ expression E1, E2;\n @@\n - oidcmp(E1, E2) != 0\n + !oideq(E1, E2)\n+\n+@@\n+identifier f != hasheq;\n+expression E1, E2;\n+@@\n+  f(...) {<...\n+- hashcmp(E1, E2) != 0\n++ !hasheq(E1, E2)\n+  ...>}\ndiff --git a/http-walker.c b/http-walker.c\nindex 3a8edc7f2f..b3334bf657 100644\n--- a/http-walker.c\n+++ b/http-walker.c\n@@ -543,7 +543,7 @@ static int fetch_object(struct walker *walker, unsigned char *sha1)\n \t} else if (req->zret != Z_STREAM_END) {\n \t\twalker->corrupt_object_found++;\n \t\tret = error(\"File %s (%s) corrupt\", hex, req->url);\n-\t} else if (hashcmp(obj_req->oid.hash, req->real_sha1)) {\n+\t} else if (!hasheq(obj_req->oid.hash, req->real_sha1)) {\n \t\tret = error(\"File %s has bad hash\", hex);\n \t} else if (req->rename < 0) {\n \t\tstruct strbuf buf = STRBUF_INIT;\ndiff --git a/http.c b/http.c\nindex 4162860ee3..98ff122585 100644\n--- a/http.c\n+++ b/http.c\n@@ -2394,7 +2394,7 @@ int finish_http_object_request(struct http_object_request *freq)\n \t\tunlink_or_warn(freq->tmpfile.buf);\n \t\treturn -1;\n \t}\n-\tif (hashcmp(freq->sha1, freq->real_sha1)) {\n+\tif (!hasheq(freq->sha1, freq->real_sha1)) {\n \t\tunlink_or_warn(freq->tmpfile.buf);\n \t\treturn -1;\n \t}\ndiff --git a/pack-check.c b/pack-check.c\nindex d3a57df34f..fa5f0ff8fa 100644\n--- a/pack-check.c\n+++ b/pack-check.c\n@@ -79,10 +79,10 @@ static int verify_packfile(struct packed_git *p,\n \t} while (offset < pack_sig_ofs);\n \tthe_hash_algo->final_fn(hash, &ctx);\n \tpack_sig = use_pack(p, w_curs, pack_sig_ofs, NULL);\n-\tif (hashcmp(hash, pack_sig))\n+\tif (!hasheq(hash, pack_sig))\n \t\terr = error(\"%s pack checksum mismatch\",\n \t\t\t    p->pack_name);\n-\tif (hashcmp(index_base + index_size - the_hash_algo->hexsz, pack_sig))\n+\tif (!hasheq(index_base + index_size - the_hash_algo->hexsz, pack_sig))\n \t\terr = error(\"%s pack checksum does not match its index\",\n \t\t\t    p->pack_name);\n \tunuse_pack(w_curs);\n@@ -180,7 +180,7 @@ int verify_pack_index(struct packed_git *p)\n \tthe_hash_algo->init_fn(&ctx);\n \tthe_hash_algo->update_fn(&ctx, index_base, (unsigned int)(index_size - the_hash_algo->rawsz));\n \tthe_hash_algo->final_fn(hash, &ctx);\n-\tif (hashcmp(hash, index_base + index_size - the_hash_algo->rawsz))\n+\tif (!hasheq(hash, index_base + index_size - the_hash_algo->rawsz))\n \t\terr = error(\"Packfile index for %s hash mismatch\",\n \t\t\t    p->pack_name);\n \treturn err;\ndiff --git a/pack-write.c b/pack-write.c\nindex 7d14716c40..29d17a9bec 100644\n--- a/pack-write.c\n+++ b/pack-write.c\n@@ -260,7 +260,7 @@ void fixup_pack_header_footer(int pack_fd,\n \t\tif (partial_pack_offset == 0) {\n \t\t\tunsigned char hash[GIT_MAX_RAWSZ];\n \t\t\tthe_hash_algo->final_fn(hash, &old_hash_ctx);\n-\t\t\tif (hashcmp(hash, partial_pack_hash) != 0)\n+\t\t\tif (!hasheq(hash, partial_pack_hash))\n \t\t\t\tdie(\"Unexpected checksum for %s \"\n \t\t\t\t    \"(disk corruption?)\", pack_name);\n \t\t\t/*\ndiff --git a/packfile.c b/packfile.c\nindex c2e96293ad..1e9eacd9b3 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -517,7 +517,7 @@ static int open_packed_git_1(struct packed_git *p)\n \tif (read_result != hashsz)\n \t\treturn error(\"packfile %s signature is unavailable\", p->pack_name);\n \tidx_hash = ((unsigned char *)p->index_data) + p->index_size - hashsz * 2;\n-\tif (hashcmp(hash, idx_hash))\n+\tif (!hasheq(hash, idx_hash))\n \t\treturn error(\"packfile %s does not match index\", p->pack_name);\n \treturn 0;\n }\ndiff --git a/read-cache.c b/read-cache.c\nindex 88bb80326b..421a7f4953 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -1668,7 +1668,7 @@ static int verify_hdr(struct cache_header *hdr, unsigned long size)\n \tthe_hash_algo->init_fn(&c);\n \tthe_hash_algo->update_fn(&c, hdr, size - the_hash_algo->rawsz);\n \tthe_hash_algo->final_fn(hash, &c);\n-\tif (hashcmp(hash, (unsigned char *)hdr + size - the_hash_algo->rawsz))\n+\tif (!hasheq(hash, (unsigned char *)hdr + size - the_hash_algo->rawsz))\n \t\treturn error(\"bad index file sha1 signature\");\n \treturn 0;\n }\n@@ -2395,7 +2395,7 @@ static int verify_index_from(const struct index_state *istate, const char *path)\n \tif (n != the_hash_algo->rawsz)\n \t\tgoto out;\n \n-\tif (hashcmp(istate->oid.hash, hash))\n+\tif (!hasheq(istate->oid.hash, hash))\n \t\tgoto out;\n \n \tclose(fd);\ndiff --git a/sha1-file.c b/sha1-file.c\nindex cc8a196349..d85f4e93e1 100644\n--- a/sha1-file.c\n+++ b/sha1-file.c\n@@ -2213,7 +2213,7 @@ static int check_stream_sha1(git_zstream *stream,\n \t}\n \n \tthe_hash_algo->final_fn(real_sha1, &c);\n-\tif (hashcmp(expected_sha1, real_sha1)) {\n+\tif (!hasheq(expected_sha1, real_sha1)) {\n \t\terror(_(\"sha1 mismatch for %s (expected %s)\"), path,\n \t\t      sha1_to_hex(expected_sha1));\n \t\treturn -1;\n-- \n2.19.0.rc0.584.g84d5b2a847\n\n"},{"id":"356758","messageId":"20180828212255.GG11036@sigill.intra.peff.net","threadId":"49212","inReplyTo":"20180828212126.GA7039@sigill.intra.peff.net","subject":"[PATCH v2 7/9] convert hashmap comparison functions to oideq()","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2018-08-28T21:22:55Z","receivedAt":"2018-08-28T21:22:59Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"The comparison functions used for hashmaps don't care about\nstrict ordering; they only want to compare entries for\nequality. Let's use the oideq() function instead, which can\npotentially be better optimized. Note that unlike the\nprevious patches mass-converting calls like \"!oidcmp()\",\nthis patch could actually provide an improvement even with\nthe current implementation. Those comparison functions are\npassed around as function pointers, so at compile-time the\ncompiler cannot realize that the caller (which is in another\nfile completely) will treat the return value as a boolean.\n\nNote that this does change the return values in quite a\nsubtle way (it's still an int, but now the sign bit is\nirrelevant for ordering). Because of their funny\nhashmap-specific signature, it's unlikely that any of these\nstatic functions would be reused for more generic ordering.\nBut to be double-sure, let's stop using \"cmp\" in their\nnames.\n\nCalling them \"eq\" doesn't quite work either, because the\nhashmap convention is actually _inverted_. \"0\" means \"same\",\nand non-zero means \"different\". So I've called them \"neq\" by\nconvention here.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n builtin/describe.c |  6 +++---\n oidmap.c           | 12 ++++++------\n patch-ids.c        |  8 ++++----\n 3 files changed, 13 insertions(+), 13 deletions(-)\n\ndiff --git a/builtin/describe.c b/builtin/describe.c\nindex 1e7c75ba82..22c0541da5 100644\n--- a/builtin/describe.c\n+++ b/builtin/describe.c\n@@ -62,7 +62,7 @@ static const char *prio_names[] = {\n \tN_(\"head\"), N_(\"lightweight\"), N_(\"annotated\"),\n };\n \n-static int commit_name_cmp(const void *unused_cmp_data,\n+static int commit_name_neq(const void *unused_cmp_data,\n \t\t\t   const void *entry,\n \t\t\t   const void *entry_or_key,\n \t\t\t   const void *peeled)\n@@ -70,7 +70,7 @@ static int commit_name_cmp(const void *unused_cmp_data,\n \tconst struct commit_name *cn1 = entry;\n \tconst struct commit_name *cn2 = entry_or_key;\n \n-\treturn oidcmp(&cn1->peeled, peeled ? peeled : &cn2->peeled);\n+\treturn !oideq(&cn1->peeled, peeled ? peeled : &cn2->peeled);\n }\n \n static inline struct commit_name *find_commit_name(const struct object_id *peeled)\n@@ -596,7 +596,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)\n \t\treturn cmd_name_rev(args.argc, args.argv, prefix);\n \t}\n \n-\thashmap_init(&names, commit_name_cmp, NULL, 0);\n+\thashmap_init(&names, commit_name_neq, NULL, 0);\n \tfor_each_rawref(get_name, NULL);\n \tif (!hashmap_get_size(&names) && !always)\n \t\tdie(_(\"No names found, cannot describe anything.\"));\ndiff --git a/oidmap.c b/oidmap.c\nindex d9fb19ba6a..b0841a0f58 100644\n--- a/oidmap.c\n+++ b/oidmap.c\n@@ -1,14 +1,14 @@\n #include \"cache.h\"\n #include \"oidmap.h\"\n \n-static int cmpfn(const void *hashmap_cmp_fn_data,\n-\t\t const void *entry, const void *entry_or_key,\n-\t\t const void *keydata)\n+static int oidmap_neq(const void *hashmap_cmp_fn_data,\n+\t\t      const void *entry, const void *entry_or_key,\n+\t\t      const void *keydata)\n {\n \tconst struct oidmap_entry *entry_ = entry;\n \tif (keydata)\n-\t\treturn oidcmp(&entry_->oid, (const struct object_id *) keydata);\n-\treturn oidcmp(&entry_->oid,\n+\t\treturn !oideq(&entry_->oid, (const struct object_id *) keydata);\n+\treturn !oideq(&entry_->oid,\n \t\t      &((const struct oidmap_entry *) entry_or_key)->oid);\n }\n \n@@ -21,7 +21,7 @@ static int hash(const struct object_id *oid)\n \n void oidmap_init(struct oidmap *map, size_t initial_size)\n {\n-\thashmap_init(&map->map, cmpfn, NULL, initial_size);\n+\thashmap_init(&map->map, oidmap_neq, NULL, initial_size);\n }\n \n void oidmap_free(struct oidmap *map, int free_entries)\ndiff --git a/patch-ids.c b/patch-ids.c\nindex 8f7c25d5db..960ea24054 100644\n--- a/patch-ids.c\n+++ b/patch-ids.c\n@@ -28,14 +28,14 @@ int commit_patch_id(struct commit *commit, struct diff_options *options,\n /*\n  * When we cannot load the full patch-id for both commits for whatever\n  * reason, the function returns -1 (i.e. return error(...)). Despite\n- * the \"cmp\" in the name of this function, the caller only cares about\n+ * the \"neq\" in the name of this function, the caller only cares about\n  * the return value being zero (a and b are equivalent) or non-zero (a\n  * and b are different), and returning non-zero would keep both in the\n  * result, even if they actually were equivalent, in order to err on\n  * the side of safety.  The actual value being negative does not have\n  * any significance; only that it is non-zero matters.\n  */\n-static int patch_id_cmp(const void *cmpfn_data,\n+static int patch_id_neq(const void *cmpfn_data,\n \t\t\tconst void *entry,\n \t\t\tconst void *entry_or_key,\n \t\t\tconst void *unused_keydata)\n@@ -53,7 +53,7 @@ static int patch_id_cmp(const void *cmpfn_data,\n \t    commit_patch_id(b->commit, opt, &b->patch_id, 0))\n \t\treturn error(\"Could not get patch ID for %s\",\n \t\t\toid_to_hex(&b->commit->object.oid));\n-\treturn oidcmp(&a->patch_id, &b->patch_id);\n+\treturn !oideq(&a->patch_id, &b->patch_id);\n }\n \n int init_patch_ids(struct patch_ids *ids)\n@@ -63,7 +63,7 @@ int init_patch_ids(struct patch_ids *ids)\n \tids->diffopts.detect_rename = 0;\n \tids->diffopts.flags.recursive = 1;\n \tdiff_setup_done(&ids->diffopts);\n-\thashmap_init(&ids->patches, patch_id_cmp, &ids->diffopts, 256);\n+\thashmap_init(&ids->patches, patch_id_neq, &ids->diffopts, 256);\n \treturn 0;\n }\n \n-- \n2.19.0.rc0.584.g84d5b2a847\n\n"},{"id":"356759","messageId":"20180828212259.GH11036@sigill.intra.peff.net","threadId":"49212","inReplyTo":"20180828212126.GA7039@sigill.intra.peff.net","subject":"[PATCH v2 8/9] read-cache: use oideq() in ce_compare functions","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2018-08-28T21:22:59Z","receivedAt":"2018-08-28T21:23:02Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"These functions return the full oidcmp() value, but the\ncallers really only care whether it is non-zero. We can use\nthe more strict !oideq(), which a compiler may be able to\noptimize further.\n\nThis does change the meaning of the return value subtly, but\nit's unlikely that anybody would try to use them for\nordering. They're static-local in this file, and they\nalready return other error values that would confuse an\nordering (e.g., open() failure gives -1).\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n read-cache.c | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/read-cache.c b/read-cache.c\nindex 421a7f4953..eb7cea6272 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -213,7 +213,7 @@ static int ce_compare_data(const struct cache_entry *ce, struct stat *st)\n \tif (fd >= 0) {\n \t\tstruct object_id oid;\n \t\tif (!index_fd(&oid, fd, st, OBJ_BLOB, ce->name, 0))\n-\t\t\tmatch = oidcmp(&oid, &ce->oid);\n+\t\t\tmatch = !oideq(&oid, &ce->oid);\n \t\t/* index_fd() closed the file descriptor already */\n \t}\n \treturn match;\n@@ -254,7 +254,7 @@ static int ce_compare_gitlink(const struct cache_entry *ce)\n \t */\n \tif (resolve_gitlink_ref(ce->name, \"HEAD\", &oid) < 0)\n \t\treturn 0;\n-\treturn oidcmp(&oid, &ce->oid);\n+\treturn !oideq(&oid, &ce->oid);\n }\n \n static int ce_modified_check_fs(const struct cache_entry *ce, struct stat *st)\n-- \n2.19.0.rc0.584.g84d5b2a847\n\n"},{"id":"356760","messageId":"20180828212303.GI11036@sigill.intra.peff.net","threadId":"49212","inReplyTo":"20180828212126.GA7039@sigill.intra.peff.net","subject":"[PATCH v2 9/9] show_dirstat: simplify same-content check","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2018-08-28T21:23:03Z","receivedAt":"2018-08-28T21:23:06Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"We use two nested conditionals to store a content_changed\nvariable, but only bother to look at the result once,\ndirectly after we set it. We can drop the variable entirely\nand just use a single \"if\".\n\nThis needless complexity is the result of 2ff3a80334 (Teach\n--dirstat not to completely ignore rearranged lines within a\nfile, 2011-04-11). Before that, we held onto the\ncontent_changed variable much longer.\n\nWhile we're touching the condition, we can swap out oidcmp()\nfor !oideq(). Our coccinelle patches didn't previously find\nthis case because of the intermediate variable, but now it's\na simple boolean in a conditional.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n diff.c | 11 +++--------\n 1 file changed, 3 insertions(+), 8 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 5d3219b600..605ba4b6b8 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -2933,16 +2933,11 @@ static void show_dirstat(struct diff_options *options)\n \t\tstruct diff_filepair *p = q->queue[i];\n \t\tconst char *name;\n \t\tunsigned long copied, added, damage;\n-\t\tint content_changed;\n \n \t\tname = p->two->path ? p->two->path : p->one->path;\n \n-\t\tif (p->one->oid_valid && p->two->oid_valid)\n-\t\t\tcontent_changed = oidcmp(&p->one->oid, &p->two->oid);\n-\t\telse\n-\t\t\tcontent_changed = 1;\n-\n-\t\tif (!content_changed) {\n+\t\tif (p->one->oid_valid && p->two->oid_valid &&\n+\t\t    oideq(&p->one->oid, &p->two->oid)) {\n \t\t\t/*\n \t\t\t * The SHA1 has not changed, so pre-/post-content is\n \t\t\t * identical. We can therefore skip looking at the\n@@ -2989,7 +2984,7 @@ static void show_dirstat(struct diff_options *options)\n \t\t * made to the preimage.\n \t\t * If the resulting damage is zero, we know that\n \t\t * diffcore_count_changes() considers the two entries to\n-\t\t * be identical, but since content_changed is true, we\n+\t\t * be identical, but since the oid changed, we\n \t\t * know that there must have been _some_ kind of change,\n \t\t * so we force all entries to have damage > 0.\n \t\t */\n-- \n2.19.0.rc0.584.g84d5b2a847\n"},{"id":"356771","messageId":"4a35886d-b1f5-6d5a-554e-508d838e542e@gmail.com","threadId":"49212","inReplyTo":"20180828212126.GA7039@sigill.intra.peff.net","subject":"Re: [PATCH 0/9] introducing oideq()","fromName":"Derrick Stolee","fromEmail":"stolee@gmail.com","sentAt":"2018-08-28T21:36:03Z","receivedAt":"2018-08-28T21:36:14Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 8/28/2018 5:21 PM, Jeff King wrote:\n> On Sun, Aug 26, 2018 at 08:56:21PM +0000, brian m. carlson wrote:\n>\n>>> Due to the simplicity of the current code and our inlining, the compiler\n>>> can usually figure this out for now. So I wouldn't expect this patch to\n>>> actually improve performance right away. But as that discussion shows,\n>>> we are likely to take a performance hit as we move to more runtime\n>>> determination of the_hash_algo parameters. Having these callers use the\n>>> more strict form will potentially help us recover that.\n>>>\n>>> So in that sense we _could_ simply punt on this series until then (and\n>>> it's certainly post-v2.19 material). But I think it's worth doing now,\n>>> simply from a readability/annotation standpoint. IMHO the resulting code\n>>> is more clear (though I've long since taught myself to read !foocmp() as\n>>> equality).\n>> I would quite like to see this series picked up for v2.20.  If we want\n>> to minimize performance regressions with the SHA-256 work, I think it's\n>> important.\n> Thanks. One of the things I was worried about was causing unnecessary\n> conflicts with existing topics, including your work. But if everybody is\n> on board, I'd be happy to see this go in early in the next release cycle\n> (the longer we wait, the more annoying conflicts Junio has to resolve).\n\nI'm happy to take this change whenever. In my opinion, right after \nv2.19.0 is cut would be a great time to merge it into master.\n\nThis v2 is good.\n\nReviewed-by: Derrick Stolee <dstolee@microsoft.com>\n\n"},{"id":"356781","messageId":"20180829000806.GC432229@genre.crustytoothpaste.net","threadId":"49212","inReplyTo":"20180828212126.GA7039@sigill.intra.peff.net","subject":"Re: [PATCH 0/9] introducing oideq()","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-08-29T00:08:06Z","receivedAt":"2018-08-29T00:08:14Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Tue, Aug 28, 2018 at 05:21:27PM -0400, Jeff King wrote:\n> On Sun, Aug 26, 2018 at 08:56:21PM +0000, brian m. carlson wrote:\n> > I would quite like to see this series picked up for v2.20.  If we want\n> > to minimize performance regressions with the SHA-256 work, I think it's\n> > important.\n> \n> Thanks. One of the things I was worried about was causing unnecessary\n> conflicts with existing topics, including your work. But if everybody is\n> on board, I'd be happy to see this go in early in the next release cycle\n> (the longer we wait, the more annoying conflicts Junio has to resolve).\n\nI can send out work that doesn't conflict with this while it makes its\nway to master.  There are a lot of test fixes that can go in in the mean\ntime.\n\nI will be sending out a series that actually implements SHA-256 as an\nRFC soon, but I don't think there will be any conflicts (and it will\njust be an RFC anyway).\n-- \nbrian m. carlson: Houston, Texas, US\nOpenPGP: https://keybase.io/bk2204\n"}]}