Git fork

oid_pos(): access table through const pointers

When we are looking up an oid in an array, we obviously don't need to
write to the array. Let's mark it as const in the function interfaces,
as well as in the local variables we use to derference the void pointer
(note a few cases use pointers-to-pointers, so we mark everything
const).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Jeff King and committed by
Junio C Hamano
8380dcd7 45ee13b9

+13 -13
+2 -2
builtin/name-rev.c
··· 390 390 } 391 391 } 392 392 393 - static const struct object_id *nth_tip_table_ent(size_t ix, void *table_) 393 + static const struct object_id *nth_tip_table_ent(size_t ix, const void *table_) 394 394 { 395 - struct tip_table_entry *table = table_; 395 + const struct tip_table_entry *table = table_; 396 396 return &table[ix].oid; 397 397 } 398 398
+2 -2
commit-graph.c
··· 1012 1012 return 0; 1013 1013 } 1014 1014 1015 - static const struct object_id *commit_to_oid(size_t index, void *table) 1015 + static const struct object_id *commit_to_oid(size_t index, const void *table) 1016 1016 { 1017 - struct commit **commits = table; 1017 + const struct commit * const *commits = table; 1018 1018 return &commits[index]->object.oid; 1019 1019 } 1020 1020
+2 -2
commit.c
··· 105 105 return parse_timestamp(dateptr, NULL, 10); 106 106 } 107 107 108 - static const struct object_id *commit_graft_oid_access(size_t index, void *table) 108 + static const struct object_id *commit_graft_oid_access(size_t index, const void *table) 109 109 { 110 - struct commit_graft **commit_graft_table = table; 110 + const struct commit_graft * const *commit_graft_table = table; 111 111 return &commit_graft_table[index]->oid; 112 112 } 113 113
+1 -1
hash-lookup.c
··· 50 50 * The oid of element i (between 0 and nr - 1) should be returned 51 51 * by "fn(i, table)". 52 52 */ 53 - int oid_pos(const struct object_id *oid, void *table, size_t nr, 53 + int oid_pos(const struct object_id *oid, const void *table, size_t nr, 54 54 oid_access_fn fn) 55 55 { 56 56 size_t hi = nr;
+2 -2
hash-lookup.h
··· 1 1 #ifndef HASH_LOOKUP_H 2 2 #define HASH_LOOKUP_H 3 3 4 - typedef const struct object_id *oid_access_fn(size_t index, void *table); 4 + typedef const struct object_id *oid_access_fn(size_t index, const void *table); 5 5 6 6 int oid_pos(const struct object_id *oid, 7 - void *table, 7 + const void *table, 8 8 size_t nr, 9 9 oid_access_fn fn); 10 10
+2 -2
oid-array.c
··· 22 22 array->sorted = 1; 23 23 } 24 24 25 - static const struct object_id *oid_access(size_t index, void *table) 25 + static const struct object_id *oid_access(size_t index, const void *table) 26 26 { 27 - struct object_id *array = table; 27 + const struct object_id *array = table; 28 28 return &array[index]; 29 29 } 30 30
+2 -2
pack-bitmap-write.c
··· 610 610 die("Failed to write bitmap index"); 611 611 } 612 612 613 - static const struct object_id *oid_access(size_t pos, void *table) 613 + static const struct object_id *oid_access(size_t pos, const void *table) 614 614 { 615 - struct pack_idx_entry **index = table; 615 + const struct pack_idx_entry * const *index = table; 616 616 return &index[pos]->oid; 617 617 } 618 618