29
const char *keep_hash);
30
extern void clear_incremental_midx_files_ext(struct odb_source *source,
31
const char *ext,
32
- const char **keep_hashes,
33
- uint32_t hashes_nr);
32
+ const struct strvec *keep_hashes);
33
extern int cmp_idx_or_pack_name(const char *idx_or_pack_name,
34
const char *idx_name);
35
1108
}
1109
1110
static void clear_midx_files(struct odb_source *source,
1112
- const char **hashes, uint32_t hashes_nr,
1113
- unsigned incremental)
1111
+ const struct strvec *hashes, unsigned incremental)
1112
{
1113
/*
1114
* if incremental:
1122
*/
1123
struct strbuf buf = STRBUF_INIT;
1124
const char *exts[] = { MIDX_EXT_BITMAP, MIDX_EXT_REV, MIDX_EXT_MIDX };
1127
- uint32_t i, j;
1125
+ uint32_t i;
1126
1127
for (i = 0; i < ARRAY_SIZE(exts); i++) {
1130
- clear_incremental_midx_files_ext(source, exts[i],
1131
- hashes, hashes_nr);
1132
- for (j = 0; j < hashes_nr; j++)
1133
- clear_midx_files_ext(source, exts[i], hashes[j]);
1128
+ clear_incremental_midx_files_ext(source, exts[i], hashes);
1129
+ if (hashes) {
1130
+ for (size_t j = 0; j < hashes->nr; j++)
1131
+ clear_midx_files_ext(source, exts[i],
1132
+ hashes->v[j]);
1133
+ }
1134
}
1135
1136
if (incremental)
1267
int pack_name_concat_len = 0;
1268
int dropped_packs = 0;
1269
int result = -1;
1270
- const char **keep_hashes = NULL;
1271
- size_t keep_hashes_nr = 0;
1270
+ struct strvec keep_hashes = STRVEC_INIT;
1271
struct chunkfile *cf;
1272
1273
trace2_region_enter("midx", "write_midx_internal", r);
1707
if (ctx.num_multi_pack_indexes_before == UINT32_MAX)
1708
die(_("too many multi-pack-indexes"));
1709
1711
- if (ctx.compact) {
1712
- struct multi_pack_index *m;
1713
-
1714
- /*
1715
- * Keep all MIDX layers excluding those in the range [from, to].
1716
- */
1717
- for (m = ctx.base_midx; m; m = m->base_midx)
1718
- keep_hashes_nr++;
1719
- for (m = ctx.m;
1720
- m && midx_hashcmp(m, ctx.compact_to, r->hash_algo);
1721
- m = m->base_midx)
1722
- keep_hashes_nr++;
1723
-
1724
- keep_hashes_nr++; /* include the compacted layer */
1725
- } else {
1726
- keep_hashes_nr = ctx.num_multi_pack_indexes_before + 1;
1727
- }
1728
- CALLOC_ARRAY(keep_hashes, keep_hashes_nr);
1729
-
1710
if (ctx.incremental) {
1711
FILE *chainf = fdopen_lock_file(&lk, "w");
1712
struct strbuf final_midx_name = STRBUF_INIT;
1713
struct multi_pack_index *m = ctx.base_midx;
1714
struct multi_pack_index **layers = NULL;
1715
size_t layers_nr = 0, layers_alloc = 0;
1736
- size_t j = 0;
1716
1717
if (!chainf) {
1718
error_errno(_("unable to open multi-pack-index chain file"));
1740
layers[layers_nr++] = mp;
1741
}
1742
while (layers_nr)
1764
- keep_hashes[j++] =
1765
- xstrdup(midx_get_checksum_hex(layers[--layers_nr]));
1743
+ strvec_push(&keep_hashes,
1744
+ midx_get_checksum_hex(layers[--layers_nr]));
1745
1767
- keep_hashes[j++] =
1768
- xstrdup(hash_to_hex_algop(midx_hash,
1769
- r->hash_algo));
1746
+ strvec_push(&keep_hashes,
1747
+ hash_to_hex_algop(midx_hash,
1748
+ r->hash_algo));
1749
1750
for (mp = ctx.m;
1751
mp && midx_hashcmp(mp, ctx.compact_to,
1755
layers[layers_nr++] = mp;
1756
}
1757
while (layers_nr)
1779
- keep_hashes[j++] =
1780
- xstrdup(midx_get_checksum_hex(layers[--layers_nr]));
1758
+ strvec_push(&keep_hashes,
1759
+ midx_get_checksum_hex(layers[--layers_nr]));
1760
} else {
1761
for (; m; m = m->base_midx) {
1762
ALLOC_GROW(layers, layers_nr + 1, layers_alloc);
1763
layers[layers_nr++] = m;
1764
}
1765
while (layers_nr)
1787
- keep_hashes[j++] =
1788
- xstrdup(midx_get_checksum_hex(layers[--layers_nr]));
1766
+ strvec_push(&keep_hashes,
1767
+ midx_get_checksum_hex(layers[--layers_nr]));
1768
1790
- keep_hashes[j++] =
1791
- xstrdup(hash_to_hex_algop(midx_hash,
1792
- r->hash_algo));
1769
+ strvec_push(&keep_hashes,
1770
+ hash_to_hex_algop(midx_hash,
1771
+ r->hash_algo));
1772
}
1773
1795
- ASSERT(j == keep_hashes_nr);
1796
-
1774
free(layers);
1775
1799
- for (uint32_t i = 0; i < j; i++)
1800
- fprintf(get_lock_file_fp(&lk), "%s\n", keep_hashes[i]);
1776
+ for (size_t i = 0; i < keep_hashes.nr; i++)
1777
+ fprintf(get_lock_file_fp(&lk), "%s\n", keep_hashes.v[i]);
1778
} else {
1802
- keep_hashes[ctx.num_multi_pack_indexes_before] =
1803
- xstrdup(hash_to_hex_algop(midx_hash, r->hash_algo));
1779
+ strvec_push(&keep_hashes,
1780
+ hash_to_hex_algop(midx_hash, r->hash_algo));
1781
}
1782
1783
if (ctx.m || ctx.base_midx)
1786
if (commit_lock_file(&lk) < 0)
1787
die_errno(_("could not write multi-pack-index"));
1788
1812
- clear_midx_files(opts->source, keep_hashes, keep_hashes_nr,
1813
- ctx.incremental);
1789
+ clear_midx_files(opts->source, &keep_hashes, ctx.incremental);
1790
result = 0;
1791
1792
cleanup:
1802
free(ctx.entries);
1803
free(ctx.pack_perm);
1804
free(ctx.pack_order);
1829
- if (keep_hashes) {
1830
- for (uint32_t i = 0; i < keep_hashes_nr; i++)
1831
- free((char *)keep_hashes[i]);
1832
- free(keep_hashes);
1833
- }
1805
+ strvec_clear(&keep_hashes);
1806
strbuf_release(&midx_name);
1807
close_midx(midx_to_free);
1808