Unverified Commit 48005936 by Edward Thomson Committed by GitHub

Merge pull request #4965 from hackworks/eliminate-check-for-keep-file

Allow bypassing check for '.keep' file
parents b8837827 004a3398
...@@ -205,7 +205,8 @@ typedef enum { ...@@ -205,7 +205,8 @@ typedef enum {
GIT_OPT_SET_ALLOCATOR, GIT_OPT_SET_ALLOCATOR,
GIT_OPT_ENABLE_UNSAVED_INDEX_SAFETY, GIT_OPT_ENABLE_UNSAVED_INDEX_SAFETY,
GIT_OPT_GET_PACK_MAX_OBJECTS, GIT_OPT_GET_PACK_MAX_OBJECTS,
GIT_OPT_SET_PACK_MAX_OBJECTS GIT_OPT_SET_PACK_MAX_OBJECTS,
GIT_OPT_DISABLE_PACK_KEEP_FILE_CHECKS
} git_libgit2_opt_t; } git_libgit2_opt_t;
/** /**
...@@ -395,6 +396,10 @@ typedef enum { ...@@ -395,6 +396,10 @@ typedef enum {
* > Set the maximum number of objects libgit2 will allow in a pack * > Set the maximum number of objects libgit2 will allow in a pack
* > file when downloading a pack file from a remote. * > file when downloading a pack file from a remote.
* *
* opts(GIT_OPT_DISABLE_PACK_KEEP_FILE_CHECKS, int enabled)
* > This will cause .keep file existence checks to be skipped when
* > accessing packfiles, which can help performance with remote filesystems.
*
* @param option Option key * @param option Option key
* @param ... value to set the option * @param ... value to set the option
* @return 0 on success, <0 on failure * @return 0 on success, <0 on failure
......
...@@ -16,6 +16,9 @@ ...@@ -16,6 +16,9 @@
#include <zlib.h> #include <zlib.h>
/* Option to bypass checking existence of '.keep' files */
bool git_disable_pack_keep_file_checks = false;
static int packfile_open(struct git_pack_file *p); static int packfile_open(struct git_pack_file *p);
static git_off_t nth_packed_object_offset(const struct git_pack_file *p, uint32_t n); static git_off_t nth_packed_object_offset(const struct git_pack_file *p, uint32_t n);
static int packfile_unpack_compressed( static int packfile_unpack_compressed(
...@@ -1141,9 +1144,11 @@ int git_packfile_alloc(struct git_pack_file **pack_out, const char *path) ...@@ -1141,9 +1144,11 @@ int git_packfile_alloc(struct git_pack_file **pack_out, const char *path)
if (git__suffixcmp(path, ".idx") == 0) { if (git__suffixcmp(path, ".idx") == 0) {
size_t root_len = path_len - strlen(".idx"); size_t root_len = path_len - strlen(".idx");
memcpy(p->pack_name + root_len, ".keep", sizeof(".keep")); if (!git_disable_pack_keep_file_checks) {
if (git_path_exists(p->pack_name) == true) memcpy(p->pack_name + root_len, ".keep", sizeof(".keep"));
p->pack_keep = 1; if (git_path_exists(p->pack_name) == true)
p->pack_keep = 1;
}
memcpy(p->pack_name + root_len, ".pack", sizeof(".pack")); memcpy(p->pack_name + root_len, ".pack", sizeof(".pack"));
} }
......
...@@ -57,6 +57,7 @@ int git_libgit2_features(void) ...@@ -57,6 +57,7 @@ int git_libgit2_features(void)
extern size_t git_mwindow__window_size; extern size_t git_mwindow__window_size;
extern size_t git_mwindow__mapped_limit; extern size_t git_mwindow__mapped_limit;
extern size_t git_indexer__max_objects; extern size_t git_indexer__max_objects;
extern bool git_disable_pack_keep_file_checks;
static int config_level_to_sysdir(int config_level) static int config_level_to_sysdir(int config_level)
{ {
...@@ -279,6 +280,10 @@ int git_libgit2_opts(int key, ...) ...@@ -279,6 +280,10 @@ int git_libgit2_opts(int key, ...)
*(va_arg(ap, size_t *)) = git_indexer__max_objects; *(va_arg(ap, size_t *)) = git_indexer__max_objects;
break; break;
case GIT_OPT_DISABLE_PACK_KEEP_FILE_CHECKS:
git_disable_pack_keep_file_checks = (va_arg(ap, int) != 0);
break;
default: default:
git_error_set(GIT_ERROR_INVALID, "invalid option key"); git_error_set(GIT_ERROR_INVALID, "invalid option key");
error = -1; error = -1;
......
...@@ -14,6 +14,8 @@ static git_vector _commits; ...@@ -14,6 +14,8 @@ static git_vector _commits;
static int _commits_is_initialized; static int _commits_is_initialized;
static git_transfer_progress _stats; static git_transfer_progress _stats;
extern bool git_disable_pack_keep_file_checks;
void test_pack_packbuilder__initialize(void) void test_pack_packbuilder__initialize(void)
{ {
_repo = cl_git_sandbox_init("testrepo.git"); _repo = cl_git_sandbox_init("testrepo.git");
...@@ -32,6 +34,7 @@ void test_pack_packbuilder__cleanup(void) ...@@ -32,6 +34,7 @@ void test_pack_packbuilder__cleanup(void)
unsigned int i; unsigned int i;
cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_FSYNC_GITDIR, 0)); cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_FSYNC_GITDIR, 0));
cl_git_pass(git_libgit2_opts(GIT_OPT_DISABLE_PACK_KEEP_FILE_CHECKS, false));
if (_commits_is_initialized) { if (_commits_is_initialized) {
_commits_is_initialized = 0; _commits_is_initialized = 0;
...@@ -260,3 +263,10 @@ void test_pack_packbuilder__foreach_with_cancel(void) ...@@ -260,3 +263,10 @@ void test_pack_packbuilder__foreach_with_cancel(void)
git_packbuilder_foreach(_packbuilder, foreach_cancel_cb, idx), -1111); git_packbuilder_foreach(_packbuilder, foreach_cancel_cb, idx), -1111);
git_indexer_free(idx); git_indexer_free(idx);
} }
void test_pack_packbuilder__keep_file_check(void)
{
assert(!git_disable_pack_keep_file_checks);
cl_git_pass(git_libgit2_opts(GIT_OPT_DISABLE_PACK_KEEP_FILE_CHECKS, true));
assert(git_disable_pack_keep_file_checks);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment