Skip to content

Commit 183bdb2

Browse files
author
Junio C Hamano
committed
pack-objects eye-candy: finishing touches.
This updates the progress output to match "every one second or every percent whichever comes early" used by unpack-objects, as discussed on the list. Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 5e8dc75 commit 183bdb2

File tree

1 file changed

+33
-10
lines changed

1 file changed

+33
-10
lines changed

pack-objects.c

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -324,24 +324,38 @@ static void write_pack_file(void)
324324
struct sha1file *f;
325325
unsigned long offset;
326326
struct pack_header hdr;
327+
unsigned last_percent = 999;
328+
int do_progress = 0;
327329

328330
if (!base_name)
329331
f = sha1fd(1, "<stdout>");
330-
else
331-
f = sha1create("%s-%s.%s", base_name, sha1_to_hex(object_list_sha1), "pack");
332+
else {
333+
f = sha1create("%s-%s.%s", base_name,
334+
sha1_to_hex(object_list_sha1), "pack");
335+
do_progress = progress;
336+
}
337+
if (do_progress)
338+
fprintf(stderr, "Writing %d objects.\n", nr_objects);
339+
332340
hdr.hdr_signature = htonl(PACK_SIGNATURE);
333341
hdr.hdr_version = htonl(PACK_VERSION);
334342
hdr.hdr_entries = htonl(nr_objects);
335343
sha1write(f, &hdr, sizeof(hdr));
336344
offset = sizeof(hdr);
337345
for (i = 0; i < nr_objects; i++) {
338346
offset = write_one(f, objects + i, offset);
339-
if (progress_update) {
340-
fprintf(stderr, "Writing (%d %d%%)\r",
341-
i+1, (i+1) * 100/nr_objects);
342-
progress_update = 0;
347+
if (do_progress) {
348+
unsigned percent = written * 100 / nr_objects;
349+
if (progress_update || percent != last_percent) {
350+
fprintf(stderr, "%4u%% (%u/%u) done\r",
351+
percent, written, nr_objects);
352+
progress_update = 0;
353+
last_percent = percent;
354+
}
343355
}
344356
}
357+
if (do_progress)
358+
fputc('\n', stderr);
345359

346360
sha1close(f, pack_file_sha1, 1);
347361
}
@@ -680,10 +694,14 @@ static void find_deltas(struct object_entry **list, int window, int depth)
680694
int i, idx;
681695
unsigned int array_size = window * sizeof(struct unpacked);
682696
struct unpacked *array = xmalloc(array_size);
697+
unsigned processed = 0;
698+
unsigned last_percent = 999;
683699

684700
memset(array, 0, array_size);
685701
i = nr_objects;
686702
idx = 0;
703+
if (progress)
704+
fprintf(stderr, "Deltifying %d objects.\n", nr_objects);
687705

688706
while (--i >= 0) {
689707
struct object_entry *entry = list[i];
@@ -692,10 +710,15 @@ static void find_deltas(struct object_entry **list, int window, int depth)
692710
char type[10];
693711
int j;
694712

695-
if (progress_update || i == 0) {
696-
fprintf(stderr, "Deltifying (%d %d%%)\r",
697-
nr_objects-i, (nr_objects-i) * 100/nr_objects);
698-
progress_update = 0;
713+
processed++;
714+
if (progress) {
715+
unsigned percent = processed * 100 / nr_objects;
716+
if (percent != last_percent || progress_update) {
717+
fprintf(stderr, "%4u%% (%u/%u) done\r",
718+
percent, processed, nr_objects);
719+
progress_update = 0;
720+
last_percent = percent;
721+
}
699722
}
700723

701724
if (entry->delta)

0 commit comments

Comments
 (0)