Commit
f1d88b9698c4d9965fa72f1ce5739836ab97940f
t/helper: adapt read-midx to not link ad-hoc source anymore
Same as in the preceding commit, refactor the setup of ad-hoc object database sources when accessing a multi-pack index in an arbitrary location to not link the newly created source into the main object database anymore. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt <ps@pks.im> · 2026-09-11 05:51 UTC · committed by Junio C Hamano
1 file changed,
+31
−12
modified t/helper/test-read-midx.c
| @@ -5,34 +5,42 @@ | |||
| 5 | 5 | #include "midx.h" | |
| 6 | 6 | #include "repository.h" | |
| 7 | 7 | #include "odb.h" | |
| 8 | + | #include "odb/source-packed.h" | |
| 8 | 9 | #include "pack-bitmap.h" | |
| 9 | 10 | #include "packfile.h" | |
| 10 | 11 | #include "setup.h" | |
| 11 | 12 | #include "gettext.h" | |
| 12 | 13 | #include "pack-revindex.h" | |
| 13 | 14 | ||
| 14 | - | static struct multi_pack_index *setup_midx(const char *object_dir) | |
| 15 | + | static struct multi_pack_index *setup_midx(const char *object_dir, | |
| 16 | + | struct odb_source_packed **out) | |
| 15 | 17 | { | |
| 16 | - | struct odb_source_files *files; | |
| 18 | + | struct odb_source_packed *packed; | |
| 17 | 19 | struct odb_source *source; | |
| 20 | + | ||
| 18 | 21 | setup_git_directory(the_repository); | |
| 22 | + | ||
| 19 | 23 | source = odb_find_source(the_repository->objects, object_dir); | |
| 20 | - | if (!source) | |
| 21 | - | source = odb_add_to_alternates_memory(the_repository->objects, | |
| 22 | - | object_dir); | |
| 23 | - | files = odb_source_files_downcast(source); | |
| 24 | + | if (source) { | |
| 25 | + | packed = odb_source_files_downcast(source)->packed; | |
| 26 | + | } else { | |
| 27 | + | packed = odb_source_packed_new(the_repository->objects, | |
| 28 | + | object_dir, false); | |
| 29 | + | *out = packed; | |
| 30 | + | } | |
| 24 | 31 | ||
| 25 | - | return load_multi_pack_index(files->packed); | |
| 32 | + | return load_multi_pack_index(packed); | |
| 26 | 33 | } | |
| 27 | 34 | ||
| 28 | 35 | static int read_midx_file(const char *object_dir, const char *checksum, | |
| 29 | 36 | int show_objects) | |
| 30 | 37 | { | |
| 38 | + | struct odb_source_packed *packed = NULL; | |
| 31 | 39 | uint32_t i; | |
| 32 | 40 | struct multi_pack_index *m, *tip; | |
| 33 | 41 | int ret = 0; | |
| 34 | 42 | ||
| 35 | - | m = tip = setup_midx(object_dir); | |
| 43 | + | m = tip = setup_midx(object_dir, &packed); | |
| 36 | 44 | ||
| 37 | 45 | if (!m) | |
| 38 | 46 | return 1; | |
| @@ -91,29 +99,35 @@ static int read_midx_file(const char *object_dir, const char *checksum, | |||
| 91 | 99 | ||
| 92 | 100 | out: | |
| 93 | 101 | close_midx(tip); | |
| 102 | + | if (packed) | |
| 103 | + | odb_source_free(&packed->base); | |
| 94 | 104 | ||
| 95 | 105 | return ret; | |
| 96 | 106 | } | |
| 97 | 107 | ||
| 98 | 108 | static int read_midx_checksum(const char *object_dir) | |
| 99 | 109 | { | |
| 110 | + | struct odb_source_packed *packed = NULL; | |
| 100 | 111 | struct multi_pack_index *m; | |
| 101 | 112 | ||
| 102 | - | m = setup_midx(object_dir); | |
| 113 | + | m = setup_midx(object_dir, &packed); | |
| 103 | 114 | if (!m) | |
| 104 | 115 | return 1; | |
| 105 | 116 | printf("%s\n", midx_get_checksum_hex(m)); | |
| 106 | 117 | ||
| 107 | 118 | close_midx(m); | |
| 119 | + | if (packed) | |
| 120 | + | odb_source_free(&packed->base); | |
| 108 | 121 | return 0; | |
| 109 | 122 | } | |
| 110 | 123 | ||
| 111 | 124 | static int read_midx_preferred_pack(const char *object_dir) | |
| 112 | 125 | { | |
| 126 | + | struct odb_source_packed *packed = NULL; | |
| 113 | 127 | struct multi_pack_index *midx = NULL; | |
| 114 | 128 | uint32_t preferred_pack; | |
| 115 | 129 | ||
| 116 | - | midx = setup_midx(object_dir); | |
| 130 | + | midx = setup_midx(object_dir, &packed); | |
| 117 | 131 | if (!midx) | |
| 118 | 132 | return 1; | |
| 119 | 133 | ||
| @@ -124,17 +138,21 @@ static int read_midx_preferred_pack(const char *object_dir) | |||
| 124 | 138 | } | |
| 125 | 139 | ||
| 126 | 140 | printf("%s\n", midx->pack_names[preferred_pack]); | |
| 141 | + | ||
| 127 | 142 | close_midx(midx); | |
| 143 | + | if (packed) | |
| 144 | + | odb_source_free(&packed->base); | |
| 128 | 145 | return 0; | |
| 129 | 146 | } | |
| 130 | 147 | ||
| 131 | 148 | static int read_midx_bitmapped_packs(const char *object_dir) | |
| 132 | 149 | { | |
| 150 | + | struct odb_source_packed *packed = NULL; | |
| 133 | 151 | struct multi_pack_index *midx = NULL; | |
| 134 | 152 | struct bitmapped_pack pack; | |
| 135 | 153 | uint32_t i; | |
| 136 | 154 | ||
| 137 | - | midx = setup_midx(object_dir); | |
| 155 | + | midx = setup_midx(object_dir, &packed); | |
| 138 | 156 | if (!midx) | |
| 139 | 157 | return 1; | |
| 140 | 158 | ||
| @@ -150,7 +168,8 @@ static int read_midx_bitmapped_packs(const char *object_dir) | |||
| 150 | 168 | } | |
| 151 | 169 | ||
| 152 | 170 | close_midx(midx); | |
| 153 | - | ||
| 171 | + | if (packed) | |
| 172 | + | odb_source_free(&packed->base); | |
| 154 | 173 | return 0; | |
| 155 | 174 | } | |
| 156 | 175 | ||