@matheusbsbs / matheus-bagliano / commits / d1f128b050
Fork 0

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>

Linus Torvalds committed Mar 6, 2008 at 12:46 UTC d1f128b0509dce8b492c233b36131f096fd71274
4 files changed +16 -16
cache.h
+5 -5
@@ -346,12 +346,12 @@ extern void verify_non_filename(const char *prefix, const char *name);
346 /* Initialize and use the cache information */
347 extern int read_index(struct index_state *);
348 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);
350 extern int discard_index(struct index_state *);
351 -extern int unmerged_index(struct index_state *);
351 +extern int unmerged_index(const struct index_state *);
352 extern int verify_path(const char *path);
353 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);
355 #define ADD_CACHE_OK_TO_ADD 1 /* Ok to add */
356 #define ADD_CACHE_OK_TO_REPLACE 2 /* Ok to replace file/directory */
357 #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);
368 #define CE_MATCH_IGNORE_VALID 01
369 /* do not check the contents but report dirty on racily-clean entries */
370 #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);
373
374 extern int ce_path_match(const struct cache_entry *ce, const char **pathspec);
375 extern int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, enum object_type type, const char *path);
hash.c
+3 -3
@@ -9,7 +9,7 @@
9 * the existing entry, or the empty slot if none existed. The caller
10 * can then look at the (*ptr) to see whether it existed or not.
11 */
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)
13 {
14 unsigned int size = table->size, nr = hash % size;
15 struct hash_table_entry *array = table->array;
@@ -66,7 +66,7 @@ static void grow_hash_table(struct hash_table *table)
66 free(old_array);
67 }
68
69 -void *lookup_hash(unsigned int hash, struct hash_table *table)
69 +void *lookup_hash(unsigned int hash, const struct hash_table *table)
70 {
71 if (!table->array)
72 return NULL;
@@ -81,7 +81,7 @@ void **insert_hash(unsigned int hash, void *ptr, struct hash_table *table)
81 return insert_hash_entry(hash, ptr, table);
82 }
83
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 *))
85 {
86 int sum = 0;
87 unsigned int i;
hash.h
+2 -2
@@ -28,9 +28,9 @@ struct hash_table {
28 struct hash_table_entry *array;
29 };
30
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);
32 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 *));
34 extern void free_hash(struct hash_table *table);
35
36 static inline void init_hash(struct hash_table *table)
read-cache.c
+6 -6
@@ -255,13 +255,13 @@ static int ce_match_stat_basic(struct cache_entry *ce, struct stat *st)
255 return changed;
256 }
257
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)
259 {
260 return (istate->timestamp &&
261 ((unsigned int)istate->timestamp) <= ce->ce_mtime);
262 }
263
264 -int ie_match_stat(struct index_state *istate,
264 +int ie_match_stat(const struct index_state *istate,
265 struct cache_entry *ce, struct stat *st,
266 unsigned int options)
267 {
@@ -304,7 +304,7 @@ int ie_match_stat(struct index_state *istate,
304 return changed;
305 }
306
307 -int ie_modified(struct index_state *istate,
307 +int ie_modified(const struct index_state *istate,
308 struct cache_entry *ce, struct stat *st, unsigned int options)
309 {
310 int changed, changed_fs;
@@ -412,7 +412,7 @@ int cache_name_compare(const char *name1, int flags1, const char *name2, int fla
412 return 0;
413 }
414
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)
416 {
417 int first, last;
418
@@ -1201,7 +1201,7 @@ int discard_index(struct index_state *istate)
1201 return 0;
1202 }
1203
1204 -int unmerged_index(struct index_state *istate)
1204 +int unmerged_index(const struct index_state *istate)
1205 {
1206 int i;
1207 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)
1346 return ce_write(c, fd, ondisk, size);
1347 }
1348
1349 -int write_index(struct index_state *istate, int newfd)
1349 +int write_index(const struct index_state *istate, int newfd)
1350 {
1351 SHA_CTX c;
1352 struct cache_header hdr;