{"thread":{"id":"40631","subject":"[PATCH 1/2] checkout: progress on non-tty. progress with lf","startedAt":"2015-10-24T14:59:46Z","lastAt":"2015-10-25T01:50:17Z","messageCount":2,"participants":["Edmundo Carmona","Edmundo Carmona Antoranz"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"272169","messageId":"1445698786-22673-1-git-send-email-eantoranz@gmail.com","threadId":"40631","inReplyTo":null,"subject":"[PATCH 1/2] checkout: progress on non-tty. progress with lf","fromName":"Edmundo Carmona","fromEmail":"eantoranz@gmail.com","sentAt":"2015-10-24T14:59:46Z","receivedAt":"2015-10-24T14:59:46Z","isPatch":true,"sender":{"key":"eantoranz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1491018?v=4"},"body":"From: Edmundo Carmona Antoranz <eantoranz@gmail.com>\n\n--progress-no-tty: option to write progress even if not working on a TTY\n--progress-lf: option to print progress using LF instead of CR\nSigned-off-by: Edmundo Carmona Antoranz <eantoranz@gmail.com>\n---\n builtin/checkout.c | 12 ++++++++++--\n progress.c         |  8 +++++++-\n progress.h         |  1 +\n unpack-trees.c     |  3 +++\n unpack-trees.h     |  2 ++\n 5 files changed, 23 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex bc703c0..2c86a9a 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -37,6 +37,8 @@ struct checkout_opts {\n \tint overwrite_ignore;\n \tint ignore_skipworktree;\n \tint ignore_other_worktrees;\n+\tint progress_lf;\n+\tint progress_notty;\n \n \tconst char *new_branch;\n \tconst char *new_branch_force;\n@@ -417,7 +419,8 @@ 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-\topts.verbose_update = !o->quiet && isatty(2);\n+\topts.verbose_update = !o->quiet && (o->progress_notty || isatty(2));\n+\topts.eol = o->progress_lf ? _(\"\\n\") : NULL;\n \topts.src_index = &the_index;\n \topts.dst_index = &the_index;\n \tparse_tree(tree);\n@@ -501,7 +504,8 @@ 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->quiet && (opts->progress_notty || isatty(2));\n+\t\ttopts.eol = opts->progress_lf ? _(\"\\n\") : NULL;\n \t\ttopts.fn = twoway_merge;\n \t\tif (opts->overwrite_ignore) {\n \t\t\ttopts.dir = xcalloc(1, sizeof(*topts.dir));\n@@ -1156,6 +1160,10 @@ 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-lf\", &opts.progress_lf,\n+\t\t\t N_(\"write progress using lf instead of cr\")),\n+\t\tOPT_BOOL(0, \"progress-no-tty\", &opts.progress_notty,\n+\t\t\t N_(\"write progress info even if not using a TTY\")),\n \t\tOPT_END(),\n \t};\n \ndiff --git a/progress.c b/progress.c\nindex 353bd37..3af0594 100644\n--- a/progress.c\n+++ b/progress.c\n@@ -36,6 +36,7 @@ struct progress {\n \tunsigned delay;\n \tunsigned delayed_percent_treshold;\n \tstruct throughput *throughput;\n+\tconst char *eol;\n };\n \n static volatile sig_atomic_t progress_update;\n@@ -99,7 +100,7 @@ static int display(struct progress *progress, unsigned n, const char *done)\n \n \tprogress->last_value = n;\n \ttp = (progress->throughput) ? progress->throughput->display.buf : \"\";\n-\teol = done ? done : \"   \\r\";\n+\teol = done ? done : (progress->eol ? progress->eol : \"   \\r\");\n \tif (progress->total) {\n \t\tunsigned percent = n * 100 / progress->total;\n \t\tif (percent != progress->last_percent || progress_update) {\n@@ -221,6 +222,7 @@ struct progress *start_progress_delay(const char *title, unsigned total,\n \tprogress->delayed_percent_treshold = percent_treshold;\n \tprogress->delay = delay;\n \tprogress->throughput = NULL;\n+\tprogress->eol = NULL;\n \tset_progress_signal();\n \treturn progress;\n }\n@@ -230,6 +232,10 @@ struct progress *start_progress(const char *title, unsigned total)\n \treturn start_progress_delay(title, total, 0, 0);\n }\n \n+void set_progress_eol(struct progress *p_progress, const char *eol) {\n+\tp_progress->eol = eol;\n+}\n+\n void stop_progress(struct progress **p_progress)\n {\n \tstop_progress_msg(p_progress, _(\"done\"));\ndiff --git a/progress.h b/progress.h\nindex 611e4c4..dbde34e 100644\n--- a/progress.h\n+++ b/progress.h\n@@ -8,6 +8,7 @@ int display_progress(struct progress *progress, unsigned n);\n struct progress *start_progress(const char *title, unsigned total);\n struct progress *start_progress_delay(const char *title, unsigned total,\n \t\t\t\t       unsigned percent_treshold, unsigned delay);\n+void set_progress_eol(struct progress *p_progress, const char *eol);\n void stop_progress(struct progress **progress);\n void stop_progress_msg(struct progress **progress, const char *msg);\n \ndiff --git a/unpack-trees.c b/unpack-trees.c\nindex 8e2032f..250482b 100644\n--- a/unpack-trees.c\n+++ b/unpack-trees.c\n@@ -202,6 +202,9 @@ static int check_updates(struct unpack_trees_options *o)\n \n \t\tprogress = start_progress_delay(_(\"Checking out files\"),\n \t\t\t\t\t\ttotal, 50, 1);\n+\t\tif (o->eol) {\n+\t\t\tset_progress_eol(progress, o->eol);\n+\t\t}\n \t\tcnt = 0;\n \t}\n \ndiff --git a/unpack-trees.h b/unpack-trees.h\nindex 36a73a6..3e4bc47 100644\n--- a/unpack-trees.h\n+++ b/unpack-trees.h\n@@ -71,6 +71,8 @@ struct unpack_trees_options {\n \tstruct index_state *src_index;\n \tstruct index_state result;\n \n+\tconst char *eol;\n+\n \tstruct exclude_list *el; /* for internal use */\n };\n \n-- \n2.6.1\n"},{"id":"272181","messageId":"CAOc6etbn3656Az9hhK3B5ZAwjSVmqj=XU+6F=v-8VyUOvD90zw@mail.gmail.com","threadId":"40631","inReplyTo":"1445698786-22673-1-git-send-email-eantoranz@gmail.com","subject":"Re: [PATCH 1/2] checkout: progress on non-tty. progress with lf","fromName":"Edmundo Carmona Antoranz","fromEmail":"eantoranz@gmail.com","sentAt":"2015-10-25T01:50:17Z","receivedAt":"2015-10-25T01:50:17Z","isPatch":true,"sender":{"key":"eantoranz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1491018?v=4"},"body":"Hello, everybody!\n\nSo, this is my first patch ever for git. What would be the expected\nworkflow for this patch from a newcomer like me? Maybe getting some\nfire starting monday?\n\nOn the technical side, I was wondering if it made more sense to use a\n\"boolean\" value to control if progress should use CR or LF, instead of\nallowing to set whatever we wanted in struct progress.eol.\n\nSomething like\n\ndiff --git a/progress.c b/progress.c\nindex 3af0594..8584e48 100644\n--- a/progress.c\n+++ b/progress.c\n@@ -36,7 +36,7 @@ struct progress {\n       unsigned delay;\n       unsigned delayed_percent_treshold;\n       struct throughput *throughput;\n-       const char *eol;\n+       int eol_lf;\n};\n\nstatic volatile sig_atomic_t progress_update;\n@@ -100,7 +100,7 @@ static int display(struct progress *progress,\nunsigned n, const char *done)\n\n       progress->last_value = n;\n       tp = (progress->throughput) ? progress->throughput->display.buf : \"\";\n-       eol = done ? done : (progress->eol ? progress->eol : \"   \\r\");\n+       eol = done ? done : (progress->eol_lf ? \"\\n\" : \"   \\r\");\n       if (progress->total) {\n               unsigned percent = n * 100 / progress->total;\n               if (percent != progress->last_percent || progress_update) {\n\n\nThanks!\n\nOn Sat, Oct 24, 2015 at 8:59 AM, Edmundo Carmona <eantoranz@gmail.com> wrote:\n> From: Edmundo Carmona Antoranz <eantoranz@gmail.com>\n>\n> --progress-no-tty: option to write progress even if not working on a TTY\n> --progress-lf: option to print progress using LF instead of CR\n> Signed-off-by: Edmundo Carmona Antoranz <eantoranz@gmail.com>\n> ---\n>  builtin/checkout.c | 12 ++++++++++--\n>  progress.c         |  8 +++++++-\n>  progress.h         |  1 +\n>  unpack-trees.c     |  3 +++\n>  unpack-trees.h     |  2 ++\n>  5 files changed, 23 insertions(+), 3 deletions(-)\n>\n> diff --git a/builtin/checkout.c b/builtin/checkout.c\n> index bc703c0..2c86a9a 100644\n> --- a/builtin/checkout.c\n> +++ b/builtin/checkout.c\n> @@ -37,6 +37,8 @@ struct checkout_opts {\n>         int overwrite_ignore;\n>         int ignore_skipworktree;\n>         int ignore_other_worktrees;\n> +       int progress_lf;\n> +       int progress_notty;\n>\n>         const char *new_branch;\n>         const char *new_branch_force;\n> @@ -417,7 +419,8 @@ static int reset_tree(struct tree *tree, const struct checkout_opts *o,\n>         opts.reset = 1;\n>         opts.merge = 1;\n>         opts.fn = oneway_merge;\n> -       opts.verbose_update = !o->quiet && isatty(2);\n> +       opts.verbose_update = !o->quiet && (o->progress_notty || isatty(2));\n> +       opts.eol = o->progress_lf ? _(\"\\n\") : NULL;\n>         opts.src_index = &the_index;\n>         opts.dst_index = &the_index;\n>         parse_tree(tree);\n> @@ -501,7 +504,8 @@ static int merge_working_tree(const struct checkout_opts *opts,\n>                 topts.update = 1;\n>                 topts.merge = 1;\n>                 topts.gently = opts->merge && old->commit;\n> -               topts.verbose_update = !opts->quiet && isatty(2);\n> +               topts.verbose_update = !opts->quiet && (opts->progress_notty || isatty(2));\n> +               topts.eol = opts->progress_lf ? _(\"\\n\") : NULL;\n>                 topts.fn = twoway_merge;\n>                 if (opts->overwrite_ignore) {\n>                         topts.dir = xcalloc(1, sizeof(*topts.dir));\n> @@ -1156,6 +1160,10 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)\n>                                 N_(\"second guess 'git checkout <no-such-branch>'\")),\n>                 OPT_BOOL(0, \"ignore-other-worktrees\", &opts.ignore_other_worktrees,\n>                          N_(\"do not check if another worktree is holding the given ref\")),\n> +               OPT_BOOL(0, \"progress-lf\", &opts.progress_lf,\n> +                        N_(\"write progress using lf instead of cr\")),\n> +               OPT_BOOL(0, \"progress-no-tty\", &opts.progress_notty,\n> +                        N_(\"write progress info even if not using a TTY\")),\n>                 OPT_END(),\n>         };\n>\n> diff --git a/progress.c b/progress.c\n> index 353bd37..3af0594 100644\n> --- a/progress.c\n> +++ b/progress.c\n> @@ -36,6 +36,7 @@ struct progress {\n>         unsigned delay;\n>         unsigned delayed_percent_treshold;\n>         struct throughput *throughput;\n> +       const char *eol;\n>  };\n>\n>  static volatile sig_atomic_t progress_update;\n> @@ -99,7 +100,7 @@ static int display(struct progress *progress, unsigned n, const char *done)\n>\n>         progress->last_value = n;\n>         tp = (progress->throughput) ? progress->throughput->display.buf : \"\";\n> -       eol = done ? done : \"   \\r\";\n> +       eol = done ? done : (progress->eol ? progress->eol : \"   \\r\");\n>         if (progress->total) {\n>                 unsigned percent = n * 100 / progress->total;\n>                 if (percent != progress->last_percent || progress_update) {\n> @@ -221,6 +222,7 @@ struct progress *start_progress_delay(const char *title, unsigned total,\n>         progress->delayed_percent_treshold = percent_treshold;\n>         progress->delay = delay;\n>         progress->throughput = NULL;\n> +       progress->eol = NULL;\n>         set_progress_signal();\n>         return progress;\n>  }\n> @@ -230,6 +232,10 @@ struct progress *start_progress(const char *title, unsigned total)\n>         return start_progress_delay(title, total, 0, 0);\n>  }\n>\n> +void set_progress_eol(struct progress *p_progress, const char *eol) {\n> +       p_progress->eol = eol;\n> +}\n> +\n>  void stop_progress(struct progress **p_progress)\n>  {\n>         stop_progress_msg(p_progress, _(\"done\"));\n> diff --git a/progress.h b/progress.h\n> index 611e4c4..dbde34e 100644\n> --- a/progress.h\n> +++ b/progress.h\n> @@ -8,6 +8,7 @@ int display_progress(struct progress *progress, unsigned n);\n>  struct progress *start_progress(const char *title, unsigned total);\n>  struct progress *start_progress_delay(const char *title, unsigned total,\n>                                        unsigned percent_treshold, unsigned delay);\n> +void set_progress_eol(struct progress *p_progress, const char *eol);\n>  void stop_progress(struct progress **progress);\n>  void stop_progress_msg(struct progress **progress, const char *msg);\n>\n> diff --git a/unpack-trees.c b/unpack-trees.c\n> index 8e2032f..250482b 100644\n> --- a/unpack-trees.c\n> +++ b/unpack-trees.c\n> @@ -202,6 +202,9 @@ static int check_updates(struct unpack_trees_options *o)\n>\n>                 progress = start_progress_delay(_(\"Checking out files\"),\n>                                                 total, 50, 1);\n> +               if (o->eol) {\n> +                       set_progress_eol(progress, o->eol);\n> +               }\n>                 cnt = 0;\n>         }\n>\n> diff --git a/unpack-trees.h b/unpack-trees.h\n> index 36a73a6..3e4bc47 100644\n> --- a/unpack-trees.h\n> +++ b/unpack-trees.h\n> @@ -71,6 +71,8 @@ struct unpack_trees_options {\n>         struct index_state *src_index;\n>         struct index_state result;\n>\n> +       const char *eol;\n> +\n>         struct exclude_list *el; /* for internal use */\n>  };\n>\n> --\n> 2.6.1\n>\n"}]}