aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Smith2017-10-17 23:17:33 -0500
committerJason A. Donenfeld2018-01-19 11:40:52 +0100
commit2b95c9d49c8581e2b19efca1613ada292f56bf08 (patch)
tree70fc81a35ac6ef886b2af6c44bc74818c276b3ff
parent6b5b655f6d2449fe33d8f48f6e98d5e421bf3ff9 (diff)
downloadcgit-2b95c9d49c8581e2b19efca1613ada292f56bf08.tar.gz
cgit-2b95c9d49c8581e2b19efca1613ada292f56bf08.tar.bz2
cgit-2b95c9d49c8581e2b19efca1613ada292f56bf08.zip
ui-blame: Break out emit_blame_entry into component methods
Signed-off-by: Jeff Smith <whydoubt@gmail.com> Reviewed-by: John Keeping <john@keeping.me.uk>
-rw-r--r--ui-blame.c44
1 files changed, 30 insertions, 14 deletions
diff --git a/ui-blame.c b/ui-blame.c
index 62647a8..bbaad1c 100644
--- a/ui-blame.c
+++ b/ui-blame.c
@@ -41,36 +41,52 @@ static char *emit_suspect_detail(struct blame_origin *suspect)
41 return strbuf_detach(&detail, NULL); 41 return strbuf_detach(&detail, NULL);
42} 42}
43 43
44static void emit_blame_entry(struct blame_scoreboard *sb, 44static void emit_blame_entry_hash(struct blame_entry *ent)
45 struct blame_entry *ent)
46{ 45{
47 struct blame_origin *suspect = ent->suspect; 46 struct blame_origin *suspect = ent->suspect;
48 struct object_id *oid = &suspect->commit->object.oid; 47 struct object_id *oid = &suspect->commit->object.oid;
48
49 char *detail = emit_suspect_detail(suspect);
50 cgit_commit_link(find_unique_abbrev(oid->hash, DEFAULT_ABBREV), detail,
51 NULL, ctx.qry.head, oid_to_hex(oid), suspect->path);
52 free(detail);
53}
54
55static void emit_blame_entry_linenumber(struct blame_entry *ent)
56{
49 const char *numberfmt = "<a id='n%1$d' href='#n%1$d'>%1$d</a>\n"; 57 const char *numberfmt = "<a id='n%1$d' href='#n%1$d'>%1$d</a>\n";
58
59 unsigned long lineno = ent->lno;
60 while (lineno < ent->lno + ent->num_lines)
61 htmlf(numberfmt, ++lineno);
62}
63
64static void emit_blame_entry_line(struct blame_scoreboard *sb,
65 struct blame_entry *ent)
66{
50 const char *cp, *cpend; 67 const char *cp, *cpend;
51 68
52 char *detail = emit_suspect_detail(suspect); 69 cp = blame_nth_line(sb, ent->lno);
70 cpend = blame_nth_line(sb, ent->lno + ent->num_lines);
71
72 html_ntxt(cp, cpend - cp);
73}
53 74
75static void emit_blame_entry(struct blame_scoreboard *sb,
76 struct blame_entry *ent)
77{
54 html("<tr><td class='sha1 hashes'>"); 78 html("<tr><td class='sha1 hashes'>");
55 cgit_commit_link(find_unique_abbrev(oid->hash, DEFAULT_ABBREV), detail, 79 emit_blame_entry_hash(ent);
56 NULL, ctx.qry.head, oid_to_hex(oid), suspect->path);
57 html("</td>\n"); 80 html("</td>\n");
58 81
59 free(detail);
60
61 if (ctx.cfg.enable_tree_linenumbers) { 82 if (ctx.cfg.enable_tree_linenumbers) {
62 unsigned long lineno = ent->lno;
63 html("<td class='linenumbers'><pre>"); 83 html("<td class='linenumbers'><pre>");
64 while (lineno < ent->lno + ent->num_lines) 84 emit_blame_entry_linenumber(ent);
65 htmlf(numberfmt, ++lineno);
66 html("</pre></td>\n"); 85 html("</pre></td>\n");
67 } 86 }
68 87
69 cp = blame_nth_line(sb, ent->lno);
70 cpend = blame_nth_line(sb, ent->lno + ent->num_lines);
71
72 html("<td class='lines'><pre><code>"); 88 html("<td class='lines'><pre><code>");
73 html_ntxt(cp, cpend - cp); 89 emit_blame_entry_line(sb, ent);
74 html("</code></pre></td></tr>\n"); 90 html("</code></pre></td></tr>\n");
75} 91}
76 92