]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Do not use memcmp(sha1_1, sha1_2, 20) with hardcoded length.
authorDavid Rientjes <rientjes@google.com>
Thu, 17 Aug 2006 18:54:57 +0000 (11:54 -0700)
committerJunio C Hamano <junkio@cox.net>
Thu, 17 Aug 2006 21:23:53 +0000 (14:23 -0700)
Introduces global inline:

hashcmp(const unsigned char *sha1, const unsigned char *sha2)

Uses memcmp for comparison and returns the result based on the length of
the hash name (a future runtime decision).

Acked-by: Alex Riesen <raa.lkml@gmail.com>
Signed-off-by: David Rientjes <rientjes@google.com>
Signed-off-by: Junio C Hamano <junkio@cox.net>
31 files changed:
builtin-commit-tree.c
builtin-diff-stages.c
builtin-diff.c
builtin-pack-objects.c
builtin-show-branch.c
builtin-unpack-objects.c
builtin-update-index.c
cache.h
combine-diff.c
commit.c
convert-objects.c
diff-lib.c
diff.c
diffcore-break.c
diffcore-rename.c
dump-cache-tree.c
http-fetch.c
http-push.c
index-pack.c
merge-tree.c
object.c
pack-check.c
pack-redundant.c
read-cache.c
refs.c
send-pack.c
sha1_file.c
sha1_name.c
ssh-fetch.c
tree-diff.c
unpack-trees.c

index 9c987966711d4bff1f709df0c14071170950e21d..e2e690a1ae89b47f595288e452da10113f7b2e8f 100644 (file)
@@ -69,7 +69,7 @@ static int new_parent(int idx)
        int i;
        unsigned char *sha1 = parent_sha1[idx];
        for (i = 0; i < idx; i++) {
-               if (!memcmp(parent_sha1[i], sha1, 20)) {
+               if (!hashcmp(parent_sha1[i], sha1)) {
                        error("duplicate parent %s ignored", sha1_to_hex(sha1));
                        return 0;
                }
index 5960e089975f1f27c55c5bd8ea1c968ffe695d1f..70bb89808d2296246edbafb8378aa651c3382261 100644 (file)
@@ -46,7 +46,7 @@ static void diff_stages(int stage1, int stage2, const char **pathspec)
                else if (!two)
                        diff_addremove(&diff_options, '-', ntohl(one->ce_mode),
                                       one->sha1, name, NULL);
-               else if (memcmp(one->sha1, two->sha1, 20) ||
+               else if (hashcmp(one->sha1, two->sha1) ||
                         (one->ce_mode != two->ce_mode) ||
                         diff_options.find_copies_harder)
                        diff_change(&diff_options,
index 40e5c96f30e3d638c09b276805158bdba3ddde58..874f773421620642425e67f650de2a34396f1c0f 100644 (file)
@@ -69,7 +69,7 @@ static void stuff_change(struct diff_options *opt,
        struct diff_filespec *one, *two;
 
        if (!is_null_sha1(old_sha1) && !is_null_sha1(new_sha1) &&
-           !memcmp(old_sha1, new_sha1, 20))
+           !hashcmp(old_sha1, new_sha1))
                return;
 
        if (opt->reverse_diff) {
index 448461bc4826da8b34ebf32c876d9b2341f51447..f19f0d60460a721dafcd232d4896231f765a979f 100644 (file)
@@ -441,7 +441,7 @@ static int locate_object_entry_hash(const unsigned char *sha1)
        memcpy(&ui, sha1, sizeof(unsigned int));
        i = ui % object_ix_hashsz;
        while (0 < object_ix[i]) {
-               if (!memcmp(sha1, objects[object_ix[i]-1].sha1, 20))
+               if (!hashcmp(sha1, objects[object_ix[i] - 1].sha1))
                        return i;
                if (++i == object_ix_hashsz)
                        i = 0;
@@ -607,7 +607,7 @@ static struct pbase_tree_cache *pbase_tree_get(const unsigned char *sha1)
         */
        for (neigh = 0; neigh < 8; neigh++) {
                ent = pbase_tree_cache[my_ix];
-               if (ent && !memcmp(ent->sha1, sha1, 20)) {
+               if (ent && !hashcmp(ent->sha1, sha1)) {
                        ent->ref++;
                        return ent;
                }
@@ -789,7 +789,7 @@ static void add_preferred_base(unsigned char *sha1)
                return;
 
        for (it = pbase_tree; it; it = it->next) {
-               if (!memcmp(it->pcache.sha1, tree_sha1, 20)) {
+               if (!hashcmp(it->pcache.sha1, tree_sha1)) {
                        free(data);
                        return;
                }
@@ -931,7 +931,7 @@ static struct object_entry **create_sorted_list(entry_sort_t sort)
 
 static int sha1_sort(const struct object_entry *a, const struct object_entry *b)
 {
-       return memcmp(a->sha1, b->sha1, 20);
+       return hashcmp(a->sha1, b->sha1);
 }
 
 static struct object_entry **create_final_object_list(void)
index 95fbf77fad84a13330b0c0e58586edac0eb037f0..18786f88e3252dbd46d88014f2f35205c53d5200 100644 (file)
@@ -378,7 +378,7 @@ static int append_head_ref(const char *refname, const unsigned char *sha1)
        /* If both heads/foo and tags/foo exists, get_sha1 would
         * get confused.
         */
-       if (get_sha1(refname + ofs, tmp) || memcmp(tmp, sha1, 20))
+       if (get_sha1(refname + ofs, tmp) || hashcmp(tmp, sha1))
                ofs = 5;
        return append_ref(refname + ofs, sha1);
 }
@@ -442,7 +442,7 @@ static int rev_is_head(char *head_path, int headlen, char *name,
 {
        int namelen;
        if ((!head_path[0]) ||
-           (head_sha1 && sha1 && memcmp(head_sha1, sha1, 20)))
+           (head_sha1 && sha1 && hashcmp(head_sha1, sha1)))
                return 0;
        namelen = strlen(name);
        if ((headlen < namelen) ||
index 63f4b8e45d1cb80042583fba382acc7f4f1f952c..f0ae5c987af79bc5254df7cd3587ed1852e63209 100644 (file)
@@ -136,7 +136,7 @@ static void added_object(unsigned char *sha1, const char *type, void *data, unsi
        struct delta_info *info;
 
        while ((info = *p) != NULL) {
-               if (!memcmp(info->base_sha1, sha1, 20)) {
+               if (!hashcmp(info->base_sha1, sha1)) {
                        *p = info->next;
                        p = &delta_list;
                        resolve_delta(type, data, size, info->delta, info->size);
@@ -292,7 +292,7 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix)
        unpack_all();
        SHA1_Update(&ctx, buffer, offset);
        SHA1_Final(sha1, &ctx);
-       if (memcmp(fill(20), sha1, 20))
+       if (hashcmp(fill(20), sha1))
                die("final sha1 did not match");
        use(20);
 
index 9f0cf28ba2dde7c5000029107460a3f4ca873aa3..5dd91af180df0f832ecc747050ad5306efe9c8b6 100644 (file)
@@ -378,7 +378,7 @@ static int unresolve_one(const char *path)
                ret = -1;
                goto free_return;
        }
-       if (!memcmp(ce_2->sha1, ce_3->sha1, 20) &&
+       if (!hashcmp(ce_2->sha1, ce_3->sha1) &&
            ce_2->ce_mode == ce_3->ce_mode) {
                fprintf(stderr, "%s: identical in both, skipping.\n",
                        path);
@@ -460,7 +460,7 @@ static int do_reupdate(int ac, const char **av,
                        old = read_one_ent(NULL, head_sha1,
                                           ce->name, ce_namelen(ce), 0);
                if (old && ce->ce_mode == old->ce_mode &&
-                   !memcmp(ce->sha1, old->sha1, 20)) {
+                   !hashcmp(ce->sha1, old->sha1)) {
                        free(old);
                        continue; /* unchanged */
                }
diff --git a/cache.h b/cache.h
index c7382996f62061f1022262fcc6e6f3f15e946d0a..f99254bf991af312e2e15aa279e75db4a3b1dbdd 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -214,6 +214,10 @@ static inline int is_null_sha1(const unsigned char *sha1)
 {
        return !memcmp(sha1, null_sha1, 20);
 }
+static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)
+{
+       return memcmp(sha1, sha2, 20);
+}
 
 int git_mkstemp(char *path, size_t n, const char *template);
 
index ce063b4ffa48eb1db8849d5aabb6732fc98946b6..0682acd50d618e4ba8319372c46c72b3e479b8e6 100644 (file)
@@ -688,8 +688,8 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
        for (i = 0; i < num_parent; i++) {
                int j;
                for (j = 0; j < i; j++) {
-                       if (!memcmp(elem->parent[i].sha1,
-                                   elem->parent[j].sha1, 20)) {
+                       if (!hashcmp(elem->parent[i].sha1,
+                                    elem->parent[j].sha1)) {
                                reuse_combine_diff(sline, cnt, i, j);
                                break;
                        }
index 972d1b70c02d0a21bbb187ef964e6604d4556e87..d17451fbff04caff575e6c869e111178a9479833 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -123,7 +123,7 @@ static int commit_graft_pos(const unsigned char *sha1)
        while (lo < hi) {
                int mi = (lo + hi) / 2;
                struct commit_graft *graft = commit_graft[mi];
-               int cmp = memcmp(sha1, graft->sha1, 20);
+               int cmp = hashcmp(sha1, graft->sha1);
                if (!cmp)
                        return mi;
                if (cmp < 0)
index 168771ed857dd9e95b1e14da40f1e39d18f7b2cf..4e7ff7517f40f5dd5c23cd3fd6a42d3cb621aec1 100644 (file)
@@ -39,7 +39,7 @@ static struct entry *lookup_entry(unsigned char *sha1)
        while (low < high) {
                int next = (low + high) / 2;
                struct entry *n = convert[next];
-               int cmp = memcmp(sha1, n->old_sha1, 20);
+               int cmp = hashcmp(sha1, n->old_sha1);
                if (!cmp)
                        return n;
                if (cmp < 0) {
index 116b5a9d6834c9517ccc2202510b37a1e1d863a5..3e4b3b96b71925974eee5f1f691158c314722011 100644 (file)
@@ -215,7 +215,7 @@ static int show_modified(struct rev_info *revs,
        }
 
        oldmode = old->ce_mode;
-       if (mode == oldmode && !memcmp(sha1, old->sha1, 20) &&
+       if (mode == oldmode && !hashcmp(sha1, old->sha1) &&
            !revs->diffopt.find_copies_harder)
                return 0;
 
diff --git a/diff.c b/diff.c
index 7a238d023336d4340efd67534dae4ed23dd5d3c0..da7cca1952e7e245730bd81419e1b23ce57ef173 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -1140,7 +1140,7 @@ static int work_tree_matches(const char *name, const unsigned char *sha1)
        if ((lstat(name, &st) < 0) ||
            !S_ISREG(st.st_mode) || /* careful! */
            ce_match_stat(ce, &st, 0) ||
-           memcmp(sha1, ce->sha1, 20))
+           hashcmp(sha1, ce->sha1))
                return 0;
        /* we return 1 only when we can stat, it is a regular file,
         * stat information matches, and sha1 recorded in the cache
@@ -1168,7 +1168,7 @@ static struct sha1_size_cache *locate_size_cache(unsigned char *sha1,
        while (last > first) {
                int cmp, next = (last + first) >> 1;
                e = sha1_size_cache[next];
-               cmp = memcmp(e->sha1, sha1, 20);
+               cmp = hashcmp(e->sha1, sha1);
                if (!cmp)
                        return e;
                if (cmp < 0) {
@@ -1579,7 +1579,7 @@ static void run_diff(struct diff_filepair *p, struct diff_options *o)
                ;
        }
 
-       if (memcmp(one->sha1, two->sha1, 20)) {
+       if (hashcmp(one->sha1, two->sha1)) {
                int abbrev = o->full_index ? 40 : DEFAULT_ABBREV;
 
                len += snprintf(msg + len, sizeof(msg) - len,
@@ -2098,7 +2098,7 @@ int diff_unmodified_pair(struct diff_filepair *p)
         * dealing with a change.
         */
        if (one->sha1_valid && two->sha1_valid &&
-           !memcmp(one->sha1, two->sha1, sizeof(one->sha1)))
+           !hashcmp(one->sha1, two->sha1))
                return 1; /* no change */
        if (!one->sha1_valid && !two->sha1_valid)
                return 1; /* both look at the same file on the filesystem. */
@@ -2237,7 +2237,7 @@ static void diff_resolve_rename_copy(void)
                        if (!p->status)
                                p->status = DIFF_STATUS_RENAMED;
                }
-               else if (memcmp(p->one->sha1, p->two->sha1, 20) ||
+               else if (hashcmp(p->one->sha1, p->two->sha1) ||
                         p->one->mode != p->two->mode)
                        p->status = DIFF_STATUS_MODIFIED;
                else {
index ed0e14c6d8b1b8347f20c890854972be6c6a234c..acb18db1db27dc29fdb76bd519174aa56f56121d 100644 (file)
@@ -56,7 +56,7 @@ static int should_break(struct diff_filespec *src,
                return 0; /* leave symlink rename alone */
 
        if (src->sha1_valid && dst->sha1_valid &&
-           !memcmp(src->sha1, dst->sha1, 20))
+           !hashcmp(src->sha1, dst->sha1))
                return 0; /* they are the same */
 
        if (diff_populate_filespec(src, 0) || diff_populate_filespec(dst, 0))
index 0ec488a9033ea2d4514dab450d9e20581782ddbb..ef239012b65c901bba5eef598f62679fd288106e 100644 (file)
@@ -101,7 +101,7 @@ static int is_exact_match(struct diff_filespec *src,
                          int contents_too)
 {
        if (src->sha1_valid && dst->sha1_valid &&
-           !memcmp(src->sha1, dst->sha1, 20))
+           !hashcmp(src->sha1, dst->sha1))
                return 1;
        if (!contents_too)
                return 0;
index 1ccaf5177318f8765205e192abdffc3336c9aacb..1f73f1ea7dfa6a14dedf384c99751e86c8121ff4 100644 (file)
@@ -33,7 +33,7 @@ static int dump_cache_tree(struct cache_tree *it,
        }
        else {
                dump_one(it, pfx, "");
-               if (memcmp(it->sha1, ref->sha1, 20) ||
+               if (hashcmp(it->sha1, ref->sha1) ||
                    ref->entry_count != it->entry_count ||
                    ref->subtree_nr != it->subtree_nr) {
                        dump_one(ref, pfx, "#(ref) ");
index 7f07d2a967fdecb497344817700962e9e213d3dd..d1f74b443be23e8cd7f10128713217acfab5254b 100644 (file)
@@ -301,7 +301,7 @@ static void finish_object_request(struct object_request *obj_req)
                unlink(obj_req->tmpfile);
                return;
        }
-       if (memcmp(obj_req->sha1, obj_req->real_sha1, 20)) {
+       if (hashcmp(obj_req->sha1, obj_req->real_sha1)) {
                unlink(obj_req->tmpfile);
                return;
        }
@@ -1070,7 +1070,7 @@ static int fetch_object(struct alt_base *repo, unsigned char *sha1)
        int ret = 0;
        struct object_request *obj_req = object_queue_head;
 
-       while (obj_req != NULL && memcmp(obj_req->sha1, sha1, 20))
+       while (obj_req != NULL && hashcmp(obj_req->sha1, sha1))
                obj_req = obj_req->next;
        if (obj_req == NULL)
                return error("Couldn't find request for %s in the queue", hex);
@@ -1109,7 +1109,7 @@ static int fetch_object(struct alt_base *repo, unsigned char *sha1)
        } else if (obj_req->zret != Z_STREAM_END) {
                corrupt_object_found++;
                ret = error("File %s (%s) corrupt", hex, obj_req->url);
-       } else if (memcmp(obj_req->sha1, obj_req->real_sha1, 20)) {
+       } else if (hashcmp(obj_req->sha1, obj_req->real_sha1)) {
                ret = error("File %s has bad hash", hex);
        } else if (obj_req->rename < 0) {
                ret = error("unable to write sha1 filename %s",
index 2bd984576523a7f2b646095eae92d08e7476b023..48497797f1650a2ed3f24010a85123993b14d8aa 100644 (file)
@@ -745,7 +745,7 @@ static void finish_request(struct transfer_request *request)
                        SHA1_Final(request->real_sha1, &request->c);
                        if (request->zret != Z_STREAM_END) {
                                unlink(request->tmpfile);
-                       } else if (memcmp(request->obj->sha1, request->real_sha1, 20)) {
+                       } else if (hashcmp(request->obj->sha1, request->real_sha1)) {
                                unlink(request->tmpfile);
                        } else {
                                request->rename =
@@ -2416,7 +2416,7 @@ int main(int argc, char **argv)
 
                if (!ref->peer_ref)
                        continue;
-               if (!memcmp(ref->old_sha1, ref->peer_ref->new_sha1, 20)) {
+               if (!hashcmp(ref->old_sha1, ref->peer_ref->new_sha1)) {
                        if (push_verbosely || 1)
                                fprintf(stderr, "'%s': up-to-date\n", ref->name);
                        continue;
index b20659c2591f2669e03570c9809249b37ec58c38..96ea6874634959c18263779a01f8385ee9ffde1e 100644 (file)
@@ -82,7 +82,7 @@ static void parse_pack_header(void)
        SHA1_Init(&ctx);
        SHA1_Update(&ctx, pack_base, pack_size - 20);
        SHA1_Final(sha1, &ctx);
-       if (memcmp(sha1, pack_base + pack_size - 20, 20))
+       if (hashcmp(sha1, pack_base + pack_size - 20))
                die("packfile '%s' SHA1 mismatch", pack_name);
 }
 
@@ -189,7 +189,7 @@ static int find_delta(const unsigned char *base_sha1)
                 struct delta_entry *delta = &deltas[next];
                 int cmp;
 
-                cmp = memcmp(base_sha1, delta->base_sha1, 20);
+                cmp = hashcmp(base_sha1, delta->base_sha1);
                 if (!cmp)
                         return next;
                 if (cmp < 0) {
@@ -210,9 +210,9 @@ static int find_deltas_based_on_sha1(const unsigned char *base_sha1,
 
        if (first < 0)
                return -1;
-       while (first > 0 && !memcmp(deltas[first-1].base_sha1, base_sha1, 20))
+       while (first > 0 && !hashcmp(deltas[first - 1].base_sha1, base_sha1))
                --first;
-       while (last < end && !memcmp(deltas[last+1].base_sha1, base_sha1, 20))
+       while (last < end && !hashcmp(deltas[last + 1].base_sha1, base_sha1))
                ++last;
        *first_index = first;
        *last_index = last;
@@ -278,7 +278,7 @@ static int compare_delta_entry(const void *a, const void *b)
 {
        const struct delta_entry *delta_a = a;
        const struct delta_entry *delta_b = b;
-       return memcmp(delta_a->base_sha1, delta_b->base_sha1, 20);
+       return hashcmp(delta_a->base_sha1, delta_b->base_sha1);
 }
 
 static void parse_pack_objects(void)
@@ -350,7 +350,7 @@ static int sha1_compare(const void *_a, const void *_b)
 {
        struct object_entry *a = *(struct object_entry **)_a;
        struct object_entry *b = *(struct object_entry **)_b;
-       return memcmp(a->sha1, b->sha1, 20);
+       return hashcmp(a->sha1, b->sha1);
 }
 
 static void write_index_file(const char *index_name, unsigned char *sha1)
index 7cf00be6d51b17ca60979a9c856e67405906d9a7..c2e9a867edb5b843150cd3df47583f49f15314cb 100644 (file)
@@ -152,7 +152,7 @@ static int same_entry(struct name_entry *a, struct name_entry *b)
 {
        return  a->sha1 &&
                b->sha1 &&
-               !memcmp(a->sha1, b->sha1, 20) &&
+               !hashcmp(a->sha1, b->sha1) &&
                a->mode == b->mode;
 }
 
index b5d8ed467d1c10c2f2dd596717159f7ee48a8007..fdcfff7c86057bf8e5a7285518f186c67a1715bb 100644 (file)
--- a/object.c
+++ b/object.c
@@ -58,7 +58,7 @@ struct object *lookup_object(const unsigned char *sha1)
 
        i = hashtable_index(sha1);
        while ((obj = obj_hash[i]) != NULL) {
-               if (!memcmp(sha1, obj->sha1, 20))
+               if (!hashcmp(sha1, obj->sha1))
                        break;
                i++;
                if (i == obj_hash_size)
index 3a62e1b7e40927390e10ae63943596a367ecbf47..04c6c0082119360e307130f10972371236905747 100644 (file)
@@ -29,10 +29,10 @@ static int verify_packfile(struct packed_git *p)
        pack_base = p->pack_base;
        SHA1_Update(&ctx, pack_base, pack_size - 20);
        SHA1_Final(sha1, &ctx);
-       if (memcmp(sha1, (char *) pack_base + pack_size - 20, 20))
+       if (hashcmp(sha1, (unsigned char *)pack_base + pack_size - 20))
                return error("Packfile %s SHA1 mismatch with itself",
                             p->pack_name);
-       if (memcmp(sha1, (char *) index_base + index_size - 40, 20))
+       if (hashcmp(sha1, (unsigned char *)index_base + index_size - 40))
                return error("Packfile %s SHA1 mismatch with idx",
                             p->pack_name);
 
@@ -135,7 +135,7 @@ int verify_pack(struct packed_git *p, int verbose)
        SHA1_Init(&ctx);
        SHA1_Update(&ctx, index_base, index_size - 20);
        SHA1_Final(sha1, &ctx);
-       if (memcmp(sha1, (char *) index_base + index_size - 20, 20))
+       if (hashcmp(sha1, (unsigned char *)index_base + index_size - 20))
                ret = error("Packfile index for %s SHA1 mismatch",
                            p->pack_name);
 
index 92a09ed36281b293a8c9002a33ab80f740949a37..edb5524fc48b49bca5c0dd319caf348c9bda7c23 100644 (file)
@@ -139,7 +139,7 @@ static inline struct llist_item *llist_insert_sorted_unique(struct llist *list,
 
        l = (hint == NULL) ? list->front : hint;
        while (l) {
-               int cmp = memcmp(l->sha1, sha1, 20);
+               int cmp = hashcmp(l->sha1, sha1);
                if (cmp > 0) { /* we insert before this entry */
                        return llist_insert(list, prev, sha1);
                }
@@ -162,7 +162,7 @@ redo_from_start:
        l = (hint == NULL) ? list->front : hint;
        prev = NULL;
        while (l) {
-               int cmp = memcmp(l->sha1, sha1, 20);
+               int cmp = hashcmp(l->sha1, sha1);
                if (cmp > 0) /* not in list, since sorted */
                        return prev;
                if(!cmp) { /* found */
@@ -256,7 +256,7 @@ static void cmp_two_packs(struct pack_list *p1, struct pack_list *p2)
        while (p1_off <= p1->pack->index_size - 3 * 20 &&
               p2_off <= p2->pack->index_size - 3 * 20)
        {
-               int cmp = memcmp(p1_base + p1_off, p2_base + p2_off, 20);
+               int cmp = hashcmp(p1_base + p1_off, p2_base + p2_off);
                /* cmp ~ p1 - p2 */
                if (cmp == 0) {
                        p1_hint = llist_sorted_remove(p1->unique_objects,
@@ -351,16 +351,16 @@ static size_t sizeof_union(struct packed_git *p1, struct packed_git *p2)
 {
        size_t ret = 0;
        int p1_off, p2_off;
-       char *p1_base, *p2_base;
+       unsigned char *p1_base, *p2_base;
 
        p1_off = p2_off = 256 * 4 + 4;
-       p1_base = (char *)p1->index_base;
-       p2_base = (char *)p2->index_base;
+       p1_base = (unsigned char *)p1->index_base;
+       p2_base = (unsigned char *)p2->index_base;
 
        while (p1_off <= p1->index_size - 3 * 20 &&
               p2_off <= p2->index_size - 3 * 20)
        {
-               int cmp = memcmp(p1_base + p1_off, p2_base + p2_off, 20);
+               int cmp = hashcmp(p1_base + p1_off, p2_base + p2_off);
                /* cmp ~ p1 - p2 */
                if (cmp == 0) {
                        ret++;
index 6bec833eecae934af1dce18683c70522481b002a..b6982eac416fe765e1a570cdb25298e83264c81e 100644 (file)
@@ -60,7 +60,7 @@ static int ce_compare_data(struct cache_entry *ce, struct stat *st)
        if (fd >= 0) {
                unsigned char sha1[20];
                if (!index_fd(sha1, fd, st, 0, NULL))
-                       match = memcmp(sha1, ce->sha1, 20);
+                       match = hashcmp(sha1, ce->sha1);
                /* index_fd() closed the file descriptor already */
        }
        return match;
@@ -744,7 +744,7 @@ static int verify_hdr(struct cache_header *hdr, unsigned long size)
        SHA1_Init(&c);
        SHA1_Update(&c, hdr, size - 20);
        SHA1_Final(sha1, &c);
-       if (memcmp(sha1, (char *) hdr + size - 20, 20))
+       if (hashcmp(sha1, (unsigned char *)hdr + size - 20))
                return error("bad index file sha1 signature");
        return 0;
 }
diff --git a/refs.c b/refs.c
index 86ef91661400376f6bdc2af37fac7982f8872df9..17cd0cef3c9819d70083554f99d8f09391171db1 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -281,7 +281,7 @@ static struct ref_lock *verify_lock(struct ref_lock *lock,
                unlock_ref(lock);
                return NULL;
        }
-       if (memcmp(lock->old_sha1, old_sha1, 20)) {
+       if (hashcmp(lock->old_sha1, old_sha1)) {
                error("Ref %s is at %s but expected %s", lock->ref_file,
                        sha1_to_hex(lock->old_sha1), sha1_to_hex(old_sha1));
                unlock_ref(lock);
@@ -411,7 +411,7 @@ int write_ref_sha1(struct ref_lock *lock,
 
        if (!lock)
                return -1;
-       if (!lock->force_write && !memcmp(lock->old_sha1, sha1, 20)) {
+       if (!lock->force_write && !hashcmp(lock->old_sha1, sha1)) {
                unlock_ref(lock);
                return 0;
        }
@@ -475,7 +475,7 @@ int read_ref_at(const char *ref, unsigned long at_time, unsigned char *sha1)
                                        die("Log %s is corrupt.", logfile);
                                if (get_sha1_hex(rec + 41, sha1))
                                        die("Log %s is corrupt.", logfile);
-                               if (memcmp(logged_sha1, sha1, 20)) {
+                               if (hashcmp(logged_sha1, sha1)) {
                                        tz = strtoul(tz_c, NULL, 10);
                                        fprintf(stderr,
                                                "warning: Log %s has gap after %s.\n",
@@ -489,7 +489,7 @@ int read_ref_at(const char *ref, unsigned long at_time, unsigned char *sha1)
                        else {
                                if (get_sha1_hex(rec + 41, logged_sha1))
                                        die("Log %s is corrupt.", logfile);
-                               if (memcmp(logged_sha1, sha1, 20)) {
+                               if (hashcmp(logged_sha1, sha1)) {
                                        tz = strtoul(tz_c, NULL, 10);
                                        fprintf(stderr,
                                                "warning: Log %s unexpectedly ended on %s.\n",
index 43e10b0a620cc3d51d8905a9de36350ca6b67966..f7c0cfc6f67ba4d325ac6fc9f6c74fad78d1208e 100644 (file)
@@ -265,7 +265,7 @@ static int send_pack(int in, int out, int nr_refspec, char **refspec)
                char old_hex[60], *new_hex;
                if (!ref->peer_ref)
                        continue;
-               if (!memcmp(ref->old_sha1, ref->peer_ref->new_sha1, 20)) {
+               if (!hashcmp(ref->old_sha1, ref->peer_ref->new_sha1)) {
                        if (verbose)
                                fprintf(stderr, "'%s': up-to-date\n", ref->name);
                        continue;
index 18dece46b1e248a4e52e9ead3bf172ed6ab78236..04f7f94d21eb61f5fefa7de45996e131ac20c016 100644 (file)
@@ -485,10 +485,10 @@ int use_packed_git(struct packed_git *p)
                /* Check if the pack file matches with the index file.
                 * this is cheap.
                 */
-               if (memcmp((char*)(p->index_base) + p->index_size - 40,
-                          (char *) p->pack_base + p->pack_size - 20,
-                          20)) {
-
+               if (hashcmp((unsigned char *)(p->index_base) +
+                           p->index_size - 40,
+                           (unsigned char *)p->pack_base +
+                           p->pack_size - 20)) {
                        die("packfile %s does not match index.", p->pack_name);
                }
        }
@@ -643,7 +643,7 @@ int check_sha1_signature(const unsigned char *sha1, void *map, unsigned long siz
        SHA1_Update(&c, header, 1+sprintf(header, "%s %lu", type, size));
        SHA1_Update(&c, map, size);
        SHA1_Final(real_sha1, &c);
-       return memcmp(sha1, real_sha1, 20) ? -1 : 0;
+       return hashcmp(sha1, real_sha1) ? -1 : 0;
 }
 
 void *map_sha1_file(const unsigned char *sha1, unsigned long *size)
@@ -941,7 +941,7 @@ int check_reuse_pack_delta(struct packed_git *p, unsigned long offset,
        ptr = unpack_object_header(p, ptr, kindp, sizep);
        if (*kindp != OBJ_DELTA)
                goto done;
-       memcpy(base, (char *) p->pack_base + ptr, 20);
+       memcpy(base, (unsigned char *) p->pack_base + ptr, 20);
        status = 0;
  done:
        unuse_packed_git(p);
@@ -1206,7 +1206,7 @@ int find_pack_entry_one(const unsigned char *sha1,
 
        do {
                int mi = (lo + hi) / 2;
-               int cmp = memcmp((char *) index + (24 * mi) + 4, sha1, 20);
+               int cmp = hashcmp((unsigned char *)index + (24 * mi) + 4, sha1);
                if (!cmp) {
                        e->offset = ntohl(*((unsigned int *) ((char *) index + (24 * mi))));
                        memcpy(e->sha1, sha1, 20);
@@ -1715,7 +1715,7 @@ int write_sha1_from_fd(const unsigned char *sha1, int fd, char *buffer,
                unlink(tmpfile);
                return error("File %s corrupted", sha1_to_hex(sha1));
        }
-       if (memcmp(sha1, real_sha1, 20)) {
+       if (hashcmp(sha1, real_sha1)) {
                unlink(tmpfile);
                return error("File %s has bad hash", sha1_to_hex(sha1));
        }
index f567454d22ada41b1565f26e7136e62b70769dfa..e9eb6ce882ea92523c9a871c7581457af2dc78c5 100644 (file)
@@ -84,7 +84,7 @@ static int find_short_packed_object(int len, const unsigned char *match, unsigne
                        int cmp;
 
                        nth_packed_object_sha1(p, mid, now);
-                       cmp = memcmp(match, now, 20);
+                       cmp = hashcmp(match, now);
                        if (!cmp) {
                                first = mid;
                                break;
@@ -106,7 +106,7 @@ static int find_short_packed_object(int len, const unsigned char *match, unsigne
                                                memcpy(found_sha1, now, 20);
                                                found++;
                                        }
-                                       else if (memcmp(found_sha1, now, 20)) {
+                                       else if (hashcmp(found_sha1, now)) {
                                                found = 2;
                                                break;
                                        }
@@ -144,7 +144,7 @@ static int find_unique_short_object(int len, char *canonical,
                return 0;
        }
        /* Both have unique ones -- do they match? */
-       if (memcmp(packed_sha1, unpacked_sha1, 20))
+       if (hashcmp(packed_sha1, unpacked_sha1))
                return SHORT_NAME_AMBIGUOUS;
        memcpy(sha1, packed_sha1, 20);
        return 0;
index 0b89df6ddae5cfdfa4259379fc801f5e28f7c403..b006c5c9802d96bc504188e10a9698a1f943477c 100644 (file)
@@ -67,7 +67,7 @@ int fetch(unsigned char *sha1)
        signed char remote;
        struct object_list *temp;
 
-       if (memcmp(sha1, in_transit->item->sha1, 20)) {
+       if (hashcmp(sha1, in_transit->item->sha1)) {
                /* we must have already fetched it to clean the queue */
                return has_sha1_file(sha1) ? 0 : -1;
        }
index 916f489c5b79e04035f96dd9f667f70efedb83fa..7e2f4f088a359fe138b085730ba1b3465342e9e9 100644 (file)
@@ -39,8 +39,7 @@ static int compare_tree_entry(struct tree_desc *t1, struct tree_desc *t2, const
                show_entry(opt, "+", t2, base);
                return 1;
        }
-       if (!opt->find_copies_harder &&
-           !memcmp(sha1, sha2, 20) && mode1 == mode2)
+       if (!opt->find_copies_harder && !hashcmp(sha1, sha2) && mode1 == mode2)
                return 0;
 
        /*
index 43ed12484f6eb8bb828987872b2782182e579b9f..467d9940f5a2e9cd8a880e4c8f0f1d2a8a5f7aa1 100644 (file)
@@ -417,7 +417,7 @@ static int same(struct cache_entry *a, struct cache_entry *b)
        if (!a && !b)
                return 1;
        return a->ce_mode == b->ce_mode &&
-               !memcmp(a->sha1, b->sha1, 20);
+              !hashcmp(a->sha1, b->sha1);
 }