Skip to content

Commit a587b5a

Browse files
ttaylorrgitster
authored andcommitted
pack-write.c: extract 'write_rev_file_order'
Existing callers provide the reverse index code with an array of 'struct pack_idx_entry *'s, which is then sorted by pack order (comparing the offsets of each object within the pack). Prepare for the multi-pack index to write a .rev file by providing a way to write the reverse index without an array of pack_idx_entry (which the MIDX code does not have). Instead, callers can invoke 'write_rev_index_positions()', which takes an array of uint32_t's. The ith entry in this array specifies the ith object's (in index order) position within the pack (in pack order). Expose this new function for use in a later patch, and rewrite the existing write_rev_file() in terms of this new function. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f894081 commit a587b5a

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

pack-write.c

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -201,21 +201,12 @@ static void write_rev_header(struct hashfile *f)
201201
}
202202

203203
static void write_rev_index_positions(struct hashfile *f,
204-
struct pack_idx_entry **objects,
204+
uint32_t *pack_order,
205205
uint32_t nr_objects)
206206
{
207-
uint32_t *pack_order;
208207
uint32_t i;
209-
210-
ALLOC_ARRAY(pack_order, nr_objects);
211-
for (i = 0; i < nr_objects; i++)
212-
pack_order[i] = i;
213-
QSORT_S(pack_order, nr_objects, pack_order_cmp, objects);
214-
215208
for (i = 0; i < nr_objects; i++)
216209
hashwrite_be32(f, pack_order[i]);
217-
218-
free(pack_order);
219210
}
220211

221212
static void write_rev_trailer(struct hashfile *f, const unsigned char *hash)
@@ -228,6 +219,29 @@ const char *write_rev_file(const char *rev_name,
228219
uint32_t nr_objects,
229220
const unsigned char *hash,
230221
unsigned flags)
222+
{
223+
uint32_t *pack_order;
224+
uint32_t i;
225+
const char *ret;
226+
227+
ALLOC_ARRAY(pack_order, nr_objects);
228+
for (i = 0; i < nr_objects; i++)
229+
pack_order[i] = i;
230+
QSORT_S(pack_order, nr_objects, pack_order_cmp, objects);
231+
232+
ret = write_rev_file_order(rev_name, pack_order, nr_objects, hash,
233+
flags);
234+
235+
free(pack_order);
236+
237+
return ret;
238+
}
239+
240+
const char *write_rev_file_order(const char *rev_name,
241+
uint32_t *pack_order,
242+
uint32_t nr_objects,
243+
const unsigned char *hash,
244+
unsigned flags)
231245
{
232246
struct hashfile *f;
233247
int fd;
@@ -262,7 +276,7 @@ const char *write_rev_file(const char *rev_name,
262276

263277
write_rev_header(f);
264278

265-
write_rev_index_positions(f, objects, nr_objects);
279+
write_rev_index_positions(f, pack_order, nr_objects);
266280
write_rev_trailer(f, hash);
267281

268282
if (rev_name && adjust_shared_perm(rev_name) < 0)

pack.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ struct ref;
9494
void write_promisor_file(const char *promisor_name, struct ref **sought, int nr_sought);
9595

9696
const char *write_rev_file(const char *rev_name, struct pack_idx_entry **objects, uint32_t nr_objects, const unsigned char *hash, unsigned flags);
97+
const char *write_rev_file_order(const char *rev_name, uint32_t *pack_order, uint32_t nr_objects, const unsigned char *hash, unsigned flags);
9798

9899
/*
99100
* The "hdr" output buffer should be at least this big, which will handle sizes

0 commit comments

Comments
 (0)