Merge branch 'nd/const-struct-cache-entry'

* nd/const-struct-cache-entry:
  Convert "struct cache_entry *" to "const ..." wherever possible
This commit is contained in:
Junio C Hamano 2013-07-22 11:24:00 -07:00
commit d3aeb31dc4
29 changed files with 93 additions and 85 deletions

View File

@ -2999,7 +2999,7 @@ static int read_blob_object(struct strbuf *buf, const unsigned char *sha1, unsig
return 0; return 0;
} }
static int read_file_or_gitlink(struct cache_entry *ce, struct strbuf *buf) static int read_file_or_gitlink(const struct cache_entry *ce, struct strbuf *buf)
{ {
if (!ce) if (!ce)
return 0; return 0;
@ -3117,7 +3117,7 @@ static struct patch *previous_patch(struct patch *patch, int *gone)
return previous; return previous;
} }
static int verify_index_match(struct cache_entry *ce, struct stat *st) static int verify_index_match(const struct cache_entry *ce, struct stat *st)
{ {
if (S_ISGITLINK(ce->ce_mode)) { if (S_ISGITLINK(ce->ce_mode)) {
if (!S_ISDIR(st->st_mode)) if (!S_ISDIR(st->st_mode))
@ -3130,7 +3130,7 @@ static int verify_index_match(struct cache_entry *ce, struct stat *st)
#define SUBMODULE_PATCH_WITHOUT_INDEX 1 #define SUBMODULE_PATCH_WITHOUT_INDEX 1
static int load_patch_target(struct strbuf *buf, static int load_patch_target(struct strbuf *buf,
struct cache_entry *ce, const struct cache_entry *ce,
struct stat *st, struct stat *st,
const char *name, const char *name,
unsigned expected_mode) unsigned expected_mode)
@ -3160,7 +3160,8 @@ static int load_patch_target(struct strbuf *buf,
* we read from the result of a previous diff. * we read from the result of a previous diff.
*/ */
static int load_preimage(struct image *image, static int load_preimage(struct image *image,
struct patch *patch, struct stat *st, struct cache_entry *ce) struct patch *patch, struct stat *st,
const struct cache_entry *ce)
{ {
struct strbuf buf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT;
size_t len; size_t len;
@ -3273,7 +3274,7 @@ static int load_current(struct image *image, struct patch *patch)
} }
static int try_threeway(struct image *image, struct patch *patch, static int try_threeway(struct image *image, struct patch *patch,
struct stat *st, struct cache_entry *ce) struct stat *st, const struct cache_entry *ce)
{ {
unsigned char pre_sha1[20], post_sha1[20], our_sha1[20]; unsigned char pre_sha1[20], post_sha1[20], our_sha1[20];
struct strbuf buf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT;
@ -3343,7 +3344,7 @@ static int try_threeway(struct image *image, struct patch *patch,
return 0; return 0;
} }
static int apply_data(struct patch *patch, struct stat *st, struct cache_entry *ce) static int apply_data(struct patch *patch, struct stat *st, const struct cache_entry *ce)
{ {
struct image image; struct image image;

View File

@ -97,7 +97,7 @@ static int read_tree_some(struct tree *tree, const char **pathspec)
return 0; return 0;
} }
static int skip_same_name(struct cache_entry *ce, int pos) static int skip_same_name(const struct cache_entry *ce, int pos)
{ {
while (++pos < active_nr && while (++pos < active_nr &&
!strcmp(active_cache[pos]->name, ce->name)) !strcmp(active_cache[pos]->name, ce->name))
@ -105,7 +105,7 @@ static int skip_same_name(struct cache_entry *ce, int pos)
return pos; return pos;
} }
static int check_stage(int stage, struct cache_entry *ce, int pos) static int check_stage(int stage, const struct cache_entry *ce, int pos)
{ {
while (pos < active_nr && while (pos < active_nr &&
!strcmp(active_cache[pos]->name, ce->name)) { !strcmp(active_cache[pos]->name, ce->name)) {
@ -119,7 +119,7 @@ static int check_stage(int stage, struct cache_entry *ce, int pos)
return error(_("path '%s' does not have their version"), ce->name); return error(_("path '%s' does not have their version"), ce->name);
} }
static int check_stages(unsigned stages, struct cache_entry *ce, int pos) static int check_stages(unsigned stages, const struct cache_entry *ce, int pos)
{ {
unsigned seen = 0; unsigned seen = 0;
const char *name = ce->name; const char *name = ce->name;
@ -321,7 +321,7 @@ static int checkout_paths(const struct checkout_opts *opts,
/* Any unmerged paths? */ /* Any unmerged paths? */
for (pos = 0; pos < active_nr; pos++) { for (pos = 0; pos < active_nr; pos++) {
struct cache_entry *ce = active_cache[pos]; const struct cache_entry *ce = active_cache[pos];
if (ce->ce_flags & CE_MATCHED) { if (ce->ce_flags & CE_MATCHED) {
if (!ce_stage(ce)) if (!ce_stage(ce))
continue; continue;

View File

@ -221,7 +221,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
struct dir_entry *ent = dir.entries[i]; struct dir_entry *ent = dir.entries[i];
int len, pos; int len, pos;
int matches = 0; int matches = 0;
struct cache_entry *ce; const struct cache_entry *ce;
struct stat st; struct stat st;
/* /*

View File

@ -207,7 +207,7 @@ static int list_paths(struct string_list *list, const char *with_tree,
} }
for (i = 0; i < active_nr; i++) { for (i = 0; i < active_nr; i++) {
struct cache_entry *ce = active_cache[i]; const struct cache_entry *ce = active_cache[i];
struct string_list_item *item; struct string_list_item *item;
if (ce->ce_flags & CE_UPDATE) if (ce->ce_flags & CE_UPDATE)

View File

@ -376,7 +376,7 @@ static int grep_cache(struct grep_opt *opt, const struct pathspec *pathspec, int
read_cache(); read_cache();
for (nr = 0; nr < active_nr; nr++) { for (nr = 0; nr < active_nr; nr++) {
struct cache_entry *ce = active_cache[nr]; const struct cache_entry *ce = active_cache[nr];
if (!S_ISREG(ce->ce_mode)) if (!S_ISREG(ce->ce_mode))
continue; continue;
if (!match_pathspec_depth(pathspec, ce->name, ce_namelen(ce), 0, NULL)) if (!match_pathspec_depth(pathspec, ce->name, ce_namelen(ce), 0, NULL))

View File

@ -127,7 +127,7 @@ static void show_killed_files(struct dir_struct *dir)
} }
} }
static void show_ce_entry(const char *tag, struct cache_entry *ce) static void show_ce_entry(const char *tag, const struct cache_entry *ce)
{ {
int len = max_prefix_len; int len = max_prefix_len;
@ -165,7 +165,7 @@ static void show_ce_entry(const char *tag, struct cache_entry *ce)
} }
write_name(ce->name, ce_namelen(ce)); write_name(ce->name, ce_namelen(ce));
if (debug_mode) { if (debug_mode) {
struct stat_data *sd = &ce->ce_stat_data; const struct stat_data *sd = &ce->ce_stat_data;
printf(" ctime: %d:%d\n", sd->sd_ctime.sec, sd->sd_ctime.nsec); printf(" ctime: %d:%d\n", sd->sd_ctime.sec, sd->sd_ctime.nsec);
printf(" mtime: %d:%d\n", sd->sd_mtime.sec, sd->sd_mtime.nsec); printf(" mtime: %d:%d\n", sd->sd_mtime.sec, sd->sd_mtime.nsec);
@ -203,7 +203,7 @@ static void show_ru_info(void)
} }
} }
static int ce_excluded(struct dir_struct *dir, struct cache_entry *ce) static int ce_excluded(struct dir_struct *dir, const struct cache_entry *ce)
{ {
int dtype = ce_to_dtype(ce); int dtype = ce_to_dtype(ce);
return is_excluded(dir, ce->name, &dtype); return is_excluded(dir, ce->name, &dtype);
@ -223,7 +223,7 @@ static void show_files(struct dir_struct *dir)
} }
if (show_cached || show_stage) { if (show_cached || show_stage) {
for (i = 0; i < active_nr; i++) { for (i = 0; i < active_nr; i++) {
struct cache_entry *ce = active_cache[i]; const struct cache_entry *ce = active_cache[i];
if ((dir->flags & DIR_SHOW_IGNORED) && if ((dir->flags & DIR_SHOW_IGNORED) &&
!ce_excluded(dir, ce)) !ce_excluded(dir, ce))
continue; continue;
@ -237,7 +237,7 @@ static void show_files(struct dir_struct *dir)
} }
if (show_deleted || show_modified) { if (show_deleted || show_modified) {
for (i = 0; i < active_nr; i++) { for (i = 0; i < active_nr; i++) {
struct cache_entry *ce = active_cache[i]; const struct cache_entry *ce = active_cache[i];
struct stat st; struct stat st;
int err; int err;
if ((dir->flags & DIR_SHOW_IGNORED) && if ((dir->flags & DIR_SHOW_IGNORED) &&
@ -273,7 +273,7 @@ static void prune_cache(const char *prefix)
last = active_nr; last = active_nr;
while (last > first) { while (last > first) {
int next = (last + first) >> 1; int next = (last + first) >> 1;
struct cache_entry *ce = active_cache[next]; const struct cache_entry *ce = active_cache[next];
if (!strncmp(ce->name, prefix, max_prefix_len)) { if (!strncmp(ce->name, prefix, max_prefix_len)) {
first = next+1; first = next+1;
continue; continue;

View File

@ -16,7 +16,7 @@ static int merge_entry(int pos, const char *path)
die("git merge-index: %s not in the cache", path); die("git merge-index: %s not in the cache", path);
found = 0; found = 0;
do { do {
struct cache_entry *ce = active_cache[pos]; const struct cache_entry *ce = active_cache[pos];
int stage = ce_stage(ce); int stage = ce_stage(ce);
if (strcmp(ce->name, path)) if (strcmp(ce->name, path))
@ -58,7 +58,7 @@ static void merge_all(void)
{ {
int i; int i;
for (i = 0; i < active_nr; i++) { for (i = 0; i < active_nr; i++) {
struct cache_entry *ce = active_cache[i]; const struct cache_entry *ce = active_cache[i];
if (!ce_stage(ce)) if (!ce_stage(ce))
continue; continue;
i += merge_entry(i, ce->name)-1; i += merge_entry(i, ce->name)-1;

View File

@ -903,7 +903,7 @@ static int suggest_conflicts(int renormalizing)
die_errno(_("Could not open '%s' for writing"), filename); die_errno(_("Could not open '%s' for writing"), filename);
fprintf(fp, "\nConflicts:\n"); fprintf(fp, "\nConflicts:\n");
for (pos = 0; pos < active_nr; pos++) { for (pos = 0; pos < active_nr; pos++) {
struct cache_entry *ce = active_cache[pos]; const struct cache_entry *ce = active_cache[pos];
if (ce_stage(ce)) { if (ce_stage(ce)) {
fprintf(fp, "\t%s\n", ce->name); fprintf(fp, "\t%s\n", ce->name);

View File

@ -67,7 +67,7 @@ static int check_submodules_use_gitfiles(void)
for (i = 0; i < list.nr; i++) { for (i = 0; i < list.nr; i++) {
const char *name = list.entry[i].name; const char *name = list.entry[i].name;
int pos; int pos;
struct cache_entry *ce; const struct cache_entry *ce;
struct stat st; struct stat st;
pos = cache_name_pos(name, strlen(name)); pos = cache_name_pos(name, strlen(name));
@ -120,7 +120,7 @@ static int check_local_mod(unsigned char *head, int index_only)
for (i = 0; i < list.nr; i++) { for (i = 0; i < list.nr; i++) {
struct stat st; struct stat st;
int pos; int pos;
struct cache_entry *ce; const struct cache_entry *ce;
const char *name = list.entry[i].name; const char *name = list.entry[i].name;
unsigned char sha1[20]; unsigned char sha1[20];
unsigned mode; unsigned mode;
@ -321,7 +321,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
seen = xcalloc(i, 1); seen = xcalloc(i, 1);
for (i = 0; i < active_nr; i++) { for (i = 0; i < active_nr; i++) {
struct cache_entry *ce = active_cache[i]; const struct cache_entry *ce = active_cache[i];
if (!match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, seen)) if (!match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, seen))
continue; continue;
ALLOC_GROW(list.entry, list.nr + 1, list.alloc); ALLOC_GROW(list.entry, list.nr + 1, list.alloc);

View File

@ -83,7 +83,7 @@ static int process_lstat_error(const char *path, int err)
return error("lstat(\"%s\"): %s", path, strerror(errno)); return error("lstat(\"%s\"): %s", path, strerror(errno));
} }
static int add_one_path(struct cache_entry *old, const char *path, int len, struct stat *st) static int add_one_path(const struct cache_entry *old, const char *path, int len, struct stat *st)
{ {
int option, size; int option, size;
struct cache_entry *ce; struct cache_entry *ce;
@ -142,7 +142,7 @@ static int process_directory(const char *path, int len, struct stat *st)
/* Exact match: file or existing gitlink */ /* Exact match: file or existing gitlink */
if (pos >= 0) { if (pos >= 0) {
struct cache_entry *ce = active_cache[pos]; const struct cache_entry *ce = active_cache[pos];
if (S_ISGITLINK(ce->ce_mode)) { if (S_ISGITLINK(ce->ce_mode)) {
/* Do nothing to the index if there is no HEAD! */ /* 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)
/* Inexact match: is there perhaps a subdirectory match? */ /* Inexact match: is there perhaps a subdirectory match? */
pos = -pos-1; pos = -pos-1;
while (pos < active_nr) { while (pos < active_nr) {
struct cache_entry *ce = active_cache[pos++]; const struct cache_entry *ce = active_cache[pos++];
if (strncmp(ce->name, path, len)) if (strncmp(ce->name, path, len))
break; break;
@ -183,7 +183,7 @@ static int process_path(const char *path)
{ {
int pos, len; int pos, len;
struct stat st; struct stat st;
struct cache_entry *ce; const struct cache_entry *ce;
len = strlen(path); len = strlen(path);
if (has_symlink_leading_path(path, len)) if (has_symlink_leading_path(path, len))
@ -448,7 +448,7 @@ static int unresolve_one(const char *path)
/* already merged */ /* already merged */
pos = unmerge_cache_entry_at(pos); pos = unmerge_cache_entry_at(pos);
if (pos < active_nr) { if (pos < active_nr) {
struct cache_entry *ce = active_cache[pos]; const struct cache_entry *ce = active_cache[pos];
if (ce_stage(ce) && if (ce_stage(ce) &&
ce_namelen(ce) == namelen && ce_namelen(ce) == namelen &&
!memcmp(ce->name, path, namelen)) !memcmp(ce->name, path, namelen))
@ -462,7 +462,7 @@ static int unresolve_one(const char *path)
*/ */
pos = -pos-1; pos = -pos-1;
if (pos < active_nr) { if (pos < active_nr) {
struct cache_entry *ce = active_cache[pos]; const struct cache_entry *ce = active_cache[pos];
if (ce_namelen(ce) == namelen && if (ce_namelen(ce) == namelen &&
!memcmp(ce->name, path, namelen)) { !memcmp(ce->name, path, namelen)) {
fprintf(stderr, fprintf(stderr,
@ -558,7 +558,7 @@ static int do_reupdate(int ac, const char **av,
has_head = 0; has_head = 0;
redo: redo:
for (pos = 0; pos < active_nr; pos++) { for (pos = 0; pos < active_nr; pos++) {
struct cache_entry *ce = active_cache[pos]; const struct cache_entry *ce = active_cache[pos];
struct cache_entry *old = NULL; struct cache_entry *old = NULL;
int save_nr; int save_nr;

View File

@ -149,7 +149,7 @@ void cache_tree_invalidate_path(struct cache_tree *it, const char *path)
cache_tree_invalidate_path(down->cache_tree, slash + 1); cache_tree_invalidate_path(down->cache_tree, slash + 1);
} }
static int verify_cache(struct cache_entry **cache, static int verify_cache(const struct cache_entry * const *cache,
int entries, int flags) int entries, int flags)
{ {
int i, funny; int i, funny;
@ -158,7 +158,7 @@ static int verify_cache(struct cache_entry **cache,
/* Verify that the tree is merged */ /* Verify that the tree is merged */
funny = 0; funny = 0;
for (i = 0; i < entries; i++) { for (i = 0; i < entries; i++) {
struct cache_entry *ce = cache[i]; const struct cache_entry *ce = cache[i];
if (ce_stage(ce)) { if (ce_stage(ce)) {
if (silent) if (silent)
return -1; return -1;
@ -234,7 +234,7 @@ int cache_tree_fully_valid(struct cache_tree *it)
} }
static int update_one(struct cache_tree *it, static int update_one(struct cache_tree *it,
struct cache_entry **cache, const struct cache_entry * const *cache,
int entries, int entries,
const char *base, const char *base,
int baselen, int baselen,
@ -265,7 +265,7 @@ static int update_one(struct cache_tree *it,
*/ */
i = 0; i = 0;
while (i < entries) { while (i < entries) {
struct cache_entry *ce = cache[i]; const struct cache_entry *ce = cache[i];
struct cache_tree_sub *sub; struct cache_tree_sub *sub;
const char *path, *slash; const char *path, *slash;
int pathlen, sublen, subcnt, subskip; int pathlen, sublen, subcnt, subskip;
@ -312,7 +312,7 @@ static int update_one(struct cache_tree *it,
i = 0; i = 0;
while (i < entries) { while (i < entries) {
struct cache_entry *ce = cache[i]; const struct cache_entry *ce = cache[i];
struct cache_tree_sub *sub; struct cache_tree_sub *sub;
const char *path, *slash; const char *path, *slash;
int pathlen, entlen; int pathlen, entlen;
@ -397,7 +397,7 @@ static int update_one(struct cache_tree *it,
} }
int cache_tree_update(struct cache_tree *it, int cache_tree_update(struct cache_tree *it,
struct cache_entry **cache, const struct cache_entry * const *cache,
int entries, int entries,
int flags) int flags)
{ {
@ -599,8 +599,8 @@ int write_cache_as_tree(unsigned char *sha1, int flags, const char *prefix)
was_valid = cache_tree_fully_valid(active_cache_tree); was_valid = cache_tree_fully_valid(active_cache_tree);
if (!was_valid) { if (!was_valid) {
if (cache_tree_update(active_cache_tree, if (cache_tree_update(active_cache_tree,
active_cache, active_nr, (const struct cache_entry * const *)active_cache,
flags) < 0) active_nr, flags) < 0)
return WRITE_TREE_UNMERGED_INDEX; return WRITE_TREE_UNMERGED_INDEX;
if (0 <= newfd) { if (0 <= newfd) {
if (!write_cache(newfd, active_cache, active_nr) && if (!write_cache(newfd, active_cache, active_nr) &&
@ -701,5 +701,6 @@ int update_main_cache_tree(int flags)
if (!the_index.cache_tree) if (!the_index.cache_tree)
the_index.cache_tree = cache_tree(); the_index.cache_tree = cache_tree();
return cache_tree_update(the_index.cache_tree, return cache_tree_update(the_index.cache_tree,
the_index.cache, the_index.cache_nr, flags); (const struct cache_entry * const *)the_index.cache,
the_index.cache_nr, flags);
} }

View File

@ -30,7 +30,7 @@ void cache_tree_write(struct strbuf *, struct cache_tree *root);
struct cache_tree *cache_tree_read(const char *buffer, unsigned long size); struct cache_tree *cache_tree_read(const char *buffer, unsigned long size);
int cache_tree_fully_valid(struct cache_tree *); int cache_tree_fully_valid(struct cache_tree *);
int cache_tree_update(struct cache_tree *, struct cache_entry **, int, int); int cache_tree_update(struct cache_tree *, const struct cache_entry * const *, int, int);
int update_main_cache_tree(int); int update_main_cache_tree(int);

View File

@ -478,7 +478,7 @@ extern int remove_file_from_index(struct index_state *, const char *path);
extern int add_to_index(struct index_state *, const char *path, struct stat *, int flags); extern int add_to_index(struct index_state *, const char *path, struct stat *, int flags);
extern int add_file_to_index(struct index_state *, const char *path, int flags); extern int add_file_to_index(struct index_state *, const char *path, int flags);
extern struct cache_entry *make_cache_entry(unsigned int mode, const unsigned char *sha1, const char *path, int stage, int refresh); extern struct cache_entry *make_cache_entry(unsigned int mode, const unsigned char *sha1, const char *path, int stage, int refresh);
extern int ce_same_name(struct cache_entry *a, struct cache_entry *b); extern int ce_same_name(const struct cache_entry *a, const struct cache_entry *b);
extern int index_name_is_other(const struct index_state *, const char *, int); extern int index_name_is_other(const struct index_state *, const char *, int);
extern void *read_blob_data_from_index(struct index_state *, const char *, unsigned long *); extern void *read_blob_data_from_index(struct index_state *, const char *, unsigned long *);

2
diff.c
View File

@ -2586,7 +2586,7 @@ void fill_filespec(struct diff_filespec *spec, const unsigned char *sha1,
*/ */
static int reuse_worktree_file(const char *name, const unsigned char *sha1, int want_file) static int reuse_worktree_file(const char *name, const unsigned char *sha1, int want_file)
{ {
struct cache_entry *ce; const struct cache_entry *ce;
struct stat st; struct stat st;
int pos, len; int pos, len;

6
dir.c
View File

@ -933,7 +933,7 @@ enum exist_status {
*/ */
static enum exist_status directory_exists_in_index_icase(const char *dirname, int len) static enum exist_status directory_exists_in_index_icase(const char *dirname, int len)
{ {
struct cache_entry *ce = index_name_exists(&the_index, dirname, len + 1, ignore_case); const struct cache_entry *ce = index_name_exists(&the_index, dirname, len + 1, ignore_case);
unsigned char endchar; unsigned char endchar;
if (!ce) if (!ce)
@ -977,7 +977,7 @@ static enum exist_status directory_exists_in_index(const char *dirname, int len)
if (pos < 0) if (pos < 0)
pos = -pos-1; pos = -pos-1;
while (pos < active_nr) { while (pos < active_nr) {
struct cache_entry *ce = active_cache[pos++]; const struct cache_entry *ce = active_cache[pos++];
unsigned char endchar; unsigned char endchar;
if (strncmp(ce->name, dirname, len)) if (strncmp(ce->name, dirname, len))
@ -1113,7 +1113,7 @@ static int exclude_matches_pathspec(const char *path, int len,
static int get_index_dtype(const char *path, int len) static int get_index_dtype(const char *path, int len)
{ {
int pos; int pos;
struct cache_entry *ce; const struct cache_entry *ce;
ce = cache_name_exists(path, len, 0); ce = cache_name_exists(path, len, 0);
if (ce) { if (ce) {

12
entry.c
View File

@ -79,7 +79,7 @@ static int create_file(const char *path, unsigned int mode)
return open(path, O_WRONLY | O_CREAT | O_EXCL, mode); return open(path, O_WRONLY | O_CREAT | O_EXCL, mode);
} }
static void *read_blob_entry(struct cache_entry *ce, unsigned long *size) static void *read_blob_entry(const struct cache_entry *ce, unsigned long *size)
{ {
enum object_type type; enum object_type type;
void *new = read_sha1_file(ce->sha1, &type, size); 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)
return NULL; return NULL;
} }
static int open_output_fd(char *path, struct cache_entry *ce, int to_tempfile) static int open_output_fd(char *path, const struct cache_entry *ce, int to_tempfile)
{ {
int symlink = (ce->ce_mode & S_IFMT) != S_IFREG; int symlink = (ce->ce_mode & S_IFMT) != S_IFREG;
if (to_tempfile) { if (to_tempfile) {
@ -115,7 +115,7 @@ static int fstat_output(int fd, const struct checkout *state, struct stat *st)
return 0; return 0;
} }
static int streaming_write_entry(struct cache_entry *ce, char *path, static int streaming_write_entry(const struct cache_entry *ce, char *path,
struct stream_filter *filter, struct stream_filter *filter,
const struct checkout *state, int to_tempfile, const struct checkout *state, int to_tempfile,
int *fstat_done, struct stat *statbuf) int *fstat_done, struct stat *statbuf)
@ -136,7 +136,8 @@ static int streaming_write_entry(struct cache_entry *ce, char *path,
return result; return result;
} }
static int write_entry(struct cache_entry *ce, char *path, const struct checkout *state, int to_tempfile) static int write_entry(struct cache_entry *ce,
char *path, const struct checkout *state, int to_tempfile)
{ {
unsigned int ce_mode_s_ifmt = ce->ce_mode & S_IFMT; unsigned int ce_mode_s_ifmt = ce->ce_mode & S_IFMT;
int fd, ret, fstat_done = 0; int fd, ret, fstat_done = 0;
@ -233,7 +234,8 @@ static int check_path(const char *path, int len, struct stat *st, int skiplen)
return lstat(path, st); return lstat(path, st);
} }
int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath) int checkout_entry(struct cache_entry *ce,
const struct checkout *state, char *topath)
{ {
static char path[PATH_MAX + 1]; static char path[PATH_MAX + 1];
struct stat st; struct stat st;

View File

@ -251,7 +251,7 @@ struct tree *write_tree_from_memory(struct merge_options *o)
int i; int i;
fprintf(stderr, "BUG: There are unmerged index entries:\n"); fprintf(stderr, "BUG: There are unmerged index entries:\n");
for (i = 0; i < active_nr; i++) { for (i = 0; i < active_nr; i++) {
struct cache_entry *ce = active_cache[i]; const struct cache_entry *ce = active_cache[i];
if (ce_stage(ce)) if (ce_stage(ce))
fprintf(stderr, "BUG: %d %.*s\n", ce_stage(ce), fprintf(stderr, "BUG: %d %.*s\n", ce_stage(ce),
(int)ce_namelen(ce), ce->name); (int)ce_namelen(ce), ce->name);
@ -264,7 +264,8 @@ struct tree *write_tree_from_memory(struct merge_options *o)
if (!cache_tree_fully_valid(active_cache_tree) && if (!cache_tree_fully_valid(active_cache_tree) &&
cache_tree_update(active_cache_tree, cache_tree_update(active_cache_tree,
active_cache, active_nr, 0) < 0) (const struct cache_entry * const *)active_cache,
active_nr, 0) < 0)
die(_("error building trees")); die(_("error building trees"));
result = lookup_tree(active_cache_tree->sha1); result = lookup_tree(active_cache_tree->sha1);
@ -339,7 +340,7 @@ static struct string_list *get_unmerged(void)
for (i = 0; i < active_nr; i++) { for (i = 0; i < active_nr; i++) {
struct string_list_item *item; struct string_list_item *item;
struct stage_data *e; struct stage_data *e;
struct cache_entry *ce = active_cache[i]; const struct cache_entry *ce = active_cache[i];
if (!ce_stage(ce)) if (!ce_stage(ce))
continue; continue;

View File

@ -32,7 +32,7 @@ void add_pathspec_matches_against_index(const char **pathspec,
if (!num_unmatched) if (!num_unmatched)
return; return;
for (i = 0; i < active_nr; i++) { for (i = 0; i < active_nr; i++) {
struct cache_entry *ce = active_cache[i]; const struct cache_entry *ce = active_cache[i];
match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, seen); match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, seen);
} }
} }
@ -67,7 +67,7 @@ const char *check_path_for_gitlink(const char *path)
{ {
int i, path_len = strlen(path); int i, path_len = strlen(path);
for (i = 0; i < active_nr; i++) { for (i = 0; i < active_nr; i++) {
struct cache_entry *ce = active_cache[i]; const struct cache_entry *ce = active_cache[i];
if (S_ISGITLINK(ce->ce_mode)) { if (S_ISGITLINK(ce->ce_mode)) {
int ce_len = ce_namelen(ce); int ce_len = ce_namelen(ce);
if (path_len <= ce_len || path[ce_len] != '/' || if (path_len <= ce_len || path[ce_len] != '/' ||

View File

@ -722,7 +722,7 @@ struct cache_entry *make_cache_entry(unsigned int mode,
return ce; return ce;
} }
int ce_same_name(struct cache_entry *a, struct cache_entry *b) int ce_same_name(const struct cache_entry *a, const struct cache_entry *b)
{ {
int len = ce_namelen(a); int len = ce_namelen(a);
return ce_namelen(b) == len && !memcmp(a->name, b->name, len); return ce_namelen(b) == len && !memcmp(a->name, b->name, len);

View File

@ -299,7 +299,7 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu
{ {
mmfile_t mmfile[3] = {{NULL}}; mmfile_t mmfile[3] = {{NULL}};
mmbuffer_t result = {NULL, 0}; mmbuffer_t result = {NULL, 0};
struct cache_entry *ce; const struct cache_entry *ce;
int pos, len, i, hunk_no; int pos, len, i, hunk_no;
struct rerere_io_mem io; struct rerere_io_mem io;
int marker_size = ll_merge_marker_size(path); 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
static int check_one_conflict(int i, int *type) static int check_one_conflict(int i, int *type)
{ {
struct cache_entry *e = active_cache[i]; const struct cache_entry *e = active_cache[i];
if (!ce_stage(e)) { if (!ce_stage(e)) {
*type = RESOLVED; *type = RESOLVED;
@ -374,8 +374,8 @@ static int check_one_conflict(int i, int *type)
/* Only handle regular files with both stages #2 and #3 */ /* Only handle regular files with both stages #2 and #3 */
if (i + 1 < active_nr) { if (i + 1 < active_nr) {
struct cache_entry *e2 = active_cache[i]; const struct cache_entry *e2 = active_cache[i];
struct cache_entry *e3 = active_cache[i + 1]; const struct cache_entry *e3 = active_cache[i + 1];
if (ce_stage(e2) == 2 && if (ce_stage(e2) == 2 &&
ce_stage(e3) == 3 && ce_stage(e3) == 3 &&
ce_same_name(e, e3) && ce_same_name(e, e3) &&
@ -398,7 +398,7 @@ static int find_conflict(struct string_list *conflict)
for (i = 0; i < active_nr;) { for (i = 0; i < active_nr;) {
int conflict_type; int conflict_type;
struct cache_entry *e = active_cache[i]; const struct cache_entry *e = active_cache[i];
i = check_one_conflict(i, &conflict_type); i = check_one_conflict(i, &conflict_type);
if (conflict_type == THREE_STAGED) if (conflict_type == THREE_STAGED)
string_list_insert(conflict, (const char *)e->name); string_list_insert(conflict, (const char *)e->name);
@ -414,7 +414,7 @@ int rerere_remaining(struct string_list *merge_rr)
for (i = 0; i < active_nr;) { for (i = 0; i < active_nr;) {
int conflict_type; int conflict_type;
struct cache_entry *e = active_cache[i]; const struct cache_entry *e = active_cache[i];
i = check_one_conflict(i, &conflict_type); i = check_one_conflict(i, &conflict_type);
if (conflict_type == PUNTED) if (conflict_type == PUNTED)
string_list_insert(merge_rr, (const char *)e->name); string_list_insert(merge_rr, (const char *)e->name);

View File

@ -115,7 +115,7 @@ void resolve_undo_clear_index(struct index_state *istate)
int unmerge_index_entry_at(struct index_state *istate, int pos) int unmerge_index_entry_at(struct index_state *istate, int pos)
{ {
struct cache_entry *ce; const struct cache_entry *ce;
struct string_list_item *item; struct string_list_item *item;
struct resolve_undo_info *ru; struct resolve_undo_info *ru;
int i, err = 0, matched; int i, err = 0, matched;
@ -167,7 +167,7 @@ void unmerge_marked_index(struct index_state *istate)
return; return;
for (i = 0; i < istate->cache_nr; i++) { for (i = 0; i < istate->cache_nr; i++) {
struct cache_entry *ce = istate->cache[i]; const struct cache_entry *ce = istate->cache[i];
if (ce->ce_flags & CE_MATCHED) if (ce->ce_flags & CE_MATCHED)
i = unmerge_index_entry_at(istate, i); i = unmerge_index_entry_at(istate, i);
} }
@ -181,7 +181,7 @@ void unmerge_index(struct index_state *istate, const char **pathspec)
return; return;
for (i = 0; i < istate->cache_nr; i++) { for (i = 0; i < istate->cache_nr; i++) {
struct cache_entry *ce = istate->cache[i]; const struct cache_entry *ce = istate->cache[i];
if (!match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, NULL)) if (!match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, NULL))
continue; continue;
i = unmerge_index_entry_at(istate, i); i = unmerge_index_entry_at(istate, i);

View File

@ -1358,7 +1358,7 @@ static void prepare_show_merge(struct rev_info *revs)
if (!active_nr) if (!active_nr)
read_cache(); read_cache();
for (i = 0; i < active_nr; i++) { for (i = 0; i < active_nr; i++) {
struct cache_entry *ce = active_cache[i]; const struct cache_entry *ce = active_cache[i];
if (!ce_stage(ce)) if (!ce_stage(ce))
continue; continue;
if (ce_path_match(ce, &revs->prune_data)) { if (ce_path_match(ce, &revs->prune_data)) {

View File

@ -331,7 +331,7 @@ static int do_recursive_merge(struct commit *base, struct commit *next,
int i; int i;
strbuf_addstr(msgbuf, "\nConflicts:\n"); strbuf_addstr(msgbuf, "\nConflicts:\n");
for (i = 0; i < active_nr;) { for (i = 0; i < active_nr;) {
struct cache_entry *ce = active_cache[i++]; const struct cache_entry *ce = active_cache[i++];
if (ce_stage(ce)) { if (ce_stage(ce)) {
strbuf_addch(msgbuf, '\t'); strbuf_addch(msgbuf, '\t');
strbuf_addstr(msgbuf, ce->name); strbuf_addstr(msgbuf, ce->name);
@ -371,7 +371,8 @@ static int is_index_unchanged(void)
active_cache_tree = cache_tree(); active_cache_tree = cache_tree();
if (!cache_tree_fully_valid(active_cache_tree)) if (!cache_tree_fully_valid(active_cache_tree))
if (cache_tree_update(active_cache_tree, active_cache, if (cache_tree_update(active_cache_tree,
(const struct cache_entry * const *)active_cache,
active_nr, 0)) active_nr, 0))
return error(_("Unable to update cache tree\n")); return error(_("Unable to update cache tree\n"));

View File

@ -1234,7 +1234,7 @@ static void diagnose_invalid_index_path(int stage,
const char *filename) const char *filename)
{ {
struct stat st; struct stat st;
struct cache_entry *ce; const struct cache_entry *ce;
int pos; int pos;
unsigned namelen = strlen(filename); unsigned namelen = strlen(filename);
unsigned fullnamelen; unsigned fullnamelen;
@ -1328,7 +1328,7 @@ static int get_sha1_with_context_1(const char *name,
*/ */
if (name[0] == ':') { if (name[0] == ':') {
int stage = 0; int stage = 0;
struct cache_entry *ce; const struct cache_entry *ce;
char *new_path = NULL; char *new_path = NULL;
int pos; int pos;
if (!only_to_die && namelen > 2 && name[1] == '/') { if (!only_to_die && namelen > 2 && name[1] == '/') {

View File

@ -624,7 +624,7 @@ int fetch_populated_submodules(const struct argv_array *options,
struct strbuf submodule_path = STRBUF_INIT; struct strbuf submodule_path = STRBUF_INIT;
struct strbuf submodule_git_dir = STRBUF_INIT; struct strbuf submodule_git_dir = STRBUF_INIT;
struct strbuf submodule_prefix = STRBUF_INIT; struct strbuf submodule_prefix = STRBUF_INIT;
struct cache_entry *ce = active_cache[i]; const struct cache_entry *ce = active_cache[i];
const char *git_dir, *name, *default_argv; const char *git_dir, *name, *default_argv;
if (!S_ISGITLINK(ce->ce_mode)) if (!S_ISGITLINK(ce->ce_mode))

View File

@ -59,6 +59,8 @@ int main(int ac, char **av)
struct cache_tree *another = cache_tree(); struct cache_tree *another = cache_tree();
if (read_cache() < 0) if (read_cache() < 0)
die("unable to read index file"); die("unable to read index file");
cache_tree_update(another, active_cache, active_nr, WRITE_TREE_DRY_RUN); cache_tree_update(another,
(const struct cache_entry * const *)active_cache,
active_nr, WRITE_TREE_DRY_RUN);
return dump_cache_tree(active_cache_tree, another, ""); return dump_cache_tree(active_cache_tree, another, "");
} }

2
tree.c
View File

@ -159,7 +159,7 @@ int read_tree(struct tree *tree, int stage, struct pathspec *match)
* sort at the end. * sort at the end.
*/ */
for (i = 0; !fn && i < active_nr; i++) { for (i = 0; !fn && i < active_nr; i++) {
struct cache_entry *ce = active_cache[i]; const struct cache_entry *ce = active_cache[i];
if (ce_stage(ce) == stage) if (ce_stage(ce) == stage)
fn = read_one_entry; fn = read_one_entry;
} }

View File

@ -179,7 +179,7 @@ static void display_error_msgs(struct unpack_trees_options *o)
* Unlink the last component and schedule the leading directories for * Unlink the last component and schedule the leading directories for
* removal, such that empty directories get removed. * removal, such that empty directories get removed.
*/ */
static void unlink_entry(struct cache_entry *ce) static void unlink_entry(const struct cache_entry *ce)
{ {
if (!check_leading_path(ce->name, ce_namelen(ce))) if (!check_leading_path(ce->name, ce_namelen(ce)))
return; return;
@ -199,7 +199,7 @@ static int check_updates(struct unpack_trees_options *o)
if (o->update && o->verbose_update) { if (o->update && o->verbose_update) {
for (total = cnt = 0; cnt < index->cache_nr; cnt++) { for (total = cnt = 0; cnt < index->cache_nr; cnt++) {
struct cache_entry *ce = index->cache[cnt]; const struct cache_entry *ce = index->cache[cnt];
if (ce->ce_flags & (CE_UPDATE | CE_WT_REMOVE)) if (ce->ce_flags & (CE_UPDATE | CE_WT_REMOVE))
total++; total++;
} }
@ -212,7 +212,7 @@ static int check_updates(struct unpack_trees_options *o)
if (o->update) if (o->update)
git_attr_set_direction(GIT_ATTR_CHECKOUT, &o->result); git_attr_set_direction(GIT_ATTR_CHECKOUT, &o->result);
for (i = 0; i < index->cache_nr; i++) { for (i = 0; i < index->cache_nr; i++) {
struct cache_entry *ce = index->cache[i]; const struct cache_entry *ce = index->cache[i];
if (ce->ce_flags & CE_WT_REMOVE) { if (ce->ce_flags & CE_WT_REMOVE) {
display_progress(progress, ++cnt); display_progress(progress, ++cnt);
@ -376,7 +376,7 @@ static struct cache_entry *next_cache_entry(struct unpack_trees_options *o)
return NULL; return NULL;
} }
static void add_same_unmerged(struct cache_entry *ce, static void add_same_unmerged(const struct cache_entry *ce,
struct unpack_trees_options *o) struct unpack_trees_options *o)
{ {
struct index_state *index = o->src_index; struct index_state *index = o->src_index;
@ -650,7 +650,7 @@ static int find_cache_pos(struct traverse_info *info,
int p_len = tree_entry_len(p); int p_len = tree_entry_len(p);
for (pos = o->cache_bottom; pos < index->cache_nr; pos++) { for (pos = o->cache_bottom; pos < index->cache_nr; pos++) {
struct cache_entry *ce = index->cache[pos]; const struct cache_entry *ce = index->cache[pos];
const char *ce_name, *ce_slash; const char *ce_name, *ce_slash;
int cmp, ce_len; int cmp, ce_len;
@ -1353,7 +1353,7 @@ static int verify_clean_subdirectory(const struct cache_entry *ce,
*/ */
static int icase_exists(struct unpack_trees_options *o, const char *name, int len, struct stat *st) static int icase_exists(struct unpack_trees_options *o, const char *name, int len, struct stat *st)
{ {
struct cache_entry *src; const struct cache_entry *src;
src = index_name_exists(o->src_index, name, len, 1); src = index_name_exists(o->src_index, name, len, 1);
return src && !ie_match_stat(o->src_index, src, st, CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE); 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,
enum unpack_trees_error_types error_type, enum unpack_trees_error_types error_type,
struct unpack_trees_options *o) struct unpack_trees_options *o)
{ {
struct cache_entry *result; const struct cache_entry *result;
/* /*
* It may be that the 'lstat()' succeeded even though * It may be that the 'lstat()' succeeded even though

View File

@ -372,7 +372,7 @@ static void wt_status_collect_changed_cb(struct diff_queue_struct *q,
static int unmerged_mask(const char *path) static int unmerged_mask(const char *path)
{ {
int pos, mask; int pos, mask;
struct cache_entry *ce; const struct cache_entry *ce;
pos = cache_name_pos(path, strlen(path)); pos = cache_name_pos(path, strlen(path));
if (0 <= pos) if (0 <= pos)
@ -476,7 +476,7 @@ static void wt_status_collect_changes_initial(struct wt_status *s)
for (i = 0; i < active_nr; i++) { for (i = 0; i < active_nr; i++) {
struct string_list_item *it; struct string_list_item *it;
struct wt_status_change_data *d; struct wt_status_change_data *d;
struct cache_entry *ce = active_cache[i]; const struct cache_entry *ce = active_cache[i];
if (!ce_path_match(ce, &pathspec)) if (!ce_path_match(ce, &pathspec))
continue; continue;