cGit-UI for Git Repositories

cGit-UI – is a web interface for Git Repositories. cGit CGI script is writen in C and therefore it's fast enough

12 Commits   0 Branches   1 Tag
     5         kx 
     5         kx #ifdef HAVE_CONFIG_H
     5         kx #include <config.h>
     5         kx #endif
     5         kx 
     5         kx #include <stdlib.h>
     5         kx #include <stdio.h>
     5         kx #include <sys/sysinfo.h>
     5         kx #include <sys/types.h>
     5         kx #ifdef HAVE_INTTYPES_H
     5         kx #include <inttypes.h>
     5         kx #else
     5         kx #include <stdint.h>
     5         kx #endif
     5         kx #include <stddef.h>   /* offsetof(3) */
     5         kx #include <dirent.h>
     5         kx #include <sys/stat.h> /* chmod(2)    */
     5         kx #include <sys/file.h>
     5         kx #include <sys/mman.h>
     5         kx #include <fcntl.h>
     5         kx #include <limits.h>
     5         kx #include <string.h>   /* strdup(3)   */
     5         kx #include <libgen.h>   /* basename(3) */
     5         kx #include <ctype.h>    /* tolower(3)  */
     5         kx #include <errno.h>
     5         kx #include <time.h>
     5         kx #include <sys/time.h>
     5         kx #include <pwd.h>
     5         kx #include <grp.h>
     5         kx #include <stdarg.h>
     5         kx #include <locale.h>
     5         kx #include <unistd.h>
     5         kx 
     5         kx #include <git2.h>
     5         kx 
     5         kx #include <nls.h>
     5         kx 
     5         kx #include <defs.h>
     5         kx 
     5         kx #include <fatal.h>
     5         kx #include <http.h>
     5         kx #include <html.h>
     5         kx 
     5         kx #include <dlist.h>
     5         kx #include <strbuf.h>
     5         kx #include <repolist.h>
     5         kx #include <wrapper.h>
     5         kx #include <system.h>
     5         kx #include <date.h>
     5         kx 
     5         kx #include <ctx.h>
     5         kx #include <git-shared.h>
     5         kx #include <ui-shared.h>
     5         kx 
     5         kx 
     5         kx static void cgit_print_blame( struct strbuf *sb, const char *relative_path, const char *revision )
     5         kx {
     5         kx   const char *name = NULL, *git_root = NULL, *repo_root = NULL;
     5         kx 
     5         kx   if( !sb || !relative_path ) return;
     5         kx 
     5         kx   name      = ctx.repo.name;
     5         kx   git_root  = ctx.repo.git_root;
     5         kx   repo_root = ctx.repo.repo_root;
     5         kx 
     5         kx   strbuf_addf( sb, "<div class=\"blame\">" );
     5         kx   strbuf_addf( sb, "  <pre><code class='language-PlainText'>" );
     5         kx 
     5         kx   if( name && git_root )
     5         kx   {
     5         kx     char ref[PATH_MAX] = { 0 };
     5         kx     char rpath[PATH_MAX] = { 0 };
     5         kx 
     5         kx     char path[PATH_MAX] = { 0 };
     5         kx     char cmd[PATH_MAX];
     5         kx     struct strbuf buf = STRBUF_INIT;
     5         kx     char *raw = NULL;
     5         kx     pid_t p = (pid_t) -1;
     5         kx     int   rc;
     5         kx 
     5         kx     sprintf( (char *)&path[0], "%s/", git_root );
     5         kx     if( repo_root && *repo_root )
     5         kx     {
     5         kx       strcat( (char *)&path[0], repo_root );
     5         kx       strcat( (char *)&path[0], "/" );
     5         kx     }
     5         kx     strcat( (char *)&path[0], name );
     5         kx 
     5         kx     if( !is_bare( (char *)&path[0] ) )
     5         kx     {
     5         kx       strcat( (char *)&path[0], "/.git" );
     5         kx     }
     5         kx 
     5         kx     parse_relative_path( (char *)&ref[0], (char *)&rpath[0], relative_path );
     5         kx 
     5         kx     if( revision && *revision )
     5         kx       snprintf( (char *)&cmd[0], 1024, "git --git-dir=%s blame %s -- %s 2>/dev/null", (char *)&path[0], revision, (char *)&rpath[0] );
     5         kx     else
     5         kx       snprintf( (char *)&cmd[0], 1024, "git --git-dir=%s blame -- %s 2>/dev/null", (char *)&path[0], (char *)&rpath[0] );
     5         kx     p = sys_exec_command( &buf, cmd );
     5         kx     rc = sys_wait_command( p, NULL );
     5         kx     if( rc != 0 )
     5         kx     {
     5         kx       strbuf_release( &buf );
     5         kx       return;
     5         kx     }
     5         kx 
     5         kx     if( buf.buf[0] )
     5         kx     {
     5         kx       raw = strbuf_detach( &buf, NULL );
     5         kx       strbuf_addstr_xml_quoted( &buf, (const char *)raw );
     5         kx       free( raw );
     5         kx 
     5         kx       strbuf_addbuf( sb, (const struct strbuf *)&buf );
     5         kx     }
     5         kx     strbuf_release( &buf );
     5         kx   }
     5         kx 
     5         kx   strbuf_addstr( sb, "\n  </code></pre>\n" );
     5         kx   strbuf_addstr( sb, "</div>\n" );
     5         kx 
     5         kx   return;
     5         kx }
     5         kx 
     5         kx void cgit_print_blame_page( void )
     5         kx {
     5         kx   FILE  *fp;
     5         kx   struct strbuf buf = STRBUF_INIT;
     5         kx 
     5         kx   fp = xfopen( ctx.page.header, "r" );
     5         kx   (void)strbuf_env_fread( &buf, fp );
     5         kx   fclose( fp );
     5         kx 
     5         kx   strbuf_addf( &buf, "        <div class=\"content segment\">\n" );
     5         kx   strbuf_addf( &buf, "          <div class=\"container\">\n" );
     5         kx   strbuf_addf( &buf, "            <div class=\"cgit-main-content\">\n" );
     5         kx 
     5         kx   if( ctx.repo.name )
     5         kx   {
     5         kx     cgit_print_blame( &buf, ctx.repo.relative_path, (!strcmp( ctx.query.rev, "0" )) ? (const char *)&ctx.repo.relative_info.revision[0] : ctx.query.rev );
     5         kx   }
     5         kx   else
     5         kx   {
     5         kx     strbuf_addf( &buf, "              <h1>Requested resource cannot be shown</h1>\n" );
     5         kx     strbuf_addf( &buf, "              <p class='leading'>Repository '%s' not found.</p>\n", ctx.repo.name );
     5         kx   }
     5         kx 
     5         kx   strbuf_addf( &buf, "            </div> <!-- End of cgit-main-content -->\n" );
     5         kx   strbuf_addf( &buf, "          </div> <!-- End of container -->\n" );
     5         kx   strbuf_addf( &buf, "        </div> <!-- End of content segment -->\n" );
     5         kx 
     5         kx   fp = xfopen( ctx.page.footer, "r" );
     5         kx   (void)strbuf_env_fread( &buf, fp );
     5         kx   fclose( fp );
     5         kx 
     5         kx   ctx.page.size = buf.len;
     5         kx   cgit_print_http_headers();
     5         kx   strbuf_write( &buf, STDOUT_FILENO );
     5         kx   strbuf_release( &buf );
     5         kx }