Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b139fe0

Browse files
committed
repo: support the preciousObjects extension
libgit2 implicitly supports precious objects, since there's no gc command, nor even any option in our object database functionality to delete an object from the odb. In the future, when we support deleting objects, or a gc functionality, we will need to honor the preciousObjects extension and reject those APIs when it is set. In the meantime, since users cannot use libgit2 (directly) to delete an object, we can simply add this to our allowlist.
1 parent 403a03b commit b139fe0

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

src/libgit2/repository.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,6 +1881,7 @@ static const char *builtin_extensions[] = {
18811881
"noop",
18821882
"objectformat",
18831883
"worktreeconfig",
1884+
"preciousobjects"
18841885
};
18851886

18861887
static git_vector user_extensions = { 0, git__strcmp_cb };

tests/libgit2/core/opts.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ void test_core_opts__extensions_query(void)
3434

3535
cl_git_pass(git_libgit2_opts(GIT_OPT_GET_EXTENSIONS, &out));
3636

37-
cl_assert_equal_sz(out.count, 3);
37+
cl_assert_equal_sz(out.count, 4);
3838
cl_assert_equal_s("noop", out.strings[0]);
3939
cl_assert_equal_s("objectformat", out.strings[1]);
40-
cl_assert_equal_s("worktreeconfig", out.strings[2]);
40+
cl_assert_equal_s("preciousobjects", out.strings[2]);
41+
cl_assert_equal_s("worktreeconfig", out.strings[3]);
4142

4243
git_strarray_dispose(&out);
4344
}
@@ -50,11 +51,12 @@ void test_core_opts__extensions_add(void)
5051
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_EXTENSIONS, in, ARRAY_SIZE(in)));
5152
cl_git_pass(git_libgit2_opts(GIT_OPT_GET_EXTENSIONS, &out));
5253

53-
cl_assert_equal_sz(out.count, 4);
54+
cl_assert_equal_sz(out.count, 5);
5455
cl_assert_equal_s("foo", out.strings[0]);
5556
cl_assert_equal_s("noop", out.strings[1]);
5657
cl_assert_equal_s("objectformat", out.strings[2]);
57-
cl_assert_equal_s("worktreeconfig", out.strings[3]);
58+
cl_assert_equal_s("preciousobjects", out.strings[3]);
59+
cl_assert_equal_s("worktreeconfig", out.strings[4]);
5860

5961
git_strarray_dispose(&out);
6062
}
@@ -67,11 +69,12 @@ void test_core_opts__extensions_remove(void)
6769
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_EXTENSIONS, in, ARRAY_SIZE(in)));
6870
cl_git_pass(git_libgit2_opts(GIT_OPT_GET_EXTENSIONS, &out));
6971

70-
cl_assert_equal_sz(out.count, 4);
72+
cl_assert_equal_sz(out.count, 5);
7173
cl_assert_equal_s("bar", out.strings[0]);
7274
cl_assert_equal_s("baz", out.strings[1]);
7375
cl_assert_equal_s("objectformat", out.strings[2]);
74-
cl_assert_equal_s("worktreeconfig", out.strings[3]);
76+
cl_assert_equal_s("preciousobjects", out.strings[3]);
77+
cl_assert_equal_s("worktreeconfig", out.strings[4]);
7578

7679
git_strarray_dispose(&out);
7780
}
@@ -84,12 +87,13 @@ void test_core_opts__extensions_uniq(void)
8487
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_EXTENSIONS, in, ARRAY_SIZE(in)));
8588
cl_git_pass(git_libgit2_opts(GIT_OPT_GET_EXTENSIONS, &out));
8689

87-
cl_assert_equal_sz(out.count, 5);
90+
cl_assert_equal_sz(out.count, 6);
8891
cl_assert_equal_s("bar", out.strings[0]);
8992
cl_assert_equal_s("foo", out.strings[1]);
9093
cl_assert_equal_s("noop", out.strings[2]);
9194
cl_assert_equal_s("objectformat", out.strings[3]);
92-
cl_assert_equal_s("worktreeconfig", out.strings[4]);
95+
cl_assert_equal_s("preciousobjects", out.strings[4]);
96+
cl_assert_equal_s("worktreeconfig", out.strings[5]);
9397

9498
git_strarray_dispose(&out);
9599
}

tests/libgit2/repo/extensions.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,13 @@ void test_repo_extensions__adds_extension(void)
7070
cl_assert(git__suffixcmp(git_repository_path(extended), "/") == 0);
7171
git_repository_free(extended);
7272
}
73+
74+
void test_repo_extensions__preciousobjects(void)
75+
{
76+
git_repository *extended = NULL;
77+
78+
cl_repo_set_string(repo, "extensions.preciousObjects", "true");
79+
80+
cl_git_pass(git_repository_open(&extended, "empty_bare.git"));
81+
git_repository_free(extended);
82+
}

0 commit comments

Comments
 (0)