{"thread":{"id":"45006","subject":"[PATCH] blame: draft of line format","startedAt":"2017-01-31T02:28:44Z","lastAt":"2017-03-07T01:14:35Z","messageCount":4,"participants":["Edmundo Carmona Antoranz","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"310585","messageId":"20170131022830.8538-1-eantoranz@gmail.com","threadId":"45006","inReplyTo":null,"subject":"[PATCH] blame: draft of line format","fromName":"Edmundo Carmona Antoranz","fromEmail":"eantoranz@gmail.com","sentAt":"2017-01-31T02:28:30Z","receivedAt":"2017-01-31T02:28:44Z","isPatch":true,"sender":{"key":"eantoranz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1491018?v=4"},"body":"---\n builtin/blame.c | 24 ++++++++++++++++++++++++\n 1 file changed, 24 insertions(+)\n\ndiff --git a/builtin/blame.c b/builtin/blame.c\nindex 126b8c9e5..89c1a862d 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -52,6 +52,7 @@ static int xdl_opts;\n static int abbrev = -1;\n static int no_whole_file_rename;\n static int show_progress;\n+static char *format_line;\n \n static struct date_mode blame_date_mode = { DATE_ISO8601 };\n static size_t blame_date_width;\n@@ -1931,6 +1932,19 @@ static void emit_porcelain(struct scoreboard *sb, struct blame_entry *ent,\n \t\tputchar('\\n');\n }\n \n+static void pretty_info(char* revid, struct blame_entry *ent, struct strbuf *rev_buffer)\n+{\n+\tstruct pretty_print_context ctx = {0};\n+\tstruct rev_info rev;\n+\n+\tstruct strbuf format = STRBUF_INIT;\n+\tstrbuf_addstr(&format, format_line);\n+\tctx.fmt = CMIT_FMT_USERFORMAT;\n+\tget_commit_format(format.buf, &rev);\n+\tpretty_print_commit(&ctx, ent->suspect->commit, rev_buffer);\n+\tstrbuf_release(&format);\n+}\n+\n static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)\n {\n \tint cnt;\n@@ -1939,11 +1953,15 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)\n \tstruct commit_info ci;\n \tchar hex[GIT_SHA1_HEXSZ + 1];\n \tint show_raw_time = !!(opt & OUTPUT_RAW_TIMESTAMP);\n+\tstruct strbuf line_revision_buf = STRBUF_INIT;\n \n \tget_commit_info(suspect->commit, &ci, 1);\n \tsha1_to_hex_r(hex, suspect->commit->object.oid.hash);\n \n \tcp = nth_line(sb, ent->lno);\n+\n+\tif (format_line)\n+\t\tpretty_info(hex, ent, &line_revision_buf);\n \tfor (cnt = 0; cnt < ent->num_lines; cnt++) {\n \t\tchar ch;\n \t\tint length = (opt & OUTPUT_LONG_OBJECT_NAME) ? GIT_SHA1_HEXSZ : abbrev;\n@@ -1968,6 +1986,10 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)\n \t\t\t       format_time(ci.author_time, ci.author_tz.buf,\n \t\t\t\t\t   show_raw_time),\n \t\t\t       ent->lno + 1 + cnt);\n+\t\t} else if (format_line) {\n+\t\t\tprintf(\"%s\", line_revision_buf.buf);\n+\t\t\tprintf(\" %*d) \",\n+\t\t\t       max_digits, ent->lno + 1 + cnt);\n \t\t} else {\n \t\t\tif (opt & OUTPUT_SHOW_SCORE)\n \t\t\t\tprintf(\" %*d %02d\",\n@@ -2007,6 +2029,7 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)\n \tif (sb->final_buf_size && cp[-1] != '\\n')\n \t\tputchar('\\n');\n \n+\tstrbuf_release(&line_revision_buf);\n \tcommit_info_destroy(&ci);\n }\n \n@@ -2605,6 +2628,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)\n \n \t\tOPT_BIT(0, \"minimal\", &xdl_opts, N_(\"Spend extra cycles to find better match\"), XDF_NEED_MINIMAL),\n \t\tOPT_STRING('S', NULL, &revs_file, N_(\"file\"), N_(\"Use revisions from <file> instead of calling git-rev-list\")),\n+\t\tOPT_STRING(0, \"format-line\", &format_line, N_(\"format-line\"), N_(\"Use pretty format for revisions\")),\n \t\tOPT_STRING(0, \"contents\", &contents_from, N_(\"file\"), N_(\"Use <file>'s contents as the final image\")),\n \t\t{ OPTION_CALLBACK, 'C', NULL, &opt, N_(\"score\"), N_(\"Find line copies within and across files\"), PARSE_OPT_OPTARG, blame_copy_callback },\n \t\t{ OPTION_CALLBACK, 'M', NULL, &opt, N_(\"score\"), N_(\"Find line movements within and across files\"), PARSE_OPT_OPTARG, blame_move_callback },\n-- \n2.11.0.rc1\n\n"},{"id":"310586","messageId":"CAOc6etbZ56V_9GSwOO3eFqg1TCwXT3+hDT67xEgZvui7DO-dRg@mail.gmail.com","threadId":"45006","inReplyTo":"20170131022830.8538-1-eantoranz@gmail.com","subject":"Re: [PATCH] blame: draft of line format","fromName":"Edmundo Carmona Antoranz","fromEmail":"eantoranz@gmail.com","sentAt":"2017-01-31T02:34:19Z","receivedAt":"2017-01-31T02:34:30Z","isPatch":true,"sender":{"key":"eantoranz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1491018?v=4"},"body":"I'm basing in on the \"pretty API\" so that we don't have to reinvent\nthe wheel. I have already noticed that many of the formatting options\navailable for pretty are not working... I'm sure it would require some\nwork setting up the call to pretty api but the basic is laid out\nthere.\n\nLet me know of your thoughts.\n"},{"id":"310613","messageId":"20170131194138.fbcbdnkfjgizxnoa@sigill.intra.peff.net","threadId":"45006","inReplyTo":"20170131022830.8538-1-eantoranz@gmail.com","subject":"Re: [PATCH] blame: draft of line format","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-01-31T19:41:39Z","receivedAt":"2017-01-31T19:44:11Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Jan 30, 2017 at 08:28:30PM -0600, Edmundo Carmona Antoranz wrote:\n\n> +static void pretty_info(char* revid, struct blame_entry *ent, struct strbuf *rev_buffer)\n> +{\n> +\tstruct pretty_print_context ctx = {0};\n> +\tstruct rev_info rev;\n> +\n> +\tstruct strbuf format = STRBUF_INIT;\n> +\tstrbuf_addstr(&format, format_line);\n> +\tctx.fmt = CMIT_FMT_USERFORMAT;\n> +\tget_commit_format(format.buf, &rev);\n> +\tpretty_print_commit(&ctx, ent->suspect->commit, rev_buffer);\n> +\tstrbuf_release(&format);\n> +}\n\nI think this may be less awkward if you use format_commit_message() as\nthe entry point. Then you do not need a rev_info struct at all, it\ntouches fewer global variables, etc.\n\nI don't know if that would cause the other difficulties you mentioned,\nthough.\n\n-Peff\n"},{"id":"313394","messageId":"CAOc6etZjvpiQ65JHWzVeEqUzO0uJv8UjuWw7mbvCL5Om9weZLg@mail.gmail.com","threadId":"45006","inReplyTo":"20170131194138.fbcbdnkfjgizxnoa@sigill.intra.peff.net","subject":"Re: [PATCH] blame: draft of line format","fromName":"Edmundo Carmona Antoranz","fromEmail":"eantoranz@gmail.com","sentAt":"2017-03-06T23:29:56Z","receivedAt":"2017-03-07T01:14:35Z","isPatch":true,"sender":{"key":"eantoranz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1491018?v=4"},"body":"On Tue, Jan 31, 2017 at 1:41 PM, Jeff King <peff@peff.net> wrote:\n> On Mon, Jan 30, 2017 at 08:28:30PM -0600, Edmundo Carmona Antoranz wrote:\n>\n>> +static void pretty_info(char* revid, struct blame_entry *ent, struct strbuf *rev_buffer)\n>> +{\n>> +     struct pretty_print_context ctx = {0};\n>> +     struct rev_info rev;\n>> +\n>> +     struct strbuf format = STRBUF_INIT;\n>> +     strbuf_addstr(&format, format_line);\n>> +     ctx.fmt = CMIT_FMT_USERFORMAT;\n>> +     get_commit_format(format.buf, &rev);\n>> +     pretty_print_commit(&ctx, ent->suspect->commit, rev_buffer);\n>> +     strbuf_release(&format);\n>> +}\n>\n> I think this may be less awkward if you use format_commit_message() as\n> the entry point. Then you do not need a rev_info struct at all, it\n> touches fewer global variables, etc.\n>\n> I don't know if that would cause the other difficulties you mentioned,\n> though.\n>\n> -Peff\n\nThanks for the tip, Peff. It made the code to get rev info much\nshorter. I'll work on some other improvements and then I'll send\nanother patch.\n\nBest regards!\n"}]}