{"thread":{"id":"5300","subject":"[PATCH] introduce inline is_same_sha1","startedAt":"2006-08-17T00:25:30Z","lastAt":"2006-08-18T04:09:07Z","messageCount":8,"participants":["David Rientjes","Junio C Hamano","Alex Riesen"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"25440","messageId":"Pine.LNX.4.63.0608161721020.11465@chino.corp.google.com","threadId":"5300","inReplyTo":null,"subject":"[PATCH] introduce inline is_same_sha1","fromName":"David Rientjes","fromEmail":"rientjes@google.com","sentAt":"2006-08-17T00:25:30Z","receivedAt":"2006-08-17T00:25:30Z","isPatch":true,"sender":{"key":"rientjes@google.com","avatar":null},"body":"Introduces global inline:\n\tis_same_sha1(const unsigned char *sha1,\n\t\t     const unsigned char *sha2);\n\nUses memcmp for comparison and returns the result.  All tests for comparisons \nfor sha1 have been changed to use the new global inline, but existing uses of \nmemcmp have been preserved where the return value other than 0 is needed, i.e.:\n\n\tint cmp = !memcmp(old_sha1, new_sha1, 20);\n\nConversions from char* to unsigned char* casts have been made where appropriate.\n\nSigned-off-by: David Rientjes <rientjes@google.com>\n---\n builtin-commit-tree.c    |    2 +-\n builtin-diff-stages.c    |    2 +-\n builtin-diff.c           |    2 +-\n builtin-pack-objects.c   |    6 +++---\n builtin-show-branch.c    |    4 ++--\n builtin-unpack-objects.c |    4 ++--\n builtin-update-index.c   |    4 ++--\n cache.h                  |    4 ++++\n combine-diff.c           |    4 ++--\n diff-lib.c               |    2 +-\n diff.c                   |    8 ++++----\n diffcore-break.c         |    2 +-\n diffcore-rename.c        |    2 +-\n dump-cache-tree.c        |    2 +-\n http-fetch.c             |    6 +++---\n http-push.c              |    4 ++--\n index-pack.c             |   10 ++++++----\n merge-tree.c             |    2 +-\n object.c                 |    2 +-\n pack-check.c             |    6 +++---\n read-cache.c             |    2 +-\n refs.c                   |    8 ++++----\n send-pack.c              |    2 +-\n sha1_file.c              |   16 ++++++++--------\n sha1_name.c              |    4 ++--\n ssh-fetch.c              |    2 +-\n tree-diff.c              |    2 +-\n unpack-trees.c           |    2 +-\n 28 files changed, 61 insertions(+), 55 deletions(-)\n\ndiff --git a/builtin-commit-tree.c b/builtin-commit-tree.c\nindex 9c98796..99fab3b 100644\n--- a/builtin-commit-tree.c\n+++ b/builtin-commit-tree.c\n@@ -69,7 +69,7 @@ static int new_parent(int idx)\n \tint i;\n \tunsigned char *sha1 = parent_sha1[idx];\n \tfor (i = 0; i < idx; i++) {\n-\t\tif (!memcmp(parent_sha1[i], sha1, 20)) {\n+\t\tif (is_same_sha1(parent_sha1[i], sha1)) {\n \t\t\terror(\"duplicate parent %s ignored\", sha1_to_hex(sha1));\n \t\t\treturn 0;\n \t\t}\ndiff --git a/builtin-diff-stages.c b/builtin-diff-stages.c\nindex 5960e08..4593fd2 100644\n--- a/builtin-diff-stages.c\n+++ b/builtin-diff-stages.c\n@@ -46,7 +46,7 @@ static void diff_stages(int stage1, int \n \t\telse if (!two)\n \t\t\tdiff_addremove(&diff_options, '-', ntohl(one->ce_mode),\n \t\t\t\t       one->sha1, name, NULL);\n-\t\telse if (memcmp(one->sha1, two->sha1, 20) ||\n+\t\telse if (!is_same_sha1(one->sha1, two->sha1) ||\n \t\t\t (one->ce_mode != two->ce_mode) ||\n \t\t\t diff_options.find_copies_harder)\n \t\t\tdiff_change(&diff_options,\ndiff --git a/builtin-diff.c b/builtin-diff.c\nindex 40e5c96..12ae9b1 100644\n--- a/builtin-diff.c\n+++ b/builtin-diff.c\n@@ -69,7 +69,7 @@ static void stuff_change(struct diff_opt\n \tstruct diff_filespec *one, *two;\n \n \tif (!is_null_sha1(old_sha1) && !is_null_sha1(new_sha1) &&\n-\t    !memcmp(old_sha1, new_sha1, 20))\n+\t    is_same_sha1(old_sha1, new_sha1))\n \t\treturn;\n \n \tif (opt->reverse_diff) {\ndiff --git a/builtin-pack-objects.c b/builtin-pack-objects.c\nindex 448461b..3c1d3c1 100644\n--- a/builtin-pack-objects.c\n+++ b/builtin-pack-objects.c\n@@ -441,7 +441,7 @@ static int locate_object_entry_hash(cons\n \tmemcpy(&ui, sha1, sizeof(unsigned int));\n \ti = ui % object_ix_hashsz;\n \twhile (0 < object_ix[i]) {\n-\t\tif (!memcmp(sha1, objects[object_ix[i]-1].sha1, 20))\n+\t\tif (is_same_sha1(sha1, objects[object_ix[i] - 1].sha1))\n \t\t\treturn i;\n \t\tif (++i == object_ix_hashsz)\n \t\t\ti = 0;\n@@ -607,7 +607,7 @@ static struct pbase_tree_cache *pbase_tr\n \t */\n \tfor (neigh = 0; neigh < 8; neigh++) {\n \t\tent = pbase_tree_cache[my_ix];\n-\t\tif (ent && !memcmp(ent->sha1, sha1, 20)) {\n+\t\tif (ent && is_same_sha1(ent->sha1, sha1)) {\n \t\t\tent->ref++;\n \t\t\treturn ent;\n \t\t}\n@@ -789,7 +789,7 @@ static void add_preferred_base(unsigned \n \t\treturn;\n \n \tfor (it = pbase_tree; it; it = it->next) {\n-\t\tif (!memcmp(it->pcache.sha1, tree_sha1, 20)) {\n+\t\tif (is_same_sha1(it->pcache.sha1, tree_sha1)) {\n \t\t\tfree(data);\n \t\t\treturn;\n \t\t}\ndiff --git a/builtin-show-branch.c b/builtin-show-branch.c\nindex 95fbf77..88c7c1c 100644\n--- a/builtin-show-branch.c\n+++ b/builtin-show-branch.c\n@@ -378,7 +378,7 @@ static int append_head_ref(const char *r\n \t/* If both heads/foo and tags/foo exists, get_sha1 would\n \t * get confused.\n \t */\n-\tif (get_sha1(refname + ofs, tmp) || memcmp(tmp, sha1, 20))\n+\tif (get_sha1(refname + ofs, tmp) || !is_same_sha1(tmp, sha1))\n \t\tofs = 5;\n \treturn append_ref(refname + ofs, sha1);\n }\n@@ -442,7 +442,7 @@ static int rev_is_head(char *head_path, \n {\n \tint namelen;\n \tif ((!head_path[0]) ||\n-\t    (head_sha1 && sha1 && memcmp(head_sha1, sha1, 20)))\n+\t    (head_sha1 && sha1 && !is_same_sha1(head_sha1, sha1)))\n \t\treturn 0;\n \tnamelen = strlen(name);\n \tif ((headlen < namelen) ||\ndiff --git a/builtin-unpack-objects.c b/builtin-unpack-objects.c\nindex 63f4b8e..4f42d21 100644\n--- a/builtin-unpack-objects.c\n+++ b/builtin-unpack-objects.c\n@@ -136,7 +136,7 @@ static void added_object(unsigned char *\n \tstruct delta_info *info;\n \n \twhile ((info = *p) != NULL) {\n-\t\tif (!memcmp(info->base_sha1, sha1, 20)) {\n+\t\tif (is_same_sha1(info->base_sha1, sha1)) {\n \t\t\t*p = info->next;\n \t\t\tp = &delta_list;\n \t\t\tresolve_delta(type, data, size, info->delta, info->size);\n@@ -292,7 +292,7 @@ int cmd_unpack_objects(int argc, const c\n \tunpack_all();\n \tSHA1_Update(&ctx, buffer, offset);\n \tSHA1_Final(sha1, &ctx);\n-\tif (memcmp(fill(20), sha1, 20))\n+\tif (!is_same_sha1(fill(20), sha1))\n \t\tdie(\"final sha1 did not match\");\n \tuse(20);\n \ndiff --git a/builtin-update-index.c b/builtin-update-index.c\nindex 9f0cf28..1f74edd 100644\n--- a/builtin-update-index.c\n+++ b/builtin-update-index.c\n@@ -378,7 +378,7 @@ static int unresolve_one(const char *pat\n \t\tret = -1;\n \t\tgoto free_return;\n \t}\n-\tif (!memcmp(ce_2->sha1, ce_3->sha1, 20) &&\n+\tif (is_same_sha1(ce_2->sha1, ce_3->sha1) &&\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@@ -460,7 +460,7 @@ static int do_reupdate(int ac, const cha\n \t\t\told = read_one_ent(NULL, head_sha1,\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    !memcmp(ce->sha1, old->sha1, 20)) {\n+\t\t    is_same_sha1(ce->sha1, old->sha1)) {\n \t\t\tfree(old);\n \t\t\tcontinue; /* unchanged */\n \t\t}\ndiff --git a/cache.h b/cache.h\nindex c738299..5a78b03 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -214,6 +214,10 @@ static inline int is_null_sha1(const uns\n {\n \treturn !memcmp(sha1, null_sha1, 20);\n }\n+static inline int is_same_sha1(const unsigned char *sha1, const unsigned char *sha2)\n+{\n+\treturn !memcmp(sha1, sha2, 20);\n+}\n \n int git_mkstemp(char *path, size_t n, const char *template);\n \ndiff --git a/combine-diff.c b/combine-diff.c\nindex ce063b4..c78a157 100644\n--- a/combine-diff.c\n+++ b/combine-diff.c\n@@ -688,8 +688,8 @@ static void show_patch_diff(struct combi\n \tfor (i = 0; i < num_parent; i++) {\n \t\tint j;\n \t\tfor (j = 0; j < i; j++) {\n-\t\t\tif (!memcmp(elem->parent[i].sha1,\n-\t\t\t\t    elem->parent[j].sha1, 20)) {\n+\t\t\tif (is_same_sha1(elem->parent[i].sha1,\n+\t\t\t\t\t elem->parent[j].sha1)) {\n \t\t\t\treuse_combine_diff(sline, cnt, i, j);\n \t\t\t\tbreak;\n \t\t\t}\ndiff --git a/diff-lib.c b/diff-lib.c\nindex 116b5a9..4bcb350 100644\n--- a/diff-lib.c\n+++ b/diff-lib.c\n@@ -215,7 +215,7 @@ static int show_modified(struct rev_info\n \t}\n \n \toldmode = old->ce_mode;\n-\tif (mode == oldmode && !memcmp(sha1, old->sha1, 20) &&\n+\tif (mode == oldmode && is_same_sha1(sha1, old->sha1) &&\n \t    !revs->diffopt.find_copies_harder)\n \t\treturn 0;\n \ndiff --git a/diff.c b/diff.c\nindex 7a238d0..b1e07a1 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -1140,7 +1140,7 @@ static int work_tree_matches(const char \n \tif ((lstat(name, &st) < 0) ||\n \t    !S_ISREG(st.st_mode) || /* careful! */\n \t    ce_match_stat(ce, &st, 0) ||\n-\t    memcmp(sha1, ce->sha1, 20))\n+\t    !is_same_sha1(sha1, ce->sha1))\n \t\treturn 0;\n \t/* we return 1 only when we can stat, it is a regular file,\n \t * stat information matches, and sha1 recorded in the cache\n@@ -1579,7 +1579,7 @@ static void run_diff(struct diff_filepai\n \t\t;\n \t}\n \n-\tif (memcmp(one->sha1, two->sha1, 20)) {\n+\tif (!is_same_sha1(one->sha1, two->sha1)) {\n \t\tint abbrev = o->full_index ? 40 : DEFAULT_ABBREV;\n \n \t\tlen += snprintf(msg + len, sizeof(msg) - len,\n@@ -2098,7 +2098,7 @@ int diff_unmodified_pair(struct diff_fil\n \t * dealing with a change.\n \t */\n \tif (one->sha1_valid && two->sha1_valid &&\n-\t    !memcmp(one->sha1, two->sha1, sizeof(one->sha1)))\n+\t    is_same_sha1(one->sha1, two->sha1))\n \t\treturn 1; /* no change */\n \tif (!one->sha1_valid && !two->sha1_valid)\n \t\treturn 1; /* both look at the same file on the filesystem. */\n@@ -2237,7 +2237,7 @@ static void diff_resolve_rename_copy(voi\n \t\t\tif (!p->status)\n \t\t\t\tp->status = DIFF_STATUS_RENAMED;\n \t\t}\n-\t\telse if (memcmp(p->one->sha1, p->two->sha1, 20) ||\n+\t\telse if (!is_same_sha1(p->one->sha1, p->two->sha1) ||\n \t\t\t p->one->mode != p->two->mode)\n \t\t\tp->status = DIFF_STATUS_MODIFIED;\n \t\telse {\ndiff --git a/diffcore-break.c b/diffcore-break.c\nindex ed0e14c..821ec57 100644\n--- a/diffcore-break.c\n+++ b/diffcore-break.c\n@@ -56,7 +56,7 @@ static int should_break(struct diff_file\n \t\treturn 0; /* leave symlink rename alone */\n \n \tif (src->sha1_valid && dst->sha1_valid &&\n-\t    !memcmp(src->sha1, dst->sha1, 20))\n+\t    is_same_sha1(src->sha1, dst->sha1))\n \t\treturn 0; /* they are the same */\n \n \tif (diff_populate_filespec(src, 0) || diff_populate_filespec(dst, 0))\ndiff --git a/diffcore-rename.c b/diffcore-rename.c\nindex 0ec488a..32afcc3 100644\n--- a/diffcore-rename.c\n+++ b/diffcore-rename.c\n@@ -101,7 +101,7 @@ static int is_exact_match(struct diff_fi\n \t\t\t  int contents_too)\n {\n \tif (src->sha1_valid && dst->sha1_valid &&\n-\t    !memcmp(src->sha1, dst->sha1, 20))\n+\t    is_same_sha1(src->sha1, dst->sha1))\n \t\treturn 1;\n \tif (!contents_too)\n \t\treturn 0;\ndiff --git a/dump-cache-tree.c b/dump-cache-tree.c\nindex 1ccaf51..51aadcc 100644\n--- a/dump-cache-tree.c\n+++ b/dump-cache-tree.c\n@@ -33,7 +33,7 @@ static int dump_cache_tree(struct cache_\n \t}\n \telse {\n \t\tdump_one(it, pfx, \"\");\n-\t\tif (memcmp(it->sha1, ref->sha1, 20) ||\n+\t\tif (!is_same_sha1(it->sha1, ref->sha1) ||\n \t\t    ref->entry_count != it->entry_count ||\n \t\t    ref->subtree_nr != it->subtree_nr) {\n \t\t\tdump_one(ref, pfx, \"#(ref) \");\ndiff --git a/http-fetch.c b/http-fetch.c\nindex 7f07d2a..dc4e30e 100644\n--- a/http-fetch.c\n+++ b/http-fetch.c\n@@ -301,7 +301,7 @@ static void finish_object_request(struct\n \t\tunlink(obj_req->tmpfile);\n \t\treturn;\n \t}\n-\tif (memcmp(obj_req->sha1, obj_req->real_sha1, 20)) {\n+\tif (!is_same_sha1(obj_req->sha1, obj_req->real_sha1)) {\n \t\tunlink(obj_req->tmpfile);\n \t\treturn;\n \t}\n@@ -1070,7 +1070,7 @@ static int fetch_object(struct alt_base \n \tint ret = 0;\n \tstruct object_request *obj_req = object_queue_head;\n \n-\twhile (obj_req != NULL && memcmp(obj_req->sha1, sha1, 20))\n+\twhile (obj_req != NULL && !is_same_sha1(obj_req->sha1, sha1))\n \t\tobj_req = obj_req->next;\n \tif (obj_req == NULL)\n \t\treturn error(\"Couldn't find request for %s in the queue\", hex);\n@@ -1109,7 +1109,7 @@ #endif\n \t} else if (obj_req->zret != Z_STREAM_END) {\n \t\tcorrupt_object_found++;\n \t\tret = error(\"File %s (%s) corrupt\", hex, obj_req->url);\n-\t} else if (memcmp(obj_req->sha1, obj_req->real_sha1, 20)) {\n+\t} else if (!is_same_sha1(obj_req->sha1, obj_req->real_sha1)) {\n \t\tret = error(\"File %s has bad hash\", hex);\n \t} else if (obj_req->rename < 0) {\n \t\tret = error(\"unable to write sha1 filename %s\",\ndiff --git a/http-push.c b/http-push.c\nindex 2bd9845..6a13c3e 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -745,7 +745,7 @@ static void finish_request(struct transf\n \t\t\tSHA1_Final(request->real_sha1, &request->c);\n \t\t\tif (request->zret != Z_STREAM_END) {\n \t\t\t\tunlink(request->tmpfile);\n-\t\t\t} else if (memcmp(request->obj->sha1, request->real_sha1, 20)) {\n+\t\t\t} else if (!is_same_sha1(request->obj->sha1, request->real_sha1)) {\n \t\t\t\tunlink(request->tmpfile);\n \t\t\t} else {\n \t\t\t\trequest->rename =\n@@ -2416,7 +2416,7 @@ int main(int argc, char **argv)\n \n \t\tif (!ref->peer_ref)\n \t\t\tcontinue;\n-\t\tif (!memcmp(ref->old_sha1, ref->peer_ref->new_sha1, 20)) {\n+\t\tif (is_same_sha1(ref->old_sha1, ref->peer_ref->new_sha1)) {\n \t\t\tif (push_verbosely || 1)\n \t\t\t\tfprintf(stderr, \"'%s': up-to-date\\n\", ref->name);\n \t\t\tcontinue;\ndiff --git a/index-pack.c b/index-pack.c\nindex b20659c..be4c36b 100644\n--- a/index-pack.c\n+++ b/index-pack.c\n@@ -82,7 +82,7 @@ static void parse_pack_header(void)\n \tSHA1_Init(&ctx);\n \tSHA1_Update(&ctx, pack_base, pack_size - 20);\n \tSHA1_Final(sha1, &ctx);\n-\tif (memcmp(sha1, pack_base + pack_size - 20, 20))\n+\tif (!is_same_sha1(sha1, pack_base + pack_size - 20))\n \t\tdie(\"packfile '%s' SHA1 mismatch\", pack_name);\n }\n \n@@ -210,9 +210,11 @@ static int find_deltas_based_on_sha1(con\n \n \tif (first < 0)\n \t\treturn -1;\n-\twhile (first > 0 && !memcmp(deltas[first-1].base_sha1, base_sha1, 20))\n+\twhile (first > 0 && is_same_sha1(deltas[first - 1].base_sha1,\n+\t\t\t\t\t base_sha1))\n \t\t--first;\n-\twhile (last < end && !memcmp(deltas[last+1].base_sha1, base_sha1, 20))\n+\twhile (last < end && is_same_sha1(deltas[last + 1].base_sha1,\n+\t\t\t\t\t  base_sha1))\n \t\t++last;\n \t*first_index = first;\n \t*last_index = last;\ndiff --git a/merge-tree.c b/merge-tree.c\nindex 7cf00be..7f68cb9 100644\n--- a/merge-tree.c\n+++ b/merge-tree.c\n@@ -152,7 +152,7 @@ static int same_entry(struct name_entry \n {\n \treturn\ta->sha1 &&\n \t\tb->sha1 &&\n-\t\t!memcmp(a->sha1, b->sha1, 20) &&\n+\t\tis_same_sha1(a->sha1, b->sha1) &&\n \t\ta->mode == b->mode;\n }\n \ndiff --git a/object.c b/object.c\nindex b5d8ed4..bcf3564 100644\n--- a/object.c\n+++ b/object.c\n@@ -58,7 +58,7 @@ struct object *lookup_object(const unsig\n \n \ti = hashtable_index(sha1);\n \twhile ((obj = obj_hash[i]) != NULL) {\n-\t\tif (!memcmp(sha1, obj->sha1, 20))\n+\t\tif (is_same_sha1(sha1, obj->sha1))\n \t\t\tbreak;\n \t\ti++;\n \t\tif (i == obj_hash_size)\ndiff --git a/pack-check.c b/pack-check.c\nindex 3a62e1b..8434a8d 100644\n--- a/pack-check.c\n+++ b/pack-check.c\n@@ -29,10 +29,10 @@ static int verify_packfile(struct packed\n \tpack_base = p->pack_base;\n \tSHA1_Update(&ctx, pack_base, pack_size - 20);\n \tSHA1_Final(sha1, &ctx);\n-\tif (memcmp(sha1, (char *) pack_base + pack_size - 20, 20))\n+\tif (!is_same_sha1(sha1, (unsigned char *)pack_base + pack_size - 20))\n \t\treturn error(\"Packfile %s SHA1 mismatch with itself\",\n \t\t\t     p->pack_name);\n-\tif (memcmp(sha1, (char *) index_base + index_size - 40, 20))\n+\tif (!is_same_sha1(sha1, (unsigned char *)index_base + index_size - 40))\n \t\treturn error(\"Packfile %s SHA1 mismatch with idx\",\n \t\t\t     p->pack_name);\n \n@@ -135,7 +135,7 @@ int verify_pack(struct packed_git *p, in\n \tSHA1_Init(&ctx);\n \tSHA1_Update(&ctx, index_base, index_size - 20);\n \tSHA1_Final(sha1, &ctx);\n-\tif (memcmp(sha1, (char *) index_base + index_size - 20, 20))\n+\tif (!is_same_sha1(sha1, (unsigned char *)index_base + index_size - 20))\n \t\tret = error(\"Packfile index for %s SHA1 mismatch\",\n \t\t\t    p->pack_name);\n \ndiff --git a/read-cache.c b/read-cache.c\nindex 3228ffb..ae0156f 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -739,7 +739,7 @@ static int verify_hdr(struct cache_heade\n \tSHA1_Init(&c);\n \tSHA1_Update(&c, hdr, size - 20);\n \tSHA1_Final(sha1, &c);\n-\tif (memcmp(sha1, (char *) hdr + size - 20, 20))\n+\tif (!is_same_sha1(sha1, (unsigned char *)hdr + size - 20))\n \t\treturn error(\"bad index file sha1 signature\");\n \treturn 0;\n }\ndiff --git a/refs.c b/refs.c\nindex 86ef916..5f3f5d2 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -281,7 +281,7 @@ static struct ref_lock *verify_lock(stru\n \t\tunlock_ref(lock);\n \t\treturn NULL;\n \t}\n-\tif (memcmp(lock->old_sha1, old_sha1, 20)) {\n+\tif (!is_same_sha1(lock->old_sha1, old_sha1)) {\n \t\terror(\"Ref %s is at %s but expected %s\", lock->ref_file,\n \t\t\tsha1_to_hex(lock->old_sha1), sha1_to_hex(old_sha1));\n \t\tunlock_ref(lock);\n@@ -411,7 +411,7 @@ int write_ref_sha1(struct ref_lock *lock\n \n \tif (!lock)\n \t\treturn -1;\n-\tif (!lock->force_write && !memcmp(lock->old_sha1, sha1, 20)) {\n+\tif (!lock->force_write && is_same_sha1(lock->old_sha1, sha1)) {\n \t\tunlock_ref(lock);\n \t\treturn 0;\n \t}\n@@ -475,7 +475,7 @@ int read_ref_at(const char *ref, unsigne\n \t\t\t\t\tdie(\"Log %s is corrupt.\", logfile);\n \t\t\t\tif (get_sha1_hex(rec + 41, sha1))\n \t\t\t\t\tdie(\"Log %s is corrupt.\", logfile);\n-\t\t\t\tif (memcmp(logged_sha1, sha1, 20)) {\n+\t\t\t\tif (!is_same_sha1(logged_sha1, sha1)) {\n \t\t\t\t\ttz = strtoul(tz_c, NULL, 10);\n \t\t\t\t\tfprintf(stderr,\n \t\t\t\t\t\t\"warning: Log %s has gap after %s.\\n\",\n@@ -489,7 +489,7 @@ int read_ref_at(const char *ref, unsigne\n \t\t\telse {\n \t\t\t\tif (get_sha1_hex(rec + 41, logged_sha1))\n \t\t\t\t\tdie(\"Log %s is corrupt.\", logfile);\n-\t\t\t\tif (memcmp(logged_sha1, sha1, 20)) {\n+\t\t\t\tif (!is_same_sha1(logged_sha1, sha1)) {\n \t\t\t\t\ttz = strtoul(tz_c, NULL, 10);\n \t\t\t\t\tfprintf(stderr,\n \t\t\t\t\t\t\"warning: Log %s unexpectedly ended on %s.\\n\",\ndiff --git a/send-pack.c b/send-pack.c\nindex 43e10b0..d7f58cd 100644\n--- a/send-pack.c\n+++ b/send-pack.c\n@@ -265,7 +265,7 @@ static int send_pack(int in, int out, in\n \t\tchar old_hex[60], *new_hex;\n \t\tif (!ref->peer_ref)\n \t\t\tcontinue;\n-\t\tif (!memcmp(ref->old_sha1, ref->peer_ref->new_sha1, 20)) {\n+\t\tif (is_same_sha1(ref->old_sha1, ref->peer_ref->new_sha1)) {\n \t\t\tif (verbose)\n \t\t\t\tfprintf(stderr, \"'%s': up-to-date\\n\", ref->name);\n \t\t\tcontinue;\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 18dece4..04d54ef 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -485,10 +485,10 @@ int use_packed_git(struct packed_git *p)\n \t\t/* Check if the pack file matches with the index file.\n \t\t * this is cheap.\n \t\t */\n-\t\tif (memcmp((char*)(p->index_base) + p->index_size - 40,\n-\t\t\t   (char *) p->pack_base + p->pack_size - 20,\n-\t\t\t   20)) {\n-\n+\t\tif (!is_same_sha1((unsigned char *)(p->index_base) +\n+\t\t\t\t  p->index_size - 40,\n+\t\t\t\t  (unsigned char *)p->pack_base +\n+\t\t\t\t  p->pack_size - 20)) {\n \t\t\tdie(\"packfile %s does not match index.\", p->pack_name);\n \t\t}\n \t}\n@@ -643,7 +643,7 @@ int check_sha1_signature(const unsigned \n \tSHA1_Update(&c, header, 1+sprintf(header, \"%s %lu\", type, size));\n \tSHA1_Update(&c, map, size);\n \tSHA1_Final(real_sha1, &c);\n-\treturn memcmp(sha1, real_sha1, 20) ? -1 : 0;\n+\treturn !is_same_sha1(sha1, real_sha1) ? -1 : 0;\n }\n \n void *map_sha1_file(const unsigned char *sha1, unsigned long *size)\n@@ -941,7 +941,7 @@ int check_reuse_pack_delta(struct packed\n \tptr = unpack_object_header(p, ptr, kindp, sizep);\n \tif (*kindp != OBJ_DELTA)\n \t\tgoto done;\n-\tmemcpy(base, (char *) p->pack_base + ptr, 20);\n+\tmemcpy(base, (unsigned char *) p->pack_base + ptr, 20);\n \tstatus = 0;\n  done:\n \tunuse_packed_git(p);\n@@ -1715,7 +1715,7 @@ int write_sha1_from_fd(const unsigned ch\n \t\tunlink(tmpfile);\n \t\treturn error(\"File %s corrupted\", sha1_to_hex(sha1));\n \t}\n-\tif (memcmp(sha1, real_sha1, 20)) {\n+\tif (!is_same_sha1(sha1, real_sha1)) {\n \t\tunlink(tmpfile);\n \t\treturn error(\"File %s has bad hash\", sha1_to_hex(sha1));\n \t}\ndiff --git a/sha1_name.c b/sha1_name.c\nindex f567454..2d4d26a 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -106,7 +106,7 @@ static int find_short_packed_object(int \n \t\t\t\t\t\tmemcpy(found_sha1, now, 20);\n \t\t\t\t\t\tfound++;\n \t\t\t\t\t}\n-\t\t\t\t\telse if (memcmp(found_sha1, now, 20)) {\n+\t\t\t\t\telse if (!is_same_sha1(found_sha1, now)) {\n \t\t\t\t\t\tfound = 2;\n \t\t\t\t\t\tbreak;\n \t\t\t\t\t}\n@@ -144,7 +144,7 @@ static int find_unique_short_object(int \n \t\treturn 0;\n \t}\n \t/* Both have unique ones -- do they match? */\n-\tif (memcmp(packed_sha1, unpacked_sha1, 20))\n+\tif (!is_same_sha1(packed_sha1, unpacked_sha1))\n \t\treturn SHORT_NAME_AMBIGUOUS;\n \tmemcpy(sha1, packed_sha1, 20);\n \treturn 0;\ndiff --git a/ssh-fetch.c b/ssh-fetch.c\nindex 0b89df6..603e244 100644\n--- a/ssh-fetch.c\n+++ b/ssh-fetch.c\n@@ -67,7 +67,7 @@ int fetch(unsigned char *sha1)\n \tsigned char remote;\n \tstruct object_list *temp;\n \n-\tif (memcmp(sha1, in_transit->item->sha1, 20)) {\n+\tif (!is_same_sha1(sha1, in_transit->item->sha1)) {\n \t\t/* we must have already fetched it to clean the queue */\n \t\treturn has_sha1_file(sha1) ? 0 : -1;\n \t}\ndiff --git a/tree-diff.c b/tree-diff.c\nindex 916f489..51df262 100644\n--- a/tree-diff.c\n+++ b/tree-diff.c\n@@ -40,7 +40,7 @@ static int compare_tree_entry(struct tre\n \t\treturn 1;\n \t}\n \tif (!opt->find_copies_harder &&\n-\t    !memcmp(sha1, sha2, 20) && mode1 == mode2)\n+\t    is_same_sha1(sha1, sha2) && mode1 == mode2)\n \t\treturn 0;\n \n \t/*\ndiff --git a/unpack-trees.c b/unpack-trees.c\nindex 43ed124..153b321 100644\n--- a/unpack-trees.c\n+++ b/unpack-trees.c\n@@ -417,7 +417,7 @@ static int same(struct cache_entry *a, s\n \tif (!a && !b)\n \t\treturn 1;\n \treturn a->ce_mode == b->ce_mode &&\n-\t\t!memcmp(a->sha1, b->sha1, 20);\n+\t\tis_same_sha1(a->sha1, b->sha1);\n }\n \n \n-- \n1.4.2.g1c2a-dirty\n"},{"id":"25441","messageId":"7vveos17ym.fsf@assigned-by-dhcp.cox.net","threadId":"5300","inReplyTo":"Pine.LNX.4.63.0608161721020.11465@chino.corp.google.com","subject":"Re: [PATCH] introduce inline is_same_sha1","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-08-17T01:12:17Z","receivedAt":"2006-08-17T01:12:17Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"David Rientjes <rientjes@google.com> writes:\n\n> Introduces global inline:\n> \tis_same_sha1(const unsigned char *sha1,\n> \t\t     const unsigned char *sha2);\n>\n> Uses memcmp for comparison and returns the result.  All tests\n> for comparisons for sha1 have been changed to use the new\n> global inline, but existing uses of memcmp have been preserved\n> where the return value other than 0 is needed, i.e.:\n>\n> \tint cmp = !memcmp(old_sha1, new_sha1, 20);\n>\n> Conversions from char* to unsigned char* casts have been made\n> where appropriate.\n>\n> Signed-off-by: David Rientjes <rientjes@google.com>\n\nI would have expected the inline function to be:\n\n\tint cmp_object_name(const void *, const void *)\n\nNo need for \"unsigned char *\" that way [*1*].  \n\nI do not know what your ultimate goal with this patch is, but I\nlike the fact that we do not have to hardcode \"20\" everywhere.\nWith a yet-to-be-written companion patch to make the \"20\" into a\nsymbolic constant OBJECT_NAME_LENGTH, we could someday have a\nflag day to use a hash different from SHA-1 with an updated\n'git-convert-objects' ;-).\n\nI would have liked if the function were to give the comparison\nresults similar to standard comparison functions such as memcmp\nand strcmp.  I do not know off-hand if we order by the object\nnames, and we might only be interested in equality tests, but\nstill...\n\nLine-wrap the message for comfortable viewing on 80-column\nterminals, please.\n\n[Footnote]\n\n*1* On the other hand if stricter type checking is wanted,\n    \"const unsigned char *\" is too weak.  We would need either\n    sparse annotation or a new type (maybe a struct that has a\n    single member that has 20-byte uchar array).  I personally\n    think that is an overkill, though.\n"},{"id":"25444","messageId":"Pine.LNX.4.63.0608162029540.14684@chino.corp.google.com","threadId":"5300","inReplyTo":"7vveos17ym.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] introduce inline is_same_sha1","fromName":"David Rientjes","fromEmail":"rientjes@google.com","sentAt":"2006-08-17T03:51:58Z","receivedAt":"2006-08-17T03:51:58Z","isPatch":true,"sender":{"key":"rientjes@google.com","avatar":null},"body":"On Wed, 16 Aug 2006, Junio C Hamano wrote:\n\n> I would have expected the inline function to be:\n> \n> \tint cmp_object_name(const void *, const void *)\n> \n> No need for \"unsigned char *\" that way [*1*].  \n> \n> I do not know what your ultimate goal with this patch is, but I\n> like the fact that we do not have to hardcode \"20\" everywhere.\n> With a yet-to-be-written companion patch to make the \"20\" into a\n> symbolic constant OBJECT_NAME_LENGTH, we could someday have a\n> flag day to use a hash different from SHA-1 with an updated\n> 'git-convert-objects' ;-).\n> \n\nThe reason it is not\n\tint cmp_object_name(const void *, const void *)\n\nties into the ultimate goal.  As you said, 20 is hardcoded everywhere in \nthe code as the length sha1's name.  Since my own development tree uses \ntwo different hashes configurable at runtime, I decided to create a single \nstatic inline that would deal with name comparisons.  I submitted a \nsimilar change to your tree because, like you, I envisioned that someday \nyou may have several different hashes that require different comparison \nlengths.  The easy solution is using strcmp in the inline but then you're \nrequired to cast based on signness and sometimes you want to truncate the \ncomparison to n bytes anyway depending on your hash of choice.  If you \nwant to open your project to the possibility of implementing other \nhashes, my patch is a step in that direction.\n\n> I would have liked if the function were to give the comparison\n> results similar to standard comparison functions such as memcmp\n> and strcmp.  I do not know off-hand if we order by the object\n> names, and we might only be interested in equality tests, but\n> still...\n> \n\nRemember, this is an inline function.  The only reason for writing it \nwould be to isolate the number 20 to this particular function (those that \nrequire comparisons were untouched, as I previously stated, so it still \nexists there as well), otherwise it's useless.  If you're going to allow a \nconfigurable hash function, then you'll need to isolate the n-bytes \nsomewhere if you don't want to pass HASH_NAME_LENGTH around everywhere.\n\ngit does sort on sha1 name, specifically with qsort in pack-objects using \nsha1_sort (which isn't an inline, but should be).\n\n(It would be helpful if you were to specifically request changes to a \npatch or explicitly state whether or not you queued to apply it, I can \nnever tell).\n\n\t\tDavid\n"},{"id":"25448","messageId":"7vzme3vpwr.fsf@assigned-by-dhcp.cox.net","threadId":"5300","inReplyTo":"Pine.LNX.4.63.0608162029540.14684@chino.corp.google.com","subject":"Re: [PATCH] introduce inline is_same_sha1","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-08-17T06:26:28Z","receivedAt":"2006-08-17T06:26:28Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"David Rientjes <rientjes@google.com> writes:\n\n> On Wed, 16 Aug 2006, Junio C Hamano wrote:\n>\n> The reason it is not\n> \tint cmp_object_name(const void *, const void *)\n>\n> ties into the ultimate goal.  As you said, 20 is hardcoded everywhere in \n> the code as the length sha1's name.  Since my own development tree uses \n> two different hashes configurable at runtime, I decided to create a single \n> static inline that would deal with name comparisons.  I submitted a \n> similar change to your tree because, like you, I envisioned that someday \n> you may have several different hashes that require different comparison \n> lengths.\n\nGood, we are on the same wavelength.  But that does not explain\nwhy you do not use (void *) which would let you avoid casts at\nthe calling sites.\n\n>> I would have liked if the function were to give the comparison\n>> results similar to standard comparison functions such as memcmp\n>> and strcmp.  I do not know off-hand if we order by the object\n>> names, and we might only be interested in equality tests, but\n>> still...\n>\n> Remember, this is an inline function.  The only reason for writing it \n> would be to isolate the number 20 to this particular function (those that \n> require comparisons were untouched, as I previously stated, so it still \n> exists there as well), otherwise it's useless.\n\nI may be slower than I usually am, but I fail to see the logic.\nIf we are isolating the comparison length and nothing else,\nwhich I agree is a good thing, I would expect the function to\nreturn 0 when same, just like memcmp(), which means \"is_same\" is\nnot the interface we would want.  \"is_same\" is justified only\nwhen all the callers want to know equality and not comparison.\n\n> ... If you're going to allow a \n> configurable hash function, then you'll need to isolate the n-bytes \n> somewhere if you don't want to pass HASH_NAME_LENGTH around everywhere.\n\nExactly.  So if some other call sites do want comparison, they\nwould either need to do memcmp() with 20 or needs cmp_object_name()\nlike interface, wouldn't they?\n\n> git does sort on sha1 name, specifically with qsort in pack-objects using \n> sha1_sort (which isn't an inline, but should be).\n\nCorrect, pack idx is sorted by object name.\n\n> (It would be helpful if you were to specifically request changes to a \n> patch or explicitly state whether or not you queued to apply it, I can \n> never tell).\n\nI am interested in this clean-up, but please convince me that\nhaving two interfaces (is_same and compare) is better way to\nabstract out 20 than one interface (compare), or if you agree\nwith me that one interface is better, please redo the patch and\nthe change the call sites you deliberately left as memcmp() in\nthe patch as well.\n\nI sometimes say \"I'd apply this as is, but you need to fix such\nand such\", when the contributor has a good track record of\nresponding.  Please don't get this wrong, but you are still\nunknown quantity to me.  This is a learning process for both of\nus.\n\nBy the way, Wednesdays and Saturdays (my time) are my git days,\nso I try to summarize the current status of \"master\" and \"next\"\nbranches on these days.  On other days I hack on git only during\nlunch and evenings so the turnaround and response tend be slower\nand sketchier.\n"},{"id":"25481","messageId":"81b0412b0608170459if099fcane9d9e91a3fdac9e6@mail.gmail.com","threadId":"5300","inReplyTo":"Pine.LNX.4.63.0608161721020.11465@chino.corp.google.com","subject":"Re: [PATCH] introduce inline is_same_sha1","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2006-08-17T11:59:02Z","receivedAt":"2006-08-17T11:59:02Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"On 8/17/06, David Rientjes <rientjes@google.com> wrote:\n> Introduces global inline:\n>         is_same_sha1(const unsigned char *sha1,\n>                      const unsigned char *sha2);\n\nIt is longer and negates all (like in \"lots\") previous callsites of memcmp.\nAre sure you didn't do a trivial typo somewhere?\n\nWhy not just sha1cmp? And if you're aiming at hash-type independence,\nwhy not hashcmp?\n"},{"id":"25498","messageId":"Pine.LNX.4.63.0608171152110.22819@chino.corp.google.com","threadId":"5300","inReplyTo":"81b0412b0608170459if099fcane9d9e91a3fdac9e6@mail.gmail.com","subject":"Re: [PATCH] introduce inline is_same_sha1","fromName":"David Rientjes","fromEmail":"rientjes@google.com","sentAt":"2006-08-17T18:54:57Z","receivedAt":"2006-08-17T18:54:57Z","isPatch":true,"sender":{"key":"rientjes@google.com","avatar":null},"body":"On Thu, 17 Aug 2006, Alex Riesen wrote:\n\n> It is longer and negates all (like in \"lots\") previous callsites of memcmp.\n> Are sure you didn't do a trivial typo somewhere?\n> \n> Why not just sha1cmp? And if you're aiming at hash-type independence,\n> why not hashcmp?\n> \n\nhashcmp is a very good suggestion.  Please ack the following.\n\n\t\tDavid\n---\nIntroduces global inline:\n\thashcmp(const unsigned char *sha1, const unsigned char *sha2)\n\nUses memcmp for comparison and returns the result based on the length of \nthe hash name (a future runtime decision).\n\nSigned-off-by: David Rientjes <rientjes@google.com>\n---\n builtin-commit-tree.c    |    2 +-\n builtin-diff-stages.c    |    2 +-\n builtin-diff.c           |    2 +-\n builtin-pack-objects.c   |    8 ++++----\n builtin-show-branch.c    |    4 ++--\n builtin-unpack-objects.c |    4 ++--\n builtin-update-index.c   |    4 ++--\n cache.h                  |    4 ++++\n combine-diff.c           |    4 ++--\n commit.c                 |    2 +-\n convert-objects.c        |    2 +-\n diff-lib.c               |    2 +-\n diff.c                   |   10 +++++-----\n diffcore-break.c         |    2 +-\n diffcore-rename.c        |    2 +-\n dump-cache-tree.c        |    2 +-\n http-fetch.c             |    6 +++---\n http-push.c              |    4 ++--\n index-pack.c             |   14 ++++++++------\n merge-tree.c             |    2 +-\n object.c                 |    2 +-\n pack-check.c             |    6 +++---\n pack-redundant.c         |   14 +++++++-------\n read-cache.c             |    4 ++--\n refs.c                   |    8 ++++----\n send-pack.c              |    2 +-\n sha1_file.c              |   16 ++++++++--------\n sha1_name.c              |    6 +++---\n ssh-fetch.c              |    2 +-\n tree-diff.c              |    3 +--\n unpack-trees.c           |    2 +-\n 31 files changed, 76 insertions(+), 71 deletions(-)\n\ndiff --git a/builtin-commit-tree.c b/builtin-commit-tree.c\nindex 9c98796..e2e690a 100644\n--- a/builtin-commit-tree.c\n+++ b/builtin-commit-tree.c\n@@ -69,7 +69,7 @@ static int new_parent(int idx)\n \tint i;\n \tunsigned char *sha1 = parent_sha1[idx];\n \tfor (i = 0; i < idx; i++) {\n-\t\tif (!memcmp(parent_sha1[i], sha1, 20)) {\n+\t\tif (!hashcmp(parent_sha1[i], sha1)) {\n \t\t\terror(\"duplicate parent %s ignored\", sha1_to_hex(sha1));\n \t\t\treturn 0;\n \t\t}\ndiff --git a/builtin-diff-stages.c b/builtin-diff-stages.c\nindex 5960e08..70bb898 100644\n--- a/builtin-diff-stages.c\n+++ b/builtin-diff-stages.c\n@@ -46,7 +46,7 @@ static void diff_stages(int stage1, int \n \t\telse if (!two)\n \t\t\tdiff_addremove(&diff_options, '-', ntohl(one->ce_mode),\n \t\t\t\t       one->sha1, name, NULL);\n-\t\telse if (memcmp(one->sha1, two->sha1, 20) ||\n+\t\telse if (hashcmp(one->sha1, two->sha1) ||\n \t\t\t (one->ce_mode != two->ce_mode) ||\n \t\t\t diff_options.find_copies_harder)\n \t\t\tdiff_change(&diff_options,\ndiff --git a/builtin-diff.c b/builtin-diff.c\nindex 40e5c96..874f773 100644\n--- a/builtin-diff.c\n+++ b/builtin-diff.c\n@@ -69,7 +69,7 @@ static void stuff_change(struct diff_opt\n \tstruct diff_filespec *one, *two;\n \n \tif (!is_null_sha1(old_sha1) && !is_null_sha1(new_sha1) &&\n-\t    !memcmp(old_sha1, new_sha1, 20))\n+\t    !hashcmp(old_sha1, new_sha1))\n \t\treturn;\n \n \tif (opt->reverse_diff) {\ndiff --git a/builtin-pack-objects.c b/builtin-pack-objects.c\nindex 448461b..f19f0d6 100644\n--- a/builtin-pack-objects.c\n+++ b/builtin-pack-objects.c\n@@ -441,7 +441,7 @@ static int locate_object_entry_hash(cons\n \tmemcpy(&ui, sha1, sizeof(unsigned int));\n \ti = ui % object_ix_hashsz;\n \twhile (0 < object_ix[i]) {\n-\t\tif (!memcmp(sha1, objects[object_ix[i]-1].sha1, 20))\n+\t\tif (!hashcmp(sha1, objects[object_ix[i] - 1].sha1))\n \t\t\treturn i;\n \t\tif (++i == object_ix_hashsz)\n \t\t\ti = 0;\n@@ -607,7 +607,7 @@ static struct pbase_tree_cache *pbase_tr\n \t */\n \tfor (neigh = 0; neigh < 8; neigh++) {\n \t\tent = pbase_tree_cache[my_ix];\n-\t\tif (ent && !memcmp(ent->sha1, sha1, 20)) {\n+\t\tif (ent && !hashcmp(ent->sha1, sha1)) {\n \t\t\tent->ref++;\n \t\t\treturn ent;\n \t\t}\n@@ -789,7 +789,7 @@ static void add_preferred_base(unsigned \n \t\treturn;\n \n \tfor (it = pbase_tree; it; it = it->next) {\n-\t\tif (!memcmp(it->pcache.sha1, tree_sha1, 20)) {\n+\t\tif (!hashcmp(it->pcache.sha1, tree_sha1)) {\n \t\t\tfree(data);\n \t\t\treturn;\n \t\t}\n@@ -931,7 +931,7 @@ static struct object_entry **create_sort\n \n static int sha1_sort(const struct object_entry *a, const struct object_entry *b)\n {\n-\treturn memcmp(a->sha1, b->sha1, 20);\n+\treturn hashcmp(a->sha1, b->sha1);\n }\n \n static struct object_entry **create_final_object_list(void)\ndiff --git a/builtin-show-branch.c b/builtin-show-branch.c\nindex 95fbf77..18786f8 100644\n--- a/builtin-show-branch.c\n+++ b/builtin-show-branch.c\n@@ -378,7 +378,7 @@ static int append_head_ref(const char *r\n \t/* If both heads/foo and tags/foo exists, get_sha1 would\n \t * get confused.\n \t */\n-\tif (get_sha1(refname + ofs, tmp) || memcmp(tmp, sha1, 20))\n+\tif (get_sha1(refname + ofs, tmp) || hashcmp(tmp, sha1))\n \t\tofs = 5;\n \treturn append_ref(refname + ofs, sha1);\n }\n@@ -442,7 +442,7 @@ static int rev_is_head(char *head_path, \n {\n \tint namelen;\n \tif ((!head_path[0]) ||\n-\t    (head_sha1 && sha1 && memcmp(head_sha1, sha1, 20)))\n+\t    (head_sha1 && sha1 && hashcmp(head_sha1, sha1)))\n \t\treturn 0;\n \tnamelen = strlen(name);\n \tif ((headlen < namelen) ||\ndiff --git a/builtin-unpack-objects.c b/builtin-unpack-objects.c\nindex 63f4b8e..f0ae5c9 100644\n--- a/builtin-unpack-objects.c\n+++ b/builtin-unpack-objects.c\n@@ -136,7 +136,7 @@ static void added_object(unsigned char *\n \tstruct delta_info *info;\n \n \twhile ((info = *p) != NULL) {\n-\t\tif (!memcmp(info->base_sha1, sha1, 20)) {\n+\t\tif (!hashcmp(info->base_sha1, sha1)) {\n \t\t\t*p = info->next;\n \t\t\tp = &delta_list;\n \t\t\tresolve_delta(type, data, size, info->delta, info->size);\n@@ -292,7 +292,7 @@ int cmd_unpack_objects(int argc, const c\n \tunpack_all();\n \tSHA1_Update(&ctx, buffer, offset);\n \tSHA1_Final(sha1, &ctx);\n-\tif (memcmp(fill(20), sha1, 20))\n+\tif (hashcmp(fill(20), sha1))\n \t\tdie(\"final sha1 did not match\");\n \tuse(20);\n \ndiff --git a/builtin-update-index.c b/builtin-update-index.c\nindex 9f0cf28..5dd91af 100644\n--- a/builtin-update-index.c\n+++ b/builtin-update-index.c\n@@ -378,7 +378,7 @@ static int unresolve_one(const char *pat\n \t\tret = -1;\n \t\tgoto free_return;\n \t}\n-\tif (!memcmp(ce_2->sha1, ce_3->sha1, 20) &&\n+\tif (!hashcmp(ce_2->sha1, ce_3->sha1) &&\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@@ -460,7 +460,7 @@ static int do_reupdate(int ac, const cha\n \t\t\told = read_one_ent(NULL, head_sha1,\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    !memcmp(ce->sha1, old->sha1, 20)) {\n+\t\t    !hashcmp(ce->sha1, old->sha1)) {\n \t\t\tfree(old);\n \t\t\tcontinue; /* unchanged */\n \t\t}\ndiff --git a/cache.h b/cache.h\nindex c738299..f99254b 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -214,6 +214,10 @@ static inline int is_null_sha1(const uns\n {\n \treturn !memcmp(sha1, null_sha1, 20);\n }\n+static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)\n+{\n+\treturn memcmp(sha1, sha2, 20);\n+}\n \n int git_mkstemp(char *path, size_t n, const char *template);\n \ndiff --git a/combine-diff.c b/combine-diff.c\nindex ce063b4..0682acd 100644\n--- a/combine-diff.c\n+++ b/combine-diff.c\n@@ -688,8 +688,8 @@ static void show_patch_diff(struct combi\n \tfor (i = 0; i < num_parent; i++) {\n \t\tint j;\n \t\tfor (j = 0; j < i; j++) {\n-\t\t\tif (!memcmp(elem->parent[i].sha1,\n-\t\t\t\t    elem->parent[j].sha1, 20)) {\n+\t\t\tif (!hashcmp(elem->parent[i].sha1,\n+\t\t\t\t     elem->parent[j].sha1)) {\n \t\t\t\treuse_combine_diff(sline, cnt, i, j);\n \t\t\t\tbreak;\n \t\t\t}\ndiff --git a/commit.c b/commit.c\nindex 972d1b7..d17451f 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -123,7 +123,7 @@ static int commit_graft_pos(const unsign\n \twhile (lo < hi) {\n \t\tint mi = (lo + hi) / 2;\n \t\tstruct commit_graft *graft = commit_graft[mi];\n-\t\tint cmp = memcmp(sha1, graft->sha1, 20);\n+\t\tint cmp = hashcmp(sha1, graft->sha1);\n \t\tif (!cmp)\n \t\t\treturn mi;\n \t\tif (cmp < 0)\ndiff --git a/convert-objects.c b/convert-objects.c\nindex 168771e..4e7ff75 100644\n--- a/convert-objects.c\n+++ b/convert-objects.c\n@@ -39,7 +39,7 @@ static struct entry *lookup_entry(unsign\n \twhile (low < high) {\n \t\tint next = (low + high) / 2;\n \t\tstruct entry *n = convert[next];\n-\t\tint cmp = memcmp(sha1, n->old_sha1, 20);\n+\t\tint cmp = hashcmp(sha1, n->old_sha1);\n \t\tif (!cmp)\n \t\t\treturn n;\n \t\tif (cmp < 0) {\ndiff --git a/diff-lib.c b/diff-lib.c\nindex 116b5a9..3e4b3b9 100644\n--- a/diff-lib.c\n+++ b/diff-lib.c\n@@ -215,7 +215,7 @@ static int show_modified(struct rev_info\n \t}\n \n \toldmode = old->ce_mode;\n-\tif (mode == oldmode && !memcmp(sha1, old->sha1, 20) &&\n+\tif (mode == oldmode && !hashcmp(sha1, old->sha1) &&\n \t    !revs->diffopt.find_copies_harder)\n \t\treturn 0;\n \ndiff --git a/diff.c b/diff.c\nindex 7a238d0..da7cca1 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -1140,7 +1140,7 @@ static int work_tree_matches(const char \n \tif ((lstat(name, &st) < 0) ||\n \t    !S_ISREG(st.st_mode) || /* careful! */\n \t    ce_match_stat(ce, &st, 0) ||\n-\t    memcmp(sha1, ce->sha1, 20))\n+\t    hashcmp(sha1, ce->sha1))\n \t\treturn 0;\n \t/* we return 1 only when we can stat, it is a regular file,\n \t * stat information matches, and sha1 recorded in the cache\n@@ -1168,7 +1168,7 @@ static struct sha1_size_cache *locate_si\n \twhile (last > first) {\n \t\tint cmp, next = (last + first) >> 1;\n \t\te = sha1_size_cache[next];\n-\t\tcmp = memcmp(e->sha1, sha1, 20);\n+\t\tcmp = hashcmp(e->sha1, sha1);\n \t\tif (!cmp)\n \t\t\treturn e;\n \t\tif (cmp < 0) {\n@@ -1579,7 +1579,7 @@ static void run_diff(struct diff_filepai\n \t\t;\n \t}\n \n-\tif (memcmp(one->sha1, two->sha1, 20)) {\n+\tif (hashcmp(one->sha1, two->sha1)) {\n \t\tint abbrev = o->full_index ? 40 : DEFAULT_ABBREV;\n \n \t\tlen += snprintf(msg + len, sizeof(msg) - len,\n@@ -2098,7 +2098,7 @@ int diff_unmodified_pair(struct diff_fil\n \t * dealing with a change.\n \t */\n \tif (one->sha1_valid && two->sha1_valid &&\n-\t    !memcmp(one->sha1, two->sha1, sizeof(one->sha1)))\n+\t    !hashcmp(one->sha1, two->sha1))\n \t\treturn 1; /* no change */\n \tif (!one->sha1_valid && !two->sha1_valid)\n \t\treturn 1; /* both look at the same file on the filesystem. */\n@@ -2237,7 +2237,7 @@ static void diff_resolve_rename_copy(voi\n \t\t\tif (!p->status)\n \t\t\t\tp->status = DIFF_STATUS_RENAMED;\n \t\t}\n-\t\telse if (memcmp(p->one->sha1, p->two->sha1, 20) ||\n+\t\telse if (hashcmp(p->one->sha1, p->two->sha1) ||\n \t\t\t p->one->mode != p->two->mode)\n \t\t\tp->status = DIFF_STATUS_MODIFIED;\n \t\telse {\ndiff --git a/diffcore-break.c b/diffcore-break.c\nindex ed0e14c..acb18db 100644\n--- a/diffcore-break.c\n+++ b/diffcore-break.c\n@@ -56,7 +56,7 @@ static int should_break(struct diff_file\n \t\treturn 0; /* leave symlink rename alone */\n \n \tif (src->sha1_valid && dst->sha1_valid &&\n-\t    !memcmp(src->sha1, dst->sha1, 20))\n+\t    !hashcmp(src->sha1, dst->sha1))\n \t\treturn 0; /* they are the same */\n \n \tif (diff_populate_filespec(src, 0) || diff_populate_filespec(dst, 0))\ndiff --git a/diffcore-rename.c b/diffcore-rename.c\nindex 0ec488a..ef23901 100644\n--- a/diffcore-rename.c\n+++ b/diffcore-rename.c\n@@ -101,7 +101,7 @@ static int is_exact_match(struct diff_fi\n \t\t\t  int contents_too)\n {\n \tif (src->sha1_valid && dst->sha1_valid &&\n-\t    !memcmp(src->sha1, dst->sha1, 20))\n+\t    !hashcmp(src->sha1, dst->sha1))\n \t\treturn 1;\n \tif (!contents_too)\n \t\treturn 0;\ndiff --git a/dump-cache-tree.c b/dump-cache-tree.c\nindex 1ccaf51..1f73f1e 100644\n--- a/dump-cache-tree.c\n+++ b/dump-cache-tree.c\n@@ -33,7 +33,7 @@ static int dump_cache_tree(struct cache_\n \t}\n \telse {\n \t\tdump_one(it, pfx, \"\");\n-\t\tif (memcmp(it->sha1, ref->sha1, 20) ||\n+\t\tif (hashcmp(it->sha1, ref->sha1) ||\n \t\t    ref->entry_count != it->entry_count ||\n \t\t    ref->subtree_nr != it->subtree_nr) {\n \t\t\tdump_one(ref, pfx, \"#(ref) \");\ndiff --git a/http-fetch.c b/http-fetch.c\nindex 7f07d2a..d1f74b4 100644\n--- a/http-fetch.c\n+++ b/http-fetch.c\n@@ -301,7 +301,7 @@ static void finish_object_request(struct\n \t\tunlink(obj_req->tmpfile);\n \t\treturn;\n \t}\n-\tif (memcmp(obj_req->sha1, obj_req->real_sha1, 20)) {\n+\tif (hashcmp(obj_req->sha1, obj_req->real_sha1)) {\n \t\tunlink(obj_req->tmpfile);\n \t\treturn;\n \t}\n@@ -1070,7 +1070,7 @@ static int fetch_object(struct alt_base \n \tint ret = 0;\n \tstruct object_request *obj_req = object_queue_head;\n \n-\twhile (obj_req != NULL && memcmp(obj_req->sha1, sha1, 20))\n+\twhile (obj_req != NULL && hashcmp(obj_req->sha1, sha1))\n \t\tobj_req = obj_req->next;\n \tif (obj_req == NULL)\n \t\treturn error(\"Couldn't find request for %s in the queue\", hex);\n@@ -1109,7 +1109,7 @@ #endif\n \t} else if (obj_req->zret != Z_STREAM_END) {\n \t\tcorrupt_object_found++;\n \t\tret = error(\"File %s (%s) corrupt\", hex, obj_req->url);\n-\t} else if (memcmp(obj_req->sha1, obj_req->real_sha1, 20)) {\n+\t} else if (hashcmp(obj_req->sha1, obj_req->real_sha1)) {\n \t\tret = error(\"File %s has bad hash\", hex);\n \t} else if (obj_req->rename < 0) {\n \t\tret = error(\"unable to write sha1 filename %s\",\ndiff --git a/http-push.c b/http-push.c\nindex 2bd9845..4849779 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -745,7 +745,7 @@ static void finish_request(struct transf\n \t\t\tSHA1_Final(request->real_sha1, &request->c);\n \t\t\tif (request->zret != Z_STREAM_END) {\n \t\t\t\tunlink(request->tmpfile);\n-\t\t\t} else if (memcmp(request->obj->sha1, request->real_sha1, 20)) {\n+\t\t\t} else if (hashcmp(request->obj->sha1, request->real_sha1)) {\n \t\t\t\tunlink(request->tmpfile);\n \t\t\t} else {\n \t\t\t\trequest->rename =\n@@ -2416,7 +2416,7 @@ int main(int argc, char **argv)\n \n \t\tif (!ref->peer_ref)\n \t\t\tcontinue;\n-\t\tif (!memcmp(ref->old_sha1, ref->peer_ref->new_sha1, 20)) {\n+\t\tif (!hashcmp(ref->old_sha1, ref->peer_ref->new_sha1)) {\n \t\t\tif (push_verbosely || 1)\n \t\t\t\tfprintf(stderr, \"'%s': up-to-date\\n\", ref->name);\n \t\t\tcontinue;\ndiff --git a/index-pack.c b/index-pack.c\nindex b20659c..2063ae9 100644\n--- a/index-pack.c\n+++ b/index-pack.c\n@@ -82,7 +82,7 @@ static void parse_pack_header(void)\n \tSHA1_Init(&ctx);\n \tSHA1_Update(&ctx, pack_base, pack_size - 20);\n \tSHA1_Final(sha1, &ctx);\n-\tif (memcmp(sha1, pack_base + pack_size - 20, 20))\n+\tif (hashcmp(sha1, pack_base + pack_size - 20))\n \t\tdie(\"packfile '%s' SHA1 mismatch\", pack_name);\n }\n \n@@ -189,7 +189,7 @@ static int find_delta(const unsigned cha\n                 struct delta_entry *delta = &deltas[next];\n                 int cmp;\n \n-                cmp = memcmp(base_sha1, delta->base_sha1, 20);\n+                cmp = hashcmp(base_sha1, delta->base_sha1);\n                 if (!cmp)\n                         return next;\n                 if (cmp < 0) {\n@@ -210,9 +210,11 @@ static int find_deltas_based_on_sha1(con\n \n \tif (first < 0)\n \t\treturn -1;\n-\twhile (first > 0 && !memcmp(deltas[first-1].base_sha1, base_sha1, 20))\n+\twhile (first > 0 && !hashcmp(deltas[first - 1].base_sha1,\n+\t\t\t\t     base_sha1))\n \t\t--first;\n-\twhile (last < end && !memcmp(deltas[last+1].base_sha1, base_sha1, 20))\n+\twhile (last < end && !hashcmp(deltas[last + 1].base_sha1,\n+\t\t\t\t      base_sha1))\n \t\t++last;\n \t*first_index = first;\n \t*last_index = last;\n@@ -278,7 +280,7 @@ static int compare_delta_entry(const voi\n {\n \tconst struct delta_entry *delta_a = a;\n \tconst struct delta_entry *delta_b = b;\n-\treturn memcmp(delta_a->base_sha1, delta_b->base_sha1, 20);\n+\treturn hashcmp(delta_a->base_sha1, delta_b->base_sha1);\n }\n \n static void parse_pack_objects(void)\n@@ -350,7 +352,7 @@ static int sha1_compare(const void *_a, \n {\n \tstruct object_entry *a = *(struct object_entry **)_a;\n \tstruct object_entry *b = *(struct object_entry **)_b;\n-\treturn memcmp(a->sha1, b->sha1, 20);\n+\treturn hashcmp(a->sha1, b->sha1);\n }\n \n static void write_index_file(const char *index_name, unsigned char *sha1)\ndiff --git a/merge-tree.c b/merge-tree.c\nindex 7cf00be..c2e9a86 100644\n--- a/merge-tree.c\n+++ b/merge-tree.c\n@@ -152,7 +152,7 @@ static int same_entry(struct name_entry \n {\n \treturn\ta->sha1 &&\n \t\tb->sha1 &&\n-\t\t!memcmp(a->sha1, b->sha1, 20) &&\n+\t\t!hashcmp(a->sha1, b->sha1) &&\n \t\ta->mode == b->mode;\n }\n \ndiff --git a/object.c b/object.c\nindex b5d8ed4..fdcfff7 100644\n--- a/object.c\n+++ b/object.c\n@@ -58,7 +58,7 @@ struct object *lookup_object(const unsig\n \n \ti = hashtable_index(sha1);\n \twhile ((obj = obj_hash[i]) != NULL) {\n-\t\tif (!memcmp(sha1, obj->sha1, 20))\n+\t\tif (!hashcmp(sha1, obj->sha1))\n \t\t\tbreak;\n \t\ti++;\n \t\tif (i == obj_hash_size)\ndiff --git a/pack-check.c b/pack-check.c\nindex 3a62e1b..04c6c00 100644\n--- a/pack-check.c\n+++ b/pack-check.c\n@@ -29,10 +29,10 @@ static int verify_packfile(struct packed\n \tpack_base = p->pack_base;\n \tSHA1_Update(&ctx, pack_base, pack_size - 20);\n \tSHA1_Final(sha1, &ctx);\n-\tif (memcmp(sha1, (char *) pack_base + pack_size - 20, 20))\n+\tif (hashcmp(sha1, (unsigned char *)pack_base + pack_size - 20))\n \t\treturn error(\"Packfile %s SHA1 mismatch with itself\",\n \t\t\t     p->pack_name);\n-\tif (memcmp(sha1, (char *) index_base + index_size - 40, 20))\n+\tif (hashcmp(sha1, (unsigned char *)index_base + index_size - 40))\n \t\treturn error(\"Packfile %s SHA1 mismatch with idx\",\n \t\t\t     p->pack_name);\n \n@@ -135,7 +135,7 @@ int verify_pack(struct packed_git *p, in\n \tSHA1_Init(&ctx);\n \tSHA1_Update(&ctx, index_base, index_size - 20);\n \tSHA1_Final(sha1, &ctx);\n-\tif (memcmp(sha1, (char *) index_base + index_size - 20, 20))\n+\tif (hashcmp(sha1, (unsigned char *)index_base + index_size - 20))\n \t\tret = error(\"Packfile index for %s SHA1 mismatch\",\n \t\t\t    p->pack_name);\n \ndiff --git a/pack-redundant.c b/pack-redundant.c\nindex 92a09ed..edb5524 100644\n--- a/pack-redundant.c\n+++ b/pack-redundant.c\n@@ -139,7 +139,7 @@ static inline struct llist_item *llist_i\n \n \tl = (hint == NULL) ? list->front : hint;\n \twhile (l) {\n-\t\tint cmp = memcmp(l->sha1, sha1, 20);\n+\t\tint cmp = hashcmp(l->sha1, sha1);\n \t\tif (cmp > 0) { /* we insert before this entry */\n \t\t\treturn llist_insert(list, prev, sha1);\n \t\t}\n@@ -162,7 +162,7 @@ redo_from_start:\n \tl = (hint == NULL) ? list->front : hint;\n \tprev = NULL;\n \twhile (l) {\n-\t\tint cmp = memcmp(l->sha1, sha1, 20);\n+\t\tint cmp = hashcmp(l->sha1, sha1);\n \t\tif (cmp > 0) /* not in list, since sorted */\n \t\t\treturn prev;\n \t\tif(!cmp) { /* found */\n@@ -256,7 +256,7 @@ static void cmp_two_packs(struct pack_li\n \twhile (p1_off <= p1->pack->index_size - 3 * 20 &&\n \t       p2_off <= p2->pack->index_size - 3 * 20)\n \t{\n-\t\tint cmp = memcmp(p1_base + p1_off, p2_base + p2_off, 20);\n+\t\tint cmp = hashcmp(p1_base + p1_off, p2_base + p2_off);\n \t\t/* cmp ~ p1 - p2 */\n \t\tif (cmp == 0) {\n \t\t\tp1_hint = llist_sorted_remove(p1->unique_objects,\n@@ -351,16 +351,16 @@ static size_t sizeof_union(struct packed\n {\n \tsize_t ret = 0;\n \tint p1_off, p2_off;\n-\tchar *p1_base, *p2_base;\n+\tunsigned char *p1_base, *p2_base;\n \n \tp1_off = p2_off = 256 * 4 + 4;\n-\tp1_base = (char *)p1->index_base;\n-\tp2_base = (char *)p2->index_base;\n+\tp1_base = (unsigned char *)p1->index_base;\n+\tp2_base = (unsigned char *)p2->index_base;\n \n \twhile (p1_off <= p1->index_size - 3 * 20 &&\n \t       p2_off <= p2->index_size - 3 * 20)\n \t{\n-\t\tint cmp = memcmp(p1_base + p1_off, p2_base + p2_off, 20);\n+\t\tint cmp = hashcmp(p1_base + p1_off, p2_base + p2_off);\n \t\t/* cmp ~ p1 - p2 */\n \t\tif (cmp == 0) {\n \t\t\tret++;\ndiff --git a/read-cache.c b/read-cache.c\nindex 6bec833..b6982ea 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -60,7 +60,7 @@ static int ce_compare_data(struct cache_\n \tif (fd >= 0) {\n \t\tunsigned char sha1[20];\n \t\tif (!index_fd(sha1, fd, st, 0, NULL))\n-\t\t\tmatch = memcmp(sha1, ce->sha1, 20);\n+\t\t\tmatch = hashcmp(sha1, ce->sha1);\n \t\t/* index_fd() closed the file descriptor already */\n \t}\n \treturn match;\n@@ -744,7 +744,7 @@ static int verify_hdr(struct cache_heade\n \tSHA1_Init(&c);\n \tSHA1_Update(&c, hdr, size - 20);\n \tSHA1_Final(sha1, &c);\n-\tif (memcmp(sha1, (char *) hdr + size - 20, 20))\n+\tif (hashcmp(sha1, (unsigned char *)hdr + size - 20))\n \t\treturn error(\"bad index file sha1 signature\");\n \treturn 0;\n }\ndiff --git a/refs.c b/refs.c\nindex 86ef916..17cd0ce 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -281,7 +281,7 @@ static struct ref_lock *verify_lock(stru\n \t\tunlock_ref(lock);\n \t\treturn NULL;\n \t}\n-\tif (memcmp(lock->old_sha1, old_sha1, 20)) {\n+\tif (hashcmp(lock->old_sha1, old_sha1)) {\n \t\terror(\"Ref %s is at %s but expected %s\", lock->ref_file,\n \t\t\tsha1_to_hex(lock->old_sha1), sha1_to_hex(old_sha1));\n \t\tunlock_ref(lock);\n@@ -411,7 +411,7 @@ int write_ref_sha1(struct ref_lock *lock\n \n \tif (!lock)\n \t\treturn -1;\n-\tif (!lock->force_write && !memcmp(lock->old_sha1, sha1, 20)) {\n+\tif (!lock->force_write && !hashcmp(lock->old_sha1, sha1)) {\n \t\tunlock_ref(lock);\n \t\treturn 0;\n \t}\n@@ -475,7 +475,7 @@ int read_ref_at(const char *ref, unsigne\n \t\t\t\t\tdie(\"Log %s is corrupt.\", logfile);\n \t\t\t\tif (get_sha1_hex(rec + 41, sha1))\n \t\t\t\t\tdie(\"Log %s is corrupt.\", logfile);\n-\t\t\t\tif (memcmp(logged_sha1, sha1, 20)) {\n+\t\t\t\tif (hashcmp(logged_sha1, sha1)) {\n \t\t\t\t\ttz = strtoul(tz_c, NULL, 10);\n \t\t\t\t\tfprintf(stderr,\n \t\t\t\t\t\t\"warning: Log %s has gap after %s.\\n\",\n@@ -489,7 +489,7 @@ int read_ref_at(const char *ref, unsigne\n \t\t\telse {\n \t\t\t\tif (get_sha1_hex(rec + 41, logged_sha1))\n \t\t\t\t\tdie(\"Log %s is corrupt.\", logfile);\n-\t\t\t\tif (memcmp(logged_sha1, sha1, 20)) {\n+\t\t\t\tif (hashcmp(logged_sha1, sha1)) {\n \t\t\t\t\ttz = strtoul(tz_c, NULL, 10);\n \t\t\t\t\tfprintf(stderr,\n \t\t\t\t\t\t\"warning: Log %s unexpectedly ended on %s.\\n\",\ndiff --git a/send-pack.c b/send-pack.c\nindex 43e10b0..f7c0cfc 100644\n--- a/send-pack.c\n+++ b/send-pack.c\n@@ -265,7 +265,7 @@ static int send_pack(int in, int out, in\n \t\tchar old_hex[60], *new_hex;\n \t\tif (!ref->peer_ref)\n \t\t\tcontinue;\n-\t\tif (!memcmp(ref->old_sha1, ref->peer_ref->new_sha1, 20)) {\n+\t\tif (!hashcmp(ref->old_sha1, ref->peer_ref->new_sha1)) {\n \t\t\tif (verbose)\n \t\t\t\tfprintf(stderr, \"'%s': up-to-date\\n\", ref->name);\n \t\t\tcontinue;\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 18dece4..04f7f94 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -485,10 +485,10 @@ int use_packed_git(struct packed_git *p)\n \t\t/* Check if the pack file matches with the index file.\n \t\t * this is cheap.\n \t\t */\n-\t\tif (memcmp((char*)(p->index_base) + p->index_size - 40,\n-\t\t\t   (char *) p->pack_base + p->pack_size - 20,\n-\t\t\t   20)) {\n-\n+\t\tif (hashcmp((unsigned char *)(p->index_base) +\n+\t\t\t    p->index_size - 40,\n+\t\t\t    (unsigned char *)p->pack_base +\n+\t\t\t    p->pack_size - 20)) {\n \t\t\tdie(\"packfile %s does not match index.\", p->pack_name);\n \t\t}\n \t}\n@@ -643,7 +643,7 @@ int check_sha1_signature(const unsigned \n \tSHA1_Update(&c, header, 1+sprintf(header, \"%s %lu\", type, size));\n \tSHA1_Update(&c, map, size);\n \tSHA1_Final(real_sha1, &c);\n-\treturn memcmp(sha1, real_sha1, 20) ? -1 : 0;\n+\treturn hashcmp(sha1, real_sha1) ? -1 : 0;\n }\n \n void *map_sha1_file(const unsigned char *sha1, unsigned long *size)\n@@ -941,7 +941,7 @@ int check_reuse_pack_delta(struct packed\n \tptr = unpack_object_header(p, ptr, kindp, sizep);\n \tif (*kindp != OBJ_DELTA)\n \t\tgoto done;\n-\tmemcpy(base, (char *) p->pack_base + ptr, 20);\n+\tmemcpy(base, (unsigned char *) p->pack_base + ptr, 20);\n \tstatus = 0;\n  done:\n \tunuse_packed_git(p);\n@@ -1206,7 +1206,7 @@ int find_pack_entry_one(const unsigned c\n \n \tdo {\n \t\tint mi = (lo + hi) / 2;\n-\t\tint cmp = memcmp((char *) index + (24 * mi) + 4, sha1, 20);\n+\t\tint cmp = hashcmp((unsigned char *)index + (24 * mi) + 4, sha1);\n \t\tif (!cmp) {\n \t\t\te->offset = ntohl(*((unsigned int *) ((char *) index + (24 * mi))));\n \t\t\tmemcpy(e->sha1, sha1, 20);\n@@ -1715,7 +1715,7 @@ int write_sha1_from_fd(const unsigned ch\n \t\tunlink(tmpfile);\n \t\treturn error(\"File %s corrupted\", sha1_to_hex(sha1));\n \t}\n-\tif (memcmp(sha1, real_sha1, 20)) {\n+\tif (hashcmp(sha1, real_sha1)) {\n \t\tunlink(tmpfile);\n \t\treturn error(\"File %s has bad hash\", sha1_to_hex(sha1));\n \t}\ndiff --git a/sha1_name.c b/sha1_name.c\nindex f567454..e9eb6ce 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -84,7 +84,7 @@ static int find_short_packed_object(int \n \t\t\tint cmp;\n \n \t\t\tnth_packed_object_sha1(p, mid, now);\n-\t\t\tcmp = memcmp(match, now, 20);\n+\t\t\tcmp = hashcmp(match, now);\n \t\t\tif (!cmp) {\n \t\t\t\tfirst = mid;\n \t\t\t\tbreak;\n@@ -106,7 +106,7 @@ static int find_short_packed_object(int \n \t\t\t\t\t\tmemcpy(found_sha1, now, 20);\n \t\t\t\t\t\tfound++;\n \t\t\t\t\t}\n-\t\t\t\t\telse if (memcmp(found_sha1, now, 20)) {\n+\t\t\t\t\telse if (hashcmp(found_sha1, now)) {\n \t\t\t\t\t\tfound = 2;\n \t\t\t\t\t\tbreak;\n \t\t\t\t\t}\n@@ -144,7 +144,7 @@ static int find_unique_short_object(int \n \t\treturn 0;\n \t}\n \t/* Both have unique ones -- do they match? */\n-\tif (memcmp(packed_sha1, unpacked_sha1, 20))\n+\tif (hashcmp(packed_sha1, unpacked_sha1))\n \t\treturn SHORT_NAME_AMBIGUOUS;\n \tmemcpy(sha1, packed_sha1, 20);\n \treturn 0;\ndiff --git a/ssh-fetch.c b/ssh-fetch.c\nindex 0b89df6..b006c5c 100644\n--- a/ssh-fetch.c\n+++ b/ssh-fetch.c\n@@ -67,7 +67,7 @@ int fetch(unsigned char *sha1)\n \tsigned char remote;\n \tstruct object_list *temp;\n \n-\tif (memcmp(sha1, in_transit->item->sha1, 20)) {\n+\tif (hashcmp(sha1, in_transit->item->sha1)) {\n \t\t/* we must have already fetched it to clean the queue */\n \t\treturn has_sha1_file(sha1) ? 0 : -1;\n \t}\ndiff --git a/tree-diff.c b/tree-diff.c\nindex 916f489..7e2f4f0 100644\n--- a/tree-diff.c\n+++ b/tree-diff.c\n@@ -39,8 +39,7 @@ static int compare_tree_entry(struct tre\n \t\tshow_entry(opt, \"+\", t2, base);\n \t\treturn 1;\n \t}\n-\tif (!opt->find_copies_harder &&\n-\t    !memcmp(sha1, sha2, 20) && mode1 == mode2)\n+\tif (!opt->find_copies_harder && !hashcmp(sha1, sha2) && mode1 == mode2)\n \t\treturn 0;\n \n \t/*\ndiff --git a/unpack-trees.c b/unpack-trees.c\nindex 43ed124..467d994 100644\n--- a/unpack-trees.c\n+++ b/unpack-trees.c\n@@ -417,7 +417,7 @@ static int same(struct cache_entry *a, s\n \tif (!a && !b)\n \t\treturn 1;\n \treturn a->ce_mode == b->ce_mode &&\n-\t\t!memcmp(a->sha1, b->sha1, 20);\n+\t       !hashcmp(a->sha1, b->sha1);\n }\n \n \n-- \n1.4.2.gd4ba-dirty\n"},{"id":"25507","messageId":"81b0412b0608171350w1095e35ch7c017e973e6510f5@mail.gmail.com","threadId":"5300","inReplyTo":"Pine.LNX.4.63.0608171152110.22819@chino.corp.google.com","subject":"Re: [PATCH] introduce inline is_same_sha1","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2006-08-17T20:50:50Z","receivedAt":"2006-08-17T20:50:50Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"On 8/17/06, David Rientjes <rientjes@google.com> wrote:\n> Introduces global inline:\n>         hashcmp(const unsigned char *sha1, const unsigned char *sha2)\n>\n> Uses memcmp for comparison and returns the result based on the length of\n> the hash name (a future runtime decision).\n>\n> Signed-off-by: David Rientjes <rientjes@google.com>\n\nAcked-by: Alex Riesen <raa.lkml@gmail.com>\n"},{"id":"25514","messageId":"7vejveelcs.fsf@assigned-by-dhcp.cox.net","threadId":"5300","inReplyTo":"Pine.LNX.4.63.0608171152110.22819@chino.corp.google.com","subject":"Re: [PATCH] introduce inline is_same_sha1","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-08-18T04:09:07Z","receivedAt":"2006-08-18T04:09:07Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"David Rientjes <rientjes@google.com> writes:\n\n> On Thu, 17 Aug 2006, Alex Riesen wrote:\n>\n>> Why not just sha1cmp? And if you're aiming at hash-type independence,\n>> why not hashcmp?\n>\n> hashcmp is a very good suggestion.\n>\n> \t\tDavid\n> ---\n> Introduces global inline:\n> \thashcmp(const unsigned char *sha1, const unsigned char *sha2)\n>\n> Uses memcmp for comparison and returns the result based on the length of \n> the hash name (a future runtime decision).\n>\n> Signed-off-by: David Rientjes <rientjes@google.com>\n\nLooks very very good.  Much cleaner.\n\nAlso, I retract my previous comment that the parameters should\nbe (void*).  Looking at the call sites that need casts, they\nwould need either (unsigned char*) or (char*) cast regardless of\nthe type of the argument hashcmp() function takes anyway.\n\nThanks.  Will apply.\n\nOh, by the way, two minor procedural requests.\n\nPick a good one-line description of the patch; as it was sent,\nthe commit would have shown (in \"git shortlog\" output):\n\n\tIntroduces global inline:\n\nwhich does not make much sense to the first time readers.\n\nPlease use something other than '---' as the delimiter after the\ncover letter, if you write one _before_ the commit log message.\nE-mailed patch acceptance tools consider anything after '---' is\npatch and does not contribute to the commit log, so it is lost\nfrom the resulting commit.\n\nA short cover letter like this is better placed _after_ the real\nseparator '---' that comes after your commit log message, like\nthis:\n\nFrom: David Rientjes <rientjes@google.com>\nSubject: Do not use memcmp(sha1_1, sha1_2, 20) with hardcoded length.\n\nIntroduces global inline:\n\n\thashcmp(const unsigned char *sha1, const unsigned char *sha2)\n\nUses memcmp for comparison and returns the result based on the length of \nthe hash name (a future runtime decision).\n\nSigned-off-by: David Rientjes <rientjes@google.com>\n---\n\n On Thu, 17 Aug 2006, Alex Riesen wrote:\n\n > Why not just sha1cmp? And if you're aiming at hash-type independence,\n > why not hashcmp?\n\n hashcmp is a very good suggestion.  Please ack the following.\n\n builtin-commit-tree.c    |    2 +-\n builtin-diff-stages.c    |    2 +-\n ...\n"}]}