neocgit

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

commit 6967dae190732352d8a0df2ac74177abe21bbdf6
parent a78ce3a598bc78649dce2dcf6095c20949c5ae87
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Fri, 29 Jun 2018 09:15:12 +0200

NEW: Work on links and summary page

Signed-off-by: Ne02ptzero <louis@ne02ptzero.me>

Diffstat:
Mcgit.css | 14++++++++++++--
Mcmd.c | 4++--
Mfilters/email-gravatar.py | 2+-
Mhtml.h | 5+++++
Mui-commit.c | 4++++
Mui-log.c | 26++++++++++----------------
Mui-shared.c | 57++++++++++++++++++++++++++++-----------------------------
Mui-summary.c | 28+++++++++++-----------------
Mui-summary.h | 2+-
Mui-tree.c | 24++++++++++++++++++------
Mui-tree.h | 2+-
11 files changed, 93 insertions(+), 75 deletions(-)

diff --git a/cgit.css b/cgit.css @@ -3,6 +3,7 @@ html, body { height: 100%; padding: 0; margin: 0; + overflow-x: hidden; } div#cgit { @@ -321,7 +322,6 @@ div#cgit table { .last-commit ul { display: inline-block; - /*border: 1px solid green;*/ width: 100%; padding: 0; margin: 0; @@ -330,13 +330,13 @@ div#cgit table { .last-commit ul li { display: inline-block; vertical-align: middle; - /*border: 1px solid red;*/ margin: 0; padding: 0; } .last-commit .avatar { width: 6%; + max-width: 40px; } .last-commit .avatar img { @@ -365,6 +365,7 @@ div#cgit table { .last-commit .hash { width: calc(10% - 8px); + float: right; } .last-commit .hash input { @@ -374,6 +375,15 @@ div#cgit table { padding: 5px 5px; border-radius: 3px; margin-left: -10px; + margin-top: 5px; +} + +.repository-tree { + padding: 10px 15px; +} + +.repo-tree { + border: 1px solid black; } div#cgit table.tabs { diff --git a/cmd.c b/cmd.c @@ -50,7 +50,7 @@ static void about_fn(void) free(currenturl); free(redirect); } else if (ctx.repo->readme.nr) - cgit_print_repo_readme(ctx.qry.path); + cgit_print_repo_readme(ctx.qry.path, true); else if (ctx.repo->homepage) cgit_redirect(ctx.repo->homepage, false); else { @@ -161,7 +161,7 @@ static void tag_fn(void) static void tree_fn(void) { - cgit_print_tree(ctx.qry.sha1, ctx.qry.path); + cgit_print_tree(ctx.qry.sha1, ctx.qry.path, true); } #define def_cmd(name, want_repo, want_vpath, is_clone) \ diff --git a/filters/email-gravatar.py b/filters/email-gravatar.py @@ -36,4 +36,4 @@ sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach()) md5 = hashlib.md5(email.encode()).hexdigest() text = sys.stdin.read().strip() -print("<img src='//www.gravatar.com/avatar/" + md5 + "?s=13&amp;d=retro' width='13' height='13' alt='Gravatar' /> " + text) +print("<img src='//www.gravatar.com/avatar/" + md5 + "?s=100&amp;d=retro' width='13' height='13' alt='Gravatar' /> ") diff --git a/html.h b/html.h @@ -3,6 +3,11 @@ #include "cgit.h" +#define URL(...) "/%s/" __VA_ARGS__ "?h=%s" +#define BRANCH ctx.qry.head +#define LINK ctx.repo->name, BRANCH +#define HTML_LINK(s, ...) htmlf(s, LINK, ##__VA_ARGS__) + extern void html_raw(const char *txt, size_t size); #define _html(txt) html(txt "\n"); extern void html(const char *txt); diff --git a/ui-commit.c b/ui-commit.c @@ -54,6 +54,8 @@ void cgit_print_commit(char *hex, const char *prefix) html_txt(info->author_email); } cgit_close_filter(ctx.repo->email_filter); + htmlf("%s ", info->author); + html_txt(info->author_email); html("</td><td class='right'>"); html_txt(show_date(info->author_date, info->author_tz, cgit_date_mode(DATE_ISO8601))); @@ -66,6 +68,8 @@ void cgit_print_commit(char *hex, const char *prefix) html_txt(info->committer_email); } cgit_close_filter(ctx.repo->email_filter); + htmlf("%s ", info->author); + html_txt(info->author_email); html("</td><td class='right'>"); html_txt(show_date(info->committer_date, info->committer_tz, cgit_date_mode(DATE_ISO8601))); diff --git a/ui-log.c b/ui-log.c @@ -241,9 +241,13 @@ static void print_commit(struct commit *commit, struct rev_info *revs) oid_to_hex(&commit->object.oid), ctx.qry.vpath); show_commit_decorations(commit); html("</td><td>"); + + char *tmp = strdup(info->author); cgit_open_filter(ctx.repo->email_filter, info->author_email, "log"); - html_txt(info->author); + html_txt(info->author); cgit_close_filter(ctx.repo->email_filter); + html_txt(tmp); + free(tmp); if (revs->graph) { html("</td><td>"); @@ -345,33 +349,23 @@ int cgit_count_commits(void) struct commit *commit; struct argv_array rev_argv = ARGV_ARRAY_INIT; int ret = 0; - char *tip; - int must_free_tip; + const char *tip; + int must_free_tip = 0; argv_array_push(&rev_argv, "log_rev_setup"); init_revisions(&rev, NULL); tip = disambiguate_ref(ctx.qry.head, &must_free_tip); argv_array_push(&rev_argv, tip); - rev.abbrev = default_abbrev; - rev.verbose_header = 1; - rev.show_root_diff = 0; - rev.ignore_missing = 1; - rev.simplify_history = 1; setup_revisions(rev_argv.argc, rev_argv.argv, &rev, NULL); - rev.show_decorations = 1; - rev.grep_filter.ignore_case = 1; - rev.diffopt.detect_rename = 1; - rev.diffopt.rename_limit = ctx.cfg.renamelimit; - compile_grep_patterns(&rev.grep_filter); prepare_revision_walk(&rev); - for (ret = 0; commit = get_revision(&rev) != NULL; ret) - ret++; + for (ret = 0; (commit = get_revision(&rev)) != NULL; ret++) + ; if (must_free_tip) - free(tip); + free((char *)tip); return ret; } diff --git a/ui-shared.c b/ui-shared.c @@ -957,11 +957,6 @@ static void print_header(void) html("Contribute"); html("</li>"); - if (ctx.repo != NULL) - { - // XXX: repo - } - char *current_url = cgit_currenturl(); html("<li class='search'>"); html("<form method='get' action='"); @@ -975,23 +970,23 @@ static void print_header(void) html("</div>"); /* html("<td class='main'>");*/ - /*if (ctx.repo) {*/ - /*cgit_index_link("index", NULL, NULL, NULL, NULL, 0, 1);*/ - /*html(" : ");*/ - /*cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL);*/ - /*if (ctx.env.authenticated) {*/ - /*html("</td><td class='form'>");*/ - /*html("<form method='get'>\n");*/ - /*cgit_add_hidden_formfields(0, 1, ctx.qry.page);*/ - /*html("<select name='h' onchange='this.form.submit();'>\n");*/ - /*for_each_branch_ref(print_branch_option, ctx.qry.head);*/ - /*if (ctx.repo->enable_remote_branches)*/ - /*for_each_remote_ref(print_branch_option, ctx.qry.head);*/ - /*html("</select> ");*/ - /*html("<input type='submit' value='switch'/>");*/ - /*html("</form>");*/ - /*}*/ - /*} else*/ +/* if (ctx.repo) {*/ + /*cgit_index_link("index", NULL, NULL, NULL, NULL, 0, 1);*/ + /*html(" : ");*/ + /*cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL);*/ + /*if (ctx.env.authenticated) {*/ + /*html("</td><td class='form'>");*/ + /*html("<form method='get'>\n");*/ + /*cgit_add_hidden_formfields(0, 1, ctx.qry.page);*/ + /*html("<select name='h' onchange='this.form.submit();'>\n");*/ + /*for_each_branch_ref(print_branch_option, ctx.qry.head);*/ + /*if (ctx.repo->enable_remote_branches)*/ + /*for_each_remote_ref(print_branch_option, ctx.qry.head);*/ + /*html("</select> ");*/ + /*html("<input type='submit' value='switch'/>");*/ + /*html("</form>");*/ + /*}*/ + /*}*/ /*html_txt(ctx.cfg.root_title);*/ /*html("</td></tr>\n");*/ @@ -1033,17 +1028,18 @@ void cgit_print_pageheader(void) html("<br />"); htmlf("<h3>%s</h3>", ctx.repo->name); htmlf("<span>%s</span>", ctx.repo->desc); - htmlf("<h5>%s</h5>", ctx.repo->owner); + htmlf("<h5>%s</h5>", ctx.repo->owner == NULL ? "" : ctx.repo->owner); cgit_add_clone_urls(print_url); } _html("</div>"); _html("<div class='summary-menu'>") { _html("<ul>") { - htmlf("<li><a href='#'>Commits (%d)</a></li>", cgit_count_commits()); - htmlf("<li><a href='#'>Branches (%d)</a></li>", cgit_count_branches()); + HTML_LINK("<li><a href='" URL() "'>Summary</a></li>"); + HTML_LINK("<li><a href='" URL("log") "'>Commits (%d)</a></li>", cgit_count_commits()); + HTML_LINK("<li><a href='" URL("refs") "'>Branches (%d)</a></li>", cgit_count_branches()); htmlf("<li><a href='#'>Tags (%d)</a></li>", cgit_count_tags()); html("<li><a href='#'>Readme</a></li>"); - html("<li><a href='#'>Diff</a></li>"); + HTML_LINK("<li><a href='" URL("diff") "'>Diff</a></li>"); } _html("</ul>"); } _html("</div>"); @@ -1054,7 +1050,7 @@ void cgit_print_pageheader(void) cgit_add_hidden_formfields(0, 1, ctx.qry.page); html("<select name='h' onchange='this.form.submit();'>\n"); for_each_branch_ref(print_branch_option, ctx.qry.head); - html("</select>"); + html("</select> "); } html("</form>"); } _html("</li>"); @@ -1063,7 +1059,7 @@ void cgit_print_pageheader(void) } _html("</li>"); _html("<li class='history'>") { - html("<a href='#'>History</a>"); + htmlf("<a href='/%s/log'>History</a>", ctx.repo->name); } _html("</li>"); } _html("</ul>"); } _html("</div>"); @@ -1081,7 +1077,9 @@ void cgit_print_pageheader(void) _html("<ul>") { _html("<li class='avatar'>") { - htmlf("<img src='%s' />", ctx.cfg.logo); + cgit_open_filter(ctx.repo->email_filter, info->committer_email, "commit"); + html_txt(info->committer); + cgit_close_filter(ctx.repo->email_filter); } _html("</li>"); _html("<li class='commit-info'><ul>") { @@ -1100,6 +1098,7 @@ void cgit_print_pageheader(void) } _html("</ul>"); } _html("</div>"); } _html("</div>"); + /* if (ctx.repo->readme.nr)*/ /*reporevlink("about", "about", NULL,*/ /*hc("about"), ctx.qry.head, NULL,*/ diff --git a/ui-summary.c b/ui-summary.c @@ -49,19 +49,11 @@ void cgit_print_summary(void) if (ctx.repo->enable_log_linecount) columns++; - cgit_print_layout_start(); - html("<table summary='repository info' class='list nowrap'>"); - cgit_print_branches(ctx.cfg.summary_branches); - htmlf("<tr class='nohover'><td colspan='%d'>&nbsp;</td></tr>", columns); - cgit_print_tags(ctx.cfg.summary_tags); - if (ctx.cfg.summary_log > 0) { - htmlf("<tr class='nohover'><td colspan='%d'>&nbsp;</td></tr>", columns); - cgit_print_log(ctx.qry.head, 0, ctx.cfg.summary_log, NULL, - NULL, NULL, 0, 0, 0); - } - urls = 0; - cgit_add_clone_urls(print_url); - html("</table>"); + cgit_print_layout_start(); + + cgit_print_tree(ctx.qry.sha1, ctx.qry.path, false); + cgit_print_repo_readme(ctx.qry.path, false); + cgit_print_layout_end(); } @@ -99,7 +91,7 @@ static char* append_readme_path(const char *filename, const char *ref, const cha return full_path; } -void cgit_print_repo_readme(char *path) +void cgit_print_repo_readme(char *path, bool layout) { char *filename, *ref, *mimetype; int free_filename = 0; @@ -113,8 +105,9 @@ void cgit_print_repo_readme(char *path) return; } free(mimetype); - - cgit_print_layout_start(); + + if (layout) + cgit_print_layout_start(); if (ctx.repo->readme.nr == 0) goto done; @@ -144,5 +137,6 @@ void cgit_print_repo_readme(char *path) free(filename); done: - cgit_print_layout_end(); + if (layout) + cgit_print_layout_end(); } diff --git a/ui-summary.h b/ui-summary.h @@ -2,6 +2,6 @@ #define UI_SUMMARY_H extern void cgit_print_summary(void); -extern void cgit_print_repo_readme(char *path); +extern void cgit_print_repo_readme(char *path, bool layout); #endif /* UI_SUMMARY_H */ diff --git a/ui-tree.c b/ui-tree.c @@ -279,7 +279,7 @@ static void ls_tail(void) cgit_print_layout_end(); } -static void ls_tree(const struct object_id *oid, char *path, struct walk_tree_context *walk_tree_ctx) +static void ls_tree(const struct object_id *oid, char *path, struct walk_tree_context *walk_tree_ctx, bool layout) { struct tree *tree; struct pathspec paths = { @@ -293,9 +293,16 @@ static void ls_tree(const struct object_id *oid, char *path, struct walk_tree_co return; } - ls_head(); - read_tree_recursive(tree, "", 0, 1, &paths, ls_item, walk_tree_ctx); - ls_tail(); + if (layout) + cgit_print_layout_start(); + + html("<div class='repository-tree'><div class='repo-tree'><table>"); + html("<th>Name</th><th>Last commit</th><th>Last update</th>"); + read_tree_recursive(tree, "", 0, 1, &paths, ls_item, walk_tree_ctx); + html("</table></div></div>"); + + if (layout) + cgit_print_layout_end(); } @@ -329,12 +336,17 @@ static int walk_tree(const struct object_id *oid, struct strbuf *base, return 0; } +void cgit_print_tree_no_layout(const char *rev, char *path) +{ + +} + /* * Show a tree or a blob * rev: the commit pointing at the root tree object * path: path to tree or blob */ -void cgit_print_tree(const char *rev, char *path) +void cgit_print_tree(const char *rev, char *path, bool layout) { struct object_id oid; struct commit *commit; @@ -369,7 +381,7 @@ void cgit_print_tree(const char *rev, char *path) walk_tree_ctx.curr_rev = xstrdup(rev); if (path == NULL) { - ls_tree(&commit->maybe_tree->object.oid, NULL, &walk_tree_ctx); + ls_tree(&commit->maybe_tree->object.oid, NULL, &walk_tree_ctx, layout); goto cleanup; } diff --git a/ui-tree.h b/ui-tree.h @@ -1,6 +1,6 @@ #ifndef UI_TREE_H #define UI_TREE_H -extern void cgit_print_tree(const char *rev, char *path); +extern void cgit_print_tree(const char *rev, char *path, bool layout); #endif /* UI_TREE_H */