git-cvsimport-script: typo head -> heads
[git/jnareb-git/bp-gitweb.git] / check-files.c
blob6fd69e79d6c253937498c553662ebe832a020449
1 /*
2 * check-files.c
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.
7 * Copyright (C) 2005 Linus Torvalds
8 */
9 #include "cache.h"
11 static void check_file(const char *path)
13 int fd = open(path, O_RDONLY);
14 struct cache_entry *ce;
15 struct stat st;
16 int pos, changed;
18 /* Nonexistent is fine */
19 if (fd < 0) {
20 if (errno != ENOENT)
21 die("%s: %s", path, strerror(errno));
22 return;
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];
31 if (lstat(path, &st) < 0)
32 die("lstat(%s): %s", path, strerror(errno));
34 changed = ce_match_stat(ce, &st);
35 if (changed)
36 die("preparing to update file '%s' not uptodate in cache", path);
39 int main(int argc, char **argv)
41 int i;
43 read_cache();
44 for (i = 1; i < argc ; i++)
45 check_file(argv[i]);
46 return 0;