Skip to content

Commit 5ee2ad6

Browse files
Linus TorvaldsJunio C Hamano
authored andcommitted
Make "git clone" less of a deathly quiet experience
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 packing 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 seems to 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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 29e55cd commit 5ee2ad6

File tree

4 files changed

+37
-5
lines changed

4 files changed

+37
-5
lines changed

cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,6 @@ extern int copy_fd(int ifd, int ofd);
348348

349349
/* Finish off pack transfer receiving end */
350350
extern int receive_unpack_pack(int fd[2], const char *me, int quiet);
351-
extern int receive_keep_pack(int fd[2], const char *me);
351+
extern int receive_keep_pack(int fd[2], const char *me, int quiet);
352352

353353
#endif /* CACHE_H */

clone-pack.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ static const char clone_pack_usage[] =
66
"git-clone-pack [--exec=<git-upload-pack>] [<host>:]<directory> [<heads>]*";
77
static const char *exec = "git-upload-pack";
88

9+
static int quiet = 0;
10+
911
static void clone_handshake(int fd[2], struct ref *ref)
1012
{
1113
unsigned char sha1[20];
@@ -123,7 +125,9 @@ static int clone_pack(int fd[2], int nr_match, char **match)
123125
}
124126
clone_handshake(fd, refs);
125127

126-
status = receive_keep_pack(fd, "git-clone-pack");
128+
if (!quiet)
129+
fprintf(stderr, "Generating pack ...\r");
130+
status = receive_keep_pack(fd, "git-clone-pack", quiet);
127131

128132
if (!status) {
129133
if (nr_match == 0)
@@ -154,8 +158,10 @@ int main(int argc, char **argv)
154158
char *arg = argv[i];
155159

156160
if (*arg == '-') {
157-
if (!strcmp("-q", arg))
161+
if (!strcmp("-q", arg)) {
162+
quiet = 1;
158163
continue;
164+
}
159165
if (!strncmp("--exec=", arg, 7)) {
160166
exec = arg + 7;
161167
continue;

fetch-clone.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "cache.h"
22
#include "exec_cmd.h"
33
#include <sys/wait.h>
4+
#include <sys/time.h>
45

56
static int finish_pack(const char *pack_tmp_name, const char *me)
67
{
@@ -129,10 +130,12 @@ int receive_unpack_pack(int fd[2], const char *me, int quiet)
129130
die("git-unpack-objects died of unnatural causes %d", status);
130131
}
131132

132-
int receive_keep_pack(int fd[2], const char *me)
133+
int receive_keep_pack(int fd[2], const char *me, int quiet)
133134
{
134135
char tmpfile[PATH_MAX];
135136
int ofd, ifd;
137+
unsigned long total;
138+
static struct timeval prev_tv;
136139

137140
ifd = fd[0];
138141
snprintf(tmpfile, sizeof(tmpfile),
@@ -141,6 +144,8 @@ int receive_keep_pack(int fd[2], const char *me)
141144
if (ofd < 0)
142145
return error("unable to create temporary file %s", tmpfile);
143146

147+
gettimeofday(&prev_tv, NULL);
148+
total = 0;
144149
while (1) {
145150
char buf[8192];
146151
ssize_t sz, wsz, pos;
@@ -165,6 +170,27 @@ int receive_keep_pack(int fd[2], const char *me)
165170
}
166171
pos += wsz;
167172
}
173+
total += sz;
174+
if (!quiet) {
175+
static unsigned long last;
176+
struct timeval tv;
177+
unsigned long diff = total - last;
178+
/* not really "msecs", but a power-of-two millisec (1/1024th of a sec) */
179+
unsigned long msecs;
180+
181+
gettimeofday(&tv, NULL);
182+
msecs = tv.tv_sec - prev_tv.tv_sec;
183+
msecs <<= 10;
184+
msecs += (int)(tv.tv_usec - prev_tv.tv_usec) >> 10;
185+
if (msecs > 500) {
186+
prev_tv = tv;
187+
last = total;
188+
fprintf(stderr, "%4lu.%03luMB (%lu kB/s) \r",
189+
total >> 20,
190+
1000*((total >> 10) & 1023)>>10,
191+
diff / msecs );
192+
}
193+
}
168194
}
169195
close(ofd);
170196
return finish_pack(tmpfile, me);

fetch-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ static int fetch_pack(int fd[2], int nr_match, char **match)
378378
fprintf(stderr, "warning: no common commits\n");
379379

380380
if (keep_pack)
381-
status = receive_keep_pack(fd, "git-fetch-pack");
381+
status = receive_keep_pack(fd, "git-fetch-pack", quiet);
382382
else
383383
status = receive_unpack_pack(fd, "git-fetch-pack", quiet);
384384

0 commit comments

Comments
 (0)