From: Lars Hjemli Date: Tue, 8 Apr 2008 19:29:21 +0000 (+0200) Subject: Merge branch 'lh/cleanup' X-Git-Url: https://gitweb.ps.run/ps-cgit/commitdiff_plain/23296ad648c0e2a9e3cf40a3de322b10ad25cce3?hp=-c Merge branch 'lh/cleanup' * 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 ... --- 23296ad648c0e2a9e3cf40a3de322b10ad25cce3 diff --combined Makefile index 8bf47f2,355186e..931c60e --- a/Makefile +++ 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 = -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 # @@@ -12,13 -12,62 +12,62 @@@ # -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 339bf00,98ffaf9..937b5e7 --- a/html.c +++ b/html.c @@@ -6,7 -6,13 +6,13 @@@ * (see COPYING for full license text) */ - #include "cgit.h" + #include + #include + #include + #include + #include + + int htmlfd = STDOUT_FILENO; char *fmt(const char *format, ...) { @@@ -21,8 -27,10 +27,10 @@@ 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(">"); 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(">"); else if (c=='<') @@@ -80,8 -92,12 +88,8 @@@ } 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(">"); 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; @@@ -182,3 -185,67 +175,67 @@@ 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 7ee2c41,36bfae4..c1c4ce3 --- a/ui-patch.c +++ b/ui-patch.c @@@ -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)); @@@ -88,14 -90,12 +90,16 @@@ 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: ");