Skip to content

Commit e3ff068

Browse files
peffgitster
authored andcommitted
convert "hashcmp() == 0" to hasheq()
This is the partner patch to the previous one, but covering the "hash" variants instead of "oid". Note that our coccinelle rule is slightly more complex to avoid triggering the call in hasheq(). I didn't bother to add a new rule to convert: - hasheq(E1->hash, E2->hash) + oideq(E1, E2) Since these are new functions, there won't be any such existing callers. And since most of the code is already using oideq, we're not likely to introduce new ones. We might still see "!hashcmp(E1->hash, E2->hash)" from topics in flight. But because our new rule comes after the existing ones, that should first get converted to "!oidcmp(E1, E2)" and then to "oideq(E1, E2)". Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 4a7e27e commit e3ff068

File tree

8 files changed

+23
-14
lines changed

8 files changed

+23
-14
lines changed

builtin/fetch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ static int will_fetch(struct ref **head, const unsigned char *sha1)
238238
{
239239
struct ref *rm = *head;
240240
while (rm) {
241-
if (!hashcmp(rm->old_oid.hash, sha1))
241+
if (hasheq(rm->old_oid.hash, sha1))
242242
return 1;
243243
rm = rm->next;
244244
}

cache.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,12 +1053,12 @@ static inline int oideq(const struct object_id *oid1, const struct object_id *oi
10531053

10541054
static inline int is_null_sha1(const unsigned char *sha1)
10551055
{
1056-
return !hashcmp(sha1, null_sha1);
1056+
return hasheq(sha1, null_sha1);
10571057
}
10581058

10591059
static inline int is_null_oid(const struct object_id *oid)
10601060
{
1061-
return !hashcmp(oid->hash, null_sha1);
1061+
return hasheq(oid->hash, null_sha1);
10621062
}
10631063

10641064
static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src)
@@ -1095,7 +1095,7 @@ static inline void oidread(struct object_id *oid, const unsigned char *hash)
10951095

10961096
static inline int is_empty_blob_sha1(const unsigned char *sha1)
10971097
{
1098-
return !hashcmp(sha1, the_hash_algo->empty_blob->hash);
1098+
return hasheq(sha1, the_hash_algo->empty_blob->hash);
10991099
}
11001100

11011101
static inline int is_empty_blob_oid(const struct object_id *oid)
@@ -1105,7 +1105,7 @@ static inline int is_empty_blob_oid(const struct object_id *oid)
11051105

11061106
static inline int is_empty_tree_sha1(const unsigned char *sha1)
11071107
{
1108-
return !hashcmp(sha1, the_hash_algo->empty_tree->hash);
1108+
return hasheq(sha1, the_hash_algo->empty_tree->hash);
11091109
}
11101110

11111111
static inline int is_empty_tree_oid(const struct object_id *oid)

contrib/coccinelle/object_id.cocci

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,12 @@ expression E1, E2;
114114
@@
115115
- oidcmp(E1, E2) == 0
116116
+ oideq(E1, E2)
117+
118+
@@
119+
identifier f != hasheq;
120+
expression E1, E2;
121+
@@
122+
f(...) {<...
123+
- hashcmp(E1, E2) == 0
124+
+ hasheq(E1, E2)
125+
...>}

http-walker.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ static int fetch_object(struct walker *walker, unsigned char *sha1)
483483

484484
list_for_each(pos, head) {
485485
obj_req = list_entry(pos, struct object_request, node);
486-
if (!hashcmp(obj_req->oid.hash, sha1))
486+
if (hasheq(obj_req->oid.hash, sha1))
487487
break;
488488
}
489489
if (obj_req == NULL)

notes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ static struct leaf_node *note_tree_find(struct notes_tree *t,
147147
void **p = note_tree_search(t, &tree, &n, key_sha1);
148148
if (GET_PTR_TYPE(*p) == PTR_TYPE_NOTE) {
149149
struct leaf_node *l = (struct leaf_node *) CLR_PTR_TYPE(*p);
150-
if (!hashcmp(key_sha1, l->key_oid.hash))
150+
if (hasheq(key_sha1, l->key_oid.hash))
151151
return l;
152152
}
153153
return NULL;

object.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ struct object *lookup_object(struct repository *r, const unsigned char *sha1)
9595

9696
first = i = hash_obj(sha1, r->parsed_objects->obj_hash_size);
9797
while ((obj = r->parsed_objects->obj_hash[i]) != NULL) {
98-
if (!hashcmp(sha1, obj->oid.hash))
98+
if (hasheq(sha1, obj->oid.hash))
9999
break;
100100
i++;
101101
if (i == r->parsed_objects->obj_hash_size)

pack-objects.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ static uint32_t locate_object_entry_hash(struct packing_data *pdata,
1616
while (pdata->index[i] > 0) {
1717
uint32_t pos = pdata->index[i] - 1;
1818

19-
if (!hashcmp(sha1, pdata->objects[pos].idx.oid.hash)) {
19+
if (hasheq(sha1, pdata->objects[pos].idx.oid.hash)) {
2020
*found = 1;
2121
return i;
2222
}

packfile.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ void mark_bad_packed_object(struct packed_git *p, const unsigned char *sha1)
10151015
{
10161016
unsigned i;
10171017
for (i = 0; i < p->num_bad_objects; i++)
1018-
if (!hashcmp(sha1, p->bad_object_sha1 + GIT_SHA1_RAWSZ * i))
1018+
if (hasheq(sha1, p->bad_object_sha1 + GIT_SHA1_RAWSZ * i))
10191019
return;
10201020
p->bad_object_sha1 = xrealloc(p->bad_object_sha1,
10211021
st_mult(GIT_MAX_RAWSZ,
@@ -1031,8 +1031,8 @@ const struct packed_git *has_packed_and_bad(const unsigned char *sha1)
10311031

10321032
for (p = the_repository->objects->packed_git; p; p = p->next)
10331033
for (i = 0; i < p->num_bad_objects; i++)
1034-
if (!hashcmp(sha1,
1035-
p->bad_object_sha1 + the_hash_algo->rawsz * i))
1034+
if (hasheq(sha1,
1035+
p->bad_object_sha1 + the_hash_algo->rawsz * i))
10361036
return p;
10371037
return NULL;
10381038
}
@@ -1830,8 +1830,8 @@ static int fill_pack_entry(const struct object_id *oid,
18301830
if (p->num_bad_objects) {
18311831
unsigned i;
18321832
for (i = 0; i < p->num_bad_objects; i++)
1833-
if (!hashcmp(oid->hash,
1834-
p->bad_object_sha1 + the_hash_algo->rawsz * i))
1833+
if (hasheq(oid->hash,
1834+
p->bad_object_sha1 + the_hash_algo->rawsz * i))
18351835
return 0;
18361836
}
18371837

0 commit comments

Comments
 (0)