]> gitweb.ps.run Git - ps-cgit/commitdiff
Merge branch 'lh/cleanup'
authorLars Hjemli <hjemli@gmail.com>
Tue, 8 Apr 2008 19:29:21 +0000 (21:29 +0200)
committerLars Hjemli <hjemli@gmail.com>
Tue, 8 Apr 2008 19:29:21 +0000 (21:29 +0200)
* lh/cleanup: (21 commits)
  Reset ctx.repo to NULL when the config parser is finished
  Move cgit_parse_query() from parsing.c to html.c as http_parse_querystring()
  Move function for configfile parsing into configfile.[ch]
  Add cache.h
  Remove global and obsolete cgit_cmd
  Makefile: copy the QUIET constructs from the Makefile in git.git
  Move cgit_version from shared.c to cgit.c
  Makefile: autobuild dependency rules
  Initial Makefile cleanup
  Move non-generic functions from shared.c to cgit.c
  Add ui-shared.h
  Add separate header-files for each page/view
  Refactor snapshot support
  Add command dispatcher
  Remove obsolete cacheitem parameter to ui-functions
  Add struct cgit_page to cgit_context
  Introduce html.h
  Improve initialization of git directory
  Move cgit_repo into cgit_context
  Add all config variables into struct cgit_context
  ...

1  2 
Makefile
html.c
ui-patch.c

diff --combined Makefile
index 8bf47f22a73e7a4a7172bbb58dc96cb428485c97,355186eb068df3c44a3ff6890a472ef2a58bd672..931c60e4d7a750f6453ecb8fde8c332a99f1047b
+++ b/Makefile
@@@ -4,7 -4,7 +4,7 @@@ CGIT_SCRIPT_PATH = /var/www/htdocs/cgi
  CGIT_CONFIG = /etc/cgitrc
  CACHE_ROOT = /var/cache/cgit
  SHA1_HEADER = <openssl/sha.h>
 -GIT_VER = 1.5.4.1
 +GIT_VER = 1.5.5.rc1
  GIT_URL = http://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.bz2
  
  #
  #
  -include cgit.conf
  
+ #
+ # Define a way to invoke make in subdirs quietly, shamelessly ripped
+ # from git.git
+ #
+ QUIET_SUBDIR0  = +$(MAKE) -C # space to separate -C and subdir
+ QUIET_SUBDIR1  =
  
- EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto
- OBJECTS = shared.o cache.o parsing.o html.o ui-shared.o ui-repolist.o \
-       ui-summary.o ui-log.o ui-tree.o ui-commit.o ui-diff.o \
-       ui-snapshot.o ui-blob.o ui-tag.o ui-refs.o ui-patch.o
+ ifneq ($(findstring $(MAKEFLAGS),w),w)
+ PRINT_DIR = --no-print-directory
+ else # "make -w"
+ NO_SUBDIR = :
+ endif
+ ifndef V
+       QUIET_CC       = @echo '   ' CC $@;
+       QUIET_MM       = @echo '   ' MM $@;
+       QUIET_SUBDIR0  = +@subdir=
+       QUIET_SUBDIR1  = ;$(NO_SUBDIR) echo '   ' SUBDIR $$subdir; \
+                        $(MAKE) $(PRINT_DIR) -C $$subdir
+ endif
+ #
+ # Define a pattern rule for automatic dependency building
+ #
+ %.d: %.c
+       $(QUIET_MM)$(CC) $(CFLAGS) -MM $< | sed -e 's/\($*\)\.o:/\1.o $@:/g' >$@
+ #
+ # Define a pattern rule for silent object building
+ #
+ %.o: %.c
+       $(QUIET_CC)$(CC) -o $*.o -c $(CFLAGS) $<
  
  
+ EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto
+ OBJECTS =
+ OBJECTS += cache.o
+ OBJECTS += cgit.o
+ OBJECTS += cmd.o
+ OBJECTS += configfile.o
+ OBJECTS += html.o
+ OBJECTS += parsing.o
+ OBJECTS += shared.o
+ OBJECTS += ui-blob.o
+ OBJECTS += ui-commit.o
+ OBJECTS += ui-diff.o
+ OBJECTS += ui-log.o
+ OBJECTS += ui-patch.o
+ OBJECTS += ui-refs.o
+ OBJECTS += ui-repolist.o
+ OBJECTS += ui-shared.o
+ OBJECTS += ui-snapshot.o
+ OBJECTS += ui-summary.o
+ OBJECTS += ui-tag.o
+ OBJECTS += ui-tree.o
  ifdef NEEDS_LIBICONV
        EXTLIBS += -liconv
  endif
@@@ -41,21 -90,25 +90,25 @@@ CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_S
  CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"'
  
  
- cgit: cgit.c $(OBJECTS)
-       $(CC) $(CFLAGS) cgit.c -o cgit $(OBJECTS) $(EXTLIBS)
+ cgit: $(OBJECTS)
+       $(QUIET_CC)$(CC) $(CFLAGS) -o cgit $(OBJECTS) $(EXTLIBS)
+ $(OBJECTS): git/xdiff/lib.a git/libgit.a
+ cgit.o: VERSION
  
- $(OBJECTS): cgit.h git/xdiff/lib.a git/libgit.a VERSION
+ -include $(OBJECTS:.o=.d)
  
  git/xdiff/lib.a: | git
  
  git/libgit.a: | git
  
  git:
-       cd git && $(MAKE) xdiff/lib.a
-       cd git && $(MAKE) libgit.a
+       $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) xdiff/lib.a
+       $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) libgit.a
  
  test: all
-       $(MAKE) -C tests
+       $(QUIET_SUBDIR0)tests $(QUIET_SUBDIR1) all
  
  install: all
        mkdir -p $(DESTDIR)$(CGIT_SCRIPT_PATH)
@@@ -69,7 -122,7 +122,7 @@@ uninstall
        rm -f $(CGIT_SCRIPT_PATH)/cgit.png
  
  clean:
-       rm -f cgit VERSION *.o
+       rm -f cgit VERSION *.o *.d
        cd git && $(MAKE) clean
  
  distclean: clean
diff --combined html.c
index 339bf0043aceafae6cd5894046c9e676742432b3,98ffaf976a4abdf92e4ba4f5a973ab0c5184a515..937b5e7d6ef162554e187dc047c506c973edb553
--- 1/html.c
--- 2/html.c
+++ b/html.c
@@@ -6,7 -6,13 +6,13 @@@
   *   (see COPYING for full license text)
   */
  
- #include "cgit.h"
+ #include <unistd.h>
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <stdarg.h>
+ #include <string.h>
+ int htmlfd = STDOUT_FILENO;
  
  char *fmt(const char *format, ...)
  {
        va_start(args, format);
        len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args);
        va_end(args);
-       if (len>sizeof(buf[bufidx]))
-               die("[html.c] string truncated: %s", format);
+       if (len>sizeof(buf[bufidx])) {
+               fprintf(stderr, "[html.c] string truncated: %s\n", format);
+               exit(1);
+       }
        return buf[bufidx];
  }
  
@@@ -48,7 -56,9 +56,7 @@@ void html_txt(char *txt
        while(t && *t){
                int c = *t;
                if (c=='<' || c=='>' || c=='&') {
 -                      *t = '\0';
 -                      html(txt);
 -                      *t = c;
 +                      write(htmlfd, txt, t - txt);
                        if (c=='>')
                                html("&gt;");
                        else if (c=='<')
@@@ -69,7 -79,9 +77,7 @@@ void html_ntxt(int len, char *txt
        while(t && *t && len--){
                int c = *t;
                if (c=='<' || c=='>' || c=='&') {
 -                      *t = '\0';
 -                      html(txt);
 -                      *t = c;
 +                      write(htmlfd, txt, t - txt);
                        if (c=='>')
                                html("&gt;");
                        else if (c=='<')
                }
                t++;
        }
 -      if (t!=txt) {
 -              char c = *t;
 -              *t = '\0';
 -              html(txt);
 -              *t = c;
 -      }
 +      if (t!=txt)
 +              write(htmlfd, txt, t - txt);
        if (len<0)
                html("...");
  }
@@@ -92,7 -108,9 +100,7 @@@ void html_attr(char *txt
        while(t && *t){
                int c = *t;
                if (c=='<' || c=='>' || c=='\'') {
 -                      *t = '\0';
 -                      html(txt);
 -                      *t = c;
 +                      write(htmlfd, txt, t - txt);
                        if (c=='>')
                                html("&gt;");
                        else if (c=='<')
@@@ -150,25 -168,10 +158,10 @@@ void html_link_close(void
  
  void html_fileperm(unsigned short mode)
  {
-       htmlf("%c%c%c", (mode & 4 ? 'r' : '-'), 
+       htmlf("%c%c%c", (mode & 4 ? 'r' : '-'),
              (mode & 2 ? 'w' : '-'), (mode & 1 ? 'x' : '-'));
  }
  
- void html_filemode(unsigned short mode)
- {
-       if (S_ISDIR(mode))
-               html("d");
-       else if (S_ISLNK(mode))
-               html("l");
-       else if (S_ISGITLINK(mode))
-               html("m");
-       else
-               html("-");
-       html_fileperm(mode >> 6);
-       html_fileperm(mode >> 3);
-       html_fileperm(mode);
- }
  int html_include(const char *filename)
  {
        FILE *f;
        fclose(f);
        return 0;
  }
+ int hextoint(char c)
+ {
+       if (c >= 'a' && c <= 'f')
+               return 10 + c - 'a';
+       else if (c >= 'A' && c <= 'F')
+               return 10 + c - 'A';
+       else if (c >= '0' && c <= '9')
+               return c - '0';
+       else
+               return -1;
+ }
+ char *convert_query_hexchar(char *txt)
+ {
+       int d1, d2;
+       if (strlen(txt) < 3) {
+               *txt = '\0';
+               return txt-1;
+       }
+       d1 = hextoint(*(txt+1));
+       d2 = hextoint(*(txt+2));
+       if (d1<0 || d2<0) {
+               strcpy(txt, txt+3);
+               return txt-1;
+       } else {
+               *txt = d1 * 16 + d2;
+               strcpy(txt+1, txt+3);
+               return txt;
+       }
+ }
+ int http_parse_querystring(char *txt, void (*fn)(const char *name, const char *value))
+ {
+       char *t, *value = NULL, c;
+       if (!txt)
+               return 0;
+       t = txt = strdup(txt);
+       if (t == NULL) {
+               printf("Out of memory\n");
+               exit(1);
+       }
+       while((c=*t) != '\0') {
+               if (c=='=') {
+                       *t = '\0';
+                       value = t+1;
+               } else if (c=='+') {
+                       *t = ' ';
+               } else if (c=='%') {
+                       t = convert_query_hexchar(t);
+               } else if (c=='&') {
+                       *t = '\0';
+                       (*fn)(txt, value);
+                       txt = t+1;
+                       value = NULL;
+               }
+               t++;
+       }
+       if (t!=txt)
+               (*fn)(txt, value);
+       return 0;
+ }
diff --combined ui-patch.c
index 7ee2c416ee3825630b0c7014b12a99020555a0b5,36bfae4836df393cd1c24c94b58e15702e2bc134..c1c4ce30368d668b954d460a4df3b836da58db4f
@@@ -7,6 -7,8 +7,8 @@@
   */
  
  #include "cgit.h"
+ #include "html.h"
+ #include "ui-shared.h"
  
  static void print_line(char *line, int len)
  {
@@@ -68,7 -70,7 +70,7 @@@ static void filepair_cb(struct diff_fil
                html("Error running diff");
  }
  
- void cgit_print_patch(char *hex, struct cacheitem *item)
+ void cgit_print_patch(char *hex)
  {
        struct commit *commit;
        struct commitinfo *info;
@@@ -76,7 -78,7 +78,7 @@@
        char *patchname;
  
        if (!hex)
-               hex = cgit_query_head;
+               hex = ctx.qry.head;
  
        if (get_sha1(hex, sha1)) {
                cgit_print_error(fmt("Bad object id: %s", hex));
                return;
        }
        info = cgit_parse_commit(commit);
 -      hashcpy(old_sha1, commit->parents->item->object.sha1);
 +
 +      if (commit->parents && commit->parents->item)
 +              hashcpy(old_sha1, commit->parents->item->object.sha1);
 +      else
 +              hashclr(old_sha1);
  
        patchname = fmt("%s.patch", sha1_to_hex(sha1));
-       cgit_print_snapshot_start("text/plain", patchname, item);
+       ctx.page.mimetype = "text/plain";
+       ctx.page.filename = patchname;
+       cgit_print_http_headers(&ctx);
        htmlf("From %s Mon Sep 17 00:00:00 2001\n", sha1_to_hex(sha1));
        htmlf("From: %s%s\n", info->author, info->author_email);
        html("Date: ");