fetch-clone progress: finishing touches.
This makes fetch-pack also report the progress of packing part. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Feb 11, 2006 at 17:54 UTC
21fcd1bdea2440236aea1713ea42a66bc2da5563
2 files changed
+43
-4
clone-pack.c
+2
-2
@@ -125,9 +125,9 @@ static int clone_pack(int fd[2], int nr_match, char **match)
125
}
126
clone_handshake(fd, refs);
127
128
- if (!quiet)
129
- fprintf(stderr, "Generating pack ...\r");
128
status = receive_keep_pack(fd, "git-clone-pack", quiet);
129
+ if (!quiet)
130
+ fprintf(stderr, "\n");
131
132
if (!status) {
133
if (nr_match == 0)
pack-objects.c
+41
-2
@@ -3,6 +3,7 @@
3
#include "delta.h"
4
#include "pack.h"
5
#include "csum-file.h"
6
+#include <sys/time.h>
7
8
static const char pack_usage[] = "git-pack-objects [--non-empty] [--local] [--incremental] [--window=N] [--depth=N] {--stdout | base-name} < object-list";
9
@@ -26,6 +27,7 @@ static struct object_entry *objects = NULL;
27
static int nr_objects = 0, nr_alloc = 0;
28
static const char *base_name;
29
static unsigned char pack_file_sha1[20];
30
+static int progress = 0;
31
32
static void *delta_against(void *buf, unsigned long size, struct object_entry *entry)
33
{
@@ -362,10 +364,13 @@ static void find_deltas(struct object_entry **list, int window, int depth)
364
int i, idx;
365
unsigned int array_size = window * sizeof(struct unpacked);
366
struct unpacked *array = xmalloc(array_size);
367
+ int eye_candy;
368
369
memset(array, 0, array_size);
370
i = nr_objects;
371
idx = 0;
372
+ eye_candy = i - (nr_objects / 20);
373
+
374
while (--i >= 0) {
375
struct object_entry *entry = list[i];
376
struct unpacked *n = array + idx;
@@ -373,6 +378,10 @@ static void find_deltas(struct object_entry **list, int window, int depth)
378
char type[10];
379
int j;
380
381
+ if (progress && i <= eye_candy) {
382
+ eye_candy -= nr_objects / 20;
383
+ fputc('.', stderr);
384
+ }
385
free(n->data);
386
n->entry = entry;
387
n->data = read_sha1_file(entry->sha1, type, &size);
@@ -404,11 +413,13 @@ static void prepare_pack(int window, int depth)
413
{
414
get_object_details();
415
407
- fprintf(stderr, "Packing %d objects\n", nr_objects);
408
-
416
+ if (progress)
417
+ fprintf(stderr, "Packing %d objects", nr_objects);
418
sorted_by_type = create_sorted_list(type_size_sort);
419
if (window && depth)
420
find_deltas(sorted_by_type, window+1, depth);
421
+ if (progress)
422
+ fputc('\n', stderr);
423
write_pack_file();
424
}
425
@@ -472,6 +483,10 @@ int main(int argc, char **argv)
483
int window = 10, depth = 10, pack_to_stdout = 0;
484
struct object_entry **list;
485
int i;
486
+ struct timeval prev_tv;
487
+ int eye_candy = 0;
488
+ int eye_candy_incr = 500;
489
+
490
491
setup_git_directory();
492
@@ -519,12 +534,34 @@ int main(int argc, char **argv)
534
if (pack_to_stdout != !base_name)
535
usage(pack_usage);
536
537
+ progress = isatty(2);
538
+
539
prepare_packed_git();
540
+ if (progress) {
541
+ fprintf(stderr, "Generating pack...\n");
542
+ gettimeofday(&prev_tv, NULL);
543
+ }
544
while (fgets(line, sizeof(line), stdin) != NULL) {
545
unsigned int hash;
546
char *p;
547
unsigned char sha1[20];
548
549
+ if (progress && (eye_candy <= nr_objects)) {
550
+ fprintf(stderr, "Counting objects...%d\r", nr_objects);
551
+ if (eye_candy && (50 <= eye_candy_incr)) {
552
+ struct timeval tv;
553
+ int time_diff;
554
+ gettimeofday(&tv, NULL);
555
+ time_diff = (tv.tv_sec - prev_tv.tv_sec);
556
+ time_diff <<= 10;
557
+ time_diff += (tv.tv_usec - prev_tv.tv_usec);
558
+ if ((1 << 9) < time_diff)
559
+ eye_candy_incr += 50;
560
+ else if (50 < eye_candy_incr)
561
+ eye_candy_incr -= 50;
562
+ }
563
+ eye_candy += eye_candy_incr;
564
+ }
565
if (get_sha1_hex(line, sha1))
566
die("expected sha1, got garbage:\n %s", line);
567
hash = 0;
@@ -537,6 +574,8 @@ int main(int argc, char **argv)
574
}
575
add_object_entry(sha1, hash);
576
}
577
+ if (progress)
578
+ fprintf(stderr, "Done counting %d objects.\n", nr_objects);
579
if (non_empty && !nr_objects)
580
return 0;
581