Files
libgit2/tests/pack/filelimit.c
lhchavez 9679df5736 mwindow: set limit on number of open files
There are some cases in which repositories accrue a large number of
packfiles. The existing mwindow limit applies only to the total size of
mmap'd files, not on their number. This leads to a situation in which
having lots of small packfiles could exhaust the allowed number of open
files, particularly on macOS, where the default ulimit is very low
(256).

This change adds a new configuration parameter
(GIT_OPT_SET_MWINDOW_FILE_LIMIT) that sets the maximum number of open
packfiles, with a default of 128. This is low enough so that even macOS
users should not hit it during normal use.

Based on PR #5386, originally written by @josharian.

Fixes: #2758
2020-06-21 07:15:26 -07:00

37 lines
1015 B
C

#include "clar_libgit2.h"
#include <git2.h>
void test_pack_filelimit__open_repo_with_1025_packfiles(void)
{
git_repository *repo;
git_revwalk *walk;
git_oid id;
int i;
/*
* This repository contains 1025 packfiles, each with one commit, one tree,
* and two blobs. The first blob (README.md) has the same content in all
* commits, but the second one (file.txt) has a different content in each
* commit.
*/
cl_git_pass(git_repository_open(&repo, cl_fixture("1025.git")));
cl_git_pass(git_revwalk_new(&walk, repo));
cl_git_pass(git_revwalk_sorting(walk, GIT_SORT_TOPOLOGICAL));
cl_git_pass(git_revwalk_push_ref(walk, "refs/heads/master"));
/*
* Walking the tree requires opening each of the 1025 packfiles. This should
* work in all platforms, including those where the default limit of open
* file descriptors is small (e.g. 256 in macOS).
*/
i = 0;
while (git_revwalk_next(&id, walk) == 0)
++i;
cl_assert_equal_i(1025, i);
git_revwalk_free(walk);
git_repository_free(repo);
}