diff options
author | Cameron Katri <me@cameronkatri.com> | 2021-06-14 19:38:46 -0400 |
---|---|---|
committer | Cameron Katri <me@cameronkatri.com> | 2021-06-15 11:45:44 -0400 |
commit | 09631f5ed55f51b686814a31340c2fa80ac48b3d (patch) | |
tree | ceabc9840c327a95b90c74b8239ab2e8cf2df84f /cmd.c | |
parent | 5258c297ba6fb604ae1415fbc19a3fe42457e49e (diff) | |
download | cgit-ck/license.tar.gz cgit-ck/license.tar.zst cgit-ck/license.zip |
Add a license tabck/license
This tab is nearly identical to the about tab, use the license field in
cgitrc to set a list of files to check for or use repo.license or
cgit.license as a git-config key.
Diffstat (limited to 'cmd.c')
-rw-r--r-- | cmd.c | 27 |
1 files changed, 26 insertions, 1 deletions
@@ -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_info_file(ctx.repo->readme, ctx.qry.path); else if (ctx.repo->homepage) cgit_redirect(ctx.repo->homepage, false); else { @@ -97,6 +97,30 @@ static void info_fn(void) cgit_clone_info(); } +static void license_fn(void) +{ + if (ctx.repo) { + size_t path_info_len = ctx.env.path_info ? strlen(ctx.env.path_info) : 0; + if (!ctx.qry.path && + ctx.qry.url[strlen(ctx.qry.url) - 1] != '/' && + (!path_info_len || ctx.env.path_info[path_info_len - 1] != '/')) { + char *currenturl = cgit_currenturl(); + char *redirect = fmtalloc("%s/", currenturl); + cgit_redirect(redirect, true); + free(currenturl); + free(redirect); + } else if (ctx.repo->license.nr) + cgit_print_repo_info_file(ctx.repo->license, ctx.qry.path); + else { + char *currenturl = cgit_currenturl(); + char *redirect = fmtalloc("%s../", currenturl); + cgit_redirect(redirect, false); + free(currenturl); + free(redirect); + } + } +} + static void log_fn(void) { cgit_print_log(ctx.qry.oid, ctx.qry.ofs, ctx.cfg.max_commit_count, @@ -178,6 +202,7 @@ struct cgit_cmd *cgit_get_cmd(void) def_cmd(commit, 1, 1, 0), def_cmd(diff, 1, 1, 0), def_cmd(info, 1, 0, 1), + def_cmd(license, 1, 1, 0), def_cmd(log, 1, 1, 0), def_cmd(ls_cache, 0, 0, 0), def_cmd(objects, 1, 0, 1), |