From 99a09f7f18f321c2a37e483bcd8aeb6dff781abc Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Thu, 22 Oct 2015 09:29:40 -0400 Subject: index: test that we round-trip nsecs Test that nanoseconds are round-tripped correctly when we read an index file that contains them. We should, however, ignore them because we don't understand them, and any new entries in the index should contain a `0` nsecs field, while existing preserving entries. --- tests/index/nsec.c | 78 +++++++++++++++++++++ tests/resources/nsecs/.gitted/HEAD | 1 + tests/resources/nsecs/.gitted/config | 8 +++ tests/resources/nsecs/.gitted/index | Bin 0 -> 281 bytes .../03/1986a8372d1442cfe9e3b54906a9aadc524a7e | 2 + .../03/9afd91c98f82c14e425bb6796d8ca98e9c8cac | Bin 0 -> 102 bytes .../6d/8b18077cc99abd8dda05a6062c646406abb2d4 | Bin 0 -> 22 bytes .../c5/12b6c64656b87ea8caf37a32bc5a562d797745 | Bin 0 -> 22 bytes .../df/78d3d51c369e1d2f1eadb73464aadd931d56b4 | Bin 0 -> 22 bytes tests/resources/nsecs/.gitted/refs/heads/master | 1 + tests/resources/nsecs/a.txt | 1 + tests/resources/nsecs/b.txt | 1 + tests/resources/nsecs/c.txt | 1 + 13 files changed, 93 insertions(+) create mode 100644 tests/index/nsec.c create mode 100644 tests/resources/nsecs/.gitted/HEAD create mode 100644 tests/resources/nsecs/.gitted/config create mode 100644 tests/resources/nsecs/.gitted/index create mode 100644 tests/resources/nsecs/.gitted/objects/03/1986a8372d1442cfe9e3b54906a9aadc524a7e create mode 100644 tests/resources/nsecs/.gitted/objects/03/9afd91c98f82c14e425bb6796d8ca98e9c8cac create mode 100644 tests/resources/nsecs/.gitted/objects/6d/8b18077cc99abd8dda05a6062c646406abb2d4 create mode 100644 tests/resources/nsecs/.gitted/objects/c5/12b6c64656b87ea8caf37a32bc5a562d797745 create mode 100644 tests/resources/nsecs/.gitted/objects/df/78d3d51c369e1d2f1eadb73464aadd931d56b4 create mode 100644 tests/resources/nsecs/.gitted/refs/heads/master create mode 100644 tests/resources/nsecs/a.txt create mode 100644 tests/resources/nsecs/b.txt create mode 100644 tests/resources/nsecs/c.txt diff --git a/tests/index/nsec.c b/tests/index/nsec.c new file mode 100644 index 000000000..5004339f0 --- /dev/null +++ b/tests/index/nsec.c @@ -0,0 +1,78 @@ +#include "clar_libgit2.h" +#include "index.h" +#include "git2/sys/index.h" +#include "git2/repository.h" +#include "../reset/reset_helpers.h" + +static git_repository *repo; +static git_index *repo_index; + +#define TEST_REPO_PATH "nsecs" + +// Fixture setup and teardown +void test_index_nsec__initialize(void) +{ + repo = cl_git_sandbox_init("nsecs"); + git_repository_index(&repo_index, repo); +} + +void test_index_nsec__cleanup(void) +{ + git_index_free(repo_index); + repo_index = NULL; + + cl_git_sandbox_cleanup(); +} + +static bool has_nsecs(void) +{ + const git_index_entry *entry; + size_t i; + bool has_nsecs = false; + + for (i = 0; i < git_index_entrycount(repo_index); i++) { + entry = git_index_get_byindex(repo_index, i); + + if (entry->ctime.nanoseconds || entry->mtime.nanoseconds) { + has_nsecs = true; + break; + } + } + + return has_nsecs; +} + +void test_index_nsec__has_nanos(void) +{ + cl_assert_equal_b(true, has_nsecs()); +} + +void test_index_nsec__staging_maintains_other_nanos(void) +{ + const git_index_entry *entry; + + cl_git_rewritefile("nsecs/a.txt", "This is file A"); + cl_git_pass(git_index_add_bypath(repo_index, "a.txt")); + cl_git_pass(git_index_write(repo_index)); + + cl_git_pass(git_index_write(repo_index)); + + git_index_read(repo_index, 1); + cl_assert_equal_b(true, has_nsecs()); + + cl_assert((entry = git_index_get_bypath(repo_index, "a.txt", 0))); + cl_assert_equal_i(0, entry->ctime.nanoseconds); + cl_assert_equal_i(0, entry->mtime.nanoseconds); +} + +void test_index_nsec__status_doesnt_clear_nsecs(void) +{ + git_status_list *statuslist; + + cl_git_pass(git_status_list_new(&statuslist, repo, NULL)); + + git_index_read(repo_index, 1); + cl_assert_equal_b(true, has_nsecs()); + + git_status_list_free(statuslist); +} diff --git a/tests/resources/nsecs/.gitted/HEAD b/tests/resources/nsecs/.gitted/HEAD new file mode 100644 index 000000000..cb089cd89 --- /dev/null +++ b/tests/resources/nsecs/.gitted/HEAD @@ -0,0 +1 @@ +ref: refs/heads/master diff --git a/tests/resources/nsecs/.gitted/config b/tests/resources/nsecs/.gitted/config new file mode 100644 index 000000000..78387c50b --- /dev/null +++ b/tests/resources/nsecs/.gitted/config @@ -0,0 +1,8 @@ +[core] + repositoryformatversion = 0 + filemode = false + bare = false + logallrefupdates = true + symlinks = false + ignorecase = true + hideDotFiles = dotGitOnly diff --git a/tests/resources/nsecs/.gitted/index b/tests/resources/nsecs/.gitted/index new file mode 100644 index 000000000..9233f1b11 Binary files /dev/null and b/tests/resources/nsecs/.gitted/index differ diff --git a/tests/resources/nsecs/.gitted/objects/03/1986a8372d1442cfe9e3b54906a9aadc524a7e b/tests/resources/nsecs/.gitted/objects/03/1986a8372d1442cfe9e3b54906a9aadc524a7e new file mode 100644 index 000000000..a813b7424 --- /dev/null +++ b/tests/resources/nsecs/.gitted/objects/03/1986a8372d1442cfe9e3b54906a9aadc524a7e @@ -0,0 +1,2 @@ +xA +0D]J4DMu-/"FHFf P aʠZ rnX*4kUixK-#%y Z20;Џ; ŰJZ7FRBy?g?<^@]f˔GvܵNUOKv \ No newline at end of file diff --git a/tests/resources/nsecs/.gitted/objects/03/9afd91c98f82c14e425bb6796d8ca98e9c8cac b/tests/resources/nsecs/.gitted/objects/03/9afd91c98f82c14e425bb6796d8ca98e9c8cac new file mode 100644 index 000000000..74bb7d3fe Binary files /dev/null and b/tests/resources/nsecs/.gitted/objects/03/9afd91c98f82c14e425bb6796d8ca98e9c8cac differ diff --git a/tests/resources/nsecs/.gitted/objects/6d/8b18077cc99abd8dda05a6062c646406abb2d4 b/tests/resources/nsecs/.gitted/objects/6d/8b18077cc99abd8dda05a6062c646406abb2d4 new file mode 100644 index 000000000..7bf3a956c Binary files /dev/null and b/tests/resources/nsecs/.gitted/objects/6d/8b18077cc99abd8dda05a6062c646406abb2d4 differ diff --git a/tests/resources/nsecs/.gitted/objects/c5/12b6c64656b87ea8caf37a32bc5a562d797745 b/tests/resources/nsecs/.gitted/objects/c5/12b6c64656b87ea8caf37a32bc5a562d797745 new file mode 100644 index 000000000..dcf4c8ccb Binary files /dev/null and b/tests/resources/nsecs/.gitted/objects/c5/12b6c64656b87ea8caf37a32bc5a562d797745 differ diff --git a/tests/resources/nsecs/.gitted/objects/df/78d3d51c369e1d2f1eadb73464aadd931d56b4 b/tests/resources/nsecs/.gitted/objects/df/78d3d51c369e1d2f1eadb73464aadd931d56b4 new file mode 100644 index 000000000..df45d3314 Binary files /dev/null and b/tests/resources/nsecs/.gitted/objects/df/78d3d51c369e1d2f1eadb73464aadd931d56b4 differ diff --git a/tests/resources/nsecs/.gitted/refs/heads/master b/tests/resources/nsecs/.gitted/refs/heads/master new file mode 100644 index 000000000..3dda65b65 --- /dev/null +++ b/tests/resources/nsecs/.gitted/refs/heads/master @@ -0,0 +1 @@ +031986a8372d1442cfe9e3b54906a9aadc524a7e diff --git a/tests/resources/nsecs/a.txt b/tests/resources/nsecs/a.txt new file mode 100644 index 000000000..be4c1ee68 --- /dev/null +++ b/tests/resources/nsecs/a.txt @@ -0,0 +1 @@ +File A diff --git a/tests/resources/nsecs/b.txt b/tests/resources/nsecs/b.txt new file mode 100644 index 000000000..19a0af40f --- /dev/null +++ b/tests/resources/nsecs/b.txt @@ -0,0 +1 @@ +File B diff --git a/tests/resources/nsecs/c.txt b/tests/resources/nsecs/c.txt new file mode 100644 index 000000000..31d776008 --- /dev/null +++ b/tests/resources/nsecs/c.txt @@ -0,0 +1 @@ +File C -- cgit v1.2.1 From 7499eae98aaf15805882c3db16b661d76260af79 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Thu, 22 Oct 2015 09:30:41 -0400 Subject: diff: ignore nsecs when diffing Although our index contains the literal time present in the index, we do not read nanoseconds from disk, and thus we should not use them in any comparisons, lest we always think our working directory is dirty. Guard this behind a `GIT_USE_NSECS` for future improvement. --- src/diff.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/diff.c b/src/diff.c index d97dcd9d2..d98a28966 100644 --- a/src/diff.c +++ b/src/diff.c @@ -493,8 +493,10 @@ static int diff_list_apply_options( /* Don't set GIT_DIFFCAPS_USE_DEV - compile time option in core git */ - /* Set GIT_DIFFCAPS_TRUST_NANOSECS on a platform basis */ + /* Don't trust nanoseconds; we do not load nanos from disk */ +#ifdef GIT_USE_NSEC diff->diffcaps = diff->diffcaps | GIT_DIFFCAPS_TRUST_NANOSECS; +#endif /* If not given explicit `opts`, check `diff.xyz` configs */ if (!opts) { -- cgit v1.2.1