@@ -872,14 +872,15 @@ static void write_reused_pack_one(size_t pos, struct hashfile *out,
872872 /* Convert to REF_DELTA if we must... */
873873 if (!allow_ofs_delta ) {
874874 int base_pos = find_revindex_position (reuse_packfile , base_offset );
875- const unsigned char * base_sha1 =
876- nth_packed_object_sha1 (reuse_packfile ,
877- reuse_packfile -> revindex [base_pos ].nr );
875+ struct object_id base_oid ;
876+
877+ nth_packed_object_id (& base_oid , reuse_packfile ,
878+ reuse_packfile -> revindex [base_pos ].nr );
878879
879880 len = encode_in_pack_object_header (header , sizeof (header ),
880881 OBJ_REF_DELTA , size );
881882 hashwrite (out , header , len );
882- hashwrite (out , base_sha1 , 20 );
883+ hashwrite (out , base_oid . hash , 20 );
883884 copy_pack_data (out , reuse_packfile , w_curs , cur , next - cur );
884885 return ;
885886 }
@@ -1618,23 +1619,17 @@ static void cleanup_preferred_base(void)
16181619 * deltify other objects against, in order to avoid
16191620 * circular deltas.
16201621 */
1621- static int can_reuse_delta (const unsigned char * base_sha1 ,
1622+ static int can_reuse_delta (const struct object_id * base_oid ,
16221623 struct object_entry * delta ,
16231624 struct object_entry * * base_out )
16241625{
16251626 struct object_entry * base ;
1626- struct object_id base_oid ;
1627-
1628- if (!base_sha1 )
1629- return 0 ;
1630-
1631- oidread (& base_oid , base_sha1 );
16321627
16331628 /*
16341629 * First see if we're already sending the base (or it's explicitly in
16351630 * our "excluded" list).
16361631 */
1637- base = packlist_find (& to_pack , & base_oid );
1632+ base = packlist_find (& to_pack , base_oid );
16381633 if (base ) {
16391634 if (!in_same_island (& delta -> idx .oid , & base -> idx .oid ))
16401635 return 0 ;
@@ -1647,9 +1642,9 @@ static int can_reuse_delta(const unsigned char *base_sha1,
16471642 * even if it was buried too deep in history to make it into the
16481643 * packing list.
16491644 */
1650- if (thin && bitmap_has_oid_in_uninteresting (bitmap_git , & base_oid )) {
1645+ if (thin && bitmap_has_oid_in_uninteresting (bitmap_git , base_oid )) {
16511646 if (use_delta_islands ) {
1652- if (!in_same_island (& delta -> idx .oid , & base_oid ))
1647+ if (!in_same_island (& delta -> idx .oid , base_oid ))
16531648 return 0 ;
16541649 }
16551650 * base_out = NULL ;
@@ -1666,7 +1661,8 @@ static void check_object(struct object_entry *entry)
16661661 if (IN_PACK (entry )) {
16671662 struct packed_git * p = IN_PACK (entry );
16681663 struct pack_window * w_curs = NULL ;
1669- const unsigned char * base_ref = NULL ;
1664+ int have_base = 0 ;
1665+ struct object_id base_ref ;
16701666 struct object_entry * base_entry ;
16711667 unsigned long used , used_0 ;
16721668 unsigned long avail ;
@@ -1707,9 +1703,13 @@ static void check_object(struct object_entry *entry)
17071703 unuse_pack (& w_curs );
17081704 return ;
17091705 case OBJ_REF_DELTA :
1710- if (reuse_delta && !entry -> preferred_base )
1711- base_ref = use_pack (p , & w_curs ,
1712- entry -> in_pack_offset + used , NULL );
1706+ if (reuse_delta && !entry -> preferred_base ) {
1707+ oidread (& base_ref ,
1708+ use_pack (p , & w_curs ,
1709+ entry -> in_pack_offset + used ,
1710+ NULL ));
1711+ have_base = 1 ;
1712+ }
17131713 entry -> in_pack_header_size = used + the_hash_algo -> rawsz ;
17141714 break ;
17151715 case OBJ_OFS_DELTA :
@@ -1739,13 +1739,15 @@ static void check_object(struct object_entry *entry)
17391739 revidx = find_pack_revindex (p , ofs );
17401740 if (!revidx )
17411741 goto give_up ;
1742- base_ref = nth_packed_object_sha1 (p , revidx -> nr );
1742+ if (!nth_packed_object_id (& base_ref , p , revidx -> nr ))
1743+ have_base = 1 ;
17431744 }
17441745 entry -> in_pack_header_size = used + used_0 ;
17451746 break ;
17461747 }
17471748
1748- if (can_reuse_delta (base_ref , entry , & base_entry )) {
1749+ if (have_base &&
1750+ can_reuse_delta (& base_ref , entry , & base_entry )) {
17491751 oe_set_type (entry , entry -> in_pack_type );
17501752 SET_SIZE (entry , in_pack_size ); /* delta size */
17511753 SET_DELTA_SIZE (entry , in_pack_size );
@@ -1755,7 +1757,7 @@ static void check_object(struct object_entry *entry)
17551757 entry -> delta_sibling_idx = base_entry -> delta_child_idx ;
17561758 SET_DELTA_CHILD (base_entry , entry );
17571759 } else {
1758- SET_DELTA_EXT (entry , base_ref );
1760+ SET_DELTA_EXT (entry , & base_ref );
17591761 }
17601762
17611763 unuse_pack (& w_curs );
@@ -3053,7 +3055,7 @@ static void add_objects_in_unpacked_packs(void)
30533055 in_pack .alloc );
30543056
30553057 for (i = 0 ; i < p -> num_objects ; i ++ ) {
3056- nth_packed_object_oid (& oid , p , i );
3058+ nth_packed_object_id (& oid , p , i );
30573059 o = lookup_unknown_object (& oid );
30583060 if (!(o -> flags & OBJECT_ADDED ))
30593061 mark_in_pack_object (o , p , & in_pack );
@@ -3157,7 +3159,7 @@ static void loosen_unused_packed_objects(void)
31573159 die (_ ("cannot open pack index" ));
31583160
31593161 for (i = 0 ; i < p -> num_objects ; i ++ ) {
3160- nth_packed_object_oid (& oid , p , i );
3162+ nth_packed_object_id (& oid , p , i );
31613163 if (!packlist_find (& to_pack , & oid ) &&
31623164 !has_sha1_pack_kept_or_nonlocal (& oid ) &&
31633165 !loosened_object_can_be_discarded (& oid , p -> mtime ))
0 commit comments