Skip to content

Commit 5afd72a

Browse files
committed
Merge branch 'ab/pack-linkage-fix'
"ld" on Solaris fails to link some test helpers, which has been worked around by reshuffling the inline function definitions from a header file to a source file that is the only user of them. * ab/pack-linkage-fix: pack-objects: move static inline from a header to the sole consumer
2 parents 2f0ca41 + 7d089fb commit 5afd72a

File tree

2 files changed

+167
-166
lines changed

2 files changed

+167
-166
lines changed

builtin/pack-objects.c

Lines changed: 167 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,134 @@
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-
66187
static struct pack_idx_entry **written_list;
67188
static uint32_t nr_result, nr_written, nr_seen;
68189
static 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 */
305437
static 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+
645785
static 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

pack-objects.h

Lines changed: 0 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -268,152 +268,10 @@ static inline void oe_set_in_pack(struct packing_data *pack,
268268
pack->in_pack[e - pack->objects] = p;
269269
}
270270

271-
static inline struct object_entry *oe_delta(
272-
const struct packing_data *pack,
273-
const struct object_entry *e)
274-
{
275-
if (!e->delta_idx)
276-
return NULL;
277-
if (e->ext_base)
278-
return &pack->ext_bases[e->delta_idx - 1];
279-
else
280-
return &pack->objects[e->delta_idx - 1];
281-
}
282-
283-
static inline void oe_set_delta(struct packing_data *pack,
284-
struct object_entry *e,
285-
struct object_entry *delta)
286-
{
287-
if (delta)
288-
e->delta_idx = (delta - pack->objects) + 1;
289-
else
290-
e->delta_idx = 0;
291-
}
292-
293271
void oe_set_delta_ext(struct packing_data *pack,
294272
struct object_entry *e,
295273
const struct object_id *oid);
296274

297-
static inline struct object_entry *oe_delta_child(
298-
const struct packing_data *pack,
299-
const struct object_entry *e)
300-
{
301-
if (e->delta_child_idx)
302-
return &pack->objects[e->delta_child_idx - 1];
303-
return NULL;
304-
}
305-
306-
static inline void oe_set_delta_child(struct packing_data *pack,
307-
struct object_entry *e,
308-
struct object_entry *delta)
309-
{
310-
if (delta)
311-
e->delta_child_idx = (delta - pack->objects) + 1;
312-
else
313-
e->delta_child_idx = 0;
314-
}
315-
316-
static inline struct object_entry *oe_delta_sibling(
317-
const struct packing_data *pack,
318-
const struct object_entry *e)
319-
{
320-
if (e->delta_sibling_idx)
321-
return &pack->objects[e->delta_sibling_idx - 1];
322-
return NULL;
323-
}
324-
325-
static inline void oe_set_delta_sibling(struct packing_data *pack,
326-
struct object_entry *e,
327-
struct object_entry *delta)
328-
{
329-
if (delta)
330-
e->delta_sibling_idx = (delta - pack->objects) + 1;
331-
else
332-
e->delta_sibling_idx = 0;
333-
}
334-
335-
unsigned long oe_get_size_slow(struct packing_data *pack,
336-
const struct object_entry *e);
337-
static inline unsigned long oe_size(struct packing_data *pack,
338-
const struct object_entry *e)
339-
{
340-
if (e->size_valid)
341-
return e->size_;
342-
343-
return oe_get_size_slow(pack, e);
344-
}
345-
346-
static inline int oe_size_less_than(struct packing_data *pack,
347-
const struct object_entry *lhs,
348-
unsigned long rhs)
349-
{
350-
if (lhs->size_valid)
351-
return lhs->size_ < rhs;
352-
if (rhs < pack->oe_size_limit) /* rhs < 2^x <= lhs ? */
353-
return 0;
354-
return oe_get_size_slow(pack, lhs) < rhs;
355-
}
356-
357-
static inline int oe_size_greater_than(struct packing_data *pack,
358-
const struct object_entry *lhs,
359-
unsigned long rhs)
360-
{
361-
if (lhs->size_valid)
362-
return lhs->size_ > rhs;
363-
if (rhs < pack->oe_size_limit) /* rhs < 2^x <= lhs ? */
364-
return 1;
365-
return oe_get_size_slow(pack, lhs) > rhs;
366-
}
367-
368-
static inline void oe_set_size(struct packing_data *pack,
369-
struct object_entry *e,
370-
unsigned long size)
371-
{
372-
if (size < pack->oe_size_limit) {
373-
e->size_ = size;
374-
e->size_valid = 1;
375-
} else {
376-
e->size_valid = 0;
377-
if (oe_get_size_slow(pack, e) != size)
378-
BUG("'size' is supposed to be the object size!");
379-
}
380-
}
381-
382-
static inline unsigned long oe_delta_size(struct packing_data *pack,
383-
const struct object_entry *e)
384-
{
385-
if (e->delta_size_valid)
386-
return e->delta_size_;
387-
388-
/*
389-
* pack->delta_size[] can't be NULL because oe_set_delta_size()
390-
* must have been called when a new delta is saved with
391-
* oe_set_delta().
392-
* If oe_delta() returns NULL (i.e. default state, which means
393-
* delta_size_valid is also false), then the caller must never
394-
* call oe_delta_size().
395-
*/
396-
return pack->delta_size[e - pack->objects];
397-
}
398-
399-
static inline void oe_set_delta_size(struct packing_data *pack,
400-
struct object_entry *e,
401-
unsigned long size)
402-
{
403-
if (size < pack->oe_delta_size_limit) {
404-
e->delta_size_ = size;
405-
e->delta_size_valid = 1;
406-
} else {
407-
packing_data_lock(pack);
408-
if (!pack->delta_size)
409-
ALLOC_ARRAY(pack->delta_size, pack->nr_alloc);
410-
packing_data_unlock(pack);
411-
412-
pack->delta_size[e - pack->objects] = size;
413-
e->delta_size_valid = 0;
414-
}
415-
}
416-
417275
static inline unsigned int oe_tree_depth(struct packing_data *pack,
418276
struct object_entry *e)
419277
{
@@ -422,23 +280,6 @@ static inline unsigned int oe_tree_depth(struct packing_data *pack,
422280
return pack->tree_depth[e - pack->objects];
423281
}
424282

425-
static inline void oe_set_tree_depth(struct packing_data *pack,
426-
struct object_entry *e,
427-
unsigned int tree_depth)
428-
{
429-
if (!pack->tree_depth)
430-
CALLOC_ARRAY(pack->tree_depth, pack->nr_alloc);
431-
pack->tree_depth[e - pack->objects] = tree_depth;
432-
}
433-
434-
static inline unsigned char oe_layer(struct packing_data *pack,
435-
struct object_entry *e)
436-
{
437-
if (!pack->layer)
438-
return 0;
439-
return pack->layer[e - pack->objects];
440-
}
441-
442283
static inline void oe_set_layer(struct packing_data *pack,
443284
struct object_entry *e,
444285
unsigned char layer)

0 commit comments

Comments
 (0)