Re: [PATCH] checkout: be quiet if not on isatty()

6 messages, 3 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH] checkout: be quiet if not on isatty()

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:51:56

Steffen Daode Nurpmeso [off-list ref] writes:
Signed-off-by: Steffen Daode Nurpmeso <redacted>
Justification is necessary why this is a good change.

Perhaps you meant something like this:

	In general, the progress output should not be given unless the
        output is sent to a tty (i.e. an interactive session).

But this patch may be squelching the output a bit too much. The opts.quiet
field is used not just to set verbose_update in the unpack_trees_options
used in reset_tree() and merge_working_tree(), but also used to report the
local changes at the end of merge_working_tree(), report tracking
information, and report where the detached HEAD is at, among other things.

Independently, it might make sense to squelch advice messages in a
non-interactive session, but I think that should probably be done by
flipping advice_* variables in advice.c, I think.
quoted hunk
---
 builtin/checkout.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 4eaedff..6fb6d48 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -958,6 +958,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
 	gitmodules_config();
 	git_config(git_checkout_config, &opts);
 
+	opts.quiet = !isatty(2);
 	opts.track = BRANCH_TRACK_UNSPECIFIED;
 
 	argc = parse_options(argc, argv, prefix, options, checkout_usage,

Re: [PATCH] checkout: be quiet if not on isatty()

From: martin f krafft <hidden>
Date: 2016-06-15 22:51:56

also sprach Junio C Hamano [off-list ref] [2011.08.28.0822 +0200]:
	In general, the progress output should not be given unless the
        output is sent to a tty (i.e. an interactive session).
Just as a note — around Unix, it's generally "output should not be
given unless there was an unexpected condition, or --verbose was
passed. If a tool did successfully what it was asked to do, it
should just be quiet about it."

-- 
martin | http://madduck.net/ | http://two.sentenc.es/
 
/.ing an issue is like asking an infinite number of monkeys for advice
                                                   -- in #debian-devel
 
spamtraps: madduck.bogus@madduck.net

[PATCH] checkout: add --verbose, and restrict progress reporting (was: Re: [PATCH] checkout: be quiet if not on isatty())

From: Steffen Daode Nurpmeso <hidden>
Date: 2016-06-15 22:51:56

This commit adds support for the -v/--verbose pair of options,
and thus offers the possibility to be more specific in deciding
which purely informational feedback message is displayed or not.

Without any of --verbose and --quiet involved, the progress
reporting is now restricted to interactive sessions, i.e. only
shown if the output is send to a terminal.

Analyzed-by: Junio C Hamano [off-list ref]
Inspired-by: martin f krafft [off-list ref]
Signed-off-by: Steffen Daode Nurpmeso <redacted>
---

Well i was stepping down from my hill, actually singing my
sunday's song (was it Elvis..), but i didn't dare to implement the
behaviour Martin suggested.  But isn't he right?
This thing here was also tested a bit.

 Documentation/git-checkout.txt |   13 +++++++++----
 builtin/checkout.c             |   12 +++++++++---
 2 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt
index c0a96e6..77ad4f3 100644
--- a/Documentation/git-checkout.txt
+++ b/Documentation/git-checkout.txt
@@ -8,9 +8,9 @@ git-checkout - Checkout a branch or paths to the working tree
 SYNOPSIS
 --------
 [verse]
-'git checkout' [-q] [-f] [-m] [<branch>]
-'git checkout' [-q] [-f] [-m] [--detach] [<commit>]
-'git checkout' [-q] [-f] [-m] [[-b|-B|--orphan] <new_branch>] [<start_point>]
+'git checkout' [-v] [-q] [-f] [-m] [<branch>]
+'git checkout' [-v] [-q] [-f] [-m] [--detach] [<commit>]
+'git checkout' [-v] [-q] [-f] [-m] [[-b|-B|--orphan] <new_branch>] [<start_point>]
 'git checkout' [-f|--ours|--theirs|-m|--conflict=<style>] [<tree-ish>] [--] <paths>...
 'git checkout' [-p|--patch] [<tree-ish>] [--] [<paths>...]
 
@@ -66,9 +66,14 @@ file can be discarded to re-create the original conflicted merge result.
 
 OPTIONS
 -------
+-v::
+--verbose::
+	Be verbose, force progress reporting.
+
 -q::
 --quiet::
-	Quiet, suppress feedback messages.
+	Be quiet, suppress feedback messages and progress reporting.
+	Overrides "--verbose", if given.
 
 -f::
 --force::
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 4eaedff..7297843 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -27,6 +27,7 @@ static const char * const checkout_usage[] = {
 };
 
 struct checkout_opts {
+	int verbose;
 	int quiet;
 	int merge;
 	int force;
@@ -325,7 +326,7 @@ static int reset_tree(struct tree *tree, struct checkout_opts *o, int worktree)
 	opts.reset = 1;
 	opts.merge = 1;
 	opts.fn = oneway_merge;
-	opts.verbose_update = !o->quiet;
+	opts.verbose_update = o->verbose;
 	opts.src_index = &the_index;
 	opts.dst_index = &the_index;
 	parse_tree(tree);
@@ -402,7 +403,7 @@ static int merge_working_tree(struct checkout_opts *opts,
 		topts.update = 1;
 		topts.merge = 1;
 		topts.gently = opts->merge && old->commit;
-		topts.verbose_update = !opts->quiet;
+		topts.verbose_update = opts->verbose;
 		topts.fn = twoway_merge;
 		topts.dir = xcalloc(1, sizeof(*topts.dir));
 		topts.dir->flags |= DIR_SHOW_IGNORED;
@@ -927,7 +928,8 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
 	int patch_mode = 0;
 	int dwim_new_local_branch = 1;
 	struct option options[] = {
-		OPT__QUIET(&opts.quiet, "suppress progress reporting"),
+		OPT__VERBOSE(&opts.verbose, "force progress reporting"),
+		OPT__QUIET(&opts.quiet, "suppress feedback reporting"),
 		OPT_STRING('b', NULL, &opts.new_branch, "branch",
 			   "create and checkout a new branch"),
 		OPT_STRING('B', NULL, &opts.new_branch_force, "branch",
@@ -958,6 +960,10 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
 	gitmodules_config();
 	git_config(git_checkout_config, &opts);
 
+	if (opts.quiet)
+		opts.verbose = 0;
+	else if (!opts.verbose)
+		opts.verbose = isatty(2);
 	opts.track = BRANCH_TRACK_UNSPECIFIED;
 
 	argc = parse_options(argc, argv, prefix, options, checkout_usage,
-- 
1.7.7.rc0.dirty

[PATCH 0/2 RFC] Add update_progress(), divert checkout messages

From: <hidden>
Date: 2016-06-15 22:51:56

From: Steffen Daode Nurpmeso <redacted>

Whereas only syntactic sugar, i think it's a bit odd that during
a checkout which mostly removes files the git-checkout progress
displays "Checking out files" all of the time.

There are two solutions to this: either simply change that string
to "Updating working tree", which is acceptable to anybody at
anytime.  Or divert what progress reports to the actual action
which is currently performed.  This series tries to achieve the
latter.

But maybe progress should instead be extended that it could handle
a situation like the following directly.  I.e., offer an
additional start_parted_progress() series, or extend the current
one with an additional "signed parted" argument.  That
update_progress() could then instead be named
progress_change_part() or whatever.  ?

    Updating work tree: removing files (x/y [xy%]) total%
       Main-Title        Action-title  Action-cnt 

Steffen Daode Nurpmeso (2):
  progress: add update_progress()
  unpack-trees: divert check_updates() output via update_progress()

 progress.c     |   15 +++++++++++++++
 progress.h     |    2 ++
 unpack-trees.c |   30 +++++++++++++++++++++++-------
 3 files changed, 40 insertions(+), 7 deletions(-)

-- 
1.7.7.rc0.dirty

[PATCH 1/2] progress: add update_progress()

From: <hidden>
Date: 2016-06-15 22:51:56

From: Steffen Daode Nurpmeso <redacted>

Sometimes the task which is tracked via progress is splitted
into two parts, e.g. check_updates() in unpack_trees.c updates
the working tree by first removing files, followed by checking
out files.  Whereas it is possible to simply recreate a progress
reporter, it's easier to simply call in to update the state of
the yet existing one.

Inspired-by: Junio C Hamano [off-list ref]
Signed-off-by: Steffen Daode Nurpmeso <redacted>
---
 progress.c |   15 +++++++++++++++
 progress.h |    2 ++
 2 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/progress.c b/progress.c
index 3971f49..c86f83f 100644
--- a/progress.c
+++ b/progress.c
@@ -234,6 +234,21 @@ struct progress *start_progress(const char *title, unsigned total)
 	return start_progress_delay(title, total, 0, 0);
 }
 
+void update_progress(struct progress *progress, const char *title,
+			unsigned total)
+{
+	if (!progress)
+		return;
+	progress->title = title;
+	progress->total = total;
+	progress->last_value = -1;
+	progress->last_percent = -1;
+	if (progress->delay < 0)
+		progress->delay = 0;
+	clear_progress_signal();
+	set_progress_signal();
+}
+
 void stop_progress(struct progress **p_progress)
 {
 	stop_progress_msg(p_progress, "done");
diff --git a/progress.h b/progress.h
index 611e4c4..eed5b58 100644
--- a/progress.h
+++ b/progress.h
@@ -8,6 +8,8 @@ int display_progress(struct progress *progress, unsigned n);
 struct progress *start_progress(const char *title, unsigned total);
 struct progress *start_progress_delay(const char *title, unsigned total,
 				       unsigned percent_treshold, unsigned delay);
+void update_progress(struct progress *progress, const char *title,
+			unsigned total);
 void stop_progress(struct progress **progress);
 void stop_progress_msg(struct progress **progress, const char *msg);
 
-- 
1.7.7.rc0.dirty

[PATCH 2/2] unpack-trees: divert check_updates() output via update_progress()

From: <hidden>
Date: 2016-06-15 22:51:56

From: Steffen Daode Nurpmeso <redacted>

The progress shown by check_updates() yet always printed
"Checking out files", even if basically files were only
unlinked.

This commit diverts that into "Updating working tree:" plus the
actual action which currently is performed (i.e. "removing
files" or "checking out files").

Inspired-by: Junio C Hamano [off-list ref]
Signed-off-by: Steffen Daode Nurpmeso <redacted>
---
 unpack-trees.c |   30 +++++++++++++++++++++++-------
 1 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/unpack-trees.c b/unpack-trees.c
index cc616c3..95cd8a6 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -178,26 +178,34 @@ static void unlink_entry(struct cache_entry *ce)
 static struct checkout state;
 static int check_updates(struct unpack_trees_options *o)
 {
-	unsigned cnt = 0, total = 0;
+	unsigned rm_cnt, co_cnt, cnt;
 	struct progress *progress = NULL;
 	struct index_state *index = &o->result;
 	int i;
 	int errs = 0;
 
 	if (o->update && o->verbose_update) {
-		for (total = cnt = 0; cnt < index->cache_nr; cnt++) {
+		rm_cnt = co_cnt = 0;
+		for (cnt = 0; cnt < index->cache_nr; cnt++) {
 			struct cache_entry *ce = index->cache[cnt];
-			if (ce->ce_flags & (CE_UPDATE | CE_WT_REMOVE))
-				total++;
+			switch (ce->ce_flags & (CE_UPDATE | CE_WT_REMOVE)) {
+			case CE_UPDATE:
+				co_cnt++;
+				break;
+			default:
+				rm_cnt++;
+				break;
+			}
 		}
 
-		progress = start_progress_delay("Checking out files",
-						total, 50, 1);
+		progress = start_progress_delay("Updating work tree: "
+						"removing files",
+						rm_cnt, 64, 1);
 		cnt = 0;
 	}
-
 	if (o->update)
 		git_attr_set_direction(GIT_ATTR_CHECKOUT, &o->result);
+
 	for (i = 0; i < index->cache_nr; i++) {
 		struct cache_entry *ce = index->cache[i];
 
@@ -211,6 +219,13 @@ static int check_updates(struct unpack_trees_options *o)
 	remove_marked_cache_entries(&o->result);
 	remove_scheduled_dirs();
 
+	if (co_cnt > 0) {
+		update_progress(progress,
+				"Updating work tree: checking out files",
+				co_cnt);
+		cnt = 0;
+	}
+
 	for (i = 0; i < index->cache_nr; i++) {
 		struct cache_entry *ce = index->cache[i];
 
@@ -222,6 +237,7 @@ static int check_updates(struct unpack_trees_options *o)
 			}
 		}
 	}
+
 	stop_progress(&progress);
 	if (o->update)
 		git_attr_set_direction(GIT_ATTR_CHECKIN, NULL);
-- 
1.7.7.rc0.dirty
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help