Skip to contentSkip to conversation

checkout: add --progress option

PATCH Superseded Edmundo Carmona Antoranz 2 participants 3 messages Jun 15, 2016 Documentation

v6 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

PATCH v6 1/1 checkout: add --progress option

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.

---
 Documentation/git-checkout.txt |  6 ++++++
 builtin/checkout.c             | 14 ++++++++++++--
 2 files changed, 18 insertions(+), 2 deletions(-)
Documentation/git-checkout.txt +6 -0
index e269fb1..c24c8ee 100644
@@ -107,6 +107,12 @@ OPTIONS
 --quiet::
 	Quiet, suppress feedback messages.
 
+--[no-]progress::
+	Progress status is reported on the standard error stream
+	by default when it is attached to a terminal, unless --quiet
+	is specified. This flag enables progress reporting even if not
+	attached to a terminal, regardless of -q.
+
 -f::
 --force::
 	When switching branches, proceed even if the index or the
builtin/checkout.c +12 -2
index bc703c0..e346f52 100644
@@ -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,13 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
 	argc = parse_options(argc, argv, prefix, options, checkout_usage,
 			     PARSE_OPT_KEEP_DASHDASH);
 
+	if (opts.show_progress < 0) {
+		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);
Signature · 1 line
2.6.1
#1 lore raw
Quoted 10 lines · 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.

---

Documentation/git-checkout.txt OPTIONS · line 114

Quoted 8 lines
Documentation/git-checkout.txt +5 -0
@@ -107,6 +107,12 @@ OPTIONS
 --quiet::
        Quiet, suppress feedback messages.
 
+--[no-]progress::
+       Progress status is reported on the standard error stream
+       by default when it is attached to a terminal, unless --quiet
+       is specified. This flag enables progress reporting even if not
+       attached to a terminal, regardless of -q.

The mix of -q and --quiet is inconsistent and potentially confusing. I suspect that your intention was to hint that they are equivalent, however, the reader who is not familiar with -q as an alias of --quiet may now be forced to look up both options, rather than just one, only to discover that they are the same, thus potentially requiring extra effort. It probably would be better to consistently use --quiet.

Also, quoting with backticks is recommended: --quite

The rest of the patch looks good.

Quoted 62 lines
Documentation/git-checkout.txt +0 -0
 -f::
 --force::
        When switching branches, proceed even if the index or the
builtin/checkout.c +12 -3
@@ -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,13 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
        argc = parse_options(argc, argv, prefix, options, checkout_usage,
                             PARSE_OPT_KEEP_DASHDASH);
 
+       if (opts.show_progress < 0) {
+               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

#2 lore raw
Quoted 13 lines · Eric Sunshine

Documentation/git-checkout.txt OPTIONS · line 114

Quoted 5 lines

+--[no-]progress::

Documentation/git-checkout.txt +4 -0
+       Progress status is reported on the standard error stream
+       by default when it is attached to a terminal, unless --quiet
+       is specified. This flag enables progress reporting even if not
+       attached to a terminal, regardless of -q.

The mix of -q and --quiet is inconsistent and potentially confusing. I suspect that your intention was to hint that they are equivalent, however, the reader who is not familiar with -q as an alias of --quiet may now be forced to look up both options, rather than just one, only to discover that they are the same, thus potentially requiring extra effort. It probably would be better to consistently use --quiet.

Quoted 3 lines

Also, quoting with backticks is recommended: --quite

The rest of the patch looks good.

Good! Going for v7.