From: john at keeping.me.uk (John Keeping)
Subject: [RFCv2 PATCH 5/7] ui-blame: pull blame info from libgit
Date: Sat, 23 Sep 2017 16:47:58 +0100 [thread overview]
Message-ID: <20170923154758.GE2548@john.keeping.me.uk> (raw)
In-Reply-To: <20170923033848.5922-6-whydoubt@gmail.com>
On Fri, Sep 22, 2017 at 10:38:46PM -0500, Jeff Smith wrote:
> Use the blame interface added in libgit to output the blame information
> of a file in the repository.
>
> Signed-off-by: Jeff Smith <whydoubt at gmail.com>
> ---
> diff --git a/ui-blame.c b/ui-blame.c
> index 901ca89..cc4457a 100644
> --- a/ui-blame.c
> +++ b/ui-blame.c
> @@ -10,6 +10,183 @@
> #include "ui-blame.h"
> #include "html.h"
> #include "ui-shared.h"
> +#include "argv-array.h"
> +#include "blame.h"
> +
> +
> +/*
> + * Information on commits, used for output.
> + */
> +struct commit_info {
> + struct strbuf author;
> + struct strbuf author_mail;
> + struct ident_split author_ident;
> +
> + /* filled only when asked for details */
> + struct strbuf committer;
> + struct strbuf committer_mail;
> + struct ident_split committer_ident;
> +
> + struct strbuf summary;
> +};
I think I commented on this last time, but I still don't understand why
this adds a new commit_info structure rather than reusing our existing
commitinfo and cgit_parse_commit(), especially since...
> +static void get_commit_info(struct commit *commit,
> + struct commit_info *ret,
> + int detailed)
> +{
> + int len;
> + const char *subject, *encoding;
> + const char *message;
> +
> + commit_info_init(ret);
> +
> + encoding = get_log_output_encoding();
... this is wrong as our output encoding has nothing to do with the
environment but is specified by PAGE_ENCODING.
> + message = logmsg_reencode(commit, NULL, encoding);
> + get_ac_line(message, "\nauthor ",
> + &ret->author, &ret->author_mail,
> + &ret->author_ident);
> +
> + if (!detailed) {
> + unuse_commit_buffer(commit, message);
> + return;
> + }
> +
> + get_ac_line(message, "\ncommitter ",
> + &ret->committer, &ret->committer_mail,
> + &ret->committer_ident);
> +
> + len = find_commit_subject(message, &subject);
> + if (len)
> + strbuf_add(&ret->summary, subject, len);
> + else
> + strbuf_addf(&ret->summary, "(%s)", oid_to_hex(&commit->object.oid));
> +
> + unuse_commit_buffer(commit, message);
> +}
> +
> +static char *emit_one_suspect_detail(struct blame_origin *suspect, const char *hex)
> +{
> + struct commit_info ci;
> + struct strbuf detail = STRBUF_INIT;
> +
> + get_commit_info(suspect->commit, &ci, 1);
> +
> + strbuf_addf(&detail, "author %s", ci.author.buf);
> + if (!ctx.cfg.noplainemail)
> + strbuf_addf(&detail, " %s", ci.author_mail.buf);
> + strbuf_addf(&detail, " %s\n",
> + show_ident_date(&ci.author_ident,
> + cgit_date_mode(DATE_ISO8601)));
> +
> + strbuf_addf(&detail, "committer %s", ci.committer.buf);
> + if (!ctx.cfg.noplainemail)
> + strbuf_addf(&detail, " %s", ci.committer_mail.buf);
> + strbuf_addf(&detail, " %s\n\n",
> + show_ident_date(&ci.committer_ident,
> + cgit_date_mode(DATE_ISO8601)));
> +
> + strbuf_addbuf(&detail, &ci.summary);
> +
> + commit_info_destroy(&ci);
> + return strbuf_detach(&detail, NULL);
> +}
> +
> +static void emit_blame_entry(struct blame_scoreboard *sb, struct blame_entry *ent)
> +{
> + struct blame_origin *suspect = ent->suspect;
> + char hex[GIT_SHA1_HEXSZ + 1];
> + char *detail, *abbrev;
> + unsigned long lineno;
> + const char *numberfmt = "<a id='n%1$d' href='#n%1$d'>%1$d</a>\n";
> + const char *cp, *cpend;
> +
> + oid_to_hex_r(hex, &suspect->commit->object.oid);
> + detail = emit_one_suspect_detail(suspect, hex);
> + abbrev = xstrdup(find_unique_abbrev(suspect->commit->object.oid.hash,
> + DEFAULT_ABBREV));
nit: I don't think there's any need to strdup for abbrev, we use the
result immediately so the static buffer won't get overwritten.
> + html("<tr><td class='lines'><pre>");
> + cgit_commit_link(abbrev, detail, NULL, ctx.qry.head, hex, suspect->path);
> + html("</pre></td>\n");
> +
> + free(detail);
> + free(abbrev);
> +
> + if (ctx.cfg.enable_tree_linenumbers) {
> + html("<td class='linenumbers'><pre>");
> + lineno = ent->lno;
> + while (lineno < ent->lno + ent->num_lines)
> + htmlf(numberfmt, ++lineno);
> + html("</pre></td>\n");
> + }
> +
> + cp = blame_nth_line(sb, ent->lno);
> + cpend = blame_nth_line(sb, ent->lno + ent->num_lines);
> +
> + html("<td class='lines'><pre><code>");
> + html_ntxt(cpend - cp, cp);
> + html("</code></pre></td></tr>\n");
> +}
>
> struct walk_tree_context {
> char *curr_rev;
> @@ -47,10 +224,16 @@ static void set_title_from_path(const char *path)
> strcat(new_title, ctx.page.title);
> ctx.page.title = new_title;
> }
> +
> static void print_object(const unsigned char *sha1, const char *path, const char *basename, const char *rev)
> {
> enum object_type type;
> unsigned long size;
> + struct argv_array rev_argv = ARGV_ARRAY_INIT;
> + struct rev_info revs;
> + struct blame_scoreboard sb;
> + struct blame_origin *o;
> + struct blame_entry *ent = NULL;
>
> type = sha1_object_info(sha1, &size);
> if (type == OBJ_BAD) {
> @@ -59,7 +242,22 @@ static void print_object(const unsigned char *sha1, const char *path, const char
> return;
> }
>
> - /* Read in applicable data here */
> + argv_array_push(&rev_argv, "blame");
> + argv_array_push(&rev_argv, rev);
> + init_revisions(&revs, NULL);
> + DIFF_OPT_SET(&revs.diffopt, ALLOW_TEXTCONV);
> + setup_revisions(rev_argv.argc, rev_argv.argv, &revs, NULL);
> + init_scoreboard(&sb);
> + sb.revs = &revs;
> + setup_scoreboard(&sb, path, &o);
> + o->suspects = blame_entry_prepend(NULL, 0, sb.num_lines, o);
> + prio_queue_put(&sb.commits, o->commit);
> + blame_origin_decref(o);
> + sb.ent = NULL;
> + sb.path = path;
> + assign_blame(&sb, 0);
> + blame_sort_final(&sb);
> + blame_coalesce(&sb);
>
> set_title_from_path(path);
>
> @@ -76,7 +274,15 @@ static void print_object(const unsigned char *sha1, const char *path, const char
> return;
> }
>
> - /* Output data here */
> + html("<table class='blame blob'>");
> + for (ent = sb.ent; ent; ) {
> + struct blame_entry *e = ent->next;
> + emit_blame_entry(&sb, ent);
> + free(ent);
> + ent = e;
> + }
> + html("</table>\n");
> + free((void *)sb.final_buf);
>
> cgit_print_layout_end();
> return;
next prev parent reply other threads:[~2017-09-23 15:47 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-08 2:18 [RFC PATCH 0/4] Add ui-blame whydoubt
2017-06-08 2:18 ` [RFC PATCH 1/4] git: update to v2.14 whydoubt
2017-07-22 11:25 ` john
2017-06-08 2:18 ` [RFC PATCH 2/4] ui-blame: create placeholder and links whydoubt
2017-07-22 11:31 ` john
2017-06-08 2:18 ` [RFC PATCH 3/4] ui-blame: create needed html_ntxt_noellipsis function whydoubt
2017-07-22 11:36 ` john
2017-06-08 2:18 ` [RFC PATCH 4/4] ui-blame: fill in the contents whydoubt
2017-07-05 8:32 ` list
2017-07-22 11:47 ` john
2017-06-08 9:00 ` [RFC PATCH 0/4] Add ui-blame list
2017-07-22 12:02 ` john
2017-08-05 0:23 ` dlcampbell
2017-08-05 0:57 ` whydoubt
2017-08-24 18:14 ` list
2017-08-31 13:05 ` whydoubt
2017-09-23 3:38 ` [RFCv2 PATCH 0/7] " whydoubt
2017-09-23 3:38 ` [RFCv2 PATCH 1/7] ui-blame: create enable-blame config item whydoubt
2017-09-23 15:46 ` john
2017-09-24 3:12 ` whydoubt
2017-09-23 3:38 ` [RFCv2 PATCH 2/7] ui-blame: create framework whydoubt
2017-09-23 15:47 ` john
2017-09-24 3:24 ` whydoubt
2017-09-23 3:38 ` [RFCv2 PATCH 3/7] ui-blame: create links whydoubt
2017-09-23 15:47 ` john
2017-09-24 20:25 ` whydoubt
2017-09-23 3:38 ` [RFCv2 PATCH 4/7] ui-blame: html_ntxt with no ellipsis whydoubt
2017-09-23 15:47 ` john
2017-09-23 3:38 ` [RFCv2 PATCH 5/7] ui-blame: pull blame info from libgit whydoubt
2017-09-23 15:47 ` john [this message]
2017-09-24 19:06 ` whydoubt
2017-09-24 20:09 ` whydoubt
2017-09-24 20:52 ` john
2017-09-23 3:38 ` [RFCv2 PATCH 6/7] ui-blame: begin building whydoubt
2017-09-23 3:38 ` [RFCv2 PATCH 7/7] ui-blame: generate blame page when requested whydoubt
2017-09-23 15:53 ` [RFCv2 PATCH 0/7] Add ui-blame john
2017-09-24 3:05 ` whydoubt
2017-09-27 22:43 ` [PATCH 0/5] " whydoubt
2017-09-27 22:43 ` [PATCH 1/5] html: html_ntxt with no ellipsis whydoubt
2017-09-30 11:55 ` john
2017-09-27 22:43 ` [PATCH 2/5] ui-tree: move set_title_from_path to ui-shared whydoubt
2017-09-30 11:56 ` john
2017-09-27 22:43 ` [PATCH 3/5] ui-shared: make a char* parameter const whydoubt
2017-09-30 12:00 ` john
2017-09-27 22:43 ` [PATCH 4/5] ui-blame: add blame UI whydoubt
2017-09-30 12:07 ` john
2017-09-27 22:43 ` [PATCH 5/5] ui-tree: link to blame UI if enabled whydoubt
2017-09-30 12:08 ` john
2017-09-30 12:10 ` [PATCH 0/5] Add ui-blame john
2017-10-02 1:17 ` Jason
2017-10-02 5:34 ` list
2017-10-02 22:35 ` whydoubt
2017-10-02 23:29 ` list
2017-10-03 18:22 ` john
2017-10-03 18:23 ` Jason
2017-10-03 18:36 ` Jason
2017-10-03 19:06 ` whydoubt
2017-10-02 4:39 ` [PATCHv2 " whydoubt
2017-10-02 4:39 ` [PATCHv2 1/5] html: html_ntxt with no ellipsis whydoubt
2017-10-02 4:39 ` [PATCHv2 2/5] ui-tree: move set_title_from_path to ui-shared whydoubt
2017-10-02 4:39 ` [PATCHv2 3/5] ui-shared: make a char* parameter const whydoubt
2017-10-02 4:39 ` [PATCHv2 4/5] ui-blame: add blame UI whydoubt
2017-10-02 4:39 ` [PATCHv2 5/5] ui-tree: link to blame UI if enabled whydoubt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170923154758.GE2548@john.keeping.me.uk \
--to=cgit@lists.zx2c4.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).