{"thread":{"id":"40689","subject":"[PATCH v2] checkout: refactor of --progress option","startedAt":"2015-10-31T18:47:16Z","lastAt":"2015-10-31T18:47:16Z","messageCount":1,"participants":["Edmundo Carmona Antoranz"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"272636","messageId":"1446317236-18051-1-git-send-email-eantoranz@gmail.com","threadId":"40689","inReplyTo":null,"subject":"[PATCH v2] checkout: refactor of --progress option","fromName":"Edmundo Carmona Antoranz","fromEmail":"eantoranz@gmail.com","sentAt":"2015-10-31T18:47:16Z","receivedAt":"2015-10-31T18:47:16Z","isPatch":true,"sender":{"key":"eantoranz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1491018?v=4"},"body":"- removed static variable show_progress\n- processing if progress will be shown or not right\n  after running parse_options()\n\nSigned-off-by: Edmundo Carmona Antoranz <eantoranz@gmail.com>\n---\n builtin/checkout.c | 38 +++++++++++++++++++++-----------------\n 1 file changed, 21 insertions(+), 17 deletions(-)\n\ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex e28c36b..81c9e6f 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -27,8 +27,6 @@ static const char * const checkout_usage[] = {\n \tNULL,\n };\n \n-static int option_progress = -1;\n-\n struct checkout_opts {\n \tint patch_mode;\n \tint quiet;\n@@ -39,6 +37,7 @@ struct checkout_opts {\n \tint overwrite_ignore;\n \tint ignore_skipworktree;\n \tint ignore_other_worktrees;\n+\tint show_progress;\n \n \tconst char *new_branch;\n \tconst char *new_branch_force;\n@@ -419,19 +418,7 @@ static int reset_tree(struct tree *tree, const struct checkout_opts *o,\n \topts.reset = 1;\n \topts.merge = 1;\n \topts.fn = oneway_merge;\n-\t/**\n-\t * Rules to display progress:\n-\t * -q is selected\n-\t *      no verbiage\n-\t * -q is _not_ selected and --no-progress _is_ selected,\n-\t *      progress will be skipped\n-\t * -q is _not_ selected and --progress _is_ selected,\n-\t *      progress will be printed to stderr\n-\t * -q is _not_ selected and --progress is 'undefined'\n-\t *      progress will be printed to stderr _if_ working on a terminal\n-\t */\n-\topts.verbose_update = !o->quiet && (option_progress > 0 ||\n-\t\t\t\t\t   (option_progress < 0 && isatty(2)));\n+\topts.verbose_update = o->show_progress;\n \topts.src_index = &the_index;\n \topts.dst_index = &the_index;\n \tparse_tree(tree);\n@@ -515,7 +502,7 @@ static int merge_working_tree(const struct checkout_opts *opts,\n \t\ttopts.update = 1;\n \t\ttopts.merge = 1;\n \t\ttopts.gently = opts->merge && old->commit;\n-\t\ttopts.verbose_update = !opts->quiet && isatty(2);\n+\t\ttopts.verbose_update = opts->show_progress;\n \t\ttopts.fn = twoway_merge;\n \t\tif (opts->overwrite_ignore) {\n \t\t\ttopts.dir = xcalloc(1, sizeof(*topts.dir));\n@@ -1170,7 +1157,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)\n \t\t\t\tN_(\"second guess 'git checkout <no-such-branch>'\")),\n \t\tOPT_BOOL(0, \"ignore-other-worktrees\", &opts.ignore_other_worktrees,\n \t\t\t N_(\"do not check if another worktree is holding the given ref\")),\n-\t\tOPT_BOOL(0, \"progress\", &option_progress, N_(\"force progress reporting\")),\n+\t\tOPT_BOOL(0, \"progress\", &opts.show_progress, N_(\"force progress reporting\")),\n \t\tOPT_END(),\n \t};\n \n@@ -1178,6 +1165,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)\n \tmemset(&new, 0, sizeof(new));\n \topts.overwrite_ignore = 1;\n \topts.prefix = prefix;\n+\topts.show_progress = -1;\n \n \tgitmodules_config();\n \tgit_config(git_checkout_config, &opts);\n@@ -1187,6 +1175,22 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)\n \targc = parse_options(argc, argv, prefix, options, checkout_usage,\n \t\t\t     PARSE_OPT_KEEP_DASHDASH);\n \n+\t/*\n+\t * Final processing of show_progress\n+\t * Any of these 3 conditions will make progress output be skipped:\n+\t * - selected --quiet\n+\t * - selected --no-progress\n+\t * - didn't select --progress and not working on a terminal\n+\t */\n+\tif (opts.show_progress) {\n+\t\t/* user selected --progress or didn't specify */\n+\t\tif (opts.quiet) {\n+\t\t\topts.show_progress = 0;\n+\t\t} else if (opts.show_progress < 0) {\n+\t\t\topts.show_progress = isatty(2);\n+\t\t}\n+\t}\n+\n \tif (conflict_style) {\n \t\topts.merge = 1; /* implied */\n \t\tgit_xmerge_config(\"merge.conflictstyle\", conflict_style, NULL);\n-- \n2.6.1\n"}]}