Re: [PATCH 18/19] update-index: test the system before enabling untracked cache
On Wed, Oct 29, 2014 at 12:37 AM, Torsten Bögershausen tbo...@web.de wrote: On 2014-10-27 13.10, Nguyễn Thái Ngọc Duy wrote: [] +static void xmkdir(const char *path) +{ + if (mkdir(path, 0700)) + die_errno(_(failed to create directory %s), path); +} Does it makes sense to ignore EINTR and do a retry ? Another question is if the function could be called mkdir_or_die() instead? I realized that there are 2 families of xfunc() in wrapper.c, some die, some retry. This is only used interactively, I think it's ok to ignore EINTR as long as we report clearly the case (and hope the user to re-enter the command) -- Duy -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 18/19] update-index: test the system before enabling untracked cache
Torsten Bögershausen tbo...@web.de writes: On 2014-10-27 13.10, Nguyễn Thái Ngọc Duy wrote: [] +static void xmkdir(const char *path) +{ +if (mkdir(path, 0700)) +die_errno(_(failed to create directory %s), path); +} Does it makes sense to ignore EINTR and do a retry ? Another question is if the function could be called mkdir_or_die() instead? Probably. It is in the same league as xread() and xwrite(). I realized that there are 2 families of xfunc() in wrapper.c, some die, some retry. The general idea of wrapper.c is to free callers from coding something they have only one sensible choice for. The ones that retry such as xread() and xwrite() are to free callers from diagnosing and retrying upon EAGAIN/EINTR because they want to read or write and there is no other thing they want to do. The ones that die such as xmkstemp() are for the failure modes that are likely without any other choice. xcalloc() and other allocators started as (and still are) the latter, but instead of immediately dying they know a last-ditch effort that is common to all Git operations. -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 18/19] update-index: test the system before enabling untracked cache
On 2014-10-27 13.10, Nguyễn Thái Ngọc Duy wrote: [] +static void xmkdir(const char *path) +{ + if (mkdir(path, 0700)) + die_errno(_(failed to create directory %s), path); +} Does it makes sense to ignore EINTR and do a retry ? Another question is if the function could be called mkdir_or_die() instead? I realized that there are 2 families of xfunc() in wrapper.c, some die, some retry. -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 18/19] update-index: test the system before enabling untracked cache
On Mon, Oct 27, 2014 at 8:10 AM, Nguyễn Thái Ngọc Duy pclo...@gmail.com wrote: Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- diff --git a/builtin/update-index.c b/builtin/update-index.c index e57e2d7..471c0b4 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -48,6 +48,145 @@ static void report(const char *fmt, ...) va_end(vp); } +static int test_if_untracked_cache_is_supported(void) +{ + struct stat st; + struct stat_data base; + int fd; + + fprintf(stderr, _(Testing )); + xmkdir(dir-mtime-test); + atexit(remove_test_directory); + xstat(dir-mtime-test, st); + fill_stat_data(base, st); + fputc('.', stderr); + + avoid_racy(); + fd = create_file(dir-mtime-test/newfile); + xstat(dir-mtime-test, st); + if (!match_stat_data(base, st)) { close(fd); + fputc('\n', stderr); + fprintf_ln(stderr,_(directory stat info does not + change after adding a new file)); + return 0; + } + fill_stat_data(base, st); + fputc('.', stderr); + + avoid_racy(); + xmkdir(dir-mtime-test/new-dir); + xstat(dir-mtime-test, st); + if (!match_stat_data(base, st)) { close(fd); + fputc('\n', stderr); + fprintf_ln(stderr, _(directory stat info does not change +after adding a new directory)); + return 0; + } + fill_stat_data(base, st); + fputc('.', stderr); + + avoid_racy(); + write_or_die(fd, data, 4); + close(fd); + xstat(dir-mtime-test, st); + if (match_stat_data(base, st)) { + fputc('\n', stderr); + fprintf_ln(stderr, _(directory stat info changes +after updating a file)); + return 0; + } + fputc('.', stderr); + + avoid_racy(); + close(create_file(dir-mtime-test/new-dir/new)); + xstat(dir-mtime-test, st); + if (match_stat_data(base, st)) { + fputc('\n', stderr); + fprintf_ln(stderr, _(directory stat info changes after +adding a file inside subdirectory)); + return 0; + } + fputc('.', stderr); + + avoid_racy(); + xunlink(dir-mtime-test/newfile); + xstat(dir-mtime-test, st); + if (!match_stat_data(base, st)) { + fputc('\n', stderr); + fprintf_ln(stderr, _(directory stat info does not +change after deleting a file)); + return 0; + } + fill_stat_data(base, st); + fputc('.', stderr); + + avoid_racy(); + xunlink(dir-mtime-test/new-dir/new); + xrmdir(dir-mtime-test/new-dir); + xstat(dir-mtime-test, st); + if (!match_stat_data(base, st)) { + fputc('\n', stderr); + fprintf_ln(stderr, _(directory stat info does not +change after deleting a directory)); + return 0; + } + + xrmdir(dir-mtime-test); + fprintf_ln(stderr, _( OK)); + return 1; +} -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 18/19] update-index: test the system before enabling untracked cache
Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com --- Documentation/git-update-index.txt | 6 ++ builtin/update-index.c | 146 + 2 files changed, 152 insertions(+) diff --git a/Documentation/git-update-index.txt b/Documentation/git-update-index.txt index 16f2686..fab1fea 100644 --- a/Documentation/git-update-index.txt +++ b/Documentation/git-update-index.txt @@ -180,6 +180,12 @@ may not support it yet. system must change `st_mtime` field of a directory if files are added or deleted in that directory. +--force-untracked-cache:: + For safety, `--untracked-cache` performs tests on the working + directory to make sure untracked cache can be used. These + tests can take a few seconds. `--force-untracked-cache` can be + used to skip the tests. + \--:: Do not interpret any more arguments as options. diff --git a/builtin/update-index.c b/builtin/update-index.c index e57e2d7..471c0b4 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -48,6 +48,145 @@ static void report(const char *fmt, ...) va_end(vp); } +static void remove_test_directory(void) +{ + struct strbuf sb = STRBUF_INIT; + strbuf_addstr(sb, dir-mtime-test); + remove_dir_recursively(sb, 0); + strbuf_release(sb); +} + +static void xmkdir(const char *path) +{ + if (mkdir(path, 0700)) + die_errno(_(failed to create directory %s), path); +} + +static int xstat(const char *path, struct stat *st) +{ + if (stat(path, st)) + die_errno(_(failed to stat %s), path); + return 0; +} + +static int create_file(const char *path) +{ + int 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) +{ + if (unlink(path)) + die_errno(_(failed to delete file %s), path); +} + +static void xrmdir(const char *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; + + fprintf(stderr, _(Testing )); + xmkdir(dir-mtime-test); + atexit(remove_test_directory); + xstat(dir-mtime-test, st); + fill_stat_data(base, st); + fputc('.', stderr); + + avoid_racy(); + fd = create_file(dir-mtime-test/newfile); + xstat(dir-mtime-test, st); + if (!match_stat_data(base, st)) { + fputc('\n', stderr); + fprintf_ln(stderr,_(directory stat info does not + change after adding a new file)); + return 0; + } + fill_stat_data(base, st); + fputc('.', stderr); + + avoid_racy(); + xmkdir(dir-mtime-test/new-dir); + xstat(dir-mtime-test, st); + if (!match_stat_data(base, st)) { + fputc('\n', stderr); + fprintf_ln(stderr, _(directory stat info does not change +after adding a new directory)); + return 0; + } + fill_stat_data(base, st); + fputc('.', stderr); + + avoid_racy(); + write_or_die(fd, data, 4); + close(fd); + xstat(dir-mtime-test, st); + if (match_stat_data(base, st)) { + fputc('\n', stderr); + fprintf_ln(stderr, _(directory stat info changes +after updating a file)); + return 0; + } + fputc('.', stderr); + + avoid_racy(); + close(create_file(dir-mtime-test/new-dir/new)); + xstat(dir-mtime-test, st); + if (match_stat_data(base, st)) { + fputc('\n', stderr); + fprintf_ln(stderr, _(directory stat info changes after +adding a file inside subdirectory)); + return 0; + } + fputc('.', stderr); + + avoid_racy(); + xunlink(dir-mtime-test/newfile); + xstat(dir-mtime-test, st); + if (!match_stat_data(base, st)) { + fputc('\n', stderr); + fprintf_ln(stderr, _(directory stat info does not +change after deleting a file)); + return 0; + } + fill_stat_data(base, st); + fputc('.', stderr); + + avoid_racy(); + xunlink(dir-mtime-test/new-dir/new); + xrmdir(dir-mtime-test/new-dir); + xstat(dir-mtime-test, st); + if (!match_stat_data(base, st)) { + fputc('\n', stderr); +