Thread (6 messages) flat view 6 messages, 2 authors, 2016-06-15

Re: [PATCH] prune: show progress while marking reachable objects

From: Nguyen Thai Ngoc Duy <hidden>
Date: 2016-06-15 22:52:27
Subsystem: the rest · Maintainer: Linus Torvalds

On Tue, Nov 08, 2011 at 12:31:49AM -0500, Jeff King wrote:
On Sat, Nov 05, 2011 at 07:00:08PM +0700, Nguyen Thai Ngoc Duy wrote:
quoted
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.
Thanks, this is a nice start. It's missing a few things IMHO:

  1. It actually counts commits, not all objects. I'm tempted to say
     this doesn't matter, as any eye candy is helpful. Except that the
     most common use of prune is as part of "git gc", in which case
     pack-objects will have just done the "counting objects" phase and
     come up with some number. If we count all objects, then our end
     number is the same (modulo any .keep packs, but at least it's
     probably in the same order of magnitude). That gives the user a
     better sense of completion time.

  2. Prune should learn --progress/--no-progress, isatty(2), etc. And
     git-gc should pass --no-progress when it's told to be quiet.
  3. Show progress meter while pruning packed objects. It does not
     seem to take long enough time to show the meter. Anyway the code
     is there we should enable it.

-- 8< --
Subject: [PATCH] prune: show progress meter while pruning packed objects

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
 builtin.h              |    4 ++++
 builtin/prune-packed.c |   13 +++++--------
 builtin/prune.c        |   13 +++++++++----
 3 files changed, 18 insertions(+), 12 deletions(-)
diff --git a/builtin.h b/builtin.h
index 0e9da90..0a5b511 100644
--- a/builtin.h
+++ b/builtin.h
@@ -13,6 +13,10 @@ extern const char git_version_string[];
 extern const char git_usage_string[];
 extern const char git_more_info_string[];
 
+#define PRUNE_DRY_RUN  01
+#define PRUNE_PROGRESS 02
+#define PRUNE_VERBOSE  04
+
 extern void prune_packed_objects(int);
 extern int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
 			 int merge_title, int shortlog_len);
diff --git a/builtin/prune-packed.c b/builtin/prune-packed.c
index f9463de..d9f6d1d 100644
--- a/builtin/prune-packed.c
+++ b/builtin/prune-packed.c
@@ -8,9 +8,6 @@ static const char * const prune_packed_usage[] = {
 	NULL
 };
 
-#define DRY_RUN 01
-#define VERBOSE 02
-
 static struct progress *progress;
 
 static void prune_dir(int i, DIR *dir, char *pathname, int len, int opts)
@@ -29,7 +26,7 @@ static void prune_dir(int i, DIR *dir, char *pathname, int len, int opts)
 		if (!has_sha1_pack(sha1))
 			continue;
 		memcpy(pathname + len, de->d_name, 38);
-		if (opts & DRY_RUN)
+		if (opts & PRUNE_DRY_RUN)
 			printf("rm -f %s\n", pathname);
 		else
 			unlink_or_warn(pathname);
@@ -46,7 +43,7 @@ void prune_packed_objects(int opts)
 	const char *dir = get_object_directory();
 	int len = strlen(dir);
 
-	if (opts == VERBOSE)
+	if (opts & PRUNE_PROGRESS)
 		progress = start_progress_delay("Removing duplicate objects",
 			256, 95, 2);
 
@@ -71,10 +68,10 @@ void prune_packed_objects(int opts)
 
 int cmd_prune_packed(int argc, const char **argv, const char *prefix)
 {
-	int opts = isatty(2) ? VERBOSE : 0;
+	int opts = isatty(2) ? PRUNE_PROGRESS : 0;
 	const struct option prune_packed_options[] = {
-		OPT_BIT('n', "dry-run", &opts, "dry run", DRY_RUN),
-		OPT_NEGBIT('q', "quiet", &opts, "be quiet", VERBOSE),
+		OPT_BIT('n', "dry-run", &opts, "dry run", PRUNE_DRY_RUN),
+		OPT_NEGBIT('q', "quiet", &opts, "be quiet", PRUNE_PROGRESS),
 		OPT_END()
 	};
 
diff --git a/builtin/prune.c b/builtin/prune.c
index 58d7cb8..4cdbac0 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -127,9 +127,10 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
 {
 	struct rev_info revs;
 	struct progress *progress = NULL;
+	int prune_opts = 0;
 	const struct option options[] = {
-		OPT__DRY_RUN(&show_only, "do not remove, show only"),
-		OPT__VERBOSE(&verbose, "report pruned objects"),
+		OPT_BIT('n', "dry-run", &prune_opts, "do not remove, show only", PRUNE_DRY_RUN),
+		OPT_BIT('v', "verbose", &prune_opts, "report pruned objects", PRUNE_VERBOSE),
 		OPT_BOOL(0, "progress", &show_progress, "show progress"),
 		OPT_DATE(0, "expire", &expire,
 			 "expire objects older than <time>"),
@@ -143,6 +144,8 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
 	init_revisions(&revs, prefix);
 
 	argc = parse_options(argc, argv, prefix, options, prune_usage, 0);
+	show_only = prune_opts & PRUNE_DRY_RUN;
+	verbose = prune_opts & PRUNE_VERBOSE;
 	while (argc--) {
 		unsigned char sha1[20];
 		const char *name = *argv++;
@@ -159,14 +162,16 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
 
 	if (show_progress == -1)
 		show_progress = isatty(2);
-	if (show_progress)
+	if (show_progress) {
+		prune_opts |= PRUNE_PROGRESS;
 		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);
+	prune_packed_objects(prune_opts);
 	remove_temporary_files(get_object_directory());
 	s = xstrdup(mkpath("%s/pack", get_object_directory()));
 	remove_temporary_files(s);
-- 
1.7.3.1.256.g2539c.dirty

-- 8< --
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help