Do a cross-project merge of Paul Mackerras' gitk visualizer
[git/git.git] / check-files.c
1 /*
2 * check-files.c
3 *
4 * Check that a set of files are up-to-date in the filesystem or
5 * do not exist. Used to verify a patch target before doing a patch.
6 *
7 * Copyright (C) 2005 Linus Torvalds
8 */
9 #include "cache.h"
10
11 static void check_file(const char *path)
12 {
13 int fd = open(path, O_RDONLY);
14 struct cache_entry *ce;
15 struct stat st;
16 int pos, changed;
17
18 /* Nonexistent is fine */
19 if (fd < 0) {
20 if (errno != ENOENT)
21 die("%s: %s", path, strerror(errno));
22 return;
23 }
24
25 /* Exists but is not in the cache is not fine */
26 pos = cache_name_pos(path, strlen(path));
27 if (pos < 0)
28 die("preparing to update existing file '%s' not in cache", path);
29 ce = active_cache[pos];
30
31 if (lstat(path, &st) < 0)
32 die("lstat(%s): %s", path, strerror(errno));
33
34 changed = ce_match_stat(ce, &st);
35 if (changed)
36 die("preparing to update file '%s' not uptodate in cache", path);
37 }
38
39 int main(int argc, char **argv)
40 {
41 int i;
42
43 read_cache();
44 for (i = 1; i < argc ; i++)
45 check_file(argv[i]);
46 return 0;
47 }