Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dc2cf3e

Browse files
committed
Merge pull request libgit2#3480 from ethomson/nsecs
Nanoseconds in the index: ignore for diffing
2 parents 44b1e3e + 7499eae commit dc2cf3e

14 files changed

+96
-1
lines changed

src/diff.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,10 @@ static int diff_list_apply_options(
493493

494494
/* Don't set GIT_DIFFCAPS_USE_DEV - compile time option in core git */
495495

496-
/* Set GIT_DIFFCAPS_TRUST_NANOSECS on a platform basis */
496+
/* Don't trust nanoseconds; we do not load nanos from disk */
497+
#ifdef GIT_USE_NSEC
497498
diff->diffcaps = diff->diffcaps | GIT_DIFFCAPS_TRUST_NANOSECS;
499+
#endif
498500

499501
/* If not given explicit `opts`, check `diff.xyz` configs */
500502
if (!opts) {

tests/index/nsec.c

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#include "clar_libgit2.h"
2+
#include "index.h"
3+
#include "git2/sys/index.h"
4+
#include "git2/repository.h"
5+
#include "../reset/reset_helpers.h"
6+
7+
static git_repository *repo;
8+
static git_index *repo_index;
9+
10+
#define TEST_REPO_PATH "nsecs"
11+
12+
// Fixture setup and teardown
13+
void test_index_nsec__initialize(void)
14+
{
15+
repo = cl_git_sandbox_init("nsecs");
16+
git_repository_index(&repo_index, repo);
17+
}
18+
19+
void test_index_nsec__cleanup(void)
20+
{
21+
git_index_free(repo_index);
22+
repo_index = NULL;
23+
24+
cl_git_sandbox_cleanup();
25+
}
26+
27+
static bool has_nsecs(void)
28+
{
29+
const git_index_entry *entry;
30+
size_t i;
31+
bool has_nsecs = false;
32+
33+
for (i = 0; i < git_index_entrycount(repo_index); i++) {
34+
entry = git_index_get_byindex(repo_index, i);
35+
36+
if (entry->ctime.nanoseconds || entry->mtime.nanoseconds) {
37+
has_nsecs = true;
38+
break;
39+
}
40+
}
41+
42+
return has_nsecs;
43+
}
44+
45+
void test_index_nsec__has_nanos(void)
46+
{
47+
cl_assert_equal_b(true, has_nsecs());
48+
}
49+
50+
void test_index_nsec__staging_maintains_other_nanos(void)
51+
{
52+
const git_index_entry *entry;
53+
54+
cl_git_rewritefile("nsecs/a.txt", "This is file A");
55+
cl_git_pass(git_index_add_bypath(repo_index, "a.txt"));
56+
cl_git_pass(git_index_write(repo_index));
57+
58+
cl_git_pass(git_index_write(repo_index));
59+
60+
git_index_read(repo_index, 1);
61+
cl_assert_equal_b(true, has_nsecs());
62+
63+
cl_assert((entry = git_index_get_bypath(repo_index, "a.txt", 0)));
64+
cl_assert_equal_i(0, entry->ctime.nanoseconds);
65+
cl_assert_equal_i(0, entry->mtime.nanoseconds);
66+
}
67+
68+
void test_index_nsec__status_doesnt_clear_nsecs(void)
69+
{
70+
git_status_list *statuslist;
71+
72+
cl_git_pass(git_status_list_new(&statuslist, repo, NULL));
73+
74+
git_index_read(repo_index, 1);
75+
cl_assert_equal_b(true, has_nsecs());
76+
77+
git_status_list_free(statuslist);
78+
}

tests/resources/nsecs/.gitted/HEAD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ref: refs/heads/master

tests/resources/nsecs/.gitted/config

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[core]
2+
repositoryformatversion = 0
3+
filemode = false
4+
bare = false
5+
logallrefupdates = true
6+
symlinks = false
7+
ignorecase = true
8+
hideDotFiles = dotGitOnly

tests/resources/nsecs/.gitted/index

281 Bytes
Binary file not shown.

tests/resources/nsecs/.gitted/objects/03/1986a8372d1442cfe9e3b54906a9aadc524a7e

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
x��A
2+
�0D]��J�4D��Mu-��/�"F�H��F��f��P aʠ�Z�� r�n�X��*�4kU��i�xK-#%�y� Z����2�0�;�Џ;���Ű�J�Z7F����R�B�y�?g�?�<�^@�]f˔G�v��ܵ�N�UOKv
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
031986a8372d1442cfe9e3b54906a9aadc524a7e

tests/resources/nsecs/a.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
File A

tests/resources/nsecs/b.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
File B

tests/resources/nsecs/c.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
File C

0 commit comments

Comments
 (0)