*
* Copyright (C) Linus Torvalds, 2005
*/
-#include <signal.h>
#include "cache.h"
/*
* Default to not allowing changes to the list of files. The
* tool doesn't actually care, but this makes it harder to add
* files to the revision control by mistake by doing something
- * like "update-cache *" and suddenly having all the object
+ * like "git-update-cache *" and suddenly having all the object
* files be revision controlled.
*/
static int allow_add = 0, allow_remove = 0, allow_replace = 0, not_new = 0;
return (unsigned long)ptr > (unsigned long)-1000L;
}
-/*
- * This only updates the "non-critical" parts of the directory
- * cache, ie the parts that aren't tracked by GIT, and only used
- * to validate the cache.
- */
-static void fill_stat_cache_info(struct cache_entry *ce, struct stat *st)
-{
- ce->ce_ctime.sec = htonl(st->st_ctime);
- ce->ce_mtime.sec = htonl(st->st_mtime);
-#ifdef NSEC
- ce->ce_ctime.nsec = htonl(st->st_ctim.tv_nsec);
- ce->ce_mtime.nsec = htonl(st->st_mtim.tv_nsec);
-#endif
- ce->ce_dev = htonl(st->st_dev);
- ce->ce_ino = htonl(st->st_ino);
- ce->ce_uid = htonl(st->st_uid);
- ce->ce_gid = htonl(st->st_gid);
- ce->ce_size = htonl(st->st_size);
-}
-
static int add_file_to_cache(char *path)
{
int size, namelen, option, status;
* file that hasn't been changed but where the stat entry is
* out of date.
*
- * For example, you'd want to do this after doing a "read-tree",
+ * For example, you'd want to do this after doing a "git-read-tree",
* to link up the stat cache details with the proper files.
*/
static struct cache_entry *refresh_entry(struct cache_entry *ce)
return add_cache_entry(ce, option);
}
-static const char *lockfile_name = NULL;
-
-static void remove_lock_file(void)
-{
- if (lockfile_name)
- unlink(lockfile_name);
-}
-
-static void remove_lock_file_on_signal(int signo)
-{
- remove_lock_file();
-}
+struct cache_file cache_file;
int main(int argc, char **argv)
{
int i, newfd, entries, has_errors = 0;
int allow_options = 1;
- static char lockfile[MAXPATHLEN+1];
- const char *indexfile = get_index_file();
-
- snprintf(lockfile, sizeof(lockfile), "%s.lock", indexfile);
- newfd = open(lockfile, O_RDWR | O_CREAT | O_EXCL, 0600);
+ newfd = hold_index_file_for_update(&cache_file, get_index_file());
if (newfd < 0)
die("unable to create new cachefile");
- signal(SIGINT, remove_lock_file_on_signal);
- atexit(remove_lock_file);
- lockfile_name = lockfile;
-
entries = read_cache();
if (entries < 0)
die("cache corrupted");
}
if (!strcmp(path, "--cacheinfo")) {
if (i+3 >= argc)
- die("update-cache: --cacheinfo <mode> <sha1> <path>");
+ die("git-update-cache: --cacheinfo <mode> <sha1> <path>");
if (add_cacheinfo(argv[i+1], argv[i+2], argv[i+3]))
- die("update-cache: --cacheinfo cannot add %s", argv[i+3]);
+ die("git-update-cache: --cacheinfo cannot add %s", argv[i+3]);
i += 3;
continue;
}
if (!strcmp(path, "--force-remove")) {
if (argc <= i + 1)
- die("update-cache: --force-remove <path>");
+ die("git-update-cache: --force-remove <path>");
if (remove_file_from_cache(argv[i+1]))
- die("update-cache: --force-remove cannot remove %s", argv[i+1]);
+ die("git-update-cache: --force-remove cannot remove %s", argv[i+1]);
i++;
continue;
}
if (add_file_to_cache(path))
die("Unable to add %s to database", path);
}
- if (write_cache(newfd, active_cache, active_nr) || rename(lockfile, indexfile))
+ if (write_cache(newfd, active_cache, active_nr) ||
+ commit_index_file(&cache_file))
die("Unable to write new cachefile");
- lockfile_name = NULL;
return has_errors ? 1 : 0;
}