midx: add entries to write_midx_context
In an effort to align write_midx_internal() with the chunk-format API, continue to group necessary data into "struct write_midx_context". This change collects the "struct pack_midx_entry *entries" list and its count into the context. Update write_midx_oid_fanout() and write_midx_oid_lookup() to take the context directly, as these are easy conversions with this new data. Only the callers of write_midx_object_offsets() and write_midx_large_offsets() are updated here, since additional data in the context before those methods can match chunk_write_fn. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Derrick Stolee committed
Feb 18, 2021 at 14:07 UTC
31bda9a237b363574bd8a5bd98f86bdeb6ced1e6
1 file changed
+26
-23
midx.c
+26
-23
@@ -458,6 +458,9 @@ struct write_midx_context {
458
struct multi_pack_index *m;
459
struct progress *progress;
460
unsigned pack_paths_checked;
461
+
462
+ struct pack_midx_entry *entries;
463
+ uint32_t entries_nr;
464
};
465
466
static void add_pack_to_midx(const char *full_path, size_t full_path_len,
@@ -678,11 +681,11 @@ static size_t write_midx_pack_names(struct hashfile *f, void *data)
681
}
682
683
static size_t write_midx_oid_fanout(struct hashfile *f,
681
- struct pack_midx_entry *objects,
682
- uint32_t nr_objects)
684
+ void *data)
685
{
684
- struct pack_midx_entry *list = objects;
685
- struct pack_midx_entry *last = objects + nr_objects;
686
+ struct write_midx_context *ctx = data;
687
+ struct pack_midx_entry *list = ctx->entries;
688
+ struct pack_midx_entry *last = ctx->entries + ctx->entries_nr;
689
uint32_t count = 0;
690
uint32_t i;
691
@@ -706,18 +709,19 @@ static size_t write_midx_oid_fanout(struct hashfile *f,
709
return MIDX_CHUNK_FANOUT_SIZE;
710
}
711
709
-static size_t write_midx_oid_lookup(struct hashfile *f, unsigned char hash_len,
710
- struct pack_midx_entry *objects,
711
- uint32_t nr_objects)
712
+static size_t write_midx_oid_lookup(struct hashfile *f,
713
+ void *data)
714
{
713
- struct pack_midx_entry *list = objects;
715
+ struct write_midx_context *ctx = data;
716
+ unsigned char hash_len = the_hash_algo->rawsz;
717
+ struct pack_midx_entry *list = ctx->entries;
718
uint32_t i;
719
size_t written = 0;
720
717
- for (i = 0; i < nr_objects; i++) {
721
+ for (i = 0; i < ctx->entries_nr; i++) {
722
struct pack_midx_entry *obj = list++;
723
720
- if (i < nr_objects - 1) {
724
+ if (i < ctx->entries_nr - 1) {
725
struct pack_midx_entry *next = list;
726
if (oidcmp(&obj->oid, &next->oid) >= 0)
727
BUG("OIDs not in order: %s >= %s",
@@ -805,8 +809,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
809
uint64_t written = 0;
810
uint32_t chunk_ids[MIDX_MAX_CHUNKS + 1];
811
uint64_t chunk_offsets[MIDX_MAX_CHUNKS + 1];
808
- uint32_t nr_entries, num_large_offsets = 0;
809
- struct pack_midx_entry *entries = NULL;
812
+ uint32_t num_large_offsets = 0;
813
struct progress *progress = NULL;
814
int large_offsets_needed = 0;
815
int pack_name_concat_len = 0;
@@ -852,12 +855,12 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
855
if (ctx.m && ctx.nr == ctx.m->num_packs && !packs_to_drop)
856
goto cleanup;
857
855
- entries = get_sorted_entries(ctx.m, ctx.info, ctx.nr, &nr_entries);
858
+ ctx.entries = get_sorted_entries(ctx.m, ctx.info, ctx.nr, &ctx.entries_nr);
859
857
- for (i = 0; i < nr_entries; i++) {
858
- if (entries[i].offset > 0x7fffffff)
860
+ for (i = 0; i < ctx.entries_nr; i++) {
861
+ if (ctx.entries[i].offset > 0x7fffffff)
862
num_large_offsets++;
860
- if (entries[i].offset > 0xffffffff)
863
+ if (ctx.entries[i].offset > 0xffffffff)
864
large_offsets_needed = 1;
865
}
866
@@ -947,10 +950,10 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
950
951
cur_chunk++;
952
chunk_ids[cur_chunk] = MIDX_CHUNKID_OBJECTOFFSETS;
950
- chunk_offsets[cur_chunk] = chunk_offsets[cur_chunk - 1] + nr_entries * the_hash_algo->rawsz;
953
+ chunk_offsets[cur_chunk] = chunk_offsets[cur_chunk - 1] + ctx.entries_nr * the_hash_algo->rawsz;
954
955
cur_chunk++;
953
- chunk_offsets[cur_chunk] = chunk_offsets[cur_chunk - 1] + nr_entries * MIDX_CHUNK_OFFSET_WIDTH;
956
+ chunk_offsets[cur_chunk] = chunk_offsets[cur_chunk - 1] + ctx.entries_nr * MIDX_CHUNK_OFFSET_WIDTH;
957
if (large_offsets_needed) {
958
chunk_ids[cur_chunk] = MIDX_CHUNKID_LARGEOFFSETS;
959
@@ -993,19 +996,19 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
996
break;
997
998
case MIDX_CHUNKID_OIDFANOUT:
996
- written += write_midx_oid_fanout(f, entries, nr_entries);
999
+ written += write_midx_oid_fanout(f, &ctx);
1000
break;
1001
1002
case MIDX_CHUNKID_OIDLOOKUP:
1000
- written += write_midx_oid_lookup(f, the_hash_algo->rawsz, entries, nr_entries);
1003
+ written += write_midx_oid_lookup(f, &ctx);
1004
break;
1005
1006
case MIDX_CHUNKID_OBJECTOFFSETS:
1004
- written += write_midx_object_offsets(f, large_offsets_needed, pack_perm, entries, nr_entries);
1007
+ written += write_midx_object_offsets(f, large_offsets_needed, pack_perm, ctx.entries, ctx.entries_nr);
1008
break;
1009
1010
case MIDX_CHUNKID_LARGEOFFSETS:
1008
- written += write_midx_large_offsets(f, num_large_offsets, entries, nr_entries);
1011
+ written += write_midx_large_offsets(f, num_large_offsets, ctx.entries, ctx.entries_nr);
1012
break;
1013
1014
default:
@@ -1035,7 +1038,7 @@ cleanup:
1038
}
1039
1040
free(ctx.info);
1038
- free(entries);
1041
+ free(ctx.entries);
1042
free(pack_perm);
1043
free(midx_name);
1044
return result;