Convert "struct cache_entry *" to "const ..." wherever possible

I attempted to make index_state->cache[] a "const struct cache_entry **" to find out how existing entries in index are modified and where. The question I have is what do we do if we really need to keep track of on-disk changes in the index. The result is - diff-lib.c: setting CE_UPTODATE - name-hash.c: setting CE_HASHED - preload-index.c, read-cache.c, unpack-trees.c and builtin/update-index: obvious - entry.c: write_entry() may refresh the checked out entry via fill_stat_cache_info(). This causes "non-const struct cache_entry *" in builtin/apply.c, builtin/checkout-index.c and builtin/checkout.c - builtin/ls-files.c: --with-tree changes stagemask and may set CE_UPDATE Of these, write_entry() and its call sites are probably most interesting because it modifies on-disk info. But this is stat info and can be retrieved via refresh, at least for porcelain commands. Other just uses ce_flags for local purposes. So, keeping track of "dirty" entries is just a matter of setting a flag in index modification functions exposed by read-cache.c. Except unpack-trees, the rest of the code base does not do anything funny behind read-cache's back. The actual patch is less valueable than the summary above. But if anyone wants to re-identify the above sites. Applying this patch, then this: diff --git a/cache.h b/cache.h index 430d021..1692891 100644 --- a/cache.h +++ b/cache.h @@ -267,7 +267,7 @@ static inline unsigned int canon_mode(unsigned int mode) #define cache_entry_size(len) (offsetof(struct cache_entry,name) + (len) + 1) struct index_state { - struct cache_entry **cache; + const struct cache_entry **cache; unsigned int version; unsigned int cache_nr, cache_alloc, cache_changed; struct string_list *resolve_undo; will help quickly identify them without bogus warnings. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Jul 9, 2013 at 22:29 UTC 9c5e6c802cde9881785b7f1b3278b97be4aabd82
29 files changed +93 -85
builtin/apply.c
+7 -6
@@ -2999,7 +2999,7 @@ static int read_blob_object(struct strbuf *buf, const unsigned char *sha1, unsig
2999 return 0;
3000 }
3001
3002 -static int read_file_or_gitlink(struct cache_entry *ce, struct strbuf *buf)
3002 +static int read_file_or_gitlink(const struct cache_entry *ce, struct strbuf *buf)
3003 {
3004 if (!ce)
3005 return 0;
@@ -3117,7 +3117,7 @@ static struct patch *previous_patch(struct patch *patch, int *gone)
3117 return previous;
3118 }
3119
3120 -static int verify_index_match(struct cache_entry *ce, struct stat *st)
3120 +static int verify_index_match(const struct cache_entry *ce, struct stat *st)
3121 {
3122 if (S_ISGITLINK(ce->ce_mode)) {
3123 if (!S_ISDIR(st->st_mode))
@@ -3130,7 +3130,7 @@ static int verify_index_match(struct cache_entry *ce, struct stat *st)
3130 #define SUBMODULE_PATCH_WITHOUT_INDEX 1
3131
3132 static int load_patch_target(struct strbuf *buf,
3133 - struct cache_entry *ce,
3133 + const struct cache_entry *ce,
3134 struct stat *st,
3135 const char *name,
3136 unsigned expected_mode)
@@ -3160,7 +3160,8 @@ static int load_patch_target(struct strbuf *buf,
3160 * we read from the result of a previous diff.
3161 */
3162 static int load_preimage(struct image *image,
3163 - struct patch *patch, struct stat *st, struct cache_entry *ce)
3163 + struct patch *patch, struct stat *st,
3164 + const struct cache_entry *ce)
3165 {
3166 struct strbuf buf = STRBUF_INIT;
3167 size_t len;
@@ -3273,7 +3274,7 @@ static int load_current(struct image *image, struct patch *patch)
3274 }
3275
3276 static int try_threeway(struct image *image, struct patch *patch,
3276 - struct stat *st, struct cache_entry *ce)
3277 + struct stat *st, const struct cache_entry *ce)
3278 {
3279 unsigned char pre_sha1[20], post_sha1[20], our_sha1[20];
3280 struct strbuf buf = STRBUF_INIT;
@@ -3343,7 +3344,7 @@ static int try_threeway(struct image *image, struct patch *patch,
3344 return 0;
3345 }
3346
3346 -static int apply_data(struct patch *patch, struct stat *st, struct cache_entry *ce)
3347 +static int apply_data(struct patch *patch, struct stat *st, const struct cache_entry *ce)
3348 {
3349 struct image image;
3350
builtin/checkout.c
+4 -4
@@ -97,7 +97,7 @@ static int read_tree_some(struct tree *tree, const char **pathspec)
97 return 0;
98 }
99
100 -static int skip_same_name(struct cache_entry *ce, int pos)
100 +static int skip_same_name(const struct cache_entry *ce, int pos)
101 {
102 while (++pos < active_nr &&
103 !strcmp(active_cache[pos]->name, ce->name))
@@ -105,7 +105,7 @@ static int skip_same_name(struct cache_entry *ce, int pos)
105 return pos;
106 }
107
108 -static int check_stage(int stage, struct cache_entry *ce, int pos)
108 +static int check_stage(int stage, const struct cache_entry *ce, int pos)
109 {
110 while (pos < active_nr &&
111 !strcmp(active_cache[pos]->name, ce->name)) {
@@ -119,7 +119,7 @@ static int check_stage(int stage, struct cache_entry *ce, int pos)
119 return error(_("path '%s' does not have their version"), ce->name);
120 }
121
122 -static int check_stages(unsigned stages, struct cache_entry *ce, int pos)
122 +static int check_stages(unsigned stages, const struct cache_entry *ce, int pos)
123 {
124 unsigned seen = 0;
125 const char *name = ce->name;
@@ -321,7 +321,7 @@ static int checkout_paths(const struct checkout_opts *opts,
321
322 /* Any unmerged paths? */
323 for (pos = 0; pos < active_nr; pos++) {
324 - struct cache_entry *ce = active_cache[pos];
324 + const struct cache_entry *ce = active_cache[pos];
325 if (ce->ce_flags & CE_MATCHED) {
326 if (!ce_stage(ce))
327 continue;
builtin/clean.c
+1 -1
@@ -221,7 +221,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
221 struct dir_entry *ent = dir.entries[i];
222 int len, pos;
223 int matches = 0;
224 - struct cache_entry *ce;
224 + const struct cache_entry *ce;
225 struct stat st;
226
227 /*
builtin/commit.c
+1 -1
@@ -205,7 +205,7 @@ static int list_paths(struct string_list *list, const char *with_tree,
205 }
206
207 for (i = 0; i < active_nr; i++) {
208 - struct cache_entry *ce = active_cache[i];
208 + const struct cache_entry *ce = active_cache[i];
209 struct string_list_item *item;
210
211 if (ce->ce_flags & CE_UPDATE)
builtin/grep.c
+1 -1
@@ -376,7 +376,7 @@ static int grep_cache(struct grep_opt *opt, const struct pathspec *pathspec, int
376 read_cache();
377
378 for (nr = 0; nr < active_nr; nr++) {
379 - struct cache_entry *ce = active_cache[nr];
379 + const struct cache_entry *ce = active_cache[nr];
380 if (!S_ISREG(ce->ce_mode))
381 continue;
382 if (!match_pathspec_depth(pathspec, ce->name, ce_namelen(ce), 0, NULL))
builtin/ls-files.c
+6 -6
@@ -127,7 +127,7 @@ static void show_killed_files(struct dir_struct *dir)
127 }
128 }
129
130 -static void show_ce_entry(const char *tag, struct cache_entry *ce)
130 +static void show_ce_entry(const char *tag, const struct cache_entry *ce)
131 {
132 int len = max_prefix_len;
133
@@ -165,7 +165,7 @@ static void show_ce_entry(const char *tag, struct cache_entry *ce)
165 }
166 write_name(ce->name, ce_namelen(ce));
167 if (debug_mode) {
168 - struct stat_data *sd = &ce->ce_stat_data;
168 + const struct stat_data *sd = &ce->ce_stat_data;
169
170 printf(" ctime: %d:%d\n", sd->sd_ctime.sec, sd->sd_ctime.nsec);
171 printf(" mtime: %d:%d\n", sd->sd_mtime.sec, sd->sd_mtime.nsec);
@@ -203,7 +203,7 @@ static void show_ru_info(void)
203 }
204 }
205
206 -static int ce_excluded(struct dir_struct *dir, struct cache_entry *ce)
206 +static int ce_excluded(struct dir_struct *dir, const struct cache_entry *ce)
207 {
208 int dtype = ce_to_dtype(ce);
209 return is_excluded(dir, ce->name, &dtype);
@@ -223,7 +223,7 @@ static void show_files(struct dir_struct *dir)
223 }
224 if (show_cached || show_stage) {
225 for (i = 0; i < active_nr; i++) {
226 - struct cache_entry *ce = active_cache[i];
226 + const struct cache_entry *ce = active_cache[i];
227 if ((dir->flags & DIR_SHOW_IGNORED) &&
228 !ce_excluded(dir, ce))
229 continue;
@@ -237,7 +237,7 @@ static void show_files(struct dir_struct *dir)
237 }
238 if (show_deleted || show_modified) {
239 for (i = 0; i < active_nr; i++) {
240 - struct cache_entry *ce = active_cache[i];
240 + const struct cache_entry *ce = active_cache[i];
241 struct stat st;
242 int err;
243 if ((dir->flags & DIR_SHOW_IGNORED) &&
@@ -273,7 +273,7 @@ static void prune_cache(const char *prefix)
273 last = active_nr;
274 while (last > first) {
275 int next = (last + first) >> 1;
276 - struct cache_entry *ce = active_cache[next];
276 + const struct cache_entry *ce = active_cache[next];
277 if (!strncmp(ce->name, prefix, max_prefix_len)) {
278 first = next+1;
279 continue;
builtin/merge-index.c
+2 -2
@@ -16,7 +16,7 @@ static int merge_entry(int pos, const char *path)
16 die("git merge-index: %s not in the cache", path);
17 found = 0;
18 do {
19 - struct cache_entry *ce = active_cache[pos];
19 + const struct cache_entry *ce = active_cache[pos];
20 int stage = ce_stage(ce);
21
22 if (strcmp(ce->name, path))
@@ -58,7 +58,7 @@ static void merge_all(void)
58 {
59 int i;
60 for (i = 0; i < active_nr; i++) {
61 - struct cache_entry *ce = active_cache[i];
61 + const struct cache_entry *ce = active_cache[i];
62 if (!ce_stage(ce))
63 continue;
64 i += merge_entry(i, ce->name)-1;
builtin/merge.c
+1 -1
@@ -889,7 +889,7 @@ static int suggest_conflicts(int renormalizing)
889 die_errno(_("Could not open '%s' for writing"), filename);
890 fprintf(fp, "\nConflicts:\n");
891 for (pos = 0; pos < active_nr; pos++) {
892 - struct cache_entry *ce = active_cache[pos];
892 + const struct cache_entry *ce = active_cache[pos];
893
894 if (ce_stage(ce)) {
895 fprintf(fp, "\t%s\n", ce->name);
builtin/rm.c
+3 -3
@@ -67,7 +67,7 @@ static int check_submodules_use_gitfiles(void)
67 for (i = 0; i < list.nr; i++) {
68 const char *name = list.entry[i].name;
69 int pos;
70 - struct cache_entry *ce;
70 + const struct cache_entry *ce;
71 struct stat st;
72
73 pos = cache_name_pos(name, strlen(name));
@@ -120,7 +120,7 @@ static int check_local_mod(unsigned char *head, int index_only)
120 for (i = 0; i < list.nr; i++) {
121 struct stat st;
122 int pos;
123 - struct cache_entry *ce;
123 + const struct cache_entry *ce;
124 const char *name = list.entry[i].name;
125 unsigned char sha1[20];
126 unsigned mode;
@@ -321,7 +321,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
321 seen = xcalloc(i, 1);
322
323 for (i = 0; i < active_nr; i++) {
324 - struct cache_entry *ce = active_cache[i];
324 + const struct cache_entry *ce = active_cache[i];
325 if (!match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, seen))
326 continue;
327 ALLOC_GROW(list.entry, list.nr + 1, list.alloc);
builtin/update-index.c
+7 -7
@@ -83,7 +83,7 @@ static int process_lstat_error(const char *path, int err)
83 return error("lstat(\"%s\"): %s", path, strerror(errno));
84 }
85
86 -static int add_one_path(struct cache_entry *old, const char *path, int len, struct stat *st)
86 +static int add_one_path(const struct cache_entry *old, const char *path, int len, struct stat *st)
87 {
88 int option, size;
89 struct cache_entry *ce;
@@ -142,7 +142,7 @@ static int process_directory(const char *path, int len, struct stat *st)
142
143 /* Exact match: file or existing gitlink */
144 if (pos >= 0) {
145 - struct cache_entry *ce = active_cache[pos];
145 + const struct cache_entry *ce = active_cache[pos];
146 if (S_ISGITLINK(ce->ce_mode)) {
147
148 /* Do nothing to the index if there is no HEAD! */
@@ -158,7 +158,7 @@ static int process_directory(const char *path, int len, struct stat *st)
158 /* Inexact match: is there perhaps a subdirectory match? */
159 pos = -pos-1;
160 while (pos < active_nr) {
161 - struct cache_entry *ce = active_cache[pos++];
161 + const struct cache_entry *ce = active_cache[pos++];
162
163 if (strncmp(ce->name, path, len))
164 break;
@@ -183,7 +183,7 @@ static int process_path(const char *path)
183 {
184 int pos, len;
185 struct stat st;
186 - struct cache_entry *ce;
186 + const struct cache_entry *ce;
187
188 len = strlen(path);
189 if (has_symlink_leading_path(path, len))
@@ -448,7 +448,7 @@ static int unresolve_one(const char *path)
448 /* already merged */
449 pos = unmerge_cache_entry_at(pos);
450 if (pos < active_nr) {
451 - struct cache_entry *ce = active_cache[pos];
451 + const struct cache_entry *ce = active_cache[pos];
452 if (ce_stage(ce) &&
453 ce_namelen(ce) == namelen &&
454 !memcmp(ce->name, path, namelen))
@@ -462,7 +462,7 @@ static int unresolve_one(const char *path)
462 */
463 pos = -pos-1;
464 if (pos < active_nr) {
465 - struct cache_entry *ce = active_cache[pos];
465 + const struct cache_entry *ce = active_cache[pos];
466 if (ce_namelen(ce) == namelen &&
467 !memcmp(ce->name, path, namelen)) {
468 fprintf(stderr,
@@ -558,7 +558,7 @@ static int do_reupdate(int ac, const char **av,
558 has_head = 0;
559 redo:
560 for (pos = 0; pos < active_nr; pos++) {
561 - struct cache_entry *ce = active_cache[pos];
561 + const struct cache_entry *ce = active_cache[pos];
562 struct cache_entry *old = NULL;
563 int save_nr;
564
cache-tree.c
+10 -9
@@ -149,7 +149,7 @@ void cache_tree_invalidate_path(struct cache_tree *it, const char *path)
149 cache_tree_invalidate_path(down->cache_tree, slash + 1);
150 }
151
152 -static int verify_cache(struct cache_entry **cache,
152 +static int verify_cache(const struct cache_entry * const *cache,
153 int entries, int flags)
154 {
155 int i, funny;
@@ -158,7 +158,7 @@ static int verify_cache(struct cache_entry **cache,
158 /* Verify that the tree is merged */
159 funny = 0;
160 for (i = 0; i < entries; i++) {
161 - struct cache_entry *ce = cache[i];
161 + const struct cache_entry *ce = cache[i];
162 if (ce_stage(ce)) {
163 if (silent)
164 return -1;
@@ -234,7 +234,7 @@ int cache_tree_fully_valid(struct cache_tree *it)
234 }
235
236 static int update_one(struct cache_tree *it,
237 - struct cache_entry **cache,
237 + const struct cache_entry * const *cache,
238 int entries,
239 const char *base,
240 int baselen,
@@ -265,7 +265,7 @@ static int update_one(struct cache_tree *it,
265 */
266 i = 0;
267 while (i < entries) {
268 - struct cache_entry *ce = cache[i];
268 + const struct cache_entry *ce = cache[i];
269 struct cache_tree_sub *sub;
270 const char *path, *slash;
271 int pathlen, sublen, subcnt, subskip;
@@ -312,7 +312,7 @@ static int update_one(struct cache_tree *it,
312
313 i = 0;
314 while (i < entries) {
315 - struct cache_entry *ce = cache[i];
315 + const struct cache_entry *ce = cache[i];
316 struct cache_tree_sub *sub;
317 const char *path, *slash;
318 int pathlen, entlen;
@@ -397,7 +397,7 @@ static int update_one(struct cache_tree *it,
397 }
398
399 int cache_tree_update(struct cache_tree *it,
400 - struct cache_entry **cache,
400 + const struct cache_entry * const *cache,
401 int entries,
402 int flags)
403 {
@@ -599,8 +599,8 @@ int write_cache_as_tree(unsigned char *sha1, int flags, const char *prefix)
599 was_valid = cache_tree_fully_valid(active_cache_tree);
600 if (!was_valid) {
601 if (cache_tree_update(active_cache_tree,
602 - active_cache, active_nr,
603 - flags) < 0)
602 + (const struct cache_entry * const *)active_cache,
603 + active_nr, flags) < 0)
604 return WRITE_TREE_UNMERGED_INDEX;
605 if (0 <= newfd) {
606 if (!write_cache(newfd, active_cache, active_nr) &&
@@ -701,5 +701,6 @@ int update_main_cache_tree(int flags)
701 if (!the_index.cache_tree)
702 the_index.cache_tree = cache_tree();
703 return cache_tree_update(the_index.cache_tree,
704 - the_index.cache, the_index.cache_nr, flags);
704 + (const struct cache_entry * const *)the_index.cache,
705 + the_index.cache_nr, flags);
706 }
cache-tree.h
+1 -1
@@ -30,7 +30,7 @@ void cache_tree_write(struct strbuf *, struct cache_tree *root);
30 struct cache_tree *cache_tree_read(const char *buffer, unsigned long size);
31
32 int cache_tree_fully_valid(struct cache_tree *);
33 -int cache_tree_update(struct cache_tree *, struct cache_entry **, int, int);
33 +int cache_tree_update(struct cache_tree *, const struct cache_entry * const *, int, int);
34
35 int update_main_cache_tree(int);
36
cache.h
+1 -1
@@ -476,7 +476,7 @@ extern int remove_file_from_index(struct index_state *, const char *path);
476 extern int add_to_index(struct index_state *, const char *path, struct stat *, int flags);
477 extern int add_file_to_index(struct index_state *, const char *path, int flags);
478 extern struct cache_entry *make_cache_entry(unsigned int mode, const unsigned char *sha1, const char *path, int stage, int refresh);
479 -extern int ce_same_name(struct cache_entry *a, struct cache_entry *b);
479 +extern int ce_same_name(const struct cache_entry *a, const struct cache_entry *b);
480 extern int index_name_is_other(const struct index_state *, const char *, int);
481 extern void *read_blob_data_from_index(struct index_state *, const char *, unsigned long *);
482
diff.c
+1 -1
@@ -2586,7 +2586,7 @@ void fill_filespec(struct diff_filespec *spec, const unsigned char *sha1,
2586 */
2587 static int reuse_worktree_file(const char *name, const unsigned char *sha1, int want_file)
2588 {
2589 - struct cache_entry *ce;
2589 + const struct cache_entry *ce;
2590 struct stat st;
2591 int pos, len;
2592
dir.c
+3 -3
@@ -933,7 +933,7 @@ enum exist_status {
933 */
934 static enum exist_status directory_exists_in_index_icase(const char *dirname, int len)
935 {
936 - struct cache_entry *ce = index_name_exists(&the_index, dirname, len + 1, ignore_case);
936 + const struct cache_entry *ce = index_name_exists(&the_index, dirname, len + 1, ignore_case);
937 unsigned char endchar;
938
939 if (!ce)
@@ -977,7 +977,7 @@ static enum exist_status directory_exists_in_index(const char *dirname, int len)
977 if (pos < 0)
978 pos = -pos-1;
979 while (pos < active_nr) {
980 - struct cache_entry *ce = active_cache[pos++];
980 + const struct cache_entry *ce = active_cache[pos++];
981 unsigned char endchar;
982
983 if (strncmp(ce->name, dirname, len))
@@ -1115,7 +1115,7 @@ static int exclude_matches_pathspec(const char *path, int len,
1115 static int get_index_dtype(const char *path, int len)
1116 {
1117 int pos;
1118 - struct cache_entry *ce;
1118 + const struct cache_entry *ce;
1119
1120 ce = cache_name_exists(path, len, 0);
1121 if (ce) {
entry.c
+7 -5
@@ -79,7 +79,7 @@ static int create_file(const char *path, unsigned int mode)
79 return open(path, O_WRONLY | O_CREAT | O_EXCL, mode);
80 }
81
82 -static void *read_blob_entry(struct cache_entry *ce, unsigned long *size)
82 +static void *read_blob_entry(const struct cache_entry *ce, unsigned long *size)
83 {
84 enum object_type type;
85 void *new = read_sha1_file(ce->sha1, &type, size);
@@ -92,7 +92,7 @@ static void *read_blob_entry(struct cache_entry *ce, unsigned long *size)
92 return NULL;
93 }
94
95 -static int open_output_fd(char *path, struct cache_entry *ce, int to_tempfile)
95 +static int open_output_fd(char *path, const struct cache_entry *ce, int to_tempfile)
96 {
97 int symlink = (ce->ce_mode & S_IFMT) != S_IFREG;
98 if (to_tempfile) {
@@ -115,7 +115,7 @@ static int fstat_output(int fd, const struct checkout *state, struct stat *st)
115 return 0;
116 }
117
118 -static int streaming_write_entry(struct cache_entry *ce, char *path,
118 +static int streaming_write_entry(const struct cache_entry *ce, char *path,
119 struct stream_filter *filter,
120 const struct checkout *state, int to_tempfile,
121 int *fstat_done, struct stat *statbuf)
@@ -136,7 +136,8 @@ static int streaming_write_entry(struct cache_entry *ce, char *path,
136 return result;
137 }
138
139 -static int write_entry(struct cache_entry *ce, char *path, const struct checkout *state, int to_tempfile)
139 +static int write_entry(struct cache_entry *ce,
140 + char *path, const struct checkout *state, int to_tempfile)
141 {
142 unsigned int ce_mode_s_ifmt = ce->ce_mode & S_IFMT;
143 int fd, ret, fstat_done = 0;
@@ -233,7 +234,8 @@ static int check_path(const char *path, int len, struct stat *st, int skiplen)
234 return lstat(path, st);
235 }
236
236 -int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath)
237 +int checkout_entry(struct cache_entry *ce,
238 + const struct checkout *state, char *topath)
239 {
240 static char path[PATH_MAX + 1];
241 struct stat st;
merge-recursive.c
+4 -3
@@ -251,7 +251,7 @@ struct tree *write_tree_from_memory(struct merge_options *o)
251 int i;
252 fprintf(stderr, "BUG: There are unmerged index entries:\n");
253 for (i = 0; i < active_nr; i++) {
254 - struct cache_entry *ce = active_cache[i];
254 + const struct cache_entry *ce = active_cache[i];
255 if (ce_stage(ce))
256 fprintf(stderr, "BUG: %d %.*s\n", ce_stage(ce),
257 (int)ce_namelen(ce), ce->name);
@@ -264,7 +264,8 @@ struct tree *write_tree_from_memory(struct merge_options *o)
264
265 if (!cache_tree_fully_valid(active_cache_tree) &&
266 cache_tree_update(active_cache_tree,
267 - active_cache, active_nr, 0) < 0)
267 + (const struct cache_entry * const *)active_cache,
268 + active_nr, 0) < 0)
269 die(_("error building trees"));
270
271 result = lookup_tree(active_cache_tree->sha1);
@@ -339,7 +340,7 @@ static struct string_list *get_unmerged(void)
340 for (i = 0; i < active_nr; i++) {
341 struct string_list_item *item;
342 struct stage_data *e;
342 - struct cache_entry *ce = active_cache[i];
343 + const struct cache_entry *ce = active_cache[i];
344 if (!ce_stage(ce))
345 continue;
346
pathspec.c
+2 -2
@@ -32,7 +32,7 @@ void add_pathspec_matches_against_index(const char **pathspec,
32 if (!num_unmatched)
33 return;
34 for (i = 0; i < active_nr; i++) {
35 - struct cache_entry *ce = active_cache[i];
35 + const struct cache_entry *ce = active_cache[i];
36 match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, seen);
37 }
38 }
@@ -67,7 +67,7 @@ const char *check_path_for_gitlink(const char *path)
67 {
68 int i, path_len = strlen(path);
69 for (i = 0; i < active_nr; i++) {
70 - struct cache_entry *ce = active_cache[i];
70 + const struct cache_entry *ce = active_cache[i];
71 if (S_ISGITLINK(ce->ce_mode)) {
72 int ce_len = ce_namelen(ce);
73 if (path_len <= ce_len || path[ce_len] != '/' ||
read-cache.c
+1 -1
@@ -722,7 +722,7 @@ struct cache_entry *make_cache_entry(unsigned int mode,
722 return ce;
723 }
724
725 -int ce_same_name(struct cache_entry *a, struct cache_entry *b)
725 +int ce_same_name(const struct cache_entry *a, const struct cache_entry *b)
726 {
727 int len = ce_namelen(a);
728 return ce_namelen(b) == len && !memcmp(a->name, b->name, len);
rerere.c
+6 -6
@@ -299,7 +299,7 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu
299 {
300 mmfile_t mmfile[3] = {{NULL}};
301 mmbuffer_t result = {NULL, 0};
302 - struct cache_entry *ce;
302 + const struct cache_entry *ce;
303 int pos, len, i, hunk_no;
304 struct rerere_io_mem io;
305 int marker_size = ll_merge_marker_size(path);
@@ -359,7 +359,7 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu
359
360 static int check_one_conflict(int i, int *type)
361 {
362 - struct cache_entry *e = active_cache[i];
362 + const struct cache_entry *e = active_cache[i];
363
364 if (!ce_stage(e)) {
365 *type = RESOLVED;
@@ -374,8 +374,8 @@ static int check_one_conflict(int i, int *type)
374
375 /* Only handle regular files with both stages #2 and #3 */
376 if (i + 1 < active_nr) {
377 - struct cache_entry *e2 = active_cache[i];
378 - struct cache_entry *e3 = active_cache[i + 1];
377 + const struct cache_entry *e2 = active_cache[i];
378 + const struct cache_entry *e3 = active_cache[i + 1];
379 if (ce_stage(e2) == 2 &&
380 ce_stage(e3) == 3 &&
381 ce_same_name(e, e3) &&
@@ -398,7 +398,7 @@ static int find_conflict(struct string_list *conflict)
398
399 for (i = 0; i < active_nr;) {
400 int conflict_type;
401 - struct cache_entry *e = active_cache[i];
401 + const struct cache_entry *e = active_cache[i];
402 i = check_one_conflict(i, &conflict_type);
403 if (conflict_type == THREE_STAGED)
404 string_list_insert(conflict, (const char *)e->name);
@@ -414,7 +414,7 @@ int rerere_remaining(struct string_list *merge_rr)
414
415 for (i = 0; i < active_nr;) {
416 int conflict_type;
417 - struct cache_entry *e = active_cache[i];
417 + const struct cache_entry *e = active_cache[i];
418 i = check_one_conflict(i, &conflict_type);
419 if (conflict_type == PUNTED)
420 string_list_insert(merge_rr, (const char *)e->name);
resolve-undo.c
+3 -3
@@ -115,7 +115,7 @@ void resolve_undo_clear_index(struct index_state *istate)
115
116 int unmerge_index_entry_at(struct index_state *istate, int pos)
117 {
118 - struct cache_entry *ce;
118 + const struct cache_entry *ce;
119 struct string_list_item *item;
120 struct resolve_undo_info *ru;
121 int i, err = 0, matched;
@@ -167,7 +167,7 @@ void unmerge_marked_index(struct index_state *istate)
167 return;
168
169 for (i = 0; i < istate->cache_nr; i++) {
170 - struct cache_entry *ce = istate->cache[i];
170 + const struct cache_entry *ce = istate->cache[i];
171 if (ce->ce_flags & CE_MATCHED)
172 i = unmerge_index_entry_at(istate, i);
173 }
@@ -181,7 +181,7 @@ void unmerge_index(struct index_state *istate, const char **pathspec)
181 return;
182
183 for (i = 0; i < istate->cache_nr; i++) {
184 - struct cache_entry *ce = istate->cache[i];
184 + const struct cache_entry *ce = istate->cache[i];
185 if (!match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, NULL))
186 continue;
187 i = unmerge_index_entry_at(istate, i);
revision.c
+1 -1
@@ -1358,7 +1358,7 @@ static void prepare_show_merge(struct rev_info *revs)
1358 if (!active_nr)
1359 read_cache();
1360 for (i = 0; i < active_nr; i++) {
1361 - struct cache_entry *ce = active_cache[i];
1361 + const struct cache_entry *ce = active_cache[i];
1362 if (!ce_stage(ce))
1363 continue;
1364 if (ce_path_match(ce, &revs->prune_data)) {
sequencer.c
+4 -3
@@ -331,7 +331,7 @@ static int do_recursive_merge(struct commit *base, struct commit *next,
331 int i;
332 strbuf_addstr(msgbuf, "\nConflicts:\n");
333 for (i = 0; i < active_nr;) {
334 - struct cache_entry *ce = active_cache[i++];
334 + const struct cache_entry *ce = active_cache[i++];
335 if (ce_stage(ce)) {
336 strbuf_addch(msgbuf, '\t');
337 strbuf_addstr(msgbuf, ce->name);
@@ -371,8 +371,9 @@ static int is_index_unchanged(void)
371 active_cache_tree = cache_tree();
372
373 if (!cache_tree_fully_valid(active_cache_tree))
374 - if (cache_tree_update(active_cache_tree, active_cache,
375 - active_nr, 0))
374 + if (cache_tree_update(active_cache_tree,
375 + (const struct cache_entry * const *)active_cache,
376 + active_nr, 0))
377 return error(_("Unable to update cache tree\n"));
378
379 return !hashcmp(active_cache_tree->sha1, head_commit->tree->object.sha1);
sha1_name.c
+2 -2
@@ -1234,7 +1234,7 @@ static void diagnose_invalid_index_path(int stage,
1234 const char *filename)
1235 {
1236 struct stat st;
1237 - struct cache_entry *ce;
1237 + const struct cache_entry *ce;
1238 int pos;
1239 unsigned namelen = strlen(filename);
1240 unsigned fullnamelen;
@@ -1328,7 +1328,7 @@ static int get_sha1_with_context_1(const char *name,
1328 */
1329 if (name[0] == ':') {
1330 int stage = 0;
1331 - struct cache_entry *ce;
1331 + const struct cache_entry *ce;
1332 char *new_path = NULL;
1333 int pos;
1334 if (!only_to_die && namelen > 2 && name[1] == '/') {
submodule.c
+1 -1
@@ -623,7 +623,7 @@ int fetch_populated_submodules(const struct argv_array *options,
623 struct strbuf submodule_path = STRBUF_INIT;
624 struct strbuf submodule_git_dir = STRBUF_INIT;
625 struct strbuf submodule_prefix = STRBUF_INIT;
626 - struct cache_entry *ce = active_cache[i];
626 + const struct cache_entry *ce = active_cache[i];
627 const char *git_dir, *name, *default_argv;
628
629 if (!S_ISGITLINK(ce->ce_mode))
test-dump-cache-tree.c
+3 -1
@@ -59,6 +59,8 @@ int main(int ac, char **av)
59 struct cache_tree *another = cache_tree();
60 if (read_cache() < 0)
61 die("unable to read index file");
62 - cache_tree_update(another, active_cache, active_nr, WRITE_TREE_DRY_RUN);
62 + cache_tree_update(another,
63 + (const struct cache_entry * const *)active_cache,
64 + active_nr, WRITE_TREE_DRY_RUN);
65 return dump_cache_tree(active_cache_tree, another, "");
66 }
tree.c
+1 -1
@@ -159,7 +159,7 @@ int read_tree(struct tree *tree, int stage, struct pathspec *match)
159 * sort at the end.
160 */
161 for (i = 0; !fn && i < active_nr; i++) {
162 - struct cache_entry *ce = active_cache[i];
162 + const struct cache_entry *ce = active_cache[i];
163 if (ce_stage(ce) == stage)
164 fn = read_one_entry;
165 }
unpack-trees.c
+7 -7
@@ -179,7 +179,7 @@ static void display_error_msgs(struct unpack_trees_options *o)
179 * Unlink the last component and schedule the leading directories for
180 * removal, such that empty directories get removed.
181 */
182 -static void unlink_entry(struct cache_entry *ce)
182 +static void unlink_entry(const struct cache_entry *ce)
183 {
184 if (!check_leading_path(ce->name, ce_namelen(ce)))
185 return;
@@ -199,7 +199,7 @@ static int check_updates(struct unpack_trees_options *o)
199
200 if (o->update && o->verbose_update) {
201 for (total = cnt = 0; cnt < index->cache_nr; cnt++) {
202 - struct cache_entry *ce = index->cache[cnt];
202 + const struct cache_entry *ce = index->cache[cnt];
203 if (ce->ce_flags & (CE_UPDATE | CE_WT_REMOVE))
204 total++;
205 }
@@ -212,7 +212,7 @@ static int check_updates(struct unpack_trees_options *o)
212 if (o->update)
213 git_attr_set_direction(GIT_ATTR_CHECKOUT, &o->result);
214 for (i = 0; i < index->cache_nr; i++) {
215 - struct cache_entry *ce = index->cache[i];
215 + const struct cache_entry *ce = index->cache[i];
216
217 if (ce->ce_flags & CE_WT_REMOVE) {
218 display_progress(progress, ++cnt);
@@ -376,7 +376,7 @@ static struct cache_entry *next_cache_entry(struct unpack_trees_options *o)
376 return NULL;
377 }
378
379 -static void add_same_unmerged(struct cache_entry *ce,
379 +static void add_same_unmerged(const struct cache_entry *ce,
380 struct unpack_trees_options *o)
381 {
382 struct index_state *index = o->src_index;
@@ -650,7 +650,7 @@ static int find_cache_pos(struct traverse_info *info,
650 int p_len = tree_entry_len(p);
651
652 for (pos = o->cache_bottom; pos < index->cache_nr; pos++) {
653 - struct cache_entry *ce = index->cache[pos];
653 + const struct cache_entry *ce = index->cache[pos];
654 const char *ce_name, *ce_slash;
655 int cmp, ce_len;
656
@@ -1353,7 +1353,7 @@ static int verify_clean_subdirectory(const struct cache_entry *ce,
1353 */
1354 static int icase_exists(struct unpack_trees_options *o, const char *name, int len, struct stat *st)
1355 {
1356 - struct cache_entry *src;
1356 + const struct cache_entry *src;
1357
1358 src = index_name_exists(o->src_index, name, len, 1);
1359 return src && !ie_match_stat(o->src_index, src, st, CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE);
@@ -1364,7 +1364,7 @@ static int check_ok_to_remove(const char *name, int len, int dtype,
1364 enum unpack_trees_error_types error_type,
1365 struct unpack_trees_options *o)
1366 {
1367 - struct cache_entry *result;
1367 + const struct cache_entry *result;
1368
1369 /*
1370 * It may be that the 'lstat()' succeeded even though
wt-status.c
+2 -2
@@ -371,7 +371,7 @@ static void wt_status_collect_changed_cb(struct diff_queue_struct *q,
371 static int unmerged_mask(const char *path)
372 {
373 int pos, mask;
374 - struct cache_entry *ce;
374 + const struct cache_entry *ce;
375
376 pos = cache_name_pos(path, strlen(path));
377 if (0 <= pos)
@@ -475,7 +475,7 @@ static void wt_status_collect_changes_initial(struct wt_status *s)
475 for (i = 0; i < active_nr; i++) {
476 struct string_list_item *it;
477 struct wt_status_change_data *d;
478 - struct cache_entry *ce = active_cache[i];
478 + const struct cache_entry *ce = active_cache[i];
479
480 if (!ce_path_match(ce, &pathspec))
481 continue;