Skip to content

Commit

Permalink
read-cache: mark cache_entry pointers const
Browse files Browse the repository at this point in the history
ie_match_stat and ie_modified only derefence their struct cache_entry
pointers for reading.  Add const to the parameter declaration here and
do the same for the static helper function used by them, as it's the
same there as well.  This allows callers to pass in const pointers.

Signed-off-by: René Scharfe <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
René Scharfe authored and gitster committed Jun 2, 2013
1 parent 20d142b commit 21a6b9f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,8 @@ extern void *read_blob_data_from_index(struct index_state *, const char *, unsig
#define CE_MATCH_RACY_IS_DIRTY 02
/* do stat comparison even if CE_SKIP_WORKTREE is true */
#define CE_MATCH_IGNORE_SKIP_WORKTREE 04
extern int ie_match_stat(const struct index_state *, struct cache_entry *, struct stat *, unsigned int);
extern int ie_modified(const struct index_state *, struct cache_entry *, struct stat *, unsigned int);
extern int ie_match_stat(const struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
extern int ie_modified(const struct index_state *, const struct cache_entry *, struct stat *, unsigned int);

#define PATHSPEC_ONESTAR 1 /* the pathspec pattern sastisfies GFNM_ONESTAR */

Expand Down
18 changes: 10 additions & 8 deletions read-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void fill_stat_cache_info(struct cache_entry *ce, struct stat *st)
ce_mark_uptodate(ce);
}

static int ce_compare_data(struct cache_entry *ce, struct stat *st)
static int ce_compare_data(const struct cache_entry *ce, struct stat *st)
{
int match = -1;
int fd = open(ce->name, O_RDONLY);
Expand All @@ -105,7 +105,7 @@ static int ce_compare_data(struct cache_entry *ce, struct stat *st)
return match;
}

static int ce_compare_link(struct cache_entry *ce, size_t expected_size)
static int ce_compare_link(const struct cache_entry *ce, size_t expected_size)
{
int match = -1;
void *buffer;
Expand All @@ -126,7 +126,7 @@ static int ce_compare_link(struct cache_entry *ce, size_t expected_size)
return match;
}

static int ce_compare_gitlink(struct cache_entry *ce)
static int ce_compare_gitlink(const struct cache_entry *ce)
{
unsigned char sha1[20];

Expand All @@ -143,7 +143,7 @@ static int ce_compare_gitlink(struct cache_entry *ce)
return hashcmp(sha1, ce->sha1);
}

static int ce_modified_check_fs(struct cache_entry *ce, struct stat *st)
static int ce_modified_check_fs(const struct cache_entry *ce, struct stat *st)
{
switch (st->st_mode & S_IFMT) {
case S_IFREG:
Expand All @@ -163,7 +163,7 @@ static int ce_modified_check_fs(struct cache_entry *ce, struct stat *st)
return 0;
}

static int ce_match_stat_basic(struct cache_entry *ce, struct stat *st)
static int ce_match_stat_basic(const struct cache_entry *ce, struct stat *st)
{
unsigned int changed = 0;

Expand Down Expand Up @@ -239,7 +239,8 @@ static int ce_match_stat_basic(struct cache_entry *ce, struct stat *st)
return changed;
}

static int is_racy_timestamp(const struct index_state *istate, struct cache_entry *ce)
static int is_racy_timestamp(const struct index_state *istate,
const struct cache_entry *ce)
{
return (!S_ISGITLINK(ce->ce_mode) &&
istate->timestamp.sec &&
Expand All @@ -255,7 +256,7 @@ static int is_racy_timestamp(const struct index_state *istate, struct cache_entr
}

int ie_match_stat(const struct index_state *istate,
struct cache_entry *ce, struct stat *st,
const struct cache_entry *ce, struct stat *st,
unsigned int options)
{
unsigned int changed;
Expand Down Expand Up @@ -311,7 +312,8 @@ int ie_match_stat(const struct index_state *istate,
}

int ie_modified(const struct index_state *istate,
struct cache_entry *ce, struct stat *st, unsigned int options)
const struct cache_entry *ce,
struct stat *st, unsigned int options)
{
int changed, changed_fs;

Expand Down

0 comments on commit 21a6b9f

Please sign in to comment.