1 diff --git a/Makefile b/Makefile
2 index bbce29d..1127961 100644
9 CGIT_SCRIPT_NAME = cgit.cgi
10 CGIT_SCRIPT_PATH = /var/www/htdocs/cgit
11 @@ -12,8 +14,8 @@ htmldir = $(docdir)
13 mandir = $(prefix)/share/man
14 SHA1_HEADER = <openssl/sha.h>
16 -GIT_URL = https://github.com/git/git/archive/v$(GIT_VER).tar.gz
18 +GIT_URL = https://git-core.googlecode.com/files/git-$(GIT_VER).tar.gz
20 MAN5_TXT = $(wildcard *.5.txt)
22 @@ -40,22 +42,14 @@ DOC_PDF = $(patsubst %.txt,%.pdf,$(MAN_TXT))
23 # Platform specific tweaks
26 +VERSION: force-version
27 + @./gen-version.sh "$(CGIT_VERSION)"
30 uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
31 uname_O := $(shell sh -c 'uname -o 2>/dev/null || echo not')
32 uname_R := $(shell sh -c 'uname -r 2>/dev/null || echo not')
34 -ifeq ($(uname_O),Cygwin)
35 - NO_STRCASESTR = YesPlease
36 - NEEDS_LIBICONV = YesPlease
39 -ifeq ($(uname_S),$(filter $(uname_S),FreeBSD OpenBSD))
40 - # Apparantly libiconv is installed in /usr/local on BSD
41 - LDFLAGS ?= -L/usr/local/lib
42 - CFLAGS ?= -I/usr/local/include
43 - NEEDS_LIBICONV = yes
47 # Let the user override the above settings.
49 @@ -76,30 +70,62 @@ endif
52 QUIET_CC = @echo ' ' CC $@;
53 - QUIET_MM = @echo ' ' MM $@;
54 + QUIET_LINK = @echo ' ' LINK $@;
55 QUIET_SUBDIR0 = +@subdir=
56 QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \
57 $(MAKE) $(PRINT_DIR) -C $$subdir
58 QUIET_TAGS = @echo ' ' TAGS $@;
63 -# Define a pattern rule for automatic dependency building
66 - $(QUIET_MM)$(CC) $(CFLAGS) -MM -MP $< | sed -e 's/\($*\)\.o:/\1.o $@:/g' >$@
70 +CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)'
71 +CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"'
72 +CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"'
73 +CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"'
74 +CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"'
77 -# Define a pattern rule for silent object building
80 - $(QUIET_CC)$(CC) -o $*.o -c $(CFLAGS) $<
81 +ifeq ($(uname_O),Cygwin)
82 + NO_STRCASESTR = YesPlease
83 + NEEDS_LIBICONV = YesPlease
86 +ifeq ($(uname_S),$(filter $(uname_S),FreeBSD OpenBSD))
87 + # Apparantly libiconv is installed in /usr/local on BSD
88 + LDFLAGS += -L/usr/local/lib
89 + CFLAGS += -I/usr/local/include
90 + NEEDS_LIBICONV = yes
93 -EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lpthread
94 +GIT_OPTIONS = prefix=/usr NO_GETTEXT=1
99 + CFLAGS += -DNO_ICONV
102 + CFLAGS += -DNO_STRCASESTR
105 + CFLAGS += -DNO_C99_FORMAT
108 + CFLAGS += -DNO_OPENSSL
109 + GIT_OPTIONS += NO_OPENSSL=1
114 +ifdef NEEDS_LIBICONV
118 +LDLIBS += git/libgit.a git/xdiff/lib.a -lz -lpthread
123 OBJECTS += configfile.o
125 @@ -125,55 +151,30 @@ OBJECTS += ui-tag.o
129 -ifdef NEEDS_LIBICONV
134 -.PHONY: all libgit test install uninstall clean force-version get-git \
135 - doc clean-doc install-doc install-man install-html install-pdf \
136 - uninstall-doc uninstall-man uninstall-html uninstall-pdf tags
137 +dep_files := $(foreach f,$(OBJECTS),$(dir $f).deps/$(notdir $f).d)
138 +dep_dirs := $(addsuffix .deps,$(sort $(dir $OBJECTS)))
144 -VERSION: force-version
145 - @./gen-version.sh "$(CGIT_VERSION)"
147 +missing_dep_dirs := $(filter-out $(wildcard $(dep_dirs)),$(dep_dirs))
148 +dep_file = $(dir $@).deps/$(notdir $@).d
149 +dep_args = -MF $(dep_file) -MMD -MP
153 -CFLAGS += -g -Wall -Igit
154 -CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)'
155 -CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"'
156 -CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"'
157 -CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"'
158 -CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"'
160 -GIT_OPTIONS = prefix=/usr
161 +$(OBJECTS): %.o: %.c $(missing_dep_dirs)
162 + $(QUIET_CC)$(CC) -o $*.o -c $(dep_args) $(CFLAGS) $<
165 - CFLAGS += -DNO_ICONV
166 +dep_files_present := $(wildcard $(dep_files))
167 +ifneq ($(dep_files_present),)
168 +include $(dep_files_present)
171 - CFLAGS += -DNO_STRCASESTR
174 - CFLAGS += -DNO_C99_FORMAT
177 - CFLAGS += -DNO_OPENSSL
178 - GIT_OPTIONS += NO_OPENSSL=1
180 - EXTLIBS += -lcrypto
183 -cgit: $(OBJECTS) libgit
184 - $(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o cgit $(OBJECTS) $(EXTLIBS)
189 -ifneq "$(MAKECMDGOALS)" "clean"
190 - -include $(OBJECTS:.o=.d)
192 +cgit: VERSION $(OBJECTS) libgit
193 + $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJECTS) $(LDLIBS)
196 $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) NO_CURL=1 $(GIT_OPTIONS) libgit.a
197 @@ -243,13 +244,24 @@ $(DOC_PDF): %.pdf : %.txt
198 a2x -f pdf cgitrc.5.txt
201 - rm -f cgit VERSION *.o *.d tags
202 + $(RM) cgit VERSION *.o tags
206 + $(MAKE) -C git clean
209 - rm -f cgitrc.5 cgitrc.5.html cgitrc.5.pdf cgitrc.5.xml cgitrc.5.fo
210 + $(RM) cgitrc.5 cgitrc.5.html cgitrc.5.pdf cgitrc.5.xml cgitrc.5.fo
213 curl -L $(GIT_URL) | tar -xzf - && rm -rf git && mv git-$(GIT_VER) git
216 $(QUIET_TAGS)find . -name '*.[ch]' | xargs ctags
218 +.PHONY: all cgit get-git libgit force-version
219 +.PHONY: clean clean-doc cleanall
220 +.PHONY: doc doc-html doc-man doc-pdf
221 +.PHONY: install install-doc install-html install-man install-pdf
223 +.PHONY: uninstall uninstall-doc uninstall-html uninstall-man uninstall-pdf
224 diff --git a/cache.c b/cache.c
225 index d7a8d5a..47cdcb4 100644
228 @@ -105,7 +105,7 @@ static int is_expired(struct cache_slot *slot)
232 - return slot->cache_st.st_mtime + slot->ttl*60 < time(NULL);
233 + return slot->cache_st.st_mtime + slot->ttl * 60 < time(NULL);
236 /* Check if the slot has been modified since we opened it.
237 @@ -141,8 +141,8 @@ static int close_lock(struct cache_slot *slot)
239 static int lock_slot(struct cache_slot *slot)
241 - slot->lock_fd = open(slot->lock_name, O_RDWR|O_CREAT|O_EXCL,
243 + slot->lock_fd = open(slot->lock_name, O_RDWR | O_CREAT | O_EXCL,
244 + S_IRUSR | S_IWUSR);
245 if (slot->lock_fd == -1)
247 if (xwrite(slot->lock_fd, slot->key, slot->keylen + 1) < 0)
248 @@ -214,7 +214,7 @@ unsigned long hash_str(const char *str)
257 @@ -342,7 +342,7 @@ int cache_process(int size, const char *path, const char *key, int ttl,
258 strcpy(filename, path);
259 if (filename[len - 1] != '/')
260 filename[len++] = '/';
261 - for(i = 0; i < 8; i++) {
262 + for (i = 0; i < 8; i++) {
263 sprintf(filename + len++, "%x",
264 (unsigned char)(hash & 0xf));
266 @@ -407,7 +407,7 @@ int cache_ls(const char *path)
269 slot.cache_name = fullname;
270 - while((ent = readdir(dir)) != NULL) {
271 + while ((ent = readdir(dir)) != NULL) {
272 if (strlen(ent->d_name) != 8)
274 strcpy(name, ent->d_name);
275 diff --git a/cgit.c b/cgit.c
276 index a97ed69..2ccf864 100644
279 @@ -172,6 +172,8 @@ void config_cb(const char *name, const char *value)
280 ctx.cfg.enable_http_clone = atoi(value);
281 else if (!strcmp(name, "enable-index-links"))
282 ctx.cfg.enable_index_links = atoi(value);
283 + else if (!strcmp(name, "enable-index-owner"))
284 + ctx.cfg.enable_index_owner = atoi(value);
285 else if (!strcmp(name, "enable-commit-graph"))
286 ctx.cfg.enable_commit_graph = atoi(value);
287 else if (!strcmp(name, "enable-log-filecount"))
288 @@ -313,7 +315,7 @@ static void querystring_cb(const char *name, const char *value)
289 ctx.qry.name = xstrdup(value);
290 } else if (!strcmp(name, "mimetype")) {
291 ctx.qry.mimetype = xstrdup(value);
292 - } else if (!strcmp(name, "s")){
293 + } else if (!strcmp(name, "s")) {
294 ctx.qry.sort = xstrdup(value);
295 } else if (!strcmp(name, "showmsg")) {
296 ctx.qry.showmsg = atoi(value);
297 @@ -354,6 +356,7 @@ static void prepare_context(struct cgit_context *ctx)
298 ctx->cfg.logo = "/cgit.png";
299 ctx->cfg.local_time = 0;
300 ctx->cfg.enable_http_clone = 1;
301 + ctx->cfg.enable_index_owner = 1;
302 ctx->cfg.enable_tree_linenumbers = 1;
303 ctx->cfg.enable_git_config = 0;
304 ctx->cfg.max_repo_count = 50;
305 @@ -442,12 +445,12 @@ char *find_default_branch(struct cgit_repo *repo)
309 -static char *guess_defbranch(const char *repo_path)
310 +static char *guess_defbranch(void)
313 unsigned char sha1[20];
315 - ref = resolve_ref("HEAD", sha1, 0, NULL);
316 + ref = resolve_ref_unsafe("HEAD", sha1, 0, NULL);
317 if (!ref || prefixcmp(ref, "refs/heads/"))
319 return xstrdup(ref + 11);
320 @@ -480,7 +483,7 @@ static int prepare_repo_cmd(struct cgit_context *ctx)
321 ctx->page.title = fmt("%s - %s", ctx->repo->name, ctx->repo->desc);
323 if (!ctx->repo->defbranch)
324 - ctx->repo->defbranch = guess_defbranch(ctx->repo->path);
325 + ctx->repo->defbranch = guess_defbranch();
327 if (!ctx->qry.head) {
329 @@ -650,7 +653,7 @@ void print_repolist(FILE *f, struct cgit_repolist *list, int start)
333 - for(i = start; i < list->count; i++)
334 + for (i = start; i < list->count; i++)
335 print_repo(f, &list->repos[i]);
338 @@ -738,7 +741,7 @@ static void cgit_parse_args(int argc, const char **argv)
340 for (i = 1; i < argc; i++) {
341 if (!strncmp(argv[i], "--cache=", 8)) {
342 - ctx.cfg.cache_root = xstrdup(argv[i]+8);
343 + ctx.cfg.cache_root = xstrdup(argv[i] + 8);
345 if (!strcmp(argv[i], "--nocache")) {
347 @@ -747,24 +750,24 @@ static void cgit_parse_args(int argc, const char **argv)
348 ctx.env.no_http = "1";
350 if (!strncmp(argv[i], "--query=", 8)) {
351 - ctx.qry.raw = xstrdup(argv[i]+8);
352 + ctx.qry.raw = xstrdup(argv[i] + 8);
354 if (!strncmp(argv[i], "--repo=", 7)) {
355 - ctx.qry.repo = xstrdup(argv[i]+7);
356 + ctx.qry.repo = xstrdup(argv[i] + 7);
358 if (!strncmp(argv[i], "--page=", 7)) {
359 - ctx.qry.page = xstrdup(argv[i]+7);
360 + ctx.qry.page = xstrdup(argv[i] + 7);
362 if (!strncmp(argv[i], "--head=", 7)) {
363 - ctx.qry.head = xstrdup(argv[i]+7);
364 + ctx.qry.head = xstrdup(argv[i] + 7);
365 ctx.qry.has_symref = 1;
367 if (!strncmp(argv[i], "--sha1=", 7)) {
368 - ctx.qry.sha1 = xstrdup(argv[i]+7);
369 + ctx.qry.sha1 = xstrdup(argv[i] + 7);
370 ctx.qry.has_sha1 = 1;
372 if (!strncmp(argv[i], "--ofs=", 6)) {
373 - ctx.qry.ofs = atoi(argv[i]+6);
374 + ctx.qry.ofs = atoi(argv[i] + 6);
376 if (!strncmp(argv[i], "--scan-tree=", 12) ||
377 !strncmp(argv[i], "--scan-path=", 12)) {
378 @@ -831,7 +834,7 @@ int main(int argc, const char **argv)
379 ctx.cfg.virtual_root = trim_end(ctx.cfg.script_name, '/');
380 if (!ctx.cfg.virtual_root)
381 ctx.cfg.virtual_root = "";
385 /* If no url parameter is specified on the querystring, lets
386 * use PATH_INFO as url. This allows cgit to work with virtual
387 @@ -853,7 +856,7 @@ int main(int argc, const char **argv)
391 - ctx.page.expires += ttl*60;
392 + ctx.page.expires += ttl * 60;
393 if (ctx.env.request_method && !strcmp(ctx.env.request_method, "HEAD"))
396 diff --git a/cgit.h b/cgit.h
397 index 7a99135..c655bd8 100644
403 #include <diffcore.h>
404 +#include <argv-array.h>
406 #include <revision.h>
407 #include <log-tree.h>
408 @@ -203,6 +204,7 @@ struct cgit_config {
409 int enable_filter_overrides;
410 int enable_http_clone;
411 int enable_index_links;
412 + int enable_index_owner;
413 int enable_commit_graph;
414 int enable_log_filecount;
415 int enable_log_linecount;
416 @@ -273,6 +275,8 @@ struct cgit_context {
417 struct cgit_page page;
420 +typedef int (*write_archive_fn_t)(const char *, const char *);
422 struct cgit_snapshot_format {
424 const char *mimetype;
425 diff --git a/cgitrc.5.txt b/cgitrc.5.txt
426 index 95a1049..4d27d9f 100644
429 @@ -120,6 +120,10 @@ enable-index-links::
430 each repo in the repository index (specifically, to the "summary",
431 "commit" and "tree" pages). Default value: "0".
433 +enable-index-owner::
434 + Flag which, when set to "1", will make cgit display the owner of
435 + each repo in the repository index. Default value: "1".
437 enable-log-filecount::
438 Flag which, when set to "1", will make cgit print the number of
439 modified files for each commit on the repository log page. Default
440 @@ -244,8 +248,8 @@ mimetype-file::
441 Specifies the file to use for automatic mimetype lookup. If specified
442 then this field is used as a fallback when no "mimetype.<ext>" match is
443 found. If unspecified then no such lookup is performed. The typical file
444 - to use on a Linux system is /etc/mime.types. Default value: none. See
445 - also: "mimetype.<ext>". The format of the file must comply to:
446 + to use on a Linux system is /etc/mime.types. The format of the file must
448 - a comment line is an empty line or a line starting with a hash (#),
449 optionally preceded by whitespace
450 - a non-comment line starts with the mimetype (like image/png), followed
451 diff --git a/cmd.c b/cmd.c
452 index 899e913..198bf2f 100644
455 @@ -166,7 +166,7 @@ struct cgit_cmd *cgit_get_cmd(struct cgit_context *ctx)
456 ctx->qry.page = "repolist";
459 - for(i = 0; i < sizeof(cmds)/sizeof(*cmds); i++)
460 + for (i = 0; i < sizeof(cmds)/sizeof(*cmds); i++)
461 if (!strcmp(ctx->qry.page, cmds[i].name))
464 diff --git a/configfile.c b/configfile.c
465 index 4908058..3fa217f 100644
469 int next_char(FILE *f)
480 @@ -27,7 +27,7 @@ void skip_line(FILE *f)
484 - while((c=next_char(f)) && c!='\n' && c!=EOF)
485 + while ((c = next_char(f)) && c != '\n' && c != EOF)
489 @@ -36,31 +36,31 @@ int read_config_line(FILE *f, char *line, const char **value, int bufsize)
490 int i = 0, isname = 0;
493 - while(i<bufsize-1) {
494 + while (i < bufsize - 1) {
495 int c = next_char(f);
496 - if (!isname && (c=='#' || c==';')) {
497 + if (!isname && (c == '#' || c == ';')) {
501 if (!isname && isspace(c))
504 - if (c=='=' && !*value) {
505 + if (c == '=' && !*value) {
507 - *value = &line[i+1];
508 - } else if (c=='\n' && !isname) {
509 + *value = &line[i + 1];
510 + } else if (c == '\n' && !isname) {
513 - } else if (c=='\n' || c==EOF) {
514 + } else if (c == '\n' || c == EOF) {
529 @@ -78,7 +78,7 @@ int parse_configfile(const char *filename, configfile_value_fn fn)
530 if (!(f = fopen(filename, "r")))
533 - while((len = read_config_line(f, line, &value, sizeof(line))) > 0)
534 + while ((len = read_config_line(f, line, &value, sizeof(line))) > 0)
538 diff --git a/html.c b/html.c
539 index 8f6e4f6..90cc1c0 100644
542 @@ -54,7 +54,7 @@ char *fmt(const char *format, ...)
543 va_start(args, format);
544 len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args);
546 - if (len>sizeof(buf[bufidx])) {
547 + if (len > sizeof(buf[bufidx])) {
548 fprintf(stderr, "[html.c] string truncated: %s\n", format);
551 @@ -92,93 +92,93 @@ void html_status(int code, const char *msg, int more_headers)
552 void html_txt(const char *txt)
558 - if (c=='<' || c=='>' || c=='&') {
559 + if (c == '<' || c == '>' || c == '&') {
560 html_raw(txt, t - txt);
580 void html_ntxt(int len, const char *txt)
583 - while(t && *t && len--){
584 + while (t && *t && len--) {
586 - if (c=='<' || c=='>' || c=='&') {
587 + if (c == '<' || c == '>' || c == '&') {
588 html_raw(txt, t - txt);
605 html_raw(txt, t - txt);
611 void html_attr(const char *txt)
617 - if (c=='<' || c=='>' || c=='\'' || c=='\"' || c=='&') {
618 + if (c == '<' || c == '>' || c == '\'' || c == '\"' || c == '&') {
619 html_raw(txt, t - txt);
627 + else if (c == '\'')
645 void html_url_path(const char *txt)
650 unsigned char c = *t;
651 const char *e = url_escape_table[c];
652 - if (e && c!='+' && c!='&') {
653 + if (e && c != '+' && c != '&') {
654 html_raw(txt, t - txt);
666 void html_url_arg(const char *txt)
671 unsigned char c = *t;
672 const char *e = url_escape_table[c];
674 @@ -186,11 +186,11 @@ void html_url_arg(const char *txt)
676 html_raw(txt, t - txt);
688 @@ -260,7 +260,7 @@ int html_include(const char *filename)
689 filename, strerror(errno), errno);
692 - while((len = fread(buf, 1, 4096, f)) > 0)
693 + while ((len = fread(buf, 1, 4096, f)) > 0)
697 @@ -286,14 +286,14 @@ char *convert_query_hexchar(char *txt)
701 - d1 = hextoint(*(txt+1));
702 - d2 = hextoint(*(txt+2));
703 - if (d1<0 || d2<0) {
704 - memmove(txt, txt+3, n-2);
705 + d1 = hextoint(*(txt + 1));
706 + d2 = hextoint(*(txt + 2));
707 + if (d1 < 0 || d2 < 0) {
708 + memmove(txt, txt + 3, n - 2);
712 - memmove(txt+1, txt+3, n-2);
713 + memmove(txt + 1, txt + 3, n - 2);
717 @@ -310,23 +310,23 @@ int http_parse_querystring(const char *txt_, void (*fn)(const char *name, const
718 printf("Out of memory\n");
721 - while((c=*t) != '\0') {
723 + while ((c=*t) != '\0') {
727 - } else if (c=='+') {
729 + } else if (c == '+') {
731 - } else if (c=='%') {
732 + } else if (c == '%') {
733 t = convert_query_hexchar(t);
734 - } else if (c=='&') {
735 + } else if (c == '&') {
749 diff --git a/parsing.c b/parsing.c
750 index 1b2a551..9b7efb3 100644
753 @@ -112,7 +112,7 @@ const char *reencode(char **txt, const char *src_enc, const char *dst_enc)
756 /* no encoding needed if src_enc equals dst_enc */
757 - if(!strcasecmp(src_enc, dst_enc))
758 + if (!strcasecmp(src_enc, dst_enc))
761 tmp = reencode_string(*txt, dst_enc, src_enc);
762 @@ -170,7 +170,7 @@ struct commitinfo *cgit_parse_commit(struct commit *commit)
765 /* if no special encoding is found, assume UTF-8 */
766 - if(!ret->msg_encoding)
767 + if (!ret->msg_encoding)
768 ret->msg_encoding = xstrdup("UTF-8");
770 // skip unknown header fields
771 diff --git a/scan-tree.c b/scan-tree.c
772 index 6ce8036..10d90f4 100644
775 @@ -106,7 +106,7 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn)
777 if (ctx.cfg.enable_git_config)
778 git_config_from_file(gitconfig_config, fmt("%s/config", path), NULL);
781 if (ctx.cfg.remove_suffix)
782 if ((p = strrchr(repo->url, '.')) && !strcmp(p, ".git"))
784 @@ -185,7 +185,7 @@ static void scan_path(const char *base, const char *path, repo_config_fn fn)
785 add_repo(base, fmt("%s/.git", path), fn);
788 - while((ent = readdir(dir)) != NULL) {
789 + while ((ent = readdir(dir)) != NULL) {
790 if (ent->d_name[0] == '.') {
791 if (ent->d_name[1] == '\0')
793 @@ -222,7 +222,7 @@ void scan_projects(const char *path, const char *projectsfile, repo_config_fn fn
794 char line[MAX_PATH * 2], *z;
799 projects = fopen(projectsfile, "r");
801 fprintf(stderr, "Error opening projectsfile %s: %s (%d)\n",
802 diff --git a/shared.c b/shared.c
803 index 8e5ae48..e732064 100644
806 @@ -28,8 +28,8 @@ int chk_positive(int result, char *msg)
808 int chk_non_negative(int result, char *msg)
811 - die("%s: %s",msg, strerror(errno));
813 + die("%s: %s", msg, strerror(errno));
817 @@ -80,7 +80,7 @@ struct cgit_repo *cgit_get_repoinfo(const char *url)
819 struct cgit_repo *repo;
821 - for (i=0; i<cgit_repolist.count; i++) {
822 + for (i = 0; i < cgit_repolist.count; i++) {
823 repo = &cgit_repolist.repos[i];
824 if (!strcmp(repo->url, url))
826 @@ -108,7 +108,7 @@ char *trim_end(const char *str, char c)
830 - while(len > 0 && str[len - 1] == c)
831 + while (len > 0 && str[len - 1] == c)
835 @@ -207,7 +207,7 @@ static int load_mmfile(mmfile_t *file, const unsigned char *sha1)
836 file->ptr = (char *)"";
839 - file->ptr = read_sha1_file(sha1, &type,
840 + file->ptr = read_sha1_file(sha1, &type,
841 (unsigned long *)&file->size);
844 @@ -307,7 +307,7 @@ void cgit_diff_tree(const unsigned char *old_sha1,
845 filepair_fn fn, const char *prefix, int ignorews)
847 struct diff_options opt;
849 + struct pathspec_item item;
852 opt.output_format = DIFF_FORMAT_CALLBACK;
853 @@ -319,10 +319,10 @@ void cgit_diff_tree(const unsigned char *old_sha1,
854 opt.format_callback = cgit_diff_tree_cb;
855 opt.format_callback_data = fn;
858 - opt.paths = &prefix;
859 - prefixlen = strlen(prefix);
860 - opt.pathlens = &prefixlen;
861 + item.match = prefix;
862 + item.len = strlen(prefix);
863 + opt.pathspec.nr = 1;
864 + opt.pathspec.items = &item;
866 diff_setup_done(&opt);
868 @@ -351,17 +351,17 @@ int cgit_parse_snapshots_mask(const char *str)
871 /* favor legacy setting */
876 - str += strspn(str,delim);
877 - tl = strcspn(str,delim);
879 + str += strspn(str, delim);
880 + tl = strcspn(str, delim);
883 for (f = cgit_snapshot_formats; f->suffix; f++) {
884 sl = strlen(f->suffix);
885 - if((tl == sl && !strncmp(f->suffix, str, tl)) ||
886 - (tl == sl-1 && !strncmp(f->suffix+1, str, tl-1))) {
887 + if ((tl == sl && !strncmp(f->suffix, str, tl)) ||
888 + (tl == sl - 1 && !strncmp(f->suffix + 1, str, tl - 1))) {
892 diff --git a/tests/t0101-index.sh b/tests/t0101-index.sh
893 index 573a351..ab63aca 100755
894 --- a/tests/t0101-index.sh
895 +++ b/tests/t0101-index.sh
897 prepare_tests "Check content on index page"
899 run_test 'generate index page' 'cgit_url "" >trash/tmp'
900 -run_test 'find foo repo' 'grep -e "foo" trash/tmp'
901 -run_test 'find foo description' 'grep -e "\[no description\]" trash/tmp'
902 -run_test 'find bar repo' 'grep -e "bar" trash/tmp'
903 -run_test 'find bar description' 'grep -e "the bar repo" trash/tmp'
904 -run_test 'find foo+bar repo' 'grep -e ">foo+bar<" trash/tmp'
905 -run_test 'verify foo+bar link' 'grep -e "/foo+bar/" trash/tmp'
906 -run_test 'verify "with%20space" link' 'grep -e "/with%20space/" trash/tmp'
907 -run_test 'no tree-link' '! grep -e "foo/tree" trash/tmp'
908 -run_test 'no log-link' '! grep -e "foo/log" trash/tmp'
909 +run_test 'find foo repo' 'grep "foo" trash/tmp'
910 +run_test 'find foo description' 'grep "\[no description\]" trash/tmp'
911 +run_test 'find bar repo' 'grep "bar" trash/tmp'
912 +run_test 'find bar description' 'grep "the bar repo" trash/tmp'
913 +run_test 'find foo+bar repo' 'grep ">foo+bar<" trash/tmp'
914 +run_test 'verify foo+bar link' 'grep "/foo+bar/" trash/tmp'
915 +run_test 'verify "with%20space" link' 'grep "/with%20space/" trash/tmp'
916 +run_test 'no tree-link' '! grep "foo/tree" trash/tmp'
917 +run_test 'no log-link' '! grep "foo/log" trash/tmp'
920 diff --git a/tests/t0102-summary.sh b/tests/t0102-summary.sh
921 index f299c5a..f778cb4 100755
922 --- a/tests/t0102-summary.sh
923 +++ b/tests/t0102-summary.sh
925 prepare_tests "Check content on summary page"
927 run_test 'generate foo summary' 'cgit_url "foo" >trash/tmp'
928 -run_test 'find commit 1' 'grep -e "commit 1" trash/tmp'
929 -run_test 'find commit 5' 'grep -e "commit 5" trash/tmp'
930 -run_test 'find branch master' 'grep -e "master" trash/tmp'
931 -run_test 'no tags' '! grep -e "tags" trash/tmp'
932 +run_test 'find commit 1' 'grep "commit 1" trash/tmp'
933 +run_test 'find commit 5' 'grep "commit 5" trash/tmp'
934 +run_test 'find branch master' 'grep "master" trash/tmp'
935 +run_test 'no tags' '! grep "tags" trash/tmp'
936 run_test 'clone-url expanded correctly' '
937 - grep -e "git://example.org/foo.git" trash/tmp
938 + grep "git://example.org/foo.git" trash/tmp
941 run_test 'generate bar summary' 'cgit_url "bar" >trash/tmp'
942 -run_test 'no commit 45' '! grep -e "commit 45" trash/tmp'
943 -run_test 'find commit 46' 'grep -e "commit 46" trash/tmp'
944 -run_test 'find commit 50' 'grep -e "commit 50" trash/tmp'
945 -run_test 'find branch master' 'grep -e "master" trash/tmp'
946 -run_test 'no tags' '! grep -e "tags" trash/tmp'
947 +run_test 'no commit 45' '! grep "commit 45" trash/tmp'
948 +run_test 'find commit 46' 'grep "commit 46" trash/tmp'
949 +run_test 'find commit 50' 'grep "commit 50" trash/tmp'
950 +run_test 'find branch master' 'grep "master" trash/tmp'
951 +run_test 'no tags' '! grep "tags" trash/tmp'
952 run_test 'clone-url expanded correctly' '
953 - grep -e "git://example.org/bar.git" trash/tmp
954 + grep "git://example.org/bar.git" trash/tmp
958 diff --git a/tests/t0103-log.sh b/tests/t0103-log.sh
959 index 7fa6754..67fcba0 100755
960 --- a/tests/t0103-log.sh
961 +++ b/tests/t0103-log.sh
963 prepare_tests "Check content on log page"
965 run_test 'generate foo/log' 'cgit_url "foo/log" >trash/tmp'
966 -run_test 'find commit 1' 'grep -e "commit 1" trash/tmp'
967 -run_test 'find commit 5' 'grep -e "commit 5" trash/tmp'
968 +run_test 'find commit 1' 'grep "commit 1" trash/tmp'
969 +run_test 'find commit 5' 'grep "commit 5" trash/tmp'
971 run_test 'generate bar/log' 'cgit_url "bar/log" >trash/tmp'
972 -run_test 'find commit 1' 'grep -e "commit 1" trash/tmp'
973 -run_test 'find commit 50' 'grep -e "commit 50" trash/tmp'
974 +run_test 'find commit 1' 'grep "commit 1" trash/tmp'
975 +run_test 'find commit 50' 'grep "commit 50" trash/tmp'
977 run_test 'generate "with%20space/log?qt=grep&q=commit+1"' '
978 cgit_url "with+space/log&qt=grep&q=commit+1" >trash/tmp
980 -run_test 'find commit 1' 'grep -e "commit 1" trash/tmp'
981 -run_test 'find link with %20 in path' 'grep -e "/with%20space/log/?qt=grep" trash/tmp'
982 -run_test 'find link with + in arg' 'grep -e "/log/?qt=grep&q=commit+1" trash/tmp'
983 -run_test 'no links with space in path' '! grep -e "href=./with space/" trash/tmp'
984 -run_test 'no links with space in arg' '! grep -e "q=commit 1" trash/tmp'
985 -run_test 'commit 2 is not visible' '! grep -e "commit 2" trash/tmp'
986 +run_test 'find commit 1' 'grep "commit 1" trash/tmp'
987 +run_test 'find link with %20 in path' 'grep "/with%20space/log/?qt=grep" trash/tmp'
988 +run_test 'find link with + in arg' 'grep "/log/?qt=grep&q=commit+1" trash/tmp'
989 +run_test 'no links with space in path' '! grep "href=./with space/" trash/tmp'
990 +run_test 'no links with space in arg' '! grep "q=commit 1" trash/tmp'
991 +run_test 'commit 2 is not visible' '! grep "commit 2" trash/tmp'
994 diff --git a/tests/t0104-tree.sh b/tests/t0104-tree.sh
995 index 2ce1251..7aa3b8d 100755
996 --- a/tests/t0104-tree.sh
997 +++ b/tests/t0104-tree.sh
999 prepare_tests "Check content on tree page"
1001 run_test 'generate bar/tree' 'cgit_url "bar/tree" >trash/tmp'
1002 -run_test 'find file-1' 'grep -e "file-1" trash/tmp'
1003 -run_test 'find file-50' 'grep -e "file-50" trash/tmp'
1004 +run_test 'find file-1' 'grep "file-1" trash/tmp'
1005 +run_test 'find file-50' 'grep "file-50" trash/tmp'
1007 run_test 'generate bar/tree/file-50' 'cgit_url "bar/tree/file-50" >trash/tmp'
1009 run_test 'find line 1' '
1010 - grep -e "<a class=.no. id=.n1. name=.n1. href=.#n1.>1</a>" trash/tmp
1011 + grep "<a class=.no. id=.n1. name=.n1. href=.#n1.>1</a>" trash/tmp
1014 run_test 'no line 2' '
1015 - ! grep -e "<a class=.no. id=.n2. name=.n2. href=.#n2.>2</a>" trash/tmp
1016 + ! grep "<a class=.no. id=.n2. name=.n2. href=.#n2.>2</a>" trash/tmp
1019 run_test 'generate foo+bar/tree' 'cgit_url "foo%2bbar/tree" >trash/tmp'
1021 run_test 'verify a+b link' '
1022 - grep -e "/foo+bar/tree/a+b" trash/tmp
1023 + grep "/foo+bar/tree/a+b" trash/tmp
1026 run_test 'generate foo+bar/tree?h=1+2' 'cgit_url "foo%2bbar/tree&h=1%2b2" >trash/tmp'
1028 run_test 'verify a+b?h=1+2 link' '
1029 - grep -e "/foo+bar/tree/a+b?h=1%2b2" trash/tmp
1030 + grep "/foo+bar/tree/a+b?h=1%2b2" trash/tmp
1034 diff --git a/tests/t0105-commit.sh b/tests/t0105-commit.sh
1035 index ae794c8..31b554b 100755
1036 --- a/tests/t0105-commit.sh
1037 +++ b/tests/t0105-commit.sh
1039 prepare_tests "Check content on commit page"
1041 run_test 'generate foo/commit' 'cgit_url "foo/commit" >trash/tmp'
1042 -run_test 'find tree link' 'grep -e "<a href=./foo/tree/.>" trash/tmp'
1043 +run_test 'find tree link' 'grep "<a href=./foo/tree/.>" trash/tmp'
1044 run_test 'find parent link' 'grep -E "<a href=./foo/commit/\?id=.+>" trash/tmp'
1046 run_test 'find commit subject' '
1047 - grep -e "<div class=.commit-subject.>commit 5<" trash/tmp
1048 + grep "<div class=.commit-subject.>commit 5<" trash/tmp
1051 -run_test 'find commit msg' 'grep -e "<div class=.commit-msg.></div>" trash/tmp'
1052 -run_test 'find diffstat' 'grep -e "<table summary=.diffstat. class=.diffstat.>" trash/tmp'
1053 +run_test 'find commit msg' 'grep "<div class=.commit-msg.></div>" trash/tmp'
1054 +run_test 'find diffstat' 'grep "<table summary=.diffstat. class=.diffstat.>" trash/tmp'
1056 run_test 'find diff summary' '
1057 - grep -e "1 files changed, 1 insertions, 0 deletions" trash/tmp
1058 + grep "1 files changed, 1 insertions, 0 deletions" trash/tmp
1061 run_test 'get root commit' '
1062 - root=$(cd trash/repos/foo && git rev-list --reverse HEAD | head -1) &&
1063 - cgit_url "foo/commit&id=$root" >trash/tmp &&
1064 - grep "</html>" trash/tmp
1065 + root=$(cd trash/repos/foo && git rev-list --reverse HEAD | head -1) &&
1066 + cgit_url "foo/commit&id=$root" >trash/tmp &&
1067 + grep "</html>" trash/tmp
1070 run_test 'root commit contains diffstat' '
1071 - grep "<a href=./foo/diff/file-1.id=[0-9a-f]\{40\}.>file-1</a>" trash/tmp
1072 + grep "<a href=./foo/diff/file-1.id=[0-9a-f]\{40\}.>file-1</a>" trash/tmp
1075 run_test 'root commit contains diff' '
1076 - grep ">diff --git a/file-1 b/file-1<" trash/tmp &&
1077 - grep -e "<div class=.add.>+1</div>" trash/tmp
1078 + grep ">diff --git a/file-1 b/file-1<" trash/tmp &&
1079 + grep "<div class=.add.>+1</div>" trash/tmp
1083 diff --git a/tests/t0106-diff.sh b/tests/t0106-diff.sh
1084 index e140bcc..eee0c8c 100755
1085 --- a/tests/t0106-diff.sh
1086 +++ b/tests/t0106-diff.sh
1088 prepare_tests "Check content on diff page"
1090 run_test 'generate foo/diff' 'cgit_url "foo/diff" >trash/tmp'
1091 -run_test 'find diff header' 'grep -e "a/file-5 b/file-5" trash/tmp'
1092 -run_test 'find blob link' 'grep -e "<a href=./foo/tree/file-5?id=" trash/tmp'
1093 -run_test 'find added file' 'grep -e "new file mode 100644" trash/tmp'
1094 +run_test 'find diff header' 'grep "a/file-5 b/file-5" trash/tmp'
1095 +run_test 'find blob link' 'grep "<a href=./foo/tree/file-5?id=" trash/tmp'
1096 +run_test 'find added file' 'grep "new file mode 100644" trash/tmp'
1098 run_test 'find hunk header' '
1099 - grep -e "<div class=.hunk.>@@ -0,0 +1 @@</div>" trash/tmp
1100 + grep "<div class=.hunk.>@@ -0,0 +1 @@</div>" trash/tmp
1103 run_test 'find added line' '
1104 - grep -e "<div class=.add.>+5</div>" trash/tmp
1105 + grep "<div class=.add.>+5</div>" trash/tmp
1109 diff --git a/tests/t0107-snapshot.sh b/tests/t0107-snapshot.sh
1110 index 8ab4912..132d2e9 100755
1111 --- a/tests/t0107-snapshot.sh
1112 +++ b/tests/t0107-snapshot.sh
1113 @@ -10,17 +10,20 @@ run_test 'get foo/snapshot/master.tar.gz' '
1115 run_test 'check html headers' '
1116 head -n 1 trash/tmp |
1117 - grep -e "Content-Type: application/x-gzip" &&
1118 + grep "Content-Type: application/x-gzip" &&
1120 head -n 2 trash/tmp |
1121 - grep -e "Content-Disposition: inline; filename=.master.tar.gz."
1122 + grep "Content-Disposition: inline; filename=.master.tar.gz."
1125 run_test 'strip off the header lines' '
1126 - tail -n +6 trash/tmp > trash/master.tar.gz
1127 + tail -n +6 trash/tmp > trash/master.tar.gz
1130 +run_test 'verify gzip format' '
1131 + gunzip --test trash/master.tar.gz
1134 -run_test 'verify gzip format' 'gunzip --test trash/master.tar.gz'
1136 rm -rf trash/master &&
1137 tar -xf trash/master.tar.gz -C trash
1138 @@ -32,7 +35,42 @@ run_test 'count files' '
1141 run_test 'verify untarred file-5' '
1142 - grep -e "^5$" trash/master/file-5 &&
1143 + grep "^5$" trash/master/file-5 &&
1144 + test $(cat trash/master/file-5 | wc -l) = 1
1147 +run_test 'get foo/snapshot/master.zip' '
1148 + cgit_url "foo/snapshot/master.zip" >trash/tmp
1151 +run_test 'check HTML headers (zip)' '
1152 + head -n 1 trash/tmp |
1153 + grep "Content-Type: application/x-zip" &&
1155 + head -n 2 trash/tmp |
1156 + grep "Content-Disposition: inline; filename=.master.zip."
1159 +run_test 'strip off the header lines (zip)' '
1160 + tail -n +6 trash/tmp >trash/master.zip
1163 +run_test 'verify zip format' '
1164 + unzip -t trash/master.zip
1168 + rm -rf trash/master &&
1169 + unzip trash/master.zip -d trash
1172 +run_test 'count files (zip)' '
1173 + c=$(ls -1 trash/master/ | wc -l) &&
1177 +run_test 'verify unzipped file-5' '
1178 + grep "^5$" trash/master/file-5 &&
1179 test $(cat trash/master/file-5 | wc -l) = 1
1182 diff --git a/tests/t0108-patch.sh b/tests/t0108-patch.sh
1183 index 6ee70b3..f92f69c 100755
1184 --- a/tests/t0108-patch.sh
1185 +++ b/tests/t0108-patch.sh
1186 @@ -9,19 +9,19 @@ run_test 'generate foo/patch' '
1189 run_test 'find `From:` line' '
1190 - grep -e "^From: " trash/tmp
1191 + grep "^From: " trash/tmp
1194 run_test 'find `Date:` line' '
1195 - grep -e "^Date: " trash/tmp
1196 + grep "^Date: " trash/tmp
1199 run_test 'find `Subject:` line' '
1200 - grep -e "^Subject: commit 5" trash/tmp
1201 + grep "^Subject: commit 5" trash/tmp
1204 run_test 'find `cgit` signature' '
1205 - tail -1 trash/tmp | grep -e "^cgit"
1206 + tail -1 trash/tmp | grep "^cgit"
1209 run_test 'find initial commit' '
1210 @@ -33,7 +33,7 @@ run_test 'generate patch for initial commit' '
1213 run_test 'find `cgit` signature' '
1214 - tail -1 trash/tmp | grep -e "^cgit"
1215 + tail -1 trash/tmp | grep "^cgit"
1219 diff --git a/ui-blob.c b/ui-blob.c
1220 index ec435e1..c59fbcb 100644
1225 #include "ui-shared.h"
1227 -static char *match_path;
1228 -static unsigned char *matched_sha1;
1229 -static int found_path;
1230 +struct walk_tree_context {
1232 + unsigned char *matched_sha1;
1236 -static int walk_tree(const unsigned char *sha1, const char *base,int baselen,
1237 - const char *pathname, unsigned mode, int stage, void *cbdata) {
1238 - if(strncmp(base,match_path,baselen)
1239 - || strcmp(match_path+baselen,pathname) )
1240 +static int walk_tree(const unsigned char *sha1, const char *base, int baselen,
1241 + const char *pathname, unsigned mode, int stage, void *cbdata)
1243 + struct walk_tree_context *walk_tree_ctx = cbdata;
1245 + if (strncmp(base, walk_tree_ctx->match_path, baselen)
1246 + || strcmp(walk_tree_ctx->match_path + baselen, pathname))
1247 return READ_TREE_RECURSIVE;
1248 - memmove(matched_sha1,sha1,20);
1250 + memmove(walk_tree_ctx->matched_sha1, sha1, 20);
1251 + walk_tree_ctx->found_path = 1;
1255 @@ -32,17 +37,27 @@ int cgit_print_file(char *path, const char *head)
1258 struct commit *commit;
1259 - const char *paths[] = {path, NULL};
1260 + struct pathspec_item path_items = {
1262 + .len = strlen(path)
1264 + struct pathspec paths = {
1266 + .items = &path_items
1268 + struct walk_tree_context walk_tree_ctx = {
1269 + .match_path = path,
1270 + .matched_sha1 = sha1,
1274 if (get_sha1(head, sha1))
1276 type = sha1_object_info(sha1, &size);
1277 - if(type == OBJ_COMMIT && path) {
1278 + if (type == OBJ_COMMIT && path) {
1279 commit = lookup_commit_reference(sha1);
1280 - match_path = path;
1281 - matched_sha1 = sha1;
1283 - read_tree_recursive(commit->tree, "", 0, 0, paths, walk_tree, NULL);
1285 + read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx);
1286 + if (!walk_tree_ctx.found_path)
1288 type = sha1_object_info(sha1, &size);
1290 @@ -63,15 +78,26 @@ void cgit_print_blob(const char *hex, char *path, const char *head)
1293 struct commit *commit;
1294 - const char *paths[] = {path, NULL};
1295 + struct pathspec_item path_items = {
1297 + .len = strlen(path)
1299 + struct pathspec paths = {
1301 + .items = &path_items
1303 + struct walk_tree_context walk_tree_ctx = {
1304 + .match_path = path,
1305 + .matched_sha1 = sha1,
1309 - if (get_sha1_hex(hex, sha1)){
1310 + if (get_sha1_hex(hex, sha1)) {
1311 cgit_print_error(fmt("Bad hex value: %s", hex));
1315 - if (get_sha1(head,sha1)) {
1316 + if (get_sha1(head, sha1)) {
1317 cgit_print_error(fmt("Bad ref: %s", head));
1320 @@ -79,11 +105,9 @@ void cgit_print_blob(const char *hex, char *path, const char *head)
1322 type = sha1_object_info(sha1, &size);
1324 - if((!hex) && type == OBJ_COMMIT && path) {
1325 + if ((!hex) && type == OBJ_COMMIT && path) {
1326 commit = lookup_commit_reference(sha1);
1327 - match_path = path;
1328 - matched_sha1 = sha1;
1329 - read_tree_recursive(commit->tree, "", 0, 0, paths, walk_tree, NULL);
1330 + read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx);
1331 type = sha1_object_info(sha1,&size);
1334 diff --git a/ui-clone.c b/ui-clone.c
1335 index 81e7a4e..fdea24f 100644
1338 @@ -19,12 +19,10 @@ static int print_ref_info(const char *refname, const unsigned char *sha1,
1339 if (!(obj = parse_object(sha1)))
1342 - if (!strcmp(refname, "HEAD") || !prefixcmp(refname, "refs/heads/"))
1343 - htmlf("%s\t%s\n", sha1_to_hex(sha1), refname);
1344 - else if (!prefixcmp(refname, "refs/tags") && obj->type == OBJ_TAG) {
1345 + htmlf("%s\t%s\n", sha1_to_hex(sha1), refname);
1346 + if (obj->type == OBJ_TAG) {
1347 if (!(obj = deref_tag(obj, refname, 0)))
1349 - htmlf("%s\t%s\n", sha1_to_hex(sha1), refname);
1350 htmlf("%s\t%s^{}\n", sha1_to_hex(obj->sha1), refname);
1353 diff --git a/ui-commit.c b/ui-commit.c
1354 index 536a8e8..74f37c8 100644
1357 @@ -39,7 +39,7 @@ void cgit_print_commit(char *hex, const char *prefix)
1358 format_note(NULL, sha1, ¬es, PAGE_ENCODING, 0);
1360 load_ref_decorations(DECORATE_FULL_REFS);
1363 cgit_print_diff_ctrls();
1364 html("<table summary='commit info' class='commit-info'>\n");
1365 html("<tr><th>author</th><td>");
1366 @@ -75,7 +75,7 @@ void cgit_print_commit(char *hex, const char *prefix)
1367 cgit_tree_link(prefix, NULL, NULL, ctx.qry.head, tmp, prefix);
1369 html("</td></tr>\n");
1370 - for (p = commit->parents; p ; p = p->next) {
1371 + for (p = commit->parents; p; p = p->next) {
1372 parent = lookup_commit_reference(p->item->object.sha1);
1374 html("<tr><td colspan='3'>");
1375 diff --git a/ui-diff.c b/ui-diff.c
1376 index 3d46da2..49e5b46 100644
1379 @@ -184,7 +184,7 @@ void cgit_print_diffstat(const unsigned char *old_sha1,
1381 cgit_diff_tree(old_sha1, new_sha1, inspect_filepair, prefix,
1383 - for(i = 0; i<files; i++)
1384 + for (i = 0; i<files; i++)
1385 print_fileinfo(&items[i]);
1387 html("<div class='diffstat-summary'>");
1388 diff --git a/ui-plain.c b/ui-plain.c
1389 index 85877d7..8ef4ec6 100644
1394 #include "ui-shared.h"
1398 +struct walk_tree_context {
1399 + int match_baselen;
1403 static char *get_mimetype_from_file(const char *filename, const char *ext)
1405 @@ -54,7 +56,7 @@ static char *get_mimetype_from_file(const char *filename, const char *ext)
1409 -static void print_object(const unsigned char *sha1, const char *path)
1410 +static int print_object(const unsigned char *sha1, const char *path)
1412 enum object_type type;
1414 @@ -65,13 +67,13 @@ static void print_object(const unsigned char *sha1, const char *path)
1415 type = sha1_object_info(sha1, &size);
1416 if (type == OBJ_BAD) {
1417 html_status(404, "Not found", 0);
1422 buf = read_sha1_file(sha1, &type, &size);
1424 html_status(404, "Not found", 0);
1428 ctx.page.mimetype = NULL;
1429 ext = strrchr(path, '.');
1430 @@ -97,9 +99,9 @@ static void print_object(const unsigned char *sha1, const char *path)
1431 ctx.page.etag = sha1_to_hex(sha1);
1432 cgit_print_http_headers(&ctx);
1433 html_raw(buf, size);
1436 free(ctx.page.mimetype);
1440 static char *buildpath(const char *base, int baselen, const char *path)
1441 @@ -138,7 +140,6 @@ static void print_dir(const unsigned char *sha1, const char *base,
1448 static void print_dir_entry(const unsigned char *sha1, const char *base,
1449 @@ -156,7 +157,6 @@ static void print_dir_entry(const unsigned char *sha1, const char *base,
1450 cgit_plain_link(path, NULL, NULL, ctx.qry.head, ctx.qry.sha1,
1456 static void print_dir_tail(void)
1457 @@ -168,18 +168,23 @@ static int walk_tree(const unsigned char *sha1, const char *base, int baselen,
1458 const char *pathname, unsigned mode, int stage,
1461 - if (baselen == match_baselen) {
1462 - if (S_ISREG(mode))
1463 - print_object(sha1, pathname);
1464 - else if (S_ISDIR(mode)) {
1465 + struct walk_tree_context *walk_tree_ctx = cbdata;
1467 + if (baselen == walk_tree_ctx->match_baselen) {
1468 + if (S_ISREG(mode)) {
1469 + if (print_object(sha1, pathname))
1470 + walk_tree_ctx->match = 1;
1471 + } else if (S_ISDIR(mode)) {
1472 print_dir(sha1, base, baselen, pathname);
1473 + walk_tree_ctx->match = 2;
1474 return READ_TREE_RECURSIVE;
1477 - else if (baselen > match_baselen)
1478 + } else if (baselen > walk_tree_ctx->match_baselen) {
1479 print_dir_entry(sha1, base, baselen, pathname, mode);
1480 - else if (S_ISDIR(mode))
1481 + walk_tree_ctx->match = 2;
1482 + } else if (S_ISDIR(mode)) {
1483 return READ_TREE_RECURSIVE;
1488 @@ -197,7 +202,17 @@ void cgit_print_plain(struct cgit_context *ctx)
1489 const char *rev = ctx->qry.sha1;
1490 unsigned char sha1[20];
1491 struct commit *commit;
1492 - const char *paths[] = {ctx->qry.path, NULL};
1493 + struct pathspec_item path_items = {
1494 + .match = ctx->qry.path,
1495 + .len = ctx->qry.path ? strlen(ctx->qry.path) : 0
1497 + struct pathspec paths = {
1499 + .items = &path_items
1501 + struct walk_tree_context walk_tree_ctx = {
1506 rev = ctx->qry.head;
1507 @@ -211,16 +226,17 @@ void cgit_print_plain(struct cgit_context *ctx)
1508 html_status(404, "Not found", 0);
1513 - match_baselen = -1;
1514 + if (!path_items.match) {
1515 + path_items.match = "";
1516 + walk_tree_ctx.match_baselen = -1;
1517 print_dir(commit->tree->object.sha1, "", 0, "");
1518 + walk_tree_ctx.match = 2;
1521 - match_baselen = basedir_len(paths[0]);
1522 - read_tree_recursive(commit->tree, "", 0, 0, paths, walk_tree, NULL);
1524 + walk_tree_ctx.match_baselen = basedir_len(path_items.match);
1525 + read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx);
1526 + if (!walk_tree_ctx.match)
1527 html_status(404, "Not found", 0);
1528 - else if (match == 2)
1529 + else if (walk_tree_ctx.match == 2)
1532 diff --git a/ui-refs.c b/ui-refs.c
1533 index caddfbc..ce06b08 100644
1536 @@ -200,7 +200,7 @@ void cgit_print_branches(int maxcount)
1537 qsort(list.refs, maxcount, sizeof(*list.refs), cmp_ref_name);
1540 - for(i=0; i<maxcount; i++)
1541 + for (i = 0; i < maxcount; i++)
1542 print_branch(list.refs[i]);
1544 if (maxcount < list.count)
1545 @@ -224,7 +224,7 @@ void cgit_print_tags(int maxcount)
1546 else if (maxcount > list.count)
1547 maxcount = list.count;
1549 - for(i=0; i<maxcount; i++)
1550 + for (i = 0; i < maxcount; i++)
1551 print_tag(list.refs[i]);
1553 if (maxcount < list.count)
1554 diff --git a/ui-repolist.c b/ui-repolist.c
1555 index dead1bf..1ae22aa 100644
1558 @@ -110,12 +110,13 @@ void print_sort_header(const char *title, const char *sort)
1559 htmlf("'>%s</a></th>", title);
1562 -void print_header(int columns)
1563 +void print_header()
1565 html("<tr class='nohover'>");
1566 print_sort_header("Name", "name");
1567 print_sort_header("Description", "desc");
1568 - print_sort_header("Owner", "owner");
1569 + if (ctx.cfg.enable_index_owner)
1570 + print_sort_header("Owner", "owner");
1571 print_sort_header("Idle", "idle");
1572 if (ctx.cfg.enable_index_links)
1573 html("<th class='left'>Links</th>");
1574 @@ -128,10 +129,10 @@ void print_pager(int items, int pagelen, char *search, char *sort)
1577 html("<div class='pager'>");
1578 - for(i = 0, ofs = 0; ofs < items; i++, ofs = i * pagelen) {
1579 + for (i = 0, ofs = 0; ofs < items; i++, ofs = i * pagelen) {
1580 class = (ctx.qry.ofs == ofs) ? "current" : NULL;
1581 - cgit_index_link(fmt("[%d]", i+1), fmt("Page %d", i+1), class,
1582 - search, sort, ofs);
1583 + cgit_index_link(fmt("[%d]", i + 1), fmt("Page %d", i + 1),
1584 + class, search, sort, ofs);
1588 @@ -239,13 +240,15 @@ int sort_repolist(char *field)
1590 void cgit_print_repolist()
1592 - int i, columns = 4, hits = 0, header = 0;
1593 + int i, columns = 3, hits = 0, header = 0;
1594 char *last_section = NULL;
1598 if (ctx.cfg.enable_index_links)
1601 + if (ctx.cfg.enable_index_owner)
1604 ctx.page.title = ctx.cfg.root_title;
1605 cgit_print_http_headers(&ctx);
1606 @@ -255,13 +258,13 @@ void cgit_print_repolist()
1607 if (ctx.cfg.index_header)
1608 html_include(ctx.cfg.index_header);
1612 sorted = sort_repolist(ctx.qry.sort);
1613 else if (ctx.cfg.section_sort)
1614 sort_repolist("section");
1616 html("<table summary='repository list' class='list nowrap'>");
1617 - for (i=0; i<cgit_repolist.count; i++) {
1618 + for (i = 0; i < cgit_repolist.count; i++) {
1619 ctx.repo = &cgit_repolist.repos[i];
1620 if (!(is_match(ctx.repo) && is_in_url(ctx.repo)))
1622 @@ -271,7 +274,7 @@ void cgit_print_repolist()
1623 if (hits > ctx.qry.ofs + ctx.cfg.max_repo_count)
1626 - print_header(columns);
1628 section = ctx.repo->section;
1629 if (section && !strcmp(section, ""))
1631 @@ -294,8 +297,10 @@ void cgit_print_repolist()
1632 html_ntxt(ctx.cfg.max_repodesc_len, ctx.repo->desc);
1635 - html_txt(ctx.repo->owner);
1636 - html("</td><td>");
1637 + if (ctx.cfg.enable_index_owner) {
1638 + html_txt(ctx.repo->owner);
1639 + html("</td><td>");
1641 print_modtime(ctx.repo);
1643 if (ctx.cfg.enable_index_links) {
1644 diff --git a/ui-shared.c b/ui-shared.c
1645 index 75b97a1..af5310b 100644
1648 @@ -23,7 +23,7 @@ static char *http_date(time_t t)
1649 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
1650 struct tm *tm = gmtime(&t);
1651 return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday],
1652 - tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year,
1653 + tm->tm_mday, month[tm->tm_mon], 1900 + tm->tm_year,
1654 tm->tm_hour, tm->tm_min, tm->tm_sec);
1657 @@ -93,7 +93,7 @@ char *cgit_fileurl(const char *reponame, const char *pagename,
1658 char *cgit_pageurl(const char *reponame, const char *pagename,
1661 - return cgit_fileurl(reponame,pagename,0,query);
1662 + return cgit_fileurl(reponame, pagename, 0, query);
1665 const char *cgit_repobasename(const char *reponame)
1666 @@ -102,21 +102,21 @@ const char *cgit_repobasename(const char *reponame)
1667 static char rvbuf[1024];
1670 - strncpy(rvbuf,reponame,sizeof(rvbuf));
1671 - if(rvbuf[sizeof(rvbuf)-1])
1672 + strncpy(rvbuf, reponame, sizeof(rvbuf));
1673 + if (rvbuf[sizeof(rvbuf)-1])
1674 die("cgit_repobasename: truncated repository name '%s'", reponame);
1675 p = strlen(rvbuf)-1;
1676 /* strip trailing slashes */
1677 - while(p && rvbuf[p]=='/') rvbuf[p--]=0;
1678 + while (p && rvbuf[p] == '/') rvbuf[p--] = 0;
1679 /* strip trailing .git */
1680 - if(p>=3 && !strncmp(&rvbuf[p-3],".git",4)) {
1681 + if (p >= 3 && !strncmp(&rvbuf[p-3], ".git", 4)) {
1682 p -= 3; rvbuf[p--] = 0;
1684 /* strip more trailing slashes if any */
1685 - while( p && rvbuf[p]=='/') rvbuf[p--]=0;
1686 + while ( p && rvbuf[p] == '/') rvbuf[p--] = 0;
1687 /* find last slash in the remaining string */
1688 rv = strrchr(rvbuf,'/');
1694 @@ -499,7 +499,7 @@ void cgit_object_link(struct object *obj)
1695 shortrev = xstrdup(fullrev);
1696 shortrev[10] = '\0';
1697 if (obj->type == OBJ_COMMIT) {
1698 - cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL,
1699 + cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL,
1700 ctx.qry.head, fullrev, NULL, 0);
1702 } else if (obj->type == OBJ_TREE)
1703 @@ -564,6 +564,7 @@ void cgit_submodule_link(const char *class, char *path, const char *rev)
1707 + html_txt(fmt(" @ %.7s", rev));
1709 path[len - 1] = tail;
1711 @@ -575,7 +576,7 @@ void cgit_print_date(time_t secs, const char *format, int local_time)
1717 time = localtime(&secs);
1719 time = gmtime(&secs);
1720 @@ -735,7 +736,7 @@ int print_archive_ref(const char *refname, const unsigned char *sha1,
1722 if (prefixcmp(refname, "refs/archives"))
1724 - strncpy(buf, refname+14, sizeof(buf));
1725 + strncpy(buf, refname + 14, sizeof(buf));
1726 obj = parse_object(sha1);
1729 @@ -967,7 +968,7 @@ void cgit_print_snapshot_links(const char *repo, const char *head,
1731 const struct cgit_snapshot_format* f;
1735 unsigned char sha1[20];
1737 if (get_sha1(fmt("refs/tags/%s", hex), sha1) == 0 &&
1738 diff --git a/ui-snapshot.c b/ui-snapshot.c
1739 index 47432bd..54e659c 100644
1744 #include "ui-shared.h"
1746 -static int write_compressed_tar_archive(struct archiver_args *args, char *filter_argv[])
1747 +static int write_archive_type(const char *format, const char *hex, const char *prefix)
1749 + struct argv_array argv = ARGV_ARRAY_INIT;
1750 + argv_array_push(&argv, "snapshot");
1751 + argv_array_push(&argv, format);
1753 + argv_array_push(&argv, "--prefix");
1754 + argv_array_push(&argv, fmt("%s/", prefix));
1756 + argv_array_push(&argv, hex);
1757 + return write_archive(argv.argc, argv.argv, NULL, 1, NULL, 0);
1760 +static int write_tar_archive(const char *hex, const char *prefix)
1762 + return write_archive_type("--format=tar", hex, prefix);
1765 +static int write_zip_archive(const char *hex, const char *prefix)
1767 + return write_archive_type("--format=zip", hex, prefix);
1770 +static int write_compressed_tar_archive(const char *hex,
1771 + const char *prefix,
1772 + char *filter_argv[])
1775 struct cgit_filter f;
1776 @@ -19,27 +44,27 @@ static int write_compressed_tar_archive(struct archiver_args *args, char *filter
1777 f.cmd = filter_argv[0];
1778 f.argv = filter_argv;
1779 cgit_open_filter(&f);
1780 - rv = write_tar_archive(args);
1781 + rv = write_tar_archive(hex, prefix);
1782 cgit_close_filter(&f);
1786 -static int write_tar_gzip_archive(struct archiver_args *args)
1787 +static int write_tar_gzip_archive(const char *hex, const char *prefix)
1789 char *argv[] = { "gzip", "-n", NULL };
1790 - return write_compressed_tar_archive(args, argv);
1791 + return write_compressed_tar_archive(hex, prefix, argv);
1794 -static int write_tar_bzip2_archive(struct archiver_args *args)
1795 +static int write_tar_bzip2_archive(const char *hex, const char *prefix)
1797 char *argv[] = { "bzip2", NULL };
1798 - return write_compressed_tar_archive(args, argv);
1799 + return write_compressed_tar_archive(hex, prefix, argv);
1802 -static int write_tar_xz_archive(struct archiver_args *args)
1803 +static int write_tar_xz_archive(const char *hex, const char *prefix)
1805 char *argv[] = { "xz", NULL };
1806 - return write_compressed_tar_archive(args, argv);
1807 + return write_compressed_tar_archive(hex, prefix, argv);
1810 const struct cgit_snapshot_format cgit_snapshot_formats[] = {
1811 @@ -48,7 +73,7 @@ const struct cgit_snapshot_format cgit_snapshot_formats[] = {
1812 { ".tar.bz2", "application/x-bzip2", write_tar_bzip2_archive, 0x04 },
1813 { ".tar", "application/x-tar", write_tar_archive, 0x08 },
1814 { ".tar.xz", "application/x-xz", write_tar_xz_archive, 0x10 },
1819 static const struct cgit_snapshot_format *get_format(const char *filename)
1820 @@ -57,7 +82,7 @@ static const struct cgit_snapshot_format *get_format(const char *filename)
1823 fl = strlen(filename);
1824 - for(fmt = cgit_snapshot_formats; fmt->suffix; fmt++) {
1825 + for (fmt = cgit_snapshot_formats; fmt->suffix; fmt++) {
1826 sl = strlen(fmt->suffix);
1829 @@ -71,34 +96,20 @@ static int make_snapshot(const struct cgit_snapshot_format *format,
1830 const char *hex, const char *prefix,
1831 const char *filename)
1833 - struct archiver_args args;
1834 - struct commit *commit;
1835 unsigned char sha1[20];
1837 - if(get_sha1(hex, sha1)) {
1838 + if (get_sha1(hex, sha1)) {
1839 cgit_print_error(fmt("Bad object id: %s", hex));
1842 - commit = lookup_commit_reference(sha1);
1844 + if (!lookup_commit_reference(sha1)) {
1845 cgit_print_error(fmt("Not a commit reference: %s", hex));
1848 - memset(&args, 0, sizeof(args));
1850 - args.base = fmt("%s/", prefix);
1851 - args.baselen = strlen(prefix) + 1;
1856 - args.tree = commit->tree;
1857 - args.time = commit->date;
1858 - args.compression_level = Z_DEFAULT_COMPRESSION;
1859 ctx.page.mimetype = xstrdup(format->mimetype);
1860 ctx.page.filename = xstrdup(filename);
1861 cgit_print_http_headers(&ctx);
1862 - format->write_func(&args);
1863 + format->write_func(hex, prefix);
1867 diff --git a/ui-ssdiff.c b/ui-ssdiff.c
1868 index 7108779..3d3dad6 100644
1871 @@ -138,9 +138,8 @@ static char *replace_tabs(char *line)
1872 strcat(result, prev_buf);
1875 - strcat(result, " ");
1876 - strncat(result, spaces, 8 - (strlen(result) % 8));
1877 strncat(result, prev_buf, cur_buf - prev_buf);
1878 + strncat(result, spaces, 8 - (strlen(result) % 8));
1880 prev_buf = cur_buf + 1;
1882 diff --git a/ui-stats.c b/ui-stats.c
1883 index 59f4c1e..9cf1dbd 100644
1886 @@ -23,21 +23,21 @@ static void trunc_week(struct tm *tm)
1888 time_t t = timegm(tm);
1889 t -= ((tm->tm_wday + 6) % 7) * DAY_SECS;
1894 static void dec_week(struct tm *tm)
1896 time_t t = timegm(tm);
1902 static void inc_week(struct tm *tm)
1904 time_t t = timegm(tm);
1910 static char *pretty_week(struct tm *tm)
1911 @@ -83,7 +83,7 @@ static char *pretty_month(struct tm *tm)
1912 static void trunc_quarter(struct tm *tm)
1915 - while(tm->tm_mon % 3 != 0)
1916 + while (tm->tm_mon % 3 != 0)
1920 @@ -153,7 +153,7 @@ int cgit_find_stats_period(const char *expr, struct cgit_period **period)
1921 if (periods[i].code == code || !strcmp(periods[i].name, expr)) {
1923 *period = &periods[i];
1929 @@ -239,7 +239,7 @@ struct string_list collect_stats(struct cgit_context *ctx,
1930 init_revisions(&rev, NULL);
1931 rev.abbrev = DEFAULT_ABBREV;
1932 rev.commit_format = CMIT_FMT_DEFAULT;
1933 - rev.no_merges = 1;
1934 + rev.max_parents = 1;
1935 rev.verbose_header = 1;
1936 rev.show_root_diff = 0;
1937 setup_revisions(argc, argv, &rev, NULL);
1938 diff --git a/ui-tag.c b/ui-tag.c
1939 index 39e4cb8..cab96b1 100644
1942 @@ -99,6 +99,6 @@ void cgit_print_tag(char *revname)
1943 if (ctx.repo->snapshots)
1944 print_download_links(revname);
1950 diff --git a/ui-tree.c b/ui-tree.c
1951 index b1adcc7..561f9e7 100644
1956 #include "ui-shared.h"
1961 +struct walk_tree_context {
1967 static void print_text_buffer(const char *name, char *buf, unsigned long size)
1969 @@ -27,10 +29,10 @@ static void print_text_buffer(const char *name, char *buf, unsigned long size)
1970 html("<tr><td class='linenumbers'><pre>");
1976 htmlf(numberfmt, ++lineno);
1977 - while(idx < size - 1) { // skip absolute last newline
1978 + while (idx < size - 1) { // skip absolute last newline
1979 if (buf[idx] == '\n')
1980 htmlf(numberfmt, ++lineno);
1982 @@ -84,7 +86,7 @@ static void print_binary_buffer(char *buf, unsigned long size)
1986 -static void print_object(const unsigned char *sha1, char *path, const char *basename)
1987 +static void print_object(const unsigned char *sha1, char *path, const char *basename, const char *rev)
1989 enum object_type type;
1991 @@ -106,7 +108,7 @@ static void print_object(const unsigned char *sha1, char *path, const char *base
1993 htmlf("blob: %s (", sha1_to_hex(sha1));
1994 cgit_plain_link("plain", NULL, NULL, ctx.qry.head,
1999 if (ctx.cfg.max_blob_size && size / 1024 > ctx.cfg.max_blob_size) {
2000 @@ -126,6 +128,7 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen,
2001 const char *pathname, unsigned int mode, int stage,
2004 + struct walk_tree_context *walk_tree_ctx = cbdata;
2008 @@ -153,7 +156,7 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen,
2009 cgit_submodule_link("ls-mod", fullpath, sha1_to_hex(sha1));
2010 } else if (S_ISDIR(mode)) {
2011 cgit_tree_link(name, NULL, "ls-dir", ctx.qry.head,
2012 - curr_rev, fullpath);
2013 + walk_tree_ctx->curr_rev, fullpath);
2015 class = strrchr(name, '.');
2016 if (class != NULL) {
2017 @@ -161,19 +164,20 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen,
2020 cgit_tree_link(name, NULL, class, ctx.qry.head,
2021 - curr_rev, fullpath);
2022 + walk_tree_ctx->curr_rev, fullpath);
2024 htmlf("</td><td class='ls-size'>%li</td>", size);
2027 - cgit_log_link("log", NULL, "button", ctx.qry.head, curr_rev,
2028 - fullpath, 0, NULL, NULL, ctx.qry.showmsg);
2029 + cgit_log_link("log", NULL, "button", ctx.qry.head,
2030 + walk_tree_ctx->curr_rev, fullpath, 0, NULL, NULL,
2032 if (ctx.repo->max_stats)
2033 cgit_stats_link("stats", NULL, "button", ctx.qry.head,
2035 if (!S_ISGITLINK(mode))
2036 - cgit_plain_link("plain", NULL, "button", ctx.qry.head, curr_rev,
2038 + cgit_plain_link("plain", NULL, "button", ctx.qry.head,
2039 + walk_tree_ctx->curr_rev, fullpath);
2040 html("</td></tr>\n");
2043 @@ -188,20 +192,19 @@ static void ls_head()
2044 html("<th class='right'>Size</th>");
2050 static void ls_tail()
2058 -static void ls_tree(const unsigned char *sha1, char *path)
2059 +static void ls_tree(const unsigned char *sha1, char *path, struct walk_tree_context *walk_tree_ctx)
2062 + struct pathspec paths = {
2066 tree = parse_tree_indirect(sha1);
2068 @@ -211,7 +214,7 @@ static void ls_tree(const unsigned char *sha1, char *path)
2072 - read_tree_recursive(tree, "", 0, 1, NULL, ls_item, NULL);
2073 + read_tree_recursive(tree, "", 0, 1, &paths, ls_item, walk_tree_ctx);
2077 @@ -220,25 +223,25 @@ static int walk_tree(const unsigned char *sha1, const char *base, int baselen,
2078 const char *pathname, unsigned mode, int stage,
2082 + struct walk_tree_context *walk_tree_ctx = cbdata;
2083 static char buffer[PATH_MAX];
2086 + if (walk_tree_ctx->state == 0) {
2087 memcpy(buffer, base, baselen);
2088 - strcpy(buffer+baselen, pathname);
2089 - if (strcmp(match_path, buffer))
2090 + strcpy(buffer + baselen, pathname);
2091 + if (strcmp(walk_tree_ctx->match_path, buffer))
2092 return READ_TREE_RECURSIVE;
2094 if (S_ISDIR(mode)) {
2096 + walk_tree_ctx->state = 1;
2098 return READ_TREE_RECURSIVE;
2100 - print_object(sha1, buffer, pathname);
2101 + print_object(sha1, buffer, pathname, walk_tree_ctx->curr_rev);
2105 - ls_item(sha1, base, baselen, pathname, mode, stage, NULL);
2106 + ls_item(sha1, base, baselen, pathname, mode, stage, walk_tree_ctx);
2110 @@ -252,12 +255,23 @@ void cgit_print_tree(const char *rev, char *path)
2112 unsigned char sha1[20];
2113 struct commit *commit;
2114 - const char *paths[] = {path, NULL};
2115 + struct pathspec_item path_items = {
2117 + .len = path ? strlen(path) : 0
2119 + struct pathspec paths = {
2120 + .nr = path ? 1 : 0,
2121 + .items = &path_items
2123 + struct walk_tree_context walk_tree_ctx = {
2124 + .match_path = path,
2131 - curr_rev = xstrdup(rev);
2132 + walk_tree_ctx.curr_rev = xstrdup(rev);
2133 if (get_sha1(rev, sha1)) {
2134 cgit_print_error(fmt("Invalid revision name: %s", rev));
2136 @@ -269,11 +283,11 @@ void cgit_print_tree(const char *rev, char *path)
2140 - ls_tree(commit->tree->object.sha1, NULL);
2141 + ls_tree(commit->tree->object.sha1, NULL, &walk_tree_ctx);
2145 - match_path = path;
2146 - read_tree_recursive(commit->tree, "", 0, 0, paths, walk_tree, NULL);
2148 + read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx);
2149 + if (walk_tree_ctx.state == 1)