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>
Junio C Hamano committed
Feb 22, 2006 at 16:02 UTC
183bdb2cccff792f11fd9e825df67af446aff171
1 file changed
+33
-10
pack-objects.c
+33
-10
@@ -324,11 +324,19 @@ static void write_pack_file(void)
324
struct sha1file *f;
325
unsigned long offset;
326
struct pack_header hdr;
327
+ unsigned last_percent = 999;
328
+ int do_progress = 0;
329
330
if (!base_name)
331
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
+
340
hdr.hdr_signature = htonl(PACK_SIGNATURE);
341
hdr.hdr_version = htonl(PACK_VERSION);
342
hdr.hdr_entries = htonl(nr_objects);
@@ -336,12 +344,18 @@ static void write_pack_file(void)
344
offset = sizeof(hdr);
345
for (i = 0; i < nr_objects; i++) {
346
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
+ }
355
}
356
}
357
+ if (do_progress)
358
+ fputc('\n', stderr);
359
360
sha1close(f, pack_file_sha1, 1);
361
}
@@ -680,10 +694,14 @@ static void find_deltas(struct object_entry **list, int window, int depth)
694
int i, idx;
695
unsigned int array_size = window * sizeof(struct unpacked);
696
struct unpacked *array = xmalloc(array_size);
697
+ unsigned processed = 0;
698
+ unsigned last_percent = 999;
699
700
memset(array, 0, array_size);
701
i = nr_objects;
702
idx = 0;
703
+ if (progress)
704
+ fprintf(stderr, "Deltifying %d objects.\n", nr_objects);
705
706
while (--i >= 0) {
707
struct object_entry *entry = list[i];
@@ -692,10 +710,15 @@ static void find_deltas(struct object_entry **list, int window, int depth)
710
char type[10];
711
int j;
712
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
+ }
722
}
723
724
if (entry->delta)