Skip to content

Commit 2576272

Browse files
bradkinggitster
authored andcommitted
read-cache.c: extend make_cache_entry refresh flag with options
Convert the make_cache_entry boolean 'refresh' argument to a more general 'refresh_options' argument. Pass the value through to the underlying refresh_cache_ent call. Add option CE_MATCH_REFRESH to enable stat refresh. Update call sites to use the new signature. Signed-off-by: Brad King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2e2e7ec commit 2576272

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

cache.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ extern int remove_file_from_index(struct index_state *, const char *path);
477477
#define ADD_CACHE_IMPLICIT_DOT 32 /* internal to "git add -u/-A" */
478478
extern int add_to_index(struct index_state *, const char *path, struct stat *, int flags);
479479
extern int add_file_to_index(struct index_state *, const char *path, int flags);
480-
extern struct cache_entry *make_cache_entry(unsigned int mode, const unsigned char *sha1, const char *path, int stage, int refresh);
480+
extern struct cache_entry *make_cache_entry(unsigned int mode, const unsigned char *sha1, const char *path, int stage, unsigned int refresh_options);
481481
extern int ce_same_name(const struct cache_entry *a, const struct cache_entry *b);
482482
extern int index_name_is_other(const struct index_state *, const char *, int);
483483
extern void *read_blob_data_from_index(struct index_state *, const char *, unsigned long *);
@@ -490,6 +490,8 @@ extern void *read_blob_data_from_index(struct index_state *, const char *, unsig
490490
#define CE_MATCH_IGNORE_SKIP_WORKTREE 04
491491
/* ignore non-existent files during stat update */
492492
#define CE_MATCH_IGNORE_MISSING 0x08
493+
/* enable stat refresh */
494+
#define CE_MATCH_REFRESH 0x10
493495
extern int ie_match_stat(const struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
494496
extern int ie_modified(const struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
495497

merge-recursive.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ static int add_cacheinfo(unsigned int mode, const unsigned char *sha1,
201201
const char *path, int stage, int refresh, int options)
202202
{
203203
struct cache_entry *ce;
204-
ce = make_cache_entry(mode, sha1 ? sha1 : null_sha1, path, stage, refresh);
204+
ce = make_cache_entry(mode, sha1 ? sha1 : null_sha1, path, stage,
205+
(refresh ? CE_MATCH_REFRESH : 0 ));
205206
if (!ce)
206207
return error(_("addinfo_cache failed for path '%s'"), path);
207208
return add_cache_entry(ce, options);

read-cache.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
#include "strbuf.h"
1616
#include "varint.h"
1717

18-
static struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int really);
18+
static struct cache_entry *refresh_cache_entry(struct cache_entry *ce,
19+
unsigned int options);
1920

2021
/* Mask for the name length in ce_flags in the on-disk index */
2122

@@ -696,7 +697,7 @@ int add_file_to_index(struct index_state *istate, const char *path, int flags)
696697

697698
struct cache_entry *make_cache_entry(unsigned int mode,
698699
const unsigned char *sha1, const char *path, int stage,
699-
int refresh)
700+
unsigned int refresh_options)
700701
{
701702
int size, len;
702703
struct cache_entry *ce;
@@ -716,10 +717,7 @@ struct cache_entry *make_cache_entry(unsigned int mode,
716717
ce->ce_namelen = len;
717718
ce->ce_mode = create_ce_mode(mode);
718719

719-
if (refresh)
720-
return refresh_cache_entry(ce, 0);
721-
722-
return ce;
720+
return refresh_cache_entry(ce, refresh_options);
723721
}
724722

725723
int ce_same_name(const struct cache_entry *a, const struct cache_entry *b)
@@ -1029,11 +1027,12 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate,
10291027
struct stat st;
10301028
struct cache_entry *updated;
10311029
int changed, size;
1030+
int refresh = options & CE_MATCH_REFRESH;
10321031
int ignore_valid = options & CE_MATCH_IGNORE_VALID;
10331032
int ignore_skip_worktree = options & CE_MATCH_IGNORE_SKIP_WORKTREE;
10341033
int ignore_missing = options & CE_MATCH_IGNORE_MISSING;
10351034

1036-
if (ce_uptodate(ce))
1035+
if (!refresh || ce_uptodate(ce))
10371036
return ce;
10381037

10391038
/*
@@ -1129,7 +1128,8 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
11291128
int ignore_submodules = (flags & REFRESH_IGNORE_SUBMODULES) != 0;
11301129
int first = 1;
11311130
int in_porcelain = (flags & REFRESH_IN_PORCELAIN);
1132-
unsigned int options = ((really ? CE_MATCH_IGNORE_VALID : 0) |
1131+
unsigned int options = (CE_MATCH_REFRESH |
1132+
(really ? CE_MATCH_IGNORE_VALID : 0) |
11331133
(not_new ? CE_MATCH_IGNORE_MISSING : 0));
11341134
const char *modified_fmt;
11351135
const char *deleted_fmt;
@@ -1208,9 +1208,10 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
12081208
return has_errors;
12091209
}
12101210

1211-
static struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int really)
1211+
static struct cache_entry *refresh_cache_entry(struct cache_entry *ce,
1212+
unsigned int options)
12121213
{
1213-
return refresh_cache_ent(&the_index, ce, really, NULL, NULL);
1214+
return refresh_cache_ent(&the_index, ce, options, NULL, NULL);
12141215
}
12151216

12161217

0 commit comments

Comments
 (0)