@@ -266,7 +266,7 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
266
266
struct git_istream * st = NULL ;
267
267
268
268
if (!usable_delta ) {
269
- if (entry -> type == OBJ_BLOB &&
269
+ if (oe_type ( entry ) == OBJ_BLOB &&
270
270
entry -> size > big_file_threshold &&
271
271
(st = open_istream (& entry -> idx .oid , & type , & size , NULL )) != NULL )
272
272
buf = NULL ;
@@ -371,7 +371,7 @@ static off_t write_reuse_object(struct hashfile *f, struct object_entry *entry,
371
371
struct pack_window * w_curs = NULL ;
372
372
struct revindex_entry * revidx ;
373
373
off_t offset ;
374
- enum object_type type = entry -> type ;
374
+ enum object_type type = oe_type ( entry ) ;
375
375
off_t datalen ;
376
376
unsigned char header [MAX_PACK_OBJECT_HEADER ],
377
377
dheader [MAX_PACK_OBJECT_HEADER ];
@@ -480,11 +480,12 @@ static off_t write_object(struct hashfile *f,
480
480
to_reuse = 0 ; /* explicit */
481
481
else if (!entry -> in_pack )
482
482
to_reuse = 0 ; /* can't reuse what we don't have */
483
- else if (entry -> type == OBJ_REF_DELTA || entry -> type == OBJ_OFS_DELTA )
483
+ else if (oe_type (entry ) == OBJ_REF_DELTA ||
484
+ oe_type (entry ) == OBJ_OFS_DELTA )
484
485
/* check_object() decided it for us ... */
485
486
to_reuse = usable_delta ;
486
487
/* ... but pack split may override that */
487
- else if (entry -> type != entry -> in_pack_type )
488
+ else if (oe_type ( entry ) != entry -> in_pack_type )
488
489
to_reuse = 0 ; /* pack has delta which is unusable */
489
490
else if (entry -> delta )
490
491
to_reuse = 0 ; /* we want to pack afresh */
@@ -705,8 +706,8 @@ static struct object_entry **compute_write_order(void)
705
706
* And then all remaining commits and tags.
706
707
*/
707
708
for (i = last_untagged ; i < to_pack .nr_objects ; i ++ ) {
708
- if (objects [i ]. type != OBJ_COMMIT &&
709
- objects [i ]. type != OBJ_TAG )
709
+ if (oe_type ( & objects [i ]) != OBJ_COMMIT &&
710
+ oe_type ( & objects [i ]) != OBJ_TAG )
710
711
continue ;
711
712
add_to_write_order (wo , & wo_end , & objects [i ]);
712
713
}
@@ -715,7 +716,7 @@ static struct object_entry **compute_write_order(void)
715
716
* And then all the trees.
716
717
*/
717
718
for (i = last_untagged ; i < to_pack .nr_objects ; i ++ ) {
718
- if (objects [i ]. type != OBJ_TREE )
719
+ if (oe_type ( & objects [i ]) != OBJ_TREE )
719
720
continue ;
720
721
add_to_write_order (wo , & wo_end , & objects [i ]);
721
722
}
@@ -1066,8 +1067,7 @@ static void create_object_entry(const struct object_id *oid,
1066
1067
1067
1068
entry = packlist_alloc (& to_pack , oid -> hash , index_pos );
1068
1069
entry -> hash = hash ;
1069
- if (type )
1070
- entry -> type = type ;
1070
+ oe_set_type (entry , type );
1071
1071
if (exclude )
1072
1072
entry -> preferred_base = 1 ;
1073
1073
else
@@ -1407,6 +1407,7 @@ static void check_object(struct object_entry *entry)
1407
1407
unsigned long avail ;
1408
1408
off_t ofs ;
1409
1409
unsigned char * buf , c ;
1410
+ enum object_type type ;
1410
1411
1411
1412
buf = use_pack (p , & w_curs , entry -> in_pack_offset , & avail );
1412
1413
@@ -1415,11 +1416,15 @@ static void check_object(struct object_entry *entry)
1415
1416
* since non-delta representations could still be reused.
1416
1417
*/
1417
1418
used = unpack_object_header_buffer (buf , avail ,
1418
- & entry -> in_pack_type ,
1419
+ & type ,
1419
1420
& entry -> size );
1420
1421
if (used == 0 )
1421
1422
goto give_up ;
1422
1423
1424
+ if (type < 0 )
1425
+ BUG ("invalid type %d" , type );
1426
+ entry -> in_pack_type = type ;
1427
+
1423
1428
/*
1424
1429
* Determine if this is a delta and if so whether we can
1425
1430
* reuse it or not. Otherwise let's find out as cheaply as
@@ -1428,9 +1433,9 @@ static void check_object(struct object_entry *entry)
1428
1433
switch (entry -> in_pack_type ) {
1429
1434
default :
1430
1435
/* Not a delta hence we've already got all we need. */
1431
- entry -> type = entry -> in_pack_type ;
1436
+ oe_set_type ( entry , entry -> in_pack_type ) ;
1432
1437
entry -> in_pack_header_size = used ;
1433
- if (entry -> type < OBJ_COMMIT || entry -> type > OBJ_BLOB )
1438
+ if (oe_type ( entry ) < OBJ_COMMIT || oe_type ( entry ) > OBJ_BLOB )
1434
1439
goto give_up ;
1435
1440
unuse_pack (& w_curs );
1436
1441
return ;
@@ -1484,7 +1489,7 @@ static void check_object(struct object_entry *entry)
1484
1489
* deltify other objects against, in order to avoid
1485
1490
* circular deltas.
1486
1491
*/
1487
- entry -> type = entry -> in_pack_type ;
1492
+ oe_set_type ( entry , entry -> in_pack_type ) ;
1488
1493
entry -> delta = base_entry ;
1489
1494
entry -> delta_size = entry -> size ;
1490
1495
entry -> delta_sibling = base_entry -> delta_child ;
@@ -1493,7 +1498,7 @@ static void check_object(struct object_entry *entry)
1493
1498
return ;
1494
1499
}
1495
1500
1496
- if (entry -> type ) {
1501
+ if (oe_type ( entry ) ) {
1497
1502
/*
1498
1503
* This must be a delta and we already know what the
1499
1504
* final object type is. Let's extract the actual
@@ -1516,7 +1521,7 @@ static void check_object(struct object_entry *entry)
1516
1521
unuse_pack (& w_curs );
1517
1522
}
1518
1523
1519
- entry -> type = oid_object_info (& entry -> idx .oid , & entry -> size );
1524
+ oe_set_type ( entry , oid_object_info (& entry -> idx .oid , & entry -> size ) );
1520
1525
/*
1521
1526
* The error condition is checked in prepare_pack(). This is
1522
1527
* to permit a missing preferred base object to be ignored
@@ -1559,6 +1564,7 @@ static void drop_reused_delta(struct object_entry *entry)
1559
1564
{
1560
1565
struct object_entry * * p = & entry -> delta -> delta_child ;
1561
1566
struct object_info oi = OBJECT_INFO_INIT ;
1567
+ enum object_type type ;
1562
1568
1563
1569
while (* p ) {
1564
1570
if (* p == entry )
@@ -1570,15 +1576,18 @@ static void drop_reused_delta(struct object_entry *entry)
1570
1576
entry -> depth = 0 ;
1571
1577
1572
1578
oi .sizep = & entry -> size ;
1573
- oi .typep = & entry -> type ;
1579
+ oi .typep = & type ;
1574
1580
if (packed_object_info (entry -> in_pack , entry -> in_pack_offset , & oi ) < 0 ) {
1575
1581
/*
1576
1582
* We failed to get the info from this pack for some reason;
1577
1583
* fall back to sha1_object_info, which may find another copy.
1578
- * And if that fails, the error will be recorded in entry->type
1584
+ * And if that fails, the error will be recorded in oe_type( entry)
1579
1585
* and dealt with in prepare_pack().
1580
1586
*/
1581
- entry -> type = oid_object_info (& entry -> idx .oid , & entry -> size );
1587
+ oe_set_type (entry , oid_object_info (& entry -> idx .oid ,
1588
+ & entry -> size ));
1589
+ } else {
1590
+ oe_set_type (entry , type );
1582
1591
}
1583
1592
}
1584
1593
@@ -1746,10 +1755,12 @@ static int type_size_sort(const void *_a, const void *_b)
1746
1755
{
1747
1756
const struct object_entry * a = * (struct object_entry * * )_a ;
1748
1757
const struct object_entry * b = * (struct object_entry * * )_b ;
1758
+ enum object_type a_type = oe_type (a );
1759
+ enum object_type b_type = oe_type (b );
1749
1760
1750
- if (a -> type > b -> type )
1761
+ if (a_type > b_type )
1751
1762
return -1 ;
1752
- if (a -> type < b -> type )
1763
+ if (a_type < b_type )
1753
1764
return 1 ;
1754
1765
if (a -> hash > b -> hash )
1755
1766
return -1 ;
@@ -1825,7 +1836,7 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
1825
1836
void * delta_buf ;
1826
1837
1827
1838
/* Don't bother doing diffs between different types */
1828
- if (trg_entry -> type != src_entry -> type )
1839
+ if (oe_type ( trg_entry ) != oe_type ( src_entry ) )
1829
1840
return -1 ;
1830
1841
1831
1842
/*
@@ -2429,11 +2440,11 @@ static void prepare_pack(int window, int depth)
2429
2440
2430
2441
if (!entry -> preferred_base ) {
2431
2442
nr_deltas ++ ;
2432
- if (entry -> type < 0 )
2443
+ if (oe_type ( entry ) < 0 )
2433
2444
die ("unable to get type of object %s" ,
2434
2445
oid_to_hex (& entry -> idx .oid ));
2435
2446
} else {
2436
- if (entry -> type < 0 ) {
2447
+ if (oe_type ( entry ) < 0 ) {
2437
2448
/*
2438
2449
* This object is not found, but we
2439
2450
* don't have to include it anyway.
@@ -2542,7 +2553,7 @@ static void read_object_list_from_stdin(void)
2542
2553
die ("expected object ID, got garbage:\n %s" , line );
2543
2554
2544
2555
add_preferred_base_object (p + 1 );
2545
- add_object_entry (& oid , 0 , p + 1 , 0 );
2556
+ add_object_entry (& oid , OBJ_NONE , p + 1 , 0 );
2546
2557
}
2547
2558
}
2548
2559
0 commit comments