Skip to content

Commit d1f128b

Browse files
torvaldsgitster
authored andcommitted
Add 'const' where appropriate to index handling functions
This is in an effort to make the source index of 'unpack_trees()' as being const, and thus making the compiler help us verify that we only access it for reading. The constification also extended to some of the hashing helpers that get called indirectly. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent bcbe5a5 commit d1f128b

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

cache.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,12 +346,12 @@ extern void verify_non_filename(const char *prefix, const char *name);
346346
/* Initialize and use the cache information */
347347
extern int read_index(struct index_state *);
348348
extern int read_index_from(struct index_state *, const char *path);
349-
extern int write_index(struct index_state *, int newfd);
349+
extern int write_index(const struct index_state *, int newfd);
350350
extern int discard_index(struct index_state *);
351-
extern int unmerged_index(struct index_state *);
351+
extern int unmerged_index(const struct index_state *);
352352
extern int verify_path(const char *path);
353353
extern int index_name_exists(struct index_state *istate, const char *name, int namelen);
354-
extern int index_name_pos(struct index_state *, const char *name, int namelen);
354+
extern int index_name_pos(const struct index_state *, const char *name, int namelen);
355355
#define ADD_CACHE_OK_TO_ADD 1 /* Ok to add */
356356
#define ADD_CACHE_OK_TO_REPLACE 2 /* Ok to replace file/directory */
357357
#define ADD_CACHE_SKIP_DFCHECK 4 /* Ok to skip DF conflict checks */
@@ -368,8 +368,8 @@ extern int ce_same_name(struct cache_entry *a, struct cache_entry *b);
368368
#define CE_MATCH_IGNORE_VALID 01
369369
/* do not check the contents but report dirty on racily-clean entries */
370370
#define CE_MATCH_RACY_IS_DIRTY 02
371-
extern int ie_match_stat(struct index_state *, struct cache_entry *, struct stat *, unsigned int);
372-
extern int ie_modified(struct index_state *, struct cache_entry *, struct stat *, unsigned int);
371+
extern int ie_match_stat(const struct index_state *, struct cache_entry *, struct stat *, unsigned int);
372+
extern int ie_modified(const struct index_state *, struct cache_entry *, struct stat *, unsigned int);
373373

374374
extern int ce_path_match(const struct cache_entry *ce, const char **pathspec);
375375
extern int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, enum object_type type, const char *path);

hash.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* the existing entry, or the empty slot if none existed. The caller
1010
* can then look at the (*ptr) to see whether it existed or not.
1111
*/
12-
static struct hash_table_entry *lookup_hash_entry(unsigned int hash, struct hash_table *table)
12+
static struct hash_table_entry *lookup_hash_entry(unsigned int hash, const struct hash_table *table)
1313
{
1414
unsigned int size = table->size, nr = hash % size;
1515
struct hash_table_entry *array = table->array;
@@ -66,7 +66,7 @@ static void grow_hash_table(struct hash_table *table)
6666
free(old_array);
6767
}
6868

69-
void *lookup_hash(unsigned int hash, struct hash_table *table)
69+
void *lookup_hash(unsigned int hash, const struct hash_table *table)
7070
{
7171
if (!table->array)
7272
return NULL;
@@ -81,7 +81,7 @@ void **insert_hash(unsigned int hash, void *ptr, struct hash_table *table)
8181
return insert_hash_entry(hash, ptr, table);
8282
}
8383

84-
int for_each_hash(struct hash_table *table, int (*fn)(void *))
84+
int for_each_hash(const struct hash_table *table, int (*fn)(void *))
8585
{
8686
int sum = 0;
8787
unsigned int i;

hash.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ struct hash_table {
2828
struct hash_table_entry *array;
2929
};
3030

31-
extern void *lookup_hash(unsigned int hash, struct hash_table *table);
31+
extern void *lookup_hash(unsigned int hash, const struct hash_table *table);
3232
extern void **insert_hash(unsigned int hash, void *ptr, struct hash_table *table);
33-
extern int for_each_hash(struct hash_table *table, int (*fn)(void *));
33+
extern int for_each_hash(const struct hash_table *table, int (*fn)(void *));
3434
extern void free_hash(struct hash_table *table);
3535

3636
static inline void init_hash(struct hash_table *table)

read-cache.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,13 @@ static int ce_match_stat_basic(struct cache_entry *ce, struct stat *st)
255255
return changed;
256256
}
257257

258-
static int is_racy_timestamp(struct index_state *istate, struct cache_entry *ce)
258+
static int is_racy_timestamp(const struct index_state *istate, struct cache_entry *ce)
259259
{
260260
return (istate->timestamp &&
261261
((unsigned int)istate->timestamp) <= ce->ce_mtime);
262262
}
263263

264-
int ie_match_stat(struct index_state *istate,
264+
int ie_match_stat(const struct index_state *istate,
265265
struct cache_entry *ce, struct stat *st,
266266
unsigned int options)
267267
{
@@ -304,7 +304,7 @@ int ie_match_stat(struct index_state *istate,
304304
return changed;
305305
}
306306

307-
int ie_modified(struct index_state *istate,
307+
int ie_modified(const struct index_state *istate,
308308
struct cache_entry *ce, struct stat *st, unsigned int options)
309309
{
310310
int changed, changed_fs;
@@ -412,7 +412,7 @@ int cache_name_compare(const char *name1, int flags1, const char *name2, int fla
412412
return 0;
413413
}
414414

415-
int index_name_pos(struct index_state *istate, const char *name, int namelen)
415+
int index_name_pos(const struct index_state *istate, const char *name, int namelen)
416416
{
417417
int first, last;
418418

@@ -1201,7 +1201,7 @@ int discard_index(struct index_state *istate)
12011201
return 0;
12021202
}
12031203

1204-
int unmerged_index(struct index_state *istate)
1204+
int unmerged_index(const struct index_state *istate)
12051205
{
12061206
int i;
12071207
for (i = 0; i < istate->cache_nr; i++) {
@@ -1346,7 +1346,7 @@ static int ce_write_entry(SHA_CTX *c, int fd, struct cache_entry *ce)
13461346
return ce_write(c, fd, ondisk, size);
13471347
}
13481348

1349-
int write_index(struct index_state *istate, int newfd)
1349+
int write_index(const struct index_state *istate, int newfd)
13501350
{
13511351
SHA_CTX c;
13521352
struct cache_header hdr;

0 commit comments

Comments
 (0)