neocgit

a more 'modern' version of cgit
Log | Files | Refs | Submodules | README | LICENSE | git clone https://git.ne02ptzero.me/git/neocgit

commit 520edc658aa125fb87c27f675b8a75ea5e4c1888
parent b0d3feba748338ebe3fe82a86361be7c85530660
Author: Louis Solofrizzo <lsolofrizzo@online.net>
Date:   Mon,  1 Oct 2018 16:56:14 +0200

Fix: Commit log UI

The UI for last commit and commit log is now properly fixed, and should
work on all screen resolutions. I've also fixed a bug with the commit
message not properly formatted for HTML.

Signed-off-by: Louis Solofrizzo <lsolofrizzo@online.net>

Diffstat:
Mcgit.css | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------
Mui-log.c | 46++++++++++++++++++++++++++++++++++------------
Mui-shared.c | 6+++---
3 files changed, 93 insertions(+), 33 deletions(-)

diff --git a/cgit.css b/cgit.css @@ -432,7 +432,7 @@ option:not(:checked) { } .commit ul .commit-info { - width: calc(95% - 138px); + width: 85%; padding: 0; margin: 0; } @@ -455,7 +455,11 @@ option:not(:checked) { } .commit .hash { - width: 138px; + border: 1px solid #eee; + border-radius: 3px; + border-radius: 3px; + border-radius: 3px; + width: 9%; } .commit .hash ul { @@ -463,37 +467,71 @@ option:not(:checked) { padding: 0; width: 100%; list-style: none; - display: inline-block; } .commit .hash ul li { - display: inline; + display: inline-block; + margin: 0; + height: 100%; + vertical-align: middle; } -.commit .hash input { - width: calc(100% - 62px); +.commit .hash ul .input { + width: calc(50% - 1px); + overflow: hidden; + border-right: 1px solid #eee; + padding-right: -1px; +} + +.last-commit .hash ul .input { + width: calc(80% - 1px); +} + +.commit .hash ul .input input { background: transparent; - border: 1px solid #eee; padding: 5px 5px; - border-radius: 3px; - border-bottom-right-radius: 0; - border-top-right-radius: 0; font-size: 14px; + border: 0; + width: 100%; } -.commit .copy, .commit-list .hash .tree { +.copy, .commit-list .hash .tree { text-align: center; - border: 1px solid #eee; - border-radius: 3px; - padding: 5px 15px 5px; - border-bottom-left-radius: 0; - border-top-left-radius: 0; color: #7e7c7c !important; transition-duration: 0.3s; transition-property: all; font-size: 14px; - width: 30px; - margin-left: -1px; + width: calc(25% - 1px); + vertical-align: middle; +} + +.commit-list .hash .tree { + width: 25%; +} + +.commit-list .hash .tree a { + color: #7e7c7c !important; + padding-top: 7px; + display: block; +} + +.copy { + border-right: 1px solid #eee; +} + +.copy span { + padding-top: 7px; + display: block !important; +} + +.last-commit .copy { + width: 20%; + border: 0; +} + +.repo-url .copy { + border: 0; + width: 35%; } .commit .copy:hover, .commit-list .hash .tree:hover { diff --git a/ui-log.c b/ui-log.c @@ -171,6 +171,33 @@ static int show_commit(struct commit *commit, struct rev_info *revs) return found; } +typedef struct { + char find; + char *replace; +} html_replace_t; + +static const html_replace_t replacements[] = { + { '&', "&amp;" }, + { '<', "&lt;" }, + { '>', "&gt;" } +}; + +static void format_html_commit_msg(struct strbuf *buf) +{ + for (size_t i = 0; i < buf->len; i++) + { + for (size_t j = 0; j < sizeof(replacements) / sizeof(replacements[0]); j++) + { + if (buf->buf[i] == replacements[j].find) + { + strbuf_splice(buf, i, 1, replacements[j].replace, + strlen(replacements[j].replace)); + break ; + } + } + } +} + static void print_commit(struct commit *commit, struct rev_info *revs) { struct commitinfo *info; @@ -204,14 +231,11 @@ static void print_commit(struct commit *commit, struct rev_info *revs) } if (info->msg && *(info->msg)) - { strbuf_addstr(&msgbuf, info->msg); - strbuf_addch(&msgbuf, '\n'); - } format_display_notes(&commit->object.oid, &msgbuf, PAGE_ENCODING, 0); - strbuf_addch(&msgbuf, '\n'); strbuf_ltrim(&msgbuf); + format_html_commit_msg(&msgbuf); _html("<li class='commit'><ul>") { _html("<li class='avatar'>") { @@ -241,30 +265,28 @@ static void print_commit(struct commit *commit, struct rev_info *revs) } _html("</ul></li>"); _html("<li class='hash'><ul>") { - html("<li>"); { + html("<li class='input'>"); { htmlf("<input type='text' value='%s' readonly id='commit-hash-%s' />", hex, hex); } html("</li>"); - html("<li>"); { - htmlf("<span class='copy' " + html("<li class='copy'>"); { + htmlf("<span " "onclick=\"document.getElementById('commit-hash-%s')" ".select(); document.execCommand('copy')\">" "<i class='fa fa-copy'></i></span>", hex); } html("</li>"); - html("<li>"); { - htmlf("<a href='/%s/tree/?id=%s' class='tree'>" + html("<li class='tree'>"); { + htmlf("<a href='/%s/tree/?id=%s'>" "<i class='fa fa-folder'></i></a>", ctx.repo->name, hex); } html("</li>"); } _html("</ul></li>"); - htmlf("<pre id='commit-msg-%s' style='display: none;'>%s</pre>", hex, msgbuf.buf); + htmlf("<pre id='commit-msg-%s' style='display: none'>%s</pre>", hex, msgbuf.buf); } _html("</ul></li>"); - - strbuf_release(&msgbuf); cgit_free_commitinfo(info); } diff --git a/ui-shared.c b/ui-shared.c @@ -1071,7 +1071,7 @@ void cgit_print_pageheader(void) } _html("</li>"); _html("<li class='history'>") { - htmlf("<a href='/%s/log/%s?h=%s'>History</a>", ctx.repo->name, ctx.qry.path, ctx.qry.head); + htmlf("<a href='/%s/log?h=%s'>History</a>", ctx.repo->name, ctx.qry.head); } _html("</li>"); } _html("</ul>"); } _html("</div>"); @@ -1112,11 +1112,11 @@ void cgit_print_pageheader(void) } html("</ul></li>"); _html("<li class='hash'><ul>") { - html("<li><input type='text' value='"); + html("<li class='input'><input type='text' value='"); html_txt(oid_to_hex(&commit->object.oid)); html("' readonly id='last-commit-value' /></li>"); - html("<li><span class='copy' " + html("<li class='copy'><span " "onclick=\"document.getElementById('last-commit-value')" ".select(); document.execCommand('copy')\">" "<i class='fa fa-copy'></i></span></li>");