{"thread":{"id":"40864","subject":"[PATCH v4] blame: add support for --[no-]progress option","startedAt":"2015-11-24T01:07:57Z","lastAt":"2015-11-25T04:33:49Z","messageCount":4,"participants":["Edmundo Carmona Antoranz","Torsten Bögershausen"],"isPatch":true,"patchVersion":4,"patchTotal":null},"messages":[{"id":"273628","messageId":"1448327277-29385-1-git-send-email-eantoranz@gmail.com","threadId":"40864","inReplyTo":null,"subject":"[PATCH v4] blame: add support for --[no-]progress option","fromName":"Edmundo Carmona Antoranz","fromEmail":"eantoranz@gmail.com","sentAt":"2015-11-24T01:07:57Z","receivedAt":"2015-11-24T01:07:57Z","isPatch":true,"sender":{"key":"eantoranz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1491018?v=4"},"body":"* created struct progress_info in builtin/blame.c\n  this struct holds the information used to display progress so\n  that only one additional parameter is passed to\n  found_guilty_entry().\n\n* --[no-]progress option is also inherited by git-annotate.\n\nSigned-off-by: Edmundo Carmona Antoranz <eantoranz@gmail.com>\n---\n Documentation/blame-options.txt |  7 +++++++\n Documentation/git-blame.txt     |  3 ++-\n builtin/blame.c                 | 40 ++++++++++++++++++++++++++++++++++++----\n 3 files changed, 45 insertions(+), 5 deletions(-)\n\ndiff --git a/Documentation/blame-options.txt b/Documentation/blame-options.txt\nindex 760eab7..ef642b9 100644\n--- a/Documentation/blame-options.txt\n+++ b/Documentation/blame-options.txt\n@@ -69,6 +69,13 @@ include::line-range-format.txt[]\n \tiso format is used. For supported values, see the discussion\n \tof the --date option at linkgit:git-log[1].\n \n+--[no-]progress::\n+\tProgress status is reported on the standard error stream\n+\tby default when it is attached to a terminal. This flag\n+\tenables progress reporting even if not attached to a\n+\tterminal. Progress information won't be displayed if using\n+\t`--porcelain` or `--incremental`.\n+\n -M|<num>|::\n \tDetect moved or copied lines within a file. When a commit\n \tmoves or copies a block of lines (e.g. the original file\ndiff --git a/Documentation/git-blame.txt b/Documentation/git-blame.txt\nindex e6e947c..b0154c2 100644\n--- a/Documentation/git-blame.txt\n+++ b/Documentation/git-blame.txt\n@@ -10,7 +10,8 @@ SYNOPSIS\n [verse]\n 'git blame' [-c] [-b] [-l] [--root] [-t] [-f] [-n] [-s] [-e] [-p] [-w] [--incremental]\n \t    [-L <range>] [-S <revs-file>] [-M] [-C] [-C] [-C] [--since=<date>]\n-\t    [--abbrev=<n>] [<rev> | --contents <file> | --reverse <rev>] [--] <file>\n+\t    [--[no-]progress] [--abbrev=<n>] [<rev> | --contents <file> | --reverse <rev>]\n+\t    [--] <file>\n \n DESCRIPTION\n -----------\ndiff --git a/builtin/blame.c b/builtin/blame.c\nindex 83612f5..1d43b52 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -28,6 +28,7 @@\n #include \"line-range.h\"\n #include \"line-log.h\"\n #include \"dir.h\"\n+#include \"progress.h\"\n \n static char blame_usage[] = N_(\"git blame [<options>] [<rev-opts>] [<rev>] [--] <file>\");\n \n@@ -50,6 +51,7 @@ static int incremental;\n static int xdl_opts;\n static int abbrev = -1;\n static int no_whole_file_rename;\n+static int show_progress;\n \n static struct date_mode blame_date_mode = { DATE_ISO8601 };\n static size_t blame_date_width;\n@@ -127,6 +129,11 @@ struct origin {\n \tchar path[FLEX_ARRAY];\n };\n \n+struct progress_info {\n+\tstruct progress *progress;\n+\tint blamed_lines;\n+};\n+\n static int diff_hunks(mmfile_t *file_a, mmfile_t *file_b, long ctxlen,\n \t\t      xdl_emit_hunk_consume_func_t hunk_func, void *cb_data)\n {\n@@ -1746,7 +1753,8 @@ static int emit_one_suspect_detail(struct origin *suspect, int repeat)\n  * The blame_entry is found to be guilty for the range.\n  * Show it in incremental output.\n  */\n-static void found_guilty_entry(struct blame_entry *ent)\n+static void found_guilty_entry(struct blame_entry *ent,\n+\t\t\t   struct progress_info * pi)\n {\n \tif (incremental) {\n \t\tstruct origin *suspect = ent->suspect;\n@@ -1758,6 +1766,8 @@ static void found_guilty_entry(struct blame_entry *ent)\n \t\twrite_filename_info(suspect->path);\n \t\tmaybe_flush_or_die(stdout, \"stdout\");\n \t}\n+\tif (pi)\n+\t\tdisplay_progress(pi->progress, pi->blamed_lines += ent->num_lines);\n }\n \n /*\n@@ -1768,6 +1778,16 @@ static void assign_blame(struct scoreboard *sb, int opt)\n {\n \tstruct rev_info *revs = sb->revs;\n \tstruct commit *commit = prio_queue_get(&sb->commits);\n+\tstruct progress_info *pi = NULL;\n+\n+\tif (show_progress) {\n+\t\tpi = malloc(sizeof(*pi));\n+\t\tif (pi) {\n+\t\t\tpi->progress = start_progress_delay(_(\"Blaming lines\"),\n+\t\t\t                                    sb->num_lines, 50, 1);\n+\t\t\tpi->blamed_lines = 0;\n+\t\t}\n+\t}\n \n \twhile (commit) {\n \t\tstruct blame_entry *ent;\n@@ -1809,7 +1829,7 @@ static void assign_blame(struct scoreboard *sb, int opt)\n \t\t\tsuspect->guilty = 1;\n \t\t\tfor (;;) {\n \t\t\t\tstruct blame_entry *next = ent->next;\n-\t\t\t\tfound_guilty_entry(ent);\n+\t\t\t\tfound_guilty_entry(ent, pi);\n \t\t\t\tif (next) {\n \t\t\t\t\tent = next;\n \t\t\t\t\tcontinue;\n@@ -1825,6 +1845,11 @@ static void assign_blame(struct scoreboard *sb, int opt)\n \t\tif (DEBUG) /* sanity */\n \t\t\tsanity_check_refcnt(sb);\n \t}\n+\n+\tif (pi) {\n+\t\tstop_progress(&pi->progress);\n+\t\tfree(pi);\n+\t};\n }\n \n static const char *format_time(unsigned long time, const char *tz_str,\n@@ -2520,6 +2545,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)\n \t\tOPT_BOOL('b', NULL, &blank_boundary, N_(\"Show blank SHA-1 for boundary commits (Default: off)\")),\n \t\tOPT_BOOL(0, \"root\", &show_root, N_(\"Do not treat root commits as boundaries (Default: off)\")),\n \t\tOPT_BOOL(0, \"show-stats\", &show_stats, N_(\"Show work cost statistics\")),\n+\t\tOPT_BOOL(0, \"progress\", &show_progress, N_(\"Force progress reporting\")),\n \t\tOPT_BIT(0, \"score-debug\", &output_option, N_(\"Show output score for blame entries\"), OUTPUT_SHOW_SCORE),\n \t\tOPT_BIT('f', \"show-name\", &output_option, N_(\"Show original filename (Default: auto)\"), OUTPUT_SHOW_NAME),\n \t\tOPT_BIT('n', \"show-number\", &output_option, N_(\"Show original linenumber (Default: off)\"), OUTPUT_SHOW_NUMBER),\n@@ -2555,6 +2581,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)\n \n \tsave_commit_buffer = 0;\n \tdashdash_pos = 0;\n+\tshow_progress = -1;\n \n \tparse_options_start(&ctx, argc, argv, prefix, options,\n \t\t\t    PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_ARGV0);\n@@ -2579,6 +2606,11 @@ parse_done:\n \tDIFF_OPT_CLR(&revs.diffopt, FOLLOW_RENAMES);\n \targc = parse_options_end(&ctx);\n \n+\tif (incremental || (output_option & OUTPUT_PORCELAIN))\n+\t\tshow_progress = 0;\n+\telse if (show_progress < 0)\n+\t\tshow_progress = isatty(2);\n+\n \tif (0 < abbrev)\n \t\t/* one more abbrev length is needed for the boundary commit */\n \t\tabbrev++;\n@@ -2830,11 +2862,11 @@ parse_done:\n \n \tread_mailmap(&mailmap, NULL);\n \n+\tassign_blame(&sb, opt);\n+\n \tif (!incremental)\n \t\tsetup_pager();\n \n-\tassign_blame(&sb, opt);\n-\n \tfree(final_commit_name);\n \n \tif (incremental)\n-- \n2.6.2\n"},{"id":"273629","messageId":"CAOc6etaxxLUio4yt4aYuG-3xFCXMHqSHKPbxnE43hXuVuGQ-zw@mail.gmail.com","threadId":"40864","inReplyTo":"1448327277-29385-1-git-send-email-eantoranz@gmail.com","subject":"Re: [PATCH v4] blame: add support for --[no-]progress option","fromName":"Edmundo Carmona Antoranz","fromEmail":"eantoranz@gmail.com","sentAt":"2015-11-24T01:10:06Z","receivedAt":"2015-11-24T01:10:06Z","isPatch":true,"sender":{"key":"eantoranz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1491018?v=4"},"body":"On Mon, Nov 23, 2015 at 7:07 PM, Edmundo Carmona Antoranz\n<eantoranz@gmail.com> wrote:\n>  {\n>         struct rev_info *revs = sb->revs;\n>         struct commit *commit = prio_queue_get(&sb->commits);\n> +       struct progress_info *pi = NULL;\n\nSwitched to using  pointer to make it more elegant.\n"},{"id":"273632","messageId":"5653FC4D.4090201@web.de","threadId":"40864","inReplyTo":"1448327277-29385-1-git-send-email-eantoranz@gmail.com","subject":"Re: [PATCH v4] blame: add support for --[no-]progress option","fromName":"Torsten Bögershausen","fromEmail":"tboegi@web.de","sentAt":"2015-11-24T05:57:33Z","receivedAt":"2015-11-24T05:57:33Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"On 11/24/2015 02:07 AM, Edmundo Carmona Antoranz wrote:\n> diff --git a/builtin/blame.c b/builtin/blame.c\n> index 83612f5..1d43b52 100644\n> --- a/builtin/blame.c\n> +++ b/builtin/blame.c\n> @@ -28,6 +28,7 @@\n>   #include \"line-range.h\"\n>   #include \"line-log.h\"\n>   #include \"dir.h\"\n> +#include \"progress.h\"\n>   \n>   static char blame_usage[] = N_(\"git blame [<options>] [<rev-opts>] [<rev>] [--] <file>\");\n>   \n> @@ -50,6 +51,7 @@ static int incremental;\n>   static int xdl_opts;\n>   static int abbrev = -1;\n>   static int no_whole_file_rename;\n> +static int show_progress;\n>   \n>   static struct date_mode blame_date_mode = { DATE_ISO8601 };\n>   static size_t blame_date_width;\n> @@ -127,6 +129,11 @@ struct origin {\n>   \tchar path[FLEX_ARRAY];\n>   };\n>   \n> +struct progress_info {\n> +\tstruct progress *progress;\n> +\tint blamed_lines;\n> +};\n> +\n>   static int diff_hunks(mmfile_t *file_a, mmfile_t *file_b, long ctxlen,\n>   \t\t      xdl_emit_hunk_consume_func_t hunk_func, void *cb_data)\n>   {\n> @@ -1746,7 +1753,8 @@ static int emit_one_suspect_detail(struct origin *suspect, int repeat)\n>    * The blame_entry is found to be guilty for the range.\n>    * Show it in incremental output.\n>    */\n> -static void found_guilty_entry(struct blame_entry *ent)\n> +static void found_guilty_entry(struct blame_entry *ent,\n> +\t\t\t   struct progress_info * pi)\nMinor remark: The '*' should be close to the variable: \"struct \nprogress_info *pi\"\n>\n"},{"id":"273699","messageId":"CAOc6etYBT_PBknCMuSr4=ARke-sNY8-YrO9yp20v7NkzDwrsMQ@mail.gmail.com","threadId":"40864","inReplyTo":"5653FC4D.4090201@web.de","subject":"Re: [PATCH v4] blame: add support for --[no-]progress option","fromName":"Edmundo Carmona Antoranz","fromEmail":"eantoranz@gmail.com","sentAt":"2015-11-25T04:33:49Z","receivedAt":"2015-11-25T04:33:49Z","isPatch":true,"sender":{"key":"eantoranz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1491018?v=4"},"body":"On Mon, Nov 23, 2015 at 11:57 PM, Torsten Bögershausen <tboegi@web.de> wrote:\n> Minor remark: The '*' should be close to the variable: \"struct progress_info\n> *pi\"\n\nNice catch, Torsten. I had already caught it as the standard... that\none slipped by.\n\nWas waiting for more comments to show up, but none so far so I'll send\nanother version with this adjustment.\n\nThanks again!\n"}]}