diff options
| -rw-r--r-- | Makefile | 5 | ||||
| -rw-r--r-- | README | 13 | ||||
| -rw-r--r-- | cache.c | 28 | ||||
| -rw-r--r-- | cgit.c | 23 | ||||
| -rw-r--r-- | cgit.h | 1 | ||||
| -rw-r--r-- | cgit.mk | 44 | ||||
| -rw-r--r-- | cgitrc.5.txt | 42 | ||||
| -rw-r--r-- | cmd.c | 2 | ||||
| -rw-r--r-- | filters/simple-authentication.lua | 2 | ||||
| -rwxr-xr-x | gen-version.sh | 2 | ||||
| m--------- | git | 0 | ||||
| -rw-r--r-- | shared.c | 1 | ||||
| -rwxr-xr-x | tests/setup.sh | 12 | ||||
| -rwxr-xr-x | tests/t0111-filter.sh | 7 | ||||
| -rw-r--r-- | ui-refs.c | 16 | ||||
| -rw-r--r-- | ui-snapshot.c | 2 | ||||
| -rw-r--r-- | ui-snapshot.h | 2 |
17 files changed, 133 insertions, 69 deletions
| @@ -1,6 +1,6 @@ | |||
| 1 | all:: | 1 | all:: |
| 2 | 2 | ||
| 3 | CGIT_VERSION = v0.10 | 3 | CGIT_VERSION = v0.10.1 |
| 4 | CGIT_SCRIPT_NAME = cgit.cgi | 4 | CGIT_SCRIPT_NAME = cgit.cgi |
| 5 | CGIT_SCRIPT_PATH = /var/www/htdocs/cgit | 5 | CGIT_SCRIPT_PATH = /var/www/htdocs/cgit |
| 6 | CGIT_DATA_PATH = $(CGIT_SCRIPT_PATH) | 6 | CGIT_DATA_PATH = $(CGIT_SCRIPT_PATH) |
| @@ -14,7 +14,7 @@ htmldir = $(docdir) | |||
| 14 | pdfdir = $(docdir) | 14 | pdfdir = $(docdir) |
| 15 | mandir = $(prefix)/share/man | 15 | mandir = $(prefix)/share/man |
| 16 | SHA1_HEADER = <openssl/sha.h> | 16 | SHA1_HEADER = <openssl/sha.h> |
| 17 | GIT_VER = 1.8.5 | 17 | GIT_VER = 1.9.0 |
| 18 | GIT_URL = https://git-core.googlecode.com/files/git-$(GIT_VER).tar.gz | 18 | GIT_URL = https://git-core.googlecode.com/files/git-$(GIT_VER).tar.gz |
| 19 | INSTALL = install | 19 | INSTALL = install |
| 20 | COPYTREE = cp -r | 20 | COPYTREE = cp -r |
| @@ -29,6 +29,7 @@ DOC_PDF = $(patsubst %.txt,%.pdf,$(MAN_TXT)) | |||
| 29 | # j, z, t. (representing long long int, char, intmax_t, size_t, ptrdiff_t). | 29 | # j, z, t. (representing long long int, char, intmax_t, size_t, ptrdiff_t). |
| 30 | # some C compilers supported these specifiers prior to C99 as an extension. | 30 | # some C compilers supported these specifiers prior to C99 as an extension. |
| 31 | # | 31 | # |
| 32 | # Define HAVE_LINUX_SENDFILE to use sendfile() | ||
| 32 | 33 | ||
| 33 | #-include config.mak | 34 | #-include config.mak |
| 34 | 35 | ||
| @@ -38,14 +38,11 @@ If you'd like to compile without Lua support, you may use: | |||
| 38 | 38 | ||
| 39 | And if you'd like to specify a Lua implementation, you may use: | 39 | And if you'd like to specify a Lua implementation, you may use: |
| 40 | 40 | ||
| 41 | $ make LUA_IMPLEMENTATION=JIT | 41 | $ make LUA_PKGCONFIG=lua5.1 |
| 42 | 42 | ||
| 43 | for using the LuaJIT project. Or: | 43 | If this is not specified, the Lua implementation will be auto-detected, |
| 44 | 44 | preferring LuaJIT if many are present. Acceptable values are generally "lua", | |
| 45 | $ make LUA_IMPLEMENTATION=VANILLA | 45 | "luajit", "lua5.1", and "lua5.2". |
| 46 | |||
| 47 | for the mainline Lua project. If you specify neither implementation, it will | ||
| 48 | be auto-detected, preferring LuaJIT if both are present. | ||
| 49 | 46 | ||
| 50 | 47 | ||
| 51 | Dependencies | 48 | Dependencies |
| @@ -54,7 +51,7 @@ Dependencies | |||
| 54 | * libzip | 51 | * libzip |
| 55 | * libcrypto (OpenSSL) | 52 | * libcrypto (OpenSSL) |
| 56 | * libssl (OpenSSL) | 53 | * libssl (OpenSSL) |
| 57 | * optional: luajit or lua | 54 | * optional: luajit or lua, most reliably used when pkg-config is available |
| 58 | 55 | ||
| 59 | Apache configuration | 56 | Apache configuration |
| 60 | -------------------- | 57 | -------------------- |
| @@ -13,6 +13,9 @@ | |||
| 13 | * | 13 | * |
| 14 | */ | 14 | */ |
| 15 | 15 | ||
| 16 | #ifdef HAVE_LINUX_SENDFILE | ||
| 17 | #include <sys/sendfile.h> | ||
| 18 | #endif | ||
| 16 | #include "cgit.h" | 19 | #include "cgit.h" |
| 17 | #include "cache.h" | 20 | #include "cache.h" |
| 18 | #include "html.h" | 21 | #include "html.h" |
| @@ -30,7 +33,6 @@ struct cache_slot { | |||
| 30 | const char *lock_name; | 33 | const char *lock_name; |
| 31 | int match; | 34 | int match; |
| 32 | struct stat cache_st; | 35 | struct stat cache_st; |
| 33 | struct stat lock_st; | ||
| 34 | int bufsize; | 36 | int bufsize; |
| 35 | char buf[CACHE_BUFSIZE]; | 37 | char buf[CACHE_BUFSIZE]; |
| 36 | }; | 38 | }; |
| @@ -81,6 +83,23 @@ static int close_slot(struct cache_slot *slot) | |||
| 81 | /* Print the content of the active cache slot (but skip the key). */ | 83 | /* Print the content of the active cache slot (but skip the key). */ |
| 82 | static int print_slot(struct cache_slot *slot) | 84 | static int print_slot(struct cache_slot *slot) |
| 83 | { | 85 | { |
| 86 | #ifdef HAVE_LINUX_SENDFILE | ||
| 87 | off_t start_off; | ||
| 88 | int ret; | ||
| 89 | |||
| 90 | start_off = slot->keylen + 1; | ||
| 91 | |||
| 92 | do { | ||
| 93 | ret = sendfile(STDOUT_FILENO, slot->cache_fd, &start_off, | ||
| 94 | slot->cache_st.st_size - start_off); | ||
| 95 | if (ret < 0) { | ||
| 96 | if (errno == EAGAIN || errno == EINTR) | ||
| 97 | continue; | ||
| 98 | return errno; | ||
| 99 | } | ||
| 100 | return 0; | ||
| 101 | } while (1); | ||
| 102 | #else | ||
| 84 | ssize_t i, j; | 103 | ssize_t i, j; |
| 85 | 104 | ||
| 86 | i = lseek(slot->cache_fd, slot->keylen + 1, SEEK_SET); | 105 | i = lseek(slot->cache_fd, slot->keylen + 1, SEEK_SET); |
| @@ -97,6 +116,7 @@ static int print_slot(struct cache_slot *slot) | |||
| 97 | return errno; | 116 | return errno; |
| 98 | else | 117 | else |
| 99 | return 0; | 118 | return 0; |
| 119 | #endif | ||
| 100 | } | 120 | } |
| 101 | 121 | ||
| 102 | /* Check if the slot has expired */ | 122 | /* Check if the slot has expired */ |
| @@ -188,6 +208,10 @@ static int fill_slot(struct cache_slot *slot) | |||
| 188 | /* Generate cache content */ | 208 | /* Generate cache content */ |
| 189 | slot->fn(); | 209 | slot->fn(); |
| 190 | 210 | ||
| 211 | /* update stat info */ | ||
| 212 | if (fstat(slot->lock_fd, &slot->cache_st)) | ||
| 213 | return errno; | ||
| 214 | |||
| 191 | /* Restore stdout */ | 215 | /* Restore stdout */ |
| 192 | if (dup2(tmp, STDOUT_FILENO) == -1) | 216 | if (dup2(tmp, STDOUT_FILENO) == -1) |
| 193 | return errno; | 217 | return errno; |
| @@ -319,7 +343,7 @@ int cache_process(int size, const char *path, const char *key, int ttl, | |||
| 319 | int result; | 343 | int result; |
| 320 | 344 | ||
| 321 | /* If the cache is disabled, just generate the content */ | 345 | /* If the cache is disabled, just generate the content */ |
| 322 | if (size <= 0) { | 346 | if (size <= 0 || ttl == 0) { |
| 323 | fn(); | 347 | fn(); |
| 324 | return 0; | 348 | return 0; |
| 325 | } | 349 | } |
| @@ -184,6 +184,8 @@ static void config_cb(const char *name, const char *value) | |||
| 184 | ctx.cfg.cache_dynamic_ttl = atoi(value); | 184 | ctx.cfg.cache_dynamic_ttl = atoi(value); |
| 185 | else if (!strcmp(name, "cache-about-ttl")) | 185 | else if (!strcmp(name, "cache-about-ttl")) |
| 186 | ctx.cfg.cache_about_ttl = atoi(value); | 186 | ctx.cfg.cache_about_ttl = atoi(value); |
| 187 | else if (!strcmp(name, "cache-snapshot-ttl")) | ||
| 188 | ctx.cfg.cache_snapshot_ttl = atoi(value); | ||
| 187 | else if (!strcmp(name, "case-sensitive-sort")) | 189 | else if (!strcmp(name, "case-sensitive-sort")) |
| 188 | ctx.cfg.case_sensitive_sort = atoi(value); | 190 | ctx.cfg.case_sensitive_sort = atoi(value); |
| 189 | else if (!strcmp(name, "about-filter")) | 191 | else if (!strcmp(name, "about-filter")) |
| @@ -331,6 +333,7 @@ static void prepare_context(void) | |||
| 331 | ctx.cfg.cache_max_create_time = 5; | 333 | ctx.cfg.cache_max_create_time = 5; |
| 332 | ctx.cfg.cache_root = CGIT_CACHE_ROOT; | 334 | ctx.cfg.cache_root = CGIT_CACHE_ROOT; |
| 333 | ctx.cfg.cache_about_ttl = 15; | 335 | ctx.cfg.cache_about_ttl = 15; |
| 336 | ctx.cfg.cache_snapshot_ttl = 5; | ||
| 334 | ctx.cfg.cache_repo_ttl = 5; | 337 | ctx.cfg.cache_repo_ttl = 5; |
| 335 | ctx.cfg.cache_root_ttl = 5; | 338 | ctx.cfg.cache_root_ttl = 5; |
| 336 | ctx.cfg.cache_scanrc_ttl = 15; | 339 | ctx.cfg.cache_scanrc_ttl = 15; |
| @@ -921,6 +924,23 @@ static void cgit_parse_args(int argc, const char **argv) | |||
| 921 | int scan = 0; | 924 | int scan = 0; |
| 922 | 925 | ||
| 923 | for (i = 1; i < argc; i++) { | 926 | for (i = 1; i < argc; i++) { |
| 927 | if (!strcmp(argv[i], "--version")) { | ||
| 928 | printf("CGit %s | http://git.zx2c4.com/cgit/\n\nCompiled in features:\n", CGIT_VERSION); | ||
| 929 | #ifdef NO_LUA | ||
| 930 | printf("[-] "); | ||
| 931 | #else | ||
| 932 | printf("[+] "); | ||
| 933 | #endif | ||
| 934 | printf("Lua scripting\n"); | ||
| 935 | #ifndef HAVE_LINUX_SENDFILE | ||
| 936 | printf("[-] "); | ||
| 937 | #else | ||
| 938 | printf("[+] "); | ||
| 939 | #endif | ||
| 940 | printf("Linux sendfile() usage\n"); | ||
| 941 | |||
| 942 | exit(0); | ||
| 943 | } | ||
| 924 | if (!prefixcmp(argv[i], "--cache=")) { | 944 | if (!prefixcmp(argv[i], "--cache=")) { |
| 925 | ctx.cfg.cache_root = xstrdup(argv[i] + 8); | 945 | ctx.cfg.cache_root = xstrdup(argv[i] + 8); |
| 926 | } else if (!strcmp(argv[i], "--nocache")) { | 946 | } else if (!strcmp(argv[i], "--nocache")) { |
| @@ -978,6 +998,9 @@ static int calc_ttl() | |||
| 978 | if (!strcmp(ctx.qry.page, "about")) | 998 | if (!strcmp(ctx.qry.page, "about")) |
| 979 | return ctx.cfg.cache_about_ttl; | 999 | return ctx.cfg.cache_about_ttl; |
| 980 | 1000 | ||
| 1001 | if (!strcmp(ctx.qry.page, "snapshot")) | ||
| 1002 | return ctx.cfg.cache_snapshot_ttl; | ||
| 1003 | |||
| 981 | if (ctx.qry.has_sha1) | 1004 | if (ctx.qry.has_sha1) |
| 982 | return ctx.cfg.cache_static_ttl; | 1005 | return ctx.cfg.cache_static_ttl; |
| 983 | 1006 | ||
| @@ -210,6 +210,7 @@ struct cgit_config { | |||
| 210 | int cache_scanrc_ttl; | 210 | int cache_scanrc_ttl; |
| 211 | int cache_static_ttl; | 211 | int cache_static_ttl; |
| 212 | int cache_about_ttl; | 212 | int cache_about_ttl; |
| 213 | int cache_snapshot_ttl; | ||
| 213 | int case_sensitive_sort; | 214 | int case_sensitive_sort; |
| 214 | int embedded; | 215 | int embedded; |
| 215 | int enable_filter_overrides; | 216 | int enable_filter_overrides; |
| @@ -29,30 +29,18 @@ ifdef NO_LUA | |||
| 29 | LUA_MESSAGE := linking without specified Lua support | 29 | LUA_MESSAGE := linking without specified Lua support |
| 30 | CGIT_CFLAGS += -DNO_LUA | 30 | CGIT_CFLAGS += -DNO_LUA |
| 31 | else | 31 | else |
| 32 | LUAJIT_CFLAGS := $(shell pkg-config --cflags luajit 2>/dev/null) | 32 | ifeq ($(LUA_PKGCONFIG),) |
| 33 | LUAJIT_LIBS := $(shell pkg-config --libs luajit 2>/dev/null) | 33 | LUA_PKGCONFIG := $(shell for pc in luajit lua lua5.2 lua5.1; do \ |
| 34 | LUA_LIBS := $(shell pkg-config --libs lua 2>/dev/null) | 34 | pkg-config --exists $$pc 2>/dev/null && echo $$pc && break; \ |
| 35 | LUA_CFLAGS := $(shell pkg-config --cflags lua 2>/dev/null) | 35 | done) |
| 36 | ifeq (JIT,$(LUA_IMPLEMENTATION)) | 36 | LUA_MODE := autodetected |
| 37 | ifeq ($(strip $(LUAJIT_LIBS)),) | 37 | else |
| 38 | $(error LuaJIT specified via LUA_IMPLEMENTATION=JIT, but library could not be found.) | 38 | LUA_MODE := specified |
| 39 | endif | 39 | endif |
| 40 | LUA_MESSAGE := linking with selected LuaJIT | 40 | ifneq ($(LUA_PKGCONFIG),) |
| 41 | CGIT_LIBS += $(LUAJIT_LIBS) | 41 | LUA_MESSAGE := linking with $(LUA_MODE) $(LUA_PKGCONFIG) |
| 42 | CGIT_CFLAGS += $(LUAJIT_CFLAGS) | 42 | LUA_LIBS := $(shell pkg-config --libs $(LUA_PKGCONFIG) 2>/dev/null) |
| 43 | else ifeq (VANILLA,$(LUA_IMPLEMENTATION)) | 43 | LUA_CFLAGS := $(shell pkg-config --cflags $(LUA_PKGCONFIG) 2>/dev/null) |
| 44 | ifeq ($(strip $(LUA_LIBS)),) | ||
| 45 | $(error Lua specified via LUA_IMPLEMENTATION=VANILLA, but library could not be found.) | ||
| 46 | endif | ||
| 47 | LUA_MESSAGE := linking with selected Lua | ||
| 48 | CGIT_LIBS += $(LUA_LIBS) | ||
| 49 | CGIT_LIBS += $(LUA_CFLAGS) | ||
| 50 | else ifneq ($(strip $(LUAJIT_LIBS)),) | ||
| 51 | LUA_MESSAGE := linking with autodetected LuaJIT | ||
| 52 | CGIT_LIBS += $(LUAJIT_LIBS) | ||
| 53 | CGIT_CFLAGS += $(LUAJIT_CFLAGS) | ||
| 54 | else ifneq ($(strip $(LUA_LIBS)),) | ||
| 55 | LUA_MESSAGE := linking with autodetected Lua | ||
| 56 | CGIT_LIBS += $(LUA_LIBS) | 44 | CGIT_LIBS += $(LUA_LIBS) |
| 57 | CGIT_CFLAGS += $(LUA_CFLAGS) | 45 | CGIT_CFLAGS += $(LUA_CFLAGS) |
| 58 | else | 46 | else |
| @@ -68,6 +56,14 @@ ifeq ($(findstring BSD,$(uname_S)),) | |||
| 68 | CGIT_LIBS += -ldl | 56 | CGIT_LIBS += -ldl |
| 69 | endif | 57 | endif |
| 70 | 58 | ||
| 59 | # glibc 2.1+ offers sendfile which the most common C library on Linux | ||
| 60 | ifeq ($(uname_S),Linux) | ||
| 61 | HAVE_LINUX_SENDFILE = YesPlease | ||
| 62 | endif | ||
| 63 | |||
| 64 | ifdef HAVE_LINUX_SENDFILE | ||
| 65 | CGIT_CFLAGS += -DHAVE_LINUX_SENDFILE | ||
| 66 | endif | ||
| 71 | 67 | ||
| 72 | CGIT_OBJ_NAMES += cgit.o | 68 | CGIT_OBJ_NAMES += cgit.o |
| 73 | CGIT_OBJ_NAMES += cache.o | 69 | CGIT_OBJ_NAMES += cache.o |
diff --git a/cgitrc.5.txt b/cgitrc.5.txt index 8eafc4a..cbaebca 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt | |||
| @@ -60,37 +60,41 @@ cache-root:: | |||
| 60 | 60 | ||
| 61 | cache-static-ttl:: | 61 | cache-static-ttl:: |
| 62 | Number which specifies the time-to-live, in minutes, for the cached | 62 | Number which specifies the time-to-live, in minutes, for the cached |
| 63 | version of repository pages accessed with a fixed SHA1. Negative | 63 | version of repository pages accessed with a fixed SHA1. See also: |
| 64 | values have infinite ttl. Default value: -1". | 64 | "CACHE". Default value: -1". |
| 65 | 65 | ||
| 66 | cache-dynamic-ttl:: | 66 | cache-dynamic-ttl:: |
| 67 | Number which specifies the time-to-live, in minutes, for the cached | 67 | Number which specifies the time-to-live, in minutes, for the cached |
| 68 | version of repository pages accessed without a fixed SHA1. Negative | 68 | version of repository pages accessed without a fixed SHA1. See also: |
| 69 | values have infinite ttl. Default value: "5". | 69 | "CACHE". Default value: "5". |
| 70 | 70 | ||
| 71 | cache-repo-ttl:: | 71 | cache-repo-ttl:: |
| 72 | Number which specifies the time-to-live, in minutes, for the cached | 72 | Number which specifies the time-to-live, in minutes, for the cached |
| 73 | version of the repository summary page. Negative values have infinite | 73 | version of the repository summary page. See also: "CACHE". Default |
| 74 | ttl. Default value: "5". | 74 | value: "5". |
| 75 | 75 | ||
| 76 | cache-root-ttl:: | 76 | cache-root-ttl:: |
| 77 | Number which specifies the time-to-live, in minutes, for the cached | 77 | Number which specifies the time-to-live, in minutes, for the cached |
| 78 | version of the repository index page. Negative values have infinite | 78 | version of the repository index page. See also: "CACHE". Default |
| 79 | ttl. Default value: "5". | 79 | value: "5". |
| 80 | 80 | ||
| 81 | cache-scanrc-ttl:: | 81 | cache-scanrc-ttl:: |
| 82 | Number which specifies the time-to-live, in minutes, for the result | 82 | Number which specifies the time-to-live, in minutes, for the result |
| 83 | of scanning a path for git repositories. Negative values have infinite | 83 | of scanning a path for git repositories. See also: "CACHE". Default |
| 84 | ttl. Default value: "15". | 84 | value: "15". |
| 85 | 85 | ||
| 86 | cache-about-ttl:: | 86 | cache-about-ttl:: |
| 87 | Number which specifies the time-to-live, in minutes, for the cached | 87 | Number which specifies the time-to-live, in minutes, for the cached |
| 88 | version of the repository about page. Negative values have infinite | 88 | version of the repository about page. See also: "CACHE". Default |
| 89 | ttl. Default value: "15". | 89 | value: "15". |
| 90 | |||
| 91 | cache-snapshot-ttl:: | ||
| 92 | Number which specifies the time-to-live, in minutes, for the cached | ||
| 93 | version of snapshots. See also: "CACHE". Default value: "5". | ||
| 90 | 94 | ||
| 91 | cache-size:: | 95 | cache-size:: |
| 92 | The maximum number of entries in the cgit cache. Default value: "0" | 96 | The maximum number of entries in the cgit cache. When set to "0", |
| 93 | (i.e. caching is disabled). | 97 | caching is disabled. See also: "CACHE". Default value: "0" |
| 94 | 98 | ||
| 95 | case-sensitive-sort:: | 99 | case-sensitive-sort:: |
| 96 | Sort items in the repo list case sensitively. Default value: "1". | 100 | Sort items in the repo list case sensitively. Default value: "1". |
| @@ -712,6 +716,16 @@ the environment variables defined in "FILTER API": | |||
| 712 | - repo.clone-url | 716 | - repo.clone-url |
| 713 | 717 | ||
| 714 | 718 | ||
| 719 | CACHE | ||
| 720 | ------ | ||
| 721 | |||
| 722 | All cache ttl values are in minutes. Negative ttl values indicate that a page | ||
| 723 | type will never expire, and thus the first time a URL is accessed, the result | ||
| 724 | will be cached indefinitely, even if the underlying git repository changes. | ||
| 725 | Conversely, when a ttl value is zero, the cache is disabled for that | ||
| 726 | particular page type, and the page type is never cached. | ||
| 727 | |||
| 728 | |||
| 715 | EXAMPLE CGITRC FILE | 729 | EXAMPLE CGITRC FILE |
| 716 | ------------------- | 730 | ------------------- |
| 717 | 731 | ||
| @@ -113,7 +113,7 @@ static void refs_fn(void) | |||
| 113 | static void snapshot_fn(void) | 113 | static void snapshot_fn(void) |
| 114 | { | 114 | { |
| 115 | cgit_print_snapshot(ctx.qry.head, ctx.qry.sha1, ctx.qry.path, | 115 | cgit_print_snapshot(ctx.qry.head, ctx.qry.sha1, ctx.qry.path, |
| 116 | ctx.repo->snapshots, ctx.qry.nohead); | 116 | ctx.qry.nohead); |
| 117 | } | 117 | } |
| 118 | 118 | ||
| 119 | static void stats_fn(void) | 119 | static void stats_fn(void) |
diff --git a/filters/simple-authentication.lua b/filters/simple-authentication.lua index 230d3a3..cc86b7e 100644 --- a/filters/simple-authentication.lua +++ b/filters/simple-authentication.lua | |||
| @@ -166,7 +166,7 @@ function url_encode(str) | |||
| 166 | return "" | 166 | return "" |
| 167 | end | 167 | end |
| 168 | str = string.gsub(str, "\n", "\r\n") | 168 | str = string.gsub(str, "\n", "\r\n") |
| 169 | str = string.gsub(str, "([^%w ])", function (c) return string.format("%%%02X", string.byte(c)) end) | 169 | str = string.gsub(str, "([^%w ])", function(c) return string.format("%%%02X", string.byte(c)) end) |
| 170 | str = string.gsub(str, " ", "+") | 170 | str = string.gsub(str, " ", "+") |
| 171 | return str | 171 | return str |
| 172 | end | 172 | end |
diff --git a/gen-version.sh b/gen-version.sh index 3a08015..80cf49a 100755 --- a/gen-version.sh +++ b/gen-version.sh | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | V=$1 | 4 | V=$1 |
| 5 | 5 | ||
| 6 | # Use `git describe` to get current version if we're inside a git repo | 6 | # Use `git describe` to get current version if we're inside a git repo |
| 7 | if test -d .git | 7 | if test "$(git rev-parse --git-dir 2>/dev/null)" = '.git' |
| 8 | then | 8 | then |
| 9 | V=$(git describe --abbrev=4 HEAD 2>/dev/null) | 9 | V=$(git describe --abbrev=4 HEAD 2>/dev/null) |
| 10 | fi | 10 | fi |
diff --git a/git b/git | |||
| Subproject d2446dfd7f3b3f8948142cfb07a0270e2497d93 | Subproject 5f95c9f850b19b368c43ae399cc831b17a26a5a | ||
| @@ -368,6 +368,7 @@ void cgit_diff_tree(const unsigned char *old_sha1, | |||
| 368 | struct diff_options opt; | 368 | struct diff_options opt; |
| 369 | struct pathspec_item item; | 369 | struct pathspec_item item; |
| 370 | 370 | ||
| 371 | memset(&item, 0, sizeof(item)); | ||
| 371 | diff_setup(&opt); | 372 | diff_setup(&opt); |
| 372 | opt.output_format = DIFF_FORMAT_CALLBACK; | 373 | opt.output_format = DIFF_FORMAT_CALLBACK; |
| 373 | opt.detect_rename = 1; | 374 | opt.detect_rename = 1; |
diff --git a/tests/setup.sh b/tests/setup.sh index 785edd7..7590f04 100755 --- a/tests/setup.sh +++ b/tests/setup.sh | |||
| @@ -60,6 +60,12 @@ fi | |||
| 60 | 60 | ||
| 61 | FILTER_DIRECTORY=$(cd ../filters && pwd) | 61 | FILTER_DIRECTORY=$(cd ../filters && pwd) |
| 62 | 62 | ||
| 63 | if cgit --version | grep -F -q "[+] Lua scripting"; then | ||
| 64 | export CGIT_HAS_LUA=1 | ||
| 65 | else | ||
| 66 | export CGIT_HAS_LUA=0 | ||
| 67 | fi | ||
| 68 | |||
| 63 | mkrepo() { | 69 | mkrepo() { |
| 64 | name=$1 | 70 | name=$1 |
| 65 | count=$2 | 71 | count=$2 |
| @@ -133,7 +139,10 @@ repo.commit-filter=exec:$FILTER_DIRECTORY/dump.sh | |||
| 133 | repo.email-filter=exec:$FILTER_DIRECTORY/dump.sh | 139 | repo.email-filter=exec:$FILTER_DIRECTORY/dump.sh |
| 134 | repo.source-filter=exec:$FILTER_DIRECTORY/dump.sh | 140 | repo.source-filter=exec:$FILTER_DIRECTORY/dump.sh |
| 135 | repo.readme=master:a+b | 141 | repo.readme=master:a+b |
| 142 | EOF | ||
| 136 | 143 | ||
| 144 | if [ $CGIT_HAS_LUA -eq 1 ]; then | ||
| 145 | cat >>cgitrc <<EOF | ||
| 137 | repo.url=filter-lua | 146 | repo.url=filter-lua |
| 138 | repo.path=$PWD/repos/filter/.git | 147 | repo.path=$PWD/repos/filter/.git |
| 139 | repo.desc=filtered repo | 148 | repo.desc=filtered repo |
| @@ -143,6 +152,7 @@ repo.email-filter=lua:$FILTER_DIRECTORY/dump.lua | |||
| 143 | repo.source-filter=lua:$FILTER_DIRECTORY/dump.lua | 152 | repo.source-filter=lua:$FILTER_DIRECTORY/dump.lua |
| 144 | repo.readme=master:a+b | 153 | repo.readme=master:a+b |
| 145 | EOF | 154 | EOF |
| 155 | fi | ||
| 146 | } | 156 | } |
| 147 | 157 | ||
| 148 | cgit_query() | 158 | cgit_query() |
| @@ -155,7 +165,7 @@ cgit_url() | |||
| 155 | CGIT_CONFIG="$PWD/cgitrc" QUERY_STRING="url=$1" cgit | 165 | CGIT_CONFIG="$PWD/cgitrc" QUERY_STRING="url=$1" cgit |
| 156 | } | 166 | } |
| 157 | 167 | ||
| 158 | strip_headers () { | 168 | strip_headers() { |
| 159 | while read -r line | 169 | while read -r line |
| 160 | do | 170 | do |
| 161 | test -z "$line" && break | 171 | test -z "$line" && break |
diff --git a/tests/t0111-filter.sh b/tests/t0111-filter.sh index 730f1c0..2fdc366 100755 --- a/tests/t0111-filter.sh +++ b/tests/t0111-filter.sh | |||
| @@ -3,7 +3,12 @@ | |||
| 3 | test_description='Check filtered content' | 3 | test_description='Check filtered content' |
| 4 | . ./setup.sh | 4 | . ./setup.sh |
| 5 | 5 | ||
| 6 | for prefix in exec lua | 6 | prefixes="exec" |
| 7 | if [ $CGIT_HAS_LUA -eq 1 ]; then | ||
| 8 | prefixes="$prefixes lua" | ||
| 9 | fi | ||
| 10 | |||
| 11 | for prefix in $prefixes | ||
| 7 | do | 12 | do |
| 8 | test_expect_success "generate filter-$prefix/tree/a%2bb" " | 13 | test_expect_success "generate filter-$prefix/tree/a%2bb" " |
| 9 | cgit_url 'filter-$prefix/tree/a%2bb' >tmp | 14 | cgit_url 'filter-$prefix/tree/a%2bb' >tmp |
| @@ -11,18 +11,10 @@ | |||
| 11 | #include "html.h" | 11 | #include "html.h" |
| 12 | #include "ui-shared.h" | 12 | #include "ui-shared.h" |
| 13 | 13 | ||
| 14 | static int cmp_age(int age1, int age2) | 14 | static inline int cmp_age(int age1, int age2) |
| 15 | { | 15 | { |
| 16 | if (age1 != 0 && age2 != 0) | 16 | /* age1 and age2 are assumed to be non-negative */ |
| 17 | return age2 - age1; | 17 | return age2 - age1; |
| 18 | |||
| 19 | if (age1 == 0 && age2 == 0) | ||
| 20 | return 0; | ||
| 21 | |||
| 22 | if (age1 == 0) | ||
| 23 | return +1; | ||
| 24 | |||
| 25 | return -1; | ||
| 26 | } | 18 | } |
| 27 | 19 | ||
| 28 | static int cmp_ref_name(const void *a, const void *b) | 20 | static int cmp_ref_name(const void *a, const void *b) |
| @@ -105,7 +97,7 @@ static void print_tag_downloads(const struct cgit_repo *repo, const char *ref) | |||
| 105 | const char *basename; | 97 | const char *basename; |
| 106 | int free_ref = 0; | 98 | int free_ref = 0; |
| 107 | 99 | ||
| 108 | if (!ref || strlen(ref) < 2) | 100 | if (!ref || strlen(ref) < 1) |
| 109 | return; | 101 | return; |
| 110 | 102 | ||
| 111 | basename = cgit_repobasename(repo->url); | 103 | basename = cgit_repobasename(repo->url); |
diff --git a/ui-snapshot.c b/ui-snapshot.c index 582dc31..3107b05 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c | |||
| @@ -193,7 +193,7 @@ static void show_error(char *fmt, ...) | |||
| 193 | } | 193 | } |
| 194 | 194 | ||
| 195 | void cgit_print_snapshot(const char *head, const char *hex, | 195 | void cgit_print_snapshot(const char *head, const char *hex, |
| 196 | const char *filename, int snapshots, int dwim) | 196 | const char *filename, int dwim) |
| 197 | { | 197 | { |
| 198 | const struct cgit_snapshot_format* f; | 198 | const struct cgit_snapshot_format* f; |
| 199 | char *prefix = NULL; | 199 | char *prefix = NULL; |
diff --git a/ui-snapshot.h b/ui-snapshot.h index b6ede52..a8deec3 100644 --- a/ui-snapshot.h +++ b/ui-snapshot.h | |||
| @@ -2,6 +2,6 @@ | |||
| 2 | #define UI_SNAPSHOT_H | 2 | #define UI_SNAPSHOT_H |
| 3 | 3 | ||
| 4 | extern void cgit_print_snapshot(const char *head, const char *hex, | 4 | extern void cgit_print_snapshot(const char *head, const char *hex, |
| 5 | const char *filename, int snapshot, int dwim); | 5 | const char *filename, int dwim); |
| 6 | 6 | ||
| 7 | #endif /* UI_SNAPSHOT_H */ | 7 | #endif /* UI_SNAPSHOT_H */ |
