* [PATCH 1/2] prune: handle --progress/no-progress
2011-11-08 5:31 ` Jeff King
@ 2011-11-08 5:34 ` Jeff King
2011-11-09 4:23 ` [PATCH] " Nguyễn Thái Ngọc Duy
2011-11-08 5:37 ` [PATCH 2/2] reachable: per-object progress Jeff King
` (2 subsequent siblings)
3 siblings, 1 reply; 7+ messages in thread
From: Jeff King @ 2011-11-08 5:34 UTC (permalink / raw)
To: Nguyễn Thái Ngọc Duy; +Cc: git, Junio C Hamano
And have "git gc" pass no-progress when quiet.
Signed-off-by: Jeff King <peff@peff.net>
---
On top of the prune progress patch you sent earlier.
I did these as separate patches so you could see each change, but I'd
also be fine if they are just squashed into your patch.
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 0498094..271376d 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -32,7 +32,7 @@
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 6b39d3f..58d7cb8 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -15,6 +15,7 @@
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 <time>"),
OPT_END()
@@ -154,7 +156,12 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
else
die("unrecognized argument: %s", name);
}
- progress = start_progress_delay("Checking connectivity", 0, 0, 2);
+
+ if (show_progress == -1)
+ show_progress = isatty(2);
+ if (show_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());
--
1.7.7.2.7.g9f96f.dirty
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH] prune: handle --progress/no-progress
2011-11-08 5:34 ` [PATCH 1/2] prune: handle --progress/no-progress Jeff King
@ 2011-11-09 4:23 ` Nguyễn Thái Ngọc Duy
0 siblings, 0 replies; 7+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2011-11-09 4:23 UTC (permalink / raw)
To: Jeff King
Cc: git, Junio C Hamano, Jeff King,
Nguyễn Thái Ngọc Duy
From: Jeff King <peff@peff.net>
And have "git gc" pass no-progress when quiet.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
Added documentation.
Documentation/git-prune.txt | 9 ++++++++-
builtin/gc.c | 4 +++-
builtin/prune.c | 11 +++++++++--
3 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/Documentation/git-prune.txt b/Documentation/git-prune.txt
index 80d01b0..6da99e2 100644
--- a/Documentation/git-prune.txt
+++ b/Documentation/git-prune.txt
@@ -9,7 +9,7 @@ git-prune - Prune all unreachable objects from the object database
SYNOPSIS
--------
[verse]
-'git prune' [-n] [-v] [--expire <expire>] [--] [<head>...]
+'git prune' [-n] [-v] [--expire <expire>] [--[no-]progress] [--] [<head>...]
DESCRIPTION
-----------
@@ -46,6 +46,13 @@ OPTIONS
--expire <time>::
Only expire loose objects older than <time>.
+--progress::
+--no-progress::
+ Progress status is reported on the standard error stream
+ by default when it is attached to a terminal, unless --no-progress
+ is specified. This flag forces progress status even if the
+ standard error stream is not directed to a terminal.
+
<head>...::
In addition to objects
reachable from any of our references, keep objects
diff --git a/builtin/gc.c b/builtin/gc.c
index 0498094..271376d 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 6b39d3f..58d7cb8 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 <time>"),
OPT_END()
@@ -154,7 +156,12 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
else
die("unrecognized argument: %s", name);
}
- progress = start_progress_delay("Checking connectivity", 0, 0, 2);
+
+ if (show_progress == -1)
+ show_progress = isatty(2);
+ if (show_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());
--
1.7.3.1.256.g2539c.dirty
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/2] reachable: per-object progress
2011-11-08 5:31 ` Jeff King
2011-11-08 5:34 ` [PATCH 1/2] prune: handle --progress/no-progress Jeff King
@ 2011-11-08 5:37 ` Jeff King
2011-11-08 5:40 ` [PATCH] prune: show progress while marking reachable objects Junio C Hamano
2011-11-09 4:26 ` Nguyen Thai Ngoc Duy
3 siblings, 0 replies; 7+ messages in thread
From: Jeff King @ 2011-11-08 5:37 UTC (permalink / raw)
To: Nguyễn Thái Ngọc Duy; +Cc: git, Junio C Hamano
The current progress code really just counts commits.
This patch makes it count all objects, giving us a "total"
count close to what a repack would show. This is nice when
using "git gc", which will usually have just repacked the
whole repo.
Signed-off-by: Jeff King <peff@peff.net>
---
This makes the change a lot more invasive, but it is at least confined
to reachable.c. I think matching repack's numbers is worth it. I did a
few basic measurements, and with "& 1023" trick and reasonable
optimizations, it doesn't seem to make prune any slower.
Again, I'd be OK if this is squashed into your original patch.
reachable.c | 51 +++++++++++++++++++++++++++++++++++++--------------
1 files changed, 37 insertions(+), 14 deletions(-)
diff --git a/reachable.c b/reachable.c
index 293d37d..bf79706 100644
--- a/reachable.c
+++ b/reachable.c
@@ -9,10 +9,23 @@
#include "cache-tree.h"
#include "progress.h"
+struct connectivity_progress {
+ struct progress *progress;
+ unsigned long count;
+};
+
+static void update_progress(struct connectivity_progress *cp)
+{
+ cp->count++;
+ if ((cp->count & 1023) == 0)
+ display_progress(cp->progress, cp->count);
+}
+
static void process_blob(struct blob *blob,
struct object_array *p,
struct name_path *path,
- const char *name)
+ const char *name,
+ struct connectivity_progress *cp)
{
struct object *obj = &blob->object;
@@ -21,6 +34,7 @@ static void process_blob(struct blob *blob,
if (obj->flags & SEEN)
return;
obj->flags |= SEEN;
+ update_progress(cp);
/* Nothing to do, really .. The blob lookup was the important part */
}
@@ -35,7 +49,8 @@ static void process_gitlink(const unsigned char *sha1,
static void process_tree(struct tree *tree,
struct object_array *p,
struct name_path *path,
- const char *name)
+ const char *name,
+ struct connectivity_progress *cp)
{
struct object *obj = &tree->object;
struct tree_desc desc;
@@ -47,6 +62,7 @@ static void process_tree(struct tree *tree,
if (obj->flags & SEEN)
return;
obj->flags |= SEEN;
+ update_progress(cp);
if (parse_tree(tree) < 0)
die("bad tree object %s", sha1_to_hex(obj->sha1));
add_object(obj, p, path, name);
@@ -58,23 +74,25 @@ static void process_tree(struct tree *tree,
while (tree_entry(&desc, &entry)) {
if (S_ISDIR(entry.mode))
- process_tree(lookup_tree(entry.sha1), p, &me, entry.path);
+ process_tree(lookup_tree(entry.sha1), p, &me, entry.path, cp);
else if (S_ISGITLINK(entry.mode))
process_gitlink(entry.sha1, p, &me, entry.path);
else
- process_blob(lookup_blob(entry.sha1), p, &me, entry.path);
+ process_blob(lookup_blob(entry.sha1), p, &me, entry.path, cp);
}
free(tree->buffer);
tree->buffer = NULL;
}
-static void process_tag(struct tag *tag, struct object_array *p, const char *name)
+static void process_tag(struct tag *tag, struct object_array *p,
+ const char *name, struct connectivity_progress *cp)
{
struct object *obj = &tag->object;
if (obj->flags & SEEN)
return;
obj->flags |= SEEN;
+ update_progress(cp);
if (parse_tag(tag) < 0)
die("bad tag object %s", sha1_to_hex(obj->sha1));
@@ -82,17 +100,17 @@ 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, struct progress *progress)
+static void walk_commit_list(struct rev_info *revs,
+ struct connectivity_progress *cp)
{
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) {
- process_tree(commit->tree, &objects, NULL, "");
- display_progress(progress, ++count);
+ process_tree(commit->tree, &objects, NULL, "", cp);
+ update_progress(cp);
}
/* Then walk all the pending objects, recursively processing them too */
@@ -100,17 +118,16 @@ static void walk_commit_list(struct rev_info *revs, struct progress *progress)
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);
+ process_tag((struct tag *) obj, &objects, name, cp);
continue;
}
if (obj->type == OBJ_TREE) {
- process_tree((struct tree *)obj, &objects, NULL, name);
+ process_tree((struct tree *)obj, &objects, NULL, name, cp);
continue;
}
if (obj->type == OBJ_BLOB) {
- process_blob((struct blob *)obj, &objects, NULL, name);
+ process_blob((struct blob *)obj, &objects, NULL, name, cp);
continue;
}
die("unknown pending object %s (%s)", sha1_to_hex(obj->sha1), name);
@@ -199,6 +216,8 @@ static void add_cache_refs(struct rev_info *revs)
void mark_reachable_objects(struct rev_info *revs, int mark_reflog,
struct progress *progress)
{
+ struct connectivity_progress cp;
+
/*
* Set up revision parsing, and mark us as being interested
* in all object types, not just commits.
@@ -217,11 +236,15 @@ void mark_reachable_objects(struct rev_info *revs, int mark_reflog,
if (mark_reflog)
for_each_reflog(add_one_reflog, revs);
+ cp.progress = progress;
+ cp.count = 0;
+
/*
* Set up the revision walk - this will move all commits
* from the pending list to the commit walking list.
*/
if (prepare_revision_walk(revs))
die("revision walk setup failed");
- walk_commit_list(revs, progress);
+ walk_commit_list(revs, &cp);
+ display_progress(cp.progress, cp.count);
}
--
1.7.7.2.7.g9f96f.dirty
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] prune: show progress while marking reachable objects
2011-11-08 5:31 ` Jeff King
2011-11-08 5:34 ` [PATCH 1/2] prune: handle --progress/no-progress Jeff King
2011-11-08 5:37 ` [PATCH 2/2] reachable: per-object progress Jeff King
@ 2011-11-08 5:40 ` Junio C Hamano
2011-11-09 4:26 ` Nguyen Thai Ngoc Duy
3 siblings, 0 replies; 7+ messages in thread
From: Junio C Hamano @ 2011-11-08 5:40 UTC (permalink / raw)
To: Jeff King; +Cc: Nguyễn Thái Ngọc Duy, git
Both patches look sensible from a quick glance.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] prune: show progress while marking reachable objects
2011-11-08 5:31 ` Jeff King
` (2 preceding siblings ...)
2011-11-08 5:40 ` [PATCH] prune: show progress while marking reachable objects Junio C Hamano
@ 2011-11-09 4:26 ` Nguyen Thai Ngoc Duy
3 siblings, 0 replies; 7+ messages in thread
From: Nguyen Thai Ngoc Duy @ 2011-11-09 4:26 UTC (permalink / raw)
To: Jeff King; +Cc: git, Junio C Hamano
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:
>
> > 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 <pclouds@gmail.com>
---
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< --
^ permalink raw reply related [flat|nested] 7+ messages in thread