Skip to content

Commit cc29f89

Browse files
committed
Merge branch 'tl/pack-bitmap-error-messages'
Tweak various messages that come from the pack-bitmap codepaths. * tl/pack-bitmap-error-messages: pack-bitmap.c: continue looping when first MIDX bitmap is found pack-bitmap.c: using error() instead of silently returning -1 pack-bitmap.c: do not ignore error when opening a bitmap file pack-bitmap.c: rename "idx_name" to "bitmap_name" pack-bitmap.c: mark more strings for translations pack-bitmap.c: fix formatting of error messages
2 parents 7c7719a + 5dcee7c commit cc29f89

File tree

1 file changed

+58
-45
lines changed

1 file changed

+58
-45
lines changed

pack-bitmap.c

Lines changed: 58 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "cache.h"
22
#include "commit.h"
3+
#include "strbuf.h"
34
#include "tag.h"
45
#include "diff.h"
56
#include "revision.h"
@@ -138,7 +139,7 @@ static struct ewah_bitmap *read_bitmap_1(struct bitmap_index *index)
138139
index->map_size - index->map_pos);
139140

140141
if (bitmap_size < 0) {
141-
error("Failed to load bitmap index (corrupted?)");
142+
error(_("failed to load bitmap index (corrupted?)"));
142143
ewah_pool_free(b);
143144
return NULL;
144145
}
@@ -160,14 +161,14 @@ static int load_bitmap_header(struct bitmap_index *index)
160161
size_t header_size = sizeof(*header) - GIT_MAX_RAWSZ + the_hash_algo->rawsz;
161162

162163
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)"));
164165

165166
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)"));
167168

168169
index->version = ntohs(header->version);
169170
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);
171172

172173
/* Parse known bitmap format options */
173174
{
@@ -176,12 +177,12 @@ static int load_bitmap_header(struct bitmap_index *index)
176177
unsigned char *index_end = index->map + index->map_size - the_hash_algo->rawsz;
177178

178179
if ((flags & BITMAP_OPT_FULL_DAG) == 0)
179-
return error("Unsupported options for bitmap index file "
180+
BUG("unsupported options for bitmap index file "
180181
"(Git requires BITMAP_OPT_FULL_DAG)");
181182

182183
if (flags & BITMAP_OPT_HASH_CACHE) {
183184
if (cache_size > index_end - index->map - header_size)
184-
return error("corrupted bitmap index file (too short to fit hash cache)");
185+
return error(_("corrupted bitmap index file (too short to fit hash cache)"));
185186
index->hashes = (void *)(index_end - cache_size);
186187
index_end -= cache_size;
187188
}
@@ -215,7 +216,7 @@ static struct stored_bitmap *store_bitmap(struct bitmap_index *index,
215216
* because the SHA1 already existed on the map. this is bad, there
216217
* shouldn't be duplicated commits in the index */
217218
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));
219220
return NULL;
220221
}
221222

@@ -259,28 +260,28 @@ static int load_bitmap_entries_v1(struct bitmap_index *index)
259260
struct object_id oid;
260261

261262
if (index->map_size - index->map_pos < 6)
262-
return error("corrupt ewah bitmap: truncated header for entry %d", i);
263+
return error(_("corrupt ewah bitmap: truncated header for entry %d"), i);
263264

264265
commit_idx_pos = read_be32(index->map, &index->map_pos);
265266
xor_offset = read_u8(index->map, &index->map_pos);
266267
flags = read_u8(index->map, &index->map_pos);
267268

268269
if (nth_bitmap_object_oid(index, &oid, commit_idx_pos) < 0)
269-
return error("corrupt ewah bitmap: commit index %u out of range",
270+
return error(_("corrupt ewah bitmap: commit index %u out of range"),
270271
(unsigned)commit_idx_pos);
271272

272273
bitmap = read_bitmap_1(index);
273274
if (!bitmap)
274275
return -1;
275276

276277
if (xor_offset > MAX_XOR_OFFSET || xor_offset > i)
277-
return error("Corrupted bitmap pack index");
278+
return error(_("corrupted bitmap pack index"));
278279

279280
if (xor_offset > 0) {
280281
xor_bitmap = recent_bitmaps[(i - xor_offset) % MAX_XOR_OFFSET];
281282

282283
if (!xor_bitmap)
283-
return error("Invalid XOR offset in bitmap pack index");
284+
return error(_("invalid XOR offset in bitmap pack index"));
284285
}
285286

286287
recent_bitmaps[i % MAX_XOR_OFFSET] = store_bitmap(
@@ -313,17 +314,21 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,
313314
struct multi_pack_index *midx)
314315
{
315316
struct stat st;
316-
char *idx_name = midx_bitmap_filename(midx);
317-
int fd = git_open(idx_name);
317+
char *bitmap_name = midx_bitmap_filename(midx);
318+
int fd = git_open(bitmap_name);
318319
uint32_t i;
319320
struct packed_git *preferred;
320321

321-
free(idx_name);
322-
323-
if (fd < 0)
322+
if (fd < 0) {
323+
if (errno != ENOENT)
324+
warning_errno("cannot open '%s'", bitmap_name);
325+
free(bitmap_name);
324326
return -1;
327+
}
328+
free(bitmap_name);
325329

326330
if (fstat(fd, &st)) {
331+
error_errno(_("cannot fstat bitmap file"));
327332
close(fd);
328333
return -1;
329334
}
@@ -332,7 +337,7 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,
332337
struct strbuf buf = STRBUF_INIT;
333338
get_midx_filename(&buf, midx->object_dir);
334339
/* ignore extra bitmap file; we can only handle one */
335-
warning("ignoring extra bitmap file: %s", buf.buf);
340+
warning(_("ignoring extra bitmap file: '%s'"), buf.buf);
336341
close(fd);
337342
strbuf_release(&buf);
338343
return -1;
@@ -348,8 +353,10 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,
348353
if (load_bitmap_header(bitmap_git) < 0)
349354
goto cleanup;
350355

351-
if (!hasheq(get_midx_checksum(bitmap_git->midx), bitmap_git->checksum))
356+
if (!hasheq(get_midx_checksum(bitmap_git->midx), bitmap_git->checksum)) {
357+
error(_("checksum doesn't match in MIDX and bitmap"));
352358
goto cleanup;
359+
}
353360

354361
if (load_midx_revindex(bitmap_git->midx) < 0) {
355362
warning(_("multi-pack bitmap is missing required reverse index"));
@@ -384,26 +391,31 @@ static int open_pack_bitmap_1(struct bitmap_index *bitmap_git, struct packed_git
384391
{
385392
int fd;
386393
struct stat st;
387-
char *idx_name;
394+
char *bitmap_name;
388395

389396
if (open_pack_index(packfile))
390397
return -1;
391398

392-
idx_name = pack_bitmap_filename(packfile);
393-
fd = git_open(idx_name);
394-
free(idx_name);
399+
bitmap_name = pack_bitmap_filename(packfile);
400+
fd = git_open(bitmap_name);
395401

396-
if (fd < 0)
402+
if (fd < 0) {
403+
if (errno != ENOENT)
404+
warning_errno("cannot open '%s'", bitmap_name);
405+
free(bitmap_name);
397406
return -1;
407+
}
408+
free(bitmap_name);
398409

399410
if (fstat(fd, &st)) {
411+
error_errno(_("cannot fstat bitmap file"));
400412
close(fd);
401413
return -1;
402414
}
403415

404416
if (bitmap_git->pack || bitmap_git->midx) {
405417
/* ignore extra bitmap file; we can only handle one */
406-
warning("ignoring extra bitmap file: %s", packfile->pack_name);
418+
warning(_("ignoring extra bitmap file: '%s'"), packfile->pack_name);
407419
close(fd);
408420
return -1;
409421
}
@@ -508,15 +520,16 @@ static int open_pack_bitmap(struct repository *r,
508520
static int open_midx_bitmap(struct repository *r,
509521
struct bitmap_index *bitmap_git)
510522
{
523+
int ret = -1;
511524
struct multi_pack_index *midx;
512525

513526
assert(!bitmap_git->map);
514527

515528
for (midx = get_multi_pack_index(r); midx; midx = midx->next) {
516529
if (!open_midx_bitmap_1(bitmap_git, midx))
517-
return 0;
530+
ret = 0;
518531
}
519-
return -1;
532+
return ret;
520533
}
521534

522535
static int open_bitmap(struct repository *r,
@@ -831,7 +844,7 @@ static struct bitmap *find_objects(struct bitmap_index *bitmap_git,
831844
revs->include_check_data = &incdata;
832845

833846
if (prepare_revision_walk(revs))
834-
die("revision walk setup failed");
847+
die(_("revision walk setup failed"));
835848

836849
show_data.bitmap_git = bitmap_git;
837850
show_data.base = base;
@@ -1640,15 +1653,15 @@ static void test_bitmap_type(struct bitmap_test_data *tdata,
16401653
}
16411654

16421655
if (bitmap_type == OBJ_NONE)
1643-
die("object %s not found in type bitmaps",
1656+
die(_("object '%s' not found in type bitmaps"),
16441657
oid_to_hex(&obj->oid));
16451658

16461659
if (bitmaps_nr > 1)
1647-
die("object %s does not have a unique type",
1660+
die(_("object '%s' does not have a unique type"),
16481661
oid_to_hex(&obj->oid));
16491662

16501663
if (bitmap_type != obj->type)
1651-
die("object %s: real type %s, expected: %s",
1664+
die(_("object '%s': real type '%s', expected: '%s'"),
16521665
oid_to_hex(&obj->oid),
16531666
type_name(obj->type),
16541667
type_name(bitmap_type));
@@ -1662,7 +1675,7 @@ static void test_show_object(struct object *object, const char *name,
16621675

16631676
bitmap_pos = bitmap_position(tdata->bitmap_git, &object->oid);
16641677
if (bitmap_pos < 0)
1665-
die("Object not in bitmap: %s\n", oid_to_hex(&object->oid));
1678+
die(_("object not in bitmap: '%s'"), oid_to_hex(&object->oid));
16661679
test_bitmap_type(tdata, object, bitmap_pos);
16671680

16681681
bitmap_set(tdata->base, bitmap_pos);
@@ -1677,7 +1690,7 @@ static void test_show_commit(struct commit *commit, void *data)
16771690
bitmap_pos = bitmap_position(tdata->bitmap_git,
16781691
&commit->object.oid);
16791692
if (bitmap_pos < 0)
1680-
die("Object not in bitmap: %s\n", oid_to_hex(&commit->object.oid));
1693+
die(_("object not in bitmap: '%s'"), oid_to_hex(&commit->object.oid));
16811694
test_bitmap_type(tdata, &commit->object, bitmap_pos);
16821695

16831696
bitmap_set(tdata->base, bitmap_pos);
@@ -1694,26 +1707,26 @@ void test_bitmap_walk(struct rev_info *revs)
16941707
struct ewah_bitmap *bm;
16951708

16961709
if (!(bitmap_git = prepare_bitmap_git(revs->repo)))
1697-
die("failed to load bitmap indexes");
1710+
die(_("failed to load bitmap indexes"));
16981711

16991712
if (revs->pending.nr != 1)
1700-
die("you must specify exactly one commit to test");
1713+
die(_("you must specify exactly one commit to test"));
17011714

1702-
fprintf(stderr, "Bitmap v%d test (%d entries loaded)\n",
1715+
fprintf_ln(stderr, "Bitmap v%d test (%d entries loaded)",
17031716
bitmap_git->version, bitmap_git->entry_count);
17041717

17051718
root = revs->pending.objects[0].item;
17061719
bm = bitmap_for_commit(bitmap_git, (struct commit *)root);
17071720

17081721
if (bm) {
1709-
fprintf(stderr, "Found bitmap for %s. %d bits / %08x checksum\n",
1722+
fprintf_ln(stderr, "Found bitmap for '%s'. %d bits / %08x checksum",
17101723
oid_to_hex(&root->oid), (int)bm->bit_size, ewah_checksum(bm));
17111724

17121725
result = ewah_to_bitmap(bm);
17131726
}
17141727

17151728
if (!result)
1716-
die("Commit %s doesn't have an indexed bitmap", oid_to_hex(&root->oid));
1729+
die(_("commit '%s' doesn't have an indexed bitmap"), oid_to_hex(&root->oid));
17171730

17181731
revs->tag_objects = 1;
17191732
revs->tree_objects = 1;
@@ -1722,7 +1735,7 @@ void test_bitmap_walk(struct rev_info *revs)
17221735
result_popcnt = bitmap_popcount(result);
17231736

17241737
if (prepare_revision_walk(revs))
1725-
die("revision walk setup failed");
1738+
die(_("revision walk setup failed"));
17261739

17271740
tdata.bitmap_git = bitmap_git;
17281741
tdata.base = bitmap_new();
@@ -1738,9 +1751,9 @@ void test_bitmap_walk(struct rev_info *revs)
17381751
stop_progress(&tdata.prg);
17391752

17401753
if (bitmap_equals(result, tdata.base))
1741-
fprintf(stderr, "OK!\n");
1754+
fprintf_ln(stderr, "OK!");
17421755
else
1743-
die("mismatch in bitmap results");
1756+
die(_("mismatch in bitmap results"));
17441757

17451758
bitmap_free(result);
17461759
bitmap_free(tdata.base);
@@ -1758,10 +1771,10 @@ int test_bitmap_commits(struct repository *r)
17581771
MAYBE_UNUSED void *value;
17591772

17601773
if (!bitmap_git)
1761-
die("failed to load bitmap indexes");
1774+
die(_("failed to load bitmap indexes"));
17621775

17631776
kh_foreach(bitmap_git->bitmaps, oid, value, {
1764-
printf("%s\n", oid_to_hex(&oid));
1777+
printf_ln("%s", oid_to_hex(&oid));
17651778
});
17661779

17671780
free_bitmap_index(bitmap_git);
@@ -1786,7 +1799,7 @@ int test_bitmap_hashes(struct repository *r)
17861799

17871800
nth_bitmap_object_oid(bitmap_git, &oid, index_pos);
17881801

1789-
printf("%s %"PRIu32"\n",
1802+
printf_ln("%s %"PRIu32"",
17901803
oid_to_hex(&oid), get_be32(bitmap_git->hashes + index_pos));
17911804
}
17921805

@@ -1948,7 +1961,7 @@ static off_t get_disk_usage_for_type(struct bitmap_index *bitmap_git,
19481961
struct object_id oid;
19491962
nth_midxed_object_oid(&oid, bitmap_git->midx, midx_pos);
19501963

1951-
die(_("could not find %s in pack %s at offset %"PRIuMAX),
1964+
die(_("could not find '%s' in pack '%s' at offset %"PRIuMAX),
19521965
oid_to_hex(&oid),
19531966
pack->pack_name,
19541967
(uintmax_t)offset);
@@ -1984,7 +1997,7 @@ static off_t get_disk_usage_for_extended(struct bitmap_index *bitmap_git)
19841997
continue;
19851998

19861999
if (oid_object_info_extended(the_repository, &obj->oid, &oi, 0) < 0)
1987-
die(_("unable to get disk usage of %s"),
2000+
die(_("unable to get disk usage of '%s'"),
19882001
oid_to_hex(&obj->oid));
19892002

19902003
total += object_size;

0 commit comments

Comments
 (0)