Convert sha1_array_lookup to take struct object_id

Convert this function by changing the declaration and definition and applying the following semantic patch to update the callers: @@ expression E1, E2; @@ - sha1_array_lookup(E1, E2.hash) + sha1_array_lookup(E1, &E2) @@ expression E1, E2; @@ - sha1_array_lookup(E1, E2->hash) + sha1_array_lookup(E1, E2) Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Mar 31, 2017 at 01:39 UTC 5d3206d5010423b3bbf479e32567d0fddc7095e0
7 files changed +11 -12
bisect.c
+3 -4
@@ -499,8 +499,7 @@ struct commit_list *filter_skipped(struct commit_list *list,
499 while (list) {
500 struct commit_list *next = list->next;
501 list->next = NULL;
502 - if (0 <= sha1_array_lookup(&skipped_revs,
503 - list->item->object.oid.hash)) {
502 + if (0 <= sha1_array_lookup(&skipped_revs, &list->item->object.oid)) {
503 if (skipped_first && !*skipped_first)
504 *skipped_first = 1;
505 /* Move current to tried list */
@@ -790,9 +789,9 @@ static void check_merge_bases(int no_checkout)
789 const struct object_id *mb = &result->item->object.oid;
790 if (!oidcmp(mb, current_bad_oid)) {
791 handle_bad_merge_base();
793 - } else if (0 <= sha1_array_lookup(&good_revs, mb->hash)) {
792 + } else if (0 <= sha1_array_lookup(&good_revs, mb)) {
793 continue;
795 - } else if (0 <= sha1_array_lookup(&skipped_revs, mb->hash)) {
794 + } else if (0 <= sha1_array_lookup(&skipped_revs, mb)) {
795 handle_skipped_merge_base(mb);
796 } else {
797 printf(_("Bisecting: a merge base must be tested\n"));
builtin/pack-objects.c
+1 -1
@@ -2677,7 +2677,7 @@ static int loosened_object_can_be_discarded(const struct object_id *oid,
2677 return 0;
2678 if (mtime > unpack_unreachable_expiration)
2679 return 0;
2680 - if (sha1_array_lookup(&recent_objects, oid->hash) >= 0)
2680 + if (sha1_array_lookup(&recent_objects, oid) >= 0)
2681 return 0;
2682 return 1;
2683 }
fsck.c
+1 -1
@@ -280,7 +280,7 @@ static int report(struct fsck_options *options, struct object *object,
280 return 0;
281
282 if (options->skiplist && object &&
283 - sha1_array_lookup(options->skiplist, object->oid.hash) >= 0)
283 + sha1_array_lookup(options->skiplist, &object->oid) >= 0)
284 return 0;
285
286 if (msg_type == FSCK_FATAL)
ref-filter.c
+2 -2
@@ -1684,14 +1684,14 @@ static const struct object_id *match_points_at(struct sha1_array *points_at,
1684 const struct object_id *tagged_oid = NULL;
1685 struct object *obj;
1686
1687 - if (sha1_array_lookup(points_at, oid->hash) >= 0)
1687 + if (sha1_array_lookup(points_at, oid) >= 0)
1688 return oid;
1689 obj = parse_object(oid->hash);
1690 if (!obj)
1691 die(_("malformed object at '%s'"), refname);
1692 if (obj->type == OBJ_TAG)
1693 tagged_oid = &((struct tag *)obj)->tagged->oid;
1694 - if (tagged_oid && sha1_array_lookup(points_at, tagged_oid->hash) >= 0)
1694 + if (tagged_oid && sha1_array_lookup(points_at, tagged_oid) >= 0)
1695 return tagged_oid;
1696 return NULL;
1697 }
sha1-array.c
+2 -2
@@ -26,11 +26,11 @@ static const unsigned char *sha1_access(size_t index, void *table)
26 return array[index].hash;
27 }
28
29 -int sha1_array_lookup(struct sha1_array *array, const unsigned char *sha1)
29 +int sha1_array_lookup(struct sha1_array *array, const struct object_id *oid)
30 {
31 if (!array->sorted)
32 sha1_array_sort(array);
33 - return sha1_pos(sha1, array->oid, array->nr, sha1_access);
33 + return sha1_pos(oid->hash, array->oid, array->nr, sha1_access);
34 }
35
36 void sha1_array_clear(struct sha1_array *array)
sha1-array.h
+1 -1
@@ -11,7 +11,7 @@ struct sha1_array {
11 #define SHA1_ARRAY_INIT { NULL, 0, 0, 0 }
12
13 void sha1_array_append(struct sha1_array *array, const struct object_id *oid);
14 -int sha1_array_lookup(struct sha1_array *array, const unsigned char *sha1);
14 +int sha1_array_lookup(struct sha1_array *array, const struct object_id *oid);
15 void sha1_array_clear(struct sha1_array *array);
16
17 typedef int (*for_each_sha1_fn)(const unsigned char sha1[20],
t/helper/test-sha1-array.c
+1 -1
@@ -23,7 +23,7 @@ int cmd_main(int argc, const char **argv)
23 } else if (skip_prefix(line.buf, "lookup ", &arg)) {
24 if (get_oid_hex(arg, &oid))
25 die("not a hexadecimal SHA1: %s", arg);
26 - printf("%d\n", sha1_array_lookup(&array, oid.hash));
26 + printf("%d\n", sha1_array_lookup(&array, &oid));
27 } else if (!strcmp(line.buf, "clear"))
28 sha1_array_clear(&array);
29 else if (!strcmp(line.buf, "for_each_unique"))