Skip to content

Commit 4e3949b

Browse files
committed
tests: test that largefiles can be read through the tree API
1 parent cf14215 commit 4e3949b

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed

src/posix.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,23 @@ int p_write(git_file fd, const void *buf, size_t cnt)
216216
return 0;
217217
}
218218

219+
int p_fallocate(int fd, off_t offset, off_t len)
220+
{
221+
#ifdef __APPLE__
222+
fstore_t prealloc;
223+
224+
memset(&prealloc, 0, sizeof(prealloc));
225+
prealloc.fst_flags = F_ALLOCATEALL;
226+
prealloc.fst_posmode = F_PEOFPOSMODE;
227+
prealloc.fst_offset = offset;
228+
prealloc.fst_length = len;
229+
230+
return fcntl(fd, F_PREALLOCATE, &prealloc);
231+
#else
232+
return posix_fallocate(fd, offset, len);
233+
#endif
234+
}
235+
219236
#ifdef NO_MMAP
220237

221238
#include "map.h"

src/posix.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ extern int p_open(const char *path, int flags, ...);
115115
extern int p_creat(const char *path, mode_t mode);
116116
extern int p_getcwd(char *buffer_out, size_t size);
117117
extern int p_rename(const char *from, const char *to);
118+
extern int p_fallocate(int fd, off_t offset, off_t len);
118119

119120
extern int git__page_size(size_t *page_size);
120121
extern int git__mmap_alignment(size_t *page_size);

src/win32/posix_w32.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,12 @@ int p_creat(const char *path, mode_t mode)
516516
return p_open(path, O_WRONLY | O_CREAT | O_TRUNC, mode);
517517
}
518518

519+
int p_fallocate(int fd, off_t offset, off_t len)
520+
{
521+
error = ENOSYS;
522+
return -1;
523+
}
524+
519525
int p_utimes(const char *path, const struct p_timeval times[2])
520526
{
521527
git_win32_path wpath;

tests/object/tree/read.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,56 @@ void test_object_tree_read__two(void)
7373
git_object_free(obj);
7474
git_tree_free(tree);
7575
}
76+
77+
#define BIGFILE "bigfile"
78+
#define BIGFILE_SIZE (off_t)4 * 1024 * 1024 * 1024 /* 4 GiB */
79+
80+
void test_object_tree_read__largefile(void)
81+
{
82+
git_reference *ref;
83+
git_commit *commit;
84+
git_tree *tree;
85+
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;
91+
92+
#ifdef GIT_WIN32
93+
cl_skip();
94+
#endif
95+
96+
if (!cl_is_env_set("GITTEST_INVASIVE_FS_SIZE"))
97+
cl_skip();
98+
99+
cl_git_pass(git_reference_lookup(&ref, g_repo, "refs/heads/master"));
100+
cl_git_pass(git_repository_index(&idx, g_repo));
101+
102+
cl_git_pass(git_buf_puts(&file, git_repository_workdir(g_repo)));
103+
cl_git_pass(git_buf_joinpath(&file, file.ptr, BIGFILE));
104+
105+
fd = p_open(git_buf_cstr(&file), O_CREAT|O_RDWR, 0644);
106+
cl_assert_(fd >= 0, "invalid file descriptor");
107+
108+
cl_must_pass(p_fallocate(fd, 0, BIGFILE_SIZE));
109+
cl_must_pass(p_close(fd));
110+
111+
cl_git_pass(git_index_add_bypath(idx, BIGFILE));
112+
cl_repo_commit_from_index(&oid, g_repo, NULL, 0, "bigfile");
113+
114+
cl_git_pass(git_commit_lookup(&commit, g_repo, &oid));
115+
cl_git_pass(git_commit_tree(&tree, commit));
116+
117+
entry = git_tree_entry_byname(tree, BIGFILE);
118+
cl_assert_(entry, "entry was NULL");
119+
120+
cl_git_pass(git_tree_entry_to_object(&object, g_repo, entry));
121+
122+
git_buf_dispose(&file);
123+
git_object_free(object);
124+
git_tree_free(tree);
125+
git_index_free(idx);
126+
git_commit_free(commit);
127+
git_reference_free(ref);
128+
}

0 commit comments

Comments
 (0)