@matheusbsbs / matheus-bagliano / commits / b2504a0d2f
Fork 0

nicer eye candies for pack-objects

This provides a stable and simpler progress reporting mechanism that updates progress as often as possible but accurately not updating more than once a second. The deltification phase is also made more interesting to watch (since repacking a big repository and only seeing a dot appear once every many seconds is rather boring and doesn't provide much food for anticipation). Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Nicolas Pitre committed Feb 22, 2006 at 16:00 UTC b2504a0d2ff5a51feb516f7732beb9549b5db454
1 file changed +25 -31
pack-objects.c
+25 -31
@@ -4,6 +4,7 @@
4 #include "pack.h"
5 #include "csum-file.h"
6 #include <sys/time.h>
7 +#include <signal.h>
8
9 static const char pack_usage[] = "git-pack-objects [-q] [--no-reuse-delta] [--non-empty] [--local] [--incremental] [--window=N] [--depth=N] {--stdout | base-name} < object-list";
10
@@ -661,17 +662,22 @@ static int try_delta(struct unpacked *cur, struct unpacked *old, unsigned max_de
662 return 0;
663 }
664
665 +static volatile int progress_update = 0;
666 +static void progress_interval(int signum)
667 +{
668 + signal(SIGALRM, progress_interval);
669 + progress_update = 1;
670 +}
671 +
672 static void find_deltas(struct object_entry **list, int window, int depth)
673 {
674 int i, idx;
675 unsigned int array_size = window * sizeof(struct unpacked);
676 struct unpacked *array = xmalloc(array_size);
669 - int eye_candy;
677
678 memset(array, 0, array_size);
679 i = nr_objects;
680 idx = 0;
674 - eye_candy = i - (nr_objects / 20);
681
682 while (--i >= 0) {
683 struct object_entry *entry = list[i];
@@ -680,9 +686,10 @@ static void find_deltas(struct object_entry **list, int window, int depth)
686 char type[10];
687 int j;
688
683 - if (progress && i <= eye_candy) {
684 - eye_candy -= nr_objects / 20;
685 - fputc('.', stderr);
689 + if (progress_update || i == 0) {
690 + fprintf(stderr, "Deltifying (%d %d%%)\r",
691 + nr_objects-i, (nr_objects-i) * 100/nr_objects);
692 + progress_update = 0;
693 }
694
695 if (entry->delta)
@@ -714,6 +721,9 @@ static void find_deltas(struct object_entry **list, int window, int depth)
721 idx = 0;
722 }
723
724 + if (progress)
725 + fputc('\n', stderr);
726 +
727 for (i = 0; i < window; ++i)
728 free(array[i].data);
729 free(array);
@@ -721,17 +731,10 @@ static void find_deltas(struct object_entry **list, int window, int depth)
731
732 static void prepare_pack(int window, int depth)
733 {
724 - if (progress)
725 - fprintf(stderr, "Packing %d objects", nr_objects);
734 get_object_details();
727 - if (progress)
728 - fputc('.', stderr);
729 -
735 sorted_by_type = create_sorted_list(type_size_sort);
736 if (window && depth)
737 find_deltas(sorted_by_type, window+1, depth);
733 - if (progress)
734 - fputc('\n', stderr);
738 write_pack_file();
739 }
740
@@ -796,10 +799,6 @@ int main(int argc, char **argv)
799 int window = 10, depth = 10, pack_to_stdout = 0;
800 struct object_entry **list;
801 int i;
799 - struct timeval prev_tv;
800 - int eye_candy = 0;
801 - int eye_candy_incr = 500;
802 -
802
803 setup_git_directory();
804
@@ -856,30 +855,25 @@ int main(int argc, char **argv)
855 usage(pack_usage);
856
857 prepare_packed_git();
858 +
859 if (progress) {
860 + struct itimerval v;
861 + v.it_interval.tv_sec = 1;
862 + v.it_interval.tv_usec = 0;
863 + v.it_value = v.it_interval;
864 + signal(SIGALRM, progress_interval);
865 + setitimer(ITIMER_REAL, &v, NULL);
866 fprintf(stderr, "Generating pack...\n");
861 - gettimeofday(&prev_tv, NULL);
867 }
868 +
869 while (fgets(line, sizeof(line), stdin) != NULL) {
870 unsigned int hash;
871 char *p;
872 unsigned char sha1[20];
873
868 - if (progress && (eye_candy <= nr_objects)) {
874 + if (progress_update) {
875 fprintf(stderr, "Counting objects...%d\r", nr_objects);
870 - if (eye_candy && (50 <= eye_candy_incr)) {
871 - struct timeval tv;
872 - int time_diff;
873 - gettimeofday(&tv, NULL);
874 - time_diff = (tv.tv_sec - prev_tv.tv_sec);
875 - time_diff <<= 10;
876 - time_diff += (tv.tv_usec - prev_tv.tv_usec);
877 - if ((1 << 9) < time_diff)
878 - eye_candy_incr += 50;
879 - else if (50 < eye_candy_incr)
880 - eye_candy_incr -= 50;
881 - }
882 - eye_candy += eye_candy_incr;
876 + progress_update = 0;
877 }
878 if (get_sha1_hex(line, sha1))
879 die("expected sha1, got garbage:\n %s", line);