git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Linus Torvalds <torvalds@osdl.org>
To: Git Mailing List <git@vger.kernel.org>,
	Junio C Hamano <junkio@cox.net>, Petr Baudis <pasky@suse.cz>
Subject: Make "git clone" less of a deathly quiet experience
Date: Fri, 10 Feb 2006 20:31:09 -0800 (PST)	[thread overview]
Message-ID: <Pine.LNX.4.64.0602102018250.3691@g5.osdl.org> (raw)


I was on IRC today (which is definitely not normal, but hey, I tried it), 
and somebody was complaining about how horribly slow "git clone" was on 
the WineHQ repository.

The WineHQ git repo is actually fairly big: 120+MB packed, 220+ thousand 
objects. So creating the pack is actually a big operation, and yes, it's 
too slow. We should be better at it, and it would be good if the pack-file 
generation were much faster.

However, it turns out that the "slow" git-pack-objects was only using up 
2.3% of CPU time. The fact is, the primary reason it took a long time is 
that even packed, it had to get 120 MB of data. So in this case, it 
appears that the fact that it uses a lot of CPU is actually a good 
trade-off, because the damn thing would have been even slower if it hadn't 
been packed.

(Of course, pre-generated packs would be good regardless)

Anyway, what _really_ made for a pissed-off user was that "git clone" was 
just very very silent all the time. No updates on what the hell it was 
doing. Was it working at all? Was something broken? Is git just a piece of 
cr*p? But "git clone" would not say a peep about it.

It used to be that "git-unpack-objects" would give nice percentages, but 
now that we don't unpack the initial clone pack any more, it doesn't. And 
I'd love to do that nice percentage view in the pack objects downloader 
too, but the thing doesn't even read the pack header, much less know how 
much it's going to get, so I was lazy and didn't.

Instead, it at least prints out how much data it's gotten, and what the 
packign speed is. Which makes the user realize that it's actually doing 
something useful instead of sitting there silently (and if the recipient 
knows how large the final result is, he can at least make a guess about 
when it migt be done).

So with this patch, I get something like this on my DSL line:

	[torvalds@g5 ~]$ time git clone master.kernel.org:/pub/scm/linux/kernel/git/torvalds/linux-2.6 clone-test
	Packing 188543 objects
	  48.398MB  (154 kB/s)

where even the speed approximation seem sto be roughtly correct (even 
though my algorithm is a truly stupid one, and only really gives "speed in 
the last half second or so").

Anyway, _something_ like this is definitely needed. It could certainly be 
better (if it showed the same kind of thing that git-unpack-objects did, 
that would be much nicer, but would require parsing the object stream as 
it comes in). But this is  big step forward, I think.

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
---

Comments? Hate-mail? Improvements?

diff --git a/cache.h b/cache.h
index bdbe2d6..c255421 100644
--- a/cache.h
+++ b/cache.h
@@ -348,6 +348,6 @@ extern int copy_fd(int ifd, int ofd);
 
 /* Finish off pack transfer receiving end */
 extern int receive_unpack_pack(int fd[2], const char *me, int quiet);
-extern int receive_keep_pack(int fd[2], const char *me);
+extern int receive_keep_pack(int fd[2], const char *me, int quiet);
 
 #endif /* CACHE_H */
diff --git a/clone-pack.c b/clone-pack.c
index f634431..719e1c4 100644
--- a/clone-pack.c
+++ b/clone-pack.c
@@ -6,6 +6,8 @@ static const char clone_pack_usage[] =
 "git-clone-pack [--exec=<git-upload-pack>] [<host>:]<directory> [<heads>]*";
 static const char *exec = "git-upload-pack";
 
+static int quiet = 0;
+
 static void clone_handshake(int fd[2], struct ref *ref)
 {
 	unsigned char sha1[20];
@@ -123,7 +125,9 @@ static int clone_pack(int fd[2], int nr_
 	}
 	clone_handshake(fd, refs);
 
-	status = receive_keep_pack(fd, "git-clone-pack");
+	if (!quiet)
+		fprintf(stderr, "Generating pack ...\r");
+	status = receive_keep_pack(fd, "git-clone-pack", quiet);
 
 	if (!status) {
 		if (nr_match == 0)
@@ -154,8 +158,10 @@ int main(int argc, char **argv)
 		char *arg = argv[i];
 
 		if (*arg == '-') {
-			if (!strcmp("-q", arg))
+			if (!strcmp("-q", arg)) {
+				quiet = 1;
 				continue;
+			}
 			if (!strncmp("--exec=", arg, 7)) {
 				exec = arg + 7;
 				continue;
diff --git a/fetch-clone.c b/fetch-clone.c
index 859f400..b67d976 100644
--- a/fetch-clone.c
+++ b/fetch-clone.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "exec_cmd.h"
 #include <sys/wait.h>
+#include <sys/time.h>
 
 static int finish_pack(const char *pack_tmp_name, const char *me)
 {
@@ -129,10 +130,12 @@ int receive_unpack_pack(int fd[2], const
 	die("git-unpack-objects died of unnatural causes %d", status);
 }
 
-int receive_keep_pack(int fd[2], const char *me)
+int receive_keep_pack(int fd[2], const char *me, int quiet)
 {
 	char tmpfile[PATH_MAX];
 	int ofd, ifd;
+	unsigned long total;
+	static struct timeval prev_tv;
 
 	ifd = fd[0];
 	snprintf(tmpfile, sizeof(tmpfile),
@@ -141,6 +144,8 @@ int receive_keep_pack(int fd[2], const c
 	if (ofd < 0)
 		return error("unable to create temporary file %s", tmpfile);
 
+	gettimeofday(&prev_tv, NULL);
+	total = 0;
 	while (1) {
 		char buf[8192];
 		ssize_t sz, wsz, pos;
@@ -165,6 +170,27 @@ int receive_keep_pack(int fd[2], const c
 			}
 			pos += wsz;
 		}
+		total += sz;
+		if (!quiet) {
+			static unsigned long last;
+			struct timeval tv;
+			unsigned long diff = total - last;
+			/* not really "msecs", but a power-of-two millisec (1/1024th of a sec) */
+			unsigned long msecs;
+
+			gettimeofday(&tv, NULL);
+			msecs = tv.tv_sec - prev_tv.tv_sec;
+			msecs <<= 10;
+			msecs += (int)(tv.tv_usec - prev_tv.tv_usec) >> 10;
+			if (msecs > 500) {
+				prev_tv = tv;
+				last = total;
+				fprintf(stderr, "%4lu.%03luMB  (%lu kB/s)        \r",
+					total >> 20,
+					1000*((total >> 10) & 1023)>>10,
+					diff / msecs );
+			}
+		}
 	}
 	close(ofd);
 	return finish_pack(tmpfile, me);
diff --git a/fetch-pack.c b/fetch-pack.c
index 27f5d2a..aa6f42a 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -378,7 +378,7 @@ static int fetch_pack(int fd[2], int nr_
 		fprintf(stderr, "warning: no common commits\n");
 
 	if (keep_pack)
-		status = receive_keep_pack(fd, "git-fetch-pack");
+		status = receive_keep_pack(fd, "git-fetch-pack", quiet);
 	else
 		status = receive_unpack_pack(fd, "git-fetch-pack", quiet);
 

             reply	other threads:[~2006-02-11  4:31 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-11  4:31 Linus Torvalds [this message]
2006-02-11  4:37 ` Make "git clone" less of a deathly quiet experience Linus Torvalds
2006-02-11  5:50   ` Junio C Hamano
2006-02-11 17:39     ` Linus Torvalds
2006-02-11  5:48 ` Junio C Hamano
2006-02-11  7:35   ` Craig Schlenter
2006-02-11  8:44     ` Radoslaw Szkodzinski
2006-02-11 13:05       ` Petr Baudis
2006-02-11 13:15         ` Radoslaw Szkodzinski
2006-02-11 13:33   ` Petr Baudis
2006-02-11 13:41     ` Petr Baudis
2006-02-11 17:24     ` Alex Riesen
2006-02-11 17:45   ` Linus Torvalds
2006-02-11 19:10     ` Keith Packard
2006-02-12  3:43       ` Andreas Ericsson
2006-02-12  4:11         ` Keith Packard
2006-02-12 11:02           ` Andreas Ericsson
2006-02-12 21:04             ` Keith Packard
2006-02-16  6:56             ` Eric W. Biederman
2006-02-16  7:33               ` Junio C Hamano
2006-02-13  2:06           ` Martin Langhoff
2006-02-13  3:36             ` Junio C Hamano
2006-02-11 18:39 ` Alex Riesen
2006-02-11 19:04   ` Linus Torvalds

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.64.0602102018250.3691@g5.osdl.org \
    --to=torvalds@osdl.org \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    --cc=pasky@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).