ce_match_stat, run_diff_files: use symbolic constants for readability
ce_match_stat() can be told: (1) to ignore CE_VALID bit (used under "assume unchanged" mode) and perform the stat comparison anyway; (2) not to perform the contents comparison for racily clean entries and report mismatch of cached stat information; using its "option" parameter. Give them symbolic constants. Similarly, run_diff_files() can be told not to report anything on removed paths. Also give it a symbolic constant for that. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Nov 10, 2007 at 00:15 UTC
4bd5b7dacc404e6b733d9ab6744429c5027bb5e1
8 files changed
+57
-34
builtin-apply.c
+1
-1
@@ -2099,7 +2099,7 @@ static int verify_index_match(struct cache_entry *ce, struct stat *st)
2099
return -1;
2100
return 0;
2101
}
2102
- return ce_match_stat(ce, st, 1);
2102
+ return ce_match_stat(ce, st, CE_MATCH_IGNORE_VALID);
2103
}
2104
2105
static int check_patch(struct patch *patch, struct patch *prev_patch)
cache.h
+10
-4
@@ -174,8 +174,8 @@ extern struct index_state the_index;
174
#define remove_file_from_cache(path) remove_file_from_index(&the_index, (path))
175
#define add_file_to_cache(path, verbose) add_file_to_index(&the_index, (path), (verbose))
176
#define refresh_cache(flags) refresh_index(&the_index, (flags), NULL, NULL)
177
-#define ce_match_stat(ce, st, really) ie_match_stat(&the_index, (ce), (st), (really))
178
-#define ce_modified(ce, st, really) ie_modified(&the_index, (ce), (st), (really))
177
+#define ce_match_stat(ce, st, options) ie_match_stat(&the_index, (ce), (st), (options))
178
+#define ce_modified(ce, st, options) ie_modified(&the_index, (ce), (st), (options))
179
#endif
180
181
enum object_type {
@@ -266,8 +266,14 @@ extern int remove_file_from_index(struct index_state *, const char *path);
266
extern int add_file_to_index(struct index_state *, const char *path, int verbose);
267
extern struct cache_entry *make_cache_entry(unsigned int mode, const unsigned char *sha1, const char *path, int stage, int refresh);
268
extern int ce_same_name(struct cache_entry *a, struct cache_entry *b);
269
-extern int ie_match_stat(struct index_state *, struct cache_entry *, struct stat *, int);
270
-extern int ie_modified(struct index_state *, struct cache_entry *, struct stat *, int);
269
+
270
+/* do stat comparison even if CE_VALID is true */
271
+#define CE_MATCH_IGNORE_VALID 01
272
+/* do not check the contents but report dirty on racily-clean entries */
273
+#define CE_MATCH_RACY_IS_DIRTY 02
274
+extern int ie_match_stat(struct index_state *, struct cache_entry *, struct stat *, unsigned int);
275
+extern int ie_modified(struct index_state *, struct cache_entry *, struct stat *, unsigned int);
276
+
277
extern int ce_path_match(const struct cache_entry *ce, const char **pathspec);
278
extern int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, enum object_type type, const char *path);
279
extern int read_fd(int fd, char **return_buf, unsigned long *return_size);
check-racy.c
+1
-1
@@ -18,7 +18,7 @@ int main(int ac, char **av)
18
19
if (ce_match_stat(ce, &st, 0))
20
dirty++;
21
- else if (ce_match_stat(ce, &st, 2))
21
+ else if (ce_match_stat(ce, &st, CE_MATCH_RACY_IS_DIRTY))
22
racy++;
23
else
24
clean++;
diff-lib.c
+9
-7
@@ -173,9 +173,10 @@ static int is_in_index(const char *path)
173
}
174
175
static int handle_diff_files_args(struct rev_info *revs,
176
- int argc, const char **argv, int *silent)
176
+ int argc, const char **argv,
177
+ unsigned int *options)
178
{
178
- *silent = 0;
179
+ *options = 0;
180
181
/* revs->max_count == -2 means --no-index */
182
while (1 < argc && argv[1][0] == '-') {
@@ -192,7 +193,7 @@ static int handle_diff_files_args(struct rev_info *revs,
193
revs->diffopt.no_index = 1;
194
}
195
else if (!strcmp(argv[1], "-q"))
195
- *silent = 1;
196
+ *options |= DIFF_SILENT_ON_REMOVED;
197
else
198
return error("invalid option: %s", argv[1]);
199
argv++; argc--;
@@ -305,9 +306,9 @@ int setup_diff_no_index(struct rev_info *revs,
306
307
int run_diff_files_cmd(struct rev_info *revs, int argc, const char **argv)
308
{
308
- int silent_on_removed;
309
+ unsigned int options;
310
310
- if (handle_diff_files_args(revs, argc, argv, &silent_on_removed))
311
+ if (handle_diff_files_args(revs, argc, argv, &options))
312
return -1;
313
314
if (revs->diffopt.no_index) {
@@ -329,13 +330,14 @@ int run_diff_files_cmd(struct rev_info *revs, int argc, const char **argv)
330
perror("read_cache");
331
return -1;
332
}
332
- return run_diff_files(revs, silent_on_removed);
333
+ return run_diff_files(revs, options);
334
}
335
335
-int run_diff_files(struct rev_info *revs, int silent_on_removed)
336
+int run_diff_files(struct rev_info *revs, unsigned int option)
337
{
338
int entries, i;
339
int diff_unmerged_stage = revs->max_count;
340
+ int silent_on_removed = option & DIFF_SILENT_ON_REMOVED;
341
342
if (diff_unmerged_stage < 0)
343
diff_unmerged_stage = 2;
diff.h
+3
-1
@@ -224,7 +224,9 @@ extern void diff_flush(struct diff_options*);
224
225
extern const char *diff_unique_abbrev(const unsigned char *, int);
226
227
-extern int run_diff_files(struct rev_info *revs, int silent_on_removed);
227
+/* do not report anything on removed paths */
228
+#define DIFF_SILENT_ON_REMOVED 01
229
+extern int run_diff_files(struct rev_info *revs, unsigned int option);
230
extern int setup_diff_no_index(struct rev_info *revs,
231
int argc, const char ** argv, int nongit, const char *prefix);
232
extern int run_diff_files_cmd(struct rev_info *revs, int argc, const char **argv);
entry.c
+1
-1
@@ -200,7 +200,7 @@ int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *t
200
strcpy(path + len, ce->name);
201
202
if (!lstat(path, &st)) {
203
- unsigned changed = ce_match_stat(ce, &st, 1);
203
+ unsigned changed = ce_match_stat(ce, &st, CE_MATCH_IGNORE_VALID);
204
if (!changed)
205
return 0;
206
if (!state->force) {
read-cache.c
+30
-17
@@ -194,11 +194,12 @@ static int ce_match_stat_basic(struct cache_entry *ce, struct stat *st)
194
}
195
196
int ie_match_stat(struct index_state *istate,
197
- struct cache_entry *ce, struct stat *st, int options)
197
+ struct cache_entry *ce, struct stat *st,
198
+ unsigned int options)
199
{
200
unsigned int changed;
200
- int ignore_valid = options & 01;
201
- int assume_racy_is_modified = options & 02;
201
+ int ignore_valid = options & CE_MATCH_IGNORE_VALID;
202
+ int assume_racy_is_modified = options & CE_MATCH_RACY_IS_DIRTY;
203
204
/*
205
* If it's marked as always valid in the index, it's
@@ -238,10 +239,11 @@ int ie_match_stat(struct index_state *istate,
239
}
240
241
int ie_modified(struct index_state *istate,
241
- struct cache_entry *ce, struct stat *st, int really)
242
+ struct cache_entry *ce, struct stat *st, unsigned int options)
243
{
244
int changed, changed_fs;
244
- changed = ie_match_stat(istate, ce, st, really);
245
+
246
+ changed = ie_match_stat(istate, ce, st, options);
247
if (!changed)
248
return 0;
249
/*
@@ -420,7 +422,7 @@ int add_file_to_index(struct index_state *istate, const char *path, int verbose)
422
pos = index_name_pos(istate, ce->name, namelen);
423
if (0 <= pos &&
424
!ce_stage(istate->cache[pos]) &&
423
- !ie_modified(istate, istate->cache[pos], &st, 1)) {
425
+ !ie_modified(istate, istate->cache[pos], &st, CE_MATCH_IGNORE_VALID)) {
426
/* Nothing changed, really */
427
free(ce);
428
return 0;
@@ -782,11 +784,13 @@ int add_index_entry(struct index_state *istate, struct cache_entry *ce, int opti
784
* to link up the stat cache details with the proper files.
785
*/
786
static struct cache_entry *refresh_cache_ent(struct index_state *istate,
785
- struct cache_entry *ce, int really, int *err)
787
+ struct cache_entry *ce,
788
+ unsigned int options, int *err)
789
{
790
struct stat st;
791
struct cache_entry *updated;
792
int changed, size;
793
+ int ignore_valid = options & CE_MATCH_IGNORE_VALID;
794
795
if (lstat(ce->name, &st) < 0) {
796
if (err)
@@ -794,16 +798,23 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate,
798
return NULL;
799
}
800
797
- changed = ie_match_stat(istate, ce, &st, really);
801
+ changed = ie_match_stat(istate, ce, &st, options);
802
if (!changed) {
799
- if (really && assume_unchanged &&
803
+ /*
804
+ * The path is unchanged. If we were told to ignore
805
+ * valid bit, then we did the actual stat check and
806
+ * found that the entry is unmodified. If the entry
807
+ * is not marked VALID, this is the place to mark it
808
+ * valid again, under "assume unchanged" mode.
809
+ */
810
+ if (ignore_valid && assume_unchanged &&
811
!(ce->ce_flags & htons(CE_VALID)))
812
; /* mark this one VALID again */
813
else
814
return ce;
815
}
816
806
- if (ie_modified(istate, ce, &st, really)) {
817
+ if (ie_modified(istate, ce, &st, options)) {
818
if (err)
819
*err = EINVAL;
820
return NULL;
@@ -814,13 +825,14 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate,
825
memcpy(updated, ce, size);
826
fill_stat_cache_info(updated, &st);
827
817
- /* In this case, if really is not set, we should leave
818
- * CE_VALID bit alone. Otherwise, paths marked with
819
- * --no-assume-unchanged (i.e. things to be edited) will
820
- * reacquire CE_VALID bit automatically, which is not
821
- * really what we want.
828
+ /*
829
+ * If ignore_valid is not set, we should leave CE_VALID bit
830
+ * alone. Otherwise, paths marked with --no-assume-unchanged
831
+ * (i.e. things to be edited) will reacquire CE_VALID bit
832
+ * automatically, which is not really what we want.
833
*/
823
- if (!really && assume_unchanged && !(ce->ce_flags & htons(CE_VALID)))
834
+ if (!ignore_valid && assume_unchanged &&
835
+ !(ce->ce_flags & htons(CE_VALID)))
836
updated->ce_flags &= ~htons(CE_VALID);
837
838
return updated;
@@ -834,6 +846,7 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
846
int allow_unmerged = (flags & REFRESH_UNMERGED) != 0;
847
int quiet = (flags & REFRESH_QUIET) != 0;
848
int not_new = (flags & REFRESH_IGNORE_MISSING) != 0;
849
+ unsigned int options = really ? CE_MATCH_IGNORE_VALID : 0;
850
851
for (i = 0; i < istate->cache_nr; i++) {
852
struct cache_entry *ce, *new;
@@ -855,7 +868,7 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
868
if (pathspec && !match_pathspec(pathspec, ce->name, strlen(ce->name), 0, seen))
869
continue;
870
858
- new = refresh_cache_ent(istate, ce, really, &cache_errno);
871
+ new = refresh_cache_ent(istate, ce, options, &cache_errno);
872
if (new == ce)
873
continue;
874
if (!new) {
unpack-trees.c
+2
-2
@@ -406,7 +406,7 @@ static void verify_uptodate(struct cache_entry *ce,
406
return;
407
408
if (!lstat(ce->name, &st)) {
409
- unsigned changed = ce_match_stat(ce, &st, 1);
409
+ unsigned changed = ce_match_stat(ce, &st, CE_MATCH_IGNORE_VALID);
410
if (!changed)
411
return;
412
/*
@@ -927,7 +927,7 @@ int oneway_merge(struct cache_entry **src,
927
if (o->reset) {
928
struct stat st;
929
if (lstat(old->name, &st) ||
930
- ce_match_stat(old, &st, 1))
930
+ ce_match_stat(old, &st, CE_MATCH_IGNORE_VALID))
931
old->ce_flags |= htons(CE_UPDATE);
932
}
933
return keep_entry(old, o);