Skip to content

Commit 004a339

Browse files
committed
Allow bypassing check '.keep' files using libgit2 option 'GIT_OPT_IGNORE_PACK_KEEP_FILE_CHECK'
1 parent 1a107fa commit 004a339

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

include/git2/common.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ typedef enum {
205205
GIT_OPT_SET_ALLOCATOR,
206206
GIT_OPT_ENABLE_UNSAVED_INDEX_SAFETY,
207207
GIT_OPT_GET_PACK_MAX_OBJECTS,
208-
GIT_OPT_SET_PACK_MAX_OBJECTS
208+
GIT_OPT_SET_PACK_MAX_OBJECTS,
209+
GIT_OPT_DISABLE_PACK_KEEP_FILE_CHECKS
209210
} git_libgit2_opt_t;
210211

211212
/**
@@ -395,6 +396,10 @@ typedef enum {
395396
* > Set the maximum number of objects libgit2 will allow in a pack
396397
* > file when downloading a pack file from a remote.
397398
*
399+
* opts(GIT_OPT_DISABLE_PACK_KEEP_FILE_CHECKS, int enabled)
400+
* > This will cause .keep file existence checks to be skipped when
401+
* > accessing packfiles, which can help performance with remote filesystems.
402+
*
398403
* @param option Option key
399404
* @param ... value to set the option
400405
* @return 0 on success, <0 on failure

src/pack.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
#include <zlib.h>
1818

19+
/* Option to bypass checking existence of '.keep' files */
20+
bool git_disable_pack_keep_file_checks = false;
21+
1922
static int packfile_open(struct git_pack_file *p);
2023
static git_off_t nth_packed_object_offset(const struct git_pack_file *p, uint32_t n);
2124
static int packfile_unpack_compressed(
@@ -1141,9 +1144,11 @@ int git_packfile_alloc(struct git_pack_file **pack_out, const char *path)
11411144
if (git__suffixcmp(path, ".idx") == 0) {
11421145
size_t root_len = path_len - strlen(".idx");
11431146

1144-
memcpy(p->pack_name + root_len, ".keep", sizeof(".keep"));
1145-
if (git_path_exists(p->pack_name) == true)
1146-
p->pack_keep = 1;
1147+
if (!git_disable_pack_keep_file_checks) {
1148+
memcpy(p->pack_name + root_len, ".keep", sizeof(".keep"));
1149+
if (git_path_exists(p->pack_name) == true)
1150+
p->pack_keep = 1;
1151+
}
11471152

11481153
memcpy(p->pack_name + root_len, ".pack", sizeof(".pack"));
11491154
}

src/settings.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ int git_libgit2_features(void)
5757
extern size_t git_mwindow__window_size;
5858
extern size_t git_mwindow__mapped_limit;
5959
extern size_t git_indexer__max_objects;
60+
extern bool git_disable_pack_keep_file_checks;
6061

6162
static int config_level_to_sysdir(int config_level)
6263
{
@@ -279,6 +280,10 @@ int git_libgit2_opts(int key, ...)
279280
*(va_arg(ap, size_t *)) = git_indexer__max_objects;
280281
break;
281282

283+
case GIT_OPT_DISABLE_PACK_KEEP_FILE_CHECKS:
284+
git_disable_pack_keep_file_checks = (va_arg(ap, int) != 0);
285+
break;
286+
282287
default:
283288
git_error_set(GIT_ERROR_INVALID, "invalid option key");
284289
error = -1;

tests/pack/packbuilder.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ static git_vector _commits;
1414
static int _commits_is_initialized;
1515
static git_transfer_progress _stats;
1616

17+
extern bool git_disable_pack_keep_file_checks;
18+
1719
void test_pack_packbuilder__initialize(void)
1820
{
1921
_repo = cl_git_sandbox_init("testrepo.git");
@@ -32,6 +34,7 @@ void test_pack_packbuilder__cleanup(void)
3234
unsigned int i;
3335

3436
cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_FSYNC_GITDIR, 0));
37+
cl_git_pass(git_libgit2_opts(GIT_OPT_DISABLE_PACK_KEEP_FILE_CHECKS, false));
3538

3639
if (_commits_is_initialized) {
3740
_commits_is_initialized = 0;
@@ -260,3 +263,10 @@ void test_pack_packbuilder__foreach_with_cancel(void)
260263
git_packbuilder_foreach(_packbuilder, foreach_cancel_cb, idx), -1111);
261264
git_indexer_free(idx);
262265
}
266+
267+
void test_pack_packbuilder__keep_file_check(void)
268+
{
269+
assert(!git_disable_pack_keep_file_checks);
270+
cl_git_pass(git_libgit2_opts(GIT_OPT_DISABLE_PACK_KEEP_FILE_CHECKS, true));
271+
assert(git_disable_pack_keep_file_checks);
272+
}

0 commit comments

Comments
 (0)