pack-bitmap.c: fix formatting of error messages

There are some text output issues in 'pack-bitmap.c', they exist in die(), error() etc. This includes issues with capitalization the first letter, newlines, error() instead of BUG(), and substitution that don't have quotes around them. Signed-off-by: Teng Long <dyroneteng@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Teng Long committed Jul 19, 2022 at 00:46 UTC baf20c39a776e9b0ea52bae2391df909c31d8ed1
1 file changed +24 -23
pack-bitmap.c
+24 -23
@@ -1,5 +1,6 @@
1 #include "cache.h"
2 #include "commit.h"
3 +#include "strbuf.h"
4 #include "tag.h"
5 #include "diff.h"
6 #include "revision.h"
@@ -138,7 +139,7 @@ static struct ewah_bitmap *read_bitmap_1(struct bitmap_index *index)
139 index->map_size - index->map_pos);
140
141 if (bitmap_size < 0) {
141 - error("Failed to load bitmap index (corrupted?)");
142 + error("failed to load bitmap index (corrupted?)");
143 ewah_pool_free(b);
144 return NULL;
145 }
@@ -160,14 +161,14 @@ static int load_bitmap_header(struct bitmap_index *index)
161 size_t header_size = sizeof(*header) - GIT_MAX_RAWSZ + the_hash_algo->rawsz;
162
163 if (index->map_size < header_size + the_hash_algo->rawsz)
163 - return error("Corrupted bitmap index (too small)");
164 + return error("corrupted bitmap index (too small)");
165
166 if (memcmp(header->magic, BITMAP_IDX_SIGNATURE, sizeof(BITMAP_IDX_SIGNATURE)) != 0)
166 - return error("Corrupted bitmap index file (wrong header)");
167 + return error("corrupted bitmap index file (wrong header)");
168
169 index->version = ntohs(header->version);
170 if (index->version != 1)
170 - return error("Unsupported version for bitmap index file (%d)", index->version);
171 + return error("unsupported version '%d' for bitmap index file", index->version);
172
173 /* Parse known bitmap format options */
174 {
@@ -176,7 +177,7 @@ static int load_bitmap_header(struct bitmap_index *index)
177 unsigned char *index_end = index->map + index->map_size - the_hash_algo->rawsz;
178
179 if ((flags & BITMAP_OPT_FULL_DAG) == 0)
179 - return error("Unsupported options for bitmap index file "
180 + BUG("unsupported options for bitmap index file "
181 "(Git requires BITMAP_OPT_FULL_DAG)");
182
183 if (flags & BITMAP_OPT_HASH_CACHE) {
@@ -215,7 +216,7 @@ static struct stored_bitmap *store_bitmap(struct bitmap_index *index,
216 * because the SHA1 already existed on the map. this is bad, there
217 * shouldn't be duplicated commits in the index */
218 if (ret == 0) {
218 - error("Duplicate entry in bitmap index: %s", oid_to_hex(oid));
219 + error("duplicate entry in bitmap index: '%s'", oid_to_hex(oid));
220 return NULL;
221 }
222
@@ -274,13 +275,13 @@ static int load_bitmap_entries_v1(struct bitmap_index *index)
275 return -1;
276
277 if (xor_offset > MAX_XOR_OFFSET || xor_offset > i)
277 - return error("Corrupted bitmap pack index");
278 + return error("corrupted bitmap pack index");
279
280 if (xor_offset > 0) {
281 xor_bitmap = recent_bitmaps[(i - xor_offset) % MAX_XOR_OFFSET];
282
283 if (xor_bitmap == NULL)
283 - return error("Invalid XOR offset in bitmap pack index");
284 + return error("invalid XOR offset in bitmap pack index");
285 }
286
287 recent_bitmaps[i % MAX_XOR_OFFSET] = store_bitmap(
@@ -330,7 +331,7 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,
331 struct strbuf buf = STRBUF_INIT;
332 get_midx_filename(&buf, midx->object_dir);
333 /* ignore extra bitmap file; we can only handle one */
333 - warning("ignoring extra bitmap file: %s", buf.buf);
334 + warning("ignoring extra bitmap file: '%s'", buf.buf);
335 close(fd);
336 strbuf_release(&buf);
337 return -1;
@@ -387,7 +388,7 @@ static int open_pack_bitmap_1(struct bitmap_index *bitmap_git, struct packed_git
388
389 if (bitmap_git->pack || bitmap_git->midx) {
390 /* ignore extra bitmap file; we can only handle one */
390 - warning("ignoring extra bitmap file: %s", packfile->pack_name);
391 + warning("ignoring extra bitmap file: '%s'", packfile->pack_name);
392 close(fd);
393 return -1;
394 }
@@ -1626,15 +1627,15 @@ static void test_bitmap_type(struct bitmap_test_data *tdata,
1627 }
1628
1629 if (bitmap_type == OBJ_NONE)
1629 - die("object %s not found in type bitmaps",
1630 + die("object '%s' not found in type bitmaps",
1631 oid_to_hex(&obj->oid));
1632
1633 if (bitmaps_nr > 1)
1633 - die("object %s does not have a unique type",
1634 + die("object '%s' does not have a unique type",
1635 oid_to_hex(&obj->oid));
1636
1637 if (bitmap_type != obj->type)
1637 - die("object %s: real type %s, expected: %s",
1638 + die("object '%s': real type '%s', expected: '%s'",
1639 oid_to_hex(&obj->oid),
1640 type_name(obj->type),
1641 type_name(bitmap_type));
@@ -1648,7 +1649,7 @@ static void test_show_object(struct object *object, const char *name,
1649
1650 bitmap_pos = bitmap_position(tdata->bitmap_git, &object->oid);
1651 if (bitmap_pos < 0)
1651 - die("Object not in bitmap: %s\n", oid_to_hex(&object->oid));
1652 + die("object not in bitmap: '%s'", oid_to_hex(&object->oid));
1653 test_bitmap_type(tdata, object, bitmap_pos);
1654
1655 bitmap_set(tdata->base, bitmap_pos);
@@ -1663,7 +1664,7 @@ static void test_show_commit(struct commit *commit, void *data)
1664 bitmap_pos = bitmap_position(tdata->bitmap_git,
1665 &commit->object.oid);
1666 if (bitmap_pos < 0)
1666 - die("Object not in bitmap: %s\n", oid_to_hex(&commit->object.oid));
1667 + die("object not in bitmap: '%s'", oid_to_hex(&commit->object.oid));
1668 test_bitmap_type(tdata, &commit->object, bitmap_pos);
1669
1670 bitmap_set(tdata->base, bitmap_pos);
@@ -1685,21 +1686,21 @@ void test_bitmap_walk(struct rev_info *revs)
1686 if (revs->pending.nr != 1)
1687 die("you must specify exactly one commit to test");
1688
1688 - fprintf(stderr, "Bitmap v%d test (%d entries loaded)\n",
1689 + fprintf_ln(stderr, "Bitmap v%d test (%d entries loaded)",
1690 bitmap_git->version, bitmap_git->entry_count);
1691
1692 root = revs->pending.objects[0].item;
1693 bm = bitmap_for_commit(bitmap_git, (struct commit *)root);
1694
1695 if (bm) {
1695 - fprintf(stderr, "Found bitmap for %s. %d bits / %08x checksum\n",
1696 + fprintf_ln(stderr, "Found bitmap for '%s'. %d bits / %08x checksum",
1697 oid_to_hex(&root->oid), (int)bm->bit_size, ewah_checksum(bm));
1698
1699 result = ewah_to_bitmap(bm);
1700 }
1701
1702 if (result == NULL)
1702 - die("Commit %s doesn't have an indexed bitmap", oid_to_hex(&root->oid));
1703 + die("commit '%s' doesn't have an indexed bitmap", oid_to_hex(&root->oid));
1704
1705 revs->tag_objects = 1;
1706 revs->tree_objects = 1;
@@ -1724,7 +1725,7 @@ void test_bitmap_walk(struct rev_info *revs)
1725 stop_progress(&tdata.prg);
1726
1727 if (bitmap_equals(result, tdata.base))
1727 - fprintf(stderr, "OK!\n");
1728 + fprintf_ln(stderr, "OK!");
1729 else
1730 die("mismatch in bitmap results");
1731
@@ -1747,7 +1748,7 @@ int test_bitmap_commits(struct repository *r)
1748 die("failed to load bitmap indexes");
1749
1750 kh_foreach(bitmap_git->bitmaps, oid, value, {
1750 - printf("%s\n", oid_to_hex(&oid));
1751 + printf_ln("%s", oid_to_hex(&oid));
1752 });
1753
1754 free_bitmap_index(bitmap_git);
@@ -1772,7 +1773,7 @@ int test_bitmap_hashes(struct repository *r)
1773
1774 nth_bitmap_object_oid(bitmap_git, &oid, index_pos);
1775
1775 - printf("%s %"PRIu32"\n",
1776 + printf_ln("%s %"PRIu32"",
1777 oid_to_hex(&oid), get_be32(bitmap_git->hashes + index_pos));
1778 }
1779
@@ -1934,7 +1935,7 @@ static off_t get_disk_usage_for_type(struct bitmap_index *bitmap_git,
1935 struct object_id oid;
1936 nth_midxed_object_oid(&oid, bitmap_git->midx, midx_pos);
1937
1937 - die(_("could not find %s in pack %s at offset %"PRIuMAX),
1938 + die(_("could not find '%s' in pack '%s' at offset %"PRIuMAX),
1939 oid_to_hex(&oid),
1940 pack->pack_name,
1941 (uintmax_t)offset);
@@ -1970,7 +1971,7 @@ static off_t get_disk_usage_for_extended(struct bitmap_index *bitmap_git)
1971 continue;
1972
1973 if (oid_object_info_extended(the_repository, &obj->oid, &oi, 0) < 0)
1973 - die(_("unable to get disk usage of %s"),
1974 + die(_("unable to get disk usage of '%s'"),
1975 oid_to_hex(&obj->oid));
1976
1977 total += object_size;