Skip to content

Commit c4d2522

Browse files
derrickstoleegitster
authored andcommitted
config: create core.multiPackIndex setting
The core.multiPackIndex config setting controls the multi-pack- index (MIDX) feature. If false, the setting will disable all reads from the multi-pack-index file. Read this config setting in the new prepare_multi_pack_index_one() which is called during prepare_packed_git(). This check is run once per repository. Add comparison commands in t5319-multi-pack-index.sh to check typical Git behavior remains the same as the config setting is turned on and off. This currently includes 'git rev-list' and 'git log' commands to trigger several object database reads. Currently, these would only catch an error in the prepare_multi_pack_index_one(), but with later commits will catch errors in object lookups, abbreviations, and approximate object counts. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 662148c commit c4d2522

File tree

6 files changed

+85
-14
lines changed

6 files changed

+85
-14
lines changed

Documentation/config.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,11 @@ core.commitGraph::
908908
Enable git commit graph feature. Allows reading from the
909909
commit-graph file.
910910

911+
core.multiPackIndex::
912+
Use the multi-pack-index file to track multiple packfiles using a
913+
single index. See link:technical/multi-pack-index.html[the
914+
multi-pack-index design document].
915+
911916
core.sparseCheckout::
912917
Enable "sparse checkout" feature. See section "Sparse checkout" in
913918
linkgit:git-read-tree[1] for more information.

midx.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "cache.h"
2+
#include "config.h"
23
#include "csum-file.h"
34
#include "dir.h"
45
#include "lockfile.h"
@@ -177,6 +178,30 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir)
177178
return NULL;
178179
}
179180

181+
int prepare_multi_pack_index_one(struct repository *r, const char *object_dir)
182+
{
183+
struct multi_pack_index *m = r->objects->multi_pack_index;
184+
struct multi_pack_index *m_search;
185+
int config_value;
186+
187+
if (repo_config_get_bool(r, "core.multipackindex", &config_value) ||
188+
!config_value)
189+
return 0;
190+
191+
for (m_search = m; m_search; m_search = m_search->next)
192+
if (!strcmp(object_dir, m_search->object_dir))
193+
return 1;
194+
195+
r->objects->multi_pack_index = load_multi_pack_index(object_dir);
196+
197+
if (r->objects->multi_pack_index) {
198+
r->objects->multi_pack_index->next = m;
199+
return 1;
200+
}
201+
202+
return 0;
203+
}
204+
180205
static size_t write_midx_header(struct hashfile *f,
181206
unsigned char num_chunks,
182207
uint32_t num_packs)

midx.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
#ifndef __MIDX_H__
22
#define __MIDX_H__
33

4+
#include "repository.h"
5+
46
struct multi_pack_index {
7+
struct multi_pack_index *next;
8+
59
int fd;
610

711
const unsigned char *data;
@@ -25,6 +29,7 @@ struct multi_pack_index {
2529
};
2630

2731
struct multi_pack_index *load_multi_pack_index(const char *object_dir);
32+
int prepare_multi_pack_index_one(struct repository *r, const char *object_dir);
2833

2934
int write_midx_file(const char *object_dir);
3035

object-store.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ struct raw_object_store {
105105
*/
106106
struct oidmap *replace_map;
107107

108+
/*
109+
* private data
110+
*
111+
* should only be accessed directly by packfile.c and midx.c
112+
*/
113+
struct multi_pack_index *multi_pack_index;
114+
108115
/*
109116
* private data
110117
*

packfile.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "tree-walk.h"
1616
#include "tree.h"
1717
#include "object-store.h"
18+
#include "midx.h"
1819

1920
char *odb_pack_name(struct strbuf *buf,
2021
const unsigned char *sha1,
@@ -935,10 +936,13 @@ static void prepare_packed_git(struct repository *r)
935936

936937
if (r->objects->packed_git_initialized)
937938
return;
939+
prepare_multi_pack_index_one(r, r->objects->objectdir);
938940
prepare_packed_git_one(r, r->objects->objectdir, 1);
939941
prepare_alt_odb(r);
940-
for (alt = r->objects->alt_odb_list; alt; alt = alt->next)
942+
for (alt = r->objects->alt_odb_list; alt; alt = alt->next) {
943+
prepare_multi_pack_index_one(r, alt->path);
941944
prepare_packed_git_one(r, alt->path, 0);
945+
}
942946
rearrange_packed_git(r);
943947
prepare_packed_git_mru(r);
944948
r->objects->packed_git_initialized = 1;

t/t5319-multi-pack-index.sh

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
test_description='multi-pack-indexes'
44
. ./test-lib.sh
55

6+
objdir=.git/objects
7+
68
midx_read_expect () {
79
NUM_PACKS=$1
810
NUM_OBJECTS=$2
@@ -76,18 +78,35 @@ test_expect_success 'create objects' '
7678
'
7779

7880
test_expect_success 'write midx with one v1 pack' '
79-
pack=$(git pack-objects --index-version=1 pack/test <obj-list) &&
80-
test_when_finished rm pack/test-$pack.pack pack/test-$pack.idx pack/multi-pack-index &&
81-
git multi-pack-index --object-dir=. write &&
82-
midx_read_expect 1 18 4 .
81+
pack=$(git pack-objects --index-version=1 $objdir/pack/test <obj-list) &&
82+
test_when_finished rm $objdir/pack/test-$pack.pack \
83+
$objdir/pack/test-$pack.idx $objdir/pack/multi-pack-index &&
84+
git multi-pack-index --object-dir=$objdir write &&
85+
midx_read_expect 1 18 4 $objdir
8386
'
8487

88+
midx_git_two_modes () {
89+
git -c core.multiPackIndex=false $1 >expect &&
90+
git -c core.multiPackIndex=true $1 >actual &&
91+
test_cmp expect actual
92+
}
93+
94+
compare_results_with_midx () {
95+
MSG=$1
96+
test_expect_success "check normal git operations: $MSG" '
97+
midx_git_two_modes "rev-list --objects --all" &&
98+
midx_git_two_modes "log --raw"
99+
'
100+
}
101+
85102
test_expect_success 'write midx with one v2 pack' '
86-
git pack-objects --index-version=2,0x40 pack/test <obj-list &&
87-
git multi-pack-index --object-dir=. write &&
88-
midx_read_expect 1 18 4 .
103+
git pack-objects --index-version=2,0x40 $objdir/pack/test <obj-list &&
104+
git multi-pack-index --object-dir=$objdir write &&
105+
midx_read_expect 1 18 4 $objdir
89106
'
90107

108+
compare_results_with_midx "one v2 pack"
109+
91110
test_expect_success 'add more objects' '
92111
for i in $(test_seq 6 10)
93112
do
@@ -97,25 +116,31 @@ test_expect_success 'add more objects' '
97116
'
98117

99118
test_expect_success 'write midx with two packs' '
100-
git pack-objects --index-version=1 pack/test-2 <obj-list &&
101-
git multi-pack-index --object-dir=. write &&
102-
midx_read_expect 2 34 4 .
119+
git pack-objects --index-version=1 $objdir/pack/test-2 <obj-list &&
120+
git multi-pack-index --object-dir=$objdir write &&
121+
midx_read_expect 2 34 4 $objdir
103122
'
104123

124+
compare_results_with_midx "two packs"
125+
105126
test_expect_success 'add more packs' '
106127
for j in $(test_seq 11 20)
107128
do
108129
generate_objects $j &&
109130
commit_and_list_objects &&
110-
git pack-objects --index-version=2 pack/test-pack <obj-list
131+
git pack-objects --index-version=2 $objdir/pack/test-pack <obj-list
111132
done
112133
'
113134

135+
compare_results_with_midx "mixed mode (two packs + extra)"
136+
114137
test_expect_success 'write midx with twelve packs' '
115-
git multi-pack-index --object-dir=. write &&
116-
midx_read_expect 12 74 4 .
138+
git multi-pack-index --object-dir=$objdir write &&
139+
midx_read_expect 12 74 4 $objdir
117140
'
118141

142+
compare_results_with_midx "twelve packs"
143+
119144
# usage: corrupt_data <file> <pos> [<data>]
120145
corrupt_data () {
121146
file=$1

0 commit comments

Comments
 (0)