Skip to content

Commit 31bda9a

Browse files
derrickstoleegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b4d9414 commit 31bda9a

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

midx.c

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,9 @@ struct write_midx_context {
458458
struct multi_pack_index *m;
459459
struct progress *progress;
460460
unsigned pack_paths_checked;
461+
462+
struct pack_midx_entry *entries;
463+
uint32_t entries_nr;
461464
};
462465

463466
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)
678681
}
679682

680683
static size_t write_midx_oid_fanout(struct hashfile *f,
681-
struct pack_midx_entry *objects,
682-
uint32_t nr_objects)
684+
void *data)
683685
{
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;
686689
uint32_t count = 0;
687690
uint32_t i;
688691

@@ -706,18 +709,19 @@ static size_t write_midx_oid_fanout(struct hashfile *f,
706709
return MIDX_CHUNK_FANOUT_SIZE;
707710
}
708711

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)
712714
{
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;
714718
uint32_t i;
715719
size_t written = 0;
716720

717-
for (i = 0; i < nr_objects; i++) {
721+
for (i = 0; i < ctx->entries_nr; i++) {
718722
struct pack_midx_entry *obj = list++;
719723

720-
if (i < nr_objects - 1) {
724+
if (i < ctx->entries_nr - 1) {
721725
struct pack_midx_entry *next = list;
722726
if (oidcmp(&obj->oid, &next->oid) >= 0)
723727
BUG("OIDs not in order: %s >= %s",
@@ -805,8 +809,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
805809
uint64_t written = 0;
806810
uint32_t chunk_ids[MIDX_MAX_CHUNKS + 1];
807811
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;
810813
struct progress *progress = NULL;
811814
int large_offsets_needed = 0;
812815
int pack_name_concat_len = 0;
@@ -852,12 +855,12 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
852855
if (ctx.m && ctx.nr == ctx.m->num_packs && !packs_to_drop)
853856
goto cleanup;
854857

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);
856859

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)
859862
num_large_offsets++;
860-
if (entries[i].offset > 0xffffffff)
863+
if (ctx.entries[i].offset > 0xffffffff)
861864
large_offsets_needed = 1;
862865
}
863866

@@ -947,10 +950,10 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
947950

948951
cur_chunk++;
949952
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;
951954

952955
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;
954957
if (large_offsets_needed) {
955958
chunk_ids[cur_chunk] = MIDX_CHUNKID_LARGEOFFSETS;
956959

@@ -993,19 +996,19 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
993996
break;
994997

995998
case MIDX_CHUNKID_OIDFANOUT:
996-
written += write_midx_oid_fanout(f, entries, nr_entries);
999+
written += write_midx_oid_fanout(f, &ctx);
9971000
break;
9981001

9991002
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);
10011004
break;
10021005

10031006
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);
10051008
break;
10061009

10071010
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);
10091012
break;
10101013

10111014
default:
@@ -1035,7 +1038,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
10351038
}
10361039

10371040
free(ctx.info);
1038-
free(entries);
1041+
free(ctx.entries);
10391042
free(pack_perm);
10401043
free(midx_name);
10411044
return result;

0 commit comments

Comments
 (0)