diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 75 | ||||
-rw-r--r-- | cache.c | 21 | ||||
-rw-r--r-- | cache.h | 23 | ||||
-rw-r--r-- | cgit.c | 391 | ||||
-rw-r--r-- | cgit.h | 237 | ||||
-rw-r--r-- | cmd.c | 112 | ||||
-rw-r--r-- | cmd.h | 15 | ||||
-rw-r--r-- | configfile.c | 87 | ||||
-rw-r--r-- | configfile.h | 8 | ||||
-rw-r--r-- | html.c | 95 | ||||
-rw-r--r-- | html.h | 20 | ||||
-rw-r--r-- | parsing.c | 146 | ||||
-rw-r--r-- | shared.c | 257 | ||||
-rw-r--r-- | ui-blob.c | 16 | ||||
-rw-r--r-- | ui-blob.h | 6 | ||||
-rw-r--r-- | ui-commit.c | 26 | ||||
-rw-r--r-- | ui-commit.h | 6 | ||||
-rw-r--r-- | ui-diff.c | 9 | ||||
-rw-r--r-- | ui-diff.h | 7 | ||||
-rw-r--r-- | ui-log.c | 32 | ||||
-rw-r--r-- | ui-log.h | 7 | ||||
-rw-r--r-- | ui-patch.c | 10 | ||||
-rw-r--r-- | ui-patch.h | 6 | ||||
-rw-r--r-- | ui-refs.c | 175 | ||||
-rw-r--r-- | ui-refs.h | 8 | ||||
-rw-r--r-- | ui-repolist.c | 54 | ||||
-rw-r--r-- | ui-repolist.h | 6 | ||||
-rw-r--r-- | ui-shared.c | 237 | ||||
-rw-r--r-- | ui-shared.h | 36 | ||||
-rw-r--r-- | ui-snapshot.c | 123 | ||||
-rw-r--r-- | ui-snapshot.h | 8 | ||||
-rw-r--r-- | ui-summary.c | 189 | ||||
-rw-r--r-- | ui-summary.h | 6 | ||||
-rw-r--r-- | ui-tag.c | 3 | ||||
-rw-r--r-- | ui-tag.h | 6 | ||||
-rw-r--r-- | ui-tree.c | 26 | ||||
-rw-r--r-- | ui-tree.h | 6 |
38 files changed, 1379 insertions, 1117 deletions
@@ -3,3 +3,4 @@ cgit | |||
3 | cgit.conf | 3 | cgit.conf |
4 | VERSION | 4 | VERSION |
5 | *.o | 5 | *.o |
6 | *.d | ||
@@ -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 | # | ||
19 | QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir | ||
20 | QUIET_SUBDIR1 = | ||
15 | 21 | ||
16 | EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto | 22 | ifneq ($(findstring $(MAKEFLAGS),w),w) |
17 | OBJECTS = shared.o cache.o parsing.o html.o ui-shared.o ui-repolist.o \ | 23 | PRINT_DIR = --no-print-directory |
18 | ui-summary.o ui-log.o ui-tree.o ui-commit.o ui-diff.o \ | 24 | else # "make -w" |
19 | ui-snapshot.o ui-blob.o ui-tag.o ui-refs.o ui-patch.o | 25 | NO_SUBDIR = : |
26 | endif | ||
27 | |||
28 | ifndef 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 | ||
34 | endif | ||
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 | ||
49 | EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto | ||
50 | OBJECTS = | ||
51 | OBJECTS += cache.o | ||
52 | OBJECTS += cgit.o | ||
53 | OBJECTS += cmd.o | ||
54 | OBJECTS += configfile.o | ||
55 | OBJECTS += html.o | ||
56 | OBJECTS += parsing.o | ||
57 | OBJECTS += shared.o | ||
58 | OBJECTS += ui-blob.o | ||
59 | OBJECTS += ui-commit.o | ||
60 | OBJECTS += ui-diff.o | ||
61 | OBJECTS += ui-log.o | ||
62 | OBJECTS += ui-patch.o | ||
63 | OBJECTS += ui-refs.o | ||
64 | OBJECTS += ui-repolist.o | ||
65 | OBJECTS += ui-shared.o | ||
66 | OBJECTS += ui-snapshot.o | ||
67 | OBJECTS += ui-summary.o | ||
68 | OBJECTS += ui-tag.o | ||
69 | OBJECTS += ui-tree.o | ||
70 | |||
22 | ifdef NEEDS_LIBICONV | 71 | ifdef NEEDS_LIBICONV |
23 | EXTLIBS += -liconv | 72 | EXTLIBS += -liconv |
24 | endif | 73 | endif |
@@ -41,21 +90,25 @@ CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"' | |||
41 | CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"' | 90 | CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"' |
42 | 91 | ||
43 | 92 | ||
44 | cgit: cgit.c $(OBJECTS) | 93 | cgit: $(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 | |||
98 | cgit.o: VERSION | ||
46 | 99 | ||
47 | $(OBJECTS): cgit.h git/xdiff/lib.a git/libgit.a VERSION | 100 | -include $(OBJECTS:.o=.d) |
48 | 101 | ||
49 | git/xdiff/lib.a: | git | 102 | git/xdiff/lib.a: | git |
50 | 103 | ||
51 | git/libgit.a: | git | 104 | git/libgit.a: | git |
52 | 105 | ||
53 | git: | 106 | git: |
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 | ||
57 | test: all | 110 | test: all |
58 | $(MAKE) -C tests | 111 | $(QUIET_SUBDIR0)tests $(QUIET_SUBDIR1) all |
59 | 112 | ||
60 | install: all | 113 | install: 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 | ||
71 | clean: | 124 | clean: |
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 | ||
75 | distclean: clean | 128 | distclean: clean |
@@ -7,6 +7,7 @@ | |||
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | #include "cache.h" | ||
10 | 11 | ||
11 | const int NOLOCK = -1; | 12 | const 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 | ||
80 | int cache_lock(struct cacheitem *item) | 81 | int 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 | ||
@@ -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 | |||
9 | struct cacheitem { | ||
10 | char *name; | ||
11 | struct stat st; | ||
12 | int ttl; | ||
13 | int fd; | ||
14 | }; | ||
15 | |||
16 | extern char *cache_safe_filename(const char *unsafe); | ||
17 | extern int cache_lock(struct cacheitem *item); | ||
18 | extern int cache_unlock(struct cacheitem *item); | ||
19 | extern int cache_cancel_lock(struct cacheitem *item); | ||
20 | extern int cache_exist(struct cacheitem *item); | ||
21 | extern int cache_expired(struct cacheitem *item); | ||
22 | |||
23 | #endif /* CGIT_CACHE_H */ | ||
@@ -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 | |||
16 | const char *cgit_version = CGIT_VERSION; | ||
17 | |||
18 | void 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")) | ||