@matheusbsbs / matheus-bagliano / commits / 5e8dc750ee
Fork 0

also adds progress when actually writing a pack

If that pack is big, it takes significant time to write and might benefit from some more eye candies as well. This is however disabled when the pack is written to stdout since in that case the output is usually piped into unpack_objects which already does its own progress reporting. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Nicolas Pitre committed Feb 22, 2006 at 17:41 UTC 5e8dc750ee56d8c295ecd7478a6bd5d148cb7177
1 file changed +16 -3
pack-objects.c
+16 -3
@@ -53,6 +53,7 @@ static int nr_objects = 0, nr_alloc = 0;
53 static const char *base_name;
54 static unsigned char pack_file_sha1[20];
55 static int progress = 1;
56 +static volatile int progress_update = 0;
57
58 /*
59 * The object names in objects array are hashed with this hashtable,
@@ -333,8 +334,14 @@ static void write_pack_file(void)
334 hdr.hdr_entries = htonl(nr_objects);
335 sha1write(f, &hdr, sizeof(hdr));
336 offset = sizeof(hdr);
336 - for (i = 0; i < nr_objects; i++)
337 + for (i = 0; i < nr_objects; i++) {
338 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;
343 + }
344 + }
345
346 sha1close(f, pack_file_sha1, 1);
347 }
@@ -662,7 +669,6 @@ static int try_delta(struct unpacked *cur, struct unpacked *old, unsigned max_de
669 return 0;
670 }
671
665 -static volatile int progress_update = 0;
672 static void progress_interval(int signum)
673 {
674 signal(SIGALRM, progress_interval);
@@ -735,7 +741,6 @@ static void prepare_pack(int window, int depth)
741 sorted_by_type = create_sorted_list(type_size_sort);
742 if (window && depth)
743 find_deltas(sorted_by_type, window+1, depth);
738 - write_pack_file();
744 }
745
746 static int reuse_cached_pack(unsigned char *sha1, int pack_to_stdout)
@@ -905,6 +910,14 @@ int main(int argc, char **argv)
910 ;
911 else {
912 prepare_pack(window, depth);
913 + if (progress && pack_to_stdout) {
914 + /* the other end usually displays progress itself */
915 + struct itimerval v = {{0,},};
916 + setitimer(ITIMER_REAL, &v, NULL);
917 + signal(SIGALRM, SIG_IGN );
918 + progress_update = 0;
919 + }
920 + write_pack_file();
921 if (!pack_to_stdout) {
922 write_index_file();
923 puts(sha1_to_hex(object_list_sha1));