checkout - eye candy.
This implements "eye candy" similar to the pack-object/unpack-object to entertain users while a large tree is being checked out after a clone or a pull. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Feb 22, 2006 at 19:02 UTC
744633cbf23d3ed505f96ffc212b30c96b79fb90
3 files changed
+63
-3
git-clone.sh
+1
-1
@@ -253,7 +253,7 @@ Pull: $head_points_at:$origin" &&
253
254
case "$no_checkout" in
255
'')
256
- git checkout
256
+ git-read-tree -m -u -v HEAD HEAD
257
esac
258
fi
259
git-merge.sh
+2
-2
@@ -130,7 +130,7 @@ case "$#,$common,$no_commit" in
130
echo "Updating from $head to $1."
131
git-update-index --refresh 2>/dev/null
132
new_head=$(git-rev-parse --verify "$1^0") &&
133
- git-read-tree -u -m $head "$new_head" &&
133
+ git-read-tree -u -v -m $head "$new_head" &&
134
finish "$new_head" "Fast forward"
135
dropsave
136
exit 0
@@ -146,7 +146,7 @@ case "$#,$common,$no_commit" in
146
147
echo "Trying really trivial in-index merge..."
148
git-update-index --refresh 2>/dev/null
149
- if git-read-tree --trivial -m -u $common $head "$1" &&
149
+ if git-read-tree --trivial -m -u -v $common $head "$1" &&
150
result_tree=$(git-write-tree)
151
then
152
echo "Wonderful."
read-tree.c
+60
@@ -9,6 +9,8 @@
9
10
#include "object.h"
11
#include "tree.h"
12
+#include <sys/time.h>
13
+#include <signal.h>
14
15
static int merge = 0;
16
static int update = 0;
@@ -16,6 +18,8 @@ static int index_only = 0;
18
static int nontrivial_merge = 0;
19
static int trivial_merges_only = 0;
20
static int aggressive = 0;
21
+static int verbose_update = 0;
22
+static volatile int progress_update = 0;
23
24
static int head_idx = -1;
25
static int merge_size = 0;
@@ -267,6 +271,12 @@ static void unlink_entry(char *name)
271
}
272
}
273
274
+static void progress_interval(int signum)
275
+{
276
+ signal(SIGALRM, progress_interval);
277
+ progress_update = 1;
278
+}
279
+
280
static void check_updates(struct cache_entry **src, int nr)
281
{
282
static struct checkout state = {
@@ -276,8 +286,49 @@ static void check_updates(struct cache_entry **src, int nr)
286
.refresh_cache = 1,
287
};
288
unsigned short mask = htons(CE_UPDATE);
289
+ unsigned last_percent = 200, cnt = 0, total = 0;
290
+
291
+ if (update && verbose_update) {
292
+ struct itimerval v;
293
+
294
+ for (total = cnt = 0; cnt < nr; cnt++) {
295
+ struct cache_entry *ce = src[cnt];
296
+ if (!ce->ce_mode || ce->ce_flags & mask)
297
+ total++;
298
+ }
299
+
300
+ /* Don't bother doing this for very small updates */
301
+ if (total < 250)
302
+ total = 0;
303
+
304
+ if (total) {
305
+ v.it_interval.tv_sec = 1;
306
+ v.it_interval.tv_usec = 0;
307
+ v.it_value = v.it_interval;
308
+ signal(SIGALRM, progress_interval);
309
+ setitimer(ITIMER_REAL, &v, NULL);
310
+ fprintf(stderr, "Checking files out...\n");
311
+ progress_update = 1;
312
+ }
313
+ cnt = 0;
314
+ }
315
+
316
while (nr--) {
317
struct cache_entry *ce = *src++;
318
+
319
+ if (total) {
320
+ if (!ce->ce_mode || ce->ce_flags & mask) {
321
+ unsigned percent;
322
+ cnt++;
323
+ percent = (cnt * 100) / total;
324
+ if (percent != last_percent ||
325
+ progress_update) {
326
+ fprintf(stderr, "%4u%% (%u/%u) done\r",
327
+ percent, cnt, total);
328
+ last_percent = percent;
329
+ }
330
+ }
331
+ }
332
if (!ce->ce_mode) {
333
if (update)
334
unlink_entry(ce->name);
@@ -289,6 +340,10 @@ static void check_updates(struct cache_entry **src, int nr)
340
checkout_entry(ce, &state);
341
}
342
}
343
+ if (total) {
344
+ fputc('\n', stderr);
345
+ signal(SIGALRM, SIG_IGN);
346
+ }
347
}
348
349
static int unpack_trees(merge_fn_t fn)
@@ -680,6 +735,11 @@ int main(int argc, char **argv)
735
continue;
736
}
737
738
+ if (!strcmp(arg, "-v")) {
739
+ verbose_update = 1;
740
+ continue;
741
+ }
742
+
743
/* "-i" means "index only", meaning that a merge will
744
* not even look at the working tree.
745
*/