@matheusbsbs / matheus-bagliano / commits / 6ed7f25e95
Fork 0

pack-objects: improve returned information from write_one()

This function returns 0 when the current object couldn't be written due to the pack size limit, otherwise the current offset in the pack. There is a problem with this approach however, since current object could be a delta and its delta base might just have been written in the same write_one() call, but those successfully written objects are not accounted in the offset variable tracked by the caller. Currently this is not an issue but a subsequent patch will need this. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nicolas Pitre committed Aug 29, 2008 at 16:07 UTC 6ed7f25e95069a900b10f838b15639af3fac05d3
1 file changed +12 -17
builtin-pack-objects.c
+12 -17
@@ -410,25 +410,22 @@ static unsigned long write_object(struct sha1file *f,
410 return hdrlen + datalen;
411 }
412
413 -static off_t write_one(struct sha1file *f,
413 +static int write_one(struct sha1file *f,
414 struct object_entry *e,
415 - off_t offset)
415 + off_t *offset)
416 {
417 unsigned long size;
418
419 /* offset is non zero if object is written already. */
420 if (e->idx.offset || e->preferred_base)
421 - return offset;
421 + return 1;
422
423 /* if we are deltified, write out base object first. */
424 - if (e->delta) {
425 - offset = write_one(f, e->delta, offset);
426 - if (!offset)
427 - return 0;
428 - }
424 + if (e->delta && !write_one(f, e->delta, offset))
425 + return 0;
426
430 - e->idx.offset = offset;
431 - size = write_object(f, e, offset);
427 + e->idx.offset = *offset;
428 + size = write_object(f, e, *offset);
429 if (!size) {
430 e->idx.offset = 0;
431 return 0;
@@ -436,9 +433,10 @@ static off_t write_one(struct sha1file *f,
433 written_list[nr_written++] = &e->idx;
434
435 /* make sure off_t is sufficiently large not to wrap */
439 - if (offset > offset + size)
436 + if (*offset > *offset + size)
437 die("pack too large for current definition of off_t");
441 - return offset + size;
438 + *offset += size;
439 + return 1;
440 }
441
442 /* forward declaration for write_pack_file */
@@ -448,7 +446,7 @@ static void write_pack_file(void)
446 {
447 uint32_t i = 0, j;
448 struct sha1file *f;
451 - off_t offset, offset_one, last_obj_offset = 0;
449 + off_t offset;
450 struct pack_header hdr;
451 uint32_t nr_remaining = nr_result;
452 time_t last_mtime = 0;
@@ -480,11 +478,8 @@ static void write_pack_file(void)
478 offset = sizeof(hdr);
479 nr_written = 0;
480 for (; i < nr_objects; i++) {
483 - last_obj_offset = offset;
484 - offset_one = write_one(f, objects + i, offset);
485 - if (!offset_one)
481 + if (!write_one(f, objects + i, &offset))
482 break;
487 - offset = offset_one;
483 display_progress(progress_state, written);
484 }
485