-
Notifications
You must be signed in to change notification settings - Fork 106
fixup! multi-pack-index: implement 'expire' verb #106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -768,6 +768,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index * | |
| struct pack_midx_entry *entries = NULL; | ||
| int large_offsets_needed = 0; | ||
| int result = 0; | ||
| uint32_t *expire_int_ids = NULL; | ||
|
|
||
| midx_name = get_midx_filename(object_dir); | ||
| if (safe_create_leading_directories(midx_name)) { | ||
|
|
@@ -792,6 +793,9 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index * | |
| ALLOC_ARRAY(packs.names, packs.alloc_names); | ||
| ALLOC_ARRAY(packs.perm, packs.alloc_perm); | ||
|
|
||
| if (packs_to_drop && packs_to_drop->nr) | ||
| expire_int_ids = xcalloc(packs_to_drop->nr, sizeof(uint32_t)); | ||
|
|
||
| if (packs.m) { | ||
| int drop_index = 0, missing_drops = 0; | ||
| for (i = 0; i < packs.m->num_packs; i++) { | ||
|
|
@@ -800,8 +804,8 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index * | |
| packs_to_drop->items[drop_index].string); | ||
|
|
||
| if (!cmp) { | ||
| expire_int_ids[drop_index] = i; | ||
| drop_index++; | ||
| continue; | ||
| } else if (cmp > 0) { | ||
| error(_("did not see pack-file %s to drop"), | ||
| packs_to_drop->items[drop_index].string); | ||
|
|
@@ -832,15 +836,43 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index * | |
|
|
||
| for_each_file_in_pack_dir(object_dir, add_pack_to_midx, &packs); | ||
|
|
||
| if (packs.m && packs.nr == packs.m->num_packs) | ||
| if (packs.m && packs.nr == packs.m->num_packs && !packs_to_drop) | ||
| goto cleanup; | ||
|
|
||
| sort_packs_by_name(packs.names, packs.nr, packs.perm); | ||
|
|
||
| if (packs_to_drop && packs_to_drop->nr) { | ||
| int drop_index = 0; | ||
| int j; | ||
|
|
||
| /* truncate the list of packs */ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: the word "truncate" is misleading here. to me that says to lop of the end. but you're collapsing the newly created holes. |
||
| for (i = 0; i < packs.nr; i++) { | ||
| if (drop_index < packs_to_drop->nr && | ||
| !strcmp(packs.names[i], packs_to_drop->items[drop_index].string)) { | ||
| packs.pack_name_concat_len -= strlen(packs_to_drop->items[drop_index].string) + 1; | ||
| drop_index++; | ||
| } else { | ||
| packs.list[i - drop_index] = packs.list[i]; | ||
| packs.names[i - drop_index] = packs.names[i]; | ||
| } | ||
| } | ||
|
|
||
| for (j = packs_to_drop->nr - 1; j >= 0; j--) { | ||
| int expired_int_id = packs.perm[expire_int_ids[j]]; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: maybe "int permuted_int_id" ? |
||
|
|
||
| for (i = 0; i < packs.nr; i++) { | ||
| if (packs.perm[i] > expired_int_id) | ||
| packs.perm[i] = packs.perm[i] - 1; | ||
| } | ||
| } | ||
|
|
||
| packs.nr = packs.nr - packs_to_drop->nr; | ||
| } | ||
|
|
||
| if (packs.pack_name_concat_len % MIDX_CHUNK_ALIGNMENT) | ||
| packs.pack_name_concat_len += MIDX_CHUNK_ALIGNMENT - | ||
| (packs.pack_name_concat_len % MIDX_CHUNK_ALIGNMENT); | ||
|
|
||
| sort_packs_by_name(packs.names, packs.nr, packs.perm); | ||
|
|
||
| entries = get_sorted_entries(packs.m, packs.list, packs.perm, packs.nr, &nr_entries); | ||
|
|
||
| for (i = 0; i < nr_entries; i++) { | ||
|
|
@@ -962,6 +994,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index * | |
| free(packs.perm); | ||
| free(entries); | ||
| free(midx_name); | ||
| free(expire_int_ids); | ||
| return result; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GH won't let me make a comment on a non delta line, so this is the closest line.
https://github.com/Microsoft/git/pull/106/files#diff-4d791aa648626485aa1adb43d8972a33R812
On line 812 below, incrementing drop_index will leave a zero cell in expire_int_ids[].
Can't tell yet if that is a good thing or a bad thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never mind. looks like you throw an error at 830 when that happens.