aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Makefile75
-rw-r--r--cache.c21
-rw-r--r--cache.h23
-rw-r--r--cgit.c391
-rw-r--r--cgit.h237
-rw-r--r--cmd.c112
-rw-r--r--cmd.h15
-rw-r--r--configfile.c87
-rw-r--r--configfile.h8
-rw-r--r--html.c95
-rw-r--r--html.h20
-rw-r--r--parsing.c146
-rw-r--r--shared.c257
-rw-r--r--ui-blob.c16
-rw-r--r--ui-blob.h6
-rw-r--r--ui-commit.c26
-rw-r--r--ui-commit.h6
-rw-r--r--ui-diff.c9
-rw-r--r--ui-diff.h7
-rw-r--r--ui-log.c32
-rw-r--r--ui-log.h7
-rw-r--r--ui-patch.c10
-rw-r--r--ui-patch.h6
-rw-r--r--ui-refs.c175
-rw-r--r--ui-refs.h8
-rw-r--r--ui-repolist.c54
-rw-r--r--ui-repolist.h6
-rw-r--r--ui-shared.c237
-rw-r--r--ui-shared.h36
-rw-r--r--ui-snapshot.c123
-rw-r--r--ui-snapshot.h8
-rw-r--r--ui-summary.c189
-rw-r--r--ui-summary.h6
-rw-r--r--ui-tag.c3
-rw-r--r--ui-tag.h6
-rw-r--r--ui-tree.c26
-rw-r--r--ui-tree.h6
38 files changed, 1379 insertions, 1117 deletions
diff --git a/.gitignore b/.gitignore
index aa36ff7..1e016e5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,4 @@ cgit
3cgit.conf 3cgit.conf
4VERSION 4VERSION
5*.o 5*.o
6*.d
diff --git a/Makefile b/Makefile
index 8bf47f2..931c60e 100644
--- a/Makefile
+++ b/Makefile
@@ -12,13 +12,62 @@ GIT_URL = http://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.bz2
12# 12#
13-include cgit.conf 13-include cgit.conf
14 14
15#
16# Define a way to invoke make in subdirs quietly, shamelessly ripped
17# from git.git
18#
19QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir
20QUIET_SUBDIR1 =
15 21
16EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto 22ifneq ($(findstring $(MAKEFLAGS),w),w)
17OBJECTS = shared.o cache.o parsing.o html.o ui-shared.o ui-repolist.o \ 23PRINT_DIR = --no-print-directory
18 ui-summary.o ui-log.o ui-tree.o ui-commit.o ui-diff.o \ 24else # "make -w"
19 ui-snapshot.o ui-blob.o ui-tag.o ui-refs.o ui-patch.o 25NO_SUBDIR = :
26endif
27
28ifndef V
29 QUIET_CC = @echo ' ' CC $@;
30 QUIET_MM = @echo ' ' MM $@;
31 QUIET_SUBDIR0 = +@subdir=
32 QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \
33 $(MAKE) $(PRINT_DIR) -C $$subdir
34endif
35
36#
37# Define a pattern rule for automatic dependency building
38#
39%.d: %.c
40 $(QUIET_MM)$(CC) $(CFLAGS) -MM $< | sed -e 's/\($*\)\.o:/\1.o $@:/g' >$@
41
42#
43# Define a pattern rule for silent object building
44#
45%.o: %.c
46 $(QUIET_CC)$(CC) -o $*.o -c $(CFLAGS) $<
20 47
21 48
49EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto
50OBJECTS =
51OBJECTS += cache.o
52OBJECTS += cgit.o
53OBJECTS += cmd.o
54OBJECTS += configfile.o
55OBJECTS += html.o
56OBJECTS += parsing.o
57OBJECTS += shared.o
58OBJECTS += ui-blob.o
59OBJECTS += ui-commit.o
60OBJECTS += ui-diff.o
61OBJECTS += ui-log.o
62OBJECTS += ui-patch.o
63OBJECTS += ui-refs.o
64OBJECTS += ui-repolist.o
65OBJECTS += ui-shared.o
66OBJECTS += ui-snapshot.o
67OBJECTS += ui-summary.o
68OBJECTS += ui-tag.o
69OBJECTS += ui-tree.o
70
22ifdef NEEDS_LIBICONV 71ifdef NEEDS_LIBICONV
23 EXTLIBS += -liconv 72 EXTLIBS += -liconv
24endif 73endif
@@ -41,21 +90,25 @@ CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"'
41CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"' 90CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"'
42 91
43 92
44cgit: cgit.c $(OBJECTS) 93cgit: $(OBJECTS)
45 $(CC) $(CFLAGS) cgit.c -o cgit $(OBJECTS) $(EXTLIBS) 94 $(QUIET_CC)$(CC) $(CFLAGS) -o cgit $(OBJECTS) $(EXTLIBS)
95
96$(OBJECTS): git/xdiff/lib.a git/libgit.a
97
98cgit.o: VERSION
46 99
47$(OBJECTS): cgit.h git/xdiff/lib.a git/libgit.a VERSION 100-include $(OBJECTS:.o=.d)
48 101
49git/xdiff/lib.a: | git 102git/xdiff/lib.a: | git
50 103
51git/libgit.a: | git 104git/libgit.a: | git
52 105
53git: 106git:
54 cd git && $(MAKE) xdiff/lib.a 107 $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) xdiff/lib.a
55 cd git && $(MAKE) libgit.a 108 $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) libgit.a
56 109
57test: all 110test: all
58 $(MAKE) -C tests 111 $(QUIET_SUBDIR0)tests $(QUIET_SUBDIR1) all
59 112
60install: all 113install: all
61 mkdir -p $(DESTDIR)$(CGIT_SCRIPT_PATH) 114 mkdir -p $(DESTDIR)$(CGIT_SCRIPT_PATH)
@@ -69,7 +122,7 @@ uninstall:
69 rm -f $(CGIT_SCRIPT_PATH)/cgit.png 122 rm -f $(CGIT_SCRIPT_PATH)/cgit.png
70 123
71clean: 124clean:
72 rm -f cgit VERSION *.o 125 rm -f cgit VERSION *.o *.d
73 cd git && $(MAKE) clean 126 cd git && $(MAKE) clean
74 127
75distclean: clean 128distclean: clean
diff --git a/cache.c b/cache.c
index 372e38d..89f7ecd 100644
--- a/cache.c
+++ b/cache.c
@@ -7,6 +7,7 @@
7 */ 7 */
8 8
9#include "cgit.h" 9#include "cgit.h"
10#include "cache.h"
10 11
11const int NOLOCK = -1; 12const int NOLOCK = -1;
12 13
@@ -44,23 +45,23 @@ int cache_create_dirs()
44{ 45{
45 char *path; 46 char *path;
46 47
47 path = fmt("%s", cgit_cache_root); 48 path = fmt("%s", ctx.cfg.cache_root);
48 if (mkdir(path, S_IRWXU) && errno!=EEXIST) 49 if (mkdir(path, S_IRWXU) && errno!=EEXIST)
49 return 0; 50 return 0;
50 51
51 if (!cgit_repo) 52 if (!ctx.repo)
52 return 0; 53 return 0;
53 54
54 path = fmt("%s/%s", cgit_cache_root, 55 path = fmt("%s/%s", ctx.cfg.cache_root,
55 cache_safe_filename(cgit_repo->url)); 56 cache_safe_filename(ctx.repo->url));
56 57
57 if (mkdir(path, S_IRWXU) && errno!=EEXIST) 58 if (mkdir(path, S_IRWXU) && errno!=EEXIST)
58 return 0; 59 return 0;
59 60
60 if (cgit_query_page) { 61 if (ctx.qry.page) {
61 path = fmt("%s/%s/%s", cgit_cache_root, 62 path = fmt("%s/%s/%s", ctx.cfg.cache_root,
62 cache_safe_filename(cgit_repo->url), 63 cache_safe_filename(ctx.repo->url),
63 cgit_query_page); 64 ctx.qry.page);
64 if (mkdir(path, S_IRWXU) && errno!=EEXIST) 65 if (mkdir(path, S_IRWXU) && errno!=EEXIST)
65 return 0; 66 return 0;
66 } 67 }
@@ -74,7 +75,7 @@ int cache_refill_overdue(const char *lockfile)
74 if (stat(lockfile, &st)) 75 if (stat(lockfile, &st))
75 return 0; 76 return 0;
76 else 77 else
77 return (time(NULL) - st.st_mtime > cgit_cache_max_create_time); 78 return (time(NULL) - st.st_mtime > ctx.cfg.cache_max_create_time);
78} 79}
79 80
80int cache_lock(struct cacheitem *item) 81int cache_lock(struct cacheitem *item)
@@ -83,7 +84,7 @@ int cache_lock(struct cacheitem *item)
83 char *lockfile = xstrdup(fmt("%s.lock", item->name)); 84 char *lockfile = xstrdup(fmt("%s.lock", item->name));
84 85
85 top: 86 top:
86 if (++i > cgit_max_lock_attempts) 87 if (++i > ctx.cfg.max_lock_attempts)
87 die("cache_lock: unable to lock %s: %s", 88 die("cache_lock: unable to lock %s: %s",
88 item->name, strerror(errno)); 89 item->name, strerror(errno));
89 90
diff --git a/cache.h b/cache.h
new file mode 100644
index 0000000..4dcbea3
--- /dev/null
+++ b/cache.h
@@ -0,0 +1,23 @@
1/*
2 * Since git has it's own cache.h which we include,
3 * lets test on CGIT_CACHE_H to avoid confusion
4 */
5
6#ifndef CGIT_CACHE_H
7#define CGIT_CACHE_H
8
9struct cacheitem {
10 char *name;
11 struct stat st;
12 int ttl;
13 int fd;
14};
15
16extern char *cache_safe_filename(const char *unsafe);
17extern int cache_lock(struct cacheitem *item);
18extern int cache_unlock(struct cacheitem *item);
19extern int cache_cancel_lock(struct cacheitem *item);
20extern int cache_exist(struct cacheitem *item);
21extern int cache_expired(struct cacheitem *item);
22
23#endif /* CGIT_CACHE_H */
diff --git a/cgit.c b/cgit.c
index e8acc03..6ec763f 100644
--- a/cgit.c
+++ b/cgit.c
@@ -7,40 +7,199 @@
7 */ 7 */
8 8
9#include "cgit.h" 9#include "cgit.h"
10#include "cache.h"
11#include "cmd.h"
12#include "configfile.h"
13#include "html.h"
14#include "ui-shared.h"
15
16const char *cgit_version = CGIT_VERSION;
17
18void config_cb(const char *name, const char *value)
19{
20 if (!strcmp(name, "root-title"))
21 ctx.cfg.root_title = xstrdup(value);
22 else if (!strcmp(name, "css"))
23 ctx.cfg.css = xstrdup(value);
24 else if (!strcmp(name, "logo"))
25 ctx.cfg.logo = xstrdup(value);
26 else if (!strcmp(name, "index-header"))
27 ctx.cfg.index_header = xstrdup(value);
28 else if (!strcmp(name, "index-info"))
29 ctx.cfg.index_info = xstrdup(value);
30 else if (!strcmp(name, "logo-link"))
31 ctx.cfg.logo_link = xstrdup(value);
32 else if (!strcmp(name, "module-link"))
33 ctx.cfg.module_link = xstrdup(value);
34 else if (!strcmp(name, "virtual-root")) {
35 ctx.cfg.virtual_root = trim_end(value, '/');
36 if (!ctx.cfg.virtual_root && (!strcmp(value, "/")))
37 ctx.cfg.virtual_root = "";
38 } else if (!strcmp(name, "nocache"))
39 ctx.cfg.nocache = atoi(value);
40 else if (!strcmp(name, "snapshots"))
41 ctx.cfg.snapshots = cgit_parse_snapshots_mask(value);
42 else if (!strcmp(name, "enable-index-links"))
43 ctx.cfg.enable_index_links = atoi(value);
44 else if (!strcmp(name, "enable-log-filecount"))
45 ctx.cfg.enable_log_filecount = atoi(value);
46 else if (!strcmp(name, "enable-log-linecount"))
47 ctx.cfg.enable_log_linecount = atoi(value);
48 else if (!strcmp(name, "cache-root"))
49 ctx.cfg.cache_root = xstrdup(value);
50 else if (!strcmp(name, "cache-root-ttl"))
51 ctx.cfg.cache_root_ttl = atoi(value);
52 else if (!strcmp(name, "cache-repo-ttl"))
53 ctx.cfg.cache_repo_ttl = atoi(value);
54 else if (!strcmp(name, "cache-static-ttl"))
55 ctx.cfg.cache_static_ttl = atoi(value);
56 else if (!strcmp(name, "cache-dynamic-ttl"))
57 ctx.cfg.cache_dynamic_ttl = atoi(value);
58 else if (!strcmp(name, "max-message-length"))
59 ctx.cfg.max_msg_len = atoi(value);
60 else if (!strcmp(name, "max-repodesc-length"))
61 ctx.cfg.max_repodesc_len = atoi(value);
62 else if (!strcmp(name, "max-commit-count"))
63 ctx.cfg.max_commit_count = atoi(value);
64 else if (!strcmp(name, "summary-log"))
65 ctx.cfg.summary_log = atoi(value);
66 else if (!strcmp(name, "summary-branches"))
67 ctx.cfg.summary_branches = atoi(value);
68 else if (!strcmp(name, "summary-tags"))
69 ctx.cfg.summary_tags = atoi(value);
70 else if (!strcmp(name, "agefile"))
71 ctx.cfg.agefile = xstrdup(value);
72 else if (!strcmp(name, "renamelimit"))
73 ctx.cfg.renamelimit = atoi(value);
74 else if (!strcmp(name, "robots"))
75 ctx.cfg.robots = xstrdup(value);
76 else if (!strcmp(name, "clone-prefix"))
77 ctx.cfg.clone_prefix = xstrdup(value);
78 else if (!strcmp(name, "repo.group"))
79 ctx.cfg.repo_group = xstrdup(value);
80 else if (!strcmp(name, "repo.url"))
81 ctx.repo = cgit_add_repo(value);
82 else if (!strcmp(name, "repo.name"))
83 ctx.repo->name = xstrdup(value);
84 else if (ctx.repo && !strcmp(name, "repo.path"))
85 ctx.repo->path = trim_end(value, '/');
86 else if (ctx.repo && !strcmp(name, "repo.clone-url"))
87 ctx.repo->clone_url = xstrdup(value);
88 else if (ctx.repo && !strcmp(name, "repo.desc"))
89 ctx.repo->desc = xstrdup(value);
90 else if (ctx.repo && !strcmp(name, "repo.owner"))
91 ctx.repo->owner = xstrdup(value);
92 else if (ctx.repo && !strcmp(name, "repo.defbranch"))
93 ctx.repo->defbranch = xstrdup(value);
94 else if (ctx.repo && !strcmp(name, "repo.snapshots"))
95 ctx.repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */
96 else if (ctx.repo && !strcmp(name, "repo.enable-log-filecount"))
97 ctx.repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value);
98 else if (ctx.repo && !strcmp(name, "repo.enable-log-linecount"))
99 ctx.repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value);
100 else if (ctx.repo && !strcmp(name, "repo.module-link"))