Skip to content

Commit 42f7740

Browse files
author
Junio C Hamano
committed
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 <[email protected]>
1 parent 520cd3e commit 42f7740

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,11 @@ PROGRAMS = \
194194
git-update-server-info$X \
195195
git-upload-pack$X git-verify-pack$X \
196196
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 =
198202

199203
BUILT_INS = \
200204
git-format-patch$X git-show$X git-whatchanged$X \

check-racy.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,11 @@ static int ce_match_stat_basic(struct cache_entry *ce, struct stat *st)
169169
return changed;
170170
}
171171

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)
173173
{
174174
unsigned int changed;
175+
int ignore_valid = options & 01;
176+
int assume_racy_is_modified = options & 02;
175177

176178
/*
177179
* 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)
200202
*/
201203
if (!changed &&
202204
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+
}
205211

206212
return changed;
207213
}

0 commit comments

Comments
 (0)