mobley

C Git HTTP server
Log | Files | Refs | Submodules | README | git clone https://git.ne02ptzero.me/git/mobley

commit 7b9bd1f7b3a1cdf53e72b7c65d07acbed282a170
parent 8b59578f38d2853739578bad5721ac2b49843fce
Author: Louis Solofrizzo <lsolofrizzo@online.net>
Date:   Fri,  5 Apr 2019 18:54:39 +0200

Add: Repository branches

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

Diffstat:
MCMakeLists.txt | 1+
Arepository_branches.c | 80+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Arepository_branches.h | 24++++++++++++++++++++++++
Mrepository_handler.c | 8+++++++-
4 files changed, 112 insertions(+), 1 deletion(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt @@ -58,6 +58,7 @@ add_executable(${MOBLEY_NAME} main.c file.c repository_log.c diff.c + repository_branches.c ./contrib/sundown/src/autolink.c ./contrib/sundown/src/buffer.c ./contrib/sundown/src/markdown.c diff --git a/repository_branches.c b/repository_branches.c @@ -0,0 +1,80 @@ +/** + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. +*/ + +#include <html.h> +#include <repository_branches.h> + +bool repository_route_branches_handler(mobley_t *ctx, server_req_t *r) +{ + git_branch_iterator *it; + git_reference *ref; + git_branch_t type; + git_commit *commit; + git_time_t time; + const git_oid *oid; + const char *name; + + if (git_branch_iterator_new(&it, r->repo->repo, GIT_BRANCH_ALL) != 0) + return false; + + html_open("table") { + html_open("thead") { + html_open("tr") { + html("td", "Name"); + html("td", "Last commit"); + html("td", "Author"); + html("td", "Date"); + } html_close("tr"); + } html_close("thead"); + + html_open("tbody") { + while (true) + { + if (git_branch_next(&ref, &type, it) == GIT_ITEROVER) + break ; + + html_open("tr") { + git_branch_name(&name, ref); + commit = repository_get_last_commit(r->repo, name); + oid = git_commit_id(commit); + + html_open("td") { + html("a", name, .href = __format("tree?branch=%s", name)); + } html_close("td"); + + html_open("td", .width = "70%") { + html_open("a", .href = __format("log/%s", git_oid_tostr_s(oid))) { + string_raw_format_html(ctx, r, git_commit_summary(commit), 150); + } html_close("a"); + } html_close("td"); + + html("td", git_commit_author(commit)->name); + + html_open("td") { + time = git_commit_time(commit); + html_git_date_ftime(&time, "%d/%m/%Y %H:%M"); + } html_close("td"); + + } html_close("tr"); + + git_reference_free(ref); + } + + git_branch_iterator_free(it); + } html_close("tbody"); + } html_close("table"); + + return true; +} diff --git a/repository_branches.h b/repository_branches.h @@ -0,0 +1,24 @@ +/** + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. +*/ + +#ifndef REPOSITORY_BRANCHES_H +# define REPOSITORY_BRANCHES_H + +# include <mobley.h> +# include <stdbool.h> + +bool repository_route_branches_handler(mobley_t *ctx, server_req_t *r); + +#endif /* REPOSITORY_BRANCHES_H */ diff --git a/repository_handler.c b/repository_handler.c @@ -15,6 +15,7 @@ #include <repository_handler.h> #include <repository_log.h> +#include <repository_branches.h> #include <html.h> #include <file_format.h> #include <file.h> @@ -330,11 +331,16 @@ bool repository_route_handler(mobley_t *ctx, server_req_t *r) if (!repository_route_tree_handler(ctx, r)) goto fail; } - if (strcmp(first->val, "log") == 0) + else if (strcmp(first->val, "log") == 0) { if (!repository_route_log_handler(ctx, r)) goto fail; } + else if (strcmp(first->val, "branches") == 0) + { + if (!repository_route_branches_handler(ctx, r)) + goto fail; + } } return true;