Skip to content

Commit 5d3206d

Browse files
bk2204gitster
authored andcommitted
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>
1 parent 4ce3621 commit 5d3206d

File tree

7 files changed

+11
-12
lines changed

7 files changed

+11
-12
lines changed

bisect.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,7 @@ struct commit_list *filter_skipped(struct commit_list *list,
499499
while (list) {
500500
struct commit_list *next = list->next;
501501
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)) {
504503
if (skipped_first && !*skipped_first)
505504
*skipped_first = 1;
506505
/* Move current to tried list */
@@ -790,9 +789,9 @@ static void check_merge_bases(int no_checkout)
790789
const struct object_id *mb = &result->item->object.oid;
791790
if (!oidcmp(mb, current_bad_oid)) {
792791
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)) {
794793
continue;
795-
} else if (0 <= sha1_array_lookup(&skipped_revs, mb->hash)) {
794+
} else if (0 <= sha1_array_lookup(&skipped_revs, mb)) {
796795
handle_skipped_merge_base(mb);
797796
} else {
798797
printf(_("Bisecting: a merge base must be tested\n"));

builtin/pack-objects.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2677,7 +2677,7 @@ static int loosened_object_can_be_discarded(const struct object_id *oid,
26772677
return 0;
26782678
if (mtime > unpack_unreachable_expiration)
26792679
return 0;
2680-
if (sha1_array_lookup(&recent_objects, oid->hash) >= 0)
2680+
if (sha1_array_lookup(&recent_objects, oid) >= 0)
26812681
return 0;
26822682
return 1;
26832683
}

fsck.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ static int report(struct fsck_options *options, struct object *object,
280280
return 0;
281281

282282
if (options->skiplist && object &&
283-
sha1_array_lookup(options->skiplist, object->oid.hash) >= 0)
283+
sha1_array_lookup(options->skiplist, &object->oid) >= 0)
284284
return 0;
285285

286286
if (msg_type == FSCK_FATAL)

ref-filter.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,14 +1684,14 @@ static const struct object_id *match_points_at(struct sha1_array *points_at,
16841684
const struct object_id *tagged_oid = NULL;
16851685
struct object *obj;
16861686

1687-
if (sha1_array_lookup(points_at, oid->hash) >= 0)
1687+
if (sha1_array_lookup(points_at, oid) >= 0)
16881688
return oid;
16891689
obj = parse_object(oid->hash);
16901690
if (!obj)
16911691
die(_("malformed object at '%s'"), refname);
16921692
if (obj->type == OBJ_TAG)
16931693
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)
16951695
return tagged_oid;
16961696
return NULL;
16971697
}

sha1-array.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ static const unsigned char *sha1_access(size_t index, void *table)
2626
return array[index].hash;
2727
}
2828

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)
3030
{
3131
if (!array->sorted)
3232
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);
3434
}
3535

3636
void sha1_array_clear(struct sha1_array *array)

sha1-array.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ struct sha1_array {
1111
#define SHA1_ARRAY_INIT { NULL, 0, 0, 0 }
1212

1313
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);
1515
void sha1_array_clear(struct sha1_array *array);
1616

1717
typedef int (*for_each_sha1_fn)(const unsigned char sha1[20],

t/helper/test-sha1-array.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ int cmd_main(int argc, const char **argv)
2323
} else if (skip_prefix(line.buf, "lookup ", &arg)) {
2424
if (get_oid_hex(arg, &oid))
2525
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));
2727
} else if (!strcmp(line.buf, "clear"))
2828
sha1_array_clear(&array);
2929
else if (!strcmp(line.buf, "for_each_unique"))

0 commit comments

Comments
 (0)