cGit-UI for Git Repositories

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

24 Commits   0 Branches   5 Tags   |
Index: cgitcgi/ui-file.c
===================================================================
--- cgitcgi/ui-file.c	(revision 15)
+++ cgitcgi/ui-file.c	(revision 16)
@@ -234,6 +234,77 @@
   return;
 }
 
+static void cgit_print_image_file( struct strbuf *sb, const char *relative_path, const char *revision )
+{
+  struct cgit_info info;
+
+  if( !sb || !relative_path ) return;
+
+  if( revision && strcmp( revision, (const char *)&ctx.repo.relative_info.revision[0] ) )
+  {
+    cgit_rpath_info( &info, relative_path, revision );
+    if( info.kind != GIT_OBJECT_BLOB )
+    {
+      strbuf_addf( sb, "              <h1>Invalid Revision</h1>\n" );
+      strbuf_addf( sb, "              <p class='leading'>File with specified revision '%s' cannot be shown.</p>\n", revision );
+      return;
+    }
+  }
+  else
+  {
+    memcpy( (void *)&info, (void *)&ctx.repo.relative_info, sizeof( struct cgit_info ) );
+  }
+
+  if( info.kind == GIT_OBJECT_BLOB )
+  {
+    git_repository *repo = NULL;
+    git_blob       *blob = NULL;
+    git_oid         oid;
+    git_off_t       rawsize = 0;
+    const char     *rawcontent = NULL;
+
+    if( git_oid_fromstr( &oid, (const char *)&info.oid[0] ) < 0 ) return;
+    if( !(repo = cgit_open_repository()) ) return;
+
+    if( git_blob_lookup( &blob, repo, &oid ) < 0 )
+    {
+      close_repository( repo );
+      return;
+    }
+
+    rawsize = git_blob_rawsize( blob );
+    rawcontent = (const char *)git_blob_rawcontent( blob );
+
+    if( rawcontent && *rawcontent )
+    {
+      struct strbuf buf = STRBUF_INIT;
+
+      strbuf_add( &buf, (const void *)rawcontent, (size_t)rawsize );
+
+      git_blob_free( blob );
+      close_repository( repo );
+
+      /****************************************************
+        This call should terminate the program on success:
+       */
+      cgit_print_raw_file( &buf, info.mime );
+
+      strbuf_release( &buf );
+    }
+    else
+    {
+      git_blob_free( blob );
+      close_repository( repo );
+      return;
+    }
+
+    git_blob_free( blob );
+    close_repository( repo );
+  }
+
+  return;
+}
+
 void cgit_print_file_page( void )
 {
   FILE  *fp;
@@ -261,6 +332,16 @@
         strbuf_addf( &buf, "              <p class='leading'>Repository '%s' not found.</p>\n", ctx.repo.name );
       }
     }
+    else if( !strncmp( ctx.repo.relative_info.mime, "image/", 6 ) )
+    {
+      /****************************************************
+        This call should terminate the program on success:
+       */
+      cgit_print_image_file( &buf, ctx.repo.relative_path, (!strcmp( ctx.query.rev, "0" )) ? (const char *)&ctx.repo.relative_info.revision[0] : ctx.query.rev );
+
+      strbuf_addf( &buf, "              <h1>Requested file cannot be shown</h1>\n" );
+      strbuf_addf( &buf, "              <p class='leading'>Files with mime type such as '%s' cannot be present.</p>\n", ctx.repo.relative_info.mime );
+    }
     else
     {
       strbuf_addf( &buf, "              <h1>Requested file cannot be shown</h1>\n" );
Index: cgitcgi/ui-shared.c
===================================================================
--- cgitcgi/ui-shared.c	(revision 15)
+++ cgitcgi/ui-shared.c	(revision 16)
@@ -730,3 +730,26 @@
   strbuf_write( &buf, STDOUT_FILENO );
   strbuf_release( &buf );
 }
+
+
+void cgit_print_raw_file( struct strbuf *sb, const char *mime )
+{
+  struct strbuf buf = STRBUF_INIT;
+  char *p = (char *)mime;
+
+  char *http_format = "Date: %s\n"
+                      "Content-Type: %s\n"
+                      "Content-Length: %ld\n\n";
+
+  if( !sb || !mime ) return;
+
+  while( *p && *p != ';' ) ++p;
+  if( *p ) *p = '\0';
+
+  strbuf_addf( &buf, http_format, http_date( time(NULL) ), mime, sb->len );
+  strbuf_addbuf( &buf, (const struct strbuf *)sb );
+  strbuf_write( &buf, STDOUT_FILENO );
+  strbuf_release( &buf );
+
+  exit( 0 );
+}
Index: cgitcgi/ui-shared.h
===================================================================
--- cgitcgi/ui-shared.h	(revision 15)
+++ cgitcgi/ui-shared.h	(revision 16)
@@ -36,6 +36,7 @@
 
 
 extern void cgit_print_404_page( void );
+extern void cgit_print_raw_file( struct strbuf *sb, const char *mime );
 
 
 #ifdef __cplusplus
Index: configure.ac
===================================================================
--- configure.ac	(revision 15)
+++ configure.ac	(revision 16)
@@ -7,7 +7,7 @@
 AC_PREREQ(2.69)dnl        dnl Minimum Autoconf version required.
 
 
-AC_INIT([cgit-ui], [0.1.4],
+AC_INIT([cgit-ui], [0.1.5],
   [support@radix.pro], [cgit-ui], [https://radix.pro])
 
 dnl ============================================================
Index: doc/build-packages/archlinux/PKGBUILD
===================================================================
--- doc/build-packages/archlinux/PKGBUILD	(revision 15)
+++ doc/build-packages/archlinux/PKGBUILD	(revision 16)
@@ -2,7 +2,7 @@
 # Maintainer: Andrey V.Kosteltsev <kx@radix.pro>
 #
 pkgname=cgit-ui
-pkgver=0.1.4
+pkgver=0.1.5
 pkgrel=2
 pkgdesc='cGit-ui CGI Script is a web interface for Git Repositories'
 arch=('x86_64')
Index: doc/build-packages/archlinux/README
===================================================================
--- doc/build-packages/archlinux/README	(revision 15)
+++ doc/build-packages/archlinux/README	(revision 16)
@@ -18,6 +18,6 @@
 
 As root:
 
-  # pacman -U ./cgit-ui-0.1.4-2-x86_64.pkg.tar.zst
+  # pacman -U ./cgit-ui-0.1.5-2-x86_64.pkg.tar.zst
 
 After install you have to configure uWsgi and Nginx servers (see: README.md).
Index: doc/build-packages/rpms/cgit-ui.spec
===================================================================
--- doc/build-packages/rpms/cgit-ui.spec	(revision 15)
+++ doc/build-packages/rpms/cgit-ui.spec	(revision 16)
@@ -1,11 +1,11 @@
 
 Name:       cgit-ui
-Version:    0.1.4
+Version:    0.1.5
 Release:    2
 Summary:    cGit-ui a web interface for Git repositories
 License:    RADIX-1.0
 Group:      System/base
-Source:     https://ftp.radix.pro/pub/cgit-ui/cgit-ui-0.1.4.tar.xz
+Source:     https://ftp.radix.pro/pub/cgit-ui/cgit-ui-0.1.5.tar.xz
 Url:        https://csvn.radix/pro/cgit-ui/
 
 
Index: doc/build-packages/slackware/cgit-ui.info
===================================================================
--- doc/build-packages/slackware/cgit-ui.info	(revision 15)
+++ doc/build-packages/slackware/cgit-ui.info	(revision 16)
@@ -1,7 +1,7 @@
 PRGNAM="cgit-ui"
-VERSION="0.1.4"
+VERSION="0.1.5"
 HOMEPAGE="http://csvn.radix.pro"
-DOWNLOAD="https://ftp.radix.pro/pub/cgit-ui/cgit-ui-0.1.4.tar.xz"
+DOWNLOAD="https://ftp.radix.pro/pub/cgit-ui/cgit-ui-0.1.5.tar.xz"
 MD5SUM="..Check MD5 sum before Building Package.."
 DOWNLOAD_x86_64=""
 MD5SUM_x86_64=""
Index: po/cgit-ui.pot
===================================================================
--- po/cgit-ui.pot	(revision 15)
+++ po/cgit-ui.pot	(revision 16)
@@ -6,9 +6,9 @@
 #, fuzzy
 msgid ""
 msgstr ""
-"Project-Id-Version: cgit-ui 0.1.4\n"
+"Project-Id-Version: cgit-ui 0.1.5\n"
 "Report-Msgid-Bugs-To: <support@radix.pro>\n"
-"POT-Creation-Date: 2020-12-07 19:21+0300\n"
+"POT-Creation-Date: 2020-12-10 05:35+0300\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
Index: po/ru_RU.utf8.po
===================================================================
--- po/ru_RU.utf8.po	(revision 15)
+++ po/ru_RU.utf8.po	(revision 16)
@@ -6,10 +6,10 @@
 #
 msgid ""
 msgstr ""
-"Project-Id-Version: cgit-ui 0.1.4\n"
+"Project-Id-Version: cgit-ui 0.1.5\n"
 "Report-Msgid-Bugs-To: <support@radix.pro>\n"
-"POT-Creation-Date: 2020-12-07 19:21+0300\n"
-"PO-Revision-Date: 2020-12-07 19:25+0300\n"
+"POT-Creation-Date: 2020-12-10 05:35+0300\n"
+"PO-Revision-Date: 2020-12-10 05:40+0300\n"
 "Last-Translator: Andrey V.Kosteltsev <kx@radix.pro>\n"
 "Language-Team: Russian\n"
 "Language: ru_RU.utf8\n"