diff options
| author | 2006-12-09 23:18:17 (JST) | |
|---|---|---|
| committer | 2006-12-09 23:18:17 (JST) | |
| commit | 0d169ada2ba81210ab1191a5f2212662e90db77e (patch) | |
| tree | 402b54583db269323ebb28e5fbf2075c4c1b3d85 | |
| download | cgit-0d169ada2ba81210ab1191a5f2212662e90db77e.zip cgit-0d169ada2ba81210ab1191a5f2212662e90db77e.tar.gz | |
Import cgit prototype from git tree
This enables basic cgit functionality, using libgit.a and xdiff/lib.a from
git + a custom "git.h" + openssl for sha1 routines.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
| -rw-r--r-- | Makefile | 24 | ||||
| -rw-r--r-- | cgit.c | 410 | ||||
| -rw-r--r-- | cgit.css | 63 | ||||
| -rw-r--r-- | cgit.h | 21 | ||||
| -rw-r--r-- | config.c | 73 | ||||
| -rw-r--r-- | git.h | 399 | ||||
| -rw-r--r-- | html.c | 100 |
7 files changed, 1090 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1470c0a --- /dev/null +++ b/Makefile | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | |||
| 2 | INSTALL_BIN = /var/www/htdocs/cgit.cgi | ||
| 3 | INSTALL_CSS = /var/www/htdocs/cgit.css | ||
| 4 | |||
| 5 | EXTLIBS = ../git/libgit.a ../git/xdiff/lib.a -lz -lcrypto | ||
| 6 | OBJECTS = cgit.o config.o html.o | ||
| 7 | |||
| 8 | all: cgit | ||
| 9 | |||
| 10 | install: all | ||
| 11 | install cgit $(INSTALL_BIN) | ||
| 12 | install cgit.css $(INSTALL_CSS) | ||
| 13 | |||
| 14 | clean: | ||
| 15 | rm -f cgit *.o | ||
| 16 | |||
| 17 | cgit: $(OBJECTS) | ||
| 18 | $(CC) -o cgit $(OBJECTS) $(EXTLIBS) | ||
| 19 | |||
| 20 | cgit.o: cgit.h git.h config.o html.o | ||
| 21 | |||
| 22 | config.o: cgit.h git.h html.c | ||
| 23 | |||
| 24 | html.o: cgit.h git.h html.c | ||
| @@ -0,0 +1,410 @@ | |||
| 1 | #include "cgit.h" | ||
| 2 | |||
| 3 | static const char cgit_doctype[] = | ||
| 4 | "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" | ||
| 5 | " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; | ||
| 6 | |||
| 7 | static const char cgit_error[] = | ||
| 8 | "<div class='error'>%s</div>"; | ||
| 9 | |||
| 10 | static const char cgit_lib_error[] = | ||
| 11 | "<div class='error'>%s: %s</div>"; | ||
| 12 | |||
| 13 | |||
| 14 | char *cgit_root = "/var/git"; | ||
| 15 | char *cgit_root_title = "Git repository browser"; | ||
| 16 | char *cgit_css = "/cgit.css"; | ||
| 17 | char *cgit_logo = "/git-logo.png"; | ||
| 18 | char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; | ||
| 19 | char *cgit_virtual_root = NULL; | ||
| 20 | |||
| 21 | char *cgit_repo_name = NULL; | ||
| 22 | char *cgit_repo_desc = NULL; | ||
| 23 | char *cgit_repo_owner = NULL; | ||
| 24 | |||
| 25 | char *cgit_query_repo = NULL; | ||
| 26 | char *cgit_query_page = NULL; | ||
| 27 | char *cgit_query_head = NULL; | ||
| 28 | |||
| 29 | int cgit_parse_query(char *txt, configfn fn) | ||
| 30 | { | ||
| 31 | char *t = txt, *value = NULL, c; | ||
| 32 | |||
| 33 | if (!txt) | ||
| 34 | return 0; | ||
| 35 | |||
| 36 | while((c=*t) != '\0') { | ||
| 37 | if (c=='=') { | ||
| 38 | *t = '\0'; | ||
| 39 | value = t+1; | ||
| 40 | } else if (c=='&') { | ||
| 41 | *t = '\0'; | ||
| 42 | (*fn)(txt, value); | ||
| 43 | txt = t+1; | ||
| 44 | value = NULL; | ||
| 45 | } | ||
| 46 | t++; | ||
| 47 | } | ||
| 48 | if (t!=txt) | ||
| 49 | (*fn)(txt, value); | ||
| 50 | return 0; | ||
| 51 | } | ||
| 52 | |||
| 53 | void cgit_global_config_cb(const char *name, const char *value) | ||
| 54 | { | ||
| 55 | if (!strcmp(name, "root")) | ||
| 56 | cgit_root = xstrdup(value); | ||
| 57 | else if (!strcmp(name, "root-title")) | ||
| 58 | cgit_root_title = xstrdup(value); | ||
| 59 | else if (!strcmp(name, "css")) | ||
| 60 | cgit_css = xstrdup(value); | ||
| 61 | else if (!strcmp(name, "logo")) | ||
| 62 | cgit_logo = xstrdup(value); | ||
| 63 | else if (!strcmp(name, "logo-link")) | ||
| 64 | cgit_logo_link = xstrdup(value); | ||
| 65 | else if (!strcmp(name, "virtual-root")) | ||
| 66 | cgit_virtual_root = xstrdup(value); | ||
| 67 | } | ||
| 68 | |||
| 69 | void cgit_repo_config_cb(const char *name, const char *value) | ||
| 70 | { | ||
| 71 | if (!strcmp(name, "name")) | ||
| 72 | cgit_repo_name = xstrdup(value); | ||
| 73 | else if (!strcmp(name, "desc")) | ||
| 74 | cgit_repo_desc = xstrdup(value); | ||
| 75 | else if (!strcmp(name, "owner")) | ||
| 76 | cgit_repo_owner = xstrdup(value); | ||
| 77 | } | ||
| 78 | |||
| 79 | void cgit_querystring_cb(const char *name, const char *value) | ||
| 80 | { | ||
| 81 | if (!strcmp(name,"r")) | ||
| 82 | cgit_query_repo = xstrdup(value); | ||
| 83 | else if (!strcmp(name, "p")) | ||
| 84 | cgit_query_page = xstrdup(value); | ||
| 85 | else if (!strcmp(name, "h")) | ||
| 86 | cgit_query_head = xstrdup(value); | ||
| 87 | } | ||
| 88 | |||
| 89 | char *cgit_repourl(const char *reponame) | ||
| 90 | { | ||
| 91 | if (cgit_virtual_root) { | ||
| 92 | return fmt("%s/%s/", cgit_virtual_root, reponame); | ||
| 93 | } else { | ||
| 94 | return fmt("?r=%s", reponame); | ||
| 95 | } | ||
| 96 | } | ||
| 97 | |||
| 98 | char *cgit_pageurl(const char *reponame, const char *pagename, | ||
| 99 | const char *query) | ||
| 100 | { | ||
| 101 | if (cgit_virtual_root) { | ||
| 102 | return fmt("%s/%s/%s/?%s", cgit_virtual_root, reponame, | ||
| 103 | pagename, query); | ||
| 104 | } else { | ||
| 105 | return fmt("?r=%s&p=%s&%s", reponame, pagename, query); | ||
| 106 | } | ||
| 107 | } | ||
| 108 | |||
| 109 | static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1, | ||
| 110 | int flags, void *cb_data) | ||
| 111 | { | ||
| 112 | struct commit *commit; | ||
| 113 | char buf[256], *url; | ||
| 114 | |||
| 115 | commit = lookup_commit(sha1); | ||
| 116 | if (commit && !parse_commit(commit)){ | ||
| 117 | html("<tr><td>"); | ||
| 118 | url = cgit_pageurl(cgit_query_repo, "log", | ||
| 119 | fmt("h=%s", refname)); | ||
| 120 | html_link_open(url, NULL, NULL); | ||
| 121 | strncpy(buf, refname, sizeof(buf)); | ||
| 122 | html_txt(buf); | ||
| 123 | html_link_close(); | ||
| 124 | html("</td><td>"); | ||
| 125 | pretty_print_commit(CMIT_FMT_ONELINE, commit, ~0, buf, | ||
| 126 | sizeof(buf), 0, NULL, NULL, 0); | ||
| 127 | html_txt(buf); | ||
| 128 | html("</td></tr>\n"); | ||
| 129 | } else { | ||
| 130 | html("<tr><td>"); | ||
| 131 | html_txt(buf); | ||
| 132 | html("</td><td>"); | ||
| 133 | htmlf("*** bad ref %s", sha1_to_hex(sha1)); | ||
| 134 | html("</td></tr>\n"); | ||
| 135 | } | ||
| 136 | return 0; | ||
| 137 | } | ||
| 138 | |||
| 139 | static void cgit_print_docstart(char *title) | ||
| 140 | { | ||
| 141 | html("Content-Type: text/html; charset=utf-8\n"); | ||
| 142 | html("\n"); | ||
| 143 | html(cgit_doctype); | ||
