bfc1508d (kx 2023-03-24 03:55:33 +0300 1)
bfc1508d (kx 2023-03-24 03:55:33 +0300 2) #ifdef HAVE_CONFIG_H
bfc1508d (kx 2023-03-24 03:55:33 +0300 3) #include <config.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300 4) #endif
bfc1508d (kx 2023-03-24 03:55:33 +0300 5)
bfc1508d (kx 2023-03-24 03:55:33 +0300 6) #include <stdlib.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300 7) #include <stdio.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300 8) #include <sys/sysinfo.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300 9) #include <sys/types.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300 10) #ifdef HAVE_INTTYPES_H
bfc1508d (kx 2023-03-24 03:55:33 +0300 11) #include <inttypes.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300 12) #else
bfc1508d (kx 2023-03-24 03:55:33 +0300 13) #include <stdint.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300 14) #endif
bfc1508d (kx 2023-03-24 03:55:33 +0300 15) #include <stddef.h> /* offsetof(3) */
bfc1508d (kx 2023-03-24 03:55:33 +0300 16) #include <dirent.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300 17) #include <sys/stat.h> /* chmod(2) */
bfc1508d (kx 2023-03-24 03:55:33 +0300 18) #include <sys/file.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300 19) #include <sys/mman.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300 20) #include <fcntl.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300 21) #include <limits.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300 22) #include <string.h> /* strdup(3) */
bfc1508d (kx 2023-03-24 03:55:33 +0300 23) #include <libgen.h> /* basename(3) */
bfc1508d (kx 2023-03-24 03:55:33 +0300 24) #include <ctype.h> /* tolower(3) */
bfc1508d (kx 2023-03-24 03:55:33 +0300 25) #include <errno.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300 26) #include <time.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300 27) #include <sys/time.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300 28) #include <pwd.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300 29) #include <grp.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300 30) #include <stdarg.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300 31) #include <locale.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300 32) #include <unistd.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300 33)
bfc1508d (kx 2023-03-24 03:55:33 +0300 34) #include <nls.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300 35)
bfc1508d (kx 2023-03-24 03:55:33 +0300 36) #include <defs.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300 37)
bfc1508d (kx 2023-03-24 03:55:33 +0300 38) #include <fatal.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300 39) #include <http.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300 40) #include <html.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300 41)
bfc1508d (kx 2023-03-24 03:55:33 +0300 42) #include <dlist.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300 43) #include <strbuf.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300 44) #include <repolist.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300 45) #include <wrapper.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300 46) #include <system.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300 47) #include <date.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300 48)
bfc1508d (kx 2023-03-24 03:55:33 +0300 49) #include <ctx.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300 50) #include <ui-shared.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300 51)
bfc1508d (kx 2023-03-24 03:55:33 +0300 52)
bfc1508d (kx 2023-03-24 03:55:33 +0300 53) static void csvn_print_blame( struct strbuf *sb, const char *relative_path, int revision )
bfc1508d (kx 2023-03-24 03:55:33 +0300 54) {
bfc1508d (kx 2023-03-24 03:55:33 +0300 55) const char *co_prefix = ctx.repo.checkout_ro_prefix;
c7693c71 (kx 2023-04-12 19:21:06 +0300 56) const char *name = ctx.repo.name;
c7693c71 (kx 2023-04-12 19:21:06 +0300 57) const char *repo_root = ctx.repo.repo_root;
bfc1508d (kx 2023-03-24 03:55:33 +0300 58)
bfc1508d (kx 2023-03-24 03:55:33 +0300 59) if( !sb || !relative_path ) return;
bfc1508d (kx 2023-03-24 03:55:33 +0300 60)
bfc1508d (kx 2023-03-24 03:55:33 +0300 61) strbuf_addf( sb, "<div class=\"blame\">" );
bfc1508d (kx 2023-03-24 03:55:33 +0300 62) strbuf_addf( sb, " <pre><code class='language-PlainText'>" );
bfc1508d (kx 2023-03-24 03:55:33 +0300 63)
bfc1508d (kx 2023-03-24 03:55:33 +0300 64) if( co_prefix )
bfc1508d (kx 2023-03-24 03:55:33 +0300 65) {
c7693c71 (kx 2023-04-12 19:21:06 +0300 66) char repo_path[PATH_MAX] = { 0 };
c7693c71 (kx 2023-04-12 19:21:06 +0300 67) char cmd[PATH_MAX];
bfc1508d (kx 2023-03-24 03:55:33 +0300 68) struct strbuf buf = STRBUF_INIT;
bfc1508d (kx 2023-03-24 03:55:33 +0300 69) char *raw = NULL;
bfc1508d (kx 2023-03-24 03:55:33 +0300 70) pid_t p = (pid_t) -1;
bfc1508d (kx 2023-03-24 03:55:33 +0300 71) int rc;
bfc1508d (kx 2023-03-24 03:55:33 +0300 72)
c7693c71 (kx 2023-04-12 19:21:06 +0300 73) if( repo_root && *repo_root )
c7693c71 (kx 2023-04-12 19:21:06 +0300 74) {
c7693c71 (kx 2023-04-12 19:21:06 +0300 75) strcat( (char *)&repo_path[0], repo_root );
c7693c71 (kx 2023-04-12 19:21:06 +0300 76) strcat( (char *)&repo_path[0], "/" );
c7693c71 (kx 2023-04-12 19:21:06 +0300 77) }
c7693c71 (kx 2023-04-12 19:21:06 +0300 78) strcat( (char *)&repo_path[0], name );
c7693c71 (kx 2023-04-12 19:21:06 +0300 79)
bfc1508d (kx 2023-03-24 03:55:33 +0300 80) if( revision )
bfc1508d (kx 2023-03-24 03:55:33 +0300 81) snprintf( (char *)&cmd[0], 1024,
bfc1508d (kx 2023-03-24 03:55:33 +0300 82) "svn blame --revision %d %s/%s/%s 2>/dev/null",
c7693c71 (kx 2023-04-12 19:21:06 +0300 83) revision, co_prefix, (char *)&repo_path[0], relative_path );
bfc1508d (kx 2023-03-24 03:55:33 +0300 84) else
bfc1508d (kx 2023-03-24 03:55:33 +0300 85) snprintf( (char *)&cmd[0], 1024,
bfc1508d (kx 2023-03-24 03:55:33 +0300 86) "svn blame %s/%s/%s 2>/dev/null",
c7693c71 (kx 2023-04-12 19:21:06 +0300 87) co_prefix, (char *)&repo_path[0], relative_path );
bfc1508d (kx 2023-03-24 03:55:33 +0300 88) p = sys_exec_command( &buf, cmd );
bfc1508d (kx 2023-03-24 03:55:33 +0300 89) rc = sys_wait_command( p, NULL );
bfc1508d (kx 2023-03-24 03:55:33 +0300 90) if( rc != 0 )
bfc1508d (kx 2023-03-24 03:55:33 +0300 91) {
bfc1508d (kx 2023-03-24 03:55:33 +0300 92) strbuf_release( &buf );
bfc1508d (kx 2023-03-24 03:55:33 +0300 93) return;
bfc1508d (kx 2023-03-24 03:55:33 +0300 94) }
bfc1508d (kx 2023-03-24 03:55:33 +0300 95)
bfc1508d (kx 2023-03-24 03:55:33 +0300 96) raw = strbuf_detach( &buf, NULL );
bfc1508d (kx 2023-03-24 03:55:33 +0300 97) strbuf_addstr_xml_quoted( &buf, (const char *)raw );
bfc1508d (kx 2023-03-24 03:55:33 +0300 98) free( raw );
bfc1508d (kx 2023-03-24 03:55:33 +0300 99)
bfc1508d (kx 2023-03-24 03:55:33 +0300 100) strbuf_addbuf( sb, (const struct strbuf *)&buf );
bfc1508d (kx 2023-03-24 03:55:33 +0300 101) strbuf_release( &buf );
bfc1508d (kx 2023-03-24 03:55:33 +0300 102) }
bfc1508d (kx 2023-03-24 03:55:33 +0300 103)
bfc1508d (kx 2023-03-24 03:55:33 +0300 104) strbuf_addstr( sb, "\n </code></pre>\n" );
bfc1508d (kx 2023-03-24 03:55:33 +0300 105) strbuf_addstr( sb, "</div>\n" );
bfc1508d (kx 2023-03-24 03:55:33 +0300 106)
bfc1508d (kx 2023-03-24 03:55:33 +0300 107) return;
bfc1508d (kx 2023-03-24 03:55:33 +0300 108) }
bfc1508d (kx 2023-03-24 03:55:33 +0300 109)
bfc1508d (kx 2023-03-24 03:55:33 +0300 110) void csvn_print_blame_page( void )
bfc1508d (kx 2023-03-24 03:55:33 +0300 111) {
bfc1508d (kx 2023-03-24 03:55:33 +0300 112) FILE *fp;
bfc1508d (kx 2023-03-24 03:55:33 +0300 113) struct strbuf buf = STRBUF_INIT;
bfc1508d (kx 2023-03-24 03:55:33 +0300 114)
bfc1508d (kx 2023-03-24 03:55:33 +0300 115) fp = xfopen( ctx.page.header, "r" );
bfc1508d (kx 2023-03-24 03:55:33 +0300 116) (void)strbuf_env_fread( &buf, fp );
bfc1508d (kx 2023-03-24 03:55:33 +0300 117) fclose( fp );
bfc1508d (kx 2023-03-24 03:55:33 +0300 118)
bfc1508d (kx 2023-03-24 03:55:33 +0300 119) strbuf_addf( &buf, " <div class=\"content segment\">\n" );
bfc1508d (kx 2023-03-24 03:55:33 +0300 120) strbuf_addf( &buf, " <div class=\"container\">\n" );
bfc1508d (kx 2023-03-24 03:55:33 +0300 121) strbuf_addf( &buf, " <div class=\"csvn-main-content\">\n" );
bfc1508d (kx 2023-03-24 03:55:33 +0300 122)
bfc1508d (kx 2023-03-24 03:55:33 +0300 123) if( ctx.repo.name )
bfc1508d (kx 2023-03-24 03:55:33 +0300 124) {
bfc1508d (kx 2023-03-24 03:55:33 +0300 125) csvn_print_blame( &buf, ctx.repo.relative_path, ctx.query.rev );
bfc1508d (kx 2023-03-24 03:55:33 +0300 126) }
bfc1508d (kx 2023-03-24 03:55:33 +0300 127) else
bfc1508d (kx 2023-03-24 03:55:33 +0300 128) {
bfc1508d (kx 2023-03-24 03:55:33 +0300 129) strbuf_addf( &buf, " <h1>Requested resource cannot be shown</h1>\n" );
bfc1508d (kx 2023-03-24 03:55:33 +0300 130) strbuf_addf( &buf, " <p class='leading'>Repository '%s' not found.</p>\n", ctx.repo.name );
bfc1508d (kx 2023-03-24 03:55:33 +0300 131) }
bfc1508d (kx 2023-03-24 03:55:33 +0300 132)
bfc1508d (kx 2023-03-24 03:55:33 +0300 133) strbuf_addf( &buf, " </div> <!-- End of csvn-main-content -->\n" );
bfc1508d (kx 2023-03-24 03:55:33 +0300 134) strbuf_addf( &buf, " </div> <!-- End of container -->\n" );
bfc1508d (kx 2023-03-24 03:55:33 +0300 135) strbuf_addf( &buf, " </div> <!-- End of content segment -->\n" );
bfc1508d (kx 2023-03-24 03:55:33 +0300 136)
bfc1508d (kx 2023-03-24 03:55:33 +0300 137) fp = xfopen( ctx.page.footer, "r" );
bfc1508d (kx 2023-03-24 03:55:33 +0300 138) (void)strbuf_env_fread( &buf, fp );
bfc1508d (kx 2023-03-24 03:55:33 +0300 139) fclose( fp );
bfc1508d (kx 2023-03-24 03:55:33 +0300 140)
bfc1508d (kx 2023-03-24 03:55:33 +0300 141) ctx.page.size = buf.len;
bfc1508d (kx 2023-03-24 03:55:33 +0300 142) csvn_print_http_headers();
bfc1508d (kx 2023-03-24 03:55:33 +0300 143) strbuf_write( &buf, STDOUT_FILENO );
bfc1508d (kx 2023-03-24 03:55:33 +0300 144) strbuf_release( &buf );
bfc1508d (kx 2023-03-24 03:55:33 +0300 145) }