+
Skip to content

Add GIT_TEST_MULTI_PACK_INDEX environment variable #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions builtin/repack.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
char *fname, *fname_old;

if (!midx_cleared) {
/* if we move a packfile, it will invalidated the midx */
clear_midx_file(get_object_directory());
clear_midx_file(the_repository);
midx_cleared = 1;
}

Expand Down Expand Up @@ -554,6 +553,10 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
if (!no_update_server_info)
update_server_info(0);
remove_temporary_files();

if (git_env_bool(GIT_TEST_MULTI_PACK_INDEX, 0))
write_midx_file(get_object_directory());

string_list_clear(&names, 0);
string_list_clear(&rollback, 0);
string_list_clear(&existing_packs, 0);
Expand Down
26 changes: 20 additions & 6 deletions midx.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,21 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local
return NULL;
}

static void close_midx(struct multi_pack_index *m)
void close_midx(struct multi_pack_index *m)
{
uint32_t i;

if (!m)
return;

munmap((unsigned char *)m->data, m->data_len);
close(m->fd);
m->fd = -1;

for (i = 0; i < m->num_packs; i++) {
if (m->packs[i]) {
close_pack(m->packs[i]);
free(m->packs);
free(m->packs[i]);
}
}
FREE_AND_NULL(m->packs);
Expand Down Expand Up @@ -331,9 +335,14 @@ int prepare_multi_pack_index_one(struct repository *r, const char *object_dir, i
struct multi_pack_index *m;
struct multi_pack_index *m_search;
int config_value;
static int env_value = -1;

if (repo_config_get_bool(r, "core.multipackindex", &config_value) ||
!config_value)
if (env_value < 0)
env_value = git_env_bool(GIT_TEST_MULTI_PACK_INDEX, 0);

if (!env_value &&
(repo_config_get_bool(r, "core.multipackindex", &config_value) ||
!config_value))
return 0;

for (m_search = r->objects->multi_pack_index; m_search; m_search = m_search->next)
Expand Down Expand Up @@ -914,9 +923,14 @@ int write_midx_file(const char *object_dir)
return 0;
}

void clear_midx_file(const char *object_dir)
void clear_midx_file(struct repository *r)
{
char *midx = get_midx_filename(object_dir);
char *midx = get_midx_filename(r->objects->objectdir);

if (r->objects && r->objects->multi_pack_index) {
close_midx(r->objects->multi_pack_index);
r->objects->multi_pack_index = NULL;
}

if (remove_path(midx)) {
UNLEAK(midx);
Expand Down
6 changes: 5 additions & 1 deletion midx.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "repository.h"

#define GIT_TEST_MULTI_PACK_INDEX "GIT_TEST_MULTI_PACK_INDEX"

struct multi_pack_index {
struct multi_pack_index *next;

Expand Down Expand Up @@ -42,7 +44,9 @@ int midx_contains_pack(struct multi_pack_index *m, const char *idx_name);
int prepare_multi_pack_index_one(struct repository *r, const char *object_dir, int local);

int write_midx_file(const char *object_dir);
void clear_midx_file(const char *object_dir);
void clear_midx_file(struct repository *r);
int verify_midx_file(const char *object_dir);

void close_midx(struct multi_pack_index *m);

#endif
4 changes: 4 additions & 0 deletions t/README
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,10 @@ GIT_TEST_COMMIT_GRAPH=<boolean>, when true, forces the commit-graph to
be written after every 'git commit' command, and overrides the
'core.commitGraph' setting to true.

GIT_TEST_MULTI_PACK_INDEX=<boolean>, when true, forces the multi-pack-
index to be written after every 'git repack' command, and overrides the
'core.multiPackIndex' setting to true.

Naming Tests
------------

Expand Down
1 change: 1 addition & 0 deletions t/t5310-pack-bitmaps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ test_expect_success 'pack-objects respects --honor-pack-keep (local bitmapped pa

test_expect_success 'pack-objects respects --local (non-local bitmapped pack)' '
mv .git/objects/pack/$packbitmap.* alt.git/objects/pack/ &&
rm -f .git/objects/pack/multi-pack-index &&
test_when_finished "mv alt.git/objects/pack/$packbitmap.* .git/objects/pack/" &&
echo HEAD | git pack-objects --local --stdout --revs >3b.pack &&
git index-pack 3b.pack &&
Expand Down
2 changes: 1 addition & 1 deletion t/t5319-multi-pack-index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ test_expect_success 'git-fsck incorrect offset' '

test_expect_success 'repack removes multi-pack-index' '
test_path_is_file $objdir/pack/multi-pack-index &&
git repack -adf &&
GIT_TEST_MULTI_PACK_INDEX=0 git repack -adf &&
test_path_is_missing $objdir/pack/multi-pack-index
'

Expand Down
2 changes: 1 addition & 1 deletion t/t9300-fast-import.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1558,7 +1558,7 @@ test_expect_success 'O: blank lines not necessary after other commands' '
INPUT_END

git fast-import <input &&
test 8 = $(find .git/objects/pack -type f | wc -l) &&
test 8 = $(find .git/objects/pack -type f | grep -v multi-pack-index | wc -l) &&
test $(git rev-parse refs/tags/O3-2nd) = $(git rev-parse O3^) &&
git log --reverse --pretty=oneline O3 | sed s/^.*z// >actual &&
test_cmp expect actual
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载