1
1
#include "cache.h"
2
2
#include "commit.h"
3
+ #include "strbuf.h"
3
4
#include "tag.h"
4
5
#include "diff.h"
5
6
#include "revision.h"
@@ -138,7 +139,7 @@ static struct ewah_bitmap *read_bitmap_1(struct bitmap_index *index)
138
139
index -> map_size - index -> map_pos );
139
140
140
141
if (bitmap_size < 0 ) {
141
- error ("Failed to load bitmap index (corrupted?)" );
142
+ error (_ ( "failed to load bitmap index (corrupted?)") );
142
143
ewah_pool_free (b );
143
144
return NULL ;
144
145
}
@@ -160,14 +161,14 @@ static int load_bitmap_header(struct bitmap_index *index)
160
161
size_t header_size = sizeof (* header ) - GIT_MAX_RAWSZ + the_hash_algo -> rawsz ;
161
162
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)") );
164
165
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)") );
167
168
168
169
index -> version = ntohs (header -> version );
169
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 );
171
172
172
173
/* Parse known bitmap format options */
173
174
{
@@ -176,12 +177,12 @@ static int load_bitmap_header(struct bitmap_index *index)
176
177
unsigned char * index_end = index -> map + index -> map_size - the_hash_algo -> rawsz ;
177
178
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 "
180
181
"(Git requires BITMAP_OPT_FULL_DAG)" );
181
182
182
183
if (flags & BITMAP_OPT_HASH_CACHE ) {
183
184
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)" ) );
185
186
index -> hashes = (void * )(index_end - cache_size );
186
187
index_end -= cache_size ;
187
188
}
@@ -215,7 +216,7 @@ static struct stored_bitmap *store_bitmap(struct bitmap_index *index,
215
216
* because the SHA1 already existed on the map. this is bad, there
216
217
* shouldn't be duplicated commits in the index */
217
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 ));
219
220
return NULL ;
220
221
}
221
222
@@ -259,28 +260,28 @@ static int load_bitmap_entries_v1(struct bitmap_index *index)
259
260
struct object_id oid ;
260
261
261
262
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 );
263
264
264
265
commit_idx_pos = read_be32 (index -> map , & index -> map_pos );
265
266
xor_offset = read_u8 (index -> map , & index -> map_pos );
266
267
flags = read_u8 (index -> map , & index -> map_pos );
267
268
268
269
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" ) ,
270
271
(unsigned )commit_idx_pos );
271
272
272
273
bitmap = read_bitmap_1 (index );
273
274
if (!bitmap )
274
275
return -1 ;
275
276
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") );
278
279
279
280
if (xor_offset > 0 ) {
280
281
xor_bitmap = recent_bitmaps [(i - xor_offset ) % MAX_XOR_OFFSET ];
281
282
282
283
if (!xor_bitmap )
283
- return error ("Invalid XOR offset in bitmap pack index" );
284
+ return error (_ ( "invalid XOR offset in bitmap pack index") );
284
285
}
285
286
286
287
recent_bitmaps [i % MAX_XOR_OFFSET ] = store_bitmap (
@@ -313,17 +314,21 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,
313
314
struct multi_pack_index * midx )
314
315
{
315
316
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 );
318
319
uint32_t i ;
319
320
struct packed_git * preferred ;
320
321
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 );
324
326
return -1 ;
327
+ }
328
+ free (bitmap_name );
325
329
326
330
if (fstat (fd , & st )) {
331
+ error_errno (_ ("cannot fstat bitmap file" ));
327
332
close (fd );
328
333
return -1 ;
329
334
}
@@ -332,7 +337,7 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,
332
337
struct strbuf buf = STRBUF_INIT ;
333
338
get_midx_filename (& buf , midx -> object_dir );
334
339
/* 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 );
336
341
close (fd );
337
342
strbuf_release (& buf );
338
343
return -1 ;
@@ -348,8 +353,10 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,
348
353
if (load_bitmap_header (bitmap_git ) < 0 )
349
354
goto cleanup ;
350
355
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" ));
352
358
goto cleanup ;
359
+ }
353
360
354
361
if (load_midx_revindex (bitmap_git -> midx ) < 0 ) {
355
362
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
384
391
{
385
392
int fd ;
386
393
struct stat st ;
387
- char * idx_name ;
394
+ char * bitmap_name ;
388
395
389
396
if (open_pack_index (packfile ))
390
397
return -1 ;
391
398
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 );
395
401
396
- if (fd < 0 )
402
+ if (fd < 0 ) {
403
+ if (errno != ENOENT )
404
+ warning_errno ("cannot open '%s'" , bitmap_name );
405
+ free (bitmap_name );
397
406
return -1 ;
407
+ }
408
+ free (bitmap_name );
398
409
399
410
if (fstat (fd , & st )) {
411
+ error_errno (_ ("cannot fstat bitmap file" ));
400
412
close (fd );
401
413
return -1 ;
402
414
}
403
415
404
416
if (bitmap_git -> pack || bitmap_git -> midx ) {
405
417
/* 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 );
407
419
close (fd );
408
420
return -1 ;
409
421
}
@@ -508,15 +520,16 @@ static int open_pack_bitmap(struct repository *r,
508
520
static int open_midx_bitmap (struct repository * r ,
509
521
struct bitmap_index * bitmap_git )
510
522
{
523
+ int ret = -1 ;
511
524
struct multi_pack_index * midx ;
512
525
513
526
assert (!bitmap_git -> map );
514
527
515
528
for (midx = get_multi_pack_index (r ); midx ; midx = midx -> next ) {
516
529
if (!open_midx_bitmap_1 (bitmap_git , midx ))
517
- return 0 ;
530
+ ret = 0 ;
518
531
}
519
- return -1 ;
532
+ return ret ;
520
533
}
521
534
522
535
static int open_bitmap (struct repository * r ,
@@ -831,7 +844,7 @@ static struct bitmap *find_objects(struct bitmap_index *bitmap_git,
831
844
revs -> include_check_data = & incdata ;
832
845
833
846
if (prepare_revision_walk (revs ))
834
- die ("revision walk setup failed" );
847
+ die (_ ( "revision walk setup failed" ) );
835
848
836
849
show_data .bitmap_git = bitmap_git ;
837
850
show_data .base = base ;
@@ -1640,15 +1653,15 @@ static void test_bitmap_type(struct bitmap_test_data *tdata,
1640
1653
}
1641
1654
1642
1655
if (bitmap_type == OBJ_NONE )
1643
- die ("object %s not found in type bitmaps" ,
1656
+ die (_ ( "object '%s' not found in type bitmaps" ) ,
1644
1657
oid_to_hex (& obj -> oid ));
1645
1658
1646
1659
if (bitmaps_nr > 1 )
1647
- die ("object %s does not have a unique type" ,
1660
+ die (_ ( "object '%s' does not have a unique type" ) ,
1648
1661
oid_to_hex (& obj -> oid ));
1649
1662
1650
1663
if (bitmap_type != obj -> type )
1651
- die ("object %s : real type %s , expected: %s" ,
1664
+ die (_ ( "object '%s' : real type '%s' , expected: '%s'" ) ,
1652
1665
oid_to_hex (& obj -> oid ),
1653
1666
type_name (obj -> type ),
1654
1667
type_name (bitmap_type ));
@@ -1662,7 +1675,7 @@ static void test_show_object(struct object *object, const char *name,
1662
1675
1663
1676
bitmap_pos = bitmap_position (tdata -> bitmap_git , & object -> oid );
1664
1677
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 ));
1666
1679
test_bitmap_type (tdata , object , bitmap_pos );
1667
1680
1668
1681
bitmap_set (tdata -> base , bitmap_pos );
@@ -1677,7 +1690,7 @@ static void test_show_commit(struct commit *commit, void *data)
1677
1690
bitmap_pos = bitmap_position (tdata -> bitmap_git ,
1678
1691
& commit -> object .oid );
1679
1692
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 ));
1681
1694
test_bitmap_type (tdata , & commit -> object , bitmap_pos );
1682
1695
1683
1696
bitmap_set (tdata -> base , bitmap_pos );
@@ -1694,26 +1707,26 @@ void test_bitmap_walk(struct rev_info *revs)
1694
1707
struct ewah_bitmap * bm ;
1695
1708
1696
1709
if (!(bitmap_git = prepare_bitmap_git (revs -> repo )))
1697
- die ("failed to load bitmap indexes" );
1710
+ die (_ ( "failed to load bitmap indexes" ) );
1698
1711
1699
1712
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" ) );
1701
1714
1702
- fprintf (stderr , "Bitmap v%d test (%d entries loaded)\n " ,
1715
+ fprintf_ln (stderr , "Bitmap v%d test (%d entries loaded)" ,
1703
1716
bitmap_git -> version , bitmap_git -> entry_count );
1704
1717
1705
1718
root = revs -> pending .objects [0 ].item ;
1706
1719
bm = bitmap_for_commit (bitmap_git , (struct commit * )root );
1707
1720
1708
1721
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" ,
1710
1723
oid_to_hex (& root -> oid ), (int )bm -> bit_size , ewah_checksum (bm ));
1711
1724
1712
1725
result = ewah_to_bitmap (bm );
1713
1726
}
1714
1727
1715
1728
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 ));
1717
1730
1718
1731
revs -> tag_objects = 1 ;
1719
1732
revs -> tree_objects = 1 ;
@@ -1722,7 +1735,7 @@ void test_bitmap_walk(struct rev_info *revs)
1722
1735
result_popcnt = bitmap_popcount (result );
1723
1736
1724
1737
if (prepare_revision_walk (revs ))
1725
- die ("revision walk setup failed" );
1738
+ die (_ ( "revision walk setup failed" ) );
1726
1739
1727
1740
tdata .bitmap_git = bitmap_git ;
1728
1741
tdata .base = bitmap_new ();
@@ -1738,9 +1751,9 @@ void test_bitmap_walk(struct rev_info *revs)
1738
1751
stop_progress (& tdata .prg );
1739
1752
1740
1753
if (bitmap_equals (result , tdata .base ))
1741
- fprintf (stderr , "OK!\n " );
1754
+ fprintf_ln (stderr , "OK!" );
1742
1755
else
1743
- die ("mismatch in bitmap results" );
1756
+ die (_ ( "mismatch in bitmap results" ) );
1744
1757
1745
1758
bitmap_free (result );
1746
1759
bitmap_free (tdata .base );
@@ -1758,10 +1771,10 @@ int test_bitmap_commits(struct repository *r)
1758
1771
MAYBE_UNUSED void * value ;
1759
1772
1760
1773
if (!bitmap_git )
1761
- die ("failed to load bitmap indexes" );
1774
+ die (_ ( "failed to load bitmap indexes" ) );
1762
1775
1763
1776
kh_foreach (bitmap_git -> bitmaps , oid , value , {
1764
- printf ("%s\n " , oid_to_hex (& oid ));
1777
+ printf_ln ("%s" , oid_to_hex (& oid ));
1765
1778
});
1766
1779
1767
1780
free_bitmap_index (bitmap_git );
@@ -1786,7 +1799,7 @@ int test_bitmap_hashes(struct repository *r)
1786
1799
1787
1800
nth_bitmap_object_oid (bitmap_git , & oid , index_pos );
1788
1801
1789
- printf ("%s %" PRIu32 "\n " ,
1802
+ printf_ln ("%s %" PRIu32 "" ,
1790
1803
oid_to_hex (& oid ), get_be32 (bitmap_git -> hashes + index_pos ));
1791
1804
}
1792
1805
@@ -1948,7 +1961,7 @@ static off_t get_disk_usage_for_type(struct bitmap_index *bitmap_git,
1948
1961
struct object_id oid ;
1949
1962
nth_midxed_object_oid (& oid , bitmap_git -> midx , midx_pos );
1950
1963
1951
- die (_ ("could not find %s in pack %s at offset %" PRIuMAX ),
1964
+ die (_ ("could not find '%s' in pack '%s' at offset %" PRIuMAX ),
1952
1965
oid_to_hex (& oid ),
1953
1966
pack -> pack_name ,
1954
1967
(uintmax_t )offset );
@@ -1984,7 +1997,7 @@ static off_t get_disk_usage_for_extended(struct bitmap_index *bitmap_git)
1984
1997
continue ;
1985
1998
1986
1999
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' " ),
1988
2001
oid_to_hex (& obj -> oid ));
1989
2002
1990
2003
total += object_size ;
0 commit comments