Skip to content

Commit 577dc49

Browse files
derrickstoleegitster
authored andcommitted
midx: rename pack_info to write_midx_context
In an effort to streamline our chunk-based file formats, align some of the code structure in write_midx_internal() to be similar to the patterns in write_commit_graph_file(). Specifically, let's create a "struct write_midx_context" that can be used as a data parameter to abstract function types. This change only renames "struct pack_info" to "struct write_midx_context" and the names of instances from "packs" to "ctx". In future changes, we will expand the data inside "struct write_midx_context" and align our chunk-writing method with the chunk-format API. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 47410aa commit 577dc49

File tree

1 file changed

+65
-65
lines changed

1 file changed

+65
-65
lines changed

midx.c

Lines changed: 65 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ static int pack_info_compare(const void *_a, const void *_b)
451451
return strcmp(a->pack_name, b->pack_name);
452452
}
453453

454-
struct pack_list {
454+
struct write_midx_context {
455455
struct pack_info *info;
456456
uint32_t nr;
457457
uint32_t alloc;
@@ -463,37 +463,37 @@ struct pack_list {
463463
static void add_pack_to_midx(const char *full_path, size_t full_path_len,
464464
const char *file_name, void *data)
465465
{
466-
struct pack_list *packs = (struct pack_list *)data;
466+
struct write_midx_context *ctx = data;
467467

468468
if (ends_with(file_name, ".idx")) {
469-
display_progress(packs->progress, ++packs->pack_paths_checked);
470-
if (packs->m && midx_contains_pack(packs->m, file_name))
469+
display_progress(ctx->progress, ++ctx->pack_paths_checked);
470+
if (ctx->m && midx_contains_pack(ctx->m, file_name))
471471
return;
472472

473-
ALLOC_GROW(packs->info, packs->nr + 1, packs->alloc);
473+
ALLOC_GROW(ctx->info, ctx->nr + 1, ctx->alloc);
474474

475-
packs->info[packs->nr].p = add_packed_git(full_path,
476-
full_path_len,
477-
0);
475+
ctx->info[ctx->nr].p = add_packed_git(full_path,
476+
full_path_len,
477+
0);
478478

479-
if (!packs->info[packs->nr].p) {
479+
if (!ctx->info[ctx->nr].p) {
480480
warning(_("failed to add packfile '%s'"),
481481
full_path);
482482
return;
483483
}
484484

485-
if (open_pack_index(packs->info[packs->nr].p)) {
485+
if (open_pack_index(ctx->info[ctx->nr].p)) {
486486
warning(_("failed to open pack-index '%s'"),
487487
full_path);
488-
close_pack(packs->info[packs->nr].p);
489-
FREE_AND_NULL(packs->info[packs->nr].p);
488+
close_pack(ctx->info[ctx->nr].p);
489+
FREE_AND_NULL(ctx->info[ctx->nr].p);
490490
return;
491491
}
492492

493-
packs->info[packs->nr].pack_name = xstrdup(file_name);
494-
packs->info[packs->nr].orig_pack_int_id = packs->nr;
495-
packs->info[packs->nr].expired = 0;
496-
packs->nr++;
493+
ctx->info[ctx->nr].pack_name = xstrdup(file_name);
494+
ctx->info[ctx->nr].orig_pack_int_id = ctx->nr;
495+
ctx->info[ctx->nr].expired = 0;
496+
ctx->nr++;
497497
}
498498
}
499499

@@ -801,7 +801,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
801801
uint32_t i;
802802
struct hashfile *f = NULL;
803803
struct lock_file lk;
804-
struct pack_list packs;
804+
struct write_midx_context ctx = { 0 };
805805
uint32_t *pack_perm = NULL;
806806
uint64_t written = 0;
807807
uint32_t chunk_ids[MIDX_MAX_CHUNKS + 1];
@@ -820,40 +820,40 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
820820
midx_name);
821821

822822
if (m)
823-
packs.m = m;
823+
ctx.m = m;
824824
else
825-
packs.m = load_multi_pack_index(object_dir, 1);
826-
827-
packs.nr = 0;
828-
packs.alloc = packs.m ? packs.m->num_packs : 16;
829-
packs.info = NULL;
830-
ALLOC_ARRAY(packs.info, packs.alloc);
831-
832-
if (packs.m) {
833-
for (i = 0; i < packs.m->num_packs; i++) {
834-
ALLOC_GROW(packs.info, packs.nr + 1, packs.alloc);
835-
836-
packs.info[packs.nr].orig_pack_int_id = i;
837-
packs.info[packs.nr].pack_name = xstrdup(packs.m->pack_names[i]);
838-
packs.info[packs.nr].p = NULL;
839-
packs.info[packs.nr].expired = 0;
840-
packs.nr++;
825+
ctx.m = load_multi_pack_index(object_dir, 1);
826+
827+
ctx.nr = 0;
828+
ctx.alloc = ctx.m ? ctx.m->num_packs : 16;
829+
ctx.info = NULL;
830+
ALLOC_ARRAY(ctx.info, ctx.alloc);
831+
832+
if (ctx.m) {
833+
for (i = 0; i < ctx.m->num_packs; i++) {
834+
ALLOC_GROW(ctx.info, ctx.nr + 1, ctx.alloc);
835+
836+
ctx.info[ctx.nr].orig_pack_int_id = i;
837+
ctx.info[ctx.nr].pack_name = xstrdup(ctx.m->pack_names[i]);
838+
ctx.info[ctx.nr].p = NULL;
839+
ctx.info[ctx.nr].expired = 0;
840+
ctx.nr++;
841841
}
842842
}
843843

844-
packs.pack_paths_checked = 0;
844+
ctx.pack_paths_checked = 0;
845845
if (flags & MIDX_PROGRESS)
846-
packs.progress = start_delayed_progress(_("Adding packfiles to multi-pack-index"), 0);
846+
ctx.progress = start_delayed_progress(_("Adding packfiles to multi-pack-index"), 0);
847847
else
848-
packs.progress = NULL;
848+
ctx.progress = NULL;
849849

850-
for_each_file_in_pack_dir(object_dir, add_pack_to_midx, &packs);
851-
stop_progress(&packs.progress);
850+
for_each_file_in_pack_dir(object_dir, add_pack_to_midx, &ctx);
851+
stop_progress(&ctx.progress);
852852

853-
if (packs.m && packs.nr == packs.m->num_packs && !packs_to_drop)
853+
if (ctx.m && ctx.nr == ctx.m->num_packs && !packs_to_drop)
854854
goto cleanup;
855855

856-
entries = get_sorted_entries(packs.m, packs.info, packs.nr, &nr_entries);
856+
entries = get_sorted_entries(ctx.m, ctx.info, ctx.nr, &nr_entries);
857857

858858
for (i = 0; i < nr_entries; i++) {
859859
if (entries[i].offset > 0x7fffffff)
@@ -862,27 +862,27 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
862862
large_offsets_needed = 1;
863863
}
864864

865-
QSORT(packs.info, packs.nr, pack_info_compare);
865+
QSORT(ctx.info, ctx.nr, pack_info_compare);
866866

867867
if (packs_to_drop && packs_to_drop->nr) {
868868
int drop_index = 0;
869869
int missing_drops = 0;
870870

871-
for (i = 0; i < packs.nr && drop_index < packs_to_drop->nr; i++) {
872-
int cmp = strcmp(packs.info[i].pack_name,
871+
for (i = 0; i < ctx.nr && drop_index < packs_to_drop->nr; i++) {
872+
int cmp = strcmp(ctx.info[i].pack_name,
873873
packs_to_drop->items[drop_index].string);
874874

875875
if (!cmp) {
876876
drop_index++;
877-
packs.info[i].expired = 1;
877+
ctx.info[i].expired = 1;
878878
} else if (cmp > 0) {
879879
error(_("did not see pack-file %s to drop"),
880880
packs_to_drop->items[drop_index].string);
881881
drop_index++;
882882
missing_drops++;
883883
i--;
884884
} else {
885-
packs.info[i].expired = 0;
885+
ctx.info[i].expired = 0;
886886
}
887887
}
888888

@@ -898,19 +898,19 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
898898
*
899899
* pack_perm[old_id] = new_id
900900
*/
901-
ALLOC_ARRAY(pack_perm, packs.nr);
902-
for (i = 0; i < packs.nr; i++) {
903-
if (packs.info[i].expired) {
901+
ALLOC_ARRAY(pack_perm, ctx.nr);
902+
for (i = 0; i < ctx.nr; i++) {
903+
if (ctx.info[i].expired) {
904904
dropped_packs++;
905-
pack_perm[packs.info[i].orig_pack_int_id] = PACK_EXPIRED;
905+
pack_perm[ctx.info[i].orig_pack_int_id] = PACK_EXPIRED;
906906
} else {
907-
pack_perm[packs.info[i].orig_pack_int_id] = i - dropped_packs;
907+
pack_perm[ctx.info[i].orig_pack_int_id] = i - dropped_packs;
908908
}
909909
}
910910

911-
for (i = 0; i < packs.nr; i++) {
912-
if (!packs.info[i].expired)
913-
pack_name_concat_len += strlen(packs.info[i].pack_name) + 1;
911+
for (i = 0; i < ctx.nr; i++) {
912+
if (!ctx.info[i].expired)
913+
pack_name_concat_len += strlen(ctx.info[i].pack_name) + 1;
914914
}
915915

916916
if (pack_name_concat_len % MIDX_CHUNK_ALIGNMENT)
@@ -921,19 +921,19 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
921921
f = hashfd(lk.tempfile->fd, lk.tempfile->filename.buf);
922922
FREE_AND_NULL(midx_name);
923923

924-
if (packs.m)
925-
close_midx(packs.m);
924+
if (ctx.m)
925+
close_midx(ctx.m);
926926

927927
cur_chunk = 0;
928928
num_chunks = large_offsets_needed ? 5 : 4;
929929

930-
if (packs.nr - dropped_packs == 0) {
930+
if (ctx.nr - dropped_packs == 0) {
931931
error(_("no pack files to index."));
932932
result = 1;
933933
goto cleanup;
934934
}
935935

936-
written = write_midx_header(f, num_chunks, packs.nr - dropped_packs);
936+
written = write_midx_header(f, num_chunks, ctx.nr - dropped_packs);
937937

938938
chunk_ids[cur_chunk] = MIDX_CHUNKID_PACKNAMES;
939939
chunk_offsets[cur_chunk] = written + (num_chunks + 1) * MIDX_CHUNKLOOKUP_WIDTH;
@@ -990,7 +990,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
990990

991991
switch (chunk_ids[i]) {
992992
case MIDX_CHUNKID_PACKNAMES:
993-
written += write_midx_pack_names(f, packs.info, packs.nr);
993+
written += write_midx_pack_names(f, ctx.info, ctx.nr);
994994
break;
995995

996996
case MIDX_CHUNKID_OIDFANOUT:
@@ -1027,15 +1027,15 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
10271027
commit_lock_file(&lk);
10281028

10291029
cleanup:
1030-
for (i = 0; i < packs.nr; i++) {
1031-
if (packs.info[i].p) {
1032-
close_pack(packs.info[i].p);
1033-
free(packs.info[i].p);
1030+
for (i = 0; i < ctx.nr; i++) {
1031+
if (ctx.info[i].p) {
1032+
close_pack(ctx.info[i].p);
1033+
free(ctx.info[i].p);
10341034
}
1035-
free(packs.info[i].pack_name);
1035+
free(ctx.info[i].pack_name);
10361036
}
10371037

1038-
free(packs.info);
1038+
free(ctx.info);
10391039
free(entries);
10401040
free(pack_perm);
10411041
free(midx_name);

0 commit comments

Comments
 (0)