Skip to content

Commit 0c2d0d4

Browse files
committed
tests: object: refactor largefile test to not use p_fallocate
The `p_fallocate` platform is currently in use in our tests, only, but it proved to be quite burdensome to get it implemented in a cross-platform way. The only "real" user is the test object::tree::read::largefile, where it's used to allocate a large file in the filesystem only to commit it to the repo and read its object back again. We can simplify this quite a bit by just using an in-memory buffer of 4GB. Sure, this cannot be used on platforms with low resources. But creating 4GB files is not any better, and we already skip the test if the environment variable "GITTEST_INVASIVE_FS_SIZE" is not set. So we're arguably not worse off than before.
1 parent c3179ef commit 0c2d0d4

File tree

1 file changed

+15
-25
lines changed

1 file changed

+15
-25
lines changed

tests/object/tree/read.c

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -79,46 +79,36 @@ void test_object_tree_read__two(void)
7979

8080
void test_object_tree_read__largefile(void)
8181
{
82-
git_reference *ref;
82+
const git_tree_entry *entry;
83+
git_index_entry ie;
8384
git_commit *commit;
85+
git_object *object;
86+
git_index *index;
8487
git_tree *tree;
8588
git_oid oid;
86-
const git_tree_entry *entry;
87-
git_object *object;
88-
git_buf file = GIT_BUF_INIT;
89-
int fd;
90-
git_index *idx;
89+
char *buf;
9190

9291
if (!cl_is_env_set("GITTEST_INVASIVE_FS_SIZE"))
9392
cl_skip();
9493

95-
cl_git_pass(git_reference_lookup(&ref, g_repo, "refs/heads/master"));
96-
cl_git_pass(git_repository_index(&idx, g_repo));
94+
cl_assert(buf = git__calloc(1, BIGFILE_SIZE));
9795

98-
cl_git_pass(git_buf_puts(&file, git_repository_workdir(g_repo)));
99-
cl_git_pass(git_buf_joinpath(&file, file.ptr, BIGFILE));
96+
memset(&ie, 0, sizeof(ie));
97+
ie.mode = GIT_FILEMODE_BLOB;
98+
ie.path = BIGFILE;
10099

101-
fd = p_open(git_buf_cstr(&file), O_CREAT|O_RDWR, 0644);
102-
cl_assert_(fd >= 0, "invalid file descriptor");
103-
104-
cl_must_pass(p_fallocate(fd, 0, BIGFILE_SIZE));
105-
cl_must_pass(p_close(fd));
106-
107-
cl_git_pass(git_index_add_bypath(idx, BIGFILE));
108-
cl_repo_commit_from_index(&oid, g_repo, NULL, 0, "bigfile");
100+
cl_git_pass(git_repository_index(&index, g_repo));
101+
cl_git_pass(git_index_add_frombuffer(index, &ie, buf, BIGFILE_SIZE));
102+
cl_repo_commit_from_index(&oid, g_repo, NULL, 0, BIGFILE);
109103

110104
cl_git_pass(git_commit_lookup(&commit, g_repo, &oid));
111105
cl_git_pass(git_commit_tree(&tree, commit));
112-
113-
entry = git_tree_entry_byname(tree, BIGFILE);
114-
cl_assert_(entry, "entry was NULL");
115-
106+
cl_assert(entry = git_tree_entry_byname(tree, BIGFILE));
116107
cl_git_pass(git_tree_entry_to_object(&object, g_repo, entry));
117108

118-
git_buf_dispose(&file);
119109
git_object_free(object);
120110
git_tree_free(tree);
121-
git_index_free(idx);
111+
git_index_free(index);
122112
git_commit_free(commit);
123-
git_reference_free(ref);
113+
git__free(buf);
124114
}

0 commit comments

Comments
 (0)