/*
* GIT - The information manager from hell
*
* Copyright (C) Linus Torvalds, 2005
*/
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "config.h"
#include "lockfile.h"
#include "quote.h"
#include "cache-tree.h"
#include "tree-walk.h"
#include "builtin.h"
#include "refs.h"
#include "resolve-undo.h"
#include "parse-options.h"
#include "pathspec.h"
#include "dir.h"
#include "split-index.h"
#include "fsmonitor.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 "git update-index *" and suddenly having all the object
* files be revision controlled.
*/
static int allow_add;
static int allow_remove;
static int allow_replace;
static int info_only;
static int force_remove;
static int verbose;
static int mark_valid_only;
static int mark_skip_worktree_only;
static int mark_fsmonitor_only;
static int ignore_skip_worktree_entries;
#define MARK_FLAG 1
#define UNMARK_FLAG 2
static struct strbuf mtime_dir = STRBUF_INIT;
/* Untracked cache mode */
enum uc_mode {
UC_UNSPECIFIED = -1,
UC_DISABLE = 0,
UC_ENABLE,
UC_TEST,
UC_FORCE
};
__attribute__((format (printf, 1, 2)))
static void report(const char *fmt, ...)
{
va_list vp;
if (!verbose)
return;
va_start(vp, fmt);
vprintf(fmt, vp);
putchar('\n');
va_end(vp);
}
static void remove_test_directory(void)
{
if (mtime_dir.len)
remove_dir_recursively(&mtime_dir, 0);
}
static const char *get_mtime_path(const char *path)
{
static struct strbuf sb = STRBUF_INIT;
strbuf_reset(&sb);
strbuf_addf(&sb, "%s/%s", mtime_dir.buf, path);
return sb.buf;
}
static void xmkdir(const char *path)
{
path = get_mtime_path(path);
if (mkdir(path, 0700))
die_errno(_("failed to create directory %s"), path);
}
static int xstat_mtime_dir(struct stat *st)
{
if (stat(mtime_dir.buf, st))
die_errno(_("failed to stat %s"), mtime_dir.buf);
return 0;
}
static int create_file(const char *path)
{
int fd;
path = get_mtime_path(path);
fd = open(path, O_CREAT | O_RDWR, 0644);
if (fd < 0)
die_errno(_("failed to create file %s"), path);
return fd;
}
static void xunlink(const char *path)
{
path = get_mtime_path(path);
if (unlink(path))
die_errno(_("failed to delete file %s"), path);
}
static void xrmdir(const char *path)
{
path = get_mtime_path(path);
if (rmdir(path))
die_errno(_("failed to delete directory %s"), path);
}
static void avoid_racy(void)
{
/*
* not use if we could usleep(10) if USE_NSEC is defined. The
* field nsec could be there, but the OS could choose to
* ignore it?
*/
sleep(1);
}
static int test_if_untracked_cache_is_supported(void)
{
struct stat st;
struct stat_data base;
int fd, ret = 0;
char *cwd;
strbuf_addstr(&mtime_dir, "mtime-test-XXXXXX");
if (!mkdtemp(mtime_dir.buf))
|