3737#include "shallow.h"
3838#include "promisor-remote.h"
3939
40+ /*
41+ * Objects we are going to pack are collected in the `to_pack` structure.
42+ * It contains an array (dynamically expanded) of the object data, and a map
43+ * that can resolve SHA1s to their position in the array.
44+ */
45+ static struct packing_data to_pack ;
46+
47+ static inline struct object_entry * oe_delta (
48+ const struct packing_data * pack ,
49+ const struct object_entry * e )
50+ {
51+ if (!e -> delta_idx )
52+ return NULL ;
53+ if (e -> ext_base )
54+ return & pack -> ext_bases [e -> delta_idx - 1 ];
55+ else
56+ return & pack -> objects [e -> delta_idx - 1 ];
57+ }
58+
59+ static inline unsigned long oe_delta_size (struct packing_data * pack ,
60+ const struct object_entry * e )
61+ {
62+ if (e -> delta_size_valid )
63+ return e -> delta_size_ ;
64+
65+ /*
66+ * pack->delta_size[] can't be NULL because oe_set_delta_size()
67+ * must have been called when a new delta is saved with
68+ * oe_set_delta().
69+ * If oe_delta() returns NULL (i.e. default state, which means
70+ * delta_size_valid is also false), then the caller must never
71+ * call oe_delta_size().
72+ */
73+ return pack -> delta_size [e - pack -> objects ];
74+ }
75+
76+ unsigned long oe_get_size_slow (struct packing_data * pack ,
77+ const struct object_entry * e );
78+
79+ static inline unsigned long oe_size (struct packing_data * pack ,
80+ const struct object_entry * e )
81+ {
82+ if (e -> size_valid )
83+ return e -> size_ ;
84+
85+ return oe_get_size_slow (pack , e );
86+ }
87+
88+ static inline void oe_set_delta (struct packing_data * pack ,
89+ struct object_entry * e ,
90+ struct object_entry * delta )
91+ {
92+ if (delta )
93+ e -> delta_idx = (delta - pack -> objects ) + 1 ;
94+ else
95+ e -> delta_idx = 0 ;
96+ }
97+
98+ static inline struct object_entry * oe_delta_sibling (
99+ const struct packing_data * pack ,
100+ const struct object_entry * e )
101+ {
102+ if (e -> delta_sibling_idx )
103+ return & pack -> objects [e -> delta_sibling_idx - 1 ];
104+ return NULL ;
105+ }
106+
107+ static inline struct object_entry * oe_delta_child (
108+ const struct packing_data * pack ,
109+ const struct object_entry * e )
110+ {
111+ if (e -> delta_child_idx )
112+ return & pack -> objects [e -> delta_child_idx - 1 ];
113+ return NULL ;
114+ }
115+
116+ static inline void oe_set_delta_child (struct packing_data * pack ,
117+ struct object_entry * e ,
118+ struct object_entry * delta )
119+ {
120+ if (delta )
121+ e -> delta_child_idx = (delta - pack -> objects ) + 1 ;
122+ else
123+ e -> delta_child_idx = 0 ;
124+ }
125+
126+ static inline void oe_set_delta_sibling (struct packing_data * pack ,
127+ struct object_entry * e ,
128+ struct object_entry * delta )
129+ {
130+ if (delta )
131+ e -> delta_sibling_idx = (delta - pack -> objects ) + 1 ;
132+ else
133+ e -> delta_sibling_idx = 0 ;
134+ }
135+
136+ static inline void oe_set_size (struct packing_data * pack ,
137+ struct object_entry * e ,
138+ unsigned long size )
139+ {
140+ if (size < pack -> oe_size_limit ) {
141+ e -> size_ = size ;
142+ e -> size_valid = 1 ;
143+ } else {
144+ e -> size_valid = 0 ;
145+ if (oe_get_size_slow (pack , e ) != size )
146+ BUG ("'size' is supposed to be the object size!" );
147+ }
148+ }
149+
150+ static inline void oe_set_delta_size (struct packing_data * pack ,
151+ struct object_entry * e ,
152+ unsigned long size )
153+ {
154+ if (size < pack -> oe_delta_size_limit ) {
155+ e -> delta_size_ = size ;
156+ e -> delta_size_valid = 1 ;
157+ } else {
158+ packing_data_lock (pack );
159+ if (!pack -> delta_size )
160+ ALLOC_ARRAY (pack -> delta_size , pack -> nr_alloc );
161+ packing_data_unlock (pack );
162+
163+ pack -> delta_size [e - pack -> objects ] = size ;
164+ e -> delta_size_valid = 0 ;
165+ }
166+ }
167+
40168#define IN_PACK (obj ) oe_in_pack(&to_pack, obj)
41169#define SIZE (obj ) oe_size(&to_pack, obj)
42170#define SET_SIZE (obj ,size ) oe_set_size(&to_pack, obj, size)
@@ -56,13 +184,6 @@ static const char *pack_usage[] = {
56184 NULL
57185};
58186
59- /*
60- * Objects we are going to pack are collected in the `to_pack` structure.
61- * It contains an array (dynamically expanded) of the object data, and a map
62- * that can resolve SHA1s to their position in the array.
63- */
64- static struct packing_data to_pack ;
65-
66187static struct pack_idx_entry * * written_list ;
67188static uint32_t nr_result , nr_written , nr_seen ;
68189static struct bitmap_index * bitmap_git ;
@@ -301,6 +422,17 @@ static void copy_pack_data(struct hashfile *f,
301422 }
302423}
303424
425+ static inline int oe_size_greater_than (struct packing_data * pack ,
426+ const struct object_entry * lhs ,
427+ unsigned long rhs )
428+ {
429+ if (lhs -> size_valid )
430+ return lhs -> size_ > rhs ;
431+ if (rhs < pack -> oe_size_limit ) /* rhs < 2^x <= lhs ? */
432+ return 1 ;
433+ return oe_get_size_slow (pack , lhs ) > rhs ;
434+ }
435+
304436/* Return 0 if we will bust the pack-size limit */
305437static unsigned long write_no_reuse_object (struct hashfile * f , struct object_entry * entry ,
306438 unsigned long limit , int usable_delta )
@@ -642,6 +774,14 @@ static int mark_tagged(const char *path, const struct object_id *oid, int flag,
642774 return 0 ;
643775}
644776
777+ static inline unsigned char oe_layer (struct packing_data * pack ,
778+ struct object_entry * e )
779+ {
780+ if (!pack -> layer )
781+ return 0 ;
782+ return pack -> layer [e - pack -> objects ];
783+ }
784+
645785static inline void add_to_write_order (struct object_entry * * wo ,
646786 unsigned int * endp ,
647787 struct object_entry * e )
@@ -2231,6 +2371,26 @@ static pthread_mutex_t progress_mutex;
22312371 * progress_mutex for protection.
22322372 */
22332373
2374+ static inline int oe_size_less_than (struct packing_data * pack ,
2375+ const struct object_entry * lhs ,
2376+ unsigned long rhs )
2377+ {
2378+ if (lhs -> size_valid )
2379+ return lhs -> size_ < rhs ;
2380+ if (rhs < pack -> oe_size_limit ) /* rhs < 2^x <= lhs ? */
2381+ return 0 ;
2382+ return oe_get_size_slow (pack , lhs ) < rhs ;
2383+ }
2384+
2385+ static inline void oe_set_tree_depth (struct packing_data * pack ,
2386+ struct object_entry * e ,
2387+ unsigned int tree_depth )
2388+ {
2389+ if (!pack -> tree_depth )
2390+ CALLOC_ARRAY (pack -> tree_depth , pack -> nr_alloc );
2391+ pack -> tree_depth [e - pack -> objects ] = tree_depth ;
2392+ }
2393+
22342394/*
22352395 * Return the size of the object without doing any delta
22362396 * reconstruction (so non-deltas are true object sizes, but deltas
0 commit comments