git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] checkout: add --progress option

From
Edmundo Carmona Antoranz <eantoranz@gmail.com>
Date
Oct 31, 2015, 00:58 UTC
Message-ID
<CAOc6etYiqH8bvnCD_9hedzDW6fhknXLGesM6dX7S9DBB_r-9zA@mail.gmail.com>
In-Reply-To
<xmqq4mh8kv0e.fsf@gitster.mtv.corp.google.com>
On Fri, Oct 30, 2015 at 1:37 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 6 quoted lines
>
> Actually, using a single variable is my preference.  In this case I
> wanted to illustrate that the value parsed by parse_options() does
> not have to be the one that is used in the final location deep in
> the callchain for educational purposes, and I found it clearer to
> use two separate variables in the illustration.
>From all your feedback, I think I got a working example not using the

static variable, also reworked the wording to explain in what cases progress will be skipped.

So... on top of my patch, I think this sums it up:
 builtin/checkout.c | 33 ++++++++++++++++-----------------
1 file changed, 16 insertions(+), 17 deletions(-)
diff --git a/builtin/checkout.c b/builtin/checkout.c
index e28c36b..a2e5cd3 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -27,8 +27,6 @@ static const char * const checkout_usage[] = {
       NULL,
};

-static int option_progress = -1;
-
struct checkout_opts {
       int patch_mode;
       int quiet;
@@ -39,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;
@@ -406,6 +405,17 @@ static void describe_detached_head(const char
*msg, struct commit *commit)
       strbuf_release(&sb);
}

+/*
+ * Any of these conditions will make progress output be skipped:
+ * - selected --quiet
+ * - selected --no-progress
+ * - (didn't select --progress nor --no-progress) and not working on a terminal
+ */
+static int verbose_update(const struct checkout_opts *o)
+{
+       return !o->quiet && o->show_progress && (o->show_progress >= 0
|| isatty(2));
+}
+
static int reset_tree(struct tree *tree, const struct checkout_opts *o,
                     int worktree, int *writeout_error)
{
@@ -419,19 +429,7 @@ static int reset_tree(struct tree *tree, const
struct checkout_opts *o,
       opts.reset = 1;
       opts.merge = 1;
       opts.fn = oneway_merge;
-       /**
-        * Rules to display progress:
-        * -q is selected
-        *      no verbiage
-        * -q is _not_ selected and --no-progress _is_ selected,
-        *      progress will be skipped
-        * -q is _not_ selected and --progress _is_ selected,
-        *      progress will be printed to stderr
-        * -q is _not_ selected and --progress is 'undefined'
-        *      progress will be printed to stderr _if_ working on a terminal
-        */
-       opts.verbose_update = !o->quiet && (option_progress > 0 ||
-                                          (option_progress < 0 && isatty(2)));
+       opts.verbose_update = verbose_update(o);
       opts.src_index = &the_index;
       opts.dst_index = &the_index;
       parse_tree(tree);
@@ -515,7 +513,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 = verbose_update(opts);
               topts.fn = twoway_merge;
               if (opts->overwrite_ignore) {
                       topts.dir = xcalloc(1, sizeof(*topts.dir));
@@ -1170,7 +1168,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", &option_progress, N_("force
progress reporting")),
+               OPT_BOOL(0, "progress", &opts.show_progress, N_("force
progress reporting")),
               OPT_END(),
       };

@@ -1178,6 +1176,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);
Previous: Junio C HamanoNext: Edmundo Carmona Antoranz
Message 8 of 16 in “checkout: add --progress option”
  1. checkout: add --progress optionEdmundo Carmona Antoranz, Oct 30, 2015
  2. Junio C HamanoOct 30, 2015
  3. Eric SunshineOct 30, 2015
  4. Junio C HamanoOct 30, 2015
  5. Eric SunshineOct 30, 2015
  6. Jeff KingOct 30, 2015
  7. Junio C HamanoOct 30, 2015
  8. Edmundo Carmona AntoranzOct 31, 2015
  9. Edmundo Carmona AntoranzOct 31, 2015
  10. Edmundo Carmona AntoranzOct 31, 2015
  11. Junio C HamanoOct 31, 2015
  12. Edmundo Carmona AntoranzOct 31, 2015
  13. Edmundo Carmona AntoranzOct 31, 2015
  14. Jeff KingOct 31, 2015
  15. Eric SunshineNov 1, 2015
  16. Edmundo Carmona AntoranzNov 1, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.