Add check program "git-check-racy"
This will help counting the racily clean paths, but it should be useless for daily use. Do not even enable it in the makefile. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Aug 15, 2006 at 21:38 UTC
42f774063db1442fc3815f596d263f90dcd8380b
3 files changed
+42
-4
Makefile
+5
-1
@@ -194,7 +194,11 @@ PROGRAMS = \
194
git-update-server-info$X \
195
git-upload-pack$X git-verify-pack$X \
196
git-pack-redundant$X git-var$X \
197
- git-describe$X git-merge-tree$X git-blame$X git-imap-send$X
197
+ git-describe$X git-merge-tree$X git-blame$X git-imap-send$X \
198
+ $(EXTRA_PROGRAMS)
199
+
200
+# Empty...
201
+EXTRA_PROGRAMS =
202
203
BUILT_INS = \
204
git-format-patch$X git-show$X git-whatchanged$X \
check-racy.c
new
+28
@@ -0,0 +1,28 @@
1
+#include "cache.h"
2
+
3
+int main(int ac, char **av)
4
+{
5
+ int i;
6
+ int dirty, clean, racy;
7
+
8
+ dirty = clean = racy = 0;
9
+ read_cache();
10
+ for (i = 0; i < active_nr; i++) {
11
+ struct cache_entry *ce = active_cache[i];
12
+ struct stat st;
13
+
14
+ if (lstat(ce->name, &st)) {
15
+ error("lstat(%s): %s", ce->name, strerror(errno));
16
+ continue;
17
+ }
18
+
19
+ if (ce_match_stat(ce, &st, 0))
20
+ dirty++;
21
+ else if (ce_match_stat(ce, &st, 2))
22
+ racy++;
23
+ else
24
+ clean++;
25
+ }
26
+ printf("dirty %d, clean %d, racy %d\n", dirty, clean, racy);
27
+ return 0;
28
+}
read-cache.c
+9
-3
@@ -169,9 +169,11 @@ static int ce_match_stat_basic(struct cache_entry *ce, struct stat *st)
169
return changed;
170
}
171
172
-int ce_match_stat(struct cache_entry *ce, struct stat *st, int ignore_valid)
172
+int ce_match_stat(struct cache_entry *ce, struct stat *st, int options)
173
{
174
unsigned int changed;
175
+ int ignore_valid = options & 01;
176
+ int assume_racy_is_modified = options & 02;
177
178
/*
179
* If it's marked as always valid in the index, it's
@@ -200,8 +202,12 @@ int ce_match_stat(struct cache_entry *ce, struct stat *st, int ignore_valid)
202
*/
203
if (!changed &&
204
index_file_timestamp &&
203
- index_file_timestamp <= ntohl(ce->ce_mtime.sec))
204
- changed |= ce_modified_check_fs(ce, st);
205
+ index_file_timestamp <= ntohl(ce->ce_mtime.sec)) {
206
+ if (assume_racy_is_modified)
207
+ changed |= DATA_CHANGED;
208
+ else
209
+ changed |= ce_modified_check_fs(ce, st);
210
+ }
211
212
return changed;
213
}