Skip to content

Commit 56c3358

Browse files
committed
Merge branch 'ps/packfile-store-in-odb-source' into seen
The packfile_store data structure is moved from object store to odb source. Comments? * ps/packfile-store-in-odb-source: packfile: move MIDX into packfile store packfile: refactor `find_pack_entry()` to work on the packfile store packfile: inline `find_kept_pack_entry()` packfile: only prepare owning store in `packfile_store_prepare()` packfile: only prepare owning store in `packfile_store_get_packs()` packfile: move packfile store into object source packfile: refactor misleading code when unusing pack windows packfile: refactor kept-pack cache to work with packfile stores packfile: pass source to `prepare_pack()` packfile: create store via its owning source
2 parents ba600d5 + 6354d4c commit 56c3358

File tree

13 files changed

+325
-247
lines changed

13 files changed

+325
-247
lines changed

builtin/fast-import.c

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ static void end_packfile(void)
900900
idx_name = keep_pack(create_index());
901901

902902
/* Register the packfile with core git's machinery. */
903-
new_p = packfile_store_load_pack(pack_data->repo->objects->packfiles,
903+
new_p = packfile_store_load_pack(pack_data->repo->objects->sources->packfiles,
904904
idx_name, 1);
905905
if (!new_p)
906906
die(_("core Git rejected index %s"), idx_name);
@@ -955,7 +955,7 @@ static int store_object(
955955
struct object_id *oidout,
956956
uintmax_t mark)
957957
{
958-
struct packfile_store *packs = the_repository->objects->packfiles;
958+
struct odb_source *source;
959959
void *out, *delta;
960960
struct object_entry *e;
961961
unsigned char hdr[96];
@@ -979,7 +979,11 @@ static int store_object(
979979
if (e->idx.offset) {
980980
duplicate_count_by_type[type]++;
981981
return 1;
982-
} else if (packfile_list_find_oid(packfile_store_get_packs(packs), &oid)) {
982+
}
983+
984+
for (source = the_repository->objects->sources; source; source = source->next) {
985+
if (!packfile_list_find_oid(packfile_store_get_packs(source->packfiles), &oid))
986+
continue;
983987
e->type = type;
984988
e->pack_id = MAX_PACK_ID;
985989
e->idx.offset = 1; /* just not zero! */
@@ -1096,10 +1100,10 @@ static void truncate_pack(struct hashfile_checkpoint *checkpoint)
10961100

10971101
static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)
10981102
{
1099-
struct packfile_store *packs = the_repository->objects->packfiles;
11001103
size_t in_sz = 64 * 1024, out_sz = 64 * 1024;
11011104
unsigned char *in_buf = xmalloc(in_sz);
11021105
unsigned char *out_buf = xmalloc(out_sz);
1106+
struct odb_source *source;
11031107
struct object_entry *e;
11041108
struct object_id oid;
11051109
unsigned long hdrlen;
@@ -1179,24 +1183,29 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)
11791183
if (e->idx.offset) {
11801184
duplicate_count_by_type[OBJ_BLOB]++;
11811185
truncate_pack(&checkpoint);
1186+
goto out;
1187+
}
11821188

1183-
} else if (packfile_list_find_oid(packfile_store_get_packs(packs), &oid)) {
1189+
for (source = the_repository->objects->sources; source; source = source->next) {
1190+
if (!packfile_list_find_oid(packfile_store_get_packs(source->packfiles), &oid))
1191+
continue;
11841192
e->type = OBJ_BLOB;
11851193
e->pack_id = MAX_PACK_ID;
11861194
e->idx.offset = 1; /* just not zero! */
11871195
duplicate_count_by_type[OBJ_BLOB]++;
11881196
truncate_pack(&checkpoint);
1189-
1190-
} else {
1191-
e->depth = 0;
1192-
e->type = OBJ_BLOB;
1193-
e->pack_id = pack_id;
1194-
e->idx.offset = offset;
1195-
e->idx.crc32 = crc32_end(pack_file);
1196-
object_count++;
1197-
object_count_by_type[OBJ_BLOB]++;
1197+
goto out;
11981198
}
11991199

1200+
e->depth = 0;
1201+
e->type = OBJ_BLOB;
1202+
e->pack_id = pack_id;
1203+
e->idx.offset = offset;
1204+
e->idx.crc32 = crc32_end(pack_file);
1205+
object_count++;
1206+
object_count_by_type[OBJ_BLOB]++;
1207+
1208+
out:
12001209
free(in_buf);
12011210
free(out_buf);
12021211
}

builtin/grep.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,8 +1213,14 @@ int cmd_grep(int argc,
12131213
*/
12141214
if (recurse_submodules)
12151215
repo_read_gitmodules(the_repository, 1);
1216-
if (startup_info->have_repository)
1217-
packfile_store_prepare(the_repository->objects->packfiles);
1216+
1217+
if (startup_info->have_repository) {
1218+
struct odb_source *source;
1219+
1220+
odb_prepare_alternates(the_repository->objects);
1221+
for (source = the_repository->objects->sources; source; source = source->next)
1222+
packfile_store_prepare(source->packfiles);
1223+
}
12181224

12191225
start_threads(&opt);
12201226
} else {

builtin/index-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1638,7 +1638,7 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
16381638
hash, "idx", 1);
16391639

16401640
if (do_fsck_object && startup_info->have_repository)
1641-
packfile_store_load_pack(the_repository->objects->packfiles,
1641+
packfile_store_load_pack(the_repository->objects->sources->packfiles,
16421642
final_index_name, 0);
16431643

16441644
if (!from_stdin) {

builtin/pack-objects.c

Lines changed: 55 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,49 +1529,53 @@ static int want_cruft_object_mtime(struct repository *r,
15291529
const struct object_id *oid,
15301530
unsigned flags, uint32_t mtime)
15311531
{
1532-
struct packed_git **cache;
1532+
struct odb_source *source;
15331533

1534-
for (cache = kept_pack_cache(r, flags); *cache; cache++) {
1535-
struct packed_git *p = *cache;
1536-
off_t ofs;
1537-
uint32_t candidate_mtime;
1534+
for (source = r->objects->sources; source; source = source->next) {
1535+
struct packed_git **cache = packfile_store_get_kept_pack_cache(source->packfiles, flags);
15381536

1539-
ofs = find_pack_entry_one(oid, p);
1540-
if (!ofs)
1541-
continue;
1537+
for (; *cache; cache++) {
1538+
struct packed_git *p = *cache;
1539+
off_t ofs;
1540+
uint32_t candidate_mtime;
15421541

1543-
/*
1544-
* We have a copy of the object 'oid' in a non-cruft
1545-
* pack. We can avoid packing an additional copy
1546-
* regardless of what the existing copy's mtime is since
1547-
* it is outside of a cruft pack.
1548-
*/
1549-
if (!p->is_cruft)
1550-
return 0;
1551-
1552-
/*
1553-
* If we have a copy of the object 'oid' in a cruft
1554-
* pack, then either read the cruft pack's mtime for
1555-
* that object, or, if that can't be loaded, assume the
1556-
* pack's mtime itself.
1557-
*/
1558-
if (!load_pack_mtimes(p)) {
1559-
uint32_t pos;
1560-
if (offset_to_pack_pos(p, ofs, &pos) < 0)
1542+
ofs = find_pack_entry_one(oid, p);
1543+
if (!ofs)
15611544
continue;
1562-
candidate_mtime = nth_packed_mtime(p, pos);
1563-
} else {
1564-
candidate_mtime = p->mtime;
1565-
}
15661545

1567-
/*
1568-
* We have a surviving copy of the object in a cruft
1569-
* pack whose mtime is greater than or equal to the one
1570-
* we are considering. We can thus avoid packing an
1571-
* additional copy of that object.
1572-
*/
1573-
if (mtime <= candidate_mtime)
1574-
return 0;
1546+
/*
1547+
* We have a copy of the object 'oid' in a non-cruft
1548+
* pack. We can avoid packing an additional copy
1549+
* regardless of what the existing copy's mtime is since
1550+
* it is outside of a cruft pack.
1551+
*/
1552+
if (!p->is_cruft)
1553+
return 0;
1554+
1555+
/*
1556+
* If we have a copy of the object 'oid' in a cruft
1557+
* pack, then either read the cruft pack's mtime for
1558+
* that object, or, if that can't be loaded, assume the
1559+
* pack's mtime itself.
1560+
*/
1561+
if (!load_pack_mtimes(p)) {
1562+
uint32_t pos;
1563+
if (offset_to_pack_pos(p, ofs, &pos) < 0)
1564+
continue;
1565+
candidate_mtime = nth_packed_mtime(p, pos);
1566+
} else {
1567+
candidate_mtime = p->mtime;
1568+
}
1569+
1570+
/*
1571+
* We have a surviving copy of the object in a cruft
1572+
* pack whose mtime is greater than or equal to the one
1573+
* we are considering. We can thus avoid packing an
1574+
* additional copy of that object.
1575+
*/
1576+
if (mtime <= candidate_mtime)
1577+
return 0;
1578+
}
15751579
}
15761580

15771581
return -1;
@@ -1624,9 +1628,9 @@ static int want_found_object(const struct object_id *oid, int exclude,
16241628
*/
16251629
unsigned flags = 0;
16261630
if (ignore_packed_keep_on_disk)
1627-
flags |= ON_DISK_KEEP_PACKS;
1631+
flags |= KEPT_PACK_ON_DISK;
16281632
if (ignore_packed_keep_in_core)
1629-
flags |= IN_CORE_KEEP_PACKS;
1633+
flags |= KEPT_PACK_IN_CORE;
16301634

16311635
/*
16321636
* If the object is in a pack that we want to ignore, *and* we
@@ -1749,13 +1753,15 @@ static int want_object_in_pack_mtime(const struct object_id *oid,
17491753
}
17501754
}
17511755

1752-
for (e = the_repository->objects->packfiles->packs.head; e; e = e->next) {
1753-
struct packed_git *p = e->pack;
1754-
want = want_object_in_pack_one(p, oid, exclude, found_pack, found_offset, found_mtime);
1755-
if (!exclude && want > 0)
1756-
packfile_list_prepend(&the_repository->objects->packfiles->packs, p);
1757-
if (want != -1)
1758-
return want;
1756+
for (source = the_repository->objects->sources; source; source = source->next) {
1757+
for (e = source->packfiles->packs.head; e; e = e->next) {
1758+
struct packed_git *p = e->pack;
1759+
want = want_object_in_pack_one(p, oid, exclude, found_pack, found_offset, found_mtime);
1760+
if (!exclude && want > 0)
1761+
packfile_list_prepend(&source->packfiles->packs, p);
1762+
if (want != -1)
1763+
return want;
1764+
}
17591765
}
17601766

17611767
if (uri_protocols.nr) {
@@ -3931,7 +3937,7 @@ static void read_stdin_packs(enum stdin_packs_mode mode, int rev_list_unpacked)
39313937
* an optimization during delta selection.
39323938
*/
39333939
revs.no_kept_objects = 1;
3934-
revs.keep_pack_cache_flags |= IN_CORE_KEEP_PACKS;
3940+
revs.keep_pack_cache_flags |= KEPT_PACK_IN_CORE;
39353941
revs.blob_objects = 1;
39363942
revs.tree_objects = 1;
39373943
revs.tag_objects = 1;
@@ -4030,7 +4036,7 @@ static void show_cruft_commit(struct commit *commit, void *data)
40304036

40314037
static int cruft_include_check_obj(struct object *obj, void *data UNUSED)
40324038
{
4033-
return !has_object_kept_pack(to_pack.repo, &obj->oid, IN_CORE_KEEP_PACKS);
4039+
return !has_object_kept_pack(to_pack.repo, &obj->oid, KEPT_PACK_IN_CORE);
40344040
}
40354041

40364042
static int cruft_include_check(struct commit *commit, void *data)

http.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2544,7 +2544,7 @@ void http_install_packfile(struct packed_git *p,
25442544
struct packfile_list *list_to_remove_from)
25452545
{
25462546
packfile_list_remove(list_to_remove_from, p);
2547-
packfile_store_add_pack(the_repository->objects->packfiles, p);
2547+
packfile_store_add_pack(the_repository->objects->sources->packfiles, p);
25482548
}
25492549

25502550
struct http_pack_request *new_http_pack_request(

midx.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ static int midx_read_object_offsets(const unsigned char *chunk_start,
101101

102102
struct multi_pack_index *get_multi_pack_index(struct odb_source *source)
103103
{
104-
packfile_store_prepare(source->odb->packfiles);
105-
return source->midx;
104+
packfile_store_prepare(source->packfiles);
105+
return source->packfiles->midx;
106106
}
107107

108108
static struct multi_pack_index *load_multi_pack_index_one(struct odb_source *source,
@@ -449,7 +449,6 @@ static uint32_t midx_for_pack(struct multi_pack_index **_m,
449449
int prepare_midx_pack(struct multi_pack_index *m,
450450
uint32_t pack_int_id)
451451
{
452-
struct repository *r = m->source->odb->repo;
453452
struct strbuf pack_name = STRBUF_INIT;
454453
struct packed_git *p;
455454

@@ -462,7 +461,7 @@ int prepare_midx_pack(struct multi_pack_index *m,
462461

463462
strbuf_addf(&pack_name, "%s/pack/%s", m->source->path,
464463
m->pack_names[pack_int_id]);
465-
p = packfile_store_load_pack(r->objects->packfiles,
464+
p = packfile_store_load_pack(m->source->packfiles,
466465
pack_name.buf, m->source->local);
467466
strbuf_release(&pack_name);
468467

@@ -732,12 +731,12 @@ int prepare_multi_pack_index_one(struct odb_source *source)
732731
if (!r->settings.core_multi_pack_index)
733732
return 0;
734733

735-
if (source->midx)
734+
if (source->packfiles->midx)
736735
return 1;
737736

738-
source->midx = load_multi_pack_index(source);
737+
source->packfiles->midx = load_multi_pack_index(source);
739738

740-
return !!source->midx;
739+
return !!source->packfiles->midx;
741740
}
742741

743742
int midx_checksum_valid(struct multi_pack_index *m)
@@ -826,9 +825,9 @@ void clear_midx_file(struct repository *r)
826825
struct odb_source *source;
827826

828827
for (source = r->objects->sources; source; source = source->next) {
829-
if (source->midx)
830-
close_midx(source->midx);
831-
source->midx = NULL;
828+
if (source->packfiles->midx)
829+
close_midx(source->packfiles->midx);
830+
source->packfiles->midx = NULL;
832831
}
833832
}
834833

0 commit comments

Comments
 (0)