From dc347195ccfbc87b6e445f5c31a5500e1df6c9b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sat, 5 Nov 2011 19:00:08 +0700 Subject: [PATCH 1/3] prune: show progress while marking reachable objects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit prune already shows progress meter while pruning. The marking part may take a few seconds or more, depending on repository size. Show progress meter during this time too. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- builtin/prune.c | 6 +++++- builtin/reflog.c | 2 +- reachable.c | 14 ++++++++++---- reachable.h | 3 ++- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/builtin/prune.c b/builtin/prune.c index e65690ba37..6b39d3fdeb 100644 --- a/builtin/prune.c +++ b/builtin/prune.c @@ -5,6 +5,7 @@ #include "builtin.h" #include "reachable.h" #include "parse-options.h" +#include "progress.h" #include "dir.h" static const char * const prune_usage[] = { @@ -124,6 +125,7 @@ static void remove_temporary_files(const char *path) int cmd_prune(int argc, const char **argv, const char *prefix) { struct rev_info revs; + struct progress *progress; const struct option options[] = { OPT__DRY_RUN(&show_only, "do not remove, show only"), OPT__VERBOSE(&verbose, "report pruned objects"), @@ -152,7 +154,9 @@ int cmd_prune(int argc, const char **argv, const char *prefix) else die("unrecognized argument: %s", name); } - mark_reachable_objects(&revs, 1); + progress = start_progress_delay("Checking connectivity", 0, 0, 2); + mark_reachable_objects(&revs, 1, progress); + stop_progress(&progress); prune_object_dir(get_object_directory()); prune_packed_objects(show_only); diff --git a/builtin/reflog.c b/builtin/reflog.c index 3a9c80f3db..062d7dad1b 100644 --- a/builtin/reflog.c +++ b/builtin/reflog.c @@ -647,7 +647,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) init_revisions(&cb.revs, prefix); if (cb.verbose) printf("Marking reachable objects..."); - mark_reachable_objects(&cb.revs, 0); + mark_reachable_objects(&cb.revs, 0, NULL); if (cb.verbose) putchar('\n'); } diff --git a/reachable.c b/reachable.c index 3fc6b1d320..293d37d224 100644 --- a/reachable.c +++ b/reachable.c @@ -7,6 +7,7 @@ #include "revision.h" #include "reachable.h" #include "cache-tree.h" +#include "progress.h" static void process_blob(struct blob *blob, struct object_array *p, @@ -81,21 +82,25 @@ static void process_tag(struct tag *tag, struct object_array *p, const char *nam add_object(tag->tagged, p, NULL, name); } -static void walk_commit_list(struct rev_info *revs) +static void walk_commit_list(struct rev_info *revs, struct progress *progress) { int i; struct commit *commit; struct object_array objects = OBJECT_ARRAY_INIT; + uint32_t count = 0; /* Walk all commits, process their trees */ - while ((commit = get_revision(revs)) != NULL) + while ((commit = get_revision(revs)) != NULL) { process_tree(commit->tree, &objects, NULL, ""); + display_progress(progress, ++count); + } /* Then walk all the pending objects, recursively processing them too */ for (i = 0; i < revs->pending.nr; i++) { struct object_array_entry *pending = revs->pending.objects + i; struct object *obj = pending->item; const char *name = pending->name; + display_progress(progress, ++count); if (obj->type == OBJ_TAG) { process_tag((struct tag *) obj, &objects, name); continue; @@ -191,7 +196,8 @@ static void add_cache_refs(struct rev_info *revs) add_cache_tree(active_cache_tree, revs); } -void mark_reachable_objects(struct rev_info *revs, int mark_reflog) +void mark_reachable_objects(struct rev_info *revs, int mark_reflog, + struct progress *progress) { /* * Set up revision parsing, and mark us as being interested @@ -217,5 +223,5 @@ void mark_reachable_objects(struct rev_info *revs, int mark_reflog) */ if (prepare_revision_walk(revs)) die("revision walk setup failed"); - walk_commit_list(revs); + walk_commit_list(revs, progress); } diff --git a/reachable.h b/reachable.h index 40751810b6..5d082adfec 100644 --- a/reachable.h +++ b/reachable.h @@ -1,6 +1,7 @@ #ifndef REACHEABLE_H #define REACHEABLE_H -extern void mark_reachable_objects(struct rev_info *revs, int mark_reflog); +struct progress; +extern void mark_reachable_objects(struct rev_info *revs, int mark_reflog, struct progress *); #endif From bf0a59b3872211eaa6d4cebb23ae110522458625 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 8 Nov 2011 00:34:08 -0500 Subject: [PATCH 2/3] prune: handle --progress/no-progress And have "git gc" pass no-progress when quiet. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/gc.c | 4 +++- builtin/prune.c | 11 +++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/builtin/gc.c b/builtin/gc.c index 0498094711..271376d82b 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -32,7 +32,7 @@ static const char *prune_expire = "2.weeks.ago"; static const char *argv_pack_refs[] = {"pack-refs", "--all", "--prune", NULL}; static const char *argv_reflog[] = {"reflog", "expire", "--all", NULL}; static const char *argv_repack[MAX_ADD] = {"repack", "-d", "-l", NULL}; -static const char *argv_prune[] = {"prune", "--expire", NULL, NULL}; +static const char *argv_prune[] = {"prune", "--expire", NULL, NULL, NULL}; static const char *argv_rerere[] = {"rerere", "gc", NULL}; static int gc_config(const char *var, const char *value, void *cb) @@ -243,6 +243,8 @@ int cmd_gc(int argc, const char **argv, const char *prefix) if (prune_expire) { argv_prune[2] = prune_expire; + if (quiet) + argv_prune[3] = "--no-progress"; if (run_command_v_opt(argv_prune, RUN_GIT_CMD)) return error(FAILED_RUN, argv_prune[0]); } diff --git a/builtin/prune.c b/builtin/prune.c index 6b39d3fdeb..58d7cb8324 100644 --- a/builtin/prune.c +++ b/builtin/prune.c @@ -15,6 +15,7 @@ static const char * const prune_usage[] = { static int show_only; static int verbose; static unsigned long expire; +static int show_progress = -1; static int prune_tmp_object(const char *path, const char *filename) { @@ -125,10 +126,11 @@ static void remove_temporary_files(const char *path) int cmd_prune(int argc, const char **argv, const char *prefix) { struct rev_info revs; - struct progress *progress; + struct progress *progress = NULL; const struct option options[] = { OPT__DRY_RUN(&show_only, "do not remove, show only"), OPT__VERBOSE(&verbose, "report pruned objects"), + OPT_BOOL(0, "progress", &show_progress, "show progress"), OPT_DATE(0, "expire", &expire, "expire objects older than