05d292b2 (kx 2023-03-24 03:51:10 +0300 1)
05d292b2 (kx 2023-03-24 03:51:10 +0300 2) #ifdef HAVE_CONFIG_H
05d292b2 (kx 2023-03-24 03:51:10 +0300 3) #include <config.h>
05d292b2 (kx 2023-03-24 03:51:10 +0300 4) #endif
05d292b2 (kx 2023-03-24 03:51:10 +0300 5)
05d292b2 (kx 2023-03-24 03:51:10 +0300 6) #include <stdlib.h>
05d292b2 (kx 2023-03-24 03:51:10 +0300 7) #include <stdio.h>
05d292b2 (kx 2023-03-24 03:51:10 +0300 8) #include <sys/sysinfo.h>
05d292b2 (kx 2023-03-24 03:51:10 +0300 9) #include <sys/types.h>
05d292b2 (kx 2023-03-24 03:51:10 +0300 10) #ifdef HAVE_INTTYPES_H
05d292b2 (kx 2023-03-24 03:51:10 +0300 11) #include <inttypes.h>
05d292b2 (kx 2023-03-24 03:51:10 +0300 12) #else
05d292b2 (kx 2023-03-24 03:51:10 +0300 13) #include <stdint.h>
05d292b2 (kx 2023-03-24 03:51:10 +0300 14) #endif
05d292b2 (kx 2023-03-24 03:51:10 +0300 15) #include <stddef.h> /* offsetof(3) */
05d292b2 (kx 2023-03-24 03:51:10 +0300 16) #include <dirent.h>
05d292b2 (kx 2023-03-24 03:51:10 +0300 17) #include <sys/stat.h> /* chmod(2) */
05d292b2 (kx 2023-03-24 03:51:10 +0300 18) #include <sys/file.h>
05d292b2 (kx 2023-03-24 03:51:10 +0300 19) #include <sys/mman.h>
05d292b2 (kx 2023-03-24 03:51:10 +0300 20) #include <fcntl.h>
05d292b2 (kx 2023-03-24 03:51:10 +0300 21) #include <limits.h>
05d292b2 (kx 2023-03-24 03:51:10 +0300 22) #include <string.h> /* strdup(3) */
05d292b2 (kx 2023-03-24 03:51:10 +0300 23) #include <libgen.h> /* basename(3) */
05d292b2 (kx 2023-03-24 03:51:10 +0300 24) #include <ctype.h> /* tolower(3) */
05d292b2 (kx 2023-03-24 03:51:10 +0300 25) #include <errno.h>
05d292b2 (kx 2023-03-24 03:51:10 +0300 26) #include <time.h>
05d292b2 (kx 2023-03-24 03:51:10 +0300 27) #include <sys/time.h>
05d292b2 (kx 2023-03-24 03:51:10 +0300 28) #include <pwd.h>
05d292b2 (kx 2023-03-24 03:51:10 +0300 29) #include <grp.h>
05d292b2 (kx 2023-03-24 03:51:10 +0300 30) #include <stdarg.h>
05d292b2 (kx 2023-03-24 03:51:10 +0300 31) #include <locale.h>
05d292b2 (kx 2023-03-24 03:51:10 +0300 32) #include <unistd.h>
05d292b2 (kx 2023-03-24 03:51:10 +0300 33)
05d292b2 (kx 2023-03-24 03:51:10 +0300 34) #include <git2.h>
05d292b2 (kx 2023-03-24 03:51:10 +0300 35)
05d292b2 (kx 2023-03-24 03:51:10 +0300 36) #include <nls.h>
05d292b2 (kx 2023-03-24 03:51:10 +0300 37)
05d292b2 (kx 2023-03-24 03:51:10 +0300 38) #include <defs.h>
05d292b2 (kx 2023-03-24 03:51:10 +0300 39)
05d292b2 (kx 2023-03-24 03:51:10 +0300 40) #include <fatal.h>
05d292b2 (kx 2023-03-24 03:51:10 +0300 41) #include <http.h>
05d292b2 (kx 2023-03-24 03:51:10 +0300 42) #include <html.h>
05d292b2 (kx 2023-03-24 03:51:10 +0300 43)
05d292b2 (kx 2023-03-24 03:51:10 +0300 44) #include <dlist.h>
05d292b2 (kx 2023-03-24 03:51:10 +0300 45) #include <strbuf.h>
05d292b2 (kx 2023-03-24 03:51:10 +0300 46) #include <repolist.h>
05d292b2 (kx 2023-03-24 03:51:10 +0300 47) #include <wrapper.h>
05d292b2 (kx 2023-03-24 03:51:10 +0300 48) #include <system.h>
05d292b2 (kx 2023-03-24 03:51:10 +0300 49) #include <date.h>
05d292b2 (kx 2023-03-24 03:51:10 +0300 50)
05d292b2 (kx 2023-03-24 03:51:10 +0300 51) #include <ctx.h>
05d292b2 (kx 2023-03-24 03:51:10 +0300 52) #include <git-shared.h>
05d292b2 (kx 2023-03-24 03:51:10 +0300 53) #include <ui-shared.h>
05d292b2 (kx 2023-03-24 03:51:10 +0300 54) #include <ui-repolist.h>
05d292b2 (kx 2023-03-24 03:51:10 +0300 55)
05d292b2 (kx 2023-03-24 03:51:10 +0300 56)
05d292b2 (kx 2023-03-24 03:51:10 +0300 57) void cgit_print_direction( struct strbuf *sb, int prev, int next )
05d292b2 (kx 2023-03-24 03:51:10 +0300 58) {
05d292b2 (kx 2023-03-24 03:51:10 +0300 59) strbuf_addf( sb, " <div class=\"direction\">\n" );
05d292b2 (kx 2023-03-24 03:51:10 +0300 60) strbuf_addf( sb, " <div class=\"row\">\n" );
05d292b2 (kx 2023-03-24 03:51:10 +0300 61) strbuf_addf( sb, " <div class=\"left col-prev\">\n" );
05d292b2 (kx 2023-03-24 03:51:10 +0300 62) strbuf_addf( sb, " <div class=\"prev-direction\">\n" );
05d292b2 (kx 2023-03-24 03:51:10 +0300 63)
05d292b2 (kx 2023-03-24 03:51:10 +0300 64) if( prev )
05d292b2 (kx 2023-03-24 03:51:10 +0300 65) {
05d292b2 (kx 2023-03-24 03:51:10 +0300 66) if( ctx.env.query_string && *ctx.env.query_string )
05d292b2 (kx 2023-03-24 03:51:10 +0300 67) strbuf_addf( sb, " <a href=\"%s?ofs=%d&%s\">≪ Prev</a>\n", ctx.repo.relative_href, prev, ctx.env.query_string );
05d292b2 (kx 2023-03-24 03:51:10 +0300 68) else
05d292b2 (kx 2023-03-24 03:51:10 +0300 69) strbuf_addf( sb, " <a href=\"%s?ofs=%d\">≪ Prev</a>\n", ctx.repo.relative_href, prev );
05d292b2 (kx 2023-03-24 03:51:10 +0300 70) }
05d292b2 (kx 2023-03-24 03:51:10 +0300 71) else
05d292b2 (kx 2023-03-24 03:51:10 +0300 72) {
05d292b2 (kx 2023-03-24 03:51:10 +0300 73) if( ctx.env.query_string && *ctx.env.query_string )
05d292b2 (kx 2023-03-24 03:51:10 +0300 74) strbuf_addf( sb, " <a href=\"%s?%s\">≪ Prev</a>\n", ctx.repo.relative_href, ctx.env.query_string );
05d292b2 (kx 2023-03-24 03:51:10 +0300 75) else
05d292b2 (kx 2023-03-24 03:51:10 +0300 76) strbuf_addf( sb, " <a href=\"%s\">≪ Prev</a>\n", ctx.repo.relative_href );
05d292b2 (kx 2023-03-24 03:51:10 +0300 77) }
05d292b2 (kx 2023-03-24 03:51:10 +0300 78)
05d292b2 (kx 2023-03-24 03:51:10 +0300 79) strbuf_addf( sb, " </div>\n" );
05d292b2 (kx 2023-03-24 03:51:10 +0300 80) strbuf_addf( sb, " </div>\n" );
05d292b2 (kx 2023-03-24 03:51:10 +0300 81) strbuf_addf( sb, " <div class=\"right col-next\">\n" );
05d292b2 (kx 2023-03-24 03:51:10 +0300 82) strbuf_addf( sb, " <div class=\"next-direction\">\n" );
05d292b2 (kx 2023-03-24 03:51:10 +0300 83)
05d292b2 (kx 2023-03-24 03:51:10 +0300 84) if( next )
05d292b2 (kx 2023-03-24 03:51:10 +0300 85) {
05d292b2 (kx 2023-03-24 03:51:10 +0300 86) if( ctx.env.query_string && *ctx.env.query_string )
05d292b2 (kx 2023-03-24 03:51:10 +0300 87) strbuf_addf( sb, " <a href=\"%s?ofs=%d&%s\">Next ≫</a>\n", ctx.repo.relative_href, next, ctx.env.query_string );
05d292b2 (kx 2023-03-24 03:51:10 +0300 88) else
05d292b2 (kx 2023-03-24 03:51:10 +0300 89) strbuf_addf( sb, " <a href=\"%s?ofs=%d\">Next ≫</a>\n", ctx.repo.relative_href, next );
05d292b2 (kx 2023-03-24 03:51:10 +0300 90) }
05d292b2 (kx 2023-03-24 03:51:10 +0300 91) else
05d292b2 (kx 2023-03-24 03:51:10 +0300 92) {
05d292b2 (kx 2023-03-24 03:51:10 +0300 93) if( ctx.env.query_string && *ctx.env.query_string )
05d292b2 (kx 2023-03-24 03:51:10 +0300 94) strbuf_addf( sb, " <a href=\"%s?%s\">Next ≫</a>\n", ctx.repo.relative_href, ctx.env.query_string );
05d292b2 (kx 2023-03-24 03:51:10 +0300 95) else
05d292b2 (kx 2023-03-24 03:51:10 +0300 96) strbuf_addf( sb, " <a href=\"%s\">Next ≫</a>\n", ctx.repo.relative_href );
05d292b2 (kx 2023-03-24 03:51:10 +0300 97) }
05d292b2 (kx 2023-03-24 03:51:10 +0300 98)
05d292b2 (kx 2023-03-24 03:51:10 +0300 99) strbuf_addf( sb, " </div>\n" );
05d292b2 (kx 2023-03-24 03:51:10 +0300 100) strbuf_addf( sb, " </div>\n" );
05d292b2 (kx 2023-03-24 03:51:10 +0300 101) strbuf_addf( sb, " </div>\n" );
05d292b2 (kx 2023-03-24 03:51:10 +0300 102) strbuf_addf( sb, " </div>\n" );
05d292b2 (kx 2023-03-24 03:51:10 +0300 103) }
05d292b2 (kx 2023-03-24 03:51:10 +0300 104)
05d292b2 (kx 2023-03-24 03:51:10 +0300 105) void cgit_print_repolist_header( struct strbuf *sb )
05d292b2 (kx 2023-03-24 03:51:10 +0300 106) {
05d292b2 (kx 2023-03-24 03:51:10 +0300 107) strbuf_addf( sb, " <div class=\"repo-list-header\">\n" );
05d292b2 (kx 2023-03-24 03:51:10 +0300 108) strbuf_addf( sb, " <div class=\"row\">\n" );
05d292b2 (kx 2023-03-24 03:51:10 +0300 109) strbuf_addf( sb, " <div class=\"col-name\">Name</div>\n" );
05d292b2 (kx 2023-03-24 03:51:10 +0300 110) strbuf_addf( sb, " <div class=\"col-desc\">Description</div>\n" );
05d292b2 (kx 2023-03-24 03:51:10 +0300 111) strbuf_addf( sb, " <div class=\"col-owner\"><div class=\"repo-owner trunc\">Owner</div></div>\n" );
05d292b2 (kx 2023-03-24 03:51:10 +0300 112) strbuf_addf( sb, " <div class=\"col-rev\"><div class=\"repo-rev trunc\">Rev</div></div>\n" );
05d292b2 (kx 2023-03-24 03:51:10 +0300 113) strbuf_addf( sb, " <div class=\"col-idle\"><div class=\"repo-idle trunc\">Idle</div></div>\n" );
05d292b2 (kx 2023-03-24 03:51:10 +0300 114) strbuf_addf( sb, " </div>\n" );
05d292b2 (kx 2023-03-24 03:51:10 +0300 115) strbuf_addf( sb, " </div>\n" );
05d292b2 (kx 2023-03-24 03:51:10 +0300 116) }
05d292b2 (kx 2023-03-24 03:51:10 +0300 117)
05d292b2 (kx 2023-03-24 03:51:10 +0300 118) void cgit_print_section_start( struct strbuf *sb, const char *name )
05d292b2 (kx 2023-03-24 03:51:10 +0300 119) {
05d292b2 (kx 2023-03-24 03:51:10 +0300 120) if( !sb ) return;
05d292b2 (kx 2023-03-24 03:51:10 +0300 121)
05d292b2 (kx 2023-03-24 03:51:10 +0300 122) strbuf_addf( sb, " <div class=\"section\">\n" );
05d292b2 (kx 2023-03-24 03:51:10 +0300 123) if( name && *name )
05d292b2 (kx 2023-03-24 03:51:10 +0300 124) strbuf_addf( sb, " <div class=\"section-header\">%s</div>\n\n", name );
05d292b2 (kx 2023-03-24 03:51:10 +0300 125) else
05d292b2 (kx 2023-03-24 03:51:10 +0300 126) strbuf_addf( sb, " <div class=\"section-header\"></div>\n\n" );
05d292b2 (kx 2023-03-24 03:51:10 +0300 127) }
05d292b2 (kx 2023-03-24 03:51:10 +0300 128)
05d292b2 (kx 2023-03-24 03:51:10 +0300 129) void cgit_print_section_stop( struct strbuf *sb )
05d292b2 (kx 2023-03-24 03:51:10 +0300 130) {
05d292b2 (kx 2023-03-24 03:51:10 +0300 131) if( !sb ) return;
05d292b2 (kx 2023-03-24 03:51:10 +0300 132) strbuf_addf( sb, " </div> <!-- end of section -->\n\n" );
05d292b2 (kx 2023-03-24 03:51:10 +0300 133) }
05d292b2 (kx 2023-03-24 03:51:10 +0300 134)
05d292b2 (kx 2023-03-24 03:51:10 +0300 135) void cgit_print_repo( struct strbuf *sb, struct repo *repo )
05d292b2 (kx 2023-03-24 03:51:10 +0300 136) {
05d292b2 (kx 2023-03-24 03:51:10 +0300 137) struct variable git_root = { (unsigned char *)"git-root", { 0 }, DT_PATH },
05d292b2 (kx 2023-03-24 03:51:10 +0300 138) repo_root = { (unsigned char *)"repo-root", { 0 }, DT_PATH },
05d292b2 (kx 2023-03-24 03:51:10 +0300 139) owner = { (unsigned char *)"owner", { 0 }, DT_STRING },
05d292b2 (kx 2023-03-24 03:51:10 +0300 140) description = { (unsigned char *)"description", { 0 }, DT_STRING };
05d292b2 (kx 2023-03-24 03:51:10 +0300 141) struct variable *groot = NULL;
05d292b2 (kx 2023-03-24 03:51:10 +0300 142) struct variable *rroot = NULL;
05d292b2 (kx 2023-03-24 03:51:10 +0300 143) struct variable *auth = NULL;
05d292b2 (kx 2023-03-24 03:51:10 +0300 144) struct variable *desc = NULL;
05d292b2 (kx 2023-03-24 03:51:10 +0300 145)
05d292b2 (kx 2023-03-24 03:51:10 +0300 146) struct short_commit_info info = { .rev = { 0 }, .date = -1, .offset = 0 };
05d292b2 (kx 2023-03-24 03:51:10 +0300 147) char path[PATH_MAX] = { 0 };
05d292b2 (kx 2023-03-24 03:51:10 +0300 148)
05d292b2 (kx 2023-03-24 03:51:10 +0300 149) if( !sb || !repo || !repo->path ) return;
05d292b2 (kx 2023-03-24 03:51:10 +0300 150)
05d292b2 (kx 2023-03-24 03:51:10 +0300 151) groot = lookup( repo, &git_root );
05d292b2 (kx 2023-03-24 03:51:10 +0300 152) rroot = lookup( repo, &repo_root );
05d292b2 (kx 2023-03-24 03:51:10 +0300 153) auth = lookup( repo, &owner );
05d292b2 (kx 2023-03-24 03:51:10 +0300 154) desc = lookup( repo, &description );
05d292b2 (kx 2023-03-24 03:51:10 +0300 155)
05d292b2 (kx 2023-03-24 03:51:10 +0300 156) if( rroot )
05d292b2 (kx 2023-03-24 03:51:10 +0300 157) sprintf( path, "%s/%s/%s", (const char *)groot->_v.vptr, (const char *)rroot->_v.vptr, repo->path );
05d292b2 (kx 2023-03-24 03:51:10 +0300 158) else
05d292b2 (kx 2023-03-24 03:51:10 +0300 159) sprintf( path, "%s/%s", (const char *)groot->_v.vptr, repo->path );
05d292b2 (kx 2023-03-24 03:51:10 +0300 160)
05d292b2 (kx 2023-03-24 03:51:10 +0300 161) fill_short_commit_info( &info, (const char *)&path[0] );
05d292b2 (kx 2023-03-24 03:51:10 +0300 162)
05d292b2 (kx 2023-03-24 03:51:10 +0300 163) strbuf_addf( sb, " <div class=\"row\">\n" );
05d292b2 (kx 2023-03-24 03:51:10 +0300 164) if( rroot )
05d292b2 (kx 2023-03-24 03:51:10 +0300 165) strbuf_addf( sb, " <div class=\"col-name\"><a href=\"/%s/%s/\"><div class=\"repo-name\">%s</div></a></div>\n", (const char *)rroot->_v.vptr, repo->path, repo->path );
05d292b2 (kx 2023-03-24 03:51:10 +0300 166) else
05d292b2 (kx 2023-03-24 03:51:10 +0300 167) strbuf_addf( sb, " <div class=\"col-name\"><a href=\"/%s/\"><div class=\"repo-name\">%s</div></a></div>\n", repo->path, repo->path );
05d292b2 (kx 2023-03-24 03:51:10 +0300 168)
05d292b2 (kx 2023-03-24 03:51:10 +0300 169) if( desc )
05d292b2 (kx 2023-03-24 03:51:10 +0300 170) strbuf_addf( sb, " <div class=\"col-desc\"><div onclick=\"trunc(this)\" class=\"repo-desc trunc\">%s</div></div>\n", (const char *)desc->_v.vptr );
05d292b2 (kx 2023-03-24 03:51:10 +0300 171) else
05d292b2 (kx 2023-03-24 03:51:10 +0300 172) strbuf_addf( sb, " <div class=\"col-desc\"><div onclick=\"trunc(this)\" class=\"repo-desc trunc\">none</div></div>\n" );
05d292b2 (kx 2023-03-24 03:51:10 +0300 173)
05d292b2 (kx 2023-03-24 03:51:10 +0300 174) if( auth )
05d292b2 (kx 2023-03-24 03:51:10 +0300 175) strbuf_addf( sb, " <div class=\"col-owner\"><div onclick=\"trunc(this)\" class=\"repo-owner trunc\">%s</div></div>\n", (const char *)auth->_v.vptr );
05d292b2 (kx 2023-03-24 03:51:10 +0300 176) else
05d292b2 (kx 2023-03-24 03:51:10 +0300 177) strbuf_addf( sb, " <div class=\"col-owner\"><div onclick=\"trunc(this)\" class=\"repo-owner trunc\">none</div></div>\n" );
05d292b2 (kx 2023-03-24 03:51:10 +0300 178)
05d292b2 (kx 2023-03-24 03:51:10 +0300 179) if( info.rev[0] )
05d292b2 (kx 2023-03-24 03:51:10 +0300 180) strbuf_addf( sb, " <div class=\"col-rev\"><div onclick=\"trunc(this)\" class=\"repo-rev trunc\"><span class=\"rev-short\" title=\"%s\">%0.8s</span></div></div>\n", (const char *)&info.rev[0], (const char *)&info.rev[0] );
05d292b2 (kx 2023-03-24 03:51:10 +0300 181) else
05d292b2 (kx 2023-03-24 03:51:10 +0300 182) strbuf_addf( sb, " <div class=\"col-rev\"><div onclick=\"trunc(this)\" class=\"repo-rev trunc\">%s</div></div>\n", "0" );
05d292b2 (kx 2023-03-24 03:51:10 +0300 183)
05d292b2 (kx 2023-03-24 03:51:10 +0300 184) if( info.date != -1 )
05d292b2 (kx 2023-03-24 03:51:10 +0300 185) {
05d292b2 (kx 2023-03-24 03:51:10 +0300 186) struct strbuf buf = STRBUF_INIT;
05d292b2 (kx 2023-03-24 03:51:10 +0300 187) cgit_print_age( &buf, (time_t)info.date, info.offset, TM_YEAR );
05d292b2 (kx 2023-03-24 03:51:10 +0300 188) strbuf_addf( sb, " <div class=\"col-idle\"><div onclick=\"trunc(this)\" class=\"repo-idle trunc\">%s</div></div>\n", buf.buf );
05d292b2 (kx 2023-03-24 03:51:10 +0300 189) strbuf_release( &buf );
05d292b2 (kx 2023-03-24 03:51:10 +0300 190) }
05d292b2 (kx 2023-03-24 03:51:10 +0300 191) else
05d292b2 (kx 2023-03-24 03:51:10 +0300 192) strbuf_addf( sb, " <div class=\"col-idle\"><div onclick=\"trunc(this)\" class=\"repo-idle trunc\">%s</div></div>\n", "unknown" );
05d292b2 (kx 2023-03-24 03:51:10 +0300 193)
05d292b2 (kx 2023-03-24 03:51:10 +0300 194) strbuf_addf( sb, " </div>\n\n" );
05d292b2 (kx 2023-03-24 03:51:10 +0300 195) }
05d292b2 (kx 2023-03-24 03:51:10 +0300 196)
05d292b2 (kx 2023-03-24 03:51:10 +0300 197)
05d292b2 (kx 2023-03-24 03:51:10 +0300 198) int cgit_print_page_repolist( struct strbuf *sb, struct dlist *config, int start_no, int n )
05d292b2 (kx 2023-03-24 03:51:10 +0300 199) {
05d292b2 (kx 2023-03-24 03:51:10 +0300 200) struct dlist *list = NULL;
05d292b2 (kx 2023-03-24 03:51:10 +0300 201) int length = 0;
05d292b2 (kx 2023-03-24 03:51:10 +0300 202)
05d292b2 (kx 2023-03-24 03:51:10 +0300 203) if( !config || !sb ) return length;
05d292b2 (kx 2023-03-24 03:51:10 +0300 204)
05d292b2 (kx 2023-03-24 03:51:10 +0300 205) list = config;
05d292b2 (kx 2023-03-24 03:51:10 +0300 206)
05d292b2 (kx 2023-03-24 03:51:10 +0300 207) if( start_no > 0 )
05d292b2 (kx 2023-03-24 03:51:10 +0300 208) {
05d292b2 (kx 2023-03-24 03:51:10 +0300 209) list = parent_section_node_repolist_nth( config, start_no );
05d292b2 (kx 2023-03-24 03:51:10 +0300 210) {
05d292b2 (kx 2023-03-24 03:51:10 +0300 211) struct section *section = (struct section *)list->data;
05d292b2 (kx 2023-03-24 03:51:10 +0300 212) struct dlist *rlist = parent_rlist_node_repolist_nth( config, start_no );
05d292b2 (kx 2023-03-24 03:51:10 +0300 213)
05d292b2 (kx 2023-03-24 03:51:10 +0300 214) cgit_print_section_start( sb, (const char *)section->name );
05d292b2 (kx 2023-03-24 03:51:10 +0300 215)
05d292b2 (kx 2023-03-24 03:51:10 +0300 216) while( rlist )
05d292b2 (kx 2023-03-24 03:51:10 +0300 217) {
05d292b2 (kx 2023-03-24 03:51:10 +0300 218) struct repo *repo = (struct repo *)rlist->data;
05d292b2 (kx 2023-03-24 03:51:10 +0300 219)
05d292b2 (kx 2023-03-24 03:51:10 +0300 220) cgit_print_repo( sb, repo );
05d292b2 (kx 2023-03-24 03:51:10 +0300 221) if( n && ++length == n )
05d292b2 (kx 2023-03-24 03:51:10 +0300 222) {
05d292b2 (kx 2023-03-24 03:51:10 +0300 223) cgit_print_section_stop( sb );
05d292b2 (kx 2023-03-24 03:51:10 +0300 224) return length;
05d292b2 (kx 2023-03-24 03:51:10 +0300 225) }
05d292b2 (kx 2023-03-24 03:51:10 +0300 226)
05d292b2 (kx 2023-03-24 03:51:10 +0300 227) rlist = dlist_next( rlist );
05d292b2 (kx 2023-03-24 03:51:10 +0300 228) }
05d292b2 (kx 2023-03-24 03:51:10 +0300 229) cgit_print_section_stop( sb );
05d292b2 (kx 2023-03-24 03:51:10 +0300 230) }
05d292b2 (kx 2023-03-24 03:51:10 +0300 231) list = dlist_next( list );
05d292b2 (kx 2023-03-24 03:51:10 +0300 232) }
05d292b2 (kx 2023-03-24 03:51:10 +0300 233)
05d292b2 (kx 2023-03-24 03:51:10 +0300 234) while( list )
05d292b2 (kx 2023-03-24 03:51:10 +0300 235) {
05d292b2 (kx 2023-03-24 03:51:10 +0300 236) struct section *section = (struct section *)list->data;
05d292b2 (kx 2023-03-24 03:51:10 +0300 237)
05d292b2 (kx 2023-03-24 03:51:10 +0300 238) if( section->type == ST_REPOS )
05d292b2 (kx 2023-03-24 03:51:10 +0300 239) {
05d292b2 (kx 2023-03-24 03:51:10 +0300 240) cgit_print_section_start( sb, (const char *)section->name );
05d292b2 (kx 2023-03-24 03:51:10 +0300 241)
05d292b2 (kx 2023-03-24 03:51:10 +0300 242) struct dlist *rlist = section->list;
05d292b2 (kx 2023-03-24 03:51:10 +0300 243) while( rlist )
05d292b2 (kx 2023-03-24 03:51:10 +0300 244) {
05d292b2 (kx 2023-03-24 03:51:10 +0300 245) struct repo *repo = (struct repo *)rlist->data;
05d292b2 (kx 2023-03-24 03:51:10 +0300 246)
05d292b2 (kx 2023-03-24 03:51:10 +0300 247) cgit_print_repo( sb, repo );
05d292b2 (kx 2023-03-24 03:51:10 +0300 248) if( n && ++length == n )
05d292b2 (kx 2023-03-24 03:51:10 +0300 249) {
05d292b2 (kx 2023-03-24 03:51:10 +0300 250) cgit_print_section_stop( sb );
05d292b2 (kx 2023-03-24 03:51:10 +0300 251) return length;
05d292b2 (kx 2023-03-24 03:51:10 +0300 252) }
05d292b2 (kx 2023-03-24 03:51:10 +0300 253)
05d292b2 (kx 2023-03-24 03:51:10 +0300 254) rlist = dlist_next( rlist );
05d292b2 (kx 2023-03-24 03:51:10 +0300 255) }
05d292b2 (kx 2023-03-24 03:51:10 +0300 256)
05d292b2 (kx 2023-03-24 03:51:10 +0300 257) cgit_print_section_stop( sb );
05d292b2 (kx 2023-03-24 03:51:10 +0300 258) }
05d292b2 (kx 2023-03-24 03:51:10 +0300 259) list = dlist_next( list );
05d292b2 (kx 2023-03-24 03:51:10 +0300 260) }
05d292b2 (kx 2023-03-24 03:51:10 +0300 261)
05d292b2 (kx 2023-03-24 03:51:10 +0300 262) return length;
05d292b2 (kx 2023-03-24 03:51:10 +0300 263) }
05d292b2 (kx 2023-03-24 03:51:10 +0300 264)
05d292b2 (kx 2023-03-24 03:51:10 +0300 265)
05d292b2 (kx 2023-03-24 03:51:10 +0300 266) void cgit_print_repolist_page( void )
05d292b2 (kx 2023-03-24 03:51:10 +0300 267) {
05d292b2 (kx 2023-03-24 03:51:10 +0300 268) FILE *fp;
05d292b2 (kx 2023-03-24 03:51:10 +0300 269) struct strbuf buf = STRBUF_INIT;
05d292b2 (kx 2023-03-24 03:51:10 +0300 270) int psize = 200, rnum = 0, pos = 0, prev, next;
05d292b2 (kx 2023-03-24 03:51:10 +0300 271)
05d292b2 (kx 2023-03-24 03:51:10 +0300 272) fp = xfopen( ctx.page.header, "r" );
05d292b2 (kx 2023-03-24 03:51:10 +0300 273) (void)strbuf_env_fread( &buf, fp );
05d292b2 (kx 2023-03-24 03:51:10 +0300 274) fclose( fp );
05d292b2 (kx 2023-03-24 03:51:10 +0300 275)
05d292b2 (kx 2023-03-24 03:51:10 +0300 276) strbuf_addf( &buf, " <div class=\"content segment\">\n" );
05d292b2 (kx 2023-03-24 03:51:10 +0300 277) strbuf_addf( &buf, " <div class=\"container\">\n" );
05d292b2 (kx 2023-03-24 03:51:10 +0300 278) strbuf_addf( &buf, " <div class=\"cgit-main-content\">\n" );
05d292b2 (kx 2023-03-24 03:51:10 +0300 279)
05d292b2 (kx 2023-03-24 03:51:10 +0300 280) if( ctx.vars.page_size && *ctx.vars.page_size )
05d292b2 (kx 2023-03-24 03:51:10 +0300 281) sscanf( ctx.vars.page_size, "%d", &psize );
05d292b2 (kx 2023-03-24 03:51:10 +0300 282)
05d292b2 (kx 2023-03-24 03:51:10 +0300 283) if( ctx.vars.num_of_repos && *ctx.vars.num_of_repos )
05d292b2 (kx 2023-03-24 03:51:10 +0300 284) sscanf( ctx.vars.num_of_repos, "%d", &rnum );
05d292b2 (kx 2023-03-24 03:51:10 +0300 285)
05d292b2 (kx 2023-03-24 03:51:10 +0300 286) if( ctx.query.ofs > 0) pos = ctx.query.ofs;
05d292b2 (kx 2023-03-24 03:51:10 +0300 287) if( ctx.query.ofs > rnum-1 ) pos = rnum - rnum % psize;
05d292b2 (kx 2023-03-24 03:51:10 +0300 288) if( pos < 0 ) pos = 0;
05d292b2 (kx 2023-03-24 03:51:10 +0300 289)
05d292b2 (kx 2023-03-24 03:51:10 +0300 290) prev = pos - psize;
05d292b2 (kx 2023-03-24 03:51:10 +0300 291) if( prev < 0 ) prev = 0;
05d292b2 (kx 2023-03-24 03:51:10 +0300 292)
05d292b2 (kx 2023-03-24 03:51:10 +0300 293) next = pos + psize;
05d292b2 (kx 2023-03-24 03:51:10 +0300 294) if( next > rnum-1 ) next = rnum - rnum % psize;
05d292b2 (kx 2023-03-24 03:51:10 +0300 295) if( next < 0 ) next = 0;
05d292b2 (kx 2023-03-24 03:51:10 +0300 296)
05d292b2 (kx 2023-03-24 03:51:10 +0300 297) cgit_print_repolist_header( &buf );
05d292b2 (kx 2023-03-24 03:51:10 +0300 298) (void)cgit_print_page_repolist( &buf, config, pos, psize );
05d292b2 (kx 2023-03-24 03:51:10 +0300 299) cgit_print_direction( &buf, prev, next );
05d292b2 (kx 2023-03-24 03:51:10 +0300 300)
05d292b2 (kx 2023-03-24 03:51:10 +0300 301) strbuf_addf( &buf, " </div> <!-- End of cgit-main-content -->\n" );
05d292b2 (kx 2023-03-24 03:51:10 +0300 302) strbuf_addf( &buf, " </div> <!-- End of container -->\n" );
05d292b2 (kx 2023-03-24 03:51:10 +0300 303) strbuf_addf( &buf, " </div> <!-- End of content segment -->\n" );
05d292b2 (kx 2023-03-24 03:51:10 +0300 304)
05d292b2 (kx 2023-03-24 03:51:10 +0300 305) fp = xfopen( ctx.page.footer, "r" );
05d292b2 (kx 2023-03-24 03:51:10 +0300 306) (void)strbuf_env_fread( &buf, fp );
05d292b2 (kx 2023-03-24 03:51:10 +0300 307) fclose( fp );
05d292b2 (kx 2023-03-24 03:51:10 +0300 308)
05d292b2 (kx 2023-03-24 03:51:10 +0300 309) ctx.page.size = buf.len;
05d292b2 (kx 2023-03-24 03:51:10 +0300 310) cgit_print_http_headers();
05d292b2 (kx 2023-03-24 03:51:10 +0300 311) strbuf_write( &buf, STDOUT_FILENO );
05d292b2 (kx 2023-03-24 03:51:10 +0300 312) strbuf_release( &buf );
05d292b2 (kx 2023-03-24 03:51:10 +0300 313) }