Git development
 help / color / mirror / Atom feed
* [PATCH v5] checkout: add --progress option
@ 2015-11-01 18:03 Edmundo Carmona Antoranz
  2015-11-01 19:13 ` Eric Sunshine
  0 siblings, 1 reply; 3+ messages in thread
From: Edmundo Carmona Antoranz @ 2015-11-01 18:03 UTC (permalink / raw)
  To: git; +Cc: peff, Edmundo Carmona Antoranz

Under normal circumstances, and like other git commands,
git checkout will write progress info to stderr if
attached to a terminal. This option allows progress
to be forced even if not using a terminal. Also,
progress can be skipped if using option --no-progress.

Signed-off-by: Edmundo Carmona Antoranz <eantoranz@gmail.com>
---
 Documentation/git-checkout.txt |  6 ++++++
 builtin/checkout.c             | 25 +++++++++++++++++++++++--
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt
index e269fb1..93ba35a 100644
--- a/Documentation/git-checkout.txt
+++ b/Documentation/git-checkout.txt
@@ -107,6 +107,12 @@ OPTIONS
 --quiet::
 	Quiet, suppress feedback messages.
 
+--progress::
+	Progress status is reported on the standard error stream
+	by default when it is attached to a terminal, unless -q
+	is specified. This flag forces progress status even if the
+	standard error stream is not directed to a terminal.
+
 -f::
 --force::
 	When switching branches, proceed even if the index or the
diff --git a/builtin/checkout.c b/builtin/checkout.c
index bc703c0..65b8b90 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -37,6 +37,7 @@ struct checkout_opts {
 	int overwrite_ignore;
 	int ignore_skipworktree;
 	int ignore_other_worktrees;
+	int show_progress;
 
 	const char *new_branch;
 	const char *new_branch_force;
@@ -417,7 +418,7 @@ static int reset_tree(struct tree *tree, const struct checkout_opts *o,
 	opts.reset = 1;
 	opts.merge = 1;
 	opts.fn = oneway_merge;
-	opts.verbose_update = !o->quiet && isatty(2);
+	opts.verbose_update = o->show_progress;
 	opts.src_index = &the_index;
 	opts.dst_index = &the_index;
 	parse_tree(tree);
@@ -501,7 +502,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
 		topts.update = 1;
 		topts.merge = 1;
 		topts.gently = opts->merge && old->commit;
-		topts.verbose_update = !opts->quiet && isatty(2);
+		topts.verbose_update = opts->show_progress;
 		topts.fn = twoway_merge;
 		if (opts->overwrite_ignore) {
 			topts.dir = xcalloc(1, sizeof(*topts.dir));
@@ -1156,6 +1157,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
 				N_("second guess 'git checkout <no-such-branch>'")),
 		OPT_BOOL(0, "ignore-other-worktrees", &opts.ignore_other_worktrees,
 			 N_("do not check if another worktree is holding the given ref")),
+		OPT_BOOL(0, "progress", &opts.show_progress, N_("force progress reporting")),
 		OPT_END(),
 	};
 
@@ -1163,6 +1165,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
 	memset(&new, 0, sizeof(new));
 	opts.overwrite_ignore = 1;
 	opts.prefix = prefix;
+	opts.show_progress = -1;
 
 	gitmodules_config();
 	git_config(git_checkout_config, &opts);
@@ -1172,6 +1175,24 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
 	argc = parse_options(argc, argv, prefix, options, checkout_usage,
 			     PARSE_OPT_KEEP_DASHDASH);
 
+	/*
+	 * Final processing of show_progress
+	 * - User selected --progress: show progress
+	 * - user selected --no-progress: skip progress
+	 * - User didn't specify:
+	 *     (check rules in order till finding the first matching one)
+	 *     - user selected --quiet: skip progress
+	 *     - stderr is connected to a terminal: show progress
+	 *     - fallback: skip progress
+	 */
+	if (opts.show_progress < 0) {
+		/* user didn't specify --[no-]progress */
+		if (opts.quiet)
+			opts.show_progress = 0;
+		else
+			opts.show_progress = isatty(2);
+	}
+
 	if (conflict_style) {
 		opts.merge = 1; /* implied */
 		git_xmerge_config("merge.conflictstyle", conflict_style, NULL);
-- 
2.6.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v5] checkout: add --progress option
  2015-11-01 18:03 [PATCH v5] checkout: add --progress option Edmundo Carmona Antoranz
@ 2015-11-01 19:13 ` Eric Sunshine
  2015-11-01 19:17   ` Edmundo Carmona Antoranz
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Sunshine @ 2015-11-01 19:13 UTC (permalink / raw)
  To: Edmundo Carmona Antoranz; +Cc: Git List, Jeff King

On Sun, Nov 1, 2015 at 1:03 PM, Edmundo Carmona Antoranz
<eantoranz@gmail.com> wrote:
> Under normal circumstances, and like other git commands,
> git checkout will write progress info to stderr if
> attached to a terminal. This option allows progress
> to be forced even if not using a terminal. Also,
> progress can be skipped if using option --no-progress.
>
> Signed-off-by: Edmundo Carmona Antoranz <eantoranz@gmail.com>
> ---
> +       /*
> +        * Final processing of show_progress
> +        * - User selected --progress: show progress
> +        * - user selected --no-progress: skip progress
> +        * - User didn't specify:
> +        *     (check rules in order till finding the first matching one)
> +        *     - user selected --quiet: skip progress
> +        *     - stderr is connected to a terminal: show progress
> +        *     - fallback: skip progress
> +        */
> +       if (opts.show_progress < 0) {
> +               /* user didn't specify --[no-]progress */
> +               if (opts.quiet)
> +                       opts.show_progress = 0;
> +               else
> +                       opts.show_progress = isatty(2);
> +       }

Style-wise this looks better.

I'll assume that you simply overlooked the remainder of my v4 review
comments, so I'll merely provide a reference to them[1] rather than
repeating myself. If that assumption is incorrect, please do have the
courtesy to state that you disagree with review comments and to
explain your position, otherwise reviewers will feel that their
efforts are wasted.

Thanks.

[1]: http://article.gmane.org/gmane.comp.version-control.git/280641

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v5] checkout: add --progress option
  2015-11-01 19:13 ` Eric Sunshine
@ 2015-11-01 19:17   ` Edmundo Carmona Antoranz
  0 siblings, 0 replies; 3+ messages in thread
From: Edmundo Carmona Antoranz @ 2015-11-01 19:17 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: Git List, Jeff King

Oh, man... I'm sorry... I didn't notice them. Let me go over them to
see what we can do.

On Sun, Nov 1, 2015 at 1:13 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:
> I'll assume that you simply overlooked the remainder of my v4 review
> comments, so I'll merely provide a reference to them[1] rather than
> repeating myself. If that assumption is incorrect, please do have the
> courtesy to state that you disagree with review comments and to
> explain your position, otherwise reviewers will feel that their
> efforts are wasted.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-11-01 19:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-01 18:03 [PATCH v5] checkout: add --progress option Edmundo Carmona Antoranz
2015-11-01 19:13 ` Eric Sunshine
2015-11-01 19:17   ` Edmundo Carmona Antoranz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox