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 print_commit( struct strbuf *sb, git_commit *commit, const char *revision, const char *parent, int files, int insertions, int deletions )
     5         kx {
     5         kx   const git_oid       *oid;
     5         kx   const char          *message;
     5         kx   git_time_t           date;
     5         kx   int                  offset;
     5         kx   const git_signature *author;
     5         kx   const git_signature *committer;
     5         kx 
     5         kx   char id[GIT_OID_HEXSZ+1] = { 0 };
     5         kx 
     5         kx   struct strbuf fbuf = STRBUF_INIT;
     5         kx   struct strbuf ibuf = STRBUF_INIT;
     5         kx   struct strbuf dbuf = STRBUF_INIT;
     5         kx 
     5         kx   struct strbuf atime = STRBUF_INIT;
     5         kx   struct strbuf ctime = STRBUF_INIT;
     5         kx   struct strbuf  cmsg = STRBUF_INIT;
     5         kx 
     5         kx   char *raw = NULL;
     5         kx 
     5         kx   if( !sb || !commit || !revision || !parent ) return;
     5         kx 
     5         kx   oid       = git_commit_id( commit );
     5         kx   if( git_oid_fmt( (char *)&id[0], oid ) < 0 || strcmp( (char *)&id[0], revision ) ) return;
     5         kx 
     5         kx   message   = git_commit_summary( commit );
     5         kx   author    = git_commit_author( commit );
     5         kx   committer = git_commit_committer( commit );
     5         kx 
     5         kx   strbuf_addf( &cmsg, "%s", message );
     5         kx   raw = strbuf_detach( &cmsg, NULL );
     5         kx   strbuf_addstr_xml_quoted( &cmsg, (const char *)raw );
     5         kx   free( raw );
     5         kx 
     5         kx   strbuf_addstr( sb, "              <div class=\"diff-cmsg\">\n" );
     5         kx   strbuf_addstr( sb, "                <div class=\"cmsg-commit\">\n" );
     5         kx 
     5         kx   date   = author->when.time;
     5         kx   offset = author->when.offset;
     5         kx   offset = (offset % 60) + ((offset / 60) * 100);
     5         kx   show_date( &atime, (time_t)date, offset, cgit_date_mode( DATE_ISO8601 ) );
     5         kx 
     5         kx   strbuf_addf( sb, "<span class=\"head\">   author:</span> %s &lt;%s&gt; %s\n", author->name, author->email, (char *)&atime.buf[0] );
     5         kx   strbuf_release( &atime );
     5         kx 
     5         kx   date   = committer->when.time;
     5         kx   offset = committer->when.offset;
     5         kx   offset = (offset % 60) + ((offset / 60) * 100);
     5         kx   show_date( &ctime, (time_t)date, offset, cgit_date_mode( DATE_ISO8601 ) );
     5         kx 
     5         kx   strbuf_addf( sb, "<span class=\"head\">committer:</span> %s &lt;%s&gt; %s\n", committer->name, committer->email, (char *)&ctime.buf[0] );
     5         kx   strbuf_release( &ctime );
     5         kx 
     5         kx     strbuf_addf( sb, "<span class=\"head\">   commit:</span> <span class=\"revision\">%s</span>\n", revision );
     5         kx     strbuf_addf( sb, "<span class=\"head\">   parent:</span> <span class=\"parent\">%s</span>\n", parent );
     5         kx   strbuf_addstr( sb, "                </div>\n" );
     5         kx   strbuf_addstr( sb, "                <div class=\"cmsg-summary\">\n" );
     5         kx   strbuf_addstr( sb, "                  <div class=\"head\">\n" );
     5         kx   strbuf_addstr( sb, "                    Commit Summary:\n" );
     5         kx   strbuf_addstr( sb, "                  </div>\n" );
     5         kx     strbuf_addf( sb, "                  <div class=\"message\">%s</div>\n", (char *)&cmsg.buf[0] );
     5         kx   strbuf_release( &cmsg );
     5         kx   strbuf_addstr( sb, "                </div>\n" );
     5         kx   strbuf_addstr( sb, "              </div>\n" );
     5         kx 
     5         kx   strbuf_addf( &fbuf, Q_("%d file changed", "%d files changed", files), files );
     5         kx   strbuf_addf( &ibuf, Q_("%d insertion", "%d insertions", insertions), insertions );
     5         kx   strbuf_addf( &dbuf, Q_("%d deletion", "%d deletions", deletions), deletions );
     5         kx 
     5         kx   strbuf_addstr( sb, "              <div class=\"diff-stat\">\n" );
     5         kx   strbuf_addstr( sb, "                <div class=\"head\">Diffstat:</div>\n" );
     5         kx     strbuf_addf( sb, "                <div class=\"line\">%s, %s, %s</div>\n", (char *)&fbuf.buf[0], (char *)&ibuf.buf[0], (char *)&dbuf.buf[0] );
     5         kx   strbuf_addstr( sb, "              </div>\n" );
     5         kx 
     5         kx   strbuf_release( &fbuf );
     5         kx   strbuf_release( &ibuf );
     5         kx   strbuf_release( &dbuf );
     5         kx }
     5         kx 
     5         kx static void cgit_print_diff( struct strbuf *sb, const char *relative_path, const char *revision )
     5         kx {
     5         kx   struct strbuf buf   = STRBUF_INIT;
     5         kx 
     5         kx   git_commit *commit = NULL;
     5         kx   char parent_hex[GIT_OID_HEXSZ+1] = { 0 };
     5         kx   int files, insertions, deletions;
     5         kx   char *raw = NULL;
     5         kx 
     5         kx   if( !sb ) return;
     5         kx 
     5         kx   commit = lookup_commit_by_hex( revision );
     5         kx 
     5         kx   cgit_diff_with_parent( &buf, (char *)&parent_hex[0], GIT_OID_HEXSZ+1, &files, &insertions, &deletions, revision, ( relative_path && *relative_path ) ? relative_path : "/" );
     5         kx 
     5         kx   print_commit( sb, commit, revision, (const char *)&parent_hex[0], files, insertions, deletions );
     5         kx   git_commit_free( commit );
     5         kx 
     5         kx   strbuf_addf( sb, "<pre><code class='language-Diff'>" );
     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   strbuf_release( &buf );
     5         kx 
     5         kx   strbuf_addstr( sb, "\n</code></pre>\n" );
     5         kx }
     5         kx 
     5         kx void cgit_print_diff_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_diff( &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 }