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
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)
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
* (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];
}
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=='<')
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=='<')
}
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("...");
}
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=='<')
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;
+ }
*/
#include "cgit.h"
+ #include "html.h"
+ #include "ui-shared.h"
static void print_line(char *line, int len)
{
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;
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: ");