From 97a91657a5032aa984d91344b91e1c5a084c2f0d Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Sat, 7 Mar 2015 12:44:39 +0100 Subject: [PATCH 001/387] git: update to v2.3.2 Update to git version v2.3.2, no changes required. Signed-off-by: Christian Hesse --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index a6935c0..ed329e8 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = -GIT_VER = 2.3.1 +GIT_VER = 2.3.2 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.gz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index 8004647..1165ae6 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 8004647a217c26f708bce2aa26ed94a4a0ed575d +Subproject commit 1165ae6f3d42e0eb0ddfc2d4e6dfa8bd0b88eb60 From 5150b7c1e69b4b09821e438006cfd77d82edae3b Mon Sep 17 00:00:00 2001 From: John Keeping Date: Sun, 8 Mar 2015 16:32:15 +0000 Subject: [PATCH 002/387] Makefile: add a target to run CGit through sparse Signed-off-by: John Keeping --- Makefile | 3 +++ cgit.mk | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ed329e8..42ed230 100644 --- a/Makefile +++ b/Makefile @@ -68,6 +68,9 @@ all:: cgit cgit: $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) -f ../cgit.mk ../cgit $(EXTRA_GIT_TARGETS) NO_CURL=1 +sparse: + $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) -f ../cgit.mk NO_CURL=1 cgit-sparse + test: @$(MAKE) --no-print-directory cgit EXTRA_GIT_TARGETS=all $(QUIET_SUBDIR0)tests $(QUIET_SUBDIR1) all diff --git a/cgit.mk b/cgit.mk index 5048b09..1b50307 100644 --- a/cgit.mk +++ b/cgit.mk @@ -96,7 +96,7 @@ CGIT_OBJS := $(addprefix $(CGIT_PREFIX),$(CGIT_OBJ_NAMES)) # Only cgit.c reference CGIT_VERSION so we only rebuild its objects when the # version changes. -CGIT_VERSION_OBJS := $(addprefix $(CGIT_PREFIX),cgit.o) +CGIT_VERSION_OBJS := $(addprefix $(CGIT_PREFIX),cgit.o cgit.sp) $(CGIT_VERSION_OBJS): $(CGIT_PREFIX)VERSION $(CGIT_VERSION_OBJS): EXTRA_CPPFLAGS = \ -DCGIT_VERSION='"$(CGIT_VERSION)"' @@ -129,3 +129,10 @@ $(CGIT_OBJS): %.o: %.c GIT-CFLAGS $(CGIT_PREFIX)CGIT-CFLAGS $(missing_dep_dirs) $(CGIT_PREFIX)cgit: $(CGIT_OBJS) GIT-LDFLAGS $(GITLIBS) @echo 1>&1 " * $(LUA_MESSAGE)" $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) $(CGIT_LIBS) + +CGIT_SP_OBJS := $(patsubst %.o,%.sp,$(CGIT_OBJS)) + +$(CGIT_SP_OBJS): %.sp: %.c GIT-CFLAGS $(CGIT_PREFIX)CGIT-CFLAGS FORCE + $(QUIET_SP)cgcc -no-compile $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) $(CGIT_CFLAGS) $(SPARSE_FLAGS) $< + +cgit-sparse: $(CGIT_SP_OBJS) From e3d3fffdd447cdb4551549faae65bae5353a2cab Mon Sep 17 00:00:00 2001 From: John Keeping Date: Sun, 8 Mar 2015 16:32:16 +0000 Subject: [PATCH 003/387] Avoid non-ANSI function declarations Sparse says things like: warning: non-ANSI function declaration of function 'calc_ttl' Signed-off-by: John Keeping --- cgit.c | 2 +- filter.c | 2 +- ui-diff.c | 2 +- ui-refs.c | 4 ++-- ui-repolist.c | 6 +++--- ui-shared.c | 12 ++++++------ ui-ssdiff.c | 16 ++++++++-------- ui-summary.c | 2 +- ui-tree.c | 4 ++-- 9 files changed, 25 insertions(+), 25 deletions(-) diff --git a/cgit.c b/cgit.c index 0ad8171..c16ed8c 100644 --- a/cgit.c +++ b/cgit.c @@ -1013,7 +1013,7 @@ static void cgit_parse_args(int argc, const char **argv) } } -static int calc_ttl() +static int calc_ttl(void) { if (!ctx.repo) return ctx.cfg.cache_root_ttl; diff --git a/filter.c b/filter.c index 9f433db..ebf4937 100644 --- a/filter.c +++ b/filter.c @@ -72,7 +72,7 @@ static inline void hook_write(struct cgit_filter *filter, ssize_t (*new_write)(s filter_write = new_write; } -static inline void unhook_write() +static inline void unhook_write(void) { assert(filter_write != NULL); assert(current_write_filter != NULL); diff --git a/ui-diff.c b/ui-diff.c index 5b6df1f..8eff178 100644 --- a/ui-diff.c +++ b/ui-diff.c @@ -311,7 +311,7 @@ static void filepair_cb(struct diff_filepair *pair) cgit_ssdiff_footer(); } -void cgit_print_diff_ctrls() +void cgit_print_diff_ctrls(void) { int i, curr; diff --git a/ui-refs.c b/ui-refs.c index ac8a6d4..d3d71dd 100644 --- a/ui-refs.c +++ b/ui-refs.c @@ -82,7 +82,7 @@ static int print_branch(struct refinfo *ref) return 0; } -static void print_tag_header() +static void print_tag_header(void) { html("Tag" "Download" @@ -234,7 +234,7 @@ void cgit_print_tags(int maxcount) cgit_free_reflist_inner(&list); } -void cgit_print_refs() +void cgit_print_refs(void) { html(""); diff --git a/ui-repolist.c b/ui-repolist.c index e945f67..a6d0321 100644 --- a/ui-repolist.c +++ b/ui-repolist.c @@ -117,7 +117,7 @@ static void print_sort_header(const char *title, const char *sort) htmlf("'>%s", title); } -static void print_header() +static void print_header(void) { html(""); print_sort_header("Name", "name"); @@ -247,7 +247,7 @@ static int sort_repolist(char *field) } -void cgit_print_repolist() +void cgit_print_repolist(void) { int i, columns = 3, hits = 0, header = 0; char *last_section = NULL; @@ -344,7 +344,7 @@ void cgit_print_repolist() cgit_print_docend(); } -void cgit_print_site_readme() +void cgit_print_site_readme(void) { if (!ctx.cfg.root_readme) return; diff --git a/ui-shared.c b/ui-shared.c index ff03cb2..6d3cfa9 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -46,7 +46,7 @@ void cgit_vprint_error(const char *fmt, va_list ap) html("\n"); } -const char *cgit_httpscheme() +const char *cgit_httpscheme(void) { if (ctx.env.https && !strcmp(ctx.env.https, "on")) return "https://"; @@ -54,7 +54,7 @@ const char *cgit_httpscheme() return "http://"; } -const char *cgit_hosturl() +const char *cgit_hosturl(void) { if (ctx.env.http_host) return ctx.env.http_host; @@ -65,14 +65,14 @@ const char *cgit_hosturl() return fmtalloc("%s:%s", ctx.env.server_name, ctx.env.server_port); } -const char *cgit_currenturl() +const char *cgit_currenturl(void) { if (!ctx.qry.url) return cgit_rooturl(); return ctx.qry.url; } -const char *cgit_rooturl() +const char *cgit_rooturl(void) { if (ctx.cfg.virtual_root) return ctx.cfg.virtual_root; @@ -80,7 +80,7 @@ const char *cgit_rooturl() return ctx.cfg.script_name; } -const char *cgit_loginurl() +const char *cgit_loginurl(void) { static const char *login_url = 0; if (!login_url) @@ -735,7 +735,7 @@ void cgit_print_docstart(void) html_include(ctx.cfg.header); } -void cgit_print_docend() +void cgit_print_docend(void) { html("\n"); if (ctx.cfg.embedded) { diff --git a/ui-ssdiff.c b/ui-ssdiff.c index 08cf513..2146c71 100644 --- a/ui-ssdiff.c +++ b/ui-ssdiff.c @@ -18,7 +18,7 @@ struct deferred_lines { static struct deferred_lines *deferred_old, *deferred_old_last; static struct deferred_lines *deferred_new, *deferred_new_last; -static void create_or_reset_lcs_table() +static void create_or_reset_lcs_table(void) { int i; @@ -276,7 +276,7 @@ static void print_ssdiff_line(char *class, free(old_line); } -static void print_deferred_old_lines() +static void print_deferred_old_lines(void) { struct deferred_lines *iter_old, *tmp; iter_old = deferred_old; @@ -289,7 +289,7 @@ static void print_deferred_old_lines() } } -static void print_deferred_new_lines() +static void print_deferred_new_lines(void) { struct deferred_lines *iter_new, *tmp; iter_new = deferred_new; @@ -302,7 +302,7 @@ static void print_deferred_new_lines() } } -static void print_deferred_changed_lines() +static void print_deferred_changed_lines(void) { struct deferred_lines *iter_old, *iter_new, *tmp; int n_old_lines = calc_deferred_lines(deferred_old); @@ -337,7 +337,7 @@ static void print_deferred_changed_lines() } } -void cgit_ssdiff_print_deferred_lines() +void cgit_ssdiff_print_deferred_lines(void) { if (!deferred_old && !deferred_new) return; @@ -388,7 +388,7 @@ void cgit_ssdiff_line_cb(char *line, int len) line[len - 1] = c; } -void cgit_ssdiff_header_begin() +void cgit_ssdiff_header_begin(void) { current_old_line = -1; current_new_line = -1; @@ -396,12 +396,12 @@ void cgit_ssdiff_header_begin() html(""); } -void cgit_ssdiff_footer() +void cgit_ssdiff_footer(void) { if (deferred_old || deferred_new) cgit_ssdiff_print_deferred_lines(); diff --git a/ui-summary.c b/ui-summary.c index fa5ba04..b0af073 100644 --- a/ui-summary.c +++ b/ui-summary.c @@ -40,7 +40,7 @@ static void print_url(const char *url) html("\n"); } -void cgit_print_summary() +void cgit_print_summary(void) { int columns = 3; diff --git a/ui-tree.c b/ui-tree.c index 4ab0137..bbc468e 100644 --- a/ui-tree.c +++ b/ui-tree.c @@ -180,7 +180,7 @@ static int ls_item(const unsigned char *sha1, struct strbuf *base, return 0; } -static void ls_head() +static void ls_head(void) { html("
"); } -void cgit_ssdiff_header_end() +void cgit_ssdiff_header_end(void) { html("
\n"); html(""); @@ -191,7 +191,7 @@ static void ls_head() html("\n"); } -static void ls_tail() +static void ls_tail(void) { html("
\n"); } From 12d3d4c3edfcf177c56ca97e5a4b0c8301ca46aa Mon Sep 17 00:00:00 2001 From: John Keeping Date: Sun, 8 Mar 2015 16:32:17 +0000 Subject: [PATCH 004/387] Avoid signed bitfields Bitfields are only defined for unsigned types. Detected by sparse. Signed-off-by: John Keeping --- ui-blob.c | 4 ++-- ui-diff.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ui-blob.c b/ui-blob.c index a025bca..388a017 100644 --- a/ui-blob.c +++ b/ui-blob.c @@ -14,8 +14,8 @@ struct walk_tree_context { const char *match_path; unsigned char *matched_sha1; - int found_path:1; - int file_only:1; + unsigned int found_path:1; + unsigned int file_only:1; }; static int walk_tree(const unsigned char *sha1, struct strbuf *base, diff --git a/ui-diff.c b/ui-diff.c index 8eff178..1cf2ce0 100644 --- a/ui-diff.c +++ b/ui-diff.c @@ -31,7 +31,7 @@ static struct fileinfo { unsigned int removed; unsigned long old_size; unsigned long new_size; - int binary:1; + unsigned int binary:1; } *items; static int use_ssdiff = 0; From 812cd49e3144946bbe604064abb1a442daa1eb9e Mon Sep 17 00:00:00 2001 From: John Keeping Date: Sun, 8 Mar 2015 16:32:18 +0000 Subject: [PATCH 005/387] scan-tree: make some variables 'static' These are not used outside this file and are not declared. Signed-off-by: John Keeping --- scan-tree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scan-tree.c b/scan-tree.c index e900ad9..8e3cf52 100644 --- a/scan-tree.c +++ b/scan-tree.c @@ -45,8 +45,8 @@ out: return result; } -struct cgit_repo *repo; -repo_config_fn config_fn; +static struct cgit_repo *repo; +static repo_config_fn config_fn; static void repo_config(const char *name, const char *value) { From eefd5e0aea23010c3f6667ba30e607e68427f9ad Mon Sep 17 00:00:00 2001 From: John Keeping Date: Sun, 8 Mar 2015 16:32:19 +0000 Subject: [PATCH 006/387] shared: make some variables 'static' These are not used outside this file and are not declared. Signed-off-by: John Keeping --- shared.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared.c b/shared.c index ae17d78..a99173b 100644 --- a/shared.c +++ b/shared.c @@ -284,8 +284,8 @@ static int load_mmfile(mmfile_t *file, const unsigned char *sha1) * ripped from git and modified to use globals instead of * a special callback-struct. */ -char *diffbuf = NULL; -int buflen = 0; +static char *diffbuf = NULL; +static int buflen = 0; static int filediff_cb(void *priv, mmbuffer_t *mb, int nbuf) { From 3fe509e17a337cbaa300b4b9aa2a248c2d0be873 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Sun, 8 Mar 2015 16:32:20 +0000 Subject: [PATCH 007/387] ui-log: make some variables 'static' These are not used outside this file and are not declared. Signed-off-by: John Keeping --- ui-log.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui-log.c b/ui-log.c index 1b60591..32b4c47 100644 --- a/ui-log.c +++ b/ui-log.c @@ -12,7 +12,7 @@ #include "ui-shared.h" #include "argv-array.h" -int files, add_lines, rem_lines; +static int files, add_lines, rem_lines; /* * The list of available column colors in the commit graph. From ad74669e67ea08969776e6700ec37323e4935e23 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Sun, 8 Mar 2015 16:32:21 +0000 Subject: [PATCH 008/387] ui-repolist: make sortcolumn definitions 'static const' These are not used outside this file and are not declared; they are also never modified. Signed-off-by: John Keeping --- ui-repolist.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui-repolist.c b/ui-repolist.c index a6d0321..2453a7f 100644 --- a/ui-repolist.c +++ b/ui-repolist.c @@ -223,7 +223,7 @@ struct sortcolumn { int (*fn)(const void *a, const void *b); }; -struct sortcolumn sortcolumn[] = { +static const struct sortcolumn sortcolumn[] = { {"section", sort_section}, {"name", sort_name}, {"desc", sort_desc}, @@ -234,7 +234,7 @@ struct sortcolumn sortcolumn[] = { static int sort_repolist(char *field) { - struct sortcolumn *column; + const struct sortcolumn *column; for (column = &sortcolumn[0]; column->name; column++) { if (strcmp(field, column->name)) From 0f23d4651c80170574c0ab2f091c0718150631ce Mon Sep 17 00:00:00 2001 From: John Keeping Date: Sun, 8 Mar 2015 16:32:22 +0000 Subject: [PATCH 009/387] ui-shared: make cgit_doctype 'static' This is not used outside this file and is not declared. Signed-off-by: John Keeping --- ui-shared.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui-shared.c b/ui-shared.c index 6d3cfa9..d4c4bb9 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -11,7 +11,7 @@ #include "cmd.h" #include "html.h" -const char cgit_doctype[] = +static const char cgit_doctype[] = "\n"; From bd9fb0324d776aa5583a70a6125fce47697701b1 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Sun, 8 Mar 2015 16:32:23 +0000 Subject: [PATCH 010/387] ui-stats: make cgit_period definitions 'static const' These definitions should not be modified (and never are) so we can move them to .rodata. Signed-off-by: John Keeping --- ui-stats.c | 14 +++++++------- ui-stats.h | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ui-stats.c b/ui-stats.c index a264f6a..9cd8247 100644 --- a/ui-stats.c +++ b/ui-stats.c @@ -125,7 +125,7 @@ static char *pretty_year(struct tm *tm) return fmt("%d", tm->tm_year + 1900); } -struct cgit_period periods[] = { +static const struct cgit_period periods[] = { {'w', "week", 12, 4, trunc_week, dec_week, inc_week, pretty_week}, {'m', "month", 12, 4, trunc_month, dec_month, inc_month, pretty_month}, {'q', "quarter", 12, 4, trunc_quarter, dec_quarter, inc_quarter, pretty_quarter}, @@ -136,7 +136,7 @@ struct cgit_period periods[] = { * and update the period pointer to the correcsponding struct. * If no matching code is found, return 0. */ -int cgit_find_stats_period(const char *expr, struct cgit_period **period) +int cgit_find_stats_period(const char *expr, const struct cgit_period **period) { int i; char code = '\0'; @@ -165,7 +165,7 @@ const char *cgit_find_stats_periodname(int idx) } static void add_commit(struct string_list *authors, struct commit *commit, - struct cgit_period *period) + const struct cgit_period *period) { struct commitinfo *info; struct string_list_item *author, *item; @@ -209,7 +209,7 @@ static int cmp_total_commits(const void *a1, const void *a2) /* Walk the commit DAG and collect number of commits per author per * timeperiod into a nested string_list collection. */ -static struct string_list collect_stats(struct cgit_period *period) +static struct string_list collect_stats(const struct cgit_period *period) { struct string_list authors; struct rev_info rev; @@ -256,7 +256,7 @@ static void print_combined_authorrow(struct string_list *authors, int from, const char *leftclass, const char *centerclass, const char *rightclass, - struct cgit_period *period) + const struct cgit_period *period) { struct string_list_item *author; struct authorstat *authorstat; @@ -295,7 +295,7 @@ static void print_combined_authorrow(struct string_list *authors, int from, } static void print_authors(struct string_list *authors, int top, - struct cgit_period *period) + const struct cgit_period *period) { struct string_list_item *author; struct authorstat *authorstat; @@ -363,7 +363,7 @@ static void print_authors(struct string_list *authors, int top, void cgit_show_stats(void) { struct string_list authors; - struct cgit_period *period; + const struct cgit_period *period; int top, i; const char *code = "w"; diff --git a/ui-stats.h b/ui-stats.h index 341ab13..0e61b03 100644 --- a/ui-stats.h +++ b/ui-stats.h @@ -20,7 +20,7 @@ struct cgit_period { char *(*pretty)(struct tm *tm); }; -extern int cgit_find_stats_period(const char *expr, struct cgit_period **period); +extern int cgit_find_stats_period(const char *expr, const struct cgit_period **period); extern const char *cgit_find_stats_periodname(int idx); extern void cgit_show_stats(void); From 94e5f212f55d3f4dd6ce83edb6db823de7eb8cc7 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Sun, 8 Mar 2015 16:32:24 +0000 Subject: [PATCH 011/387] ui-shared: avoid initializing static variable to zero Sparse complains that we are using a plain integer as a NULL pointer here, but in fact we do not have to specify a value for this variable at all since it has static storage duration and thus will be initialized to NULL by the compiler. Signed-off-by: John Keeping --- ui-shared.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui-shared.c b/ui-shared.c index d4c4bb9..1e3c131 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -82,7 +82,7 @@ const char *cgit_rooturl(void) const char *cgit_loginurl(void) { - static const char *login_url = 0; + static const char *login_url; if (!login_url) login_url = fmtalloc("%s?p=login", cgit_rooturl()); return login_url; From d34b96719053ff9340519b64f6d970caaa64350d Mon Sep 17 00:00:00 2001 From: John Keeping Date: Sun, 8 Mar 2015 16:32:25 +0000 Subject: [PATCH 012/387] ui-shared: don't use an integer as a NULL pointer Signed-off-by: John Keeping --- ui-shared.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui-shared.c b/ui-shared.c index 1e3c131..7bcb8d3 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -119,7 +119,7 @@ char *cgit_fileurl(const char *reponame, const char *pagename, char *cgit_pageurl(const char *reponame, const char *pagename, const char *query) { - return cgit_fileurl(reponame, pagename, 0, query); + return cgit_fileurl(reponame, pagename, NULL, query); } const char *cgit_repobasename(const char *reponame) From 80d52079f7f58d273d99745f93909e5c6524a9bd Mon Sep 17 00:00:00 2001 From: John Keeping Date: Sun, 8 Mar 2015 16:32:26 +0000 Subject: [PATCH 013/387] cache: don't use an integer as a NULL pointer Signed-off-by: John Keeping --- cache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cache.c b/cache.c index 900b161..cd99812 100644 --- a/cache.c +++ b/cache.c @@ -411,7 +411,7 @@ int cache_ls(const char *path) DIR *dir; struct dirent *ent; int err = 0; - struct cache_slot slot = { 0 }; + struct cache_slot slot = { NULL }; struct strbuf fullname = STRBUF_INIT; size_t prefixlen; From 438bac6f579dab5b8f64e8ce42b88cfc3f053b28 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Sun, 8 Mar 2015 16:32:27 +0000 Subject: [PATCH 014/387] html: avoid using a plain integer as a NULL pointer Sparse complains about this table because we use the integer zero as the NULL pointer. Use this as an opportunity to reformat the table so that it always contains 8 elements per row, making it easier to see which values are being set and which are not. Signed-off-by: John Keeping --- html.c | 54 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/html.c b/html.c index f0ee2d6..155cde5 100644 --- a/html.c +++ b/html.c @@ -17,28 +17,38 @@ /* Percent-encoding of each character, except: a-zA-Z0-9!$()*,./:;@- */ static const char* url_escape_table[256] = { - "%00", "%01", "%02", "%03", "%04", "%05", "%06", "%07", "%08", "%09", - "%0a", "%0b", "%0c", "%0d", "%0e", "%0f", "%10", "%11", "%12", "%13", - "%14", "%15", "%16", "%17", "%18", "%19", "%1a", "%1b", "%1c", "%1d", - "%1e", "%1f", "%20", 0, "%22", "%23", 0, "%25", "%26", "%27", 0, 0, 0, - "%2b", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "%3c", "%3d", - "%3e", "%3f", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, "%5c", 0, "%5e", 0, "%60", 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "%7b", - "%7c", "%7d", 0, "%7f", "%80", "%81", "%82", "%83", "%84", "%85", - "%86", "%87", "%88", "%89", "%8a", "%8b", "%8c", "%8d", "%8e", "%8f", - "%90", "%91", "%92", "%93", "%94", "%95", "%96", "%97", "%98", "%99", - "%9a", "%9b", "%9c", "%9d", "%9e", "%9f", "%a0", "%a1", "%a2", "%a3", - "%a4", "%a5", "%a6", "%a7", "%a8", "%a9", "%aa", "%ab", "%ac", "%ad", - "%ae", "%af", "%b0", "%b1", "%b2", "%b3", "%b4", "%b5", "%b6", "%b7", - "%b8", "%b9", "%ba", "%bb", "%bc", "%bd", "%be", "%bf", "%c0", "%c1", - "%c2", "%c3", "%c4", "%c5", "%c6", "%c7", "%c8", "%c9", "%ca", "%cb", - "%cc", "%cd", "%ce", "%cf", "%d0", "%d1", "%d2", "%d3", "%d4", "%d5", - "%d6", "%d7", "%d8", "%d9", "%da", "%db", "%dc", "%dd", "%de", "%df", - "%e0", "%e1", "%e2", "%e3", "%e4", "%e5", "%e6", "%e7", "%e8", "%e9", - "%ea", "%eb", "%ec", "%ed", "%ee", "%ef", "%f0", "%f1", "%f2", "%f3", - "%f4", "%f5", "%f6", "%f7", "%f8", "%f9", "%fa", "%fb", "%fc", "%fd", - "%fe", "%ff" + "%00", "%01", "%02", "%03", "%04", "%05", "%06", "%07", + "%08", "%09", "%0a", "%0b", "%0c", "%0d", "%0e", "%0f", + "%10", "%11", "%12", "%13", "%14", "%15", "%16", "%17", + "%18", "%19", "%1a", "%1b", "%1c", "%1d", "%1e", "%1f", + "%20", NULL, "%22", "%23", NULL, "%25", "%26", "%27", + NULL, NULL, NULL, "%2b", NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, "%3c", "%3d", "%3e", "%3f", + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, "%5c", NULL, "%5e", NULL, + "%60", NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, "%7b", "%7c", "%7d", NULL, "%7f", + "%80", "%81", "%82", "%83", "%84", "%85", "%86", "%87", + "%88", "%89", "%8a", "%8b", "%8c", "%8d", "%8e", "%8f", + "%90", "%91", "%92", "%93", "%94", "%95", "%96", "%97", + "%98", "%99", "%9a", "%9b", "%9c", "%9d", "%9e", "%9f", + "%a0", "%a1", "%a2", "%a3", "%a4", "%a5", "%a6", "%a7", + "%a8", "%a9", "%aa", "%ab", "%ac", "%ad", "%ae", "%af", + "%b0", "%b1", "%b2", "%b3", "%b4", "%b5", "%b6", "%b7", + "%b8", "%b9", "%ba", "%bb", "%bc", "%bd", "%be", "%bf", + "%c0", "%c1", "%c2", "%c3", "%c4", "%c5", "%c6", "%c7", + "%c8", "%c9", "%ca", "%cb", "%cc", "%cd", "%ce", "%cf", + "%d0", "%d1", "%d2", "%d3", "%d4", "%d5", "%d6", "%d7", + "%d8", "%d9", "%da", "%db", "%dc", "%dd", "%de", "%df", + "%e0", "%e1", "%e2", "%e3", "%e4", "%e5", "%e6", "%e7", + "%e8", "%e9", "%ea", "%eb", "%ec", "%ed", "%ee", "%ef", + "%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7", + "%f8", "%f9", "%fa", "%fb", "%fc", "%fd", "%fe", "%ff" }; char *fmt(const char *format, ...) From 8eef4589d0ba80fd4e6a9ce2f3ca4fcf266a64e0 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Sun, 8 Mar 2015 12:34:07 +0100 Subject: [PATCH 015/387] ui-shared: currenturl should take into account leading slash --- ui-shared.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ui-shared.c b/ui-shared.c index 7bcb8d3..23a893b 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -69,7 +69,11 @@ const char *cgit_currenturl(void) { if (!ctx.qry.url) return cgit_rooturl(); - return ctx.qry.url; + const char *root = cgit_rooturl(); + size_t len = strlen(root); + if (len && root[len - 1] == '/') + return fmtalloc("%s%s", root, ctx.qry.url); + return fmtalloc("%s/%s", root, ctx.qry.url); } const char *cgit_rooturl(void) From f3ab1f178f6b7822fc701efbfc9dea8c294cb04f Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Sun, 8 Mar 2015 13:08:04 +0100 Subject: [PATCH 016/387] cgit: remember to set up env vars before empty clone path --- cgit.c | 1 + 1 file changed, 1 insertion(+) diff --git a/cgit.c b/cgit.c index c16ed8c..ae413c6 100644 --- a/cgit.c +++ b/cgit.c @@ -599,6 +599,7 @@ static int prepare_repo_cmd(void) cgit_print_error("Repository seems to be empty"); if (!strcmp(ctx.qry.page, "summary")) { html("\n"); + cgit_prepare_repo_env(ctx.repo); cgit_add_clone_urls(print_no_repo_clone_urls); html("
 
Clone
\n"); } From 7511f4b4df521656d422010b06e2b5b96b21eb84 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Tue, 10 Mar 2015 02:21:31 +0100 Subject: [PATCH 017/387] filters: Add sample gentoo script --- filters/gentoo-ldap-authentication.lua | 320 +++++++++++++++++++++++++ 1 file changed, 320 insertions(+) create mode 100644 filters/gentoo-ldap-authentication.lua diff --git a/filters/gentoo-ldap-authentication.lua b/filters/gentoo-ldap-authentication.lua new file mode 100644 index 0000000..fce5632 --- /dev/null +++ b/filters/gentoo-ldap-authentication.lua @@ -0,0 +1,320 @@ +-- This script may be used with the auth-filter. Be sure to configure it as you wish. +-- +-- Requirements: +-- luacrypto >= 0.3 +-- +-- lualdap >= 1.2 +-- +-- + + +-- +-- +-- Configure these variables for your settings. +-- +-- + +-- A list of password protected repositories, with which gentooAccess +-- group is allowed to access each one. +local protected_repos = { + glouglou = "infra", + portage = "dev" +} + + +-- All cookies will be authenticated based on this secret. Make it something +-- totally random and impossible to guess. It should be large. +local secret = "BE SURE TO CUSTOMIZE THIS STRING TO SOMETHING BIG AND RANDOM" + + + +-- +-- +-- Authentication functions follow below. Swap these out if you want different authentication semantics. +-- +-- + +-- Sets HTTP cookie headers based on post and sets up redirection. +function authenticate_post() + local redirect = validate_value("redirect", post["redirect"]) + + if redirect == nil then + not_found() + return 0 + end + + redirect_to(redirect) + + local groups = gentoo_ldap_user_groups(post["username"], post["password"]) + if groups == nil then + set_cookie("cgitauth", "") + else + -- One week expiration time + set_cookie("cgitauth", secure_value("gentoogroups", table.concat(groups, ","), os.time() + 604800)) + end + + html("\n") + return 0 +end + + +-- Returns 1 if the cookie is valid and 0 if it is not. +function authenticate_cookie() + local required_group = protected_repos[cgit["repo"]] + if required_group == nil then + -- We return as valid if the repo is not protected. + return 1 + end + + local user_groups = validate_value("gentoogroups", get_cookie(http["cookie"], "cgitauth")) + if user_groups == nil or user_groups == "" then + return 0 + end + for group in string.gmatch(user_groups, "[^,]+") do + if group == required_group then + return 1 + end + end + return 0 +end + +-- Prints the html for the login form. +function body() + html("

Gentoo LDAP Authentication Required

") + html("
") + html("") + html("") + html("") + html("") + html("") + html("
") + + return 0 +end + +-- +-- +-- Gentoo LDAP support. +-- +-- + +local lualdap = require("lualdap") + +function gentoo_ldap_user_groups(username, password) + -- Ensure the user is alphanumeric + if username:match("%W") then + return nil + end + + local who = "uid=" .. username .. ",ou=devs,dc=gentoo,dc=org" + + local ldap, err = lualdap.open_simple { + uri = "ldap://ldap1.gentoo.org", + who = who, + password = password, + starttls = true, + certfile = "/var/www/uwsgi/cgit/gentoo-ldap/star.gentoo.org.crt", + keyfile = "/var/www/uwsgi/cgit/gentoo-ldap/star.gentoo.org.key", + cacertfile = "/var/www/uwsgi/cgit/gentoo-ldap/ca.pem" + } + if ldap == nil then + return nil + end + + local group_suffix = ".group" + local group_suffix_len = group_suffix:len() + local groups = {} + for dn, attribs in ldap:search { base = who, scope = "subtree" } do + local access = attribs["gentooAccess"] + if dn == who and access ~= nil then + for i, v in ipairs(access) do + local vlen = v:len() + if vlen > group_suffix_len and v:sub(-group_suffix_len) == group_suffix then + table.insert(groups, v:sub(1, vlen - group_suffix_len)) + end + end + end + end + + ldap:close() + + return groups +end + +-- +-- +-- Wrapper around filter API, exposing the http table, the cgit table, and the post table to the above functions. +-- +-- + +local actions = {} +actions["authenticate-post"] = authenticate_post +actions["authenticate-cookie"] = authenticate_cookie +actions["body"] = body + +function filter_open(...) + action = actions[select(1, ...)] + + http = {} + http["cookie"] = select(2, ...) + http["method"] = select(3, ...) + http["query"] = select(4, ...) + http["referer"] = select(5, ...) + http["path"] = select(6, ...) + http["host"] = select(7, ...) + http["https"] = select(8, ...) + + cgit = {} + cgit["repo"] = select(9, ...) + cgit["page"] = select(10, ...) + cgit["url"] = select(11, ...) + cgit["login"] = select(12, ...) + +end + +function filter_close() + return action() +end + +function filter_write(str) + post = parse_qs(str) +end + + +-- +-- +-- Utility functions based on keplerproject/wsapi. +-- +-- + +function url_decode(str) + if not str then + return "" + end + str = string.gsub(str, "+", " ") + str = string.gsub(str, "%%(%x%x)", function(h) return string.char(tonumber(h, 16)) end) + str = string.gsub(str, "\r\n", "\n") + return str +end + +function url_encode(str) + if not str then + return "" + end + str = string.gsub(str, "\n", "\r\n") + str = string.gsub(str, "([^%w ])", function(c) return string.format("%%%02X", string.byte(c)) end) + str = string.gsub(str, " ", "+") + return str +end + +function parse_qs(qs) + local tab = {} + for key, val in string.gmatch(qs, "([^&=]+)=([^&=]*)&?") do + tab[url_decode(key)] = url_decode(val) + end + return tab +end + +function get_cookie(cookies, name) + cookies = string.gsub(";" .. cookies .. ";", "%s*;%s*", ";") + return string.match(cookies, ";" .. name .. "=(.-);") +end + + +-- +-- +-- Cookie construction and validation helpers. +-- +-- + +local crypto = require("crypto") + +-- Returns value of cookie if cookie is valid. Otherwise returns nil. +function validate_value(expected_field, cookie) + local i = 0 + local value = "" + local field = "" + local expiration = 0 + local salt = "" + local hmac = "" + + if cookie == nil or cookie:len() < 3 or cookie:sub(1, 1) == "|" then + return nil + end + + for component in string.gmatch(cookie, "[^|]+") do + if i == 0 then + field = component + elseif i == 1 then + value = component + elseif i == 2 then + expiration = tonumber(component) + if expiration == nil then + expiration = -1 + end + elseif i == 3 then + salt = component + elseif i == 4 then + hmac = component + else + break + end + i = i + 1 + end + + if hmac == nil or hmac:len() == 0 then + return nil + end + + -- Lua hashes strings, so these comparisons are time invariant. + if hmac ~= crypto.hmac.digest("sha1", field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt, secret) then + return nil + end + + if expiration == -1 or (expiration ~= 0 and expiration <= os.time()) then + return nil + end + + if url_decode(field) ~= expected_field then + return nil + end + + return url_decode(value) +end + +function secure_value(field, value, expiration) + if value == nil or value:len() <= 0 then + return "" + end + + local authstr = "" + local salt = crypto.hex(crypto.rand.bytes(16)) + value = url_encode(value) + field = url_encode(field) + authstr = field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt + authstr = authstr .. "|" .. crypto.hmac.digest("sha1", authstr, secret) + return authstr +end + +function set_cookie(cookie, value) + html("Set-Cookie: " .. cookie .. "=" .. value .. "; HttpOnly") + if http["https"] == "yes" or http["https"] == "on" or http["https"] == "1" then + html("; secure") + end + html("\n") +end + +function redirect_to(url) + html("Status: 302 Redirect\n") + html("Cache-Control: no-cache, no-store\n") + html("Location: " .. url .. "\n") +end + +function not_found() + html("Status: 404 Not Found\n") + html("Cache-Control: no-cache, no-store\n\n") +end From db021a1989a52911557ce6b998c11fbe4a4bea9d Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Thu, 5 Mar 2015 20:41:45 +0100 Subject: [PATCH 018/387] Remove no-op link from submodule entries Instead of linking to the current page ("href='#'"), do not add a link to a submodule entry at all if the module-link setting is not used. Signed-off-by: Lukas Fleischer --- cgit.css | 2 +- ui-shared.c | 41 ++++++++++++++++++++++++----------------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/cgit.css b/cgit.css index 6888cde..82c755c 100644 --- a/cgit.css +++ b/cgit.css @@ -254,7 +254,7 @@ div#cgit div.error { margin: 1em 2em; } -div#cgit a.ls-blob, div#cgit a.ls-dir, div#cgit a.ls-mod { +div#cgit a.ls-blob, div#cgit a.ls-dir, div#cgit .ls-mod { font-family: monospace; } diff --git a/ui-shared.c b/ui-shared.c index 23a893b..1dd8722 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -559,25 +559,32 @@ void cgit_submodule_link(const char *class, char *path, const char *rev) item = lookup_path(list, path); } } - html("module_link, dir, rev); + if (item || ctx.repo->module_link) { + html("module_link, dir, rev); + } + html("'>"); + html_txt(path); + html(""); } else { - html("#"); + html(""); + html_txt(path); + html(""); } - html("'>"); - html_txt(path); - html(""); html_txtf(" @ %.7s", rev); if (item && tail) path[len - 1] = tail; From cadbb69990d232ce49547190b1cff2b57fc8b438 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Fri, 13 Mar 2015 16:22:11 +0100 Subject: [PATCH 019/387] Bump version --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 42ed230..043601f 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ all:: -CGIT_VERSION = v0.11.1 +CGIT_VERSION = v0.11.2 CGIT_SCRIPT_NAME = cgit.cgi CGIT_SCRIPT_PATH = /var/www/htdocs/cgit CGIT_DATA_PATH = $(CGIT_SCRIPT_PATH) From 84627609f5a7634732fe1d718e7d1c18254e64c8 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Sat, 14 Mar 2015 17:21:42 +0100 Subject: [PATCH 020/387] git: update to v2.3.3 Update to git version v2.3.3, no changes required. Signed-off-by: Christian Hesse --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 043601f..1a900f8 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = -GIT_VER = 2.3.2 +GIT_VER = 2.3.3 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.gz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index 1165ae6..bb85775 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 1165ae6f3d42e0eb0ddfc2d4e6dfa8bd0b88eb60 +Subproject commit bb8577532add843833ebf8b5324f94f84cb71ca0 From d1ddce90f58e9b7fc00c39d912a4c8d1b3e27595 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 18 Mar 2015 18:08:48 +0100 Subject: [PATCH 021/387] ui-shared: allow remote refs in branch switcher Signed-off-by: Christian Hesse --- ui-shared.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ui-shared.c b/ui-shared.c index 1dd8722..ac5a287 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -895,6 +895,8 @@ static void print_header(void) cgit_add_hidden_formfields(0, 1, ctx.qry.page); html(" "); html(""); html(""); From 2eb41c4665ad6866c8893668263c401d7b0ffc5d Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 14 May 2015 13:47:28 +0200 Subject: [PATCH 022/387] git: update to v2.4.1 Update to git version v2.4.1, no changes required. Signed-off-by: Christian Hesse --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 1a900f8..1f84c00 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = -GIT_VER = 2.3.3 +GIT_VER = 2.4.1 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.gz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index bb85775..aaa7e0d 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit bb8577532add843833ebf8b5324f94f84cb71ca0 +Subproject commit aaa7e0d7f8f003c0c8ab34f959083f6d191d44ca From 121e65391446069a538ae8d3f7938452178de7c6 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Tue, 23 Dec 2014 14:40:44 +0000 Subject: [PATCH 023/387] contrib/hooks: add sample post-receive hook using agefile One of the most frequent questions on the mailing list relates to the idle time in the repository list. The answer to this is to use the "agefile" feature to calculate the time of the last change whenever the repository receives changes. Add a sample post-receive hook in a new "contrib" directory so that we can just point people at the repository in the future. Signed-off-by: John Keeping --- contrib/hooks/post-receive.agefile | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 contrib/hooks/post-receive.agefile diff --git a/contrib/hooks/post-receive.agefile b/contrib/hooks/post-receive.agefile new file mode 100755 index 0000000..2f72ae9 --- /dev/null +++ b/contrib/hooks/post-receive.agefile @@ -0,0 +1,19 @@ +#!/bin/sh +# +# An example hook to update the "agefile" for CGit's idle time calculation. +# +# This hook assumes that you are using the default agefile location of +# "info/web/last-modified". If you change the value in your cgitrc then you +# must also change it here. +# +# To install the hook, copy (or link) it to the file "hooks/post-receive" in +# each of your repositories. +# + +agefile="$(git rev-parse --git-dir)"/info/web/last-modified + +mkdir -p "$(dirname "$agefile")" && +git for-each-ref \ + --sort=-authordate --count=1 \ + --format='%(authordate:iso8601)' \ + >"$agefile" From dc41a0018058c81ee9a0a2dc6e89f737d7c1c966 Mon Sep 17 00:00:00 2001 From: Daniel Reichelt Date: Mon, 10 Aug 2015 09:45:48 +0200 Subject: [PATCH 024/387] Fix processing of repo.hide and repo.ignore If the global option enable-filter-overrides is set to 1 the repo-specific options repo.hide and repo.ignore never got processed. Signed-off-by: Daniel Reichelt Reviewed-by: John Keeping --- cgit.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cgit.c b/cgit.c index ae413c6..8c9cfb5 100644 --- a/cgit.c +++ b/cgit.c @@ -82,6 +82,10 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va repo->logo = xstrdup(value); else if (!strcmp(name, "logo-link") && value != NULL) repo->logo_link = xstrdup(value); + else if (!strcmp(name, "hide")) + repo->hide = atoi(value); + else if (!strcmp(name, "ignore")) + repo->ignore = atoi(value); else if (ctx.cfg.enable_filter_overrides) { if (!strcmp(name, "about-filter")) repo->about_filter = cgit_new_filter(value, ABOUT); @@ -93,10 +97,6 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va repo->email_filter = cgit_new_filter(value, EMAIL); else if (!strcmp(name, "owner-filter")) repo->owner_filter = cgit_new_filter(value, OWNER); - } else if (!strcmp(name, "hide")) { - repo->hide = atoi(value); - } else if (!strcmp(name, "ignore")) { - repo->ignore = atoi(value); } } From de83de276bef7509ab8255682595ad4521f3a193 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 28 Jul 2015 10:42:01 +0200 Subject: [PATCH 025/387] git: update to v2.5.0 Update to git version v2.5.0. * Upstream commit 5455ee0573a22bb793a7083d593ae1ace909cd4c (Merge branch 'bc/object-id') changed API: for_each_ref() callback functions were taught to name the objects not with "unsigned char sha1[20]" but with "struct object_id". * Upstream commit dcf692625ac569fefbe52269061230f4fde10e47 (path.c: make get_pathname() call sites return const char *) Signed-off-by: Christian Hesse --- Makefile | 2 +- cgit.c | 2 +- cgit.h | 2 +- git | 2 +- shared.c | 8 ++++---- ui-clone.c | 8 ++++---- ui-log.c | 4 ++-- ui-shared.c | 2 +- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 1f84c00..65b4318 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = -GIT_VER = 2.4.1 +GIT_VER = 2.5.0 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.gz INSTALL = install COPYTREE = cp -r diff --git a/cgit.c b/cgit.c index 8c9cfb5..ed02614 100644 --- a/cgit.c +++ b/cgit.c @@ -421,7 +421,7 @@ struct refmatch { int match; }; -static int find_current_ref(const char *refname, const unsigned char *sha1, +static int find_current_ref(const char *refname, const struct object_id *oid, int flags, void *cb_data) { struct refmatch *info; diff --git a/cgit.h b/cgit.h index 16f8092..db9a8eb 100644 --- a/cgit.h +++ b/cgit.h @@ -335,7 +335,7 @@ extern void strbuf_ensure_end(struct strbuf *sb, char c); extern void cgit_add_ref(struct reflist *list, struct refinfo *ref); extern void cgit_free_reflist_inner(struct reflist *list); -extern int cgit_refs_cb(const char *refname, const unsigned char *sha1, +extern int cgit_refs_cb(const char *refname, const struct object_id *oid, int flags, void *cb_data); extern void *cgit_free_commitinfo(struct commitinfo *info); diff --git a/git b/git index aaa7e0d..a17c56c 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit aaa7e0d7f8f003c0c8ab34f959083f6d191d44ca +Subproject commit a17c56c056d5fea0843b429132904c429a900229 diff --git a/shared.c b/shared.c index a99173b..a83afcb 100644 --- a/shared.c +++ b/shared.c @@ -185,13 +185,13 @@ void cgit_add_ref(struct reflist *list, struct refinfo *ref) list->refs[list->count++] = ref; } -static struct refinfo *cgit_mk_refinfo(const char *refname, const unsigned char *sha1) +static struct refinfo *cgit_mk_refinfo(const char *refname, const struct object_id *oid) { struct refinfo *ref; ref = xmalloc(sizeof (struct refinfo)); ref->refname = xstrdup(refname); - ref->object = parse_object(sha1); + ref->object = parse_object(oid->hash); switch (ref->object->type) { case OBJ_TAG: ref->tag = cgit_parse_tag((struct tag *)ref->object); @@ -239,11 +239,11 @@ void cgit_free_reflist_inner(struct reflist *list) free(list->refs); } -int cgit_refs_cb(const char *refname, const unsigned char *sha1, int flags, +int cgit_refs_cb(const char *refname, const struct object_id *oid, int flags, void *cb_data) { struct reflist *list = (struct reflist *)cb_data; - struct refinfo *info = cgit_mk_refinfo(refname, sha1); + struct refinfo *info = cgit_mk_refinfo(refname, oid); if (info) cgit_add_ref(list, info); diff --git a/ui-clone.c b/ui-clone.c index e35d3d3..e4ddd34 100644 --- a/ui-clone.c +++ b/ui-clone.c @@ -12,15 +12,15 @@ #include "html.h" #include "ui-shared.h" -static int print_ref_info(const char *refname, const unsigned char *sha1, +static int print_ref_info(const char *refname, const struct object_id *oid, int flags, void *cb_data) { struct object *obj; - if (!(obj = parse_object(sha1))) + if (!(obj = parse_object(oid->hash))) return 0; - htmlf("%s\t%s\n", sha1_to_hex(sha1), refname); + htmlf("%s\t%s\n", oid_to_hex(oid), refname); if (obj->type == OBJ_TAG) { if (!(obj = deref_tag(obj, refname, 0))) return 0; @@ -50,7 +50,7 @@ static void print_pack_info(void) } } -static void send_file(char *path) +static void send_file(const char *path) { struct stat st; diff --git a/ui-log.c b/ui-log.c index 32b4c47..8028b27 100644 --- a/ui-log.c +++ b/ui-log.c @@ -249,11 +249,11 @@ static void print_commit(struct commit *commit, struct rev_info *revs) static const char *disambiguate_ref(const char *ref, int *must_free_result) { - unsigned char sha1[20]; + struct object_id oid; struct strbuf longref = STRBUF_INIT; strbuf_addf(&longref, "refs/heads/%s", ref); - if (get_sha1(longref.buf, sha1) == 0) { + if (get_sha1(longref.buf, oid.hash) == 0) { *must_free_result = 1; return strbuf_detach(&longref, NULL); } diff --git a/ui-shared.c b/ui-shared.c index ac5a287..e755c92 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -792,7 +792,7 @@ void cgit_add_clone_urls(void (*fn)(const char *)) add_clone_urls(fn, ctx.cfg.clone_prefix, ctx.repo->url); } -static int print_branch_option(const char *refname, const unsigned char *sha1, +static int print_branch_option(const char *refname, const struct object_id *oid, int flags, void *cb_data) { char *name = (char *)refname; From 13c2d3df0440ce04273de3149631a9bd97490c6e Mon Sep 17 00:00:00 2001 From: Lazaros Koromilas Date: Wed, 15 Jul 2015 15:53:12 +0300 Subject: [PATCH 026/387] filters: apply HTML escaping http://www.w3.org/International/questions/qa-escapes#use --- filters/html-converters/txt2html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/filters/html-converters/txt2html b/filters/html-converters/txt2html index a795995..495eece 100755 --- a/filters/html-converters/txt2html +++ b/filters/html-converters/txt2html @@ -1,4 +1,4 @@ #!/bin/sh echo "
"
-cat
+sed "s|&|\\&|g;s|'|\\'|g;s|\"|\\"|g;s|<|\\<|g;s|>|\\>|g"
 echo "
" From d7034806a4b1279f62d606501f831dcad31798e6 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Wed, 12 Aug 2015 14:50:09 +0200 Subject: [PATCH 027/387] about: always ensure page has a trailing slash Otherwise we can't easily embed links to other /about/ pages. Signed-off-by: Jason A. Donenfeld --- cgit.c | 3 +++ cmd.c | 12 ++++++++++-- cmd.h | 2 ++ ui-shared.c | 8 ++++++++ ui-shared.h | 3 +++ 5 files changed, 26 insertions(+), 2 deletions(-) diff --git a/cgit.c b/cgit.c index ed02614..baad1c8 100644 --- a/cgit.c +++ b/cgit.c @@ -742,6 +742,9 @@ static void process_request(void) if (ctx.repo && prepare_repo_cmd()) return; + if (cmd->pre) + cmd->pre(); + if (cmd->want_layout) { cgit_print_http_headers(); cgit_print_docstart(); diff --git a/cmd.c b/cmd.c index 188cd56..e86b0ea 100644 --- a/cmd.c +++ b/cmd.c @@ -44,6 +44,12 @@ static void about_fn(void) cgit_print_site_readme(); } +static void about_pre(void) +{ + if (ctx.repo && !ctx.qry.path && ctx.qry.url[strlen(ctx.qry.url) - 1] != '/') + cgit_redirect(fmtalloc("%s/", cgit_currenturl()), true); +} + static void blob_fn(void) { cgit_print_blob(ctx.qry.sha1, ctx.qry.path, ctx.qry.head, 0); @@ -136,15 +142,17 @@ static void tree_fn(void) cgit_print_tree(ctx.qry.sha1, ctx.qry.path); } +#define def_cmp(name, want_repo, want_layout, want_vpath, is_clone) \ + {#name, name##_fn, name##_pre, want_repo, want_layout, want_vpath, is_clone} #define def_cmd(name, want_repo, want_layout, want_vpath, is_clone) \ - {#name, name##_fn, want_repo, want_layout, want_vpath, is_clone} + {#name, name##_fn, NULL, want_repo, want_layout, want_vpath, is_clone} struct cgit_cmd *cgit_get_cmd(void) { static struct cgit_cmd cmds[] = { def_cmd(HEAD, 1, 0, 0, 1), def_cmd(atom, 1, 0, 0, 0), - def_cmd(about, 0, 1, 0, 0), + def_cmp(about, 0, 1, 0, 0), def_cmd(blob, 1, 0, 0, 0), def_cmd(commit, 1, 1, 1, 0), def_cmd(diff, 1, 1, 1, 0), diff --git a/cmd.h b/cmd.h index 752f078..2507ca5 100644 --- a/cmd.h +++ b/cmd.h @@ -2,10 +2,12 @@ #define CMD_H typedef void (*cgit_cmd_fn)(void); +typedef void (*cgit_cmd_pre_fn)(void); struct cgit_cmd { const char *name; cgit_cmd_fn fn; + cgit_cmd_pre_fn pre; unsigned int want_repo:1, want_layout:1, want_vpath:1, diff --git a/ui-shared.c b/ui-shared.c index e755c92..4f84b7c 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -689,6 +689,14 @@ void cgit_print_http_headers(void) exit(0); } +void cgit_redirect(const char *url, bool permanent) +{ + htmlf("Status: %d %s\n", permanent ? 301 : 302, permanent ? "Moved" : "Found"); + htmlf("Location: %s\n", url); + htmlf("\n"); + exit(0); +} + static void print_rel_vcs_link(const char *url) { html("tmp2 - sed "1,4d" tmp >tmp_ + git --git-dir="$PWD/repos/foo/.git" diff HEAD^.. >tmp2 && + sed "1,4d" tmp >tmp_ && cmp tmp_ tmp2 ' @@ -22,20 +22,20 @@ test_expect_success 'generate diff for initial commit' ' ' test_expect_success 'compare with output of git-diff-tree(1)' ' - git --git-dir="$PWD/repos/foo/.git" diff-tree -p --no-commit-id --root "$root" >tmp2 - sed "1,4d" tmp >tmp_ + git --git-dir="$PWD/repos/foo/.git" diff-tree -p --no-commit-id --root "$root" >tmp2 && + sed "1,4d" tmp >tmp_ && cmp tmp_ tmp2 ' test_expect_success 'generate diff for multiple commits' ' - id=$(git --git-dir="$PWD/repos/foo/.git" rev-parse HEAD) - id2=$(git --git-dir="$PWD/repos/foo/.git" rev-parse HEAD~3) + id=$(git --git-dir="$PWD/repos/foo/.git" rev-parse HEAD) && + id2=$(git --git-dir="$PWD/repos/foo/.git" rev-parse HEAD~3) && cgit_query "url=foo/rawdiff&id=$id&id2=$id2" >tmp ' test_expect_success 'compare with output of git-diff(1)' ' - git --git-dir="$PWD/repos/foo/.git" diff HEAD~3..HEAD >tmp2 - sed "1,4d" tmp >tmp_ + git --git-dir="$PWD/repos/foo/.git" diff HEAD~3..HEAD >tmp2 && + sed "1,4d" tmp >tmp_ && cmp tmp_ tmp2 ' From 044e2d26da4f8b4f9ff25e4a729ab4e393073b5e Mon Sep 17 00:00:00 2001 From: John Keeping Date: Wed, 12 Aug 2015 15:34:48 +0100 Subject: [PATCH 029/387] shared: make cgit_diff_tree_cb public This will allow us to use this nice wrapper function elsewhere, avoiding dealing with the diff queue when we only need to inspect a filepair. Signed-off-by: John Keeping --- cgit.h | 3 +++ shared.c | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cgit.h b/cgit.h index db9a8eb..b2253d2 100644 --- a/cgit.h +++ b/cgit.h @@ -340,6 +340,9 @@ extern int cgit_refs_cb(const char *refname, const struct object_id *oid, extern void *cgit_free_commitinfo(struct commitinfo *info); +void cgit_diff_tree_cb(struct diff_queue_struct *q, + struct diff_options *options, void *data); + extern int cgit_diff_files(const unsigned char *old_sha1, const unsigned char *new_sha1, unsigned long *old_size, unsigned long *new_size, diff --git a/shared.c b/shared.c index a83afcb..0431b59 100644 --- a/shared.c +++ b/shared.c @@ -250,8 +250,8 @@ int cgit_refs_cb(const char *refname, const struct object_id *oid, int flags, return 0; } -static void cgit_diff_tree_cb(struct diff_queue_struct *q, - struct diff_options *options, void *data) +void cgit_diff_tree_cb(struct diff_queue_struct *q, + struct diff_options *options, void *data) { int i; From 30304d8156a72ffc95e45e1aa9407319b81bd253 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Wed, 12 Aug 2015 15:55:28 +0100 Subject: [PATCH 030/387] log: allow users to follow a file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Teach the "log" UI to behave in the same way as "git log --follow", when given a suitable instruction by the user. The default behaviour remains to show the log without following renames, but the follow behaviour can be activated by following a link in the page header. Follow is not the default because outputting merges in follow mode is tricky ("git log --follow" will not show merges). We also disable the graph in follow mode because the commit graph is not simplified so we end up with frequent gaps in the graph and many lines that do not connect with any commits we're actually showing. We also teach the "diff" and "commit" UIs to respect the follow flag on URLs, causing the single-file version of these UIs to detect renames. This feature is needed only for commits that rename the path we're interested in. For commits before the file has been renamed (i.e. that appear later in the log list) we change the file path in the links from the log to point to the old name; this means that links to commits always limit by the path known to that commit. If we didn't do this we would need to walk down the log diff'ing every commit whenever we want to show a commit. The drawback is that the "Log" link in the top bar of such a page links to the log limited by the old name, so it will only show pre-rename commits. I consider this a reasonable trade-off since the "Back" button still works and the log matches the path displayed in the top bar. Since following renames requires running diff on every commit we consider, I've added a knob to the configuration file to globally enable/disable this feature. Note that we may consider a large number of commits the revision walking machinery no longer performs any path limitation so we have to examine every commit until we find a page full of commits that affect the target path or something related to it. Suggested-by: René Neumann Signed-off-by: John Keeping --- cgit.c | 4 ++ cgit.h | 2 + cgitrc.5.txt | 4 ++ ui-diff.c | 35 ++++++++++++++ ui-log.c | 131 +++++++++++++++++++++++++++++++++++++++++++++----- ui-refs.c | 2 +- ui-repolist.c | 2 +- ui-shared.c | 28 +++++++++-- ui-shared.h | 2 +- ui-tree.c | 2 +- 10 files changed, 194 insertions(+), 18 deletions(-) diff --git a/cgit.c b/cgit.c index baad1c8..d84b4be 100644 --- a/cgit.c +++ b/cgit.c @@ -152,6 +152,8 @@ static void config_cb(const char *name, const char *value) ctx.cfg.snapshots = cgit_parse_snapshots_mask(value); else if (!strcmp(name, "enable-filter-overrides")) ctx.cfg.enable_filter_overrides = atoi(value); + else if (!strcmp(name, "enable-follow-links")) + ctx.cfg.enable_follow_links = atoi(value); else if (!strcmp(name, "enable-http-clone")) ctx.cfg.enable_http_clone = atoi(value); else if (!strcmp(name, "enable-index-links")) @@ -333,6 +335,8 @@ static void querystring_cb(const char *name, const char *value) ctx.qry.context = atoi(value); } else if (!strcmp(name, "ignorews")) { ctx.qry.ignorews = atoi(value); + } else if (!strcmp(name, "follow")) { + ctx.qry.follow = atoi(value); } } diff --git a/cgit.h b/cgit.h index b2253d2..3120562 100644 --- a/cgit.h +++ b/cgit.h @@ -179,6 +179,7 @@ struct cgit_query { int show_all; int context; int ignorews; + int follow; char *vpath; }; @@ -221,6 +222,7 @@ struct cgit_config { int case_sensitive_sort; int embedded; int enable_filter_overrides; + int enable_follow_links; int enable_http_clone; int enable_index_links; int enable_index_owner; diff --git a/cgitrc.5.txt b/cgitrc.5.txt index e21ece9..759f353 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -150,6 +150,10 @@ enable-filter-overrides:: Flag which, when set to "1", allows all filter settings to be overridden in repository-specific cgitrc files. Default value: none. +enable-follow-links:: + Flag which, when set to "1", allows users to follow a file in the log + view. Default value: "0". + enable-http-clone:: If set to "1", cgit will act as an dumb HTTP endpoint for git clones. You can add "http://$HTTP_HOST$SCRIPT_NAME/$CGIT_REPO_URL" to clone-url diff --git a/ui-diff.c b/ui-diff.c index 1cf2ce0..caebd5d 100644 --- a/ui-diff.c +++ b/ui-diff.c @@ -36,6 +36,7 @@ static struct fileinfo { static int use_ssdiff = 0; static struct diff_filepair *current_filepair; +static const char *current_prefix; struct diff_filespec *cgit_get_current_old_file(void) { @@ -132,11 +133,30 @@ static void count_diff_lines(char *line, int len) } } +static int show_filepair(struct diff_filepair *pair) +{ + /* Always show if we have no limiting prefix. */ + if (!current_prefix) + return 1; + + /* Show if either path in the pair begins with the prefix. */ + if (starts_with(pair->one->path, current_prefix) || + starts_with(pair->two->path, current_prefix)) + return 1; + + /* Otherwise we don't want to show this filepair. */ + return 0; +} + static void inspect_filepair(struct diff_filepair *pair) { int binary = 0; unsigned long old_size = 0; unsigned long new_size = 0; + + if (!show_filepair(pair)) + return; + files++; lines_added = 0; lines_removed = 0; @@ -279,6 +299,9 @@ static void filepair_cb(struct diff_filepair *pair) int binary = 0; linediff_fn print_line_fn = print_line; + if (!show_filepair(pair)) + return; + current_filepair = pair; if (use_ssdiff) { cgit_ssdiff_header_begin(); @@ -365,6 +388,18 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, const unsigned char *old_tree_sha1, *new_tree_sha1; diff_type difftype; + /* + * If "follow" is set then the diff machinery needs to examine the + * entire commit to detect renames so we must limit the paths in our + * own callbacks and not pass the prefix to the diff machinery. + */ + if (ctx.qry.follow && ctx.cfg.enable_follow_links) { + current_prefix = prefix; + prefix = ""; + } else { + current_prefix = NULL; + } + if (!new_rev) new_rev = ctx.qry.head; if (get_sha1(new_rev, new_rev_sha1)) { diff --git a/ui-log.c b/ui-log.c index 8028b27..ff832ce 100644 --- a/ui-log.c +++ b/ui-log.c @@ -12,7 +12,7 @@ #include "ui-shared.h" #include "argv-array.h" -static int files, add_lines, rem_lines; +static int files, add_lines, rem_lines, lines_counted; /* * The list of available column colors in the commit graph. @@ -67,7 +67,7 @@ void show_commit_decorations(struct commit *commit) strncpy(buf, deco->name + 11, sizeof(buf) - 1); cgit_log_link(buf, NULL, "branch-deco", buf, NULL, ctx.qry.vpath, 0, NULL, NULL, - ctx.qry.showmsg); + ctx.qry.showmsg, 0); } else if (starts_with(deco->name, "tag: refs/tags/")) { strncpy(buf, deco->name + 15, sizeof(buf) - 1); @@ -84,7 +84,7 @@ void show_commit_decorations(struct commit *commit) cgit_log_link(buf, NULL, "remote-deco", NULL, sha1_to_hex(commit->object.sha1), ctx.qry.vpath, 0, NULL, NULL, - ctx.qry.showmsg); + ctx.qry.showmsg, 0); } else { strncpy(buf, deco->name, sizeof(buf) - 1); @@ -98,6 +98,74 @@ next: html(""); } +static void handle_rename(struct diff_filepair *pair) +{ + /* + * After we have seen a rename, we generate links to the previous + * name of the file so that commit & diff views get fed the path + * that is correct for the commit they are showing, avoiding the + * need to walk the entire history leading back to every commit we + * show in order detect renames. + */ + if (0 != strcmp(ctx.qry.vpath, pair->two->path)) { + free(ctx.qry.vpath); + ctx.qry.vpath = xstrdup(pair->two->path); + } + inspect_files(pair); +} + +static int show_commit(struct commit *commit, struct rev_info *revs) +{ + struct commit_list *parents = commit->parents; + struct commit *parent; + int found = 0, saved_fmt; + unsigned saved_flags = revs->diffopt.flags; + + + /* Always show if we're not in "follow" mode with a single file. */ + if (!ctx.qry.follow) + return 1; + + /* + * In "follow" mode, we don't show merges. This is consistent with + * "git log --follow -- ". + */ + if (parents && parents->next) + return 0; + + /* + * If this is the root commit, do what rev_info tells us. + */ + if (!parents) + return revs->show_root_diff; + + /* When we get here we have precisely one parent. */ + parent = parents->item; + parse_commit(parent); + + files = 0; + add_lines = 0; + rem_lines = 0; + + DIFF_OPT_SET(&revs->diffopt, RECURSIVE); + diff_tree_sha1(parent->tree->object.sha1, + commit->tree->object.sha1, + "", &revs->diffopt); + diffcore_std(&revs->diffopt); + + found = !diff_queue_is_empty(); + saved_fmt = revs->diffopt.output_format; + revs->diffopt.output_format = DIFF_FORMAT_CALLBACK; + revs->diffopt.format_callback = cgit_diff_tree_cb; + revs->diffopt.format_callback_data = handle_rename; + diff_flush(&revs->diffopt); + revs->diffopt.output_format = saved_fmt; + revs->diffopt.flags = saved_flags; + + lines_counted = 1; + return found; +} + static void print_commit(struct commit *commit, struct rev_info *revs) { struct commitinfo *info; @@ -177,7 +245,8 @@ static void print_commit(struct commit *commit, struct rev_info *revs) cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); } - if (ctx.repo->enable_log_filecount || ctx.repo->enable_log_linecount) { + if (!lines_counted && (ctx.repo->enable_log_filecount || + ctx.repo->enable_log_linecount)) { files = 0; add_lines = 0; rem_lines = 0; @@ -325,7 +394,17 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern } } } - if (commit_graph) { + + if (!path || !ctx.cfg.enable_follow_links) { + /* + * If we don't have a path, "follow" is a no-op so make sure + * the variable is set to false to avoid needing to check + * both this and whether we have a path everywhere. + */ + ctx.qry.follow = 0; + } + + if (commit_graph && !ctx.qry.follow) { argv_array_push(&rev_argv, "--graph"); argv_array_push(&rev_argv, "--color"); graph_set_column_colors(column_colors_html, @@ -337,6 +416,8 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern else if (commit_sort == 2) argv_array_push(&rev_argv, "--topo-order"); + if (path && ctx.qry.follow) + argv_array_push(&rev_argv, "--follow"); argv_array_push(&rev_argv, "--"); if (path) argv_array_push(&rev_argv, path); @@ -347,10 +428,17 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern rev.verbose_header = 1; rev.show_root_diff = 0; rev.ignore_missing = 1; + rev.simplify_history = 1; setup_revisions(rev_argv.argc, rev_argv.argv, &rev, NULL); load_ref_decorations(DECORATE_FULL_REFS); rev.show_decorations = 1; rev.grep_filter.regflags |= REG_ICASE; + + rev.diffopt.detect_rename = 1; + rev.diffopt.rename_limit = ctx.cfg.renamelimit; + if (ctx.qry.ignorews) + DIFF_XDL_SET(&rev.diffopt, IGNORE_WHITESPACE); + compile_grep_patterns(&rev.grep_filter); prepare_revision_walk(&rev); @@ -368,11 +456,12 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern cgit_log_link(ctx.qry.showmsg ? "Collapse" : "Expand", NULL, NULL, ctx.qry.head, ctx.qry.sha1, ctx.qry.vpath, ctx.qry.ofs, ctx.qry.grep, - ctx.qry.search, ctx.qry.showmsg ? 0 : 1); + ctx.qry.search, ctx.qry.showmsg ? 0 : 1, + ctx.qry.follow); html(")"); } html("Author"); - if (commit_graph) + if (rev.graph) html("Age"); if (ctx.repo->enable_log_filecount) { html("Files"); @@ -388,13 +477,30 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern ofs = 0; for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { + if (show_commit(commit, &rev)) + i++; free_commit_buffer(commit); free_commit_list(commit->parents); commit->parents = NULL; } for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { - print_commit(commit, &rev); + /* + * In "follow" mode, we must count the files and lines the + * first time we invoke diff on a given commit, and we need + * to do that to see if the commit touches the path we care + * about, so we do it in show_commit. Hence we must clear + * lines_counted here. + * + * This has the side effect of avoiding running diff twice + * when we are both following renames and showing file + * and/or line counts. + */ + lines_counted = 0; + if (show_commit(commit, &rev)) { + i++; + print_commit(commit, &rev); + } free_commit_buffer(commit); free_commit_list(commit->parents); commit->parents = NULL; @@ -406,7 +512,8 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern cgit_log_link("[prev]", NULL, NULL, ctx.qry.head, ctx.qry.sha1, ctx.qry.vpath, ofs - cnt, ctx.qry.grep, - ctx.qry.search, ctx.qry.showmsg); + ctx.qry.search, ctx.qry.showmsg, + ctx.qry.follow); html(""); } if ((commit = get_revision(&rev)) != NULL) { @@ -414,14 +521,16 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern cgit_log_link("[next]", NULL, NULL, ctx.qry.head, ctx.qry.sha1, ctx.qry.vpath, ofs + cnt, ctx.qry.grep, - ctx.qry.search, ctx.qry.showmsg); + ctx.qry.search, ctx.qry.showmsg, + ctx.qry.follow); html(""); } html(""); } else if ((commit = get_revision(&rev)) != NULL) { htmlf("", columns); cgit_log_link("[...]", NULL, NULL, ctx.qry.head, NULL, - ctx.qry.vpath, 0, NULL, NULL, ctx.qry.showmsg); + ctx.qry.vpath, 0, NULL, NULL, ctx.qry.showmsg, + ctx.qry.follow); html("\n"); } diff --git a/ui-refs.c b/ui-refs.c index d3d71dd..73a187b 100644 --- a/ui-refs.c +++ b/ui-refs.c @@ -63,7 +63,7 @@ static int print_branch(struct refinfo *ref) return 1; html(""); cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0, NULL, NULL, - ctx.qry.showmsg); + ctx.qry.showmsg, 0); html(""); if (ref->object->type == OBJ_COMMIT) { diff --git a/ui-repolist.c b/ui-repolist.c index 2453a7f..edefc4c 100644 --- a/ui-repolist.c +++ b/ui-repolist.c @@ -330,7 +330,7 @@ void cgit_print_repolist(void) html(""); cgit_summary_link("summary", NULL, "button", NULL); cgit_log_link("log", NULL, "button", NULL, NULL, NULL, - 0, NULL, NULL, ctx.qry.showmsg); + 0, NULL, NULL, ctx.qry.showmsg, 0); cgit_tree_link("tree", NULL, "button", NULL, NULL, NULL); html(""); } diff --git a/ui-shared.c b/ui-shared.c index 4f84b7c..6be0c2e 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -303,7 +303,8 @@ void cgit_plain_link(const char *name, const char *title, const char *class, void cgit_log_link(const char *name, const char *title, const char *class, const char *head, const char *rev, const char *path, - int ofs, const char *grep, const char *pattern, int showmsg) + int ofs, const char *grep, const char *pattern, int showmsg, + int follow) { char *delim; @@ -332,6 +333,11 @@ void cgit_log_link(const char *name, const char *title, const char *class, if (showmsg) { html(delim); html("showmsg=1"); + delim = "&"; + } + if (follow) { + html(delim); + html("follow=1"); } html("'>"); html_txt(name); @@ -373,6 +379,10 @@ void cgit_commit_link(char *name, const char *title, const char *class, html("ignorews=1"); delim = "&"; } + if (ctx.qry.follow) { + html(delim); + html("follow=1"); + } html("'>"); if (name[0] != '\0') html_txt(name); @@ -429,6 +439,10 @@ void cgit_diff_link(const char *name, const char *title, const char *class, html("ignorews=1"); delim = "&"; } + if (ctx.qry.follow) { + html(delim); + html("follow=1"); + } html("'>"); html_txt(name); html(""); @@ -469,7 +483,7 @@ static void cgit_self_link(char *name, const char *title, const char *class) ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL, ctx.qry.path, ctx.qry.ofs, ctx.qry.grep, ctx.qry.search, - ctx.qry.showmsg); + ctx.qry.showmsg, ctx.qry.follow); else if (!strcmp(ctx.qry.page, "commit")) cgit_commit_link(name, title, class, ctx.qry.head, ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL, @@ -945,7 +959,7 @@ void cgit_print_pageheader(void) ctx.qry.sha1, NULL); cgit_log_link("log", NULL, hc("log"), ctx.qry.head, NULL, ctx.qry.vpath, 0, NULL, NULL, - ctx.qry.showmsg); + ctx.qry.showmsg, ctx.qry.follow); cgit_tree_link("tree", NULL, hc("tree"), ctx.qry.head, ctx.qry.sha1, ctx.qry.vpath); cgit_commit_link("commit", NULL, hc("commit"), @@ -993,6 +1007,14 @@ void cgit_print_pageheader(void) html("
"); html("path: "); cgit_print_path_crumbs(ctx.qry.vpath); + if (ctx.cfg.enable_follow_links && !strcmp(ctx.qry.page, "log")) { + html(" ("); + ctx.qry.follow = !ctx.qry.follow; + cgit_self_link(ctx.qry.follow ? "follow" : "unfollow", + NULL, NULL); + ctx.qry.follow = !ctx.qry.follow; + html(")"); + } html("
"); } html("
"); diff --git a/ui-shared.h b/ui-shared.h index 43d0fa6..788b1bc 100644 --- a/ui-shared.h +++ b/ui-shared.h @@ -31,7 +31,7 @@ extern void cgit_plain_link(const char *name, const char *title, extern void cgit_log_link(const char *name, const char *title, const char *class, const char *head, const char *rev, const char *path, int ofs, const char *grep, - const char *pattern, int showmsg); + const char *pattern, int showmsg, int follow); extern void cgit_commit_link(char *name, const char *title, const char *class, const char *head, const char *rev, const char *path); diff --git a/ui-tree.c b/ui-tree.c index bbc468e..c8d24f6 100644 --- a/ui-tree.c +++ b/ui-tree.c @@ -166,7 +166,7 @@ static int ls_item(const unsigned char *sha1, struct strbuf *base, html(""); cgit_log_link("log", NULL, "button", ctx.qry.head, walk_tree_ctx->curr_rev, fullpath.buf, 0, NULL, NULL, - ctx.qry.showmsg); + ctx.qry.showmsg, 0); if (ctx.repo->max_stats) cgit_stats_link("stats", NULL, "button", ctx.qry.head, fullpath.buf); From da1d4c77760ff6a0eb5cbfbaf6956930089d1963 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Wed, 12 Aug 2015 16:41:34 +0100 Subject: [PATCH 031/387] ui-log: fix double counting This crept in while rebasing the previous commit onto an updated upstream. Signed-off-by: John Keeping --- ui-log.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui-log.c b/ui-log.c index ff832ce..6bff948 100644 --- a/ui-log.c +++ b/ui-log.c @@ -476,7 +476,7 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern if (ofs<0) ofs = 0; - for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { + for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; /* nop */) { if (show_commit(commit, &rev)) i++; free_commit_buffer(commit); @@ -484,7 +484,7 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern commit->parents = NULL; } - for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { + for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; /* nop */) { /* * In "follow" mode, we must count the files and lines the * first time we invoke diff on a given commit, and we need From 622e64d5f2c56543f56438cb7a705c9023bec269 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Thu, 13 Aug 2015 11:38:27 +0200 Subject: [PATCH 032/387] redirect: be more careful for different cgi setups --- cmd.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd.c b/cmd.c index e86b0ea..315edc3 100644 --- a/cmd.c +++ b/cmd.c @@ -46,7 +46,10 @@ static void about_fn(void) static void about_pre(void) { - if (ctx.repo && !ctx.qry.path && ctx.qry.url[strlen(ctx.qry.url) - 1] != '/') + if (ctx.repo && + !ctx.qry.path && + ctx.qry.url[strlen(ctx.qry.url) - 1] != '/' && + ctx.env.path_info[strlen(ctx.env.path_info) - 1] != '/') cgit_redirect(fmtalloc("%s/", cgit_currenturl()), true); } From c0b59823035efc136a82a96094d164a979d9b2e9 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Thu, 13 Aug 2015 11:38:56 +0200 Subject: [PATCH 033/387] redirect: cleanliness --- ui-shared.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ui-shared.c b/ui-shared.c index 6be0c2e..1292ac9 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -706,8 +706,7 @@ void cgit_print_http_headers(void) void cgit_redirect(const char *url, bool permanent) { htmlf("Status: %d %s\n", permanent ? 301 : 302, permanent ? "Moved" : "Found"); - htmlf("Location: %s\n", url); - htmlf("\n"); + htmlf("Location: %s\n\n", url); exit(0); } From 2ef4edee19c3f935dfffc3e0f4a56f5e2f183fa4 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Thu, 13 Aug 2015 12:14:13 +0100 Subject: [PATCH 034/387] tests: allow shell to be overridden On some systems (e.g. Solaris), /bin/sh is not a POSIX shell. Git already provides suitable overrides in its config.mak.uname file and we provide cgit.conf to allow the user to further change this. The code for this is taken from Git's t/Makefile, meaning that we now invoke the tests in the same way that Git does. Signed-off-by: John Keeping --- tests/Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/Makefile b/tests/Makefile index 1556475..65e1117 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,11 +1,15 @@ +include ../git/config.mak.uname +-include ../cgit.conf +SHELL_PATH ?= $(SHELL) +SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH)) T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh) all: $(T) $(T): - @./$@ $(CGIT_TEST_OPTS) + @'$(SHELL_PATH_SQ)' $@ $(CGIT_TEST_OPTS) clean: $(RM) -rf trash From 0393102249c30f62c8f061062bc4a9ba962b6910 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Thu, 13 Aug 2015 12:14:14 +0100 Subject: [PATCH 035/387] Makefile: include Git's config.mak.uname This pulls in the correct value of $(INSTALL) on a wide variety of systems. Signed-off-by: John Keeping --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 65b4318..74061a3 100644 --- a/Makefile +++ b/Makefile @@ -33,6 +33,7 @@ DOC_PDF = $(patsubst %.txt,%.pdf,$(MAN_TXT)) #-include config.mak +include git/config.mak.uname # # Let the user override the above settings. # From 157f544ac2149a985b0f62e9381a759c0ae252ec Mon Sep 17 00:00:00 2001 From: John Keeping Date: Thu, 13 Aug 2015 12:14:15 +0100 Subject: [PATCH 036/387] Remove redundant includes These are all included in git-compat-util.h (when necessary), which we include in cgit.h. Signed-off-by: John Keeping --- filter.c | 6 ------ html.c | 6 ------ shared.c | 1 - ui-plain.c | 1 - ui-repolist.c | 1 - ui-summary.c | 1 - 6 files changed, 16 deletions(-) diff --git a/filter.c b/filter.c index ebf4937..c7037a3 100644 --- a/filter.c +++ b/filter.c @@ -8,13 +8,7 @@ #include "cgit.h" #include "html.h" -#include -#include -#include -#include -#include #include -#include #ifndef NO_LUA #include #include diff --git a/html.c b/html.c index 155cde5..a47cff0 100644 --- a/html.c +++ b/html.c @@ -8,12 +8,6 @@ #include "cgit.h" #include "html.h" -#include -#include -#include -#include -#include -#include /* Percent-encoding of each character, except: a-zA-Z0-9!$()*,./:;@- */ static const char* url_escape_table[256] = { diff --git a/shared.c b/shared.c index 0431b59..3bd2a9e 100644 --- a/shared.c +++ b/shared.c @@ -7,7 +7,6 @@ */ #include "cgit.h" -#include struct cgit_repolist cgit_repolist; struct cgit_context ctx; diff --git a/ui-plain.c b/ui-plain.c index b787bc3..3a2cb47 100644 --- a/ui-plain.c +++ b/ui-plain.c @@ -6,7 +6,6 @@ * (see COPYING for full license text) */ -#include #include "cgit.h" #include "ui-plain.h" #include "html.h" diff --git a/ui-repolist.c b/ui-repolist.c index edefc4c..43253ed 100644 --- a/ui-repolist.c +++ b/ui-repolist.c @@ -10,7 +10,6 @@ #include "ui-repolist.h" #include "html.h" #include "ui-shared.h" -#include static time_t read_agefile(char *path) { diff --git a/ui-summary.c b/ui-summary.c index b0af073..a5c7078 100644 --- a/ui-summary.c +++ b/ui-summary.c @@ -13,7 +13,6 @@ #include "ui-refs.h" #include "ui-blob.h" #include "ui-shared.h" -#include static int urls; From f2e8ca806d43acbfd9bef53f1a3ee5ce95ff32e7 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Thu, 13 Aug 2015 12:14:16 +0100 Subject: [PATCH 037/387] configfile.c: don't include system headers directly git-compat-util.h may define various values that affect the interpretation of system headers. In most places we include cgit.h first, which pulls in git-compat-util.h, but this file does not depend on anything else in CGit, so use git-compat-util.h directly. Signed-off-by: John Keeping --- configfile.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/configfile.c b/configfile.c index 833f158..5b0d880 100644 --- a/configfile.c +++ b/configfile.c @@ -6,8 +6,7 @@ * (see COPYING for full license text) */ -#include -#include +#include #include "configfile.h" static int next_char(FILE *f) From 43620cf6aa62decaf319d00c28297e3b87a4da78 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Thu, 13 Aug 2015 12:14:17 +0100 Subject: [PATCH 038/387] cache.c: fix header order git-compat-util.h may define values that affect how system headers are interpreted, so move sys/sendfile.h after cgit.h (which includes git-compat-util.h). Signed-off-by: John Keeping --- cache.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cache.c b/cache.c index cd99812..57c8918 100644 --- a/cache.c +++ b/cache.c @@ -13,12 +13,12 @@ * */ -#ifdef HAVE_LINUX_SENDFILE -#include -#endif #include "cgit.h" #include "cache.h" #include "html.h" +#ifdef HAVE_LINUX_SENDFILE +#include +#endif #define CACHE_BUFSIZE (1024 * 4) From e09574bdf6cfbd21ff0a58a18f34d4a11db824d7 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Thu, 13 Aug 2015 12:14:18 +0100 Subject: [PATCH 039/387] cgit.h: move stdbool.h from ui-shared.h Follow the Git policy of including system headers in only one place. Signed-off-by: John Keeping --- cgit.h | 2 ++ ui-shared.h | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cgit.h b/cgit.h index 3120562..508179a 100644 --- a/cgit.h +++ b/cgit.h @@ -3,6 +3,8 @@ #include +#include + #include #include #include diff --git a/ui-shared.h b/ui-shared.h index 788b1bc..d8a3551 100644 --- a/ui-shared.h +++ b/ui-shared.h @@ -1,8 +1,6 @@ #ifndef UI_SHARED_H #define UI_SHARED_H -#include - extern const char *cgit_httpscheme(); extern const char *cgit_hosturl(); extern const char *cgit_rooturl(); From 7105a78b17b118866aee77735e26cffcd1fd08fd Mon Sep 17 00:00:00 2001 From: John Keeping Date: Thu, 13 Aug 2015 12:14:19 +0100 Subject: [PATCH 040/387] ui-tree: use "sane" isgraph() Git's git-compat-util.h defines a "sane ctype" that does not use locale information and works with signed chars, but it does not include isgraph() so we have included ctype.h ourselves. However, this means we have to include a system header before git-compat-util.h which may lead to the system defining some macros (e.g. _FILE_OFFSET_BITS on Solaris) before git-compat-util.h redefines them with a different value. We cannot include ctype.h after git-compat-util.h because we have defined many of its functions as macros which causes a stream of compilation errors. Defining our own "sane" isgraph() using Git's sane isprint() and isspace() avoids all of these problems. Signed-off-by: John Keeping --- cgit.h | 3 +++ ui-tree.c | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/cgit.h b/cgit.h index 508179a..f327627 100644 --- a/cgit.h +++ b/cgit.h @@ -25,6 +25,9 @@ #include #include +/* Add isgraph(x) to Git's sane ctype support (see git-compat-util.h) */ +#undef isgraph +#define isgraph(x) (isprint((x)) && !isspace((x))) /* * Dateformats used on misc. pages diff --git a/ui-tree.c b/ui-tree.c index c8d24f6..2dbe89e 100644 --- a/ui-tree.c +++ b/ui-tree.c @@ -6,7 +6,6 @@ * (see COPYING for full license text) */ -#include #include "cgit.h" #include "ui-tree.h" #include "html.h" From 0c4d76755b98bb597279a1930bf4c69eca7dde62 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Thu, 13 Aug 2015 12:14:20 +0100 Subject: [PATCH 041/387] filter: don't use dlsym unnecessarily We only need to hook write() if Lua filter's are in use. If support has been disabled, remove the dependency on dlsym(). Signed-off-by: John Keeping --- filter.c | 78 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 42 insertions(+), 36 deletions(-) diff --git a/filter.c b/filter.c index c7037a3..949c931 100644 --- a/filter.c +++ b/filter.c @@ -8,17 +8,13 @@ #include "cgit.h" #include "html.h" -#include #ifndef NO_LUA +#include #include #include #include #endif -static ssize_t (*libc_write)(int fd, const void *buf, size_t count); -static ssize_t (*filter_write)(struct cgit_filter *base, const void *buf, size_t count) = NULL; -static struct cgit_filter *current_write_filter = NULL; - static inline void reap_filter(struct cgit_filter *filter) { if (filter && filter->cleanup) @@ -43,37 +39,6 @@ void cgit_cleanup_filters(void) } } -void cgit_init_filters(void) -{ - libc_write = dlsym(RTLD_NEXT, "write"); - if (!libc_write) - die("Could not locate libc's write function"); -} - -ssize_t write(int fd, const void *buf, size_t count) -{ - if (fd != STDOUT_FILENO || !filter_write) - return libc_write(fd, buf, count); - return filter_write(current_write_filter, buf, count); -} - -static inline void hook_write(struct cgit_filter *filter, ssize_t (*new_write)(struct cgit_filter *base, const void *buf, size_t count)) -{ - /* We want to avoid buggy nested patterns. */ - assert(filter_write == NULL); - assert(current_write_filter == NULL); - current_write_filter = filter; - filter_write = new_write; -} - -static inline void unhook_write(void) -{ - assert(filter_write != NULL); - assert(current_write_filter != NULL); - filter_write = NULL; - current_write_filter = NULL; -} - static int open_exec_filter(struct cgit_filter *base, va_list ap) { struct cgit_exec_filter *filter = (struct cgit_exec_filter *)base; @@ -170,7 +135,48 @@ void cgit_exec_filter_init(struct cgit_exec_filter *filter, char *cmd, char **ar filter->base.argument_count = 0; } +#ifdef NO_LUA +void cgit_init_filters(void) +{ +} +#endif + #ifndef NO_LUA +static ssize_t (*libc_write)(int fd, const void *buf, size_t count); +static ssize_t (*filter_write)(struct cgit_filter *base, const void *buf, size_t count) = NULL; +static struct cgit_filter *current_write_filter = NULL; + +void cgit_init_filters(void) +{ + libc_write = dlsym(RTLD_NEXT, "write"); + if (!libc_write) + die("Could not locate libc's write function"); +} + +ssize_t write(int fd, const void *buf, size_t count) +{ + if (fd != STDOUT_FILENO || !filter_write) + return libc_write(fd, buf, count); + return filter_write(current_write_filter, buf, count); +} + +static inline void hook_write(struct cgit_filter *filter, ssize_t (*new_write)(struct cgit_filter *base, const void *buf, size_t count)) +{ + /* We want to avoid buggy nested patterns. */ + assert(filter_write == NULL); + assert(current_write_filter == NULL); + current_write_filter = filter; + filter_write = new_write; +} + +static inline void unhook_write(void) +{ + assert(filter_write != NULL); + assert(current_write_filter != NULL); + filter_write = NULL; + current_write_filter = NULL; +} + struct lua_filter { struct cgit_filter base; char *script_file; From f03e3cb8a5c6b597b87321e1f082d3ab177e8baa Mon Sep 17 00:00:00 2001 From: John Keeping Date: Thu, 13 Aug 2015 12:24:32 +0100 Subject: [PATCH 042/387] ui-shared: extract date formatting to a function This will allow this code to be common with print_rel_date. Signed-off-by: John Keeping --- ui-shared.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ui-shared.c b/ui-shared.c index 1292ac9..19cd521 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -604,19 +604,24 @@ void cgit_submodule_link(const char *class, char *path, const char *rev) path[len - 1] = tail; } -void cgit_print_date(time_t secs, const char *format, int local_time) +static const char *fmt_date(time_t secs, const char *format, int local_time) { - char buf[64]; + static char buf[64]; struct tm *time; if (!secs) - return; + return ""; if (local_time) time = localtime(&secs); else time = gmtime(&secs); strftime(buf, sizeof(buf)-1, format, time); - html_txt(buf); + return buf; +} + +void cgit_print_date(time_t secs, const char *format, int local_time) +{ + html_txt(fmt_date(secs, format, local_time)); } static void print_rel_date(time_t t, double value, From b44dd95f13f039cd9bee301655150ff765d9555e Mon Sep 17 00:00:00 2001 From: John Keeping Date: Thu, 13 Aug 2015 12:24:33 +0100 Subject: [PATCH 043/387] ui-shared: use common function in print_rel_date() Signed-off-by: John Keeping --- ui-shared.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/ui-shared.c b/ui-shared.c index 19cd521..bbb277a 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -627,17 +627,8 @@ void cgit_print_date(time_t secs, const char *format, int local_time) static void print_rel_date(time_t t, double value, const char *class, const char *suffix) { - char buf[64]; - struct tm *time; - - if (ctx.cfg.local_time) - time = localtime(&t); - else - time = gmtime(&t); - strftime(buf, sizeof(buf) - 1, FMT_LONGDATE, time); - htmlf("%.0f %s", value, suffix); } From a360666df3cfcd1b384cd66b18803d72e3893b3d Mon Sep 17 00:00:00 2001 From: John Keeping Date: Thu, 13 Aug 2015 12:24:34 +0100 Subject: [PATCH 044/387] ui-shared: show full date in tooltip if longer ago than max_relative Commit caed6cb (ui-shared: show absolute time in tooltip for relative dates, 2014-12-20) added a toolip when we show a relative time. However, in some cases we show a short date (that is, the date but not the time) if an event was sufficiently far in the past and that commit did not update that case to add the same tooltip. Signed-off-by: John Keeping --- ui-shared.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ui-shared.c b/ui-shared.c index bbb277a..36fcb21 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -644,7 +644,11 @@ void cgit_print_age(time_t t, time_t max_relative, const char *format) secs = 0; if (secs > max_relative && max_relative >= 0) { + html(""); cgit_print_date(t, format, ctx.cfg.local_time); + html(""); return; } From c543d7dbf6bf7c8be5af829bf1d3eab494856ee0 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Thu, 13 Aug 2015 15:54:37 +0100 Subject: [PATCH 045/387] Makefile: make "git/config.mak.uname" inclusion optional If we haven't got a "git" directory, it should still be possible to run "make get-git", so we cannot include this file unconditionally. Signed-off-by: John Keeping --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 74061a3..a0a6615 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,7 @@ DOC_PDF = $(patsubst %.txt,%.pdf,$(MAN_TXT)) #-include config.mak -include git/config.mak.uname +-include git/config.mak.uname # # Let the user override the above settings. # From aa12084f9835783abbd1f1e4609f8de05e73cec4 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Fri, 14 Aug 2015 00:02:50 +0200 Subject: [PATCH 046/387] ui-patch: make sure to send http headers Requesting a text/plain patch with bad commit id made cgit send text without proper http headers. This results in "500 Internal Server Error" with "Premature end of script headers" in server logs. So print http headers before error message and return. Signed-off-by: Christian Hesse Reviewed-by: John Keeping --- ui-patch.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ui-patch.c b/ui-patch.c index 6ec89b4..57ca2f8 100644 --- a/ui-patch.c +++ b/ui-patch.c @@ -25,21 +25,25 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, new_rev = ctx.qry.head; if (get_sha1(new_rev, new_rev_sha1)) { + cgit_print_http_headers(); cgit_print_error("Bad object id: %s", new_rev); return; } commit = lookup_commit_reference(new_rev_sha1); if (!commit) { + cgit_print_http_headers(); cgit_print_error("Bad commit reference: %s", new_rev); return; } if (old_rev) { if (get_sha1(old_rev, old_rev_sha1)) { + cgit_print_http_headers(); cgit_print_error("Bad object id: %s", old_rev); return; } if (!lookup_commit_reference(old_rev_sha1)) { + cgit_print_http_headers(); cgit_print_error("Bad commit reference: %s", old_rev); return; } From aec1204a54e3baa12c76db75c2f67696def05eb0 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Fri, 14 Aug 2015 12:47:01 +0100 Subject: [PATCH 047/387] ui-shared: add cgit_print_error_page() function This will allow us to generate error responses with the correct HTTP response code without needing all of the layout boilerplate. Signed-off-by: John Keeping --- ui-shared.c | 14 ++++++++++++++ ui-shared.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/ui-shared.c b/ui-shared.c index 36fcb21..06dd0a8 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -788,6 +788,20 @@ void cgit_print_docend(void) html("\n\n"); } +void cgit_print_error_page(int code, const char *msg, const char *fmt, ...) +{ + va_list ap; + ctx.page.status = code; + ctx.page.statusmsg = msg; + cgit_print_http_headers(); + cgit_print_docstart(); + cgit_print_pageheader(); + va_start(ap, fmt); + cgit_vprint_error(fmt, ap); + va_end(ap); + cgit_print_docend(); +} + static void add_clone_urls(void (*fn)(const char *), char *txt, char *suffix) { struct strbuf **url_list = strbuf_split_str(txt, ' ', 0); diff --git a/ui-shared.h b/ui-shared.h index d8a3551..652685e 100644 --- a/ui-shared.h +++ b/ui-shared.h @@ -64,6 +64,8 @@ extern void cgit_print_http_headers(void); extern void cgit_redirect(const char *url, bool permanent); extern void cgit_print_docstart(void); extern void cgit_print_docend(); +__attribute__((format (printf,3,4))) +extern void cgit_print_error_page(int code, const char *msg, const char *fmt, ...); extern void cgit_print_pageheader(void); extern void cgit_print_filemode(unsigned short mode); extern void cgit_print_snapshot_links(const char *repo, const char *head, From e9b71ae6fe910573156c4632a314b7dbf84d7b64 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Fri, 14 Aug 2015 12:47:02 +0100 Subject: [PATCH 048/387] cgit: use cgit_print_error_page() where appropriate These are more-or-less one-to-one translations but in the final hunk we gain an HTTP error code where we used to send "200 OK", which is an improvement. Signed-off-by: John Keeping --- cgit.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/cgit.c b/cgit.c index d84b4be..3a97563 100644 --- a/cgit.c +++ b/cgit.c @@ -614,13 +614,8 @@ static int prepare_repo_cmd(void) if (get_sha1(ctx.qry.head, sha1)) { char *tmp = xstrdup(ctx.qry.head); ctx.qry.head = ctx.repo->defbranch; - ctx.page.status = 404; - ctx.page.statusmsg = "Not found"; - cgit_print_http_headers(); - cgit_print_docstart(); - cgit_print_pageheader(); - cgit_print_error("Invalid branch: %s", tmp); - cgit_print_docend(); + cgit_print_error_page(404, "Not found", + "Invalid branch: %s", tmp); free(tmp); return 1; } @@ -713,18 +708,13 @@ static void process_request(void) cmd = cgit_get_cmd(); if (!cmd) { ctx.page.title = "cgit error"; - ctx.page.status = 404; - ctx.page.statusmsg = "Not found"; - cgit_print_http_headers(); - cgit_print_docstart(); - cgit_print_pageheader(); - cgit_print_error("Invalid request"); - cgit_print_docend(); + cgit_print_error_page(404, "Not found", "Invalid request"); return; } if (!ctx.cfg.enable_http_clone && cmd->is_clone) { - html_status(404, "Not found", 0); + ctx.page.title = "cgit error"; + cgit_print_error_page(404, "Not found", "Invalid request"); return; } @@ -735,11 +725,8 @@ static void process_request(void) ctx.qry.vpath = cmd->want_vpath ? ctx.qry.path : NULL; if (cmd->want_repo && !ctx.repo) { - cgit_print_http_headers(); - cgit_print_docstart(); - cgit_print_pageheader(); - cgit_print_error("No repository selected"); - cgit_print_docend(); + cgit_print_error_page(400, "Bad request", + "No repository selected"); return; } From 329381dfe45d37cb94847ee92ebe58f2d6c02a9d Mon Sep 17 00:00:00 2001 From: John Keeping Date: Fri, 14 Aug 2015 12:47:03 +0100 Subject: [PATCH 049/387] clone: use cgit_print_error_page() instead of html_status() This provides a formatted error response rather than a simple HTTP error. Signed-off-by: John Keeping --- ui-clone.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ui-clone.c b/ui-clone.c index e4ddd34..f7b0b04 100644 --- a/ui-clone.c +++ b/ui-clone.c @@ -57,13 +57,13 @@ static void send_file(const char *path) if (stat(path, &st)) { switch (errno) { case ENOENT: - html_status(404, "Not found", 0); + cgit_print_error_page(404, "Not found", "Not found"); break; case EACCES: - html_status(403, "Forbidden", 0); + cgit_print_error_page(403, "Forbidden", "Forbidden"); break; default: - html_status(400, "Bad request", 0); + cgit_print_error_page(400, "Bad request", "Bad request"); } return; } @@ -78,7 +78,7 @@ static void send_file(const char *path) void cgit_clone_info(void) { if (!ctx.qry.path || strcmp(ctx.qry.path, "refs")) { - html_status(400, "Bad request", 0); + cgit_print_error_page(400, "Bad request", "Bad request"); return; } @@ -91,7 +91,7 @@ void cgit_clone_info(void) void cgit_clone_objects(void) { if (!ctx.qry.path) { - html_status(400, "Bad request", 0); + cgit_print_error_page(400, "Bad request", "Bad request"); return; } From 2b3e76a9f95c50f55be70dbb1cfa029f5165a535 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Fri, 14 Aug 2015 12:47:04 +0100 Subject: [PATCH 050/387] plain: use cgit_print_error_page() instead of html_status() This provides a formatted error response rather than a simple HTTP error. Signed-off-by: John Keeping --- ui-plain.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ui-plain.c b/ui-plain.c index 3a2cb47..0daa7bf 100644 --- a/ui-plain.c +++ b/ui-plain.c @@ -66,13 +66,13 @@ static int print_object(const unsigned char *sha1, const char *path) type = sha1_object_info(sha1, &size); if (type == OBJ_BAD) { - html_status(404, "Not found", 0); + cgit_print_error_page(404, "Not found", "Not found"); return 0; } buf = read_sha1_file(sha1, &type, &size); if (!buf) { - html_status(404, "Not found", 0); + cgit_print_error_page(404, "Not found", "Not found"); return 0; } ctx.page.mimetype = NULL; @@ -225,12 +225,12 @@ void cgit_print_plain(void) rev = ctx.qry.head; if (get_sha1(rev, sha1)) { - html_status(404, "Not found", 0); + cgit_print_error_page(404, "Not found", "Not found"); return; } commit = lookup_commit_reference(sha1); if (!commit || parse_commit(commit)) { - html_status(404, "Not found", 0); + cgit_print_error_page(404, "Not found", "Not found"); return; } if (!path_items.match) { @@ -243,7 +243,7 @@ void cgit_print_plain(void) walk_tree_ctx.match_baselen = basedir_len(path_items.match); read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); if (!walk_tree_ctx.match) - html_status(404, "Not found", 0); + cgit_print_error_page(404, "Not found", "Not found"); else if (walk_tree_ctx.match == 2) print_dir_tail(); } From 048f195eaf2fedb56987f0c8c89b9fd46375aa87 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Fri, 14 Aug 2015 12:47:05 +0100 Subject: [PATCH 051/387] snapshot: use cgit_print_error_page() instead of html_status() This provides a formatted error response rather than a simple HTTP error. Signed-off-by: John Keeping --- ui-snapshot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui-snapshot.c b/ui-snapshot.c index cb34f4b..bf4bcd7 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c @@ -213,7 +213,7 @@ void cgit_print_snapshot(const char *head, const char *hex, if (!hex && dwim) { hex = get_ref_from_filename(ctx.repo->url, filename, f); if (hex == NULL) { - html_status(404, "Not found", 0); + cgit_print_error_page(404, "Not found", "Not found"); return; } prefix = xstrdup(filename); From 9a06211daacd2fff14c6211bfc8bad856694f0f9 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Fri, 14 Aug 2015 12:47:06 +0100 Subject: [PATCH 052/387] blob: use cgit_print_error_page() to add HTTP headers This is a bugfix as well as an improvement to the HTTP status code handling since previously we would not print HTTP headers on any of these code paths. Signed-off-by: John Keeping --- ui-blob.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ui-blob.c b/ui-blob.c index 388a017..b333f86 100644 --- a/ui-blob.c +++ b/ui-blob.c @@ -126,12 +126,14 @@ void cgit_print_blob(const char *hex, char *path, const char *head, int file_onl if (hex) { if (get_sha1_hex(hex, sha1)) { - cgit_print_error("Bad hex value: %s", hex); + cgit_print_error_page(400, "Bad request", + "Bad hex value: %s", hex); return; } } else { if (get_sha1(head, sha1)) { - cgit_print_error("Bad ref: %s", head); + cgit_print_error_page(404, "Not found", + "Bad ref: %s", head); return; } } @@ -145,13 +147,15 @@ void cgit_print_blob(const char *hex, char *path, const char *head, int file_onl } if (type == OBJ_BAD) { - cgit_print_error("Bad object name: %s", hex); + cgit_print_error_page(404, "Not found", + "Bad object name: %s", hex); return; } buf = read_sha1_file(sha1, &type, &size); if (!buf) { - cgit_print_error("Error reading object %s", hex); + cgit_print_error_page(500, "Internal server error", + "Error reading object %s", hex); return; } From e3e41e5125b1ce270b5afb42beb83e14c0f350cb Mon Sep 17 00:00:00 2001 From: John Keeping Date: Fri, 14 Aug 2015 12:47:07 +0100 Subject: [PATCH 053/387] patch: use cgit_print_error_page() for HTTP status codes Signed-off-by: John Keeping --- ui-patch.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ui-patch.c b/ui-patch.c index 57ca2f8..430231e 100644 --- a/ui-patch.c +++ b/ui-patch.c @@ -25,26 +25,26 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, new_rev = ctx.qry.head; if (get_sha1(new_rev, new_rev_sha1)) { - cgit_print_http_headers(); - cgit_print_error("Bad object id: %s", new_rev); + cgit_print_error_page(404, "Not found", + "Bad object id: %s", new_rev); return; } commit = lookup_commit_reference(new_rev_sha1); if (!commit) { - cgit_print_http_headers(); - cgit_print_error("Bad commit reference: %s", new_rev); + cgit_print_error_page(404, "Not found", + "Bad commit reference: %s", new_rev); return; } if (old_rev) { if (get_sha1(old_rev, old_rev_sha1)) { - cgit_print_http_headers(); - cgit_print_error("Bad object id: %s", old_rev); + cgit_print_error_page(404, "Not found", + "Bad object id: %s", old_rev); return; } if (!lookup_commit_reference(old_rev_sha1)) { - cgit_print_http_headers(); - cgit_print_error("Bad commit reference: %s", old_rev); + cgit_print_error_page(404, "Not found", + "Bad commit reference: %s", old_rev); return; } } else if (commit->parents && commit->parents->item) { From 58e827cbd9811500f72bf25b1db569b208661618 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Fri, 14 Aug 2015 12:47:08 +0100 Subject: [PATCH 054/387] snapshot: use cgit_print_error_page() for HTTP status codes This is a bugfix as well as an improvement to the HTTP status code handling since previously we would not print HTTP headers on any of these code paths. Signed-off-by: John Keeping --- ui-snapshot.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ui-snapshot.c b/ui-snapshot.c index bf4bcd7..9bcf13d 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c @@ -112,11 +112,13 @@ static int make_snapshot(const struct cgit_snapshot_format *format, unsigned char sha1[20]; if (get_sha1(hex, sha1)) { - cgit_print_error("Bad object id: %s", hex); + cgit_print_error_page(404, "Not found", + "Bad object id: %s", hex); return 1; } if (!lookup_commit_reference(sha1)) { - cgit_print_error("Not a commit reference: %s", hex); + cgit_print_error_page(400, "Bad request", + "Not a commit reference: %s", hex); return 1; } ctx.page.etag = sha1_to_hex(sha1); From fd00e71ab7cf1eabd8d1fc2e5980055350849034 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Fri, 14 Aug 2015 12:47:09 +0100 Subject: [PATCH 055/387] snapshot: don't reimplement cgit_print_error_page() cgit_print_error_page() has the advantage that it sets a suitable HTTP status code for the response. Note that setting "mimetype" is redundant here since it cannot have changed since being initialized in cgit.c::prepare_context(), so we do not need to worry that cgit_print_error_page() does not set it. Signed-off-by: John Keeping --- ui-snapshot.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/ui-snapshot.c b/ui-snapshot.c index 9bcf13d..f68e877 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c @@ -180,21 +180,6 @@ out: return result ? strbuf_detach(&snapshot, NULL) : NULL; } -__attribute__((format (printf, 1, 2))) -static void show_error(char *fmt, ...) -{ - va_list ap; - - ctx.page.mimetype = "text/html"; - cgit_print_http_headers(); - cgit_print_docstart(); - cgit_print_pageheader(); - va_start(ap, fmt); - cgit_vprint_error(fmt, ap); - va_end(ap); - cgit_print_docend(); -} - void cgit_print_snapshot(const char *head, const char *hex, const char *filename, int dwim) { @@ -202,13 +187,15 @@ void cgit_print_snapshot(const char *head, const char *hex, char *prefix = NULL; if (!filename) { - show_error("No snapshot name specified"); + cgit_print_error_page(400, "Bad request", + "No snapshot name specified"); return; } f = get_format(filename); if (!f) { - show_error("Unsupported snapshot format: %s", filename); + cgit_print_error_page(400, "Bad request", + "Unsupported snapshot format: %s", filename); return; } From fb2c71fad23f4f13f56f74a8b79907805ab1b772 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Fri, 14 Aug 2015 12:47:10 +0100 Subject: [PATCH 056/387] html: remove html_status() This is now unused. Signed-off-by: John Keeping --- html.c | 7 ------- html.h | 1 - 2 files changed, 8 deletions(-) diff --git a/html.c b/html.c index a47cff0..959148c 100644 --- a/html.c +++ b/html.c @@ -121,13 +121,6 @@ void html_vtxtf(const char *format, va_list ap) strbuf_release(&buf); } -void html_status(int code, const char *msg, int more_headers) -{ - htmlf("Status: %d %s\n", code, msg); - if (!more_headers) - html("\n"); -} - void html_txt(const char *txt) { const char *t = txt; diff --git a/html.h b/html.h index be3b311..c554763 100644 --- a/html.h +++ b/html.h @@ -18,7 +18,6 @@ extern void html_vtxtf(const char *format, va_list ap); __attribute__((format (printf,1,2))) extern void html_attrf(const char *format,...); -extern void html_status(int code, const char *msg, int more_headers); extern void html_txt(const char *txt); extern void html_ntxt(int len, const char *txt); extern void html_attr(const char *txt); From 764987980ec0e806205b8e075feafd4e010dcbd9 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Fri, 14 Aug 2015 12:47:11 +0100 Subject: [PATCH 057/387] ui-shared: add cgit_print_layout_{start,end}() These will avoid needing to call three functions to start page layout in subsequent patches when we move the layout setup into each individual page. Signed-off-by: John Keeping --- ui-shared.c | 12 ++++++++++++ ui-shared.h | 3 +++ 2 files changed, 15 insertions(+) diff --git a/ui-shared.c b/ui-shared.c index 06dd0a8..de06256 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -802,6 +802,18 @@ void cgit_print_error_page(int code, const char *msg, const char *fmt, ...) cgit_print_docend(); } +void cgit_print_layout_start(void) +{ + cgit_print_http_headers(); + cgit_print_docstart(); + cgit_print_pageheader(); +} + +void cgit_print_layout_end(void) +{ + cgit_print_docend(); +} + static void add_clone_urls(void (*fn)(const char *), char *txt, char *suffix) { struct strbuf **url_list = strbuf_split_str(txt, ' ', 0); diff --git a/ui-shared.h b/ui-shared.h index 652685e..246678b 100644 --- a/ui-shared.h +++ b/ui-shared.h @@ -54,6 +54,9 @@ extern void cgit_object_link(struct object *obj); extern void cgit_submodule_link(const char *class, char *path, const char *rev); +extern void cgit_print_layout_start(void); +extern void cgit_print_layout_end(void); + __attribute__((format (printf,1,2))) extern void cgit_print_error(const char *fmt, ...); __attribute__((format (printf,1,0))) From 51d9176e4bb5c619481355c6b895c6dec30c4f82 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Fri, 14 Aug 2015 12:47:12 +0100 Subject: [PATCH 058/387] about: move layout into page functions Signed-off-by: John Keeping --- cmd.c | 2 +- ui-repolist.c | 5 ++++- ui-summary.c | 8 ++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/cmd.c b/cmd.c index 315edc3..616890c 100644 --- a/cmd.c +++ b/cmd.c @@ -155,7 +155,7 @@ struct cgit_cmd *cgit_get_cmd(void) static struct cgit_cmd cmds[] = { def_cmd(HEAD, 1, 0, 0, 1), def_cmd(atom, 1, 0, 0, 0), - def_cmp(about, 0, 1, 0, 0), + def_cmp(about, 0, 0, 0, 0), def_cmd(blob, 1, 0, 0, 0), def_cmd(commit, 1, 1, 1, 0), def_cmd(diff, 1, 1, 1, 0), diff --git a/ui-repolist.c b/ui-repolist.c index 43253ed..ac1b3e3 100644 --- a/ui-repolist.c +++ b/ui-repolist.c @@ -345,9 +345,12 @@ void cgit_print_repolist(void) void cgit_print_site_readme(void) { + cgit_print_layout_start(); if (!ctx.cfg.root_readme) - return; + goto done; cgit_open_filter(ctx.cfg.about_filter, ctx.cfg.root_readme); html_include(ctx.cfg.root_readme); cgit_close_filter(ctx.cfg.about_filter); +done: + cgit_print_layout_end(); } diff --git a/ui-summary.c b/ui-summary.c index a5c7078..cd1fef5 100644 --- a/ui-summary.c +++ b/ui-summary.c @@ -101,8 +101,9 @@ void cgit_print_repo_readme(char *path) char *filename, *ref; int free_filename = 0; + cgit_print_layout_start(); if (ctx.repo->readme.nr == 0) - return; + goto done; filename = ctx.repo->readme.items[0].string; ref = ctx.repo->readme.items[0].util; @@ -111,7 +112,7 @@ void cgit_print_repo_readme(char *path) free_filename = 1; filename = append_readme_path(filename, ref, path); if (!filename) - return; + goto done; } /* Print the calculated readme, either from the git repo or from the @@ -128,4 +129,7 @@ void cgit_print_repo_readme(char *path) html("
"); if (free_filename) free(filename); + +done: + cgit_print_layout_end(); } From c53a15c77a6763b4d6fefb033923ba7493b884a2 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Fri, 14 Aug 2015 12:47:13 +0100 Subject: [PATCH 059/387] commit: move layout into page function This allows us to return a proper HTTP status code when an object is not found by switching from cgit_print_error() to cgit_print_error_page(). Signed-off-by: John Keeping --- cmd.c | 2 +- ui-commit.c | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cmd.c b/cmd.c index 616890c..1b42a47 100644 --- a/cmd.c +++ b/cmd.c @@ -157,7 +157,7 @@ struct cgit_cmd *cgit_get_cmd(void) def_cmd(atom, 1, 0, 0, 0), def_cmp(about, 0, 0, 0, 0), def_cmd(blob, 1, 0, 0, 0), - def_cmd(commit, 1, 1, 1, 0), + def_cmd(commit, 1, 0, 1, 0), def_cmd(diff, 1, 1, 1, 0), def_cmd(info, 1, 0, 0, 1), def_cmd(log, 1, 1, 1, 0), diff --git a/ui-commit.c b/ui-commit.c index d5a888d..2bca7a0 100644 --- a/ui-commit.c +++ b/ui-commit.c @@ -27,12 +27,14 @@ void cgit_print_commit(char *hex, const char *prefix) hex = ctx.qry.head; if (get_sha1(hex, sha1)) { - cgit_print_error("Bad object id: %s", hex); + cgit_print_error_page(400, "Bad request", + "Bad object id: %s", hex); return; } commit = lookup_commit_reference(sha1); if (!commit) { - cgit_print_error("Bad commit reference: %s", hex); + cgit_print_error_page(404, "Not found", + "Bad commit reference: %s", hex); return; } info = cgit_parse_commit(commit); @@ -41,6 +43,7 @@ void cgit_print_commit(char *hex, const char *prefix) load_ref_decorations(DECORATE_FULL_REFS); + cgit_print_layout_start(); cgit_print_diff_ctrls(); html("\n"); html(""); html("
author"); @@ -139,4 +142,5 @@ void cgit_print_commit(char *hex, const char *prefix) } strbuf_release(¬es); cgit_free_commitinfo(info); + cgit_print_layout_end(); } From 3b220eb22ded98851ca9dee7c3c3e3b0fd02c49b Mon Sep 17 00:00:00 2001 From: John Keeping Date: Fri, 14 Aug 2015 12:47:14 +0100 Subject: [PATCH 060/387] diff: move layout to page function The existing "show_ctrls" flag is used to control whether we are running in an existing page or control the page ourselves. Signed-off-by: John Keeping --- cmd.c | 2 +- ui-diff.c | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/cmd.c b/cmd.c index 1b42a47..d9f6eff 100644 --- a/cmd.c +++ b/cmd.c @@ -158,7 +158,7 @@ struct cgit_cmd *cgit_get_cmd(void) def_cmp(about, 0, 0, 0, 0), def_cmd(blob, 1, 0, 0, 0), def_cmd(commit, 1, 0, 1, 0), - def_cmd(diff, 1, 1, 1, 0), + def_cmd(diff, 1, 0, 1, 0), def_cmd(info, 1, 0, 0, 1), def_cmd(log, 1, 1, 1, 0), def_cmd(ls_cache, 0, 0, 0, 0), diff --git a/ui-diff.c b/ui-diff.c index caebd5d..5d18296 100644 --- a/ui-diff.c +++ b/ui-diff.c @@ -403,19 +403,22 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, if (!new_rev) new_rev = ctx.qry.head; if (get_sha1(new_rev, new_rev_sha1)) { - cgit_print_error("Bad object name: %s", new_rev); + cgit_print_error_page(404, "Not found", + "Bad object name: %s", new_rev); return; } commit = lookup_commit_reference(new_rev_sha1); if (!commit || parse_commit(commit)) { - cgit_print_error("Bad commit: %s", sha1_to_hex(new_rev_sha1)); + cgit_print_error_page(404, "Not found", + "Bad commit: %s", sha1_to_hex(new_rev_sha1)); return; } new_tree_sha1 = commit->tree->object.sha1; if (old_rev) { if (get_sha1(old_rev, old_rev_sha1)) { - cgit_print_error("Bad object name: %s", old_rev); + cgit_print_error_page(404, "Not found", + "Bad object name: %s", old_rev); return; } } else if (commit->parents && commit->parents->item) { @@ -427,7 +430,8 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, if (!is_null_sha1(old_rev_sha1)) { commit2 = lookup_commit_reference(old_rev_sha1); if (!commit2 || parse_commit(commit2)) { - cgit_print_error("Bad commit: %s", sha1_to_hex(old_rev_sha1)); + cgit_print_error_page(404, "Not found", + "Bad commit: %s", sha1_to_hex(old_rev_sha1)); return; } old_tree_sha1 = commit2->tree->object.sha1; @@ -460,8 +464,10 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, difftype = ctx.qry.has_difftype ? ctx.qry.difftype : ctx.cfg.difftype; use_ssdiff = difftype == DIFF_SSDIFF; - if (show_ctrls) + if (show_ctrls) { + cgit_print_layout_start(); cgit_print_diff_ctrls(); + } /* * Clicking on a link to a file in the diff stat should show a diff @@ -489,4 +495,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, if (!use_ssdiff) html("
"); + + if (show_ctrls) + cgit_print_layout_end(); } From 23c17d8ff01b96619bc1f71274cb44f1425e10f4 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Fri, 14 Aug 2015 12:47:15 +0100 Subject: [PATCH 061/387] log: move layout into page function Signed-off-by: John Keeping --- cmd.c | 2 +- ui-log.c | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cmd.c b/cmd.c index d9f6eff..0bf4c76 100644 --- a/cmd.c +++ b/cmd.c @@ -160,7 +160,7 @@ struct cgit_cmd *cgit_get_cmd(void) def_cmd(commit, 1, 0, 1, 0), def_cmd(diff, 1, 0, 1, 0), def_cmd(info, 1, 0, 0, 1), - def_cmd(log, 1, 1, 1, 0), + def_cmd(log, 1, 0, 1, 0), def_cmd(ls_cache, 0, 0, 0, 0), def_cmd(objects, 1, 0, 0, 1), def_cmd(patch, 1, 0, 1, 0), diff --git a/ui-log.c b/ui-log.c index 6bff948..0782478 100644 --- a/ui-log.c +++ b/ui-log.c @@ -442,8 +442,10 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern compile_grep_patterns(&rev.grep_filter); prepare_revision_walk(&rev); - if (pager) + if (pager) { + cgit_print_layout_start(); html(""); + } html(""); if (commit_graph) @@ -526,6 +528,7 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern html(""); } html(""); + cgit_print_layout_end(); } else if ((commit = get_revision(&rev)) != NULL) { htmlf("", name, sha1_to_hex(sha1)); + free(name); return 0; } } From fa5810ed8e66c4b217b8e02d2682e0fdba7f102b Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Fri, 9 Oct 2015 13:15:45 +0200 Subject: [PATCH 083/387] ui-ssdiff: fix resource leak: free allocation from cgit_fileurl Coverity-id: 13929 Signed-off-by: Christian Hesse --- ui-ssdiff.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ui-ssdiff.c b/ui-ssdiff.c index 2146c71..d183d40 100644 --- a/ui-ssdiff.c +++ b/ui-ssdiff.c @@ -230,11 +230,13 @@ static void print_ssdiff_line(char *class, struct diff_filespec *old_file = cgit_get_current_old_file(); char *lineno_str = fmt("n%d", old_line_no); char *id_str = fmt("id=%s#%s", is_null_sha1(old_file->sha1)?"HEAD":sha1_to_hex(old_rev_sha1), lineno_str); + char *fileurl = cgit_fileurl(ctx.repo->url, "tree", old_file->path, id_str); html(""); htmlf(""); htmlf("
", columns); cgit_log_link("[...]", NULL, NULL, ctx.qry.head, NULL, From 6d39dd1914dd0a904c606b079e8ef0f1643f2266 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Fri, 14 Aug 2015 12:47:16 +0100 Subject: [PATCH 062/387] refs: move layout to page function Signed-off-by: John Keeping --- cmd.c | 2 +- ui-refs.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cmd.c b/cmd.c index 0bf4c76..ce66af9 100644 --- a/cmd.c +++ b/cmd.c @@ -166,7 +166,7 @@ struct cgit_cmd *cgit_get_cmd(void) def_cmd(patch, 1, 0, 1, 0), def_cmd(plain, 1, 0, 0, 0), def_cmd(rawdiff, 1, 0, 1, 0), - def_cmd(refs, 1, 1, 0, 0), + def_cmd(refs, 1, 0, 0, 0), def_cmd(repolist, 0, 0, 0, 0), def_cmd(snapshot, 1, 0, 0, 0), def_cmd(stats, 1, 1, 1, 0), diff --git a/ui-refs.c b/ui-refs.c index 73a187b..be3572c 100644 --- a/ui-refs.c +++ b/ui-refs.c @@ -236,7 +236,7 @@ void cgit_print_tags(int maxcount) void cgit_print_refs(void) { - + cgit_print_layout_start(); html(""); if (ctx.qry.path && starts_with(ctx.qry.path, "heads")) @@ -249,4 +249,5 @@ void cgit_print_refs(void) cgit_print_tags(0); } html("
"); + cgit_print_layout_end(); } From 892c5441f4af2f53a3b1906c4d7e458829e0cf0a Mon Sep 17 00:00:00 2001 From: John Keeping Date: Fri, 14 Aug 2015 12:47:17 +0100 Subject: [PATCH 063/387] stats: move layout into page function This also allows us to return proper HTTP error codes for invalid requests. Signed-off-by: John Keeping --- cmd.c | 2 +- ui-stats.c | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cmd.c b/cmd.c index ce66af9..4f8e71d 100644 --- a/cmd.c +++ b/cmd.c @@ -169,7 +169,7 @@ struct cgit_cmd *cgit_get_cmd(void) def_cmd(refs, 1, 0, 0, 0), def_cmd(repolist, 0, 0, 0, 0), def_cmd(snapshot, 1, 0, 0, 0), - def_cmd(stats, 1, 1, 1, 0), + def_cmd(stats, 1, 0, 1, 0), def_cmd(summary, 1, 1, 0, 0), def_cmd(tag, 1, 1, 0, 0), def_cmd(tree, 1, 1, 1, 0), diff --git a/ui-stats.c b/ui-stats.c index 9cd8247..74ce0f7 100644 --- a/ui-stats.c +++ b/ui-stats.c @@ -372,11 +372,13 @@ void cgit_show_stats(void) i = cgit_find_stats_period(code, &period); if (!i) { - cgit_print_error("Unknown statistics type: %c", code[0]); + cgit_print_error_page(404, "Not found", + "Unknown statistics type: %c", code[0]); return; } if (i > ctx.repo->max_stats) { - cgit_print_error("Statistics type disabled: %s", period->name); + cgit_print_error_page(400, "Bad request", + "Statistics type disabled: %s", period->name); return; } authors = collect_stats(period); @@ -387,6 +389,7 @@ void cgit_show_stats(void) if (!top) top = 10; + cgit_print_layout_start(); html("
"); html("stat options"); html("
"); @@ -421,5 +424,6 @@ void cgit_show_stats(void) } html(""); print_authors(&authors, top, period); + cgit_print_layout_end(); } From a3daa41b78fc2c528c9a42630ab95451ddb87358 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Fri, 14 Aug 2015 12:47:18 +0100 Subject: [PATCH 064/387] summary: move layout into page function Signed-off-by: John Keeping --- cmd.c | 2 +- ui-summary.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/cmd.c b/cmd.c index 4f8e71d..928c8aa 100644 --- a/cmd.c +++ b/cmd.c @@ -170,7 +170,7 @@ struct cgit_cmd *cgit_get_cmd(void) def_cmd(repolist, 0, 0, 0, 0), def_cmd(snapshot, 1, 0, 0, 0), def_cmd(stats, 1, 0, 1, 0), - def_cmd(summary, 1, 1, 0, 0), + def_cmd(summary, 1, 0, 0, 0), def_cmd(tag, 1, 1, 0, 0), def_cmd(tree, 1, 1, 1, 0), }; diff --git a/ui-summary.c b/ui-summary.c index cd1fef5..fb04dc3 100644 --- a/ui-summary.c +++ b/ui-summary.c @@ -48,6 +48,7 @@ void cgit_print_summary(void) if (ctx.repo->enable_log_linecount) columns++; + cgit_print_layout_start(); html(""); cgit_print_branches(ctx.cfg.summary_branches); htmlf("", columns); @@ -60,6 +61,7 @@ void cgit_print_summary(void) urls = 0; cgit_add_clone_urls(print_url); html("
 
"); + cgit_print_layout_end(); } /* The caller must free the return value. */ From 696a33b66f8638d5c3e0464d66760c6d60ff24a5 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Fri, 14 Aug 2015 12:47:19 +0100 Subject: [PATCH 065/387] tag: move layout into page function This also allows us to return proper HTTP error codes when something goes wrong. Signed-off-by: John Keeping --- cmd.c | 2 +- ui-tag.c | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/cmd.c b/cmd.c index 928c8aa..54961d9 100644 --- a/cmd.c +++ b/cmd.c @@ -171,7 +171,7 @@ struct cgit_cmd *cgit_get_cmd(void) def_cmd(snapshot, 1, 0, 0, 0), def_cmd(stats, 1, 0, 1, 0), def_cmd(summary, 1, 0, 0, 0), - def_cmd(tag, 1, 1, 0, 0), + def_cmd(tag, 1, 0, 0, 0), def_cmd(tree, 1, 1, 1, 0), }; int i; diff --git a/ui-tag.c b/ui-tag.c index c1d1738..0afc663 100644 --- a/ui-tag.c +++ b/ui-tag.c @@ -52,20 +52,24 @@ void cgit_print_tag(char *revname) strbuf_addf(&fullref, "refs/tags/%s", revname); if (get_sha1(fullref.buf, sha1)) { - cgit_print_error("Bad tag reference: %s", revname); + cgit_print_error_page(404, "Not found", + "Bad tag reference: %s", revname); goto cleanup; } obj = parse_object(sha1); if (!obj) { - cgit_print_error("Bad object id: %s", sha1_to_hex(sha1)); + cgit_print_error_page(500, "Internal server error", + "Bad object id: %s", sha1_to_hex(sha1)); goto cleanup; } if (obj->type == OBJ_TAG) { tag = lookup_tag(sha1); if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) { - cgit_print_error("Bad tag object: %s", revname); + cgit_print_error_page(500, "Internal server error", + "Bad tag object: %s", revname); goto cleanup; } + cgit_print_layout_start(); html("\n"); htmlf("
tag name"); html_txt(revname); @@ -93,7 +97,9 @@ void cgit_print_tag(char *revname) print_download_links(revname); html("
\n"); print_tag_content(info->msg); + cgit_print_layout_end(); } else { + cgit_print_layout_start(); html("\n"); htmlf("
tag name"); html_txt(revname); @@ -104,6 +110,7 @@ void cgit_print_tag(char *revname) if (ctx.repo->snapshots) print_download_links(revname); html("
\n"); + cgit_print_layout_end(); } cleanup: From 9c70c0bfdb71b39f6bae6e0c77bbe40b22d64ff5 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Fri, 14 Aug 2015 12:47:20 +0100 Subject: [PATCH 066/387] tree: move layout into page function This also allows us to return proper HTTP error codes when the requested tree is not found and display an error message in one case (invalid path inside valid commit) where we previously just displayed an empty page. Signed-off-by: John Keeping --- cmd.c | 2 +- ui-tree.c | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/cmd.c b/cmd.c index 54961d9..3c90d0b 100644 --- a/cmd.c +++ b/cmd.c @@ -172,7 +172,7 @@ struct cgit_cmd *cgit_get_cmd(void) def_cmd(stats, 1, 0, 1, 0), def_cmd(summary, 1, 0, 0, 0), def_cmd(tag, 1, 0, 0, 0), - def_cmd(tree, 1, 1, 1, 0), + def_cmd(tree, 1, 0, 1, 0), }; int i; diff --git a/ui-tree.c b/ui-tree.c index 2dbe89e..1b310d5 100644 --- a/ui-tree.c +++ b/ui-tree.c @@ -92,16 +92,19 @@ static void print_object(const unsigned char *sha1, char *path, const char *base type = sha1_object_info(sha1, &size); if (type == OBJ_BAD) { - cgit_print_error("Bad object name: %s", sha1_to_hex(sha1)); + cgit_print_error_page(404, "Not found", + "Bad object name: %s", sha1_to_hex(sha1)); return; } buf = read_sha1_file(sha1, &type, &size); if (!buf) { - cgit_print_error("Error reading object %s", sha1_to_hex(sha1)); + cgit_print_error_page(500, "Internal server error", + "Error reading object %s", sha1_to_hex(sha1)); return; } + cgit_print_layout_start(); htmlf("blob: %s (", sha1_to_hex(sha1)); cgit_plain_link("plain", NULL, NULL, ctx.qry.head, rev, path); @@ -181,6 +184,7 @@ static int ls_item(const unsigned char *sha1, struct strbuf *base, static void ls_head(void) { + cgit_print_layout_start(); html("\n"); html(""); html(""); @@ -193,6 +197,7 @@ static void ls_head(void) static void ls_tail(void) { html("
Mode
\n"); + cgit_print_layout_end(); } static void ls_tree(const unsigned char *sha1, char *path, struct walk_tree_context *walk_tree_ctx) @@ -204,7 +209,8 @@ static void ls_tree(const unsigned char *sha1, char *path, struct walk_tree_cont tree = parse_tree_indirect(sha1); if (!tree) { - cgit_print_error("Not a tree object: %s", sha1_to_hex(sha1)); + cgit_print_error_page(404, "Not found", + "Not a tree object: %s", sha1_to_hex(sha1)); return; } @@ -231,6 +237,7 @@ static int walk_tree(const unsigned char *sha1, struct strbuf *base, ls_head(); return READ_TREE_RECURSIVE; } else { + walk_tree_ctx->state = 2; print_object(sha1, buffer, pathname, walk_tree_ctx->curr_rev); return 0; } @@ -265,12 +272,14 @@ void cgit_print_tree(const char *rev, char *path) rev = ctx.qry.head; if (get_sha1(rev, sha1)) { - cgit_print_error("Invalid revision name: %s", rev); + cgit_print_error_page(404, "Not found", + "Invalid revision name: %s", rev); return; } commit = lookup_commit_reference(sha1); if (!commit || parse_commit(commit)) { - cgit_print_error("Invalid commit reference: %s", rev); + cgit_print_error_page(404, "Not found", + "Invalid commit reference: %s", rev); return; } @@ -284,6 +293,10 @@ void cgit_print_tree(const char *rev, char *path) read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); if (walk_tree_ctx.state == 1) ls_tail(); + else if (walk_tree_ctx.state == 2) + cgit_print_layout_end(); + else + cgit_print_error_page(404, "Not found", "Path not found"); cleanup: free(walk_tree_ctx.curr_rev); From a420c7ce9b2c483c2f93b8a1a03cc80f3eeedb20 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Fri, 14 Aug 2015 12:47:21 +0100 Subject: [PATCH 067/387] cmd: remove "want_layout" field No commands use this any more. Signed-off-by: John Keeping --- cgit.c | 9 --------- cmd.c | 48 ++++++++++++++++++++++++------------------------ cmd.h | 1 - 3 files changed, 24 insertions(+), 34 deletions(-) diff --git a/cgit.c b/cgit.c index 3a97563..7271412 100644 --- a/cgit.c +++ b/cgit.c @@ -736,16 +736,7 @@ static void process_request(void) if (cmd->pre) cmd->pre(); - if (cmd->want_layout) { - cgit_print_http_headers(); - cgit_print_docstart(); - cgit_print_pageheader(); - } - cmd->fn(); - - if (cmd->want_layout) - cgit_print_docend(); } static int cmp_repos(const void *a, const void *b) diff --git a/cmd.c b/cmd.c index 3c90d0b..05494fe 100644 --- a/cmd.c +++ b/cmd.c @@ -145,34 +145,34 @@ static void tree_fn(void) cgit_print_tree(ctx.qry.sha1, ctx.qry.path); } -#define def_cmp(name, want_repo, want_layout, want_vpath, is_clone) \ - {#name, name##_fn, name##_pre, want_repo, want_layout, want_vpath, is_clone} -#define def_cmd(name, want_repo, want_layout, want_vpath, is_clone) \ - {#name, name##_fn, NULL, want_repo, want_layout, want_vpath, is_clone} +#define def_cmp(name, want_repo, want_vpath, is_clone) \ + {#name, name##_fn, name##_pre, want_repo, want_vpath, is_clone} +#define def_cmd(name, want_repo, want_vpath, is_clone) \ + {#name, name##_fn, NULL, want_repo, want_vpath, is_clone} struct cgit_cmd *cgit_get_cmd(void) { static struct cgit_cmd cmds[] = { - def_cmd(HEAD, 1, 0, 0, 1), - def_cmd(atom, 1, 0, 0, 0), - def_cmp(about, 0, 0, 0, 0), - def_cmd(blob, 1, 0, 0, 0), - def_cmd(commit, 1, 0, 1, 0), - def_cmd(diff, 1, 0, 1, 0), - def_cmd(info, 1, 0, 0, 1), - def_cmd(log, 1, 0, 1, 0), - def_cmd(ls_cache, 0, 0, 0, 0), - def_cmd(objects, 1, 0, 0, 1), - def_cmd(patch, 1, 0, 1, 0), - def_cmd(plain, 1, 0, 0, 0), - def_cmd(rawdiff, 1, 0, 1, 0), - def_cmd(refs, 1, 0, 0, 0), - def_cmd(repolist, 0, 0, 0, 0), - def_cmd(snapshot, 1, 0, 0, 0), - def_cmd(stats, 1, 0, 1, 0), - def_cmd(summary, 1, 0, 0, 0), - def_cmd(tag, 1, 0, 0, 0), - def_cmd(tree, 1, 0, 1, 0), + def_cmd(HEAD, 1, 0, 1), + def_cmd(atom, 1, 0, 0), + def_cmp(about, 0, 0, 0), + def_cmd(blob, 1, 0, 0), + def_cmd(commit, 1, 1, 0), + def_cmd(diff, 1, 1, 0), + def_cmd(info, 1, 0, 1), + def_cmd(log, 1, 1, 0), + def_cmd(ls_cache, 0, 0, 0), + def_cmd(objects, 1, 0, 1), + def_cmd(patch, 1, 1, 0), + def_cmd(plain, 1, 0, 0), + def_cmd(rawdiff, 1, 1, 0), + def_cmd(refs, 1, 0, 0), + def_cmd(repolist, 0, 0, 0), + def_cmd(snapshot, 1, 0, 0), + def_cmd(stats, 1, 1, 0), + def_cmd(summary, 1, 0, 0), + def_cmd(tag, 1, 0, 0), + def_cmd(tree, 1, 1, 0), }; int i; diff --git a/cmd.h b/cmd.h index 2507ca5..1a98089 100644 --- a/cmd.h +++ b/cmd.h @@ -9,7 +9,6 @@ struct cgit_cmd { cgit_cmd_fn fn; cgit_cmd_pre_fn pre; unsigned int want_repo:1, - want_layout:1, want_vpath:1, is_clone:1; }; From c5975ae56684a1188637f2bdba7d8e18de075abc Mon Sep 17 00:00:00 2001 From: John Keeping Date: Fri, 14 Aug 2015 12:47:22 +0100 Subject: [PATCH 068/387] ui-shared: cache errors for "dynamic TTL" Most errors we generate are (potentially) transient, such as non-existent object IDs so we don't want them to be cached forever. Signed-off-by: John Keeping --- ui-shared.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ui-shared.c b/ui-shared.c index de06256..89c4897 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -791,6 +791,7 @@ void cgit_print_docend(void) void cgit_print_error_page(int code, const char *msg, const char *fmt, ...) { va_list ap; + ctx.page.expires = ctx.cfg.cache_dynamic_ttl; ctx.page.status = code; ctx.page.statusmsg = msg; cgit_print_http_headers(); From 03de473354dc8c17a3b23a973b5cc67752ad20cb Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Fri, 14 Aug 2015 15:54:32 +0200 Subject: [PATCH 069/387] cmd: no need for pre function hook now Signed-off-by: Jason A. Donenfeld --- cgit.c | 3 --- cmd.c | 24 +++++++++--------------- cmd.h | 2 -- 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/cgit.c b/cgit.c index 7271412..28a2f14 100644 --- a/cgit.c +++ b/cgit.c @@ -733,9 +733,6 @@ static void process_request(void) if (ctx.repo && prepare_repo_cmd()) return; - if (cmd->pre) - cmd->pre(); - cmd->fn(); } diff --git a/cmd.c b/cmd.c index 05494fe..20c80b0 100644 --- a/cmd.c +++ b/cmd.c @@ -38,21 +38,17 @@ static void atom_fn(void) static void about_fn(void) { - if (ctx.repo) - cgit_print_repo_readme(ctx.qry.path); - else + if (ctx.repo) { + if (!ctx.qry.path && + ctx.qry.url[strlen(ctx.qry.url) - 1] != '/' && + ctx.env.path_info[strlen(ctx.env.path_info) - 1] != '/') + cgit_redirect(fmtalloc("%s/", cgit_currenturl()), true); + else + cgit_print_repo_readme(ctx.qry.path); + } else cgit_print_site_readme(); } -static void about_pre(void) -{ - if (ctx.repo && - !ctx.qry.path && - ctx.qry.url[strlen(ctx.qry.url) - 1] != '/' && - ctx.env.path_info[strlen(ctx.env.path_info) - 1] != '/') - cgit_redirect(fmtalloc("%s/", cgit_currenturl()), true); -} - static void blob_fn(void) { cgit_print_blob(ctx.qry.sha1, ctx.qry.path, ctx.qry.head, 0); @@ -145,8 +141,6 @@ static void tree_fn(void) cgit_print_tree(ctx.qry.sha1, ctx.qry.path); } -#define def_cmp(name, want_repo, want_vpath, is_clone) \ - {#name, name##_fn, name##_pre, want_repo, want_vpath, is_clone} #define def_cmd(name, want_repo, want_vpath, is_clone) \ {#name, name##_fn, NULL, want_repo, want_vpath, is_clone} @@ -155,7 +149,7 @@ struct cgit_cmd *cgit_get_cmd(void) static struct cgit_cmd cmds[] = { def_cmd(HEAD, 1, 0, 1), def_cmd(atom, 1, 0, 0), - def_cmp(about, 0, 0, 0), + def_cmd(about, 0, 0, 0), def_cmd(blob, 1, 0, 0), def_cmd(commit, 1, 1, 0), def_cmd(diff, 1, 1, 0), diff --git a/cmd.h b/cmd.h index 1a98089..6249b1d 100644 --- a/cmd.h +++ b/cmd.h @@ -2,12 +2,10 @@ #define CMD_H typedef void (*cgit_cmd_fn)(void); -typedef void (*cgit_cmd_pre_fn)(void); struct cgit_cmd { const char *name; cgit_cmd_fn fn; - cgit_cmd_pre_fn pre; unsigned int want_repo:1, want_vpath:1, is_clone:1; From 73ef8567f04c2dea8fbf83213b28e0cd1dff98f3 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Fri, 14 Aug 2015 15:20:23 +0100 Subject: [PATCH 070/387] cmd: fix command definition The previous commit removed the "pre" field from "struct cgit_cmd" but forgot to update this macro. Signed-off-by: John Keeping Reviewed-by: Christian Hesse --- cmd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd.c b/cmd.c index 20c80b0..c991092 100644 --- a/cmd.c +++ b/cmd.c @@ -142,7 +142,7 @@ static void tree_fn(void) } #define def_cmd(name, want_repo, want_vpath, is_clone) \ - {#name, name##_fn, NULL, want_repo, want_vpath, is_clone} + {#name, name##_fn, want_repo, want_vpath, is_clone} struct cgit_cmd *cgit_get_cmd(void) { From f5c83d7b5ddceb03e1c6bda2e43c48500c7da9f5 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Fri, 14 Aug 2015 16:50:56 +0200 Subject: [PATCH 071/387] move get_mimetype_from_file() to shared Signed-off-by: Christian Hesse --- cgit.h | 2 ++ shared.c | 40 ++++++++++++++++++++++++++++++++++++++++ ui-plain.c | 40 ---------------------------------------- 3 files changed, 42 insertions(+), 40 deletions(-) diff --git a/cgit.h b/cgit.h index f327627..0f1e186 100644 --- a/cgit.h +++ b/cgit.h @@ -391,4 +391,6 @@ extern int readfile(const char *path, char **buf, size_t *size); extern char *expand_macros(const char *txt); +extern char *get_mimetype_from_file(const char *filename, const char *ext); + #endif /* CGIT_H */ diff --git a/shared.c b/shared.c index 3bd2a9e..fb4e8ca 100644 --- a/shared.c +++ b/shared.c @@ -560,3 +560,43 @@ char *expand_macros(const char *txt) } return result; } + +char *get_mimetype_from_file(const char *filename, const char *ext) +{ + static const char *delimiters; + char *result; + FILE *fd; + char line[1024]; + char *mimetype; + char *token; + + if (!filename) + return NULL; + + fd = fopen(filename, "r"); + if (!fd) + return NULL; + + delimiters = " \t\r\n"; + result = NULL; + + /* loop over all lines in the file */ + while (!result && fgets(line, sizeof(line), fd)) { + mimetype = strtok(line, delimiters); + + /* skip empty lines and comment lines */ + if (!mimetype || (mimetype[0] == '#')) + continue; + + /* loop over all extensions of mimetype */ + while ((token = strtok(NULL, delimiters))) { + if (!strcasecmp(ext, token)) { + result = xstrdup(mimetype); + break; + } + } + } + fclose(fd); + + return result; +} diff --git a/ui-plain.c b/ui-plain.c index 0daa7bf..d68518e 100644 --- a/ui-plain.c +++ b/ui-plain.c @@ -16,46 +16,6 @@ struct walk_tree_context { int match; }; -static char *get_mimetype_from_file(const char *filename, const char *ext) -{ - static const char *delimiters; - char *result; - FILE *fd; - char line[1024]; - char *mimetype; - char *token; - - if (!filename) - return NULL; - - fd = fopen(filename, "r"); - if (!fd) - return NULL; - - delimiters = " \t\r\n"; - result = NULL; - - /* loop over all lines in the file */ - while (!result && fgets(line, sizeof(line), fd)) { - mimetype = strtok(line, delimiters); - - /* skip empty lines and comment lines */ - if (!mimetype || (mimetype[0] == '#')) - continue; - - /* loop over all extensions of mimetype */ - while ((token = strtok(NULL, delimiters))) { - if (!strcasecmp(ext, token)) { - result = xstrdup(mimetype); - break; - } - } - } - fclose(fd); - - return result; -} - static int print_object(const unsigned char *sha1, const char *path) { enum object_type type; From aa943bc9a68ccdcc5cbe29f6ac3b5e787d4c22ca Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Sun, 16 Aug 2015 14:53:52 +0200 Subject: [PATCH 072/387] refactor get_mimetype_from_file() to get_mimetype_for_filename() * handle mimetype within a single function * return allocated memory on success Signed-off-by: Christian Hesse --- cgit.h | 2 +- shared.c | 57 +++++++++++++++++++++++++++++++----------------------- ui-plain.c | 28 ++++++--------------------- 3 files changed, 40 insertions(+), 47 deletions(-) diff --git a/cgit.h b/cgit.h index 0f1e186..b7eccdd 100644 --- a/cgit.h +++ b/cgit.h @@ -391,6 +391,6 @@ extern int readfile(const char *path, char **buf, size_t *size); extern char *expand_macros(const char *txt); -extern char *get_mimetype_from_file(const char *filename, const char *ext); +extern char *get_mimetype_for_filename(const char *filename); #endif /* CGIT_H */ diff --git a/shared.c b/shared.c index fb4e8ca..225ce15 100644 --- a/shared.c +++ b/shared.c @@ -561,42 +561,51 @@ char *expand_macros(const char *txt) return result; } -char *get_mimetype_from_file(const char *filename, const char *ext) +char *get_mimetype_for_filename(const char *filename) { static const char *delimiters; - char *result; - FILE *fd; + char *ext = NULL, *iterate, *mimetype = NULL, *token; char line[1024]; - char *mimetype; - char *token; + FILE *fd; + struct string_list_item *mime; - if (!filename) + if (filename == NULL) return NULL; - fd = fopen(filename, "r"); - if (!fd) - return NULL; + ext = strrchr(filename, '.'); - delimiters = " \t\r\n"; - result = NULL; + if (ext && *(++ext)) { + mime = string_list_lookup(&ctx.cfg.mimetypes, ext); + if (mime) { + /* We could just pass the pointer here, but would have to care + * whether or not to free the memory. Instead just dup. */ + mimetype = xstrdup(mime->util); + } else if (ctx.cfg.mimetype_file != NULL) { + fd = fopen(ctx.cfg.mimetype_file, "r"); + if (fd == NULL) + return NULL; - /* loop over all lines in the file */ - while (!result && fgets(line, sizeof(line), fd)) { - mimetype = strtok(line, delimiters); + delimiters = " \t\r\n"; - /* skip empty lines and comment lines */ - if (!mimetype || (mimetype[0] == '#')) - continue; + /* loop over all lines in the file */ + while (mimetype == NULL && fgets(line, sizeof(line), fd)) { + iterate = strtok(line, delimiters); - /* loop over all extensions of mimetype */ - while ((token = strtok(NULL, delimiters))) { - if (!strcasecmp(ext, token)) { - result = xstrdup(mimetype); - break; + /* skip empty lines and comment lines */ + if (iterate == NULL || (iterate[0] == '#')) + continue; + + /* loop over all extensions of mimetype */ + while ((token = strtok(NULL, delimiters))) { + if (strcasecmp(ext, token) == 0) { + mimetype = xstrdup(iterate); + break; + } + } } + fclose(fd); } } - fclose(fd); - return result; + return mimetype; } diff --git a/ui-plain.c b/ui-plain.c index d68518e..0dd1a8b 100644 --- a/ui-plain.c +++ b/ui-plain.c @@ -19,10 +19,8 @@ struct walk_tree_context { static int print_object(const unsigned char *sha1, const char *path) { enum object_type type; - char *buf, *ext; + char *buf, *mimetype; unsigned long size; - struct string_list_item *mime; - int freemime; type = sha1_object_info(sha1, &size); if (type == OBJ_BAD) { @@ -35,22 +33,10 @@ static int print_object(const unsigned char *sha1, const char *path) cgit_print_error_page(404, "Not found", "Not found"); return 0; } - ctx.page.mimetype = NULL; - ext = strrchr(path, '.'); - freemime = 0; - if (ext && *(++ext)) { - mime = string_list_lookup(&ctx.cfg.mimetypes, ext); - if (mime) { - ctx.page.mimetype = (char *)mime->util; - ctx.page.charset = NULL; - } else { - ctx.page.mimetype = get_mimetype_from_file(ctx.cfg.mimetype_file, ext); - if (ctx.page.mimetype) { - freemime = 1; - ctx.page.charset = NULL; - } - } - } + + mimetype = get_mimetype_for_filename(path); + ctx.page.mimetype = mimetype; + if (!ctx.page.mimetype) { if (buffer_is_binary(buf, size)) { ctx.page.mimetype = "application/octet-stream"; @@ -64,9 +50,7 @@ static int print_object(const unsigned char *sha1, const char *path) ctx.page.etag = sha1_to_hex(sha1); cgit_print_http_headers(); html_raw(buf, size); - /* If we allocated this, then casting away const is safe. */ - if (freemime) - free((char*) ctx.page.mimetype); + free(mimetype); return 1; } From 790d2498cbc7ad60f8eef31db0467cfc97e0593b Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Sun, 16 Aug 2015 14:53:53 +0200 Subject: [PATCH 073/387] ui-summary: send images plain for about page The about page used to display just fine, but images were broken: The binary image data was embedded in html code. Use cgit_print_plain() to send images in plain mode and make them available on about page. Signed-off-by: Christian Hesse --- ui-summary.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/ui-summary.c b/ui-summary.c index fb04dc3..8e81ac4 100644 --- a/ui-summary.c +++ b/ui-summary.c @@ -9,9 +9,10 @@ #include "cgit.h" #include "ui-summary.h" #include "html.h" -#include "ui-log.h" -#include "ui-refs.h" #include "ui-blob.h" +#include "ui-log.h" +#include "ui-plain.h" +#include "ui-refs.h" #include "ui-shared.h" static int urls; @@ -100,9 +101,19 @@ static char* append_readme_path(const char *filename, const char *ref, const cha void cgit_print_repo_readme(char *path) { - char *filename, *ref; + char *filename, *ref, *mimetype; int free_filename = 0; + mimetype = get_mimetype_for_filename(path); + if (mimetype && (!strncmp(mimetype, "image/", 6) || !strncmp(mimetype, "video/", 6))) { + ctx.page.mimetype = mimetype; + ctx.page.charset = NULL; + cgit_print_plain(); + free(mimetype); + return; + } + free(mimetype); + cgit_print_layout_start(); if (ctx.repo->readme.nr == 0) goto done; From 73f199be3f0b03fbaee9b9b30ed3d782e3395af7 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 17 Aug 2015 14:35:20 +0200 Subject: [PATCH 074/387] mime: rewrite detection function Signed-off-by: Jason A. Donenfeld --- shared.c | 62 ++++++++++++++++++++++++-------------------------------- 1 file changed, 26 insertions(+), 36 deletions(-) diff --git a/shared.c b/shared.c index 225ce15..3d91a76 100644 --- a/shared.c +++ b/shared.c @@ -563,49 +563,39 @@ char *expand_macros(const char *txt) char *get_mimetype_for_filename(const char *filename) { - static const char *delimiters; - char *ext = NULL, *iterate, *mimetype = NULL, *token; - char line[1024]; - FILE *fd; + char *ext, *mimetype, *token, line[1024]; + FILE *file; struct string_list_item *mime; - if (filename == NULL) + if (!filename) return NULL; ext = strrchr(filename, '.'); + if (!ext) + return NULL; + ++ext; + if (!ext[0]) + return NULL; + mime = string_list_lookup(&ctx.cfg.mimetypes, ext); + if (mime) + return xstrdup(mime->util); - if (ext && *(++ext)) { - mime = string_list_lookup(&ctx.cfg.mimetypes, ext); - if (mime) { - /* We could just pass the pointer here, but would have to care - * whether or not to free the memory. Instead just dup. */ - mimetype = xstrdup(mime->util); - } else if (ctx.cfg.mimetype_file != NULL) { - fd = fopen(ctx.cfg.mimetype_file, "r"); - if (fd == NULL) - return NULL; - - delimiters = " \t\r\n"; - - /* loop over all lines in the file */ - while (mimetype == NULL && fgets(line, sizeof(line), fd)) { - iterate = strtok(line, delimiters); - - /* skip empty lines and comment lines */ - if (iterate == NULL || (iterate[0] == '#')) - continue; - - /* loop over all extensions of mimetype */ - while ((token = strtok(NULL, delimiters))) { - if (strcasecmp(ext, token) == 0) { - mimetype = xstrdup(iterate); - break; - } - } + if (!ctx.cfg.mimetype_file) + return NULL; + file = fopen(ctx.cfg.mimetype_file, "r"); + if (!file) + return NULL; + while (fgets(line, sizeof(line), file)) { + if (!line[0] || line[0] == '#') + continue; + mimetype = strtok(line, " \t\r\n"); + while ((token = strtok(NULL, " \t\r\n"))) { + if (!strcasecmp(ext, token)) { + fclose(file); + return xstrdup(mimetype); } - fclose(fd); } } - - return mimetype; + fclose(file); + return NULL; } From 978ce8c00c0d3117f6470a77b08aa0f97984604f Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 6 Oct 2015 07:36:40 +0200 Subject: [PATCH 075/387] git: update to v2.6.1 Update to git version v2.6.1, no changes required. Signed-off-by: Christian Hesse --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index a0a6615..138fe5b 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = -GIT_VER = 2.5.0 +GIT_VER = 2.6.1 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.gz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index a17c56c..22f698c 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit a17c56c056d5fea0843b429132904c429a900229 +Subproject commit 22f698cb188243b313e024d618283e0293e37140 From 94182d6031df0d956a94ecd7ece233e345468961 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Thu, 8 Oct 2015 23:23:56 +0100 Subject: [PATCH 076/387] cgit.c: remove useless null check Everywhere else in this function we do not check whether the value is null and parse_configfile() never passes a null value to this callback. Coverity-id: 13846 Signed-off-by: John Keeping --- cgit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cgit.c b/cgit.c index 28a2f14..5937b9e 100644 --- a/cgit.c +++ b/cgit.c @@ -110,7 +110,7 @@ static void config_cb(const char *name, const char *value) ctx.repo->path = trim_end(value, '/'); else if (ctx.repo && starts_with(name, "repo.")) repo_config(ctx.repo, name + 5, value); - else if (!strcmp(name, "readme") && value != NULL) + else if (!strcmp(name, "readme")) string_list_append(&ctx.cfg.readme, xstrdup(value)); else if (!strcmp(name, "root-title")) ctx.cfg.root_title = xstrdup(value); From 687cdf69689edcaff8e9035af93baf1a9e71cf32 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Thu, 8 Oct 2015 23:23:57 +0100 Subject: [PATCH 077/387] scan-tree: remove useless strdup() parse_configfile() takes a "const char *" and doesn't hold any references to it after it returns; there is no reason to pass it a duplicate. Coverity-id: 13941 Signed-off-by: John Keeping --- scan-tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scan-tree.c b/scan-tree.c index 8e3cf52..b5a10ff 100644 --- a/scan-tree.c +++ b/scan-tree.c @@ -174,7 +174,7 @@ static void add_repo(const char *base, struct strbuf *path, repo_config_fn fn) strbuf_addstr(path, "cgitrc"); if (!stat(path->buf, &st)) - parse_configfile(xstrdup(path->buf), &repo_config); + parse_configfile(path->buf, &repo_config); strbuf_release(&rel); } From 509488d85c06c66eb65bc4809f6e317c1ebe1d7a Mon Sep 17 00:00:00 2001 From: John Keeping Date: Thu, 8 Oct 2015 23:23:58 +0100 Subject: [PATCH 078/387] ui-blob: remove useless null check We have already called strlen() on "path" by the time we get here, so we know it can't be null. Coverity-id: 13954 Signed-off-by: John Keeping --- ui-blob.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui-blob.c b/ui-blob.c index b333f86..d3c3a10 100644 --- a/ui-blob.c +++ b/ui-blob.c @@ -85,7 +85,7 @@ int cgit_print_file(char *path, const char *head, int file_only) if (get_sha1(head, sha1)) return -1; type = sha1_object_info(sha1, &size); - if (type == OBJ_COMMIT && path) { + if (type == OBJ_COMMIT) { commit = lookup_commit_reference(sha1); read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); if (!walk_tree_ctx.found_path) From 198a4404b937033cf2cf2b054242df4e81ef3075 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Thu, 8 Oct 2015 23:23:59 +0100 Subject: [PATCH 079/387] ui-refs: remove useless null check There is no way that "tag" can be null here. Coverity-id: 13950 Signed-off-by: John Keeping --- ui-refs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui-refs.c b/ui-refs.c index be3572c..295a4c7 100644 --- a/ui-refs.c +++ b/ui-refs.c @@ -135,7 +135,7 @@ static int print_tag(struct refinfo *ref) tag = (struct tag *)obj; obj = tag->tagged; info = ref->tag; - if (!tag || !info) + if (!info) return 1; } From 35b3c67ac285f0c488b0d3042a1bbc44ef4f1f67 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Sat, 5 Sep 2015 14:32:50 +0100 Subject: [PATCH 080/387] Makefile: fix MAKEFLAGS tests with multiple flags findstring is defined as $(findstring FIND,IN) so if multiple flags are set these tests do the wrong thing unless $(MAKEFLAGS) is the second argument. Signed-off-by: John Keeping --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 138fe5b..77b9f60 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,7 @@ export CGIT_VERSION CGIT_SCRIPT_NAME CGIT_SCRIPT_PATH CGIT_DATA_PATH CGIT_CONFIG QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir QUIET_SUBDIR1 = -ifneq ($(findstring $(MAKEFLAGS),w),w) +ifneq ($(findstring w,$(MAKEFLAGS)),w) PRINT_DIR = --no-print-directory else # "make -w" NO_SUBDIR = : From ad006918a570da32457461a5e59289b611d9a732 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Fri, 9 Oct 2015 11:01:04 +0200 Subject: [PATCH 081/387] Avoid use of non-reentrant functions Signed-off-by: Jason A. Donenfeld --- shared.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/shared.c b/shared.c index 3d91a76..e216c64 100644 --- a/shared.c +++ b/shared.c @@ -563,7 +563,7 @@ char *expand_macros(const char *txt) char *get_mimetype_for_filename(const char *filename) { - char *ext, *mimetype, *token, line[1024]; + char *ext, *mimetype, *token, line[1024], *saveptr; FILE *file; struct string_list_item *mime; @@ -588,8 +588,8 @@ char *get_mimetype_for_filename(const char *filename) while (fgets(line, sizeof(line), file)) { if (!line[0] || line[0] == '#') continue; - mimetype = strtok(line, " \t\r\n"); - while ((token = strtok(NULL, " \t\r\n"))) { + mimetype = strtok_r(line, " \t\r\n", &saveptr); + while ((token = strtok_r(NULL, " \t\r\n", &saveptr))) { if (!strcasecmp(ext, token)) { fclose(file); return xstrdup(mimetype); From 896cd69dde04832f6b551f681b92bd4557092427 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Fri, 9 Oct 2015 13:15:44 +0200 Subject: [PATCH 082/387] ui-tree: fix resource leak: free before return Coverity-id: 13938 Signed-off-by: Christian Hesse --- ui-tree.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ui-tree.c b/ui-tree.c index 1b310d5..d71503d 100644 --- a/ui-tree.c +++ b/ui-tree.c @@ -143,6 +143,7 @@ static int ls_item(const unsigned char *sha1, struct strbuf *base, htmlf("
Bad object: %s %s
%s", lineno_str, lineno_str + 1); html("", class); + free(fileurl); } else if (old_line) htmlf("", class); else @@ -251,11 +253,13 @@ static void print_ssdiff_line(char *class, struct diff_filespec *new_file = cgit_get_current_new_file(); char *lineno_str = fmt("n%d", new_line_no); char *id_str = fmt("id=%s#%s", is_null_sha1(new_file->sha1)?"HEAD":sha1_to_hex(new_rev_sha1), lineno_str); + char *fileurl = cgit_fileurl(ctx.repo->url, "tree", new_file->path, id_str); html("%s", lineno_str, lineno_str + 1); html("", class); + free(fileurl); } else if (new_line) htmlf("", class); else From 37fce9916a264e23c0639df56ca3ecbbdc1c84b8 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Fri, 9 Oct 2015 13:15:46 +0200 Subject: [PATCH 084/387] ui-shared: fix resource leak: free allocation from cgit_fileurl Coverity-id: 13918 Signed-off-by: Christian Hesse --- ui-shared.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/ui-shared.c b/ui-shared.c index 89c4897..d9f8258 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -746,16 +746,19 @@ void cgit_print_docstart(void) html("'/>\n"); } if (host && ctx.repo && ctx.qry.head) { + char *fileurl; struct strbuf sb = STRBUF_INIT; strbuf_addf(&sb, "h=%s", ctx.qry.head); html("\n"); strbuf_release(&sb); + free(fileurl); } if (ctx.repo) cgit_add_clone_urls(print_rel_vcs_link); @@ -997,9 +1000,12 @@ void cgit_print_pageheader(void) ctx.qry.head, ctx.qry.vpath); html(""); html("\n"); cgit_add_hidden_formfields(1, 0, "log"); html("\n"); html("\n"); } else if (ctx.env.authenticated) { + char *currenturl = cgit_currenturl(); site_link(NULL, "index", NULL, hc("repolist"), NULL, NULL, 0, 1); if (ctx.cfg.root_readme) site_link("about", "about", NULL, hc("about"), NULL, NULL, 0, 1); html(""); html("
\n"); html("\n"); html("\n"); html("
"); + free(currenturl); } html("
\n"); if (ctx.env.authenticated && ctx.qry.vpath) { From 6f2e4400faebd829f905c824400f933fe07f5c30 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Fri, 9 Oct 2015 13:15:49 +0200 Subject: [PATCH 087/387] cmd: fix resource leak: free allocation from cgit_currenturl and fmtalloc Signed-off-by: Christian Hesse --- cmd.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cmd.c b/cmd.c index c991092..3093c62 100644 --- a/cmd.c +++ b/cmd.c @@ -41,9 +41,13 @@ static void about_fn(void) if (ctx.repo) { if (!ctx.qry.path && ctx.qry.url[strlen(ctx.qry.url) - 1] != '/' && - ctx.env.path_info[strlen(ctx.env.path_info) - 1] != '/') - cgit_redirect(fmtalloc("%s/", cgit_currenturl()), true); - else + ctx.env.path_info[strlen(ctx.env.path_info) - 1] != '/') { + char *currenturl = cgit_currenturl(); + char *redirect = fmtalloc("%s/", currenturl); + cgit_redirect(redirect, true); + free(currenturl); + free(redirect); + } else cgit_print_repo_readme(ctx.qry.path); } else cgit_print_site_readme(); From f77e2a8cfaf07b25ddedd57348a1d957b048bbf5 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Fri, 9 Oct 2015 13:15:50 +0200 Subject: [PATCH 088/387] ui-shared: return value of cgit_hosturl is not const Signed-off-by: Christian Hesse --- ui-shared.c | 6 +++--- ui-shared.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ui-shared.c b/ui-shared.c index f6d38de..09c34fd 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -54,14 +54,14 @@ const char *cgit_httpscheme(void) return "http://"; } -const char *cgit_hosturl(void) +char *cgit_hosturl(void) { if (ctx.env.http_host) - return ctx.env.http_host; + return xstrdup(ctx.env.http_host); if (!ctx.env.server_name) return NULL; if (!ctx.env.server_port || atoi(ctx.env.server_port) == 80) - return ctx.env.server_name; + return xstrdup(ctx.env.server_name); return fmtalloc("%s:%s", ctx.env.server_name, ctx.env.server_port); } diff --git a/ui-shared.h b/ui-shared.h index 4121416..474e0c5 100644 --- a/ui-shared.h +++ b/ui-shared.h @@ -2,7 +2,7 @@ #define UI_SHARED_H extern const char *cgit_httpscheme(); -extern const char *cgit_hosturl(); +extern char *cgit_hosturl(); extern const char *cgit_rooturl(); extern char *cgit_currenturl(); extern const char *cgit_loginurl(); From 6edfc1672cdc5eb0dfb0ff5db0ec1de1ec53415e Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Fri, 9 Oct 2015 13:15:51 +0200 Subject: [PATCH 089/387] ui-shared: fix resource leak: free allocation from cgit_hosturl Signed-off-by: Christian Hesse --- ui-shared.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ui-shared.c b/ui-shared.c index 09c34fd..c04f380 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -730,7 +730,7 @@ void cgit_print_docstart(void) return; } - const char *host = cgit_hosturl(); + char *host = cgit_hosturl(); html(cgit_doctype); html("\n"); html("\n"); @@ -755,7 +755,7 @@ void cgit_print_docstart(void) html("" +markdown_py -o html5 +echo "" diff --git a/filters/html-converters/resources/markdown.pl b/filters/html-converters/resources/markdown.pl deleted file mode 100755 index 4c39808..0000000 --- a/filters/html-converters/resources/markdown.pl +++ /dev/null @@ -1,1727 +0,0 @@ -#!/usr/bin/perl - -# -# Markdown -- A text-to-HTML conversion tool for web writers -# -# Copyright (c) 2004 John Gruber -# -# - - -package Markdown; -require 5.006_000; -use strict; -use warnings; - -use Digest::MD5 qw(md5_hex); -use vars qw($VERSION); -$VERSION = '1.0.1'; -# Tue 14 Dec 2004 - - -# -# Global default settings: -# -my $g_empty_element_suffix = " />"; # Change to ">" for HTML output -my $g_tab_width = 4; - - -# -# Globals: -# - -# Regex to match balanced [brackets]. See Friedl's -# "Mastering Regular Expressions", 2nd Ed., pp. 328-331. -my $g_nested_brackets; -$g_nested_brackets = qr{ - (?> # Atomic matching - [^\[\]]+ # Anything other than brackets - | - \[ - (??{ $g_nested_brackets }) # Recursive set of nested brackets - \] - )* -}x; - - -# Table of hash values for escaped characters: -my %g_escape_table; -foreach my $char (split //, '\\`*_{}[]()>#+-.!') { - $g_escape_table{$char} = md5_hex($char); -} - - -# Global hashes, used by various utility routines -my %g_urls; -my %g_titles; -my %g_html_blocks; - -# Used to track when we're inside an ordered or unordered list -# (see _ProcessListItems() for details): -my $g_list_level = 0; - - -#### Blosxom plug-in interface ########################################## - -# Set $g_blosxom_use_meta to 1 to use Blosxom's meta plug-in to determine -# which posts Markdown should process, using a "meta-markup: markdown" -# header. If it's set to 0 (the default), Markdown will process all -# entries. -my $g_blosxom_use_meta = 0; - -sub start { 1; } -sub story { - my($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_; - - if ( (! $g_blosxom_use_meta) or - (defined($meta::markup) and ($meta::markup =~ /^\s*markdown\s*$/i)) - ){ - $$body_ref = Markdown($$body_ref); - } - 1; -} - - -#### Movable Type plug-in interface ##################################### -eval {require MT}; # Test to see if we're running in MT. -unless ($@) { - require MT; - import MT; - require MT::Template::Context; - import MT::Template::Context; - - eval {require MT::Plugin}; # Test to see if we're running >= MT 3.0. - unless ($@) { - require MT::Plugin; - import MT::Plugin; - my $plugin = new MT::Plugin({ - name => "Markdown", - description => "A plain-text-to-HTML formatting plugin. (Version: $VERSION)", - doc_link => 'http://daringfireball.net/projects/markdown/' - }); - MT->add_plugin( $plugin ); - } - - MT::Template::Context->add_container_tag(MarkdownOptions => sub { - my $ctx = shift; - my $args = shift; - my $builder = $ctx->stash('builder'); - my $tokens = $ctx->stash('tokens'); - - if (defined ($args->{'output'}) ) { - $ctx->stash('markdown_output', lc $args->{'output'}); - } - - defined (my $str = $builder->build($ctx, $tokens) ) - or return $ctx->error($builder->errstr); - $str; # return value - }); - - MT->add_text_filter('markdown' => { - label => 'Markdown', - docs => 'http://daringfireball.net/projects/markdown/', - on_format => sub { - my $text = shift; - my $ctx = shift; - my $raw = 0; - if (defined $ctx) { - my $output = $ctx->stash('markdown_output'); - if (defined $output && $output =~ m/^html/i) { - $g_empty_element_suffix = ">"; - $ctx->stash('markdown_output', ''); - } - elsif (defined $output && $output eq 'raw') { - $raw = 1; - $ctx->stash('markdown_output', ''); - } - else { - $raw = 0; - $g_empty_element_suffix = " />"; - } - } - $text = $raw ? $text : Markdown($text); - $text; - }, - }); - - # If SmartyPants is loaded, add a combo Markdown/SmartyPants text filter: - my $smartypants; - - { - no warnings "once"; - $smartypants = $MT::Template::Context::Global_filters{'smarty_pants'}; - } - - if ($smartypants) { - MT->add_text_filter('markdown_with_smartypants' => { - label => 'Markdown With SmartyPants', - docs => 'http://daringfireball.net/projects/markdown/', - on_format => sub { - my $text = shift; - my $ctx = shift; - if (defined $ctx) { - my $output = $ctx->stash('markdown_output'); - if (defined $output && $output eq 'html') { - $g_empty_element_suffix = ">"; - } - else { - $g_empty_element_suffix = " />"; - } - } - $text = Markdown($text); - $text = $smartypants->($text, '1'); - }, - }); - } -} -else { -#### BBEdit/command-line text filter interface ########################## -# Needs to be hidden from MT (and Blosxom when running in static mode). - - # We're only using $blosxom::version once; tell Perl not to warn us: - no warnings 'once'; - unless ( defined($blosxom::version) ) { - use warnings; - - #### Check for command-line switches: ################# - my %cli_opts; - use Getopt::Long; - Getopt::Long::Configure('pass_through'); - GetOptions(\%cli_opts, - 'version', - 'shortversion', - 'html4tags', - ); - if ($cli_opts{'version'}) { # Version info - print "\nThis is Markdown, version $VERSION.\n"; - print "Copyright 2004 John Gruber\n"; - print "http://daringfireball.net/projects/markdown/\n\n"; - exit 0; - } - if ($cli_opts{'shortversion'}) { # Just the version number string. - print $VERSION; - exit 0; - } - if ($cli_opts{'html4tags'}) { # Use HTML tag style instead of XHTML - $g_empty_element_suffix = ">"; - } - - - #### Process incoming text: ########################### - my $text; - { - local $/; # Slurp the whole file - $text = <>; - } - print <<'EOT'; - -EOT - print "
"; - print Markdown($text); - print "
"; - } -} - - - -sub Markdown { -# -# Main function. The order in which other subs are called here is -# essential. Link and image substitutions need to happen before -# _EscapeSpecialChars(), so that any *'s or _'s in the -# and tags get encoded. -# - my $text = shift; - - # Clear the global hashes. If we don't clear these, you get conflicts - # from other articles when generating a page which contains more than - # one article (e.g. an index page that shows the N most recent - # articles): - %g_urls = (); - %g_titles = (); - %g_html_blocks = (); - - - # Standardize line endings: - $text =~ s{\r\n}{\n}g; # DOS to Unix - $text =~ s{\r}{\n}g; # Mac to Unix - - # Make sure $text ends with a couple of newlines: - $text .= "\n\n"; - - # Convert all tabs to spaces. - $text = _Detab($text); - - # Strip any lines consisting only of spaces and tabs. - # This makes subsequent regexen easier to write, because we can - # match consecutive blank lines with /\n+/ instead of something - # contorted like /[ \t]*\n+/ . - $text =~ s/^[ \t]+$//mg; - - # Turn block-level HTML blocks into hash entries - $text = _HashHTMLBlocks($text); - - # Strip link definitions, store in hashes. - $text = _StripLinkDefinitions($text); - - $text = _RunBlockGamut($text); - - $text = _UnescapeSpecialChars($text); - - return $text . "\n"; -} - - -sub _StripLinkDefinitions { -# -# Strips link definitions from text, stores the URLs and titles in -# hash references. -# - my $text = shift; - my $less_than_tab = $g_tab_width - 1; - - # Link defs are in the form: ^[id]: url "optional title" - while ($text =~ s{ - ^[ ]{0,$less_than_tab}\[(.+)\]: # id = $1 - [ \t]* - \n? # maybe *one* newline - [ \t]* - ? # url = $2 - [ \t]* - \n? # maybe one newline - [ \t]* - (?: - (?<=\s) # lookbehind for whitespace - ["(] - (.+?) # title = $3 - [")] - [ \t]* - )? # title is optional - (?:\n+|\Z) - } - {}mx) { - $g_urls{lc $1} = _EncodeAmpsAndAngles( $2 ); # Link IDs are case-insensitive - if ($3) { - $g_titles{lc $1} = $3; - $g_titles{lc $1} =~ s/"/"/g; - } - } - - return $text; -} - - -sub _HashHTMLBlocks { - my $text = shift; - my $less_than_tab = $g_tab_width - 1; - - # Hashify HTML blocks: - # We only want to do this for block-level HTML tags, such as headers, - # lists, and tables. That's because we still want to wrap

s around - # "paragraphs" that are wrapped in non-block-level tags, such as anchors, - # phrase emphasis, and spans. The list of tags we're looking for is - # hard-coded: - my $block_tags_a = qr/p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del/; - my $block_tags_b = qr/p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math/; - - # First, look for nested blocks, e.g.: - #

- #
- # tags for inner block must be indented. - #
- #
- # - # The outermost tags must start at the left margin for this to match, and - # the inner nested divs must be indented. - # We need to do this before the next, more liberal match, because the next - # match will start at the first `
` and stop at the first `
`. - $text =~ s{ - ( # save in $1 - ^ # start of line (with /m) - <($block_tags_a) # start tag = $2 - \b # word break - (.*\n)*? # any number of lines, minimally matching - # the matching end tag - [ \t]* # trailing spaces/tabs - (?=\n+|\Z) # followed by a newline or end of document - ) - }{ - my $key = md5_hex($1); - $g_html_blocks{$key} = $1; - "\n\n" . $key . "\n\n"; - }egmx; - - - # - # Now match more liberally, simply from `\n` to `\n` - # - $text =~ s{ - ( # save in $1 - ^ # start of line (with /m) - <($block_tags_b) # start tag = $2 - \b # word break - (.*\n)*? # any number of lines, minimally matching - .* # the matching end tag - [ \t]* # trailing spaces/tabs - (?=\n+|\Z) # followed by a newline or end of document - ) - }{ - my $key = md5_hex($1); - $g_html_blocks{$key} = $1; - "\n\n" . $key . "\n\n"; - }egmx; - # Special case just for
. It was easier to make a special case than - # to make the other regex more complicated. - $text =~ s{ - (?: - (?<=\n\n) # Starting after a blank line - | # or - \A\n? # the beginning of the doc - ) - ( # save in $1 - [ ]{0,$less_than_tab} - <(hr) # start tag = $2 - \b # word break - ([^<>])*? # - /?> # the matching end tag - [ \t]* - (?=\n{2,}|\Z) # followed by a blank line or end of document - ) - }{ - my $key = md5_hex($1); - $g_html_blocks{$key} = $1; - "\n\n" . $key . "\n\n"; - }egx; - - # Special case for standalone HTML comments: - $text =~ s{ - (?: - (?<=\n\n) # Starting after a blank line - | # or - \A\n? # the beginning of the doc - ) - ( # save in $1 - [ ]{0,$less_than_tab} - (?s: - - ) - [ \t]* - (?=\n{2,}|\Z) # followed by a blank line or end of document - ) - }{ - my $key = md5_hex($1); - $g_html_blocks{$key} = $1; - "\n\n" . $key . "\n\n"; - }egx; - - - return $text; -} - - -sub _RunBlockGamut { -# -# These are all the transformations that form block-level -# tags like paragraphs, headers, and list items. -# - my $text = shift; - - $text = _DoHeaders($text); - - # Do Horizontal Rules: - $text =~ s{^[ ]{0,2}([ ]?\*[ ]?){3,}[ \t]*$}{\n tags around block-level tags. - $text = _HashHTMLBlocks($text); - - $text = _FormParagraphs($text); - - return $text; -} - - -sub _RunSpanGamut { -# -# These are all the transformations that occur *within* block-level -# tags like paragraphs, headers, and list items. -# - my $text = shift; - - $text = _DoCodeSpans($text); - - $text = _EscapeSpecialChars($text); - - # Process anchor and image tags. Images must come first, - # because ![foo][f] looks like an anchor. - $text = _DoImages($text); - $text = _DoAnchors($text); - - # Make links out of things like `` - # Must come after _DoAnchors(), because you can use < and > - # delimiters in inline links like [this](). - $text = _DoAutoLinks($text); - - $text = _EncodeAmpsAndAngles($text); - - $text = _DoItalicsAndBold($text); - - # Do hard breaks: - $text =~ s/ {2,}\n/ or tags. -# my $tags_to_skip = qr!<(/?)(?:pre|code|kbd|script|math)[\s>]!; - - foreach my $cur_token (@$tokens) { - if ($cur_token->[0] eq "tag") { - # Within tags, encode * and _ so they don't conflict - # with their use in Markdown for italics and strong. - # We're replacing each such character with its - # corresponding MD5 checksum value; this is likely - # overkill, but it should prevent us from colliding - # with the escape values by accident. - $cur_token->[1] =~ s! \* !$g_escape_table{'*'}!gx; - $cur_token->[1] =~ s! _ !$g_escape_table{'_'}!gx; - $text .= $cur_token->[1]; - } else { - my $t = $cur_token->[1]; - $t = _EncodeBackslashEscapes($t); - $text .= $t; - } - } - return $text; -} - - -sub _DoAnchors { -# -# Turn Markdown link shortcuts into XHTML
tags. -# - my $text = shift; - - # - # First, handle reference-style links: [link text] [id] - # - $text =~ s{ - ( # wrap whole match in $1 - \[ - ($g_nested_brackets) # link text = $2 - \] - - [ ]? # one optional space - (?:\n[ ]*)? # one optional newline followed by spaces - - \[ - (.*?) # id = $3 - \] - ) - }{ - my $result; - my $whole_match = $1; - my $link_text = $2; - my $link_id = lc $3; - - if ($link_id eq "") { - $link_id = lc $link_text; # for shortcut links like [this][]. - } - - if (defined $g_urls{$link_id}) { - my $url = $g_urls{$link_id}; - $url =~ s! \* !$g_escape_table{'*'}!gx; # We've got to encode these to avoid - $url =~ s! _ !$g_escape_table{'_'}!gx; # conflicting with italics/bold. - $result = "? # href = $3 - [ \t]* - ( # $4 - (['"]) # quote char = $5 - (.*?) # Title = $6 - \5 # matching quote - )? # title is optional - \) - ) - }{ - my $result; - my $whole_match = $1; - my $link_text = $2; - my $url = $3; - my $title = $6; - - $url =~ s! \* !$g_escape_table{'*'}!gx; # We've got to encode these to avoid - $url =~ s! _ !$g_escape_table{'_'}!gx; # conflicting with italics/bold. - $result = " tags. -# - my $text = shift; - - # - # First, handle reference-style labeled images: ![alt text][id] - # - $text =~ s{ - ( # wrap whole match in $1 - !\[ - (.*?) # alt text = $2 - \] - - [ ]? # one optional space - (?:\n[ ]*)? # one optional newline followed by spaces - - \[ - (.*?) # id = $3 - \] - - ) - }{ - my $result; - my $whole_match = $1; - my $alt_text = $2; - my $link_id = lc $3; - - if ($link_id eq "") { - $link_id = lc $alt_text; # for shortcut links like ![this][]. - } - - $alt_text =~ s/"/"/g; - if (defined $g_urls{$link_id}) { - my $url = $g_urls{$link_id}; - $url =~ s! \* !$g_escape_table{'*'}!gx; # We've got to encode these to avoid - $url =~ s! _ !$g_escape_table{'_'}!gx; # conflicting with italics/bold. - $result = "\"$alt_text\"";? # src url = $3 - [ \t]* - ( # $4 - (['"]) # quote char = $5 - (.*?) # title = $6 - \5 # matching quote - [ \t]* - )? # title is optional - \) - ) - }{ - my $result; - my $whole_match = $1; - my $alt_text = $2; - my $url = $3; - my $title = ''; - if (defined($6)) { - $title = $6; - } - - $alt_text =~ s/"/"/g; - $title =~ s/"/"/g; - $url =~ s! \* !$g_escape_table{'*'}!gx; # We've got to encode these to avoid - $url =~ s! _ !$g_escape_table{'_'}!gx; # conflicting with italics/bold. - $result = "\"$alt_text\"";" . _RunSpanGamut($1) . "\n\n"; - }egmx; - - $text =~ s{ ^(.+)[ \t]*\n-+[ \t]*\n+ }{ - "

" . _RunSpanGamut($1) . "

\n\n"; - }egmx; - - - # atx-style headers: - # # Header 1 - # ## Header 2 - # ## Header 2 with closing hashes ## - # ... - # ###### Header 6 - # - $text =~ s{ - ^(\#{1,6}) # $1 = string of #'s - [ \t]* - (.+?) # $2 = Header text - [ \t]* - \#* # optional closing #'s (not counted) - \n+ - }{ - my $h_level = length($1); - "" . _RunSpanGamut($2) . "\n\n"; - }egmx; - - return $text; -} - - -sub _DoLists { -# -# Form HTML ordered (numbered) and unordered (bulleted) lists. -# - my $text = shift; - my $less_than_tab = $g_tab_width - 1; - - # Re-usable patterns to match list item bullets and number markers: - my $marker_ul = qr/[*+-]/; - my $marker_ol = qr/\d+[.]/; - my $marker_any = qr/(?:$marker_ul|$marker_ol)/; - - # Re-usable pattern to match any entirel ul or ol list: - my $whole_list = qr{ - ( # $1 = whole list - ( # $2 - [ ]{0,$less_than_tab} - (${marker_any}) # $3 = first list item marker - [ \t]+ - ) - (?s:.+?) - ( # $4 - \z - | - \n{2,} - (?=\S) - (?! # Negative lookahead for another list item marker - [ \t]* - ${marker_any}[ \t]+ - ) - ) - ) - }mx; - - # We use a different prefix before nested lists than top-level lists. - # See extended comment in _ProcessListItems(). - # - # Note: There's a bit of duplication here. My original implementation - # created a scalar regex pattern as the conditional result of the test on - # $g_list_level, and then only ran the $text =~ s{...}{...}egmx - # substitution once, using the scalar as the pattern. This worked, - # everywhere except when running under MT on my hosting account at Pair - # Networks. There, this caused all rebuilds to be killed by the reaper (or - # perhaps they crashed, but that seems incredibly unlikely given that the - # same script on the same server ran fine *except* under MT. I've spent - # more time trying to figure out why this is happening than I'd like to - # admit. My only guess, backed up by the fact that this workaround works, - # is that Perl optimizes the substition when it can figure out that the - # pattern will never change, and when this optimization isn't on, we run - # afoul of the reaper. Thus, the slightly redundant code to that uses two - # static s/// patterns rather than one conditional pattern. - - if ($g_list_level) { - $text =~ s{ - ^ - $whole_list - }{ - my $list = $1; - my $list_type = ($3 =~ m/$marker_ul/) ? "ul" : "ol"; - # Turn double returns into triple returns, so that we can make a - # paragraph for the last item in a list, if necessary: - $list =~ s/\n{2,}/\n\n\n/g; - my $result = _ProcessListItems($list, $marker_any); - $result = "<$list_type>\n" . $result . "\n"; - $result; - }egmx; - } - else { - $text =~ s{ - (?:(?<=\n\n)|\A\n?) - $whole_list - }{ - my $list = $1; - my $list_type = ($3 =~ m/$marker_ul/) ? "ul" : "ol"; - # Turn double returns into triple returns, so that we can make a - # paragraph for the last item in a list, if necessary: - $list =~ s/\n{2,}/\n\n\n/g; - my $result = _ProcessListItems($list, $marker_any); - $result = "<$list_type>\n" . $result . "\n"; - $result; - }egmx; - } - - - return $text; -} - - -sub _ProcessListItems { -# -# Process the contents of a single ordered or unordered list, splitting it -# into individual list items. -# - - my $list_str = shift; - my $marker_any = shift; - - - # The $g_list_level global keeps track of when we're inside a list. - # Each time we enter a list, we increment it; when we leave a list, - # we decrement. If it's zero, we're not in a list anymore. - # - # We do this because when we're not inside a list, we want to treat - # something like this: - # - # I recommend upgrading to version - # 8. Oops, now this line is treated - # as a sub-list. - # - # As a single paragraph, despite the fact that the second line starts - # with a digit-period-space sequence. - # - # Whereas when we're inside a list (or sub-list), that line will be - # treated as the start of a sub-list. What a kludge, huh? This is - # an aspect of Markdown's syntax that's hard to parse perfectly - # without resorting to mind-reading. Perhaps the solution is to - # change the syntax rules such that sub-lists must start with a - # starting cardinal number; e.g. "1." or "a.". - - $g_list_level++; - - # trim trailing blank lines: - $list_str =~ s/\n{2,}\z/\n/; - - - $list_str =~ s{ - (\n)? # leading line = $1 - (^[ \t]*) # leading whitespace = $2 - ($marker_any) [ \t]+ # list marker = $3 - ((?s:.+?) # list item text = $4 - (\n{1,2})) - (?= \n* (\z | \2 ($marker_any) [ \t]+)) - }{ - my $item = $4; - my $leading_line = $1; - my $leading_space = $2; - - if ($leading_line or ($item =~ m/\n{2,}/)) { - $item = _RunBlockGamut(_Outdent($item)); - } - else { - # Recursion for sub-lists: - $item = _DoLists(_Outdent($item)); - chomp $item; - $item = _RunSpanGamut($item); - } - - "
  • " . $item . "
  • \n"; - }egmx; - - $g_list_level--; - return $list_str; -} - - - -sub _DoCodeBlocks { -# -# Process Markdown `
    ` blocks.
    -#
    -
    -	my $text = shift;
    -
    -	$text =~ s{
    -			(?:\n\n|\A)
    -			(	            # $1 = the code block -- one or more lines, starting with a space/tab
    -			  (?:
    -			    (?:[ ]{$g_tab_width} | \t)  # Lines must start with a tab or a tab-width of spaces
    -			    .*\n+
    -			  )+
    -			)
    -			((?=^[ ]{0,$g_tab_width}\S)|\Z)	# Lookahead for non-space at line-start, or end of doc
    -		}{
    -			my $codeblock = $1;
    -			my $result; # return value
    -
    -			$codeblock = _EncodeCode(_Outdent($codeblock));
    -			$codeblock = _Detab($codeblock);
    -			$codeblock =~ s/\A\n+//; # trim leading newlines
    -			$codeblock =~ s/\s+\z//; # trim trailing whitespace
    -
    -			$result = "\n\n
    " . $codeblock . "\n
    \n\n"; - - $result; - }egmx; - - return $text; -} - - -sub _DoCodeSpans { -# -# * Backtick quotes are used for spans. -# -# * You can use multiple backticks as the delimiters if you want to -# include literal backticks in the code span. So, this input: -# -# Just type ``foo `bar` baz`` at the prompt. -# -# Will translate to: -# -#

    Just type foo `bar` baz at the prompt.

    -# -# There's no arbitrary limit to the number of backticks you -# can use as delimters. If you need three consecutive backticks -# in your code, use four for delimiters, etc. -# -# * You can use spaces to get literal backticks at the edges: -# -# ... type `` `bar` `` ... -# -# Turns to: -# -# ... type `bar` ... -# - - my $text = shift; - - $text =~ s@ - (`+) # $1 = Opening run of ` - (.+?) # $2 = The code block - (?$c
    "; - @egsx; - - return $text; -} - - -sub _EncodeCode { -# -# Encode/escape certain characters inside Markdown code runs. -# The point is that in code, these characters are literals, -# and lose their special Markdown meanings. -# - local $_ = shift; - - # Encode all ampersands; HTML entities are not - # entities within a Markdown code span. - s/&/&/g; - - # Encode $'s, but only if we're running under Blosxom. - # (Blosxom interpolates Perl variables in article bodies.) - { - no warnings 'once'; - if (defined($blosxom::version)) { - s/\$/$/g; - } - } - - - # Do the angle bracket song and dance: - s! < !<!gx; - s! > !>!gx; - - # Now, escape characters that are magic in Markdown: - s! \* !$g_escape_table{'*'}!gx; - s! _ !$g_escape_table{'_'}!gx; - s! { !$g_escape_table{'{'}!gx; - s! } !$g_escape_table{'}'}!gx; - s! \[ !$g_escape_table{'['}!gx; - s! \] !$g_escape_table{']'}!gx; - s! \\ !$g_escape_table{'\\'}!gx; - - return $_; -} - - -sub _DoItalicsAndBold { - my $text = shift; - - # must go first: - $text =~ s{ (\*\*|__) (?=\S) (.+?[*_]*) (?<=\S) \1 } - {$2}gsx; - - $text =~ s{ (\*|_) (?=\S) (.+?) (?<=\S) \1 } - {$2}gsx; - - return $text; -} - - -sub _DoBlockQuotes { - my $text = shift; - - $text =~ s{ - ( # Wrap whole match in $1 - ( - ^[ \t]*>[ \t]? # '>' at the start of a line - .+\n # rest of the first line - (.+\n)* # subsequent consecutive lines - \n* # blanks - )+ - ) - }{ - my $bq = $1; - $bq =~ s/^[ \t]*>[ \t]?//gm; # trim one level of quoting - $bq =~ s/^[ \t]+$//mg; # trim whitespace-only lines - $bq = _RunBlockGamut($bq); # recurse - - $bq =~ s/^/ /g; - # These leading spaces screw with
     content, so we need to fix that:
    -			$bq =~ s{
    -					(\s*
    .+?
    ) - }{ - my $pre = $1; - $pre =~ s/^ //mg; - $pre; - }egsx; - - "
    \n$bq\n
    \n\n"; - }egmx; - - - return $text; -} - - -sub _FormParagraphs { -# -# Params: -# $text - string to process with html

    tags -# - my $text = shift; - - # Strip leading and trailing lines: - $text =~ s/\A\n+//; - $text =~ s/\n+\z//; - - my @grafs = split(/\n{2,}/, $text); - - # - # Wrap

    tags. - # - foreach (@grafs) { - unless (defined( $g_html_blocks{$_} )) { - $_ = _RunSpanGamut($_); - s/^([ \t]*)/

    /; - $_ .= "

    "; - } - } - - # - # Unhashify HTML blocks - # - foreach (@grafs) { - if (defined( $g_html_blocks{$_} )) { - $_ = $g_html_blocks{$_}; - } - } - - return join "\n\n", @grafs; -} - - -sub _EncodeAmpsAndAngles { -# Smart processing for ampersands and angle brackets that need to be encoded. - - my $text = shift; - - # Ampersand-encoding based entirely on Nat Irons's Amputator MT plugin: - # http://bumppo.net/projects/amputator/ - $text =~ s/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/&/g; - - # Encode naked <'s - $text =~ s{<(?![a-z/?\$!])}{<}gi; - - return $text; -} - - -sub _EncodeBackslashEscapes { -# -# Parameter: String. -# Returns: The string, with after processing the following backslash -# escape sequences. -# - local $_ = shift; - - s! \\\\ !$g_escape_table{'\\'}!gx; # Must process escaped backslashes first. - s! \\` !$g_escape_table{'`'}!gx; - s! \\\* !$g_escape_table{'*'}!gx; - s! \\_ !$g_escape_table{'_'}!gx; - s! \\\{ !$g_escape_table{'{'}!gx; - s! \\\} !$g_escape_table{'}'}!gx; - s! \\\[ !$g_escape_table{'['}!gx; - s! \\\] !$g_escape_table{']'}!gx; - s! \\\( !$g_escape_table{'('}!gx; - s! \\\) !$g_escape_table{')'}!gx; - s! \\> !$g_escape_table{'>'}!gx; - s! \\\# !$g_escape_table{'#'}!gx; - s! \\\+ !$g_escape_table{'+'}!gx; - s! \\\- !$g_escape_table{'-'}!gx; - s! \\\. !$g_escape_table{'.'}!gx; - s{ \\! }{$g_escape_table{'!'}}gx; - - return $_; -} - - -sub _DoAutoLinks { - my $text = shift; - - $text =~ s{<((https?|ftp):[^'">\s]+)>}{
    $1}gi; - - # Email addresses: - $text =~ s{ - < - (?:mailto:)? - ( - [-.\w]+ - \@ - [-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+ - ) - > - }{ - _EncodeEmailAddress( _UnescapeSpecialChars($1) ); - }egix; - - return $text; -} - - -sub _EncodeEmailAddress { -# -# Input: an email address, e.g. "foo@example.com" -# -# Output: the email address as a mailto link, with each character -# of the address encoded as either a decimal or hex entity, in -# the hopes of foiling most address harvesting spam bots. E.g.: -# -# foo -# @example.com -# -# Based on a filter by Matthew Wickline, posted to the BBEdit-Talk -# mailing list: -# - - my $addr = shift; - - srand; - my @encode = ( - sub { '&#' . ord(shift) . ';' }, - sub { '&#x' . sprintf( "%X", ord(shift) ) . ';' }, - sub { shift }, - ); - - $addr = "mailto:" . $addr; - - $addr =~ s{(.)}{ - my $char = $1; - if ( $char eq '@' ) { - # this *must* be encoded. I insist. - $char = $encode[int rand 1]->($char); - } elsif ( $char ne ':' ) { - # leave ':' alone (to spot mailto: later) - my $r = rand; - # roughly 10% raw, 45% hex, 45% dec - $char = ( - $r > .9 ? $encode[2]->($char) : - $r < .45 ? $encode[1]->($char) : - $encode[0]->($char) - ); - } - $char; - }gex; - - $addr = qq{$addr}; - $addr =~ s{">.+?:}{">}; # strip the mailto: from the visible part - - return $addr; -} - - -sub _UnescapeSpecialChars { -# -# Swap back in all the special characters we've hidden. -# - my $text = shift; - - while( my($char, $hash) = each(%g_escape_table) ) { - $text =~ s/$hash/$char/g; - } - return $text; -} - - -sub _TokenizeHTML { -# -# Parameter: String containing HTML markup. -# Returns: Reference to an array of the tokens comprising the input -# string. Each token is either a tag (possibly with nested, -# tags contained therein, such as , or a -# run of text between tags. Each element of the array is a -# two-element array; the first is either 'tag' or 'text'; -# the second is the actual value. -# -# -# Derived from the _tokenize() subroutine from Brad Choate's MTRegex plugin. -# -# - - my $str = shift; - my $pos = 0; - my $len = length $str; - my @tokens; - - my $depth = 6; - my $nested_tags = join('|', ('(?:<[a-z/!$](?:[^<>]') x $depth) . (')*>)' x $depth); - my $match = qr/(?s: ) | # comment - (?s: <\? .*? \?> ) | # processing instruction - $nested_tags/ix; # nested tags - - while ($str =~ m/($match)/g) { - my $whole_tag = $1; - my $sec_start = pos $str; - my $tag_start = $sec_start - length $whole_tag; - if ($pos < $tag_start) { - push @tokens, ['text', substr($str, $pos, $tag_start - $pos)]; - } - push @tokens, ['tag', $whole_tag]; - $pos = pos $str; - } - push @tokens, ['text', substr($str, $pos, $len - $pos)] if $pos < $len; - \@tokens; -} - - -sub _Outdent { -# -# Remove one level of line-leading tabs or spaces -# - my $text = shift; - - $text =~ s/^(\t|[ ]{1,$g_tab_width})//gm; - return $text; -} - - -sub _Detab { -# -# Cribbed from a post by Bart Lateur: -# -# - my $text = shift; - - $text =~ s{(.*?)\t}{$1.(' ' x ($g_tab_width - length($1) % $g_tab_width))}ge; - return $text; -} - - -1; - -__END__ - - -=pod - -=head1 NAME - -B - - -=head1 SYNOPSIS - -B [ B<--html4tags> ] [ B<--version> ] [ B<-shortversion> ] - [ I ... ] - - -=head1 DESCRIPTION - -Markdown is a text-to-HTML filter; it translates an easy-to-read / -easy-to-write structured text format into HTML. Markdown's text format -is most similar to that of plain text email, and supports features such -as headers, *emphasis*, code blocks, blockquotes, and links. - -Markdown's syntax is designed not as a generic markup language, but -specifically to serve as a front-end to (X)HTML. You can use span-level -HTML tags anywhere in a Markdown document, and you can use block level -HTML tags (like
    and as well). - -For more information about Markdown's syntax, see: - - http://daringfireball.net/projects/markdown/ - - -=head1 OPTIONS - -Use "--" to end switch parsing. For example, to open a file named "-z", use: - - Markdown.pl -- -z - -=over 4 - - -=item B<--html4tags> - -Use HTML 4 style for empty element tags, e.g.: - -
    - -instead of Markdown's default XHTML style tags, e.g.: - -
    - - -=item B<-v>, B<--version> - -Display Markdown's version number and copyright information. - - -=item B<-s>, B<--shortversion> - -Display the short-form version number. - - -=back - - - -=head1 BUGS - -To file bug reports or feature requests (other than topics listed in the -Caveats section above) please send email to: - - support@daringfireball.net - -Please include with your report: (1) the example input; (2) the output -you expected; (3) the output Markdown actually produced. - - -=head1 VERSION HISTORY - -See the readme file for detailed release notes for this version. - -1.0.1 - 14 Dec 2004 - -1.0 - 28 Aug 2004 - - -=head1 AUTHOR - - John Gruber - http://daringfireball.net - - PHP port and other contributions by Michel Fortin - http://michelf.com - - -=head1 COPYRIGHT AND LICENSE - -Copyright (c) 2003-2004 John Gruber - -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - -* Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - -* Neither the name "Markdown" nor the names of its contributors may - be used to endorse or promote products derived from this software - without specific prior written permission. - -This software is provided by the copyright holders and contributors "as -is" and any express or implied warranties, including, but not limited -to, the implied warranties of merchantability and fitness for a -particular purpose are disclaimed. In no event shall the copyright owner -or contributors be liable for any direct, indirect, incidental, special, -exemplary, or consequential damages (including, but not limited to, -procurement of substitute goods or services; loss of use, data, or -profits; or business interruption) however caused and on any theory of -liability, whether in contract, strict liability, or tort (including -negligence or otherwise) arising in any way out of the use of this -software, even if advised of the possibility of such damage. - -=cut diff --git a/filters/html-converters/resources/rst-template.txt b/filters/html-converters/resources/rst-template.txt deleted file mode 100644 index 43cde42..0000000 --- a/filters/html-converters/resources/rst-template.txt +++ /dev/null @@ -1,4 +0,0 @@ -%(stylesheet)s -%(body_pre_docinfo)s -%(docinfo)s -%(body)s diff --git a/filters/html-converters/rst2html b/filters/html-converters/rst2html index c51f5be..756a4e1 100755 --- a/filters/html-converters/rst2html +++ b/filters/html-converters/rst2html @@ -1,2 +1,2 @@ -#!/bin/sh -rst2html.py --template="$(dirname $0)/resources/rst-template.txt" +#!/bin/bash +rst2html.py --template <(echo -e "%(stylesheet)s\n%(body_pre_docinfo)s\n%(docinfo)s\n%(body)s") From 7ef1a47991fee31c1eb1e1292bf715d577042f35 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Fri, 9 Oct 2015 14:55:47 +0200 Subject: [PATCH 091/387] ui-repolist: fix resource leak: free before return Coverity-id: 13931 Signed-off-by: Christian Hesse --- ui-repolist.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ui-repolist.c b/ui-repolist.c index ac1b3e3..4f52e0f 100644 --- a/ui-repolist.c +++ b/ui-repolist.c @@ -18,8 +18,10 @@ static time_t read_agefile(char *path) char *buf; struct strbuf date_buf = STRBUF_INIT; - if (readfile(path, &buf, &size)) + if (readfile(path, &buf, &size)) { + free(buf); return -1; + } if (parse_date(buf, &date_buf) == 0) result = strtoul(date_buf.buf, NULL, 10); From 51338f7658f81ffc120969108ed88d97c1888617 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Fri, 9 Oct 2015 14:55:48 +0200 Subject: [PATCH 092/387] ui-repolist: fix resource leak: free allocation from cgit_currenturl Coverity-id: 13930 Signed-off-by: Christian Hesse --- ui-repolist.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ui-repolist.c b/ui-repolist.c index 4f52e0f..a2e9e07 100644 --- a/ui-repolist.c +++ b/ui-repolist.c @@ -108,14 +108,16 @@ static int is_in_url(struct cgit_repo *repo) static void print_sort_header(const char *title, const char *sort) { + char *currenturl = cgit_currenturl(); html("", title); + free(currenturl); } static void print_header(void) From 979db79a80f1926c677691b68eb22b4852a77b50 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Fri, 9 Oct 2015 14:55:49 +0200 Subject: [PATCH 093/387] ui-plain: fix resource leak: free before return Coverity-id: 13940 Signed-off-by: Christian Hesse --- ui-plain.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ui-plain.c b/ui-plain.c index 0dd1a8b..4c73607 100644 --- a/ui-plain.c +++ b/ui-plain.c @@ -51,6 +51,7 @@ static int print_object(const unsigned char *sha1, const char *path) cgit_print_http_headers(); html_raw(buf, size); free(mimetype); + free(buf); return 1; } From 08a2b818f2bd3221a1685c28c62408d57b0993a7 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Fri, 9 Oct 2015 14:55:50 +0200 Subject: [PATCH 094/387] ui-plain: fix resource leak: free before assigning NULL Coverity-id: 13939 Signed-off-by: Christian Hesse --- ui-plain.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ui-plain.c b/ui-plain.c index 4c73607..e4beb99 100644 --- a/ui-plain.c +++ b/ui-plain.c @@ -84,8 +84,10 @@ static void print_dir(const unsigned char *sha1, const char *base, slash = strrchr(fullpath, '/'); if (slash) *(slash + 1) = 0; - else + else { + free(fullpath); fullpath = NULL; + } html("
  • "); cgit_plain_link("../", NULL, NULL, ctx.qry.head, ctx.qry.sha1, fullpath); From 30802126d48e145191a281a7f43109edfbcf490f Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Sat, 10 Oct 2015 16:56:24 +0200 Subject: [PATCH 095/387] ui-blob: fix resource leak: free before return Coverity-id: 13943 Signed-off-by: Christian Hesse --- ui-blob.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ui-blob.c b/ui-blob.c index d3c3a10..70a671e 100644 --- a/ui-blob.c +++ b/ui-blob.c @@ -99,6 +99,7 @@ int cgit_print_file(char *path, const char *head, int file_only) return -1; buf[size] = '\0'; html_raw(buf, size); + free(buf); return 0; } From 7320bfa893bdb8ff873c3827c3dac1ce0d4034ea Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Sat, 10 Oct 2015 16:56:23 +0200 Subject: [PATCH 096/387] ui-blob: fix resource leak: free before return Coverity-id: 13944 Signed-off-by: Christian Hesse --- ui-blob.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ui-blob.c b/ui-blob.c index 70a671e..1ded839 100644 --- a/ui-blob.c +++ b/ui-blob.c @@ -171,4 +171,5 @@ void cgit_print_blob(const char *hex, char *path, const char *head, int file_onl ctx.page.filename = path; cgit_print_http_headers(); html_raw(buf, size); + free(buf); } From 97da17b783697b4c5430f130ab449121d0692530 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Sat, 10 Oct 2015 16:56:25 +0200 Subject: [PATCH 097/387] ui-atom: fix resource leak: free allocation from cgit_repourl Coverity-id: 13947 Signed-off-by: Christian Hesse --- ui-atom.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ui-atom.c b/ui-atom.c index e2b39ee..d7138fb 100644 --- a/ui-atom.c +++ b/ui-atom.c @@ -125,11 +125,13 @@ void cgit_print_atom(char *tip, char *path, int max_count) html_txt(ctx.repo->desc); html("\n"); if (host) { + char *repourl = cgit_repourl(ctx.repo->url); html("\n"); + free(repourl); } while ((commit = get_revision(&rev)) != NULL) { add_entry(commit, host); From 144e3c6085cfea95868a799ee976ed221dd86d8a Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Sat, 10 Oct 2015 16:56:26 +0200 Subject: [PATCH 098/387] ui-atom: fix resource leak: free before return Coverity-id: 13946 Signed-off-by: Christian Hesse --- ui-atom.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ui-atom.c b/ui-atom.c index d7138fb..fab4b0f 100644 --- a/ui-atom.c +++ b/ui-atom.c @@ -80,7 +80,7 @@ static void add_entry(struct commit *commit, const char *host) void cgit_print_atom(char *tip, char *path, int max_count) { - const char *host; + char *host; const char *argv[] = {NULL, tip, NULL, NULL, NULL}; struct commit *commit; struct rev_info rev; @@ -140,4 +140,5 @@ void cgit_print_atom(char *tip, char *path, int max_count) commit->parents = NULL; } html("\n"); + free(host); } From ed5dccbeaab5c8b30e1c2fe8890fa098537a2621 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Sat, 10 Oct 2015 16:56:27 +0200 Subject: [PATCH 099/387] ui-atom: fix resource leak: free allocation from cgit_pageurl Coverity-id: 13945 Signed-off-by: Christian Hesse --- ui-atom.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ui-atom.c b/ui-atom.c index fab4b0f..e186299 100644 --- a/ui-atom.c +++ b/ui-atom.c @@ -53,14 +53,17 @@ static void add_entry(struct commit *commit, const char *host) cgit_print_date(info->author_date, FMT_ATOMDATE, 0); html("\n"); if (host) { + char *pageurl; html("\n"); + free(pageurl); } htmlf("%s\n", hex); html("\n"); From 76dc7a3371e487fdc9de7b3b4c991fe370598f0e Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Sat, 10 Oct 2015 16:56:28 +0200 Subject: [PATCH 100/387] cache: fix resource leak: close file handle before return Coverity-id: 13910 Signed-off-by: Christian Hesse --- cache.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cache.c b/cache.c index 57c8918..b169d20 100644 --- a/cache.c +++ b/cache.c @@ -215,19 +215,25 @@ static int fill_slot(struct cache_slot *slot) return errno; /* Redirect stdout to lockfile */ - if (dup2(slot->lock_fd, STDOUT_FILENO) == -1) + if (dup2(slot->lock_fd, STDOUT_FILENO) == -1) { + close(tmp); return errno; + } /* Generate cache content */ slot->fn(); /* update stat info */ - if (fstat(slot->lock_fd, &slot->cache_st)) + if (fstat(slot->lock_fd, &slot->cache_st)) { + close(tmp); return errno; + } /* Restore stdout */ - if (dup2(tmp, STDOUT_FILENO) == -1) + if (dup2(tmp, STDOUT_FILENO) == -1) { + close(tmp); return errno; + } /* Close the temporary filedescriptor */ if (close(tmp)) From ccb4254104ad6faa9225ce91b9a0610f24958022 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 12 Oct 2015 16:42:48 +0200 Subject: [PATCH 101/387] md2html: use pure python Signed-off-by: Jason A. Donenfeld --- filters/html-converters/md2html | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/filters/html-converters/md2html b/filters/html-converters/md2html index 138713d..1488f48 100755 --- a/filters/html-converters/md2html +++ b/filters/html-converters/md2html @@ -1,5 +1,7 @@ -#!/bin/sh -cat <<_EOF +#!/usr/bin/env python +import markdown +import sys +print(''' -_EOF -echo "
    " -markdown_py -o html5 -echo "
    " +''') +print("
    ") +# Note: you may want to run this through bleach for sanitization +markdown.markdownFromFile(input=sys.stdin, output_format="html5") +print("
    ") From c301899112b2a0559e0f65e3b371a907e9e5c097 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 12 Oct 2015 16:47:47 +0200 Subject: [PATCH 102/387] filters: misc cleanups Signed-off-by: Jason A. Donenfeld --- filters/html-converters/man2html | 1 - filters/html-converters/rst2html | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/filters/html-converters/man2html b/filters/html-converters/man2html index 1b28437..0ef7884 100755 --- a/filters/html-converters/man2html +++ b/filters/html-converters/man2html @@ -2,4 +2,3 @@ echo "
    " groff -mandoc -T html -P -r -P -l | egrep -v '(||||||||" - diff --git a/filters/html-converters/rst2html b/filters/html-converters/rst2html index 756a4e1..02d90f8 100755 --- a/filters/html-converters/rst2html +++ b/filters/html-converters/rst2html @@ -1,2 +1,2 @@ #!/bin/bash -rst2html.py --template <(echo -e "%(stylesheet)s\n%(body_pre_docinfo)s\n%(docinfo)s\n%(body)s") +exec rst2html.py --template <(echo -e "%(stylesheet)s\n%(body_pre_docinfo)s\n%(docinfo)s\n%(body)s") From 3f9e14ada1e9cb3bb5b162f10f824336e3142440 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 12 Oct 2015 18:33:21 +0200 Subject: [PATCH 103/387] md2html: the default of stdin works fine Signed-off-by: Jason A. Donenfeld --- filters/html-converters/md2html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/filters/html-converters/md2html b/filters/html-converters/md2html index 1488f48..67141ba 100755 --- a/filters/html-converters/md2html +++ b/filters/html-converters/md2html @@ -1,6 +1,5 @@ #!/usr/bin/env python import markdown -import sys print(''' ') -highlight(data, lexer, formatter, outfile=sys.stdout) +sys.stdout.write(highlight(data, lexer, formatter, outfile=None)) From ffe09621f2626c692a16b249a52112ba8070aa79 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Thu, 12 Nov 2015 04:44:32 +0100 Subject: [PATCH 105/387] about-formatting.sh: comment text out of date --- filters/about-formatting.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/filters/about-formatting.sh b/filters/about-formatting.sh index d024204..85daf9c 100755 --- a/filters/about-formatting.sh +++ b/filters/about-formatting.sh @@ -3,7 +3,7 @@ # This may be used with the about-filter or repo.about-filter setting in cgitrc. # It passes formatting of about pages to differing programs, depending on the usage. -# Markdown support requires perl. +# Markdown support requires python and markdown-python. # RestructuredText support requires python and docutils. # Man page support requires groff. From 4458abf64172a62b92810c2293450106e6dfc763 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Tue, 24 Nov 2015 11:28:00 +0100 Subject: [PATCH 106/387] filter: avoid integer overflow in authenticate_post ctx.env.content_length is an unsigned int, coming from the CONTENT_LENGTH environment variable, which is parsed by strtoul. The HTTP/1.1 spec says that "any Content-Length greater than or equal to zero is a valid value." By storing this into an int, we potentially overflow it, resulting in the following bounding check failing, leading to a buffer overflow. Reported-by: Erik Cabetas Signed-off-by: Jason A. Donenfeld --- cgit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cgit.c b/cgit.c index 5937b9e..05e5d57 100644 --- a/cgit.c +++ b/cgit.c @@ -651,7 +651,7 @@ static inline void open_auth_filter(const char *function) static inline void authenticate_post(void) { char buffer[MAX_AUTHENTICATION_POST_BYTES]; - int len; + unsigned int len; open_auth_filter("authenticate-post"); len = ctx.env.content_length; From 6edc84bc44d55d7f90a40238ae2107913e15f54b Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 13 Jan 2016 00:45:03 +0100 Subject: [PATCH 107/387] ui-repolist: initialize char *buf to NULL readfile() can fail if the agefile is not readable. Make sure free() does not free an ininitialized string. Signed-off-by: Christian Hesse --- ui-repolist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui-repolist.c b/ui-repolist.c index a2e9e07..8d982c4 100644 --- a/ui-repolist.c +++ b/ui-repolist.c @@ -15,7 +15,7 @@ static time_t read_agefile(char *path) { time_t result; size_t size; - char *buf; + char *buf = NULL; struct strbuf date_buf = STRBUF_INIT; if (readfile(path, &buf, &size)) { From 559ab5ecc4445c8477ecf62c9fc97efa412dd562 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 5 Jan 2016 07:38:53 +0100 Subject: [PATCH 108/387] git: update to v2.7.0 Update to git version v2.7.0. * Upstream commit ed1c9977cb1b63e4270ad8bdf967a2d02580aa08 (Remove get_object_hash.) changed API: Convert all instances of get_object_hash to use an appropriate reference to the hash member of the oid member of struct object. This provides no functional change, as it is essentially a macro substitution. Signed-off-by: Christian Hesse --- Makefile | 2 +- git | 2 +- parsing.c | 4 ++-- shared.c | 4 ++-- ui-atom.c | 2 +- ui-clone.c | 2 +- ui-commit.c | 12 ++++++------ ui-diff.c | 6 +++--- ui-log.c | 12 ++++++------ ui-patch.c | 2 +- ui-plain.c | 2 +- ui-shared.c | 2 +- ui-tree.c | 2 +- 13 files changed, 27 insertions(+), 27 deletions(-) diff --git a/Makefile b/Makefile index 77b9f60..9bb9cd5 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = -GIT_VER = 2.6.1 +GIT_VER = 2.7.0 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.gz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index 22f698c..7548842 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 22f698cb188243b313e024d618283e0293e37140 +Subproject commit 754884255bb580df159e58defa81cdd30b5c430c diff --git a/parsing.c b/parsing.c index f903c7c..5283e58 100644 --- a/parsing.c +++ b/parsing.c @@ -139,7 +139,7 @@ struct commitinfo *cgit_parse_commit(struct commit *commit) return ret; if (!skip_prefix(p, "tree ", &p)) - die("Bad commit: %s", sha1_to_hex(commit->object.sha1)); + die("Bad commit: %s", oid_to_hex(&commit->object.oid)); p += sha1hex_len + 1; while (skip_prefix(p, "parent ", &p)) @@ -199,7 +199,7 @@ struct taginfo *cgit_parse_tag(struct tag *tag) const char *p; struct taginfo *ret = NULL; - data = read_sha1_file(tag->object.sha1, &type, &size); + data = read_sha1_file(tag->object.oid.hash, &type, &size); if (!data || type != OBJ_TAG) goto cleanup; diff --git a/shared.c b/shared.c index e216c64..42b2ddc 100644 --- a/shared.c +++ b/shared.c @@ -402,8 +402,8 @@ void cgit_diff_commit(struct commit *commit, filepair_fn fn, const char *prefix) unsigned char *old_sha1 = NULL; if (commit->parents) - old_sha1 = commit->parents->item->object.sha1; - cgit_diff_tree(old_sha1, commit->object.sha1, fn, prefix, + old_sha1 = commit->parents->item->object.oid.hash; + cgit_diff_tree(old_sha1, commit->object.oid.hash, fn, prefix, ctx.qry.ignorews); } diff --git a/ui-atom.c b/ui-atom.c index e186299..11ea0c0 100644 --- a/ui-atom.c +++ b/ui-atom.c @@ -19,7 +19,7 @@ static void add_entry(struct commit *commit, const char *host) struct commitinfo *info; info = cgit_parse_commit(commit); - hex = sha1_to_hex(commit->object.sha1); + hex = oid_to_hex(&commit->object.oid); html("\n"); html(""); html_txt(info->subject); diff --git a/ui-clone.c b/ui-clone.c index f7b0b04..5f6606a 100644 --- a/ui-clone.c +++ b/ui-clone.c @@ -24,7 +24,7 @@ static int print_ref_info(const char *refname, const struct object_id *oid, if (obj->type == OBJ_TAG) { if (!(obj = deref_tag(obj, refname, 0))) return 0; - htmlf("%s\t%s^{}\n", sha1_to_hex(obj->sha1), refname); + htmlf("%s\t%s^{}\n", oid_to_hex(&obj->oid), refname); } return 0; } diff --git a/ui-commit.c b/ui-commit.c index 2bca7a0..0c3d740 100644 --- a/ui-commit.c +++ b/ui-commit.c @@ -69,14 +69,14 @@ void cgit_print_commit(char *hex, const char *prefix) cgit_print_date(info->committer_date, FMT_LONGDATE, ctx.cfg.local_time); html("</td></tr>\n"); html("<tr><th>commit</th><td colspan='2' class='sha1'>"); - tmp = sha1_to_hex(commit->object.sha1); + tmp = oid_to_hex(&commit->object.oid); cgit_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp, prefix); html(" ("); cgit_patch_link("patch", NULL, NULL, NULL, tmp, prefix); html(")</td></tr>\n"); html("<tr><th>tree</th><td colspan='2' class='sha1'>"); tmp = xstrdup(hex); - cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL, + cgit_tree_link(oid_to_hex(&commit->tree->object.oid), NULL, NULL, ctx.qry.head, tmp, NULL); if (prefix) { html(" /"); @@ -85,7 +85,7 @@ void cgit_print_commit(char *hex, const char *prefix) free(tmp); html("</td></tr>\n"); for (p = commit->parents; p; p = p->next) { - parent = lookup_commit_reference(p->item->object.sha1); + parent = lookup_commit_reference(p->item->object.oid.hash); if (!parent) { html("<tr><td colspan='3'>"); cgit_print_error("Error reading parent commit"); @@ -94,7 +94,7 @@ void cgit_print_commit(char *hex, const char *prefix) } html("<tr><th>parent</th>" "<td colspan='2' class='sha1'>"); - tmp = tmp2 = sha1_to_hex(p->item->object.sha1); + tmp = tmp2 = oid_to_hex(&p->item->object.oid); if (ctx.repo->enable_subject_links) { parent_info = cgit_parse_commit(parent); tmp2 = parent_info->subject; @@ -102,7 +102,7 @@ void cgit_print_commit(char *hex, const char *prefix) cgit_commit_link(tmp2, NULL, NULL, ctx.qry.head, tmp, prefix); html(" ("); cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex, - sha1_to_hex(p->item->object.sha1), prefix); + oid_to_hex(&p->item->object.oid), prefix); html(")</td></tr>"); parents++; } @@ -135,7 +135,7 @@ void cgit_print_commit(char *hex, const char *prefix) } if (parents < 3) { if (parents) - tmp = sha1_to_hex(commit->parents->item->object.sha1); + tmp = oid_to_hex(&commit->parents->item->object.oid); else tmp = NULL; cgit_print_diff(ctx.qry.sha1, tmp, prefix, 0, 0); diff --git a/ui-diff.c b/ui-diff.c index 5d18296..52ed942 100644 --- a/ui-diff.c +++ b/ui-diff.c @@ -413,7 +413,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, "Bad commit: %s", sha1_to_hex(new_rev_sha1)); return; } - new_tree_sha1 = commit->tree->object.sha1; + new_tree_sha1 = commit->tree->object.oid.hash; if (old_rev) { if (get_sha1(old_rev, old_rev_sha1)) { @@ -422,7 +422,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, return; } } else if (commit->parents && commit->parents->item) { - hashcpy(old_rev_sha1, commit->parents->item->object.sha1); + hashcpy(old_rev_sha1, commit->parents->item->object.oid.hash); } else { hashclr(old_rev_sha1); } @@ -434,7 +434,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, "Bad commit: %s", sha1_to_hex(old_rev_sha1)); return; } - old_tree_sha1 = commit2->tree->object.sha1; + old_tree_sha1 = commit2->tree->object.oid.hash; } else { old_tree_sha1 = NULL; } diff --git a/ui-log.c b/ui-log.c index 0782478..4573255 100644 --- a/ui-log.c +++ b/ui-log.c @@ -82,14 +82,14 @@ void show_commit_decorations(struct commit *commit) goto next; strncpy(buf, deco->name + 13, sizeof(buf) - 1); cgit_log_link(buf, NULL, "remote-deco", NULL, - sha1_to_hex(commit->object.sha1), + oid_to_hex(&commit->object.oid), ctx.qry.vpath, 0, NULL, NULL, ctx.qry.showmsg, 0); } else { strncpy(buf, deco->name, sizeof(buf) - 1); cgit_commit_link(buf, NULL, "deco", ctx.qry.head, - sha1_to_hex(commit->object.sha1), + oid_to_hex(&commit->object.oid), ctx.qry.vpath); } next: @@ -148,8 +148,8 @@ static int show_commit(struct commit *commit, struct rev_info *revs) rem_lines = 0; DIFF_OPT_SET(&revs->diffopt, RECURSIVE); - diff_tree_sha1(parent->tree->object.sha1, - commit->tree->object.sha1, + diff_tree_sha1(parent->tree->object.oid.hash, + commit->tree->object.oid.hash, "", &revs->diffopt); diffcore_std(&revs->diffopt); @@ -233,7 +233,7 @@ static void print_commit(struct commit *commit, struct rev_info *revs) } } cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head, - sha1_to_hex(commit->object.sha1), ctx.qry.vpath); + oid_to_hex(&commit->object.oid), ctx.qry.vpath); show_commit_decorations(commit); html("</td><td>"); cgit_open_filter(ctx.repo->email_filter, info->author_email, "log"); @@ -269,7 +269,7 @@ static void print_commit(struct commit *commit, struct rev_info *revs) strbuf_addstr(&msgbuf, info->msg); strbuf_addch(&msgbuf, '\n'); } - format_display_notes(commit->object.sha1, + format_display_notes(commit->object.oid.hash, &msgbuf, PAGE_ENCODING, 0); strbuf_addch(&msgbuf, '\n'); strbuf_ltrim(&msgbuf); diff --git a/ui-patch.c b/ui-patch.c index 430231e..4c051e8 100644 --- a/ui-patch.c +++ b/ui-patch.c @@ -48,7 +48,7 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, return; } } else if (commit->parents && commit->parents->item) { - hashcpy(old_rev_sha1, commit->parents->item->object.sha1); + hashcpy(old_rev_sha1, commit->parents->item->object.oid.hash); } else { hashclr(old_rev_sha1); } diff --git a/ui-plain.c b/ui-plain.c index e4beb99..58addab 100644 --- a/ui-plain.c +++ b/ui-plain.c @@ -183,7 +183,7 @@ void cgit_print_plain(void) if (!path_items.match) { path_items.match = ""; walk_tree_ctx.match_baselen = -1; - print_dir(commit->tree->object.sha1, "", 0, ""); + print_dir(commit->tree->object.oid.hash, "", 0, ""); walk_tree_ctx.match = 2; } else diff --git a/ui-shared.c b/ui-shared.c index c04f380..48358cc 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -525,7 +525,7 @@ void cgit_object_link(struct object *obj) { char *page, *shortrev, *fullrev, *name; - fullrev = sha1_to_hex(obj->sha1); + fullrev = oid_to_hex(&obj->oid); shortrev = xstrdup(fullrev); shortrev[10] = '\0'; if (obj->type == OBJ_COMMIT) { diff --git a/ui-tree.c b/ui-tree.c index d71503d..3ff2320 100644 --- a/ui-tree.c +++ b/ui-tree.c @@ -287,7 +287,7 @@ void cgit_print_tree(const char *rev, char *path) walk_tree_ctx.curr_rev = xstrdup(rev); if (path == NULL) { - ls_tree(commit->tree->object.sha1, NULL, &walk_tree_ctx); + ls_tree(commit->tree->object.oid.hash, NULL, &walk_tree_ctx); goto cleanup; } From da1b89710f5eb25297a66613ff3130b2a31cb86a Mon Sep 17 00:00:00 2001 From: Lukas Fleischer <lfleischer@lfos.de> Date: Sun, 13 Dec 2015 01:27:13 +0100 Subject: [PATCH 109/387] Fix segmentation fault in hc() The ctx.qry.page variable might be unset at this point, e.g. when an invalid command is passed and cgit_print_pageheader() is called to show an error message. Signed-off-by: Lukas Fleischer <lfleischer@lfos.de> --- ui-shared.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ui-shared.c b/ui-shared.c index 48358cc..5b48734 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -889,6 +889,9 @@ void cgit_add_hidden_formfields(int incl_head, int incl_search, static const char *hc(const char *page) { + if (!ctx.qry.page) + return NULL; + return strcmp(ctx.qry.page, page) ? NULL : "active"; } From a4014d0dbfcab1de7293179966c9b7fcfcc7b925 Mon Sep 17 00:00:00 2001 From: Peter Colberg <peter@colberg.org> Date: Tue, 8 Dec 2015 12:53:08 -0500 Subject: [PATCH 110/387] ui-repolist: extract repo visibility criteria to separate function Signed-off-by: Peter Colberg <peter@colberg.org> --- ui-repolist.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/ui-repolist.c b/ui-repolist.c index 8d982c4..4912fa5 100644 --- a/ui-repolist.c +++ b/ui-repolist.c @@ -106,6 +106,15 @@ static int is_in_url(struct cgit_repo *repo) return 0; } +static int is_visible(struct cgit_repo *repo) +{ + if (repo->hide || repo->ignore) + return 0; + if (!(is_match(repo) && is_in_url(repo))) + return 0; + return 1; +} + static void print_sort_header(const char *title, const char *sort) { char *currenturl = cgit_currenturl(); @@ -278,9 +287,7 @@ void cgit_print_repolist(void) html("<table summary='repository list' class='list nowrap'>"); for (i = 0; i < cgit_repolist.count; i++) { ctx.repo = &cgit_repolist.repos[i]; - if (ctx.repo->hide || ctx.repo->ignore) - continue; - if (!(is_match(ctx.repo) && is_in_url(ctx.repo))) + if (!is_visible(ctx.repo)) continue; hits++; if (hits <= ctx.qry.ofs) From 9abe4a26a92b91170cb9c5dab830b40fb1e0327f Mon Sep 17 00:00:00 2001 From: Peter Colberg <peter@colberg.org> Date: Tue, 8 Dec 2015 12:53:09 -0500 Subject: [PATCH 111/387] ui-repolist: return HTTP 404 if no repositories found Return HTTP status code 404 Not found when querying a non-existent repository, which signals to search engines that a repository no longer exists. Further, some webservers such as nginx permit logging requests to different files depending on the HTTP code. Signed-off-by: Peter Colberg <peter@colberg.org> --- ui-repolist.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/ui-repolist.c b/ui-repolist.c index 4912fa5..6010a39 100644 --- a/ui-repolist.c +++ b/ui-repolist.c @@ -115,6 +115,17 @@ static int is_visible(struct cgit_repo *repo) return 1; } +static int any_repos_visible(void) +{ + int i; + + for (i = 0; i < cgit_repolist.count; i++) { + if (is_visible(&cgit_repolist.repos[i])) + return 1; + } + return 0; +} + static void print_sort_header(const char *title, const char *sort) { char *currenturl = cgit_currenturl(); @@ -266,6 +277,11 @@ void cgit_print_repolist(void) char *section; int sorted = 0; + if (!any_repos_visible()) { + cgit_print_error_page(404, "Not found", "No repositories found"); + return; + } + if (ctx.cfg.enable_index_links) ++columns; if (ctx.cfg.enable_index_owner) @@ -347,9 +363,7 @@ void cgit_print_repolist(void) html("</tr>\n"); } html("</table>"); - if (!hits) - cgit_print_error("No repositories found"); - else if (hits > ctx.cfg.max_repo_count) + if (hits > ctx.cfg.max_repo_count) print_pager(hits, ctx.cfg.max_repo_count, ctx.qry.search, ctx.qry.sort); cgit_print_docend(); } From 4c69241b052f7fa6d4c967bd9bc97c9db92a9572 Mon Sep 17 00:00:00 2001 From: Peter Colberg <peter@colberg.org> Date: Wed, 13 Jan 2016 17:25:07 -0500 Subject: [PATCH 112/387] Fix missing prototype declarations Signed-off-by: Peter Colberg <peter@colberg.org> --- ui-diff.h | 2 +- ui-refs.h | 2 +- ui-repolist.h | 4 ++-- ui-shared.h | 12 ++++++------ ui-ssdiff.h | 8 ++++---- ui-summary.h | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/ui-diff.h b/ui-diff.h index 04f9029..382e8c5 100644 --- a/ui-diff.h +++ b/ui-diff.h @@ -1,7 +1,7 @@ #ifndef UI_DIFF_H #define UI_DIFF_H -extern void cgit_print_diff_ctrls(); +extern void cgit_print_diff_ctrls(void); extern void cgit_print_diff(const char *new_hex, const char *old_hex, const char *prefix, int show_ctrls, int raw); diff --git a/ui-refs.h b/ui-refs.h index b35c04a..1d4a54a 100644 --- a/ui-refs.h +++ b/ui-refs.h @@ -3,6 +3,6 @@ extern void cgit_print_branches(int maxcount); extern void cgit_print_tags(int maxcount); -extern void cgit_print_refs(); +extern void cgit_print_refs(void); #endif /* UI_REFS_H */ diff --git a/ui-repolist.h b/ui-repolist.h index 5b1e542..1b6b322 100644 --- a/ui-repolist.h +++ b/ui-repolist.h @@ -1,7 +1,7 @@ #ifndef UI_REPOLIST_H #define UI_REPOLIST_H -extern void cgit_print_repolist(); -extern void cgit_print_site_readme(); +extern void cgit_print_repolist(void); +extern void cgit_print_site_readme(void); #endif /* UI_REPOLIST_H */ diff --git a/ui-shared.h b/ui-shared.h index 474e0c5..de08e1b 100644 --- a/ui-shared.h +++ b/ui-shared.h @@ -1,11 +1,11 @@ #ifndef UI_SHARED_H #define UI_SHARED_H -extern const char *cgit_httpscheme(); -extern char *cgit_hosturl(); -extern const char *cgit_rooturl(); -extern char *cgit_currenturl(); -extern const char *cgit_loginurl(); +extern const char *cgit_httpscheme(void); +extern char *cgit_hosturl(void); +extern const char *cgit_rooturl(void); +extern char *cgit_currenturl(void); +extern const char *cgit_loginurl(void); extern char *cgit_repourl(const char *reponame); extern char *cgit_fileurl(const char *reponame, const char *pagename, const char *filename, const char *query); @@ -66,7 +66,7 @@ extern void cgit_print_age(time_t t, time_t max_relative, const char *format); extern void cgit_print_http_headers(void); extern void cgit_redirect(const char *url, bool permanent); extern void cgit_print_docstart(void); -extern void cgit_print_docend(); +extern void cgit_print_docend(void); __attribute__((format (printf,3,4))) extern void cgit_print_error_page(int code, const char *msg, const char *fmt, ...); extern void cgit_print_pageheader(void); diff --git a/ui-ssdiff.h b/ui-ssdiff.h index 88627e2..11f2714 100644 --- a/ui-ssdiff.h +++ b/ui-ssdiff.h @@ -13,13 +13,13 @@ #endif #define MAX_SSDIFF_SIZE ((MAX_SSDIFF_M) * (MAX_SSDIFF_N)) -extern void cgit_ssdiff_print_deferred_lines(); +extern void cgit_ssdiff_print_deferred_lines(void); extern void cgit_ssdiff_line_cb(char *line, int len); -extern void cgit_ssdiff_header_begin(); -extern void cgit_ssdiff_header_end(); +extern void cgit_ssdiff_header_begin(void); +extern void cgit_ssdiff_header_end(void); -extern void cgit_ssdiff_footer(); +extern void cgit_ssdiff_footer(void); #endif /* UI_SSDIFF_H */ diff --git a/ui-summary.h b/ui-summary.h index c01f560..0896650 100644 --- a/ui-summary.h +++ b/ui-summary.h @@ -1,7 +1,7 @@ #ifndef UI_SUMMARY_H #define UI_SUMMARY_H -extern void cgit_print_summary(); +extern void cgit_print_summary(void); extern void cgit_print_repo_readme(char *path); #endif /* UI_SUMMARY_H */ From 4291453ec30656c2f59645d8a74cf295ce0253a9 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Thu, 14 Jan 2016 14:13:39 +0100 Subject: [PATCH 113/387] ui-shared: Avoid new line injection into redirect header --- ui-shared.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ui-shared.c b/ui-shared.c index 5b48734..21f581f 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -709,7 +709,9 @@ void cgit_print_http_headers(void) void cgit_redirect(const char *url, bool permanent) { htmlf("Status: %d %s\n", permanent ? 301 : 302, permanent ? "Moved" : "Found"); - htmlf("Location: %s\n\n", url); + html("Location: "); + html_url_path(url); + html("\n\n"); exit(0); } From 513b3863d999f91b47d7e9f26710390db55f9463 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Thu, 14 Jan 2016 14:28:37 +0100 Subject: [PATCH 114/387] ui-shared: prevent malicious filename from injecting headers --- html.c | 26 ++++++++++++++++++++++++++ html.h | 1 + ui-shared.c | 8 +++++--- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/html.c b/html.c index 959148c..d89df3a 100644 --- a/html.c +++ b/html.c @@ -239,6 +239,32 @@ void html_url_arg(const char *txt) html(txt); } +void html_header_arg_in_quotes(const char *txt) +{ + const char *t = txt; + while (t && *t) { + unsigned char c = *t; + const char *e = NULL; + if (c == '\\') + e = "\\\\"; + else if (c == '\r') + e = "\\r"; + else if (c == '\n') + e = "\\n"; + else if (c == '"') + e = "\\\""; + if (e) { + html_raw(txt, t - txt); + html(e); + txt = t + 1; + } + t++; + } + if (t != txt) + html(txt); + +} + void html_hidden(const char *name, const char *value) { html("<input type='hidden' name='"); diff --git a/html.h b/html.h index c554763..c72e845 100644 --- a/html.h +++ b/html.h @@ -23,6 +23,7 @@ extern void html_ntxt(int len, const char *txt); extern void html_attr(const char *txt); extern void html_url_path(const char *txt); extern void html_url_arg(const char *txt); +extern void html_header_arg_in_quotes(const char *txt); extern void html_hidden(const char *name, const char *value); extern void html_option(const char *value, const char *text, const char *selected_value); extern void html_intoption(int value, const char *text, int selected_value); diff --git a/ui-shared.c b/ui-shared.c index 21f581f..54bbde7 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -692,9 +692,11 @@ void cgit_print_http_headers(void) htmlf("Content-Type: %s\n", ctx.page.mimetype); if (ctx.page.size) htmlf("Content-Length: %zd\n", ctx.page.size); - if (ctx.page.filename) - htmlf("Content-Disposition: inline; filename=\"%s\"\n", - ctx.page.filename); + if (ctx.page.filename) { + html("Content-Disposition: inline; filename=\""); + html_header_arg_in_quotes(ctx.page.filename); + html("\"\n"); + } if (!ctx.env.authenticated) html("Cache-Control: no-cache, no-store\n"); htmlf("Last-Modified: %s\n", http_date(ctx.page.modified)); From 1c581a072651524f3b0d91f33e22a42c4166dd96 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Thu, 14 Jan 2016 14:31:13 +0100 Subject: [PATCH 115/387] ui-blob: Do not accept mimetype from user --- cgit.c | 2 -- cgit.h | 1 - ui-blob.c | 1 - 3 files changed, 4 deletions(-) diff --git a/cgit.c b/cgit.c index 05e5d57..3ed1935 100644 --- a/cgit.c +++ b/cgit.c @@ -314,8 +314,6 @@ static void querystring_cb(const char *name, const char *value) ctx.qry.path = trim_end(value, '/'); } else if (!strcmp(name, "name")) { ctx.qry.name = xstrdup(value); - } else if (!strcmp(name, "mimetype")) { - ctx.qry.mimetype = xstrdup(value); } else if (!strcmp(name, "s")) { ctx.qry.sort = xstrdup(value); } else if (!strcmp(name, "showmsg")) { diff --git a/cgit.h b/cgit.h index b7eccdd..4b4bcf4 100644 --- a/cgit.h +++ b/cgit.h @@ -173,7 +173,6 @@ struct cgit_query { char *sha2; char *path; char *name; - char *mimetype; char *url; char *period; int ofs; diff --git a/ui-blob.c b/ui-blob.c index 1ded839..2cce11c 100644 --- a/ui-blob.c +++ b/ui-blob.c @@ -161,7 +161,6 @@ void cgit_print_blob(const char *hex, char *path, const char *head, int file_onl } buf[size] = '\0'; - ctx.page.mimetype = ctx.qry.mimetype; if (!ctx.page.mimetype) { if (buffer_is_binary(buf, size)) ctx.page.mimetype = "application/octet-stream"; From 92996ac2a6fc4e944c3d723e12d5ab244a43508e Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Thu, 14 Jan 2016 14:31:53 +0100 Subject: [PATCH 116/387] ui-blob: always use generic mimetypes --- ui-blob.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/ui-blob.c b/ui-blob.c index 2cce11c..43a2f10 100644 --- a/ui-blob.c +++ b/ui-blob.c @@ -161,12 +161,10 @@ void cgit_print_blob(const char *hex, char *path, const char *head, int file_onl } buf[size] = '\0'; - if (!ctx.page.mimetype) { - if (buffer_is_binary(buf, size)) - ctx.page.mimetype = "application/octet-stream"; - else - ctx.page.mimetype = "text/plain"; - } + if (buffer_is_binary(buf, size)) + ctx.page.mimetype = "application/octet-stream"; + else + ctx.page.mimetype = "text/plain"; ctx.page.filename = path; cgit_print_http_headers(); html_raw(buf, size); From 9ca2566972db968df4479108b29bb92551138b57 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Thu, 14 Jan 2016 14:43:43 +0100 Subject: [PATCH 117/387] ui-blob: set CSP just in case --- ui-blob.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ui-blob.c b/ui-blob.c index 43a2f10..d388489 100644 --- a/ui-blob.c +++ b/ui-blob.c @@ -166,6 +166,9 @@ void cgit_print_blob(const char *hex, char *path, const char *head, int file_onl else ctx.page.mimetype = "text/plain"; ctx.page.filename = path; + + html("X-Content-Type-Options: nosniff\n"); + html("Content-Security-Policy: default-src 'none'\n"); cgit_print_http_headers(); html_raw(buf, size); free(buf); From c326f3eb026d67650f79a6dda9a1a42c55d10a25 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Thu, 14 Jan 2016 14:53:28 +0100 Subject: [PATCH 118/387] ui-plain: add enable-html-serving flag Unrestricts plain/ to contents likely to be executed by browser. --- cgit.c | 5 +++++ cgit.h | 2 ++ cgitrc.5.txt | 11 +++++++++++ shared.c | 1 + ui-plain.c | 10 ++++++++++ 5 files changed, 29 insertions(+) diff --git a/cgit.c b/cgit.c index 3ed1935..7f83a2d 100644 --- a/cgit.c +++ b/cgit.c @@ -55,6 +55,8 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va repo->enable_remote_branches = atoi(value); else if (!strcmp(name, "enable-subject-links")) repo->enable_subject_links = atoi(value); + else if (!strcmp(name, "enable-html-serving")) + repo->enable_html_serving = atoi(value); else if (!strcmp(name, "branch-sort")) { if (!strcmp(value, "age")) repo->branch_sort = 1; @@ -170,6 +172,8 @@ static void config_cb(const char *name, const char *value) ctx.cfg.enable_remote_branches = atoi(value); else if (!strcmp(name, "enable-subject-links")) ctx.cfg.enable_subject_links = atoi(value); + else if (!strcmp(name, "enable-html-serving")) + ctx.cfg.enable_html_serving = atoi(value); else if (!strcmp(name, "enable-tree-linenumbers")) ctx.cfg.enable_tree_linenumbers = atoi(value); else if (!strcmp(name, "enable-git-config")) @@ -821,6 +825,7 @@ static void print_repo(FILE *f, struct cgit_repo *repo) fprintf(f, "repo.logo-link=%s\n", repo->logo_link); fprintf(f, "repo.enable-remote-branches=%d\n", repo->enable_remote_branches); fprintf(f, "repo.enable-subject-links=%d\n", repo->enable_subject_links); + fprintf(f, "repo.enable-html-serving=%d\n", repo->enable_html_serving); if (repo->branch_sort == 1) fprintf(f, "repo.branch-sort=age\n"); if (repo->commit_sort) { diff --git a/cgit.h b/cgit.h index 4b4bcf4..de5c94a 100644 --- a/cgit.h +++ b/cgit.h @@ -101,6 +101,7 @@ struct cgit_repo { int enable_log_linecount; int enable_remote_branches; int enable_subject_links; + int enable_html_serving; int max_stats; int branch_sort; int commit_sort; @@ -235,6 +236,7 @@ struct cgit_config { int enable_log_linecount; int enable_remote_branches; int enable_subject_links; + int enable_html_serving; int enable_tree_linenumbers; int enable_git_config; int local_time; diff --git a/cgitrc.5.txt b/cgitrc.5.txt index 759f353..47850a8 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -190,6 +190,13 @@ enable-subject-links:: in commit view. Default value: "0". See also: "repo.enable-subject-links". +enable-html-serving:: + Flag which, when set to "1", will allow the /plain handler to serve + mimetype headers that result in the file being treated as HTML by the + browser. When set to "0", such file types are returned instead as + text/plain or application/octet-stream. Default value: "0". See also: + "repo.enable-html-serving". + enable-tree-linenumbers:: Flag which, when set to "1", will make cgit generate linenumber links for plaintext blobs printed in the tree view. Default value: "1". @@ -513,6 +520,10 @@ repo.enable-subject-links:: A flag which can be used to override the global setting `enable-subject-links'. Default value: none. +enable-html-serving:: + A flag which can be used to override the global setting + `enable-html-serving`. Default value: none. + repo.hide:: Flag which, when set to "1", hides the repository from the repository index. The repository can still be accessed by providing a direct path. diff --git a/shared.c b/shared.c index 42b2ddc..a078a27 100644 --- a/shared.c +++ b/shared.c @@ -61,6 +61,7 @@ struct cgit_repo *cgit_add_repo(const char *url) ret->enable_log_linecount = ctx.cfg.enable_log_linecount; ret->enable_remote_branches = ctx.cfg.enable_remote_branches; ret->enable_subject_links = ctx.cfg.enable_subject_links; + ret->enable_html_serving = ctx.cfg.enable_html_serving; ret->max_stats = ctx.cfg.max_stats; ret->branch_sort = ctx.cfg.branch_sort; ret->commit_sort = ctx.cfg.commit_sort; diff --git a/ui-plain.c b/ui-plain.c index 58addab..ff85113 100644 --- a/ui-plain.c +++ b/ui-plain.c @@ -37,6 +37,16 @@ static int print_object(const unsigned char *sha1, const char *path) mimetype = get_mimetype_for_filename(path); ctx.page.mimetype = mimetype; + if (!ctx.repo->enable_html_serving) { + html("X-Content-Type-Options: nosniff\n"); + html("Content-Security-Policy: default-src 'none'\n"); + if (mimetype) { + /* Built-in white list allows PDF and everything that isn't text/ and application/ */ + if ((!strncmp(mimetype, "text/", 5) || !strncmp(mimetype, "application/", 12)) && strcmp(mimetype, "application/pdf")) + ctx.page.mimetype = NULL; + } + } + if (!ctx.page.mimetype) { if (buffer_is_binary(buf, size)) { ctx.page.mimetype = "application/octet-stream"; From e64d5e04c3e22e713539da2b06e1052390aed43d Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Thu, 14 Jan 2016 15:43:54 +0100 Subject: [PATCH 119/387] Bump version --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9bb9cd5..6590d8e 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ all:: -CGIT_VERSION = v0.11.2 +CGIT_VERSION = v0.12 CGIT_SCRIPT_NAME = cgit.cgi CGIT_SCRIPT_PATH = /var/www/htdocs/cgit CGIT_DATA_PATH = $(CGIT_SCRIPT_PATH) From baa5ad1f80f56d3c0b0095bfb468fab28c9b4982 Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Sat, 16 Jan 2016 11:03:05 +0000 Subject: [PATCH 120/387] ui-log: handle parse_commit() errors If parse_commit() fails, none of the fields in the commit structure will have been populated so we will dereference NULL when accessing item->tree. There isn't much we can do about the error at this point, but if we return true then we'll try parsing the commit again from print_commit() and we can report an error to the user at that point. Coverity-id: 13801 Signed-off-by: John Keeping <john@keeping.me.uk> --- ui-log.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ui-log.c b/ui-log.c index 4573255..a4dc707 100644 --- a/ui-log.c +++ b/ui-log.c @@ -141,7 +141,9 @@ static int show_commit(struct commit *commit, struct rev_info *revs) /* When we get here we have precisely one parent. */ parent = parents->item; - parse_commit(parent); + /* If we can't parse the commit, let print_commit() report an error. */ + if (parse_commit(parent)) + return 1; files = 0; add_lines = 0; From 3fbfced7401cfcbb8006a9a6ce4add6b37a41a55 Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Sat, 16 Jan 2016 11:03:06 +0000 Subject: [PATCH 121/387] cache: use size_t for string lengths Avoid integer truncation on 64-bit systems. Coverity-id: 13864 Signed-off-by: John Keeping <john@keeping.me.uk> --- cache.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cache.c b/cache.c index b169d20..df1b4a3 100644 --- a/cache.c +++ b/cache.c @@ -24,7 +24,7 @@ struct cache_slot { const char *key; - int keylen; + size_t keylen; int ttl; cache_fill_fn fn; int cache_fd; @@ -44,7 +44,7 @@ struct cache_slot { static int open_slot(struct cache_slot *slot) { char *bufz; - int bufkeylen = -1; + ssize_t bufkeylen = -1; slot->cache_fd = open(slot->cache_name, O_RDONLY); if (slot->cache_fd == -1) From 33bc949a1e927e14479568518bd92e70998e25f8 Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Sat, 16 Jan 2016 11:03:07 +0000 Subject: [PATCH 122/387] cache: don't check for match with no key We call open_slot() from cache_ls() without a key since we simply want to read the path out of the header. Should the file happen to contain an empty key then we end up calling memcmp() with NULL and a non-zero length. Fix this by assigning slot->match only if a key is set, which is always will be in the code paths where we use slot->match. Coverity-id: 13807 Signed-off-by: John Keeping <john@keeping.me.uk> --- cache.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cache.c b/cache.c index df1b4a3..6736a01 100644 --- a/cache.c +++ b/cache.c @@ -61,8 +61,9 @@ static int open_slot(struct cache_slot *slot) if (bufz) bufkeylen = bufz - slot->buf; - slot->match = bufkeylen == slot->keylen && - !memcmp(slot->key, slot->buf, bufkeylen + 1); + if (slot->key) + slot->match = bufkeylen == slot->keylen && + !memcmp(slot->key, slot->buf, bufkeylen + 1); return 0; } From d3756bd7b00f9ad6adede3c7f956a25b22a2254a Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Mon, 18 Jan 2016 11:14:06 +0100 Subject: [PATCH 123/387] syntax-highlighting: always use utf-8 to avoid ascii codec issues --- filters/syntax-highlighting.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/filters/syntax-highlighting.py b/filters/syntax-highlighting.py index b5d615e..1ca4108 100755 --- a/filters/syntax-highlighting.py +++ b/filters/syntax-highlighting.py @@ -21,6 +21,7 @@ import sys +import io from pygments import highlight from pygments.util import ClassNotFound from pygments.lexers import TextLexer @@ -29,6 +30,8 @@ from pygments.lexers import guess_lexer_for_filename from pygments.formatters import HtmlFormatter +sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8') +sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') data = sys.stdin.read() filename = sys.argv[1] formatter = HtmlFormatter(style='pastie') From 23f7dadaaba2817c92c42c0a642a3186aa8ef24d Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Mon, 18 Jan 2016 15:56:45 +0100 Subject: [PATCH 124/387] ui-tree: put reverse path in title --- ui-tree.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/ui-tree.c b/ui-tree.c index 3ff2320..120066c 100644 --- a/ui-tree.c +++ b/ui-tree.c @@ -84,6 +84,37 @@ static void print_binary_buffer(char *buf, unsigned long size) html("</table>\n"); } +static void set_title_from_path(const char *path) +{ + size_t path_len, path_index, path_last_end; + char *new_title; + + if (!path) + return; + + path_len = strlen(path); + new_title = xmalloc(path_len + 3 + strlen(ctx.page.title) + 1); + new_title[0] = '\0'; + + for (path_index = path_len, path_last_end = path_len; path_index-- > 0;) { + if (path[path_index] == '/') { + if (path_index == path_len - 1) { + path_last_end = path_index - 1; + continue; + } + strncat(new_title, &path[path_index + 1], path_last_end - path_index - 1); + strcat(new_title, "\\"); + path_last_end = path_index; + } + } + if (path_last_end) + strncat(new_title, path, path_last_end); + + strcat(new_title, " - "); + strcat(new_title, ctx.page.title); + ctx.page.title = new_title; +} + static void print_object(const unsigned char *sha1, char *path, const char *basename, const char *rev) { enum object_type type; @@ -104,6 +135,8 @@ static void print_object(const unsigned char *sha1, char *path, const char *base return; } + set_title_from_path(path); + cgit_print_layout_start(); htmlf("blob: %s (", sha1_to_hex(sha1)); cgit_plain_link("plain", NULL, NULL, ctx.qry.head, @@ -235,6 +268,7 @@ static int walk_tree(const unsigned char *sha1, struct strbuf *base, if (S_ISDIR(mode)) { walk_tree_ctx->state = 1; + set_title_from_path(buffer); ls_head(); return READ_TREE_RECURSIVE; } else { From 57ea1aa2a5eab7f6aba702b3366fe4dcc72124f6 Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Tue, 19 Jan 2016 19:33:01 +0000 Subject: [PATCH 125/387] ui-shared: remove "format" from cgit_print_age() We never use any format other than FMT_SHORTDATE, so move that into the function. Signed-off-by: John Keeping <john@keeping.me.uk> --- ui-log.c | 4 ++-- ui-refs.c | 6 +++--- ui-repolist.c | 2 +- ui-shared.c | 4 ++-- ui-shared.h | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ui-log.c b/ui-log.c index a4dc707..5f6a69c 100644 --- a/ui-log.c +++ b/ui-log.c @@ -204,7 +204,7 @@ static void print_commit(struct commit *commit, struct rev_info *revs) } else { html("<td>"); - cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); + cgit_print_age(commit->date, TM_WEEK * 2); html("</td>"); } @@ -244,7 +244,7 @@ static void print_commit(struct commit *commit, struct rev_info *revs) if (revs->graph) { html("</td><td>"); - cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); + cgit_print_age(commit->date, TM_WEEK * 2); } if (!lines_counted && (ctx.repo->enable_log_filecount || diff --git a/ui-refs.c b/ui-refs.c index 295a4c7..0652b89 100644 --- a/ui-refs.c +++ b/ui-refs.c @@ -73,7 +73,7 @@ static int print_branch(struct refinfo *ref) html_txt(info->author); cgit_close_filter(ctx.repo->email_filter); html("</td><td colspan='2'>"); - cgit_print_age(info->commit->date, -1, NULL); + cgit_print_age(info->commit->date, -1); } else { html("</td><td></td><td>"); cgit_object_link(ref->object); @@ -161,9 +161,9 @@ static int print_tag(struct refinfo *ref) html("</td><td colspan='2'>"); if (info) { if (info->tagger_date > 0) - cgit_print_age(info->tagger_date, -1, NULL); + cgit_print_age(info->tagger_date, -1); } else if (ref->object->type == OBJ_COMMIT) { - cgit_print_age(ref->commit->commit->date, -1, NULL); + cgit_print_age(ref->commit->commit->date, -1); } html("</td></tr>\n"); diff --git a/ui-repolist.c b/ui-repolist.c index 6010a39..6004469 100644 --- a/ui-repolist.c +++ b/ui-repolist.c @@ -79,7 +79,7 @@ static void print_modtime(struct cgit_repo *repo) { time_t t; if (get_repo_modtime(repo, &t)) - cgit_print_age(t, -1, NULL); + cgit_print_age(t, -1); } static int is_match(struct cgit_repo *repo) diff --git a/ui-shared.c b/ui-shared.c index 54bbde7..76aac60 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -635,7 +635,7 @@ static void print_rel_date(time_t t, double value, htmlf("'>%.0f %s</span>", value, suffix); } -void cgit_print_age(time_t t, time_t max_relative, const char *format) +void cgit_print_age(time_t t, time_t max_relative) { time_t now, secs; @@ -650,7 +650,7 @@ void cgit_print_age(time_t t, time_t max_relative, const char *format) html("<span title='"); html_attr(fmt_date(t, FMT_LONGDATE, ctx.cfg.local_time)); html("'>"); - cgit_print_date(t, format, ctx.cfg.local_time); + cgit_print_date(t, FMT_SHORTDATE, ctx.cfg.local_time); html("</span>"); return; } diff --git a/ui-shared.h b/ui-shared.h index de08e1b..c9413ed 100644 --- a/ui-shared.h +++ b/ui-shared.h @@ -62,7 +62,7 @@ extern void cgit_print_error(const char *fmt, ...); __attribute__((format (printf,1,0))) extern void cgit_vprint_error(const char *fmt, va_list ap); extern void cgit_print_date(time_t secs, const char *format, int local_time); -extern void cgit_print_age(time_t t, time_t max_relative, const char *format); +extern void cgit_print_age(time_t t, time_t max_relative); extern void cgit_print_http_headers(void); extern void cgit_redirect(const char *url, bool permanent); extern void cgit_print_docstart(void); From 45c87ca1c32dcd5ffd4a681fadf05627d9ce7770 Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Tue, 19 Jan 2016 19:33:02 +0000 Subject: [PATCH 126/387] parsing: add timezone to ident structures This will allow us to mimic Git's behaviour of showing times in the originator's timezone when displaying commits and tags. Signed-off-by: John Keeping <john@keeping.me.uk> --- cgit.h | 3 +++ parsing.c | 10 ++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cgit.h b/cgit.h index de5c94a..501cb48 100644 --- a/cgit.h +++ b/cgit.h @@ -130,9 +130,11 @@ struct commitinfo { char *author; char *author_email; unsigned long author_date; + int author_tz; char *committer; char *committer_email; unsigned long committer_date; + int committer_tz; char *subject; char *msg; char *msg_encoding; @@ -142,6 +144,7 @@ struct taginfo { char *tagger; char *tagger_email; unsigned long tagger_date; + int tagger_tz; char *msg; }; diff --git a/parsing.c b/parsing.c index 5283e58..9dacb16 100644 --- a/parsing.c +++ b/parsing.c @@ -69,7 +69,7 @@ static char *substr(const char *head, const char *tail) return buf; } -static void parse_user(const char *t, char **name, char **email, unsigned long *date) +static void parse_user(const char *t, char **name, char **email, unsigned long *date, int *tz) { struct ident_split ident; unsigned email_len; @@ -83,6 +83,8 @@ static void parse_user(const char *t, char **name, char **email, unsigned long * if (ident.date_begin) *date = strtoul(ident.date_begin, NULL, 10); + if (ident.tz_begin) + *tz = atoi(ident.tz_begin); } } @@ -147,13 +149,13 @@ struct commitinfo *cgit_parse_commit(struct commit *commit) if (p && skip_prefix(p, "author ", &p)) { parse_user(p, &ret->author, &ret->author_email, - &ret->author_date); + &ret->author_date, &ret->author_tz); p = next_header_line(p); } if (p && skip_prefix(p, "committer ", &p)) { parse_user(p, &ret->committer, &ret->committer_email, - &ret->committer_date); + &ret->committer_date, &ret->committer_tz); p = next_header_line(p); } @@ -208,7 +210,7 @@ struct taginfo *cgit_parse_tag(struct tag *tag) for (p = data; !end_of_header(p); p = next_header_line(p)) { if (skip_prefix(p, "tagger ", &p)) { parse_user(p, &ret->tagger, &ret->tagger_email, - &ret->tagger_date); + &ret->tagger_date, &ret->tagger_tz); } } From 360af46fac6fe79ec1868141a6c34b4c6b732ba0 Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Tue, 19 Jan 2016 19:33:03 +0000 Subject: [PATCH 127/387] ui-shared: add cgit_date_mode() This returns the correct mode value for use with Git's show_date() based on the current CGit configuration and will be used in the following patches. Signed-off-by: John Keeping <john@keeping.me.uk> --- ui-shared.c | 9 +++++++++ ui-shared.h | 1 + 2 files changed, 10 insertions(+) diff --git a/ui-shared.c b/ui-shared.c index 76aac60..923d102 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -627,6 +627,15 @@ void cgit_print_date(time_t secs, const char *format, int local_time) html_txt(fmt_date(secs, format, local_time)); } +const struct date_mode *cgit_date_mode(const char *format) +{ + static struct date_mode mode; + mode.type = DATE_STRFTIME; + mode.strftime_fmt = format; + mode.local = ctx.cfg.local_time; + return &mode; +} + static void print_rel_date(time_t t, double value, const char *class, const char *suffix) { diff --git a/ui-shared.h b/ui-shared.h index c9413ed..707cec9 100644 --- a/ui-shared.h +++ b/ui-shared.h @@ -61,6 +61,7 @@ __attribute__((format (printf,1,2))) extern void cgit_print_error(const char *fmt, ...); __attribute__((format (printf,1,0))) extern void cgit_vprint_error(const char *fmt, va_list ap); +extern const struct date_mode *cgit_date_mode(const char *format); extern void cgit_print_date(time_t secs, const char *format, int local_time); extern void cgit_print_age(time_t t, time_t max_relative); extern void cgit_print_http_headers(void); From 21dcf10386551a2eee3e552c3213bb14e535cbba Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Tue, 19 Jan 2016 19:33:04 +0000 Subject: [PATCH 128/387] ui-{commit,tag}: show dates in originator's timezone This is done by switching to Git's show_date() function and the mode given by cgit_date_mode(). Signed-off-by: John Keeping <john@keeping.me.uk> --- ui-commit.c | 6 ++++-- ui-tag.c | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ui-commit.c b/ui-commit.c index 0c3d740..e697571 100644 --- a/ui-commit.c +++ b/ui-commit.c @@ -55,7 +55,8 @@ void cgit_print_commit(char *hex, const char *prefix) } cgit_close_filter(ctx.repo->email_filter); html("</td><td class='right'>"); - cgit_print_date(info->author_date, FMT_LONGDATE, ctx.cfg.local_time); + html_txt(show_date(info->author_date, info->author_tz, + cgit_date_mode(FMT_LONGDATE))); html("</td></tr>\n"); html("<tr><th>committer</th><td>"); cgit_open_filter(ctx.repo->email_filter, info->committer_email, "commit"); @@ -66,7 +67,8 @@ void cgit_print_commit(char *hex, const char *prefix) } cgit_close_filter(ctx.repo->email_filter); html("</td><td class='right'>"); - cgit_print_date(info->committer_date, FMT_LONGDATE, ctx.cfg.local_time); + html_txt(show_date(info->committer_date, info->committer_tz, + cgit_date_mode(FMT_LONGDATE))); html("</td></tr>\n"); html("<tr><th>commit</th><td colspan='2' class='sha1'>"); tmp = oid_to_hex(&commit->object.oid); diff --git a/ui-tag.c b/ui-tag.c index 0afc663..b011198 100644 --- a/ui-tag.c +++ b/ui-tag.c @@ -76,7 +76,8 @@ void cgit_print_tag(char *revname) htmlf(" (%s)</td></tr>\n", sha1_to_hex(sha1)); if (info->tagger_date > 0) { html("<tr><td>tag date</td><td>"); - cgit_print_date(info->tagger_date, FMT_LONGDATE, ctx.cfg.local_time); + html_txt(show_date(info->tagger_date, info->tagger_tz, + cgit_date_mode(FMT_LONGDATE))); html("</td></tr>\n"); } if (info->tagger) { From f2a901d2e1db5217d6890b26c6dc1ec119505d02 Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Tue, 19 Jan 2016 19:33:05 +0000 Subject: [PATCH 129/387] ui: show ages in the originator's timezone This affects the tooltip showing the full time and the case when a date is sufficiently old to be shown in full rather than as an offset. Signed-off-by: John Keeping <john@keeping.me.uk> --- ui-log.c | 4 ++-- ui-refs.c | 6 +++--- ui-repolist.c | 2 +- ui-shared.c | 22 +++++++++++----------- ui-shared.h | 2 +- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/ui-log.c b/ui-log.c index 5f6a69c..0a3938b 100644 --- a/ui-log.c +++ b/ui-log.c @@ -204,7 +204,7 @@ static void print_commit(struct commit *commit, struct rev_info *revs) } else { html("<td>"); - cgit_print_age(commit->date, TM_WEEK * 2); + cgit_print_age(info->committer_date, info->committer_tz, TM_WEEK * 2); html("</td>"); } @@ -244,7 +244,7 @@ static void print_commit(struct commit *commit, struct rev_info *revs) if (revs->graph) { html("</td><td>"); - cgit_print_age(commit->date, TM_WEEK * 2); + cgit_print_age(info->committer_date, info->committer_tz, TM_WEEK * 2); } if (!lines_counted && (ctx.repo->enable_log_filecount || diff --git a/ui-refs.c b/ui-refs.c index 0652b89..5b4530e 100644 --- a/ui-refs.c +++ b/ui-refs.c @@ -73,7 +73,7 @@ static int print_branch(struct refinfo *ref) html_txt(info->author); cgit_close_filter(ctx.repo->email_filter); html("</td><td colspan='2'>"); - cgit_print_age(info->commit->date, -1); + cgit_print_age(info->committer_date, info->committer_tz, -1); } else { html("</td><td></td><td>"); cgit_object_link(ref->object); @@ -161,9 +161,9 @@ static int print_tag(struct refinfo *ref) html("</td><td colspan='2'>"); if (info) { if (info->tagger_date > 0) - cgit_print_age(info->tagger_date, -1); + cgit_print_age(info->tagger_date, info->tagger_tz, -1); } else if (ref->object->type == OBJ_COMMIT) { - cgit_print_age(ref->commit->commit->date, -1); + cgit_print_age(ref->commit->commit->date, 0, -1); } html("</td></tr>\n"); diff --git a/ui-repolist.c b/ui-repolist.c index 6004469..30915df 100644 --- a/ui-repolist.c +++ b/ui-repolist.c @@ -79,7 +79,7 @@ static void print_modtime(struct cgit_repo *repo) { time_t t; if (get_repo_modtime(repo, &t)) - cgit_print_age(t, -1); + cgit_print_age(t, 0, -1); } static int is_match(struct cgit_repo *repo) diff --git a/ui-shared.c b/ui-shared.c index 923d102..3ce86fe 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -636,15 +636,15 @@ const struct date_mode *cgit_date_mode(const char *format) return &mode; } -static void print_rel_date(time_t t, double value, +static void print_rel_date(time_t t, int tz, double value, const char *class, const char *suffix) { htmlf("<span class='%s' title='", class); - html_attr(fmt_date(t, FMT_LONGDATE, ctx.cfg.local_time)); + html_attr(show_date(t, tz, cgit_date_mode(FMT_LONGDATE))); htmlf("'>%.0f %s</span>", value, suffix); } -void cgit_print_age(time_t t, time_t max_relative) +void cgit_print_age(time_t t, int tz, time_t max_relative) { time_t now, secs; @@ -657,34 +657,34 @@ void cgit_print_age(time_t t, time_t max_relative) if (secs > max_relative && max_relative >= 0) { html("<span title='"); - html_attr(fmt_date(t, FMT_LONGDATE, ctx.cfg.local_time)); + html_attr(show_date(t, tz, cgit_date_mode(FMT_LONGDATE))); html("'>"); - cgit_print_date(t, FMT_SHORTDATE, ctx.cfg.local_time); + html_txt(show_date(t, tz, cgit_date_mode(FMT_SHORTDATE))); html("</span>"); return; } if (secs < TM_HOUR * 2) { - print_rel_date(t, secs * 1.0 / TM_MIN, "age-mins", "min."); + print_rel_date(t, tz, secs * 1.0 / TM_MIN, "age-mins", "min."); return; } if (secs < TM_DAY * 2) { - print_rel_date(t, secs * 1.0 / TM_HOUR, "age-hours", "hours"); + print_rel_date(t, tz, secs * 1.0 / TM_HOUR, "age-hours", "hours"); return; } if (secs < TM_WEEK * 2) { - print_rel_date(t, secs * 1.0 / TM_DAY, "age-days", "days"); + print_rel_date(t, tz, secs * 1.0 / TM_DAY, "age-days", "days"); return; } if (secs < TM_MONTH * 2) { - print_rel_date(t, secs * 1.0 / TM_WEEK, "age-weeks", "weeks"); + print_rel_date(t, tz, secs * 1.0 / TM_WEEK, "age-weeks", "weeks"); return; } if (secs < TM_YEAR * 2) { - print_rel_date(t, secs * 1.0 / TM_MONTH, "age-months", "months"); + print_rel_date(t, tz, secs * 1.0 / TM_MONTH, "age-months", "months"); return; } - print_rel_date(t, secs * 1.0 / TM_YEAR, "age-years", "years"); + print_rel_date(t, tz, secs * 1.0 / TM_YEAR, "age-years", "years"); } void cgit_print_http_headers(void) diff --git a/ui-shared.h b/ui-shared.h index 707cec9..e42f13a 100644 --- a/ui-shared.h +++ b/ui-shared.h @@ -63,7 +63,7 @@ __attribute__((format (printf,1,0))) extern void cgit_vprint_error(const char *fmt, va_list ap); extern const struct date_mode *cgit_date_mode(const char *format); extern void cgit_print_date(time_t secs, const char *format, int local_time); -extern void cgit_print_age(time_t t, time_t max_relative); +extern void cgit_print_age(time_t t, int tz, time_t max_relative); extern void cgit_print_http_headers(void); extern void cgit_redirect(const char *url, bool permanent); extern void cgit_print_docstart(void); From e68c86e8c54a6f03e7405dff3d38995c6c42e4fa Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Tue, 19 Jan 2016 19:33:06 +0000 Subject: [PATCH 130/387] ui-shared: use show_date for footer timestamp Signed-off-by: John Keeping <john@keeping.me.uk> --- ui-shared.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui-shared.c b/ui-shared.c index 3ce86fe..eaa45fb 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -801,7 +801,7 @@ void cgit_print_docend(void) else { htmlf("<div class='footer'>generated by <a href='http://git.zx2c4.com/cgit/about/'>cgit %s</a> at ", cgit_version); - cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time); + html_txt(show_date(time(NULL), 0, cgit_date_mode(FMT_LONGDATE))); html("</div>\n"); } html("</div> <!-- id=cgit -->\n"); From eb80b4edadd07957f667f057c82875c30a822a1f Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Tue, 19 Jan 2016 19:33:07 +0000 Subject: [PATCH 131/387] ui-atom: use show_date directly for atom dates This will allow us to remove cgit_print_date and use Git's show_date consistently. Signed-off-by: John Keeping <john@keeping.me.uk> --- ui-atom.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ui-atom.c b/ui-atom.c index 11ea0c0..0bf2cf2 100644 --- a/ui-atom.c +++ b/ui-atom.c @@ -17,6 +17,11 @@ static void add_entry(struct commit *commit, const char *host) char *hex; char *mail, *t, *t2; struct commitinfo *info; + struct date_mode mode = { + .type = DATE_STRFTIME, + .strftime_fmt = FMT_ATOMDATE, + .local = 0, + }; info = cgit_parse_commit(commit); hex = oid_to_hex(&commit->object.oid); @@ -25,7 +30,7 @@ static void add_entry(struct commit *commit, const char *host) html_txt(info->subject); html("\n"); html(""); - cgit_print_date(info->committer_date, FMT_ATOMDATE, 0); + html_txt(show_date(info->committer_date, 0, &mode)); html("\n"); html("\n"); if (info->author) { @@ -50,7 +55,7 @@ static void add_entry(struct commit *commit, const char *host) } html("\n"); html(""); - cgit_print_date(info->author_date, FMT_ATOMDATE, 0); + html_txt(show_date(info->author_date, 0, &mode)); html("\n"); if (host) { char *pageurl; From 17c74eefa4390d42a244b12885dc63ac4a764e44 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Tue, 19 Jan 2016 19:33:08 +0000 Subject: [PATCH 132/387] ui-shared: remove cgit_print_date() There are no longer any users of this function. Signed-off-by: John Keeping --- ui-shared.c | 20 -------------------- ui-shared.h | 1 - 2 files changed, 21 deletions(-) diff --git a/ui-shared.c b/ui-shared.c index eaa45fb..d1f9249 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -607,26 +607,6 @@ void cgit_submodule_link(const char *class, char *path, const char *rev) path[len - 1] = tail; } -static const char *fmt_date(time_t secs, const char *format, int local_time) -{ - static char buf[64]; - struct tm *time; - - if (!secs) - return ""; - if (local_time) - time = localtime(&secs); - else - time = gmtime(&secs); - strftime(buf, sizeof(buf)-1, format, time); - return buf; -} - -void cgit_print_date(time_t secs, const char *format, int local_time) -{ - html_txt(fmt_date(secs, format, local_time)); -} - const struct date_mode *cgit_date_mode(const char *format) { static struct date_mode mode; diff --git a/ui-shared.h b/ui-shared.h index e42f13a..43789de 100644 --- a/ui-shared.h +++ b/ui-shared.h @@ -62,7 +62,6 @@ extern void cgit_print_error(const char *fmt, ...); __attribute__((format (printf,1,0))) extern void cgit_vprint_error(const char *fmt, va_list ap); extern const struct date_mode *cgit_date_mode(const char *format); -extern void cgit_print_date(time_t secs, const char *format, int local_time); extern void cgit_print_age(time_t t, int tz, time_t max_relative); extern void cgit_print_http_headers(void); extern void cgit_redirect(const char *url, bool permanent); From 85ec9f0211a0c83d6cca744e6e40d73daf4050fc Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Mon, 8 Feb 2016 09:06:47 +0100 Subject: [PATCH 133/387] git: update to v2.7.1 Update to git version v2.7.1, no changes required. Signed-off-by: Christian Hesse --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 6590d8e..8bd7a0e 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = -GIT_VER = 2.7.0 +GIT_VER = 2.7.1 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.gz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index 7548842..a08595f 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 754884255bb580df159e58defa81cdd30b5c430c +Subproject commit a08595f76159b09d57553e37a5123f1091bb13e7 From a8b9ef8c1c68fbb9c89db2d8c12dca38c15e2bfd Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 8 Feb 2016 14:35:47 +0100 Subject: [PATCH 134/387] ui-stats: if we're going to abuse void*, do it safely --- ui-stats.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/ui-stats.c b/ui-stats.c index 74ce0f7..a9c13fd 100644 --- a/ui-stats.c +++ b/ui-stats.c @@ -3,12 +3,6 @@ #include "html.h" #include "ui-shared.h" -#ifdef NO_C99_FORMAT -#define SZ_FMT "%u" -#else -#define SZ_FMT "%zu" -#endif - struct authorstat { long total; struct string_list list; @@ -174,6 +168,7 @@ static void add_commit(struct string_list *authors, struct commit *commit, char *tmp; struct tm *date; time_t t; + uintptr_t *counter; info = cgit_parse_commit(commit); tmp = xstrdup(info->author); @@ -191,7 +186,9 @@ static void add_commit(struct string_list *authors, struct commit *commit, item = string_list_insert(items, tmp); if (item->util) free(tmp); - item->util++; + counter = (uintptr_t *)&item->util; + (*counter)++; + authorstat->total++; cgit_free_commitinfo(info); } @@ -286,7 +283,7 @@ static void print_combined_authorrow(struct string_list *authors, int from, items = &authorstat->list; date = string_list_lookup(items, tmp); if (date) - subtotal += (size_t)date->util; + subtotal += (uintptr_t)date->util; } htmlf("
  • ", centerclass, subtotal); total += subtotal; @@ -340,8 +337,8 @@ static void print_authors(struct string_list *authors, int top, if (!date) html(""); else { - htmlf("", (size_t)date->util); - total += (size_t)date->util; + htmlf("", (uintptr_t)date->util); + total += (uintptr_t)date->util; } } htmlf("", total); From bdcbe0922d7099ebd61d875709ea9408bc1d7543 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Mon, 8 Feb 2016 14:12:35 +0000 Subject: [PATCH 135/387] ui-stats: cast pointer before checking for zero We abuse the "void *util" field as a counter and recently started to cast it to a uintptr_t to avoid risking nasal demons by performing arithmetic on a void pointer. However, compilers are also known to do "interesting" things if they know that a pointer is or isn't NULL. Make this safer by checking if the counter (after casting) is non-zero rather than checking if the pointer is non-null. Signed-off-by: John Keeping --- ui-stats.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui-stats.c b/ui-stats.c index a9c13fd..8cd9178 100644 --- a/ui-stats.c +++ b/ui-stats.c @@ -184,9 +184,9 @@ static void add_commit(struct string_list *authors, struct commit *commit, period->trunc(date); tmp = xstrdup(period->pretty(date)); item = string_list_insert(items, tmp); - if (item->util) - free(tmp); counter = (uintptr_t *)&item->util; + if (*counter) + free(tmp); (*counter)++; authorstat->total++; From 9c15f3c6954e43c5ffd36230e666eccf112803f2 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Mon, 8 Feb 2016 15:05:54 +0000 Subject: [PATCH 136/387] Avoid DATE_STRFTIME for long/short dates Git's DATE_STRFTIME ignores the timezone argument and just uses the local timezone regardless of whether the "local" flag is set. Since our existing FMT_LONGDATE and FMT_SHORTDATE are pretty-much perfect matches to DATE_ISO8601 and DATE_SHORT, switch to taking a date_mode_type directly in cgit_date_mode(). Signed-off-by: John Keeping --- cgit.h | 2 -- ui-commit.c | 4 ++-- ui-shared.c | 13 ++++++------- ui-shared.h | 2 +- ui-tag.c | 2 +- 5 files changed, 10 insertions(+), 13 deletions(-) diff --git a/cgit.h b/cgit.h index 501cb48..5adef4d 100644 --- a/cgit.h +++ b/cgit.h @@ -32,8 +32,6 @@ /* * Dateformats used on misc. pages */ -#define FMT_LONGDATE "%Y-%m-%d %H:%M:%S (%Z)" -#define FMT_SHORTDATE "%Y-%m-%d" #define FMT_ATOMDATE "%Y-%m-%dT%H:%M:%SZ" diff --git a/ui-commit.c b/ui-commit.c index e697571..099d294 100644 --- a/ui-commit.c +++ b/ui-commit.c @@ -56,7 +56,7 @@ void cgit_print_commit(char *hex, const char *prefix) cgit_close_filter(ctx.repo->email_filter); html("\n"); html("\n"); html("\n"); } if (info->tagger) { From 75298209bf8386656b82f185e2901690ac5b671c Mon Sep 17 00:00:00 2001 From: John Keeping Date: Mon, 8 Feb 2016 15:06:27 +0000 Subject: [PATCH 137/387] ui-atom: avoid DATE_STRFTIME Git's DATE_STRFTIME ignores the timezone argument and just uses the local timezone regardless of whether the "local" flag is set. Since Atom accepts ISO8601 dates [1], we can use Git's DATE_ISO8601_STRICT instead, which does get this right. Additionally, we never use the local timezone here so we can use the date_mode_from_type() wrapper to simplify the code a bit. [1] https://tools.ietf.org/html/rfc4287#section-3.3 Signed-off-by: John Keeping --- cgit.h | 5 ----- ui-atom.c | 11 ++++------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/cgit.h b/cgit.h index 5adef4d..d10c799 100644 --- a/cgit.h +++ b/cgit.h @@ -29,11 +29,6 @@ #undef isgraph #define isgraph(x) (isprint((x)) && !isspace((x))) -/* - * Dateformats used on misc. pages - */ -#define FMT_ATOMDATE "%Y-%m-%dT%H:%M:%SZ" - /* * Limits used for relative dates diff --git a/ui-atom.c b/ui-atom.c index 0bf2cf2..41838d3 100644 --- a/ui-atom.c +++ b/ui-atom.c @@ -17,11 +17,6 @@ static void add_entry(struct commit *commit, const char *host) char *hex; char *mail, *t, *t2; struct commitinfo *info; - struct date_mode mode = { - .type = DATE_STRFTIME, - .strftime_fmt = FMT_ATOMDATE, - .local = 0, - }; info = cgit_parse_commit(commit); hex = oid_to_hex(&commit->object.oid); @@ -30,7 +25,8 @@ static void add_entry(struct commit *commit, const char *host) html_txt(info->subject); html("\n"); html(""); - html_txt(show_date(info->committer_date, 0, &mode)); + html_txt(show_date(info->committer_date, 0, + date_mode_from_type(DATE_ISO8601_STRICT))); html("\n"); html("\n"); if (info->author) { @@ -55,7 +51,8 @@ static void add_entry(struct commit *commit, const char *host) } html("\n"); html(""); - html_txt(show_date(info->author_date, 0, &mode)); + html_txt(show_date(info->author_date, 0, + date_mode_from_type(DATE_ISO8601_STRICT))); html("\n"); if (host) { char *pageurl; From 5f2664f13c90f083b827d8fafa6cfc01c0c4f513 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 22 Feb 2016 16:04:15 +0100 Subject: [PATCH 138/387] ui-shared: add homepage to tabs Signed-off-by: Jason A. Donenfeld --- cgit.c | 4 ++++ cgit.css | 5 +++++ cgit.h | 1 + cgitrc.5.txt | 13 ++++++++----- scan-tree.c | 2 ++ shared.c | 1 + ui-shared.c | 5 +++++ 7 files changed, 26 insertions(+), 5 deletions(-) diff --git a/cgit.c b/cgit.c index 7f83a2d..fc482be 100644 --- a/cgit.c +++ b/cgit.c @@ -41,6 +41,8 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va repo->desc = xstrdup(value); else if (!strcmp(name, "owner")) repo->owner = xstrdup(value); + else if (!strcmp(name, "homepage")) + repo->homepage = xstrdup(value); else if (!strcmp(name, "defbranch")) repo->defbranch = xstrdup(value); else if (!strcmp(name, "snapshots")) @@ -793,6 +795,8 @@ static void print_repo(FILE *f, struct cgit_repo *repo) fprintf(f, "repo.module-link=%s\n", repo->module_link); if (repo->section) fprintf(f, "repo.section=%s\n", repo->section); + if (repo->homepage) + fprintf(f, "repo.homepage=%s\n", repo->homepage); if (repo->clone_url) fprintf(f, "repo.clone-url=%s\n", repo->clone_url); fprintf(f, "repo.enable-commit-graph=%d\n", diff --git a/cgit.css b/cgit.css index 82c755c..50f6587 100644 --- a/cgit.css +++ b/cgit.css @@ -85,6 +85,11 @@ div#cgit table.tabs td a.active { background-color: #ccc; } +div#cgit table.tabs a[href^="http://"]:after, div#cgit table.tabs a[href^="https://"]:after { + content: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAQAAAAnOwc2AAAAAnNCSVQICFXsRgQAAAAJcEhZcwAAABQAAAAUAVyMgXwAAAAZdEVYdFNvZnR3YXJlAHd3dy5pbmtzY2FwZS5vcmeb7jwaAAAAeklEQVQI12NoYCu3q3ABwXL98vTy/0D4jaF8XXldRRoYejAwlu8BCTOU72SAg4q08j/le0GC22BC5anlfyrSGBiBGCZYllz+pywLJg8WLOMtf1GeCjRgI5IgSBhMboUIHq40r1CCQrfyDRAV6uXdZTMhsKKlVIIBFwAAVeg4KFYK95cAAAAASUVORK5CYII=); + margin: 0 0 0 5px; +} + div#cgit table.tabs td.form { text-align: right; } diff --git a/cgit.h b/cgit.h index d10c799..325432b 100644 --- a/cgit.h +++ b/cgit.h @@ -81,6 +81,7 @@ struct cgit_repo { char *path; char *desc; char *owner; + char *homepage; char *defbranch; char *module_link; struct string_list readme; diff --git a/cgitrc.5.txt b/cgitrc.5.txt index 47850a8..94901bd 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -205,11 +205,11 @@ enable-git-config:: Flag which, when set to "1", will allow cgit to use git config to set any repo specific settings. This option is used in conjunction with "scan-path", and must be defined prior, to augment repo-specific - settings. The keys gitweb.owner, gitweb.category, and gitweb.description - will map to the cgit keys repo.owner, repo.section, and repo.desc, - respectively. All git config keys that begin with "cgit." will be mapped - to the corresponding "repo." key in cgit. Default value: "0". See also: - scan-path, section-from-path. + settings. The keys gitweb.owner, gitweb.category, gitweb.description, + and gitweb.homepage will map to the cgit keys repo.owner, repo.section, + repo.desc, and repo.homepage respectively. All git config keys that begin + with "cgit." will be mapped to the corresponding "repo." key in cgit. + Default value: "0". See also: scan-path, section-from-path. favicon:: Url used as link to a shortcut icon for cgit. It is suggested to use @@ -496,6 +496,9 @@ repo.defbranch:: repo.desc:: The value to show as repository description. Default value: none. +repo.homepage:: + The value to show as repository homepage. Default value: none. + repo.email-filter:: Override the default email-filter. Default value: none. See also: "enable-filter-overrides". See also: "FILTER API". diff --git a/scan-tree.c b/scan-tree.c index b5a10ff..2e87999 100644 --- a/scan-tree.c +++ b/scan-tree.c @@ -61,6 +61,8 @@ static int gitconfig_config(const char *key, const char *value, void *cb) config_fn(repo, "desc", value); else if (!strcmp(key, "gitweb.category")) config_fn(repo, "section", value); + else if (!strcmp(key, "gitweb.homepage")) + config_fn(repo, "homepage", value); else if (starts_with(key, "cgit.")) config_fn(repo, key + 5, value); diff --git a/shared.c b/shared.c index a078a27..a63633b 100644 --- a/shared.c +++ b/shared.c @@ -54,6 +54,7 @@ struct cgit_repo *cgit_add_repo(const char *url) ret->path = NULL; ret->desc = cgit_default_repo_desc; ret->owner = NULL; + ret->homepage = NULL; ret->section = ctx.cfg.section; ret->snapshots = ctx.cfg.snapshots; ret->enable_commit_graph = ctx.cfg.enable_commit_graph; diff --git a/ui-shared.c b/ui-shared.c index 03dcc08..2c91e75 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -997,6 +997,11 @@ void cgit_print_pageheader(void) if (ctx.repo->max_stats) cgit_stats_link("stats", NULL, hc("stats"), ctx.qry.head, ctx.qry.vpath); + if (ctx.repo->homepage) { + html("homepage"); + } html("
    %s%ld0"SZ_FMT"%lu%ld
    "); html_txt(show_date(info->author_date, info->author_tz, - cgit_date_mode(FMT_LONGDATE))); + cgit_date_mode(DATE_ISO8601))); html("
    committer"); cgit_open_filter(ctx.repo->email_filter, info->committer_email, "commit"); @@ -68,7 +68,7 @@ void cgit_print_commit(char *hex, const char *prefix) cgit_close_filter(ctx.repo->email_filter); html(""); html_txt(show_date(info->committer_date, info->committer_tz, - cgit_date_mode(FMT_LONGDATE))); + cgit_date_mode(DATE_ISO8601))); html("
    commit"); tmp = oid_to_hex(&commit->object.oid); diff --git a/ui-shared.c b/ui-shared.c index d1f9249..03dcc08 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -607,11 +607,10 @@ void cgit_submodule_link(const char *class, char *path, const char *rev) path[len - 1] = tail; } -const struct date_mode *cgit_date_mode(const char *format) +const struct date_mode *cgit_date_mode(enum date_mode_type type) { static struct date_mode mode; - mode.type = DATE_STRFTIME; - mode.strftime_fmt = format; + mode.type = type; mode.local = ctx.cfg.local_time; return &mode; } @@ -620,7 +619,7 @@ static void print_rel_date(time_t t, int tz, double value, const char *class, const char *suffix) { htmlf("%.0f %s", value, suffix); } @@ -637,9 +636,9 @@ void cgit_print_age(time_t t, int tz, time_t max_relative) if (secs > max_relative && max_relative >= 0) { html(""); - html_txt(show_date(t, tz, cgit_date_mode(FMT_SHORTDATE))); + html_txt(show_date(t, tz, cgit_date_mode(DATE_SHORT))); html(""); return; } @@ -781,7 +780,7 @@ void cgit_print_docend(void) else { htmlf("\n"); } html(" \n"); diff --git a/ui-shared.h b/ui-shared.h index 43789de..b457c97 100644 --- a/ui-shared.h +++ b/ui-shared.h @@ -61,7 +61,7 @@ __attribute__((format (printf,1,2))) extern void cgit_print_error(const char *fmt, ...); __attribute__((format (printf,1,0))) extern void cgit_vprint_error(const char *fmt, va_list ap); -extern const struct date_mode *cgit_date_mode(const char *format); +extern const struct date_mode *cgit_date_mode(enum date_mode_type type); extern void cgit_print_age(time_t t, int tz, time_t max_relative); extern void cgit_print_http_headers(void); extern void cgit_redirect(const char *url, bool permanent); diff --git a/ui-tag.c b/ui-tag.c index b011198..6b838cb 100644 --- a/ui-tag.c +++ b/ui-tag.c @@ -77,7 +77,7 @@ void cgit_print_tag(char *revname) if (info->tagger_date > 0) { html("
    tag date"); html_txt(show_date(info->tagger_date, info->tagger_tz, - cgit_date_mode(FMT_LONGDATE))); + cgit_date_mode(DATE_ISO8601))); html("
    "); html("
    Signed-off-by: Jason A. Donenfeld --- ui-plain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui-plain.c b/ui-plain.c index ff85113..97cf639 100644 --- a/ui-plain.c +++ b/ui-plain.c @@ -143,7 +143,7 @@ static int walk_tree(const unsigned char *sha1, struct strbuf *base, walk_tree_ctx->match = 2; return READ_TREE_RECURSIVE; } - } else if (base->len > walk_tree_ctx->match_baselen) { + } else if (base->len < INT_MAX && (int)base->len > walk_tree_ctx->match_baselen) { print_dir_entry(sha1, base->buf, base->len, pathname, mode); walk_tree_ctx->match = 2; } else if (S_ISDIR(mode)) { From a9e9dfc55f5c57a4065be77c320224f524a9c820 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Mon, 22 Feb 2016 23:25:28 +0100 Subject: [PATCH 141/387] git: update to v2.7.2 Update to git version v2.7.2, no changes required. Signed-off-by: Christian Hesse --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 8bd7a0e..c01701c 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = -GIT_VER = 2.7.1 +GIT_VER = 2.7.2 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.gz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index a08595f..326e5bc 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit a08595f76159b09d57553e37a5123f1091bb13e7 +Subproject commit 326e5bc91eecf73234ead29636207bc516573e79 From 1892cd9a603e1eda206c40efb576bd75b7532be6 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Tue, 23 Feb 2016 06:32:03 +0100 Subject: [PATCH 142/387] md2html: Do syntax highlighting too --- filters/html-converters/md2html | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/filters/html-converters/md2html b/filters/html-converters/md2html index 67141ba..c8ee7d9 100755 --- a/filters/html-converters/md2html +++ b/filters/html-converters/md2html @@ -1,5 +1,6 @@ #!/usr/bin/env python import markdown +from pygments.formatters import HtmlFormatter print(''' ''') print("
    ") # Note: you may want to run this through bleach for sanitization -markdown.markdownFromFile(output_format="html5") +markdown.markdownFromFile(output_format="html5", extensions=["markdown.extensions.fenced_code", "markdown.extensions.codehilite", "markdown.extensions.tables"], extension_configs={"markdown.extensions.codehilite":{"css_class":"highlight"}}) print("
    ") From a0d22c391e6e2bbe0d10a888df1ba77a468d5a18 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 23 Feb 2016 10:47:25 +0100 Subject: [PATCH 143/387] css: use less blurry icon for external link Your mileage may vary, but for me the old icon looks blurry. The new one is character 0xf08e from OTF font awsome in size 10. The icon color is black, gray level is adjusted via opacity. Signed-off-by: Christian Hesse --- cgit.css | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cgit.css b/cgit.css index 50f6587..942c9be 100644 --- a/cgit.css +++ b/cgit.css @@ -86,7 +86,8 @@ div#cgit table.tabs td a.active { } div#cgit table.tabs a[href^="http://"]:after, div#cgit table.tabs a[href^="https://"]:after { - content: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAQAAAAnOwc2AAAAAnNCSVQICFXsRgQAAAAJcEhZcwAAABQAAAAUAVyMgXwAAAAZdEVYdFNvZnR3YXJlAHd3dy5pbmtzY2FwZS5vcmeb7jwaAAAAeklEQVQI12NoYCu3q3ABwXL98vTy/0D4jaF8XXldRRoYejAwlu8BCTOU72SAg4q08j/le0GC22BC5anlfyrSGBiBGCZYllz+pywLJg8WLOMtf1GeCjRgI5IgSBhMboUIHq40r1CCQrfyDRAV6uXdZTMhsKKlVIIBFwAAVeg4KFYK95cAAAAASUVORK5CYII=); + content: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAQAAAAnOwc2AAAAAmJLR0QA/4ePzL8AAAAJcEhZcwAACxMAAAsTAQCanBgAAAAHdElNRQfgAhcJDQY+gm2TAAAAHWlUWHRDb21tZW50AAAAAABDcmVhdGVkIHdpdGggR0lNUGQuZQcAAABbSURBVAhbY2BABs4MU4CwhYHBh2Erww4wrGFQZHjI8B8IgUIscJWyDHcggltQhI4zGDCcRwhChPggHIggP1QoAVmQkSETrGoHsiAEsACtBYN0oDAMbgU6EBcAAL2eHUt4XUU4AAAAAElFTkSuQmCC); + opacity: 0.5; margin: 0 0 0 5px; } From 46ff6e1993175057a18b14980696648a1c5e87ab Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Tue, 23 Feb 2016 15:14:06 +0100 Subject: [PATCH 144/387] css: fix indentation --- cgit.css | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cgit.css b/cgit.css index 942c9be..66c6d53 100644 --- a/cgit.css +++ b/cgit.css @@ -18,7 +18,7 @@ div#cgit a:hover { } div#cgit table { - border-collapse: collapse; + border-collapse: collapse; } div#cgit table#header { @@ -803,9 +803,9 @@ div#cgit table.ssdiff td.head div.head { div#cgit table.ssdiff td.foot { border-top: solid 1px #aaa; - border-left: none; - border-right: none; - border-bottom: none; + border-left: none; + border-right: none; + border-bottom: none; } div#cgit table.ssdiff td.space { From c424b5cb0253d8b55d3932efa51aa703dab2bf40 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Tue, 23 Feb 2016 15:35:32 +0100 Subject: [PATCH 145/387] tabs: do not use target=_blank --- ui-shared.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui-shared.c b/ui-shared.c index 2c91e75..3b2dc06 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -1000,7 +1000,7 @@ void cgit_print_pageheader(void) if (ctx.repo->homepage) { html("homepage"); + html("'>homepage"); } html("
    "); html(" Date: Fri, 26 Feb 2016 13:24:35 +0100 Subject: [PATCH 147/387] ui-shared: redirect should not exit early for cache Signed-off-by: Jason A. Donenfeld --- ui-shared.c | 1 - 1 file changed, 1 deletion(-) diff --git a/ui-shared.c b/ui-shared.c index 3b2dc06..9a38aa9 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -702,7 +702,6 @@ void cgit_redirect(const char *url, bool permanent) html("Location: "); html_url_path(url); html("\n\n"); - exit(0); } static void print_rel_vcs_link(const char *url) From 39735d95ca8775204ed4c5f306009707f7da79c6 Mon Sep 17 00:00:00 2001 From: Matt Comben Date: Tue, 8 Mar 2016 12:05:09 +0000 Subject: [PATCH 148/387] Renamed repo-specific configuration for enable-html-serving in cgitrc.5.txt --- cgitrc.5.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cgitrc.5.txt b/cgitrc.5.txt index 94901bd..2e1912d 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -523,7 +523,7 @@ repo.enable-subject-links:: A flag which can be used to override the global setting `enable-subject-links'. Default value: none. -enable-html-serving:: +repo.enable-html-serving:: A flag which can be used to override the global setting `enable-html-serving`. Default value: none. From 499b23979cd29513df16e4c2acce934932e09f7a Mon Sep 17 00:00:00 2001 From: Tim Nordell Date: Fri, 26 Feb 2016 14:57:30 -0600 Subject: [PATCH 149/387] ui-log: Do not always emit decoration span The decoration span does not need to be emited if there aren't any decorations to show. This modification saves slightly on bandwidth. Signed-off-by: Tim Nordell --- ui-log.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ui-log.c b/ui-log.c index 0a3938b..641a5b6 100644 --- a/ui-log.c +++ b/ui-log.c @@ -61,6 +61,8 @@ void show_commit_decorations(struct commit *commit) buf[sizeof(buf) - 1] = 0; deco = get_name_decoration(&commit->object); + if (!deco) + return; html(""); while (deco) { if (starts_with(deco->name, "refs/heads/")) { From 59d8fa1a62e7c19911fdf7ee9ceb0fdf8fa3331c Mon Sep 17 00:00:00 2001 From: Tim Nordell Date: Fri, 26 Feb 2016 14:58:41 -0600 Subject: [PATCH 150/387] ui-log: Simplify decoration code The decoration code inside of git returns the decoration type, so utilize this to create the decoration spans. Additionally, use prettify_refname(...) to get the shorter name for the ref. Signed-off-by: Tim Nordell --- ui-log.c | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/ui-log.c b/ui-log.c index 641a5b6..d6d94f6 100644 --- a/ui-log.c +++ b/ui-log.c @@ -65,36 +65,34 @@ void show_commit_decorations(struct commit *commit) return; html(""); while (deco) { - if (starts_with(deco->name, "refs/heads/")) { - strncpy(buf, deco->name + 11, sizeof(buf) - 1); + strncpy(buf, prettify_refname(deco->name), sizeof(buf) - 1); + switch(deco->type) { + case DECORATION_NONE: + /* If the git-core doesn't recognize it, + * don't display anything. */ + break; + case DECORATION_REF_LOCAL: cgit_log_link(buf, NULL, "branch-deco", buf, NULL, - ctx.qry.vpath, 0, NULL, NULL, - ctx.qry.showmsg, 0); - } - else if (starts_with(deco->name, "tag: refs/tags/")) { - strncpy(buf, deco->name + 15, sizeof(buf) - 1); + ctx.qry.vpath, 0, NULL, NULL, + ctx.qry.showmsg, 0); + break; + case DECORATION_REF_TAG: cgit_tag_link(buf, NULL, "tag-deco", buf); - } - else if (starts_with(deco->name, "refs/tags/")) { - strncpy(buf, deco->name + 10, sizeof(buf) - 1); - cgit_tag_link(buf, NULL, "tag-deco", buf); - } - else if (starts_with(deco->name, "refs/remotes/")) { + break; + case DECORATION_REF_REMOTE: if (!ctx.repo->enable_remote_branches) - goto next; - strncpy(buf, deco->name + 13, sizeof(buf) - 1); + break; cgit_log_link(buf, NULL, "remote-deco", NULL, - oid_to_hex(&commit->object.oid), - ctx.qry.vpath, 0, NULL, NULL, - ctx.qry.showmsg, 0); - } - else { - strncpy(buf, deco->name, sizeof(buf) - 1); + oid_to_hex(&commit->object.oid), + ctx.qry.vpath, 0, NULL, NULL, + ctx.qry.showmsg, 0); + break; + default: cgit_commit_link(buf, NULL, "deco", ctx.qry.head, - oid_to_hex(&commit->object.oid), - ctx.qry.vpath); + oid_to_hex(&commit->object.oid), + ctx.qry.vpath); + break; } -next: deco = deco->next; } html(""); From 86bf5b47916fbe53fe637d7181e93a34d2ad6d0c Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Sat, 30 Apr 2016 16:57:51 +0200 Subject: [PATCH 151/387] git: update to v2.8.2 Update to git version v2.8.2. * Upstream commit 1a0c8dfd89475d6bb09ddee8c019cf0ae5b3bdc2 (strbuf: give strbuf_getline() to the "most text friendly" variant) changed API. Signed-off-by: Christian Hesse --- Makefile | 2 +- git | 2 +- scan-tree.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index c01701c..a7aa08b 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = -GIT_VER = 2.7.2 +GIT_VER = 2.8.2 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.gz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index 326e5bc..60115f5 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 326e5bc91eecf73234ead29636207bc516573e79 +Subproject commit 60115f54bda3a127ed3cc8ffc6ab6c771cbceb1b diff --git a/scan-tree.c b/scan-tree.c index 2e87999..1cb4e5d 100644 --- a/scan-tree.c +++ b/scan-tree.c @@ -246,7 +246,7 @@ void scan_projects(const char *path, const char *projectsfile, repo_config_fn fn projectsfile, strerror(errno), errno); return; } - while (strbuf_getline(&line, projects, '\n') != EOF) { + while (strbuf_getline(&line, projects) != EOF) { if (!line.len) continue; strbuf_insert(&line, 0, "/", 1); From 80f12b3e7e43edcb06aea9811b790b16ca204c81 Mon Sep 17 00:00:00 2001 From: Juuso Lapinlampi Date: Wed, 11 May 2016 17:50:09 +0000 Subject: [PATCH 152/387] ui-shared: Simplify cgit_print_error_page() logic --- ui-shared.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ui-shared.c b/ui-shared.c index 9a38aa9..bf92747 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -792,13 +792,11 @@ void cgit_print_error_page(int code, const char *msg, const char *fmt, ...) ctx.page.expires = ctx.cfg.cache_dynamic_ttl; ctx.page.status = code; ctx.page.statusmsg = msg; - cgit_print_http_headers(); - cgit_print_docstart(); - cgit_print_pageheader(); + cgit_print_layout_start(); va_start(ap, fmt); cgit_vprint_error(fmt, ap); va_end(ap); - cgit_print_docend(); + cgit_print_layout_end(); } void cgit_print_layout_start(void) From 8d05b398bb1f4effcb59dddc62a3ea1f021f8631 Mon Sep 17 00:00:00 2001 From: Juuso Lapinlampi Date: Wed, 11 May 2016 18:04:14 +0000 Subject: [PATCH 153/387] ui-shared: HTML-ize DOCTYPE and Get rid of the XHTML headers, bringing cgit slowly to the modern age of HTML. --- ui-shared.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ui-shared.c b/ui-shared.c index bf92747..1529ff1 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -12,8 +12,7 @@ #include "html.h" static const char cgit_doctype[] = -"\n"; +"\n"; static char *http_date(time_t t) { @@ -723,7 +722,7 @@ void cgit_print_docstart(void) char *host = cgit_hosturl(); html(cgit_doctype); - html("\n"); + html("\n"); html("\n"); html(""); html_txt(ctx.page.title); From 9afda36ed72083febca5e1a249b7f9f09205fe16 Mon Sep 17 00:00:00 2001 From: Juuso Lapinlampi <wub@partyvan.eu> Date: Wed, 11 May 2016 18:04:18 +0000 Subject: [PATCH 154/387] ui-shared: Remove a name attribute with an empty value The name attribute is optional in an input element, but it must not be an empty value. See: https://html.spec.whatwg.org/#attr-fe-name See: https://html.spec.whatwg.org/#the-input-element --- ui-shared.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui-shared.c b/ui-shared.c index 1529ff1..770b685 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -944,7 +944,7 @@ static void print_header(void) if (ctx.repo->enable_remote_branches) for_each_remote_ref(print_branch_option, ctx.qry.head); html("</select> "); - html("<input type='submit' name='' value='switch'/>"); + html("<input type='submit' value='switch'/>"); html("</form>"); } } else From c34e28835bc06ea9f76f440909f59a697910e9e8 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Thu, 12 May 2016 21:29:40 +0200 Subject: [PATCH 155/387] forms: action should not be empty Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- ui-shared.c | 2 +- ui-stats.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ui-shared.c b/ui-shared.c index 770b685..2c88b72 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -937,7 +937,7 @@ static void print_header(void) cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL); if (ctx.env.authenticated) { html("</td><td class='form'>"); - html("<form method='get' action=''>\n"); + html("<form method='get'>\n"); cgit_add_hidden_formfields(0, 1, ctx.qry.page); html("<select name='h' onchange='this.form.submit();'>\n"); for_each_branch_ref(print_branch_option, ctx.qry.head); diff --git a/ui-stats.c b/ui-stats.c index 8cd9178..7acd358 100644 --- a/ui-stats.c +++ b/ui-stats.c @@ -389,7 +389,7 @@ void cgit_show_stats(void) cgit_print_layout_start(); html("<div class='cgit-panel'>"); html("<b>stat options</b>"); - html("<form method='get' action=''>"); + html("<form method='get'>"); cgit_add_hidden_formfields(1, 0, "stats"); html("<table><tr><td colspan='2'/></tr>"); if (ctx.repo->max_stats > 1) { From 21bf30b043c5bcbf4bb92d7e79cb642ab9c2287d Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Thu, 12 May 2016 21:38:59 +0200 Subject: [PATCH 156/387] ui-diff: action='.' is not correct Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- ui-diff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui-diff.c b/ui-diff.c index 52ed942..edee793 100644 --- a/ui-diff.c +++ b/ui-diff.c @@ -340,7 +340,7 @@ void cgit_print_diff_ctrls(void) html("<div class='cgit-panel'>"); html("<b>diff options</b>"); - html("<form method='get' action='.'>"); + html("<form method='get'>"); cgit_add_hidden_formfields(1, 0, ctx.qry.page); html("<table>"); html("<tr><td colspan='2'/></tr>"); From 41508c091186ece4cdc5d79c5ac0d2eda3d3edef Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Thu, 19 May 2016 23:12:03 +0200 Subject: [PATCH 157/387] git: update to v2.8.3 Update to git version v2.8.3, no changes required. Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index a7aa08b..23f5bc1 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.8.2 +GIT_VER = 2.8.3 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.gz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index 60115f5..0f8e831 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 60115f54bda3a127ed3cc8ffc6ab6c771cbceb1b +Subproject commit 0f8e831356d4f1a34baf46bb1a6b2d4c89ec9cb8 From a6572ce1762e0d571c3e96b5f4eff7c81015a1f2 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Tue, 7 Jun 2016 14:31:09 +0200 Subject: [PATCH 158/387] Bump version. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 23f5bc1..30c1dfa 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ all:: -CGIT_VERSION = v0.12 +CGIT_VERSION = v1.0 CGIT_SCRIPT_NAME = cgit.cgi CGIT_SCRIPT_PATH = /var/www/htdocs/cgit CGIT_DATA_PATH = $(CGIT_SCRIPT_PATH) From d88ec849c4f7af41a8a41af1a4f79a2b4d41717a Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Wed, 24 Feb 2016 18:01:42 +0100 Subject: [PATCH 159/387] Hosted on HTTPS now --- README | 4 ++-- cgit.c | 2 +- filters/gentoo-ldap-authentication.lua | 2 +- ui-shared.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README b/README index 917d74a..7a6b4a4 100644 --- a/README +++ b/README @@ -92,8 +92,8 @@ the HTTP headers `Modified` and `Expires`. Online presence --------------- -* The cgit homepage is hosted by cgit at <http://git.zx2c4.com/cgit/about/> +* The cgit homepage is hosted by cgit at <https://git.zx2c4.com/cgit/about/> * Patches, bug reports, discussions and support should go to the cgit mailing list: <cgit@lists.zx2c4.com>. To sign up, visit - <http://lists.zx2c4.com/mailman/listinfo/cgit> + <https://lists.zx2c4.com/mailman/listinfo/cgit> diff --git a/cgit.c b/cgit.c index fc482be..ab3fadb 100644 --- a/cgit.c +++ b/cgit.c @@ -941,7 +941,7 @@ static void cgit_parse_args(int argc, const char **argv) for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "--version")) { - printf("CGit %s | http://git.zx2c4.com/cgit/\n\nCompiled in features:\n", CGIT_VERSION); + printf("CGit %s | https://git.zx2c4.com/cgit/\n\nCompiled in features:\n", CGIT_VERSION); #ifdef NO_LUA printf("[-] "); #else diff --git a/filters/gentoo-ldap-authentication.lua b/filters/gentoo-ldap-authentication.lua index fce5632..6d8eb3e 100644 --- a/filters/gentoo-ldap-authentication.lua +++ b/filters/gentoo-ldap-authentication.lua @@ -4,7 +4,7 @@ -- luacrypto >= 0.3 -- <http://mkottman.github.io/luacrypto/> -- lualdap >= 1.2 --- <http://git.zx2c4.com/lualdap/about/> +-- <https://git.zx2c4.com/lualdap/about/> -- diff --git a/ui-shared.c b/ui-shared.c index 2c88b72..562fa0e 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -776,7 +776,7 @@ void cgit_print_docend(void) if (ctx.cfg.footer) html_include(ctx.cfg.footer); else { - htmlf("<div class='footer'>generated by <a href='http://git.zx2c4.com/cgit/about/'>cgit %s</a> at ", + htmlf("<div class='footer'>generated by <a href='https://git.zx2c4.com/cgit/about/'>cgit %s</a> at ", cgit_version); html_txt(show_date(time(NULL), 0, cgit_date_mode(DATE_ISO8601))); html("</div>\n"); From 7d51120440346108aad74f007431ad65b307f6d7 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Fri, 17 Jun 2016 12:27:10 +0200 Subject: [PATCH 160/387] md2html: use utf-8 and flush output buffer Otherwise we get the classic Python UTF-8 errors, and the text is all out of order. While we're at it, switch to python3 so we only have to support one set of oddball semantics. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> Suggested-by: Daniel Campbell <dlcampbell@gmx.com> --- filters/html-converters/md2html | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/filters/html-converters/md2html b/filters/html-converters/md2html index c8ee7d9..ebf3856 100755 --- a/filters/html-converters/md2html +++ b/filters/html-converters/md2html @@ -1,7 +1,11 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import markdown +import sys +import io from pygments.formatters import HtmlFormatter -print(''' +sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8') +sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') +sys.stdout.write(''' <style> .markdown-body { font-size: 14px; @@ -279,11 +283,12 @@ print(''' border: none; } ''') -print(HtmlFormatter(style='pastie').get_style_defs('.highlight')) -print(''' +sys.stdout.write(HtmlFormatter(style='pastie').get_style_defs('.highlight')) +sys.stdout.write(''' </style> ''') -print("<div class='markdown-body'>") +sys.stdout.write("<div class='markdown-body'>") +sys.stdout.flush() # Note: you may want to run this through bleach for sanitization markdown.markdownFromFile(output_format="html5", extensions=["markdown.extensions.fenced_code", "markdown.extensions.codehilite", "markdown.extensions.tables"], extension_configs={"markdown.extensions.codehilite":{"css_class":"highlight"}}) -print("</div>") +sys.stdout.write("</div>") From 5062fbe7ec16c4f736bca9aab68dde101d6d6163 Mon Sep 17 00:00:00 2001 From: Kylie McClain <somasis@exherbo.org> Date: Tue, 7 Jun 2016 17:22:35 -0400 Subject: [PATCH 161/387] cgit.mk: Use $PKG_CONFIG PKG_CONFIG is a variable dictated by autoconf standards; it should be used if set. --- cgit.mk | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cgit.mk b/cgit.mk index 1b50307..369f309 100644 --- a/cgit.mk +++ b/cgit.mk @@ -21,6 +21,8 @@ CGIT_CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"' CGIT_CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"' CGIT_CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"' +PKG_CONFIG ?= pkg-config + ifdef NO_C99_FORMAT CFLAGS += -DNO_C99_FORMAT endif @@ -31,7 +33,7 @@ ifdef NO_LUA else ifeq ($(LUA_PKGCONFIG),) LUA_PKGCONFIG := $(shell for pc in luajit lua lua5.2 lua5.1; do \ - pkg-config --exists $$pc 2>/dev/null && echo $$pc && break; \ + $(PKG_CONFIG) --exists $$pc 2>/dev/null && echo $$pc && break; \ done) LUA_MODE := autodetected else @@ -39,8 +41,8 @@ else endif ifneq ($(LUA_PKGCONFIG),) LUA_MESSAGE := linking with $(LUA_MODE) $(LUA_PKGCONFIG) - LUA_LIBS := $(shell pkg-config --libs $(LUA_PKGCONFIG) 2>/dev/null) - LUA_CFLAGS := $(shell pkg-config --cflags $(LUA_PKGCONFIG) 2>/dev/null) + LUA_LIBS := $(shell $(PKG_CONFIG) --libs $(LUA_PKGCONFIG) 2>/dev/null) + LUA_CFLAGS := $(shell $(PKG_CONFIG) --cflags $(LUA_PKGCONFIG) 2>/dev/null) CGIT_LIBS += $(LUA_LIBS) CGIT_CFLAGS += $(LUA_CFLAGS) else From 1e039ada8554c7e2fc65524827c61613a24256fb Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Mon, 13 Jun 2016 22:57:12 +0200 Subject: [PATCH 162/387] git: update to v2.9.0 Update to git version v2.9.0, no changes required. Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 30c1dfa..c7a57f8 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.8.3 +GIT_VER = 2.9.0 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.gz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index 0f8e831..05219a1 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 0f8e831356d4f1a34baf46bb1a6b2d4c89ec9cb8 +Subproject commit 05219a1276341e72d8082d76b7f5ed394b7437a4 From 9984e7ab49c59e49a0d7e62c3435e7133f7a53ec Mon Sep 17 00:00:00 2001 From: Lukas Fleischer <lfleischer@lfos.de> Date: Tue, 24 May 2016 18:15:18 +0200 Subject: [PATCH 163/387] Avoid ambiguities when prettifying snapshot names When composing snapshot file names for a tag with a prefix of the form v[0-9] (resp. V[0-9]), the leading "v" (resp. "V") is stripped. This leads to conflicts if a tag with the stripped name already exists or if there are tags only differing in the capitalization of the leading "v". Make sure we do not strip the "v" in these cases. Reported-by: Juuso Lapinlampi <wub@partyvan.eu> Signed-off-by: Lukas Fleischer <lfleischer@lfos.de> --- ui-refs.c | 24 +++++++++--------------- ui-shared.c | 26 +++++++++++++++++++++----- ui-shared.h | 2 ++ 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/ui-refs.c b/ui-refs.c index 5b4530e..75f2789 100644 --- a/ui-refs.c +++ b/ui-refs.c @@ -93,34 +93,28 @@ static void print_tag_header(void) static void print_tag_downloads(const struct cgit_repo *repo, const char *ref) { const struct cgit_snapshot_format* f; - struct strbuf filename = STRBUF_INIT; const char *basename; - int free_ref = 0; + struct strbuf filename = STRBUF_INIT; + size_t prefixlen; if (!ref || strlen(ref) < 1) return; basename = cgit_repobasename(repo->url); - if (!starts_with(ref, basename)) { - if ((ref[0] == 'v' || ref[0] == 'V') && isdigit(ref[1])) - ref++; - if (isdigit(ref[0])) { - ref = fmtalloc("%s-%s", basename, ref); - free_ref = 1; - } - } - + if (starts_with(ref, basename)) + strbuf_addstr(&filename, ref); + else + cgit_compose_snapshot_prefix(&filename, basename, ref); + prefixlen = filename.len; for (f = cgit_snapshot_formats; f->suffix; f++) { if (!(repo->snapshots & f->bit)) continue; - strbuf_reset(&filename); - strbuf_addf(&filename, "%s%s", ref, f->suffix); + strbuf_setlen(&filename, prefixlen); + strbuf_addstr(&filename, f->suffix); cgit_snapshot_link(filename.buf, NULL, NULL, NULL, NULL, filename.buf); html("  "); } - if (free_ref) - free((char *)ref); strbuf_release(&filename); } diff --git a/ui-shared.c b/ui-shared.c index 562fa0e..b1a6c46 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -1069,18 +1069,34 @@ void cgit_print_filemode(unsigned short mode) html_fileperm(mode); } +void cgit_compose_snapshot_prefix(struct strbuf *filename, const char *base, + const char *ref) +{ + unsigned char sha1[20]; + + /* + * Prettify snapshot names by stripping leading "v" or "V" if the tag + * name starts with {v,V}[0-9] and the prettify mapping is injective, + * i.e. each stripped tag can be inverted without ambiguities. + */ + if (get_sha1(fmt("refs/tags/%s", ref), sha1) == 0 && + (ref[0] == 'v' || ref[0] == 'V') && isdigit(ref[1]) && + ((get_sha1(fmt("refs/tags/%s", ref + 1), sha1) == 0) + + (get_sha1(fmt("refs/tags/v%s", ref + 1), sha1) == 0) + + (get_sha1(fmt("refs/tags/V%s", ref + 1), sha1) == 0) == 1)) + ref++; + + strbuf_addf(filename, "%s-%s", base, ref); +} + void cgit_print_snapshot_links(const char *repo, const char *head, const char *hex, int snapshots) { const struct cgit_snapshot_format* f; struct strbuf filename = STRBUF_INIT; size_t prefixlen; - unsigned char sha1[20]; - if (get_sha1(fmt("refs/tags/%s", hex), sha1) == 0 && - (hex[0] == 'v' || hex[0] == 'V') && isdigit(hex[1])) - hex++; - strbuf_addf(&filename, "%s-%s", cgit_repobasename(repo), hex); + cgit_compose_snapshot_prefix(&filename, cgit_repobasename(repo), hex); prefixlen = filename.len; for (f = cgit_snapshot_formats; f->suffix; f++) { if (!(snapshots & f->bit)) diff --git a/ui-shared.h b/ui-shared.h index b457c97..87799f1 100644 --- a/ui-shared.h +++ b/ui-shared.h @@ -71,6 +71,8 @@ __attribute__((format (printf,3,4))) extern void cgit_print_error_page(int code, const char *msg, const char *fmt, ...); extern void cgit_print_pageheader(void); extern void cgit_print_filemode(unsigned short mode); +extern void cgit_compose_snapshot_prefix(struct strbuf *filename, + const char *base, const char *ref); extern void cgit_print_snapshot_links(const char *repo, const char *head, const char *hex, int snapshots); extern void cgit_add_hidden_formfields(int incl_head, int incl_search, From 4fb49864db51affddf37ab2a563b0eb4b33e155d Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Wed, 29 Jun 2016 09:37:57 +0200 Subject: [PATCH 164/387] ui-log: color line changes Signed-off-by: Christian Hesse <mail@eworm.de> --- cgit.css | 9 +++++++++ ui-log.c | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/cgit.css b/cgit.css index 66c6d53..983eac5 100644 --- a/cgit.css +++ b/cgit.css @@ -590,6 +590,15 @@ div#cgit span.age-months { div#cgit span.age-years { color: #bbb; } + +div#cgit span.insertions { + color: #080; +} + +div#cgit span.deletions { + color: #800; +} + div#cgit div.footer { margin-top: 0.5em; text-align: center; diff --git a/ui-log.c b/ui-log.c index d6d94f6..c97b8e0 100644 --- a/ui-log.c +++ b/ui-log.c @@ -258,7 +258,8 @@ static void print_commit(struct commit *commit, struct rev_info *revs) if (ctx.repo->enable_log_filecount) htmlf("</td><td>%d", files); if (ctx.repo->enable_log_linecount) - htmlf("</td><td>-%d/+%d", rem_lines, add_lines); + htmlf("</td><td><span class='deletions'>-%d</span>/" + "<span class='insertions'>+%d</span>", rem_lines, add_lines); html("</td></tr>\n"); From c19d983ed7b86face56e41effea4fffcf9ad1e19 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Wed, 29 Jun 2016 09:37:58 +0200 Subject: [PATCH 165/387] css: consistent use of empty lines Signed-off-by: Christian Hesse <mail@eworm.de> --- cgit.css | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cgit.css b/cgit.css index 983eac5..a4331f8 100644 --- a/cgit.css +++ b/cgit.css @@ -605,13 +605,16 @@ div#cgit div.footer { font-size: 80%; color: #ccc; } + div#cgit div.footer a { color: #ccc; text-decoration: none; } + div#cgit div.footer a:hover { text-decoration: underline; } + div#cgit a.branch-deco { color: #000; margin: 0px 0.5em; @@ -619,6 +622,7 @@ div#cgit a.branch-deco { background-color: #88ff88; border: solid 1px #007700; } + div#cgit a.tag-deco { color: #000; margin: 0px 0.5em; @@ -626,6 +630,7 @@ div#cgit a.tag-deco { background-color: #ffff88; border: solid 1px #777700; } + div#cgit a.remote-deco { color: #000; margin: 0px 0.5em; @@ -633,6 +638,7 @@ div#cgit a.remote-deco { background-color: #ccccff; border: solid 1px #000077; } + div#cgit a.deco { color: #000; margin: 0px 0.5em; From 590ba455d694deaf2ec206510cf7f047ac365a96 Mon Sep 17 00:00:00 2001 From: Eric Wong <normalperson@yhbt.net> Date: Wed, 6 Jul 2016 07:08:01 +0000 Subject: [PATCH 166/387] ui-shared: fix segfault when defbranch is NULL Not sure if there's a better fix for this. defbranch is NULL here on my setup when a crawler hit an invalid URL, causing strcmp to segfault. Signed-off-by: Eric Wong <normalperson@yhbt.net> --- ui-shared.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui-shared.c b/ui-shared.c index b1a6c46..e39d004 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -253,7 +253,7 @@ static char *repolink(const char *title, const char *class, const char *page, } delim = "&"; } - if (head && strcmp(head, ctx.repo->defbranch)) { + if (head && ctx.repo->defbranch && strcmp(head, ctx.repo->defbranch)) { html(delim); html("h="); html_url_arg(head); From ccf79b3576d20a65db081725636529641a28d3c9 Mon Sep 17 00:00:00 2001 From: Peter Colberg <peter@colberg.org> Date: Fri, 10 Jun 2016 10:29:07 -0400 Subject: [PATCH 167/387] Fix spelling in man page Signed-off-by: Peter Colberg <peter@colberg.org> --- cgitrc.5.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cgitrc.5.txt b/cgitrc.5.txt index 2e1912d..9fcf445 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -676,14 +676,14 @@ commit filter:: expected on standard output. email filter:: - This filter is given two parameters: the email address of the relevent + This filter is given two parameters: the email address of the relevant author and a string indicating the originating page. The filter will then receive the text string to format on standard input and is expected to write to standard output the formatted text to be included in the page. owner filter:: - This filter is given no arguments. The owner text is avilable on + This filter is given no arguments. The owner text is available on standard input and the filter is expected to write to standard output. The output is included in the Owner column. From 40fbefba0514b33988d453aea05aa2b956e98f84 Mon Sep 17 00:00:00 2001 From: Peter Colberg <peter@colberg.org> Date: Fri, 1 Jul 2016 22:00:37 -0400 Subject: [PATCH 168/387] Link with -ldl on GNU/kFreeBSD GNU/kFreeBSD uses the FreeBSD kernel with the GNU C library. Signed-off-by: Peter Colberg <peter@colberg.org> --- cgit.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cgit.mk b/cgit.mk index 369f309..8d4f5e0 100644 --- a/cgit.mk +++ b/cgit.mk @@ -53,8 +53,8 @@ endif endif -# Add -ldl to linker flags on non-BSD systems. -ifeq ($(findstring BSD,$(uname_S)),) +# Add -ldl to linker flags on systems that commonly use GNU libc. +ifneq (,$(filter $(uname_S),Linux GNU/kFreeBSD)) CGIT_LIBS += -ldl endif From d6b0332982234c73a26119e4ed60d442870b8078 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Tue, 12 Jul 2016 00:42:41 +0200 Subject: [PATCH 169/387] git: update to v2.9.1 Update to git version v2.9.1, no changes required. Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index c7a57f8..9d067d4 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.9.0 +GIT_VER = 2.9.1 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.gz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index 05219a1..5c9159d 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 05219a1276341e72d8082d76b7f5ed394b7437a4 +Subproject commit 5c9159de87e41cf14ec5f2132afb5a06f35c26b3 From ff9893ac8192579a00dd4c73ddff18ab232099a6 Mon Sep 17 00:00:00 2001 From: Richard Maw <richard.maw@gmail.com> Date: Sat, 2 Jul 2016 20:28:10 +0100 Subject: [PATCH 170/387] Fix qry.head leak on error This is run soon before exiting so it wasn't leaked for long. Signed-off-by: Richard Maw <richard.maw@gmail.com> --- cgit.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cgit.c b/cgit.c index ab3fadb..9427c4a 100644 --- a/cgit.c +++ b/cgit.c @@ -616,11 +616,11 @@ static int prepare_repo_cmd(void) } if (get_sha1(ctx.qry.head, sha1)) { - char *tmp = xstrdup(ctx.qry.head); - ctx.qry.head = ctx.repo->defbranch; + char *old_head = ctx.qry.head; + ctx.qry.head = xstrdup(ctx.repo->defbranch); cgit_print_error_page(404, "Not found", - "Invalid branch: %s", tmp); - free(tmp); + "Invalid branch: %s", old_head); + free(old_head); return 1; } string_list_sort(&ctx.repo->submodules); From 11695a58fd732689be486edf88d145578a787c89 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Sun, 4 Sep 2016 12:38:18 +0200 Subject: [PATCH 171/387] git: update to v2.10.0 Upstream continues to replace unsigned char *sha1 with struct object_id old_oid. This makes the required changes. The git lib has its own main function now. Rename our main function to cmd_main, it is called from main then. --- Makefile | 2 +- cgit.c | 2 +- cgit.h | 8 +++--- git | 2 +- shared.c | 28 ++++++++++---------- ui-diff.c | 74 ++++++++++++++++++++++++++--------------------------- ui-diff.h | 4 +-- ui-log.c | 2 +- ui-ssdiff.c | 4 +-- 9 files changed, 63 insertions(+), 63 deletions(-) diff --git a/Makefile b/Makefile index 9d067d4..821cfb3 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.9.1 +GIT_VER = 2.10.0 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.gz INSTALL = install COPYTREE = cp -r diff --git a/cgit.c b/cgit.c index 9427c4a..2f29aa6 100644 --- a/cgit.c +++ b/cgit.c @@ -1026,7 +1026,7 @@ static int calc_ttl(void) return ctx.cfg.cache_repo_ttl; } -int main(int argc, const char **argv) +int cmd_main(int argc, const char **argv) { const char *path; int err, ttl; diff --git a/cgit.h b/cgit.h index 325432b..f34395c 100644 --- a/cgit.h +++ b/cgit.h @@ -348,14 +348,14 @@ extern void *cgit_free_commitinfo(struct commitinfo *info); void cgit_diff_tree_cb(struct diff_queue_struct *q, struct diff_options *options, void *data); -extern int cgit_diff_files(const unsigned char *old_sha1, - const unsigned char *new_sha1, +extern int cgit_diff_files(const struct object_id *old_oid, + const struct object_id *new_oid, unsigned long *old_size, unsigned long *new_size, int *binary, int context, int ignorews, linediff_fn fn); -extern void cgit_diff_tree(const unsigned char *old_sha1, - const unsigned char *new_sha1, +extern void cgit_diff_tree(const struct object_id *old_oid, + const struct object_id *new_oid, filepair_fn fn, const char *prefix, int ignorews); extern void cgit_diff_commit(struct commit *commit, filepair_fn fn, diff --git a/git b/git index 5c9159d..6ebdac1 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 5c9159de87e41cf14ec5f2132afb5a06f35c26b3 +Subproject commit 6ebdac1bab966b720d776aa43ca188fe378b1f4b diff --git a/shared.c b/shared.c index a63633b..a48eea6 100644 --- a/shared.c +++ b/shared.c @@ -263,15 +263,15 @@ void cgit_diff_tree_cb(struct diff_queue_struct *q, } } -static int load_mmfile(mmfile_t *file, const unsigned char *sha1) +static int load_mmfile(mmfile_t *file, const struct object_id *oid) { enum object_type type; - if (is_null_sha1(sha1)) { + if (is_null_oid(oid)) { file->ptr = (char *)""; file->size = 0; } else { - file->ptr = read_sha1_file(sha1, &type, + file->ptr = read_sha1_file(oid->hash, &type, (unsigned long *)&file->size); } return 1; @@ -322,8 +322,8 @@ static int filediff_cb(void *priv, mmbuffer_t *mb, int nbuf) return 0; } -int cgit_diff_files(const unsigned char *old_sha1, - const unsigned char *new_sha1, unsigned long *old_size, +int cgit_diff_files(const struct object_id *old_oid, + const struct object_id *new_oid, unsigned long *old_size, unsigned long *new_size, int *binary, int context, int ignorews, linediff_fn fn) { @@ -332,7 +332,7 @@ int cgit_diff_files(const unsigned char *old_sha1, xdemitconf_t emit_params; xdemitcb_t emit_cb; - if (!load_mmfile(&file1, old_sha1) || !load_mmfile(&file2, new_sha1)) + if (!load_mmfile(&file1, old_oid) || !load_mmfile(&file2, new_oid)) return 1; *old_size = file1.size; @@ -366,8 +366,8 @@ int cgit_diff_files(const unsigned char *old_sha1, return 0; } -void cgit_diff_tree(const unsigned char *old_sha1, - const unsigned char *new_sha1, +void cgit_diff_tree(const struct object_id *old_oid, + const struct object_id *new_oid, filepair_fn fn, const char *prefix, int ignorews) { struct diff_options opt; @@ -391,21 +391,21 @@ void cgit_diff_tree(const unsigned char *old_sha1, } diff_setup_done(&opt); - if (old_sha1 && !is_null_sha1(old_sha1)) - diff_tree_sha1(old_sha1, new_sha1, "", &opt); + if (old_oid && !is_null_oid(old_oid)) + diff_tree_sha1(old_oid->hash, new_oid->hash, "", &opt); else - diff_root_tree_sha1(new_sha1, "", &opt); + diff_root_tree_sha1(new_oid->hash, "", &opt); diffcore_std(&opt); diff_flush(&opt); } void cgit_diff_commit(struct commit *commit, filepair_fn fn, const char *prefix) { - unsigned char *old_sha1 = NULL; + const struct object_id *old_oid = NULL; if (commit->parents) - old_sha1 = commit->parents->item->object.oid.hash; - cgit_diff_tree(old_sha1, commit->object.oid.hash, fn, prefix, + old_oid = &commit->parents->item->object.oid; + cgit_diff_tree(old_oid, &commit->object.oid, fn, prefix, ctx.qry.ignorews); } diff --git a/ui-diff.c b/ui-diff.c index edee793..173d351 100644 --- a/ui-diff.c +++ b/ui-diff.c @@ -12,8 +12,8 @@ #include "ui-shared.h" #include "ui-ssdiff.h" -unsigned char old_rev_sha1[20]; -unsigned char new_rev_sha1[20]; +struct object_id old_rev_oid[1]; +struct object_id new_rev_oid[1]; static int files, slots; static int total_adds, total_rems, max_changes; @@ -21,8 +21,8 @@ static int lines_added, lines_removed; static struct fileinfo { char status; - unsigned char old_sha1[20]; - unsigned char new_sha1[20]; + struct object_id old_oid[1]; + struct object_id new_oid[1]; unsigned short old_mode; unsigned short new_mode; char *old_path; @@ -83,15 +83,15 @@ static void print_fileinfo(struct fileinfo *info) html("<tr>"); htmlf("<td class='mode'>"); - if (is_null_sha1(info->new_sha1)) { + if (is_null_oid(info->new_oid)) { cgit_print_filemode(info->old_mode); } else { cgit_print_filemode(info->new_mode); } if (info->old_mode != info->new_mode && - !is_null_sha1(info->old_sha1) && - !is_null_sha1(info->new_sha1)) { + !is_null_oid(info->old_oid) && + !is_null_oid(info->new_oid)) { html("<span class='modechange'>["); cgit_print_filemode(info->old_mode); html("]</span>"); @@ -160,7 +160,7 @@ static void inspect_filepair(struct diff_filepair *pair) files++; lines_added = 0; lines_removed = 0; - cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, &new_size, + cgit_diff_files(&pair->one->oid, &pair->two->oid, &old_size, &new_size, &binary, 0, ctx.qry.ignorews, count_diff_lines); if (files >= slots) { if (slots == 0) @@ -170,8 +170,8 @@ static void inspect_filepair(struct diff_filepair *pair) items = xrealloc(items, slots * sizeof(struct fileinfo)); } items[files-1].status = pair->status; - hashcpy(items[files-1].old_sha1, pair->one->sha1); - hashcpy(items[files-1].new_sha1, pair->two->sha1); + oidcpy(items[files-1].old_oid, &pair->one->oid); + oidcpy(items[files-1].new_oid, &pair->two->oid); items[files-1].old_mode = pair->one->mode; items[files-1].new_mode = pair->two->mode; items[files-1].old_path = xstrdup(pair->one->path); @@ -187,8 +187,8 @@ static void inspect_filepair(struct diff_filepair *pair) total_rems += lines_removed; } -static void cgit_print_diffstat(const unsigned char *old_sha1, - const unsigned char *new_sha1, +static void cgit_print_diffstat(const struct object_id *old_oid, + const struct object_id *new_oid, const char *prefix) { int i; @@ -204,7 +204,7 @@ static void cgit_print_diffstat(const unsigned char *old_sha1, html("</div>"); html("<table summary='diffstat' class='diffstat'>"); max_changes = 0; - cgit_diff_tree(old_sha1, new_sha1, inspect_filepair, prefix, + cgit_diff_tree(old_oid, new_oid, inspect_filepair, prefix, ctx.qry.ignorews); for (i = 0; i<files; i++) print_fileinfo(&items[i]); @@ -238,8 +238,8 @@ static void print_line(char *line, int len) line[len-1] = c; } -static void header(unsigned char *sha1, char *path1, int mode1, - unsigned char *sha2, char *path2, int mode2) +static void header(const struct object_id *oid1, char *path1, int mode1, + const struct object_id *oid2, char *path2, int mode2) { char *abbrev1, *abbrev2; int subproject; @@ -258,8 +258,8 @@ static void header(unsigned char *sha1, char *path1, int mode1, htmlf("<br/>deleted file mode %.6o", mode1); if (!subproject) { - abbrev1 = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV)); - abbrev2 = xstrdup(find_unique_abbrev(sha2, DEFAULT_ABBREV)); + abbrev1 = xstrdup(find_unique_abbrev(oid1->hash, DEFAULT_ABBREV)); + abbrev2 = xstrdup(find_unique_abbrev(oid2->hash, DEFAULT_ABBREV)); htmlf("<br/>index %s..%s", abbrev1, abbrev2); free(abbrev1); free(abbrev2); @@ -268,24 +268,24 @@ static void header(unsigned char *sha1, char *path1, int mode1, if (mode2 != mode1) htmlf("..%.6o", mode2); } - if (is_null_sha1(sha1)) { + if (is_null_oid(oid1)) { path1 = "dev/null"; html("<br/>--- /"); } else html("<br/>--- a/"); if (mode1 != 0) cgit_tree_link(path1, NULL, NULL, ctx.qry.head, - sha1_to_hex(old_rev_sha1), path1); + oid_to_hex(old_rev_oid), path1); else html_txt(path1); - if (is_null_sha1(sha2)) { + if (is_null_oid(oid2)) { path2 = "dev/null"; html("<br/>+++ /"); } else html("<br/>+++ b/"); if (mode2 != 0) cgit_tree_link(path2, NULL, NULL, ctx.qry.head, - sha1_to_hex(new_rev_sha1), path2); + oid_to_hex(new_rev_oid), path2); else html_txt(path2); } @@ -307,20 +307,20 @@ static void filepair_cb(struct diff_filepair *pair) cgit_ssdiff_header_begin(); print_line_fn = cgit_ssdiff_line_cb; } - header(pair->one->sha1, pair->one->path, pair->one->mode, - pair->two->sha1, pair->two->path, pair->two->mode); + header(&pair->one->oid, pair->one->path, pair->one->mode, + &pair->two->oid, pair->two->path, pair->two->mode); if (use_ssdiff) cgit_ssdiff_header_end(); if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) { if (S_ISGITLINK(pair->one->mode)) - print_line_fn(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52); + print_line_fn(fmt("-Subproject %s", oid_to_hex(&pair->one->oid)), 52); if (S_ISGITLINK(pair->two->mode)) - print_line_fn(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52); + print_line_fn(fmt("+Subproject %s", oid_to_hex(&pair->two->oid)), 52); if (use_ssdiff) cgit_ssdiff_footer(); return; } - if (cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, + if (cgit_diff_files(&pair->one->oid, &pair->two->oid, &old_size, &new_size, &binary, ctx.qry.context, ctx.qry.ignorews, print_line_fn)) cgit_print_error("Error running diff"); @@ -402,36 +402,36 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, if (!new_rev) new_rev = ctx.qry.head; - if (get_sha1(new_rev, new_rev_sha1)) { + if (get_oid(new_rev, new_rev_oid)) { cgit_print_error_page(404, "Not found", "Bad object name: %s", new_rev); return; } - commit = lookup_commit_reference(new_rev_sha1); + commit = lookup_commit_reference(new_rev_oid->hash); if (!commit || parse_commit(commit)) { cgit_print_error_page(404, "Not found", - "Bad commit: %s", sha1_to_hex(new_rev_sha1)); + "Bad commit: %s", oid_to_hex(new_rev_oid)); return; } new_tree_sha1 = commit->tree->object.oid.hash; if (old_rev) { - if (get_sha1(old_rev, old_rev_sha1)) { + if (get_oid(old_rev, old_rev_oid)) { cgit_print_error_page(404, "Not found", "Bad object name: %s", old_rev); return; } } else if (commit->parents && commit->parents->item) { - hashcpy(old_rev_sha1, commit->parents->item->object.oid.hash); + oidcpy(old_rev_oid, &commit->parents->item->object.oid); } else { - hashclr(old_rev_sha1); + oidclr(old_rev_oid); } - if (!is_null_sha1(old_rev_sha1)) { - commit2 = lookup_commit_reference(old_rev_sha1); + if (!is_null_oid(old_rev_oid)) { + commit2 = lookup_commit_reference(old_rev_oid->hash); if (!commit2 || parse_commit(commit2)) { cgit_print_error_page(404, "Not found", - "Bad commit: %s", sha1_to_hex(old_rev_sha1)); + "Bad commit: %s", oid_to_hex(old_rev_oid)); return; } old_tree_sha1 = commit2->tree->object.oid.hash; @@ -479,7 +479,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, if (difftype == DIFF_STATONLY) ctx.qry.difftype = ctx.cfg.difftype; - cgit_print_diffstat(old_rev_sha1, new_rev_sha1, prefix); + cgit_print_diffstat(old_rev_oid, new_rev_oid, prefix); if (difftype == DIFF_STATONLY) return; @@ -490,7 +490,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, html("<table summary='diff' class='diff'>"); html("<tr><td>"); } - cgit_diff_tree(old_rev_sha1, new_rev_sha1, filepair_cb, prefix, + cgit_diff_tree(old_rev_oid, new_rev_oid, filepair_cb, prefix, ctx.qry.ignorews); if (!use_ssdiff) html("</td></tr>"); diff --git a/ui-diff.h b/ui-diff.h index 382e8c5..39264a1 100644 --- a/ui-diff.h +++ b/ui-diff.h @@ -9,7 +9,7 @@ extern void cgit_print_diff(const char *new_hex, const char *old_hex, extern struct diff_filespec *cgit_get_current_old_file(void); extern struct diff_filespec *cgit_get_current_new_file(void); -extern unsigned char old_rev_sha1[20]; -extern unsigned char new_rev_sha1[20]; +extern struct object_id old_rev_oid[1]; +extern struct object_id new_rev_oid[1]; #endif /* UI_DIFF_H */ diff --git a/ui-log.c b/ui-log.c index c97b8e0..a31ff7c 100644 --- a/ui-log.c +++ b/ui-log.c @@ -49,7 +49,7 @@ static void inspect_files(struct diff_filepair *pair) files++; if (ctx.repo->enable_log_linecount) - cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, + cgit_diff_files(&pair->one->oid, &pair->two->oid, &old_size, &new_size, &binary, 0, ctx.qry.ignorews, count_lines); } diff --git a/ui-ssdiff.c b/ui-ssdiff.c index d183d40..16c812f 100644 --- a/ui-ssdiff.c +++ b/ui-ssdiff.c @@ -229,7 +229,7 @@ static void print_ssdiff_line(char *class, if (old_line_no > 0) { struct diff_filespec *old_file = cgit_get_current_old_file(); char *lineno_str = fmt("n%d", old_line_no); - char *id_str = fmt("id=%s#%s", is_null_sha1(old_file->sha1)?"HEAD":sha1_to_hex(old_rev_sha1), lineno_str); + char *id_str = fmt("id=%s#%s", is_null_oid(&old_file->oid)?"HEAD":oid_to_hex(old_rev_oid), lineno_str); char *fileurl = cgit_fileurl(ctx.repo->url, "tree", old_file->path, id_str); html("<td class='lineno'><a href='"); html(fileurl); @@ -252,7 +252,7 @@ static void print_ssdiff_line(char *class, if (new_line_no > 0) { struct diff_filespec *new_file = cgit_get_current_new_file(); char *lineno_str = fmt("n%d", new_line_no); - char *id_str = fmt("id=%s#%s", is_null_sha1(new_file->sha1)?"HEAD":sha1_to_hex(new_rev_sha1), lineno_str); + char *id_str = fmt("id=%s#%s", is_null_oid(&new_file->oid)?"HEAD":oid_to_hex(new_rev_oid), lineno_str); char *fileurl = cgit_fileurl(ctx.repo->url, "tree", new_file->path, id_str); html("<td class='lineno'><a href='"); html(fileurl); From 35df710a1fa21b62c5328e2c98f29a68a0312a25 Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Sun, 7 Aug 2016 15:54:14 +0100 Subject: [PATCH 172/387] configfile: fix EOF handling Currently we can end up passing EOF to isspace(), which is in fact libgit's sane_isspace which does: ((sane_ctype[(unsigned char)(x)] & (GIT_SPACE)) != 0) It is very unlikely that EOF cast to "unsigned char" will end up in a character that has the GIT_SPACE bit set, but the standard only requires that EOF be a negative integer, so it could access any value in the sane_ctype array. If it does end up returning true for isspace() then this loop will never terminate, so handle EOF as a special value in the same way as the other loops in this function. Signed-off-by: John Keeping <john@keeping.me.uk> --- configfile.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/configfile.c b/configfile.c index 5b0d880..e039109 100644 --- a/configfile.c +++ b/configfile.c @@ -39,7 +39,9 @@ static int read_config_line(FILE *f, struct strbuf *name, struct strbuf *value) /* Skip comments and preceding spaces. */ for(;;) { - if (c == '#' || c == ';') + if (c == EOF) + return 0; + else if (c == '#' || c == ';') skip_line(f); else if (!isspace(c)) break; From bead27b730526e4501ebaeb3b7c1116cd09f7b93 Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Sun, 7 Aug 2016 16:13:30 +0100 Subject: [PATCH 173/387] ui-shared: fix decl-after-statement warnings git.git's coding style avoids decl-after-statement and we generally try to follow it but a few warnings have crept in recently. Fix the ones in ui-shared.c Signed-off-by: John Keeping <john@keeping.me.uk> --- ui-shared.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/ui-shared.c b/ui-shared.c index e39d004..3fa36d6 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -66,10 +66,11 @@ char *cgit_hosturl(void) char *cgit_currenturl(void) { - if (!ctx.qry.url) - return xstrdup(cgit_rooturl()); const char *root = cgit_rooturl(); size_t len = strlen(root); + + if (!ctx.qry.url) + return xstrdup(root); if (len && root[len - 1] == '/') return fmtalloc("%s%s", root, ctx.qry.url); return fmtalloc("%s/%s", root, ctx.qry.url); @@ -349,6 +350,8 @@ void cgit_log_link(const char *name, const char *title, const char *class, void cgit_commit_link(char *name, const char *title, const char *class, const char *head, const char *rev, const char *path) { + char *delim; + if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) { name[ctx.cfg.max_msg_len] = '\0'; name[ctx.cfg.max_msg_len - 1] = '.'; @@ -356,8 +359,6 @@ void cgit_commit_link(char *name, const char *title, const char *class, name[ctx.cfg.max_msg_len - 3] = '.'; } - char *delim; - delim = repolink(title, class, "commit", head, path); if (rev && ctx.qry.head && strcmp(rev, ctx.qry.head)) { html(delim); @@ -714,13 +715,14 @@ static void print_rel_vcs_link(const char *url) void cgit_print_docstart(void) { + char *host = cgit_hosturl(); + if (ctx.cfg.embedded) { if (ctx.cfg.header) html_include(ctx.cfg.header); return; } - char *host = cgit_hosturl(); html(cgit_doctype); html("<html lang='en'>\n"); html("<head>\n"); From 7e67c64894b1093fbc009edd811fee1e76daa2d7 Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Sun, 7 Aug 2016 16:14:49 +0100 Subject: [PATCH 174/387] ui-ssdiff: fix decl-after-statement warnings git.git's coding style avoids decl-after-statement and we generally try to follow it but a few warnings have crept in recently. Fix the one in ui-ssdiff.c Signed-off-by: John Keeping <john@keeping.me.uk> --- ui-ssdiff.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui-ssdiff.c b/ui-ssdiff.c index 16c812f..7f261ed 100644 --- a/ui-ssdiff.c +++ b/ui-ssdiff.c @@ -92,7 +92,7 @@ static char *longest_common_subsequence(char *A, char *B) static int line_from_hunk(char *line, char type) { char *buf1, *buf2; - int len; + int len, res; buf1 = strchr(line, type); if (buf1 == NULL) @@ -105,7 +105,7 @@ static int line_from_hunk(char *line, char type) buf2 = xmalloc(len + 1); strncpy(buf2, buf1, len); buf2[len] = '\0'; - int res = atoi(buf2); + res = atoi(buf2); free(buf2); return res; } From 000cf294c4d3f3a72b31d8bd0186ac989f596890 Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Wed, 13 Jul 2016 20:19:42 +0100 Subject: [PATCH 175/387] tree: allow skipping through single-child trees If we have only a single element in a directory (for example in Java package paths), display multiple directories in one go so that it is possible to navigate directly to the first directory that contains either files or multiple directories. Signed-off-by: John Keeping <john@keeping.me.uk> --- ui-tree.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 2 deletions(-) diff --git a/ui-tree.c b/ui-tree.c index 120066c..5c31e6a 100644 --- a/ui-tree.c +++ b/ui-tree.c @@ -155,6 +155,72 @@ static void print_object(const unsigned char *sha1, char *path, const char *base print_text_buffer(basename, buf, size); } +struct single_tree_ctx { + struct strbuf *path; + unsigned char sha1[GIT_SHA1_RAWSZ]; + char *name; + size_t count; +}; + +static int single_tree_cb(const unsigned char *sha1, struct strbuf *base, + const char *pathname, unsigned mode, int stage, + void *cbdata) +{ + struct single_tree_ctx *ctx = cbdata; + + if (++ctx->count > 1) + return -1; + + if (!S_ISDIR(mode)) { + ctx->count = 2; + return -1; + } + + ctx->name = xstrdup(pathname); + hashcpy(ctx->sha1, sha1); + strbuf_addf(ctx->path, "/%s", pathname); + return 0; +} + +static void write_tree_link(const unsigned char *sha1, char *name, + char *rev, struct strbuf *fullpath) +{ + size_t initial_length = fullpath->len; + struct tree *tree; + struct single_tree_ctx tree_ctx = { + .path = fullpath, + .count = 1, + }; + struct pathspec paths = { + .nr = 0 + }; + + hashcpy(tree_ctx.sha1, sha1); + + while (tree_ctx.count == 1) { + cgit_tree_link(name, NULL, "ls-dir", ctx.qry.head, rev, + fullpath->buf); + + tree = lookup_tree(tree_ctx.sha1); + if (!tree) + return; + + free(tree_ctx.name); + tree_ctx.name = NULL; + tree_ctx.count = 0; + + read_tree_recursive(tree, "", 0, 1, &paths, single_tree_cb, + &tree_ctx); + + if (tree_ctx.count != 1) + break; + + html(" / "); + name = tree_ctx.name; + } + + strbuf_setlen(fullpath, initial_length); +} static int ls_item(const unsigned char *sha1, struct strbuf *base, const char *pathname, unsigned mode, int stage, void *cbdata) @@ -187,8 +253,8 @@ static int ls_item(const unsigned char *sha1, struct strbuf *base, if (S_ISGITLINK(mode)) { cgit_submodule_link("ls-mod", fullpath.buf, sha1_to_hex(sha1)); } else if (S_ISDIR(mode)) { - cgit_tree_link(name, NULL, "ls-dir", ctx.qry.head, - walk_tree_ctx->curr_rev, fullpath.buf); + write_tree_link(sha1, name, walk_tree_ctx->curr_rev, + &fullpath); } else { char *ext = strrchr(name, '.'); strbuf_addstr(&class, "ls-blob"); From d9dff37691633aa44524ecae216c103ea497e940 Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Sat, 13 Aug 2016 11:51:58 +0100 Subject: [PATCH 176/387] shared: remove return value from cgit_free_commitinfo() This return value is never used and the function always returns NULL. Signed-off-by: John Keeping <john@keeping.me.uk> --- cgit.h | 2 +- shared.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/cgit.h b/cgit.h index f34395c..7df0e3a 100644 --- a/cgit.h +++ b/cgit.h @@ -343,7 +343,7 @@ extern void cgit_free_reflist_inner(struct reflist *list); extern int cgit_refs_cb(const char *refname, const struct object_id *oid, int flags, void *cb_data); -extern void *cgit_free_commitinfo(struct commitinfo *info); +extern void cgit_free_commitinfo(struct commitinfo *info); void cgit_diff_tree_cb(struct diff_queue_struct *q, struct diff_options *options, void *data); diff --git a/shared.c b/shared.c index a48eea6..3ada875 100644 --- a/shared.c +++ b/shared.c @@ -95,7 +95,7 @@ struct cgit_repo *cgit_get_repoinfo(const char *url) return NULL; } -void *cgit_free_commitinfo(struct commitinfo *info) +void cgit_free_commitinfo(struct commitinfo *info) { free(info->author); free(info->author_email); @@ -105,7 +105,6 @@ void *cgit_free_commitinfo(struct commitinfo *info) free(info->msg); free(info->msg_encoding); free(info); - return NULL; } char *trim_end(const char *str, char c) From b19d889f6cb2b8ded469c1676dddb3c71751b0ee Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Sat, 13 Aug 2016 11:52:51 +0100 Subject: [PATCH 177/387] shared: make cgit_free_taginfo() public We will use this function from ui-tag.c in the next patch. Signed-off-by: John Keeping <john@keeping.me.uk> --- cgit.h | 1 + shared.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/cgit.h b/cgit.h index 7df0e3a..df42312 100644 --- a/cgit.h +++ b/cgit.h @@ -344,6 +344,7 @@ extern int cgit_refs_cb(const char *refname, const struct object_id *oid, int flags, void *cb_data); extern void cgit_free_commitinfo(struct commitinfo *info); +extern void cgit_free_taginfo(struct taginfo *info); void cgit_diff_tree_cb(struct diff_queue_struct *q, struct diff_options *options, void *data); diff --git a/shared.c b/shared.c index 3ada875..571fbba 100644 --- a/shared.c +++ b/shared.c @@ -203,7 +203,7 @@ static struct refinfo *cgit_mk_refinfo(const char *refname, const struct object_ return ref; } -static void cgit_free_taginfo(struct taginfo *tag) +void cgit_free_taginfo(struct taginfo *tag) { if (tag->tagger) free(tag->tagger); From f80b73fa20d5c884114b971a20e1b4bb847e054e Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Sat, 13 Aug 2016 11:53:24 +0100 Subject: [PATCH 178/387] ui-tag: clean up taginfo Free the taginfo when we're done with it. Also reduce the scope of a couple of variables so that it's clear that this is the only path that uses the taginfo structure. Coverity-Id: 141883 Signed-off-by: John Keeping <john@keeping.me.uk> --- ui-tag.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ui-tag.c b/ui-tag.c index 6b838cb..3fa63b3 100644 --- a/ui-tag.c +++ b/ui-tag.c @@ -44,8 +44,6 @@ void cgit_print_tag(char *revname) struct strbuf fullref = STRBUF_INIT; unsigned char sha1[20]; struct object *obj; - struct tag *tag; - struct taginfo *info; if (!revname) revname = ctx.qry.head; @@ -63,6 +61,9 @@ void cgit_print_tag(char *revname) goto cleanup; } if (obj->type == OBJ_TAG) { + struct tag *tag; + struct taginfo *info; + tag = lookup_tag(sha1); if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) { cgit_print_error_page(500, "Internal server error", @@ -99,6 +100,7 @@ void cgit_print_tag(char *revname) html("</table>\n"); print_tag_content(info->msg); cgit_print_layout_end(); + cgit_free_taginfo(info); } else { cgit_print_layout_start(); html("<table class='commit-info'>\n"); From e18a85b6a298feef88da8085ef16fd20ce971071 Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Sat, 13 Aug 2016 11:54:46 +0100 Subject: [PATCH 179/387] ui-tree: remove a fixed size buffer As libgit.a moves away from using fixed size buffers, there is no guarantee that PATH_MAX is sufficient for all of the paths in a Git tree, so we should use a dynamically sized buffer here. Coverity-Id: 141884 Signed-off-by: John Keeping <john@keeping.me.uk> --- ui-tree.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/ui-tree.c b/ui-tree.c index 5c31e6a..b98a7f0 100644 --- a/ui-tree.c +++ b/ui-tree.c @@ -324,22 +324,25 @@ static int walk_tree(const unsigned char *sha1, struct strbuf *base, const char *pathname, unsigned mode, int stage, void *cbdata) { struct walk_tree_context *walk_tree_ctx = cbdata; - static char buffer[PATH_MAX]; if (walk_tree_ctx->state == 0) { - memcpy(buffer, base->buf, base->len); - strcpy(buffer + base->len, pathname); - if (strcmp(walk_tree_ctx->match_path, buffer)) + struct strbuf buffer = STRBUF_INIT; + + strbuf_addbuf(&buffer, base); + strbuf_addstr(&buffer, pathname); + if (strcmp(walk_tree_ctx->match_path, buffer.buf)) return READ_TREE_RECURSIVE; if (S_ISDIR(mode)) { walk_tree_ctx->state = 1; - set_title_from_path(buffer); + set_title_from_path(buffer.buf); + strbuf_release(&buffer); ls_head(); return READ_TREE_RECURSIVE; } else { walk_tree_ctx->state = 2; - print_object(sha1, buffer, pathname, walk_tree_ctx->curr_rev); + print_object(sha1, buffer.buf, pathname, walk_tree_ctx->curr_rev); + strbuf_release(&buffer); return 0; } } From 927b0ae30c84fbfce877e35415681dce6eba0229 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer <lfleischer@lfos.de> Date: Thu, 29 Sep 2016 08:38:45 +0200 Subject: [PATCH 180/387] Simplify http_parse_querystring() Instead of reimplementing URL parameter parsing from scratch, use url_decode_parameter_name() and url_decode_parameter_value() which are already provided by Git. Also, change the return type of http_parse_querystring() to void since its only caller already ignores the return value. Signed-off-by: Lukas Fleischer <lfleischer@lfos.de> --- html.c | 66 +++++++++------------------------------------------------- html.h | 2 +- 2 files changed, 11 insertions(+), 57 deletions(-) diff --git a/html.c b/html.c index d89df3a..e7e6e07 100644 --- a/html.c +++ b/html.c @@ -8,6 +8,7 @@ #include "cgit.h" #include "html.h" +#include "url.h" /* Percent-encoding of each character, except: a-zA-Z0-9!$()*,./:;@- */ static const char* url_escape_table[256] = { @@ -337,64 +338,17 @@ int html_include(const char *filename) return 0; } -static int hextoint(char c) +void http_parse_querystring(const char *txt, void (*fn)(const char *name, const char *value)) { - if (c >= 'a' && c <= 'f') - return 10 + c - 'a'; - else if (c >= 'A' && c <= 'F') - return 10 + c - 'A'; - else if (c >= '0' && c <= '9') - return c - '0'; - else - return -1; -} + const char *t = txt; -static char *convert_query_hexchar(char *txt) -{ - int d1, d2, n; - n = strlen(txt); - if (n < 3) { - *txt = '\0'; - return txt-1; - } - d1 = hextoint(*(txt + 1)); - d2 = hextoint(*(txt + 2)); - if (d1 < 0 || d2 < 0) { - memmove(txt, txt + 3, n - 2); - return txt-1; - } else { - *txt = d1 * 16 + d2; - memmove(txt + 1, txt + 3, n - 2); - return txt; - } -} - -int http_parse_querystring(const char *txt_, void (*fn)(const char *name, const char *value)) -{ - char *o, *t, *txt, *value = NULL, c; - - if (!txt_) - return 0; - - o = t = txt = xstrdup(txt_); - while ((c=*t) != '\0') { - if (c == '=') { - *t = '\0'; - value = t + 1; - } else if (c == '+') { - *t = ' '; - } else if (c == '%') { - t = convert_query_hexchar(t); - } else if (c == '&') { - *t = '\0'; - (*fn)(txt, value); - txt = t + 1; - value = NULL; + while (t && *t) { + char *name = url_decode_parameter_name(&t); + if (*name) { + char *value = url_decode_parameter_value(&t); + fn(name, value); + free(value); } - t++; + free(name); } - if (t != txt) - (*fn)(txt, value); - free(o); - return 0; } diff --git a/html.h b/html.h index c72e845..1b24e55 100644 --- a/html.h +++ b/html.h @@ -32,6 +32,6 @@ extern void html_link_close(void); extern void html_fileperm(unsigned short mode); extern int html_include(const char *filename); -extern int http_parse_querystring(const char *txt, void (*fn)(const char *name, const char *value)); +extern void http_parse_querystring(const char *txt, void (*fn)(const char *name, const char *value)); #endif /* HTML_H */ From ef3108656b9c6e22604c18bd9d05bdc847d81e87 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Sat, 1 Oct 2016 23:35:04 +0200 Subject: [PATCH 181/387] Makefile: remove extra space Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 821cfb3..3ca4016 100644 --- a/Makefile +++ b/Makefile @@ -85,7 +85,7 @@ install: all $(INSTALL) -m 0644 favicon.ico $(DESTDIR)$(CGIT_DATA_PATH)/favicon.ico $(INSTALL) -m 0644 robots.txt $(DESTDIR)$(CGIT_DATA_PATH)/robots.txt $(INSTALL) -m 0755 -d $(DESTDIR)$(filterdir) - $(COPYTREE) filters/* $(DESTDIR)$(filterdir) + $(COPYTREE) filters/* $(DESTDIR)$(filterdir) install-doc: install-man install-html install-pdf From aee990b6a4512e52b1279a0633d112afe2440122 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Thu, 29 Sep 2016 21:16:14 +0200 Subject: [PATCH 182/387] cgit: replace 'unsigned char sha1[20]' with 'struct object_id oid' Upstream git is replacing 'unsigned char sha1[20]' with 'struct object_id oid'. We have some code that can be changed independent from upstream. So here we go... --- cgit.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cgit.c b/cgit.c index 2f29aa6..9f5a80f 100644 --- a/cgit.c +++ b/cgit.c @@ -471,13 +471,14 @@ static char *find_default_branch(struct cgit_repo *repo) static char *guess_defbranch(void) { const char *ref; - unsigned char sha1[20]; + struct object_id oid; - ref = resolve_ref_unsafe("HEAD", 0, sha1, NULL); + ref = resolve_ref_unsafe("HEAD", 0, oid.hash, NULL); if (!ref || !starts_with(ref, "refs/heads/")) return "master"; return xstrdup(ref + 11); } + /* The caller must free filename and ref after calling this. */ static inline void parse_readme(const char *readme, char **filename, char **ref, struct cgit_repo *repo) { @@ -557,7 +558,7 @@ static void print_no_repo_clone_urls(const char *url) static int prepare_repo_cmd(void) { - unsigned char sha1[20]; + struct object_id oid; int nongit = 0; int rc; @@ -615,7 +616,7 @@ static int prepare_repo_cmd(void) return 1; } - if (get_sha1(ctx.qry.head, sha1)) { + if (get_oid(ctx.qry.head, &oid)) { char *old_head = ctx.qry.head; ctx.qry.head = xstrdup(ctx.repo->defbranch); cgit_print_error_page(404, "Not found", From 6e4b7b6776eb994e795fa38b2619db6c55e10ecc Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Thu, 29 Sep 2016 21:38:49 +0200 Subject: [PATCH 183/387] ui-blob: replace 'unsigned char sha1[20]' with 'struct object_id oid' Upstream git is replacing 'unsigned char sha1[20]' with 'struct object_id oid'. We have some code that can be changed independent from upstream. So here we go... In addition replace memmove() with hashcpy(). --- ui-blob.c | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/ui-blob.c b/ui-blob.c index d388489..2f8bb7a 100644 --- a/ui-blob.c +++ b/ui-blob.c @@ -13,7 +13,7 @@ struct walk_tree_context { const char *match_path; - unsigned char *matched_sha1; + struct object_id matched_oid; unsigned int found_path:1; unsigned int file_only:1; }; @@ -28,14 +28,14 @@ static int walk_tree(const unsigned char *sha1, struct strbuf *base, if (strncmp(base->buf, walk_tree_ctx->match_path, base->len) || strcmp(walk_tree_ctx->match_path + base->len, pathname)) return READ_TREE_RECURSIVE; - memmove(walk_tree_ctx->matched_sha1, sha1, 20); + hashcpy(walk_tree_ctx->matched_oid.hash, sha1); walk_tree_ctx->found_path = 1; return 0; } int cgit_ref_path_exists(const char *path, const char *ref, int file_only) { - unsigned char sha1[20]; + struct object_id oid; unsigned long size; struct pathspec_item path_items = { .match = path, @@ -47,22 +47,22 @@ int cgit_ref_path_exists(const char *path, const char *ref, int file_only) }; struct walk_tree_context walk_tree_ctx = { .match_path = path, - .matched_sha1 = sha1, + .matched_oid = oid, .found_path = 0, .file_only = file_only }; - if (get_sha1(ref, sha1)) + if (get_oid(ref, &oid)) return 0; - if (sha1_object_info(sha1, &size) != OBJ_COMMIT) + if (sha1_object_info(oid.hash, &size) != OBJ_COMMIT) return 0; - read_tree_recursive(lookup_commit_reference(sha1)->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); + read_tree_recursive(lookup_commit_reference(oid.hash)->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); return walk_tree_ctx.found_path; } int cgit_print_file(char *path, const char *head, int file_only) { - unsigned char sha1[20]; + struct object_id oid; enum object_type type; char *buf; unsigned long size; @@ -77,24 +77,24 @@ int cgit_print_file(char *path, const char *head, int file_only) }; struct walk_tree_context walk_tree_ctx = { .match_path = path, - .matched_sha1 = sha1, + .matched_oid = oid, .found_path = 0, .file_only = file_only }; - if (get_sha1(head, sha1)) + if (get_oid(head, &oid)) return -1; - type = sha1_object_info(sha1, &size); + type = sha1_object_info(oid.hash, &size); if (type == OBJ_COMMIT) { - commit = lookup_commit_reference(sha1); + commit = lookup_commit_reference(oid.hash); read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); if (!walk_tree_ctx.found_path) return -1; - type = sha1_object_info(sha1, &size); + type = sha1_object_info(oid.hash, &size); } if (type == OBJ_BAD) return -1; - buf = read_sha1_file(sha1, &type, &size); + buf = read_sha1_file(oid.hash, &type, &size); if (!buf) return -1; buf[size] = '\0'; @@ -105,7 +105,7 @@ int cgit_print_file(char *path, const char *head, int file_only) void cgit_print_blob(const char *hex, char *path, const char *head, int file_only) { - unsigned char sha1[20]; + struct object_id oid; enum object_type type; char *buf; unsigned long size; @@ -120,31 +120,31 @@ void cgit_print_blob(const char *hex, char *path, const char *head, int file_onl }; struct walk_tree_context walk_tree_ctx = { .match_path = path, - .matched_sha1 = sha1, + .matched_oid = oid, .found_path = 0, .file_only = file_only }; if (hex) { - if (get_sha1_hex(hex, sha1)) { + if (get_oid_hex(hex, &oid)) { cgit_print_error_page(400, "Bad request", "Bad hex value: %s", hex); return; } } else { - if (get_sha1(head, sha1)) { + if (get_oid(head, &oid)) { cgit_print_error_page(404, "Not found", "Bad ref: %s", head); return; } } - type = sha1_object_info(sha1, &size); + type = sha1_object_info(oid.hash, &size); if ((!hex) && type == OBJ_COMMIT && path) { - commit = lookup_commit_reference(sha1); + commit = lookup_commit_reference(oid.hash); read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); - type = sha1_object_info(sha1,&size); + type = sha1_object_info(oid.hash, &size); } if (type == OBJ_BAD) { @@ -153,7 +153,7 @@ void cgit_print_blob(const char *hex, char *path, const char *head, int file_onl return; } - buf = read_sha1_file(sha1, &type, &size); + buf = read_sha1_file(oid.hash, &type, &size); if (!buf) { cgit_print_error_page(500, "Internal server error", "Error reading object %s", hex); From 3a0fd5e6b881e6a38a6be9224db0cf93512c0b2b Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Thu, 29 Sep 2016 21:41:09 +0200 Subject: [PATCH 184/387] ui-commit: replace 'unsigned char sha1[20]' with 'struct object_id oid' Upstream git is replacing 'unsigned char sha1[20]' with 'struct object_id oid'. We have some code that can be changed independent from upstream. So here we go... --- ui-commit.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ui-commit.c b/ui-commit.c index 099d294..db69d54 100644 --- a/ui-commit.c +++ b/ui-commit.c @@ -19,19 +19,19 @@ void cgit_print_commit(char *hex, const char *prefix) struct commitinfo *info, *parent_info; struct commit_list *p; struct strbuf notes = STRBUF_INIT; - unsigned char sha1[20]; + struct object_id oid; char *tmp, *tmp2; int parents = 0; if (!hex) hex = ctx.qry.head; - if (get_sha1(hex, sha1)) { + if (get_oid(hex, &oid)) { cgit_print_error_page(400, "Bad request", "Bad object id: %s", hex); return; } - commit = lookup_commit_reference(sha1); + commit = lookup_commit_reference(oid.hash); if (!commit) { cgit_print_error_page(404, "Not found", "Bad commit reference: %s", hex); @@ -39,7 +39,7 @@ void cgit_print_commit(char *hex, const char *prefix) } info = cgit_parse_commit(commit); - format_display_notes(sha1, ¬es, PAGE_ENCODING, 0); + format_display_notes(oid.hash, ¬es, PAGE_ENCODING, 0); load_ref_decorations(DECORATE_FULL_REFS); From 1a9a75d7c7c33cd89f1c34445d56e51dc349dc31 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Thu, 29 Sep 2016 21:44:41 +0200 Subject: [PATCH 185/387] ui-log: replace get_sha1() with get_oid() Data structures have been replaced already, so use correct function calls. --- ui-log.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui-log.c b/ui-log.c index a31ff7c..6cc81a3 100644 --- a/ui-log.c +++ b/ui-log.c @@ -325,7 +325,7 @@ static const char *disambiguate_ref(const char *ref, int *must_free_result) struct strbuf longref = STRBUF_INIT; strbuf_addf(&longref, "refs/heads/%s", ref); - if (get_sha1(longref.buf, oid.hash) == 0) { + if (get_oid(longref.buf, &oid) == 0) { *must_free_result = 1; return strbuf_detach(&longref, NULL); } From 85793b8181aa93ef6070f137fcb3caee624849b6 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Thu, 29 Sep 2016 21:51:41 +0200 Subject: [PATCH 186/387] ui-patch: replace 'unsigned char sha1[20]' with 'struct object_id oid' Upstream git is replacing 'unsigned char sha1[20]' with 'struct object_id oid'. We have some code that can be changed independent from upstream. So here we go... --- ui-patch.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/ui-patch.c b/ui-patch.c index 4c051e8..fd6316b 100644 --- a/ui-patch.c +++ b/ui-patch.c @@ -16,7 +16,7 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, { struct rev_info rev; struct commit *commit; - unsigned char new_rev_sha1[20], old_rev_sha1[20]; + struct object_id new_rev_oid, old_rev_oid; char rev_range[2 * 40 + 3]; char *rev_argv[] = { NULL, "--reverse", "--format=email", rev_range }; char *patchname; @@ -24,12 +24,12 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, if (!new_rev) new_rev = ctx.qry.head; - if (get_sha1(new_rev, new_rev_sha1)) { + if (get_oid(new_rev, &new_rev_oid)) { cgit_print_error_page(404, "Not found", "Bad object id: %s", new_rev); return; } - commit = lookup_commit_reference(new_rev_sha1); + commit = lookup_commit_reference(new_rev_oid.hash); if (!commit) { cgit_print_error_page(404, "Not found", "Bad commit reference: %s", new_rev); @@ -37,27 +37,27 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, } if (old_rev) { - if (get_sha1(old_rev, old_rev_sha1)) { + if (get_oid(old_rev, &old_rev_oid)) { cgit_print_error_page(404, "Not found", "Bad object id: %s", old_rev); return; } - if (!lookup_commit_reference(old_rev_sha1)) { + if (!lookup_commit_reference(old_rev_oid.hash)) { cgit_print_error_page(404, "Not found", "Bad commit reference: %s", old_rev); return; } } else if (commit->parents && commit->parents->item) { - hashcpy(old_rev_sha1, commit->parents->item->object.oid.hash); + oidcpy(&old_rev_oid, &commit->parents->item->object.oid); } else { - hashclr(old_rev_sha1); + oidclr(&old_rev_oid); } - if (is_null_sha1(old_rev_sha1)) { - memcpy(rev_range, sha1_to_hex(new_rev_sha1), 41); + if (is_null_oid(&old_rev_oid)) { + memcpy(rev_range, oid_to_hex(&new_rev_oid), GIT_SHA1_HEXSZ + 1); } else { - sprintf(rev_range, "%s..%s", sha1_to_hex(old_rev_sha1), - sha1_to_hex(new_rev_sha1)); + sprintf(rev_range, "%s..%s", oid_to_hex(&old_rev_oid), + oid_to_hex(&new_rev_oid)); } patchname = fmt("%s.patch", rev_range); From 073a8bb3963d53630826ee43f6feefb5a9660dc0 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Thu, 29 Sep 2016 22:08:19 +0200 Subject: [PATCH 187/387] ui-plain: replace 'unsigned char sha1[20]' with 'struct object_id oid' Upstream git is replacing 'unsigned char sha1[20]' with 'struct object_id oid'. We have some code that can be changed independent from upstream. So here we go... --- ui-plain.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ui-plain.c b/ui-plain.c index 97cf639..8d541e3 100644 --- a/ui-plain.c +++ b/ui-plain.c @@ -164,7 +164,7 @@ static int basedir_len(const char *path) void cgit_print_plain(void) { const char *rev = ctx.qry.sha1; - unsigned char sha1[20]; + struct object_id oid; struct commit *commit; struct pathspec_item path_items = { .match = ctx.qry.path, @@ -181,11 +181,11 @@ void cgit_print_plain(void) if (!rev) rev = ctx.qry.head; - if (get_sha1(rev, sha1)) { + if (get_oid(rev, &oid)) { cgit_print_error_page(404, "Not found", "Not found"); return; } - commit = lookup_commit_reference(sha1); + commit = lookup_commit_reference(oid.hash); if (!commit || parse_commit(commit)) { cgit_print_error_page(404, "Not found", "Not found"); return; From 6bef566f99c7f85cbab9692e22b183ae99f33c1d Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Thu, 29 Sep 2016 22:10:21 +0200 Subject: [PATCH 188/387] ui-shared: replace 'unsigned char sha1[20]' with 'struct object_id oid' Upstream git is replacing 'unsigned char sha1[20]' with 'struct object_id oid'. We have some code that can be changed independent from upstream. So here we go... --- ui-shared.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ui-shared.c b/ui-shared.c index 3fa36d6..2e4fcd9 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -1074,18 +1074,18 @@ void cgit_print_filemode(unsigned short mode) void cgit_compose_snapshot_prefix(struct strbuf *filename, const char *base, const char *ref) { - unsigned char sha1[20]; + struct object_id oid; /* * Prettify snapshot names by stripping leading "v" or "V" if the tag * name starts with {v,V}[0-9] and the prettify mapping is injective, * i.e. each stripped tag can be inverted without ambiguities. */ - if (get_sha1(fmt("refs/tags/%s", ref), sha1) == 0 && + if (get_oid(fmt("refs/tags/%s", ref), &oid) == 0 && (ref[0] == 'v' || ref[0] == 'V') && isdigit(ref[1]) && - ((get_sha1(fmt("refs/tags/%s", ref + 1), sha1) == 0) + - (get_sha1(fmt("refs/tags/v%s", ref + 1), sha1) == 0) + - (get_sha1(fmt("refs/tags/V%s", ref + 1), sha1) == 0) == 1)) + ((get_oid(fmt("refs/tags/%s", ref + 1), &oid) == 0) + + (get_oid(fmt("refs/tags/v%s", ref + 1), &oid) == 0) + + (get_oid(fmt("refs/tags/V%s", ref + 1), &oid) == 0) == 1)) ref++; strbuf_addf(filename, "%s-%s", base, ref); From 406f593895a2cc9f8944e87c94b7b6a94deee470 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Thu, 29 Sep 2016 22:12:11 +0200 Subject: [PATCH 189/387] ui-snapshot: replace 'unsigned char sha1[20]' with 'struct object_id oid' Upstream git is replacing 'unsigned char sha1[20]' with 'struct object_id oid'. We have some code that can be changed independent from upstream. So here we go... --- ui-snapshot.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/ui-snapshot.c b/ui-snapshot.c index f68e877..08c6e80 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c @@ -109,19 +109,19 @@ static int make_snapshot(const struct cgit_snapshot_format *format, const char *hex, const char *prefix, const char *filename) { - unsigned char sha1[20]; + struct object_id oid; - if (get_sha1(hex, sha1)) { + if (get_oid(hex, &oid)) { cgit_print_error_page(404, "Not found", "Bad object id: %s", hex); return 1; } - if (!lookup_commit_reference(sha1)) { + if (!lookup_commit_reference(oid.hash)) { cgit_print_error_page(400, "Bad request", "Not a commit reference: %s", hex); return 1; } - ctx.page.etag = sha1_to_hex(sha1); + ctx.page.etag = oid_to_hex(&oid); ctx.page.mimetype = xstrdup(format->mimetype); ctx.page.filename = xstrdup(filename); cgit_print_http_headers(); @@ -143,14 +143,14 @@ static const char *get_ref_from_filename(const char *url, const char *filename, const struct cgit_snapshot_format *format) { const char *reponame; - unsigned char sha1[20]; + struct object_id oid; struct strbuf snapshot = STRBUF_INIT; int result = 1; strbuf_addstr(&snapshot, filename); strbuf_setlen(&snapshot, snapshot.len - strlen(format->suffix)); - if (get_sha1(snapshot.buf, sha1) == 0) + if (get_oid(snapshot.buf, &oid) == 0) goto out; reponame = cgit_repobasename(url); @@ -162,15 +162,15 @@ static const char *get_ref_from_filename(const char *url, const char *filename, strbuf_splice(&snapshot, 0, new_start - snapshot.buf, "", 0); } - if (get_sha1(snapshot.buf, sha1) == 0) + if (get_oid(snapshot.buf, &oid) == 0) goto out; strbuf_insert(&snapshot, 0, "v", 1); - if (get_sha1(snapshot.buf, sha1) == 0) + if (get_oid(snapshot.buf, &oid) == 0) goto out; strbuf_splice(&snapshot, 0, 1, "V", 1); - if (get_sha1(snapshot.buf, sha1) == 0) + if (get_oid(snapshot.buf, &oid) == 0) goto out; result = 0; From 28185ae40a82d3304ace805c9a44e933270bd581 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Thu, 29 Sep 2016 22:14:28 +0200 Subject: [PATCH 190/387] ui-tag: replace 'unsigned char sha1[20]' with 'struct object_id oid' Upstream git is replacing 'unsigned char sha1[20]' with 'struct object_id oid'. We have some code that can be changed independent from upstream. So here we go... --- ui-tag.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ui-tag.c b/ui-tag.c index 3fa63b3..afd7d61 100644 --- a/ui-tag.c +++ b/ui-tag.c @@ -42,29 +42,29 @@ static void print_download_links(char *revname) void cgit_print_tag(char *revname) { struct strbuf fullref = STRBUF_INIT; - unsigned char sha1[20]; + struct object_id oid; struct object *obj; if (!revname) revname = ctx.qry.head; strbuf_addf(&fullref, "refs/tags/%s", revname); - if (get_sha1(fullref.buf, sha1)) { + if (get_oid(fullref.buf, &oid)) { cgit_print_error_page(404, "Not found", "Bad tag reference: %s", revname); goto cleanup; } - obj = parse_object(sha1); + obj = parse_object(oid.hash); if (!obj) { cgit_print_error_page(500, "Internal server error", - "Bad object id: %s", sha1_to_hex(sha1)); + "Bad object id: %s", oid_to_hex(&oid)); goto cleanup; } if (obj->type == OBJ_TAG) { struct tag *tag; struct taginfo *info; - tag = lookup_tag(sha1); + tag = lookup_tag(oid.hash); if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) { cgit_print_error_page(500, "Internal server error", "Bad tag object: %s", revname); @@ -74,7 +74,7 @@ void cgit_print_tag(char *revname) html("<table class='commit-info'>\n"); htmlf("<tr><td>tag name</td><td>"); html_txt(revname); - htmlf(" (%s)</td></tr>\n", sha1_to_hex(sha1)); + htmlf(" (%s)</td></tr>\n", oid_to_hex(&oid)); if (info->tagger_date > 0) { html("<tr><td>tag date</td><td>"); html_txt(show_date(info->tagger_date, info->tagger_tz, From 9dd3c5e93c5af3d35efe6e9f844456eb0f27a819 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Thu, 29 Sep 2016 22:17:07 +0200 Subject: [PATCH 191/387] ui-tree: replace 'unsigned char sha1[20]' with 'struct object_id oid' Upstream git is replacing 'unsigned char sha1[20]' with 'struct object_id oid'. We have some code that can be changed independent from upstream. So here we go... --- ui-tree.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ui-tree.c b/ui-tree.c index b98a7f0..b310242 100644 --- a/ui-tree.c +++ b/ui-tree.c @@ -357,7 +357,7 @@ static int walk_tree(const unsigned char *sha1, struct strbuf *base, */ void cgit_print_tree(const char *rev, char *path) { - unsigned char sha1[20]; + struct object_id oid; struct commit *commit; struct pathspec_item path_items = { .match = path, @@ -375,12 +375,12 @@ void cgit_print_tree(const char *rev, char *path) if (!rev) rev = ctx.qry.head; - if (get_sha1(rev, sha1)) { + if (get_oid(rev, &oid)) { cgit_print_error_page(404, "Not found", "Invalid revision name: %s", rev); return; } - commit = lookup_commit_reference(sha1); + commit = lookup_commit_reference(oid.hash); if (!commit || parse_commit(commit)) { cgit_print_error_page(404, "Not found", "Invalid commit reference: %s", rev); From d6a4730d049216f903fb0466215366f588208a40 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Tue, 4 Oct 2016 08:51:05 +0200 Subject: [PATCH 192/387] git: update to v2.10.1 Update to git version v2.10.1, no changes required. --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 3ca4016..caa32d6 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.10.0 +GIT_VER = 2.10.1 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.gz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index 6ebdac1..6406bdc 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 6ebdac1bab966b720d776aa43ca188fe378b1f4b +Subproject commit 6406bdc0b95715a087fdeeb0f6adf3deb80a25b8 From c177379547f93955fbd251b2a70a22b9bb85a257 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Fri, 7 Oct 2016 15:08:53 +0200 Subject: [PATCH 193/387] ui-repolist: fix memory leak --- ui-repolist.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ui-repolist.c b/ui-repolist.c index 30915df..1d9a7f7 100644 --- a/ui-repolist.c +++ b/ui-repolist.c @@ -275,6 +275,7 @@ void cgit_print_repolist(void) int i, columns = 3, hits = 0, header = 0; char *last_section = NULL; char *section; + char *repourl; int sorted = 0; if (!any_repos_visible()) { @@ -330,7 +331,9 @@ void cgit_print_repolist(void) !sorted && section ? "sublevel-repo" : "toplevel-repo"); cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL); html("</td><td>"); - html_link_open(cgit_repourl(ctx.repo->url), NULL, NULL); + repourl = cgit_repourl(ctx.repo->url); + html_link_open(repourl, NULL, NULL); + free(repourl); html_ntxt(ctx.cfg.max_repodesc_len, ctx.repo->desc); html_link_close(); html("</td><td>"); From 5fe88a9c81517b1a8a93d930c738cbb6f71dec2a Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Mon, 14 Mar 2016 22:41:14 +0000 Subject: [PATCH 194/387] patch: reapply path limit This was originally applied added in commit eac1b67 (ui-patch: Apply path limit to generated patch, 2010-06-10) but the ability to limit patches to particular paths was lost in commit 455b598 (ui-patch.c: Use log_tree_commit() to generate diffs, 2013-08-20). The new output is slightly different from the original because Git's diff infrastructure doesn't give us a way to insert an annotation immediately after the "---" separator, so the commit has moved below the diff stat. Signed-off-by: John Keeping <john@keeping.me.uk> --- ui-patch.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ui-patch.c b/ui-patch.c index fd6316b..ec7f352 100644 --- a/ui-patch.c +++ b/ui-patch.c @@ -18,9 +18,13 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, struct commit *commit; struct object_id new_rev_oid, old_rev_oid; char rev_range[2 * 40 + 3]; - char *rev_argv[] = { NULL, "--reverse", "--format=email", rev_range }; + const char *rev_argv[] = { NULL, "--reverse", "--format=email", rev_range, "--", prefix }; + int rev_argc = ARRAY_SIZE(rev_argv); char *patchname; + if (!prefix) + rev_argc--; + if (!new_rev) new_rev = ctx.qry.head; @@ -79,7 +83,9 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, rev.max_parents = 1; rev.diffopt.output_format |= DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_PATCH | DIFF_FORMAT_SUMMARY; - setup_revisions(ARRAY_SIZE(rev_argv), (const char **)rev_argv, &rev, + if (prefix) + rev.diffopt.stat_sep = fmt("(limited to '%s')\n\n", prefix); + setup_revisions(ARRAY_SIZE(rev_argv), rev_argv, &rev, NULL); prepare_revision_walk(&rev); From 32c27e887732298da1724c0740004925fcadae39 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer <lfleischer@lfos.de> Date: Sat, 8 Oct 2016 15:45:12 +0200 Subject: [PATCH 195/387] Use skip_prefix() to get rid of magic constants Signed-off-by: Lukas Fleischer <lfleischer@lfos.de> --- cgit.c | 56 ++++++++++++++++++++++++++++------------------------- scan-tree.c | 6 ++++-- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/cgit.c b/cgit.c index 9f5a80f..1075753 100644 --- a/cgit.c +++ b/cgit.c @@ -31,6 +31,7 @@ static void process_cached_repolist(const char *path); static void repo_config(struct cgit_repo *repo, const char *name, const char *value) { + const char *path; struct string_list_item *item; if (!strcmp(name, "name")) @@ -73,8 +74,8 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va repo->max_stats = cgit_find_stats_period(value, NULL); else if (!strcmp(name, "module-link")) repo->module_link= xstrdup(value); - else if (starts_with(name, "module-link.")) { - item = string_list_append(&repo->submodules, xstrdup(name + 12)); + else if (skip_prefix(name, "module-link.", &path)) { + item = string_list_append(&repo->submodules, xstrdup(path)); item->util = xstrdup(value); } else if (!strcmp(name, "section")) repo->section = xstrdup(value); @@ -106,14 +107,16 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va static void config_cb(const char *name, const char *value) { + const char *arg; + if (!strcmp(name, "section") || !strcmp(name, "repo.group")) ctx.cfg.section = xstrdup(value); else if (!strcmp(name, "repo.url")) ctx.repo = cgit_add_repo(value); else if (ctx.repo && !strcmp(name, "repo.path")) ctx.repo->path = trim_end(value, '/'); - else if (ctx.repo && starts_with(name, "repo.")) - repo_config(ctx.repo, name + 5, value); + else if (ctx.repo && skip_prefix(name, "repo.", &arg)) + repo_config(ctx.repo, arg, value); else if (!strcmp(name, "readme")) string_list_append(&ctx.cfg.readme, xstrdup(value)); else if (!strcmp(name, "root-title")) @@ -280,8 +283,8 @@ static void config_cb(const char *name, const char *value) ctx.cfg.branch_sort = 1; if (!strcmp(value, "name")) ctx.cfg.branch_sort = 0; - } else if (starts_with(name, "mimetype.")) - add_mimetype(name + 9, value); + } else if (skip_prefix(name, "mimetype.", &arg)) + add_mimetype(arg, value); else if (!strcmp(name, "include")) parse_configfile(expand_macros(value), config_cb); } @@ -470,13 +473,13 @@ static char *find_default_branch(struct cgit_repo *repo) static char *guess_defbranch(void) { - const char *ref; + const char *ref, *refname; struct object_id oid; ref = resolve_ref_unsafe("HEAD", 0, oid.hash, NULL); - if (!ref || !starts_with(ref, "refs/heads/")) + if (!ref || !skip_prefix(ref, "refs/heads/", &refname)) return "master"; - return xstrdup(ref + 11); + return xstrdup(refname); } /* The caller must free filename and ref after calling this. */ @@ -938,6 +941,7 @@ out: static void cgit_parse_args(int argc, const char **argv) { int i; + const char *arg; int scan = 0; for (i = 1; i < argc; i++) { @@ -958,28 +962,28 @@ static void cgit_parse_args(int argc, const char **argv) exit(0); } - if (starts_with(argv[i], "--cache=")) { - ctx.cfg.cache_root = xstrdup(argv[i] + 8); + if (skip_prefix(argv[i], "--cache=", &arg)) { + ctx.cfg.cache_root = xstrdup(arg); } else if (!strcmp(argv[i], "--nocache")) { ctx.cfg.nocache = 1; } else if (!strcmp(argv[i], "--nohttp")) { ctx.env.no_http = "1"; - } else if (starts_with(argv[i], "--query=")) { - ctx.qry.raw = xstrdup(argv[i] + 8); - } else if (starts_with(argv[i], "--repo=")) { - ctx.qry.repo = xstrdup(argv[i] + 7); - } else if (starts_with(argv[i], "--page=")) { - ctx.qry.page = xstrdup(argv[i] + 7); - } else if (starts_with(argv[i], "--head=")) { - ctx.qry.head = xstrdup(argv[i] + 7); + } else if (skip_prefix(argv[i], "--query=", &arg)) { + ctx.qry.raw = xstrdup(arg); + } else if (skip_prefix(argv[i], "--repo=", &arg)) { + ctx.qry.repo = xstrdup(arg); + } else if (skip_prefix(argv[i], "--page=", &arg)) { + ctx.qry.page = xstrdup(arg); + } else if (skip_prefix(argv[i], "--head=", &arg)) { + ctx.qry.head = xstrdup(arg); ctx.qry.has_symref = 1; - } else if (starts_with(argv[i], "--sha1=")) { - ctx.qry.sha1 = xstrdup(argv[i] + 7); + } else if (skip_prefix(argv[i], "--sha1=", &arg)) { + ctx.qry.sha1 = xstrdup(arg); ctx.qry.has_sha1 = 1; - } else if (starts_with(argv[i], "--ofs=")) { - ctx.qry.ofs = atoi(argv[i] + 6); - } else if (starts_with(argv[i], "--scan-tree=") || - starts_with(argv[i], "--scan-path=")) { + } else if (skip_prefix(argv[i], "--ofs=", &arg)) { + ctx.qry.ofs = atoi(arg); + } else if (skip_prefix(argv[i], "--scan-tree=", &arg) || + skip_prefix(argv[i], "--scan-path=", &arg)) { /* * HACK: The global snapshot bit mask defines the set * of allowed snapshot formats, but the config file @@ -993,7 +997,7 @@ static void cgit_parse_args(int argc, const char **argv) */ ctx.cfg.snapshots = 0xFF; scan++; - scan_tree(argv[i] + 12, repo_config); + scan_tree(arg, repo_config); } } if (scan) { diff --git a/scan-tree.c b/scan-tree.c index 1cb4e5d..08f3f1d 100644 --- a/scan-tree.c +++ b/scan-tree.c @@ -55,6 +55,8 @@ static void repo_config(const char *name, const char *value) static int gitconfig_config(const char *key, const char *value, void *cb) { + const char *name; + if (!strcmp(key, "gitweb.owner")) config_fn(repo, "owner", value); else if (!strcmp(key, "gitweb.description")) @@ -63,8 +65,8 @@ static int gitconfig_config(const char *key, const char *value, void *cb) config_fn(repo, "section", value); else if (!strcmp(key, "gitweb.homepage")) config_fn(repo, "homepage", value); - else if (starts_with(key, "cgit.")) - config_fn(repo, key + 5, value); + else if (skip_prefix(key, "cgit.", &name)) + config_fn(repo, name, value); return 0; } From 7fea585e252ee7a584e4b2d679009518bab48ebe Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Mon, 10 Oct 2016 20:17:51 +0200 Subject: [PATCH 196/387] ui-repolist: fix memory leak --- ui-repolist.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ui-repolist.c b/ui-repolist.c index 1d9a7f7..7158bf7 100644 --- a/ui-repolist.c +++ b/ui-repolist.c @@ -343,13 +343,15 @@ void cgit_print_repolist(void) html_txt(ctx.repo->owner); cgit_close_filter(ctx.repo->owner_filter); } else { + char *currenturl = cgit_currenturl(); html("<a href='"); - html_attr(cgit_currenturl()); + html_attr(currenturl); html("?q="); html_url_arg(ctx.repo->owner); html("'>"); html_txt(ctx.repo->owner); html("</a>"); + free(currenturl); } html("</td><td>"); } From 3e2e8f1c249bd52aae728b7f99fc471821a93b55 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Mon, 10 Oct 2016 20:32:17 +0200 Subject: [PATCH 197/387] shared: remove unused function strrpart() --- cgit.h | 1 - shared.c | 15 --------------- 2 files changed, 16 deletions(-) diff --git a/cgit.h b/cgit.h index df42312..bef6e5f 100644 --- a/cgit.h +++ b/cgit.h @@ -334,7 +334,6 @@ extern int chk_non_negative(int result, char *msg); extern char *trim_end(const char *str, char c); extern char *ensure_end(const char *str, char c); extern char *strlpart(char *txt, int maxlen); -extern char *strrpart(char *txt, int maxlen); extern void strbuf_ensure_end(struct strbuf *sb, char c); diff --git a/shared.c b/shared.c index 571fbba..8d08435 100644 --- a/shared.c +++ b/shared.c @@ -158,21 +158,6 @@ char *strlpart(char *txt, int maxlen) return result; } -char *strrpart(char *txt, int maxlen) -{ - char *result; - - if (!txt) - return txt; - - if (strlen(txt) <= maxlen) - return txt; - result = xmalloc(maxlen + 1); - memcpy(result + 3, txt + strlen(txt) - maxlen + 4, maxlen - 3); - result[0] = result[1] = result[2] = '.'; - return result; -} - void cgit_add_ref(struct reflist *list, struct refinfo *ref) { size_t size; From 2d59e6a64e9869cc8420cb532af29a9eba867004 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Mon, 10 Oct 2016 20:33:30 +0200 Subject: [PATCH 198/387] shared: remove unused function strlpart() --- cgit.h | 1 - shared.c | 16 ---------------- 2 files changed, 17 deletions(-) diff --git a/cgit.h b/cgit.h index bef6e5f..fbc6c6a 100644 --- a/cgit.h +++ b/cgit.h @@ -333,7 +333,6 @@ extern int chk_non_negative(int result, char *msg); extern char *trim_end(const char *str, char c); extern char *ensure_end(const char *str, char c); -extern char *strlpart(char *txt, int maxlen); extern void strbuf_ensure_end(struct strbuf *sb, char c); diff --git a/shared.c b/shared.c index 8d08435..c63f1e3 100644 --- a/shared.c +++ b/shared.c @@ -142,22 +142,6 @@ void strbuf_ensure_end(struct strbuf *sb, char c) strbuf_addch(sb, c); } -char *strlpart(char *txt, int maxlen) -{ - char *result; - - if (!txt) - return txt; - - if (strlen(txt) <= maxlen) - return txt; - result = xmalloc(maxlen + 1); - memcpy(result, txt, maxlen - 3); - result[maxlen-1] = result[maxlen-2] = result[maxlen-3] = '.'; - result[maxlen] = '\0'; - return result; -} - void cgit_add_ref(struct reflist *list, struct refinfo *ref) { size_t size; From c330a2e5f86e1f77d3b724877935e11014cefa21 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Tue, 11 Oct 2016 08:55:34 +0200 Subject: [PATCH 199/387] ui-blog: fix oid handling We have to use a pointer for walk_tree_ctx->matched_oid. This fixes faulty commit 6e4b7b6776eb994e795fa38b2619db6c55e10ecc (ui-blob: replace 'unsigned char sha1[20]' with 'struct object_id oid'). --- ui-blob.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ui-blob.c b/ui-blob.c index 2f8bb7a..5f30de7 100644 --- a/ui-blob.c +++ b/ui-blob.c @@ -13,7 +13,7 @@ struct walk_tree_context { const char *match_path; - struct object_id matched_oid; + struct object_id *matched_oid; unsigned int found_path:1; unsigned int file_only:1; }; @@ -28,7 +28,7 @@ static int walk_tree(const unsigned char *sha1, struct strbuf *base, if (strncmp(base->buf, walk_tree_ctx->match_path, base->len) || strcmp(walk_tree_ctx->match_path + base->len, pathname)) return READ_TREE_RECURSIVE; - hashcpy(walk_tree_ctx->matched_oid.hash, sha1); + hashcpy(walk_tree_ctx->matched_oid->hash, sha1); walk_tree_ctx->found_path = 1; return 0; } @@ -47,7 +47,7 @@ int cgit_ref_path_exists(const char *path, const char *ref, int file_only) }; struct walk_tree_context walk_tree_ctx = { .match_path = path, - .matched_oid = oid, + .matched_oid = &oid, .found_path = 0, .file_only = file_only }; @@ -77,7 +77,7 @@ int cgit_print_file(char *path, const char *head, int file_only) }; struct walk_tree_context walk_tree_ctx = { .match_path = path, - .matched_oid = oid, + .matched_oid = &oid, .found_path = 0, .file_only = file_only }; @@ -120,7 +120,7 @@ void cgit_print_blob(const char *hex, char *path, const char *head, int file_onl }; struct walk_tree_context walk_tree_ctx = { .match_path = path, - .matched_oid = oid, + .matched_oid = &oid, .found_path = 0, .file_only = file_only }; From 44f8c11c8d6edadedb9b83baf6f6a786c0bd8c30 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Sun, 6 Nov 2016 21:47:04 +0100 Subject: [PATCH 200/387] git: update to v2.10.2 Update to git version v2.10.2, no changes required. --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index caa32d6..1fe00c4 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.10.1 +GIT_VER = 2.10.2 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.gz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index 6406bdc..ac84098 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 6406bdc0b95715a087fdeeb0f6adf3deb80a25b8 +Subproject commit ac84098b7e32406a982ac01cc76a663d5605224b From 81509a228c7428abeb56ecacb45ccd8dc8fc6209 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Wed, 6 Jul 2016 22:42:36 +0200 Subject: [PATCH 201/387] css: highlight even table rows and skip empty rows This is stolen from kernel.org css [0]. [0] https://git.kernel.org/cgit-korg-0.10.1.css --- cgit.css | 20 ++++++++++++++++++++ ui-log.c | 5 +++-- ui-repolist.c | 2 +- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/cgit.css b/cgit.css index a4331f8..1dc2c11 100644 --- a/cgit.css +++ b/cgit.css @@ -134,14 +134,34 @@ div#cgit table.list tr.logheader { background: #eee; } +div#cgit table.list tr:nth-child(even) { + background: #f7f7f7; +} + +div#cgit table.list tr:nth-child(odd) { + background: white; +} + div#cgit table.list tr:hover { background: #eee; } +div#cgit table.list tr.nohover { + background: white; +} + div#cgit table.list tr.nohover:hover { background: white; } +div#cgit table.list tr.nohover-highlight:hover:nth-child(even) { + background: #f7f7f7; +} + +div#cgit table.list tr.nohover-highlight:hover:nth-child(odd) { + background: white; +} + div#cgit table.list th { font-weight: bold; /* color: #888; diff --git a/ui-log.c b/ui-log.c index 6cc81a3..3220fd9 100644 --- a/ui-log.c +++ b/ui-log.c @@ -263,8 +263,9 @@ static void print_commit(struct commit *commit, struct rev_info *revs) html("</td></tr>\n"); - if (revs->graph || ctx.qry.showmsg) { /* Print a second table row */ - html("<tr class='nohover'>"); + if ((revs->graph && !graph_is_commit_finished(revs->graph)) + || ctx.qry.showmsg) { /* Print a second table row */ + html("<tr class='nohover-highlight'>"); if (ctx.qry.showmsg) { /* Concatenate commit message + notes in msgbuf */ diff --git a/ui-repolist.c b/ui-repolist.c index 7158bf7..b57ea60 100644 --- a/ui-repolist.c +++ b/ui-repolist.c @@ -321,7 +321,7 @@ void cgit_print_repolist(void) (last_section != NULL && section == NULL) || (last_section != NULL && section != NULL && strcmp(section, last_section)))) { - htmlf("<tr class='nohover'><td colspan='%d' class='reposection'>", + htmlf("<tr class='nohover-highlight'><td colspan='%d' class='reposection'>", columns); html_txt(section); html("</td></tr>"); From 8e9ddd21a50beb9fd660cf6cd6a583234924b932 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Wed, 23 Nov 2016 05:24:26 +0100 Subject: [PATCH 202/387] Bump version. --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 1fe00c4..1ab2905 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ all:: -CGIT_VERSION = v1.0 +CGIT_VERSION = v1.1 CGIT_SCRIPT_NAME = cgit.cgi CGIT_SCRIPT_PATH = /var/www/htdocs/cgit CGIT_DATA_PATH = $(CGIT_SCRIPT_PATH) diff --git a/git b/git index ac84098..6406bdc 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit ac84098b7e32406a982ac01cc76a663d5605224b +Subproject commit 6406bdc0b95715a087fdeeb0f6adf3deb80a25b8 From 5ccd96525835b314c8615738d533d9d0b54a630c Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Thu, 24 Nov 2016 18:59:42 +0000 Subject: [PATCH 203/387] git: update to v2.10.2 again The submodule was accidentally downgraded in commit 8e9ddd21 (Bump version, 2016-11-23). Restore v2.10.2 so it matches the makefile again. Signed-off-by: John Keeping <john@keeping.me.uk> --- git | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git b/git index 6406bdc..ac84098 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 6406bdc0b95715a087fdeeb0f6adf3deb80a25b8 +Subproject commit ac84098b7e32406a982ac01cc76a663d5605224b From 2b993402c7ed5849606a5bf4d3c7cb212f491b06 Mon Sep 17 00:00:00 2001 From: Peter Colberg <peter@colberg.org> Date: Fri, 25 Nov 2016 15:57:11 -0500 Subject: [PATCH 204/387] Link with -ldl on GNU Hurd Debian GNU/Hurd uses the GNU C library. Signed-off-by: Peter Colberg <peter@colberg.org> --- cgit.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cgit.mk b/cgit.mk index 8d4f5e0..90a2346 100644 --- a/cgit.mk +++ b/cgit.mk @@ -54,7 +54,7 @@ endif endif # Add -ldl to linker flags on systems that commonly use GNU libc. -ifneq (,$(filter $(uname_S),Linux GNU/kFreeBSD)) +ifneq (,$(filter $(uname_S),Linux GNU GNU/kFreeBSD)) CGIT_LIBS += -ldl endif From 91153fd02e62f2eaca8e6c140baa4f2abf39c40e Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Wed, 30 Nov 2016 10:43:08 +0100 Subject: [PATCH 205/387] git: update to v2.11.0 Update to git version v2.11.0. Function write_archive() dropped argument (int setup_prefix). --- Makefile | 2 +- git | 2 +- ui-snapshot.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 1ab2905..fe6cc98 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.10.2 +GIT_VER = 2.11.0 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.gz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index ac84098..454cb6b 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit ac84098b7e32406a982ac01cc76a663d5605224b +Subproject commit 454cb6bd52a4de614a3633e4f547af03d5c3b640 diff --git a/ui-snapshot.c b/ui-snapshot.c index 08c6e80..9b8cddd 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c @@ -37,7 +37,7 @@ static int write_archive_type(const char *format, const char *hex, const char *p /* argv_array guarantees a trailing NULL entry. */ memcpy(nargv, argv.argv, sizeof(char *) * (argv.argc + 1)); - result = write_archive(argv.argc, nargv, NULL, 1, NULL, 0); + result = write_archive(argv.argc, nargv, NULL, NULL, 0); argv_array_clear(&argv); free(nargv); return result; From 5564a5d06678b3f9b0725bc4b2383ea1b7eb5515 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Sun, 22 Jan 2017 12:44:44 +0100 Subject: [PATCH 206/387] syntax-highlighting: replace invalid unicode with ? --- filters/syntax-highlighting.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/filters/syntax-highlighting.py b/filters/syntax-highlighting.py index 1ca4108..5888b50 100755 --- a/filters/syntax-highlighting.py +++ b/filters/syntax-highlighting.py @@ -30,8 +30,8 @@ from pygments.lexers import guess_lexer_for_filename from pygments.formatters import HtmlFormatter -sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8') -sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') +sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8', errors='replace') +sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace') data = sys.stdin.read() filename = sys.argv[1] formatter = HtmlFormatter(style='pastie') From be39d22328f841536b8e44e8aaeed80a74ebb353 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer <lfleischer@lfos.de> Date: Thu, 24 Nov 2016 20:14:54 +0100 Subject: [PATCH 207/387] ui-patch: fix crash when using path limit The array passed to setup_revisions() must be NULL-terminated. Fixes a regression introduced in 455b598 (ui-patch.c: Use log_tree_commit() to generate diffs, 2013-08-20). Reported-by: Florian Pritz <bluewind@xinu.at> Signed-off-by: Lukas Fleischer <lfleischer@lfos.de> --- ui-patch.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ui-patch.c b/ui-patch.c index ec7f352..047e2f9 100644 --- a/ui-patch.c +++ b/ui-patch.c @@ -18,8 +18,8 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, struct commit *commit; struct object_id new_rev_oid, old_rev_oid; char rev_range[2 * 40 + 3]; - const char *rev_argv[] = { NULL, "--reverse", "--format=email", rev_range, "--", prefix }; - int rev_argc = ARRAY_SIZE(rev_argv); + const char *rev_argv[] = { NULL, "--reverse", "--format=email", rev_range, "--", prefix, NULL }; + int rev_argc = ARRAY_SIZE(rev_argv) - 1; char *patchname; if (!prefix) @@ -85,8 +85,7 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, DIFF_FORMAT_PATCH | DIFF_FORMAT_SUMMARY; if (prefix) rev.diffopt.stat_sep = fmt("(limited to '%s')\n\n", prefix); - setup_revisions(ARRAY_SIZE(rev_argv), rev_argv, &rev, - NULL); + setup_revisions(rev_argc, rev_argv, &rev, NULL); prepare_revision_walk(&rev); while ((commit = get_revision(&rev)) != NULL) { From 87c47488d02fcace4da0d468cd9ddd1651b7949e Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Thu, 30 Mar 2017 13:19:50 +0200 Subject: [PATCH 208/387] ui-repolist: properly sort by age When empty repos exist, comparing them against an existing repo with a good mtime might, with particular qsort implementations, not sort correctly, because of this brokenness: if (get_repo_modtime(r1, &t) && get_repo_modtime(r2, &t)) However, sorting by the age column works as expected, so anyway, to tidy things up, we simply reuse that function. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- ui-repolist.c | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/ui-repolist.c b/ui-repolist.c index b57ea60..20a4f56 100644 --- a/ui-repolist.c +++ b/ui-repolist.c @@ -184,27 +184,6 @@ static int cmp(const char *s1, const char *s2) return 0; } -static int sort_section(const void *a, const void *b) -{ - const struct cgit_repo *r1 = a; - const struct cgit_repo *r2 = b; - int result; - time_t t; - - result = cmp(r1->section, r2->section); - if (!result) { - if (!strcmp(ctx.cfg.repository_sort, "age")) { - // get_repo_modtime caches the value in r->mtime, so we don't - // have to worry about inefficiencies here. - if (get_repo_modtime(r1, &t) && get_repo_modtime(r2, &t)) - result = r2->mtime - r1->mtime; - } - if (!result) - result = cmp(r1->name, r2->name); - } - return result; -} - static int sort_name(const void *a, const void *b) { const struct cgit_repo *r1 = a; @@ -241,6 +220,23 @@ static int sort_idle(const void *a, const void *b) return t2 - t1; } +static int sort_section(const void *a, const void *b) +{ + const struct cgit_repo *r1 = a; + const struct cgit_repo *r2 = b; + int result; + time_t t; + + result = cmp(r1->section, r2->section); + if (!result) { + if (!strcmp(ctx.cfg.repository_sort, "age")) + result = sort_idle(r1, r2); + if (!result) + result = cmp(r1->name, r2->name); + } + return result; +} + struct sortcolumn { const char *name; int (*fn)(const void *a, const void *b); From 7ebdb30fdf91d1f63b4fb07e54b089136de5507b Mon Sep 17 00:00:00 2001 From: Lukas Fleischer <lfleischer@lfos.de> Date: Wed, 5 Apr 2017 06:38:27 +0200 Subject: [PATCH 209/387] Remove unused variable from sort_section() Signed-off-by: Lukas Fleischer <lfleischer@lfos.de> --- ui-repolist.c | 1 - 1 file changed, 1 deletion(-) diff --git a/ui-repolist.c b/ui-repolist.c index 20a4f56..7272e87 100644 --- a/ui-repolist.c +++ b/ui-repolist.c @@ -225,7 +225,6 @@ static int sort_section(const void *a, const void *b) const struct cgit_repo *r1 = a; const struct cgit_repo *r2 = b; int result; - time_t t; result = cmp(r1->section, r2->section); if (!result) { From 7ce19ba550ff0d32359b9fb35eeb6282747524b9 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer <lfleischer@lfos.de> Date: Thu, 27 Jul 2017 16:20:15 +0200 Subject: [PATCH 210/387] Update .mailmap with my new email address Signed-off-by: Lukas Fleischer <lfleischer@lfos.de> --- .mailmap | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.mailmap b/.mailmap index ca6b57e..03b5479 100644 --- a/.mailmap +++ b/.mailmap @@ -5,6 +5,6 @@ Lars Hjemli <hjemli@gmail.com> <larsh@hal-2004.(none)> Lars Hjemli <hjemli@gmail.com> <larsh@hatman.(none)> Lars Hjemli <hjemli@gmail.com> <larsh@slackbox.hjemli.net> Lars Hjemli <hjemli@gmail.com> <larsh@slaptop.hjemli.net> -Lukas Fleischer <cgit@cryptocrack.de> <cgit@crytocrack.de> -Lukas Fleischer <cgit@cryptocrack.de> <info@cryptocrack.de> +Lukas Fleischer <lfleischer@lfos.de> <cgit@cryptocrack.de> +Lukas Fleischer <lfleischer@lfos.de> <info@cryptocrack.de> Stefan Bühler <source@stbuehler.de> <lighttpd@stbuehler.de> From 3d33b46df24d4dee140d0aafb1eba5fffa314cf0 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Mon, 24 Jul 2017 17:22:52 +0200 Subject: [PATCH 211/387] git: update to v2.13.4 Update to git version v2.13.4: With commit 8aee769f (pathspec: copy and free owned memory) the definition of struct pathspec_item has changed with the expectation that pathspecs will be managed dynamically. We work around this a bit by setting up a static structure, but let's allocate the match string to avoid needing to cast away const. Updated a patch from John Keeping <john@keeping.me.uk> for git v2.12.1. --- Makefile | 2 +- git | 2 +- shared.c | 4 +++- ui-blob.c | 9 ++++++--- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index fe6cc98..3d792ce 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.11.0 +GIT_VER = 2.13.4 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.gz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index 454cb6b..cf8899d 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 454cb6bd52a4de614a3633e4f547af03d5c3b640 +Subproject commit cf8899d285d2648013040ec7196ffd3de0606664 diff --git a/shared.c b/shared.c index c63f1e3..13a65a9 100644 --- a/shared.c +++ b/shared.c @@ -352,7 +352,7 @@ void cgit_diff_tree(const struct object_id *old_oid, opt.format_callback = cgit_diff_tree_cb; opt.format_callback_data = fn; if (prefix) { - item.match = prefix; + item.match = xstrdup(prefix); item.len = strlen(prefix); opt.pathspec.nr = 1; opt.pathspec.items = &item; @@ -365,6 +365,8 @@ void cgit_diff_tree(const struct object_id *old_oid, diff_root_tree_sha1(new_oid->hash, "", &opt); diffcore_std(&opt); diff_flush(&opt); + + free(item.match); } void cgit_diff_commit(struct commit *commit, filepair_fn fn, const char *prefix) diff --git a/ui-blob.c b/ui-blob.c index 5f30de7..793817f 100644 --- a/ui-blob.c +++ b/ui-blob.c @@ -38,7 +38,7 @@ int cgit_ref_path_exists(const char *path, const char *ref, int file_only) struct object_id oid; unsigned long size; struct pathspec_item path_items = { - .match = path, + .match = xstrdup(path), .len = strlen(path) }; struct pathspec paths = { @@ -53,10 +53,13 @@ int cgit_ref_path_exists(const char *path, const char *ref, int file_only) }; if (get_oid(ref, &oid)) - return 0; + goto done; if (sha1_object_info(oid.hash, &size) != OBJ_COMMIT) - return 0; + goto done; read_tree_recursive(lookup_commit_reference(oid.hash)->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); + +done: + free(path_items.match); return walk_tree_ctx.found_path; } From 86a6d358f7a6c2432fde86b9e3c5011a656f20e4 Mon Sep 17 00:00:00 2001 From: Jeff Smith <whydoubt@gmail.com> Date: Wed, 9 Aug 2017 19:02:56 -0500 Subject: [PATCH 212/387] git: update to v2.14 Numerous changes were made to git functions to use an object_id structure rather than sending sha1 hashes as raw unsigned character arrays. The functions that affect cgit are: parse_object, lookup_commit_reference, lookup_tag, lookup_tree, parse_tree_indirect, diff_root_tree_sha1, diff_tree_sha1, and format_display_notes. Commit b2141fc (config: don't include config.h by default) made it necessary to that config.h be explicitly included when needed. Commit 07a3d41 (grep: remove regflags from the public grep_opt API) removed one way of specifying the ignore-case grep option. Signed-off-by: Jeff Smith <whydoubt@gmail.com> --- Makefile | 2 +- git | 2 +- scan-tree.c | 5 +++-- shared.c | 6 +++--- ui-blob.c | 6 +++--- ui-clone.c | 2 +- ui-commit.c | 6 +++--- ui-diff.c | 18 +++++++++--------- ui-log.c | 10 +++++----- ui-patch.c | 4 ++-- ui-plain.c | 2 +- ui-snapshot.c | 2 +- ui-tag.c | 4 ++-- ui-tree.c | 18 +++++++++--------- 14 files changed, 44 insertions(+), 43 deletions(-) diff --git a/Makefile b/Makefile index 3d792ce..f3ee84c 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.13.4 +GIT_VER = 2.14.0 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.gz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index cf8899d..4384e3c 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit cf8899d285d2648013040ec7196ffd3de0606664 +Subproject commit 4384e3cde2ce8ecd194202e171ae16333d241326 diff --git a/scan-tree.c b/scan-tree.c index 08f3f1d..6a2f65a 100644 --- a/scan-tree.c +++ b/scan-tree.c @@ -10,6 +10,7 @@ #include "scan-tree.h" #include "configfile.h" #include "html.h" +#include <config.h> /* return 1 if path contains a objects/ directory and a HEAD file */ static int is_git_dir(const char *path) @@ -48,7 +49,7 @@ out: static struct cgit_repo *repo; static repo_config_fn config_fn; -static void repo_config(const char *name, const char *value) +static void scan_tree_repo_config(const char *name, const char *value) { config_fn(repo, name, value); } @@ -178,7 +179,7 @@ static void add_repo(const char *base, struct strbuf *path, repo_config_fn fn) strbuf_addstr(path, "cgitrc"); if (!stat(path->buf, &st)) - parse_configfile(path->buf, &repo_config); + parse_configfile(path->buf, &scan_tree_repo_config); strbuf_release(&rel); } diff --git a/shared.c b/shared.c index 13a65a9..df3f611 100644 --- a/shared.c +++ b/shared.c @@ -160,7 +160,7 @@ static struct refinfo *cgit_mk_refinfo(const char *refname, const struct object_ ref = xmalloc(sizeof (struct refinfo)); ref->refname = xstrdup(refname); - ref->object = parse_object(oid->hash); + ref->object = parse_object(oid); switch (ref->object->type) { case OBJ_TAG: ref->tag = cgit_parse_tag((struct tag *)ref->object); @@ -360,9 +360,9 @@ void cgit_diff_tree(const struct object_id *old_oid, diff_setup_done(&opt); if (old_oid && !is_null_oid(old_oid)) - diff_tree_sha1(old_oid->hash, new_oid->hash, "", &opt); + diff_tree_oid(old_oid, new_oid, "", &opt); else - diff_root_tree_sha1(new_oid->hash, "", &opt); + diff_root_tree_oid(new_oid, "", &opt); diffcore_std(&opt); diff_flush(&opt); diff --git a/ui-blob.c b/ui-blob.c index 793817f..761e886 100644 --- a/ui-blob.c +++ b/ui-blob.c @@ -56,7 +56,7 @@ int cgit_ref_path_exists(const char *path, const char *ref, int file_only) goto done; if (sha1_object_info(oid.hash, &size) != OBJ_COMMIT) goto done; - read_tree_recursive(lookup_commit_reference(oid.hash)->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); + read_tree_recursive(lookup_commit_reference(&oid)->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); done: free(path_items.match); @@ -89,7 +89,7 @@ int cgit_print_file(char *path, const char *head, int file_only) return -1; type = sha1_object_info(oid.hash, &size); if (type == OBJ_COMMIT) { - commit = lookup_commit_reference(oid.hash); + commit = lookup_commit_reference(&oid); read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); if (!walk_tree_ctx.found_path) return -1; @@ -145,7 +145,7 @@ void cgit_print_blob(const char *hex, char *path, const char *head, int file_onl type = sha1_object_info(oid.hash, &size); if ((!hex) && type == OBJ_COMMIT && path) { - commit = lookup_commit_reference(oid.hash); + commit = lookup_commit_reference(&oid); read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); type = sha1_object_info(oid.hash, &size); } diff --git a/ui-clone.c b/ui-clone.c index 5f6606a..0d11672 100644 --- a/ui-clone.c +++ b/ui-clone.c @@ -17,7 +17,7 @@ static int print_ref_info(const char *refname, const struct object_id *oid, { struct object *obj; - if (!(obj = parse_object(oid->hash))) + if (!(obj = parse_object(oid))) return 0; htmlf("%s\t%s\n", oid_to_hex(oid), refname); diff --git a/ui-commit.c b/ui-commit.c index db69d54..586fea0 100644 --- a/ui-commit.c +++ b/ui-commit.c @@ -31,7 +31,7 @@ void cgit_print_commit(char *hex, const char *prefix) "Bad object id: %s", hex); return; } - commit = lookup_commit_reference(oid.hash); + commit = lookup_commit_reference(&oid); if (!commit) { cgit_print_error_page(404, "Not found", "Bad commit reference: %s", hex); @@ -39,7 +39,7 @@ void cgit_print_commit(char *hex, const char *prefix) } info = cgit_parse_commit(commit); - format_display_notes(oid.hash, ¬es, PAGE_ENCODING, 0); + format_display_notes(&oid, ¬es, PAGE_ENCODING, 0); load_ref_decorations(DECORATE_FULL_REFS); @@ -87,7 +87,7 @@ void cgit_print_commit(char *hex, const char *prefix) free(tmp); html("</td></tr>\n"); for (p = commit->parents; p; p = p->next) { - parent = lookup_commit_reference(p->item->object.oid.hash); + parent = lookup_commit_reference(&p->item->object.oid); if (!parent) { html("<tr><td colspan='3'>"); cgit_print_error("Error reading parent commit"); diff --git a/ui-diff.c b/ui-diff.c index 173d351..c7fb49b 100644 --- a/ui-diff.c +++ b/ui-diff.c @@ -385,7 +385,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefix, int show_ctrls, int raw) { struct commit *commit, *commit2; - const unsigned char *old_tree_sha1, *new_tree_sha1; + const struct object_id *old_tree_oid, *new_tree_oid; diff_type difftype; /* @@ -407,13 +407,13 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, "Bad object name: %s", new_rev); return; } - commit = lookup_commit_reference(new_rev_oid->hash); + commit = lookup_commit_reference(new_rev_oid); if (!commit || parse_commit(commit)) { cgit_print_error_page(404, "Not found", "Bad commit: %s", oid_to_hex(new_rev_oid)); return; } - new_tree_sha1 = commit->tree->object.oid.hash; + new_tree_oid = &commit->tree->object.oid; if (old_rev) { if (get_oid(old_rev, old_rev_oid)) { @@ -428,15 +428,15 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, } if (!is_null_oid(old_rev_oid)) { - commit2 = lookup_commit_reference(old_rev_oid->hash); + commit2 = lookup_commit_reference(old_rev_oid); if (!commit2 || parse_commit(commit2)) { cgit_print_error_page(404, "Not found", "Bad commit: %s", oid_to_hex(old_rev_oid)); return; } - old_tree_sha1 = commit2->tree->object.oid.hash; + old_tree_oid = &commit2->tree->object.oid; } else { - old_tree_sha1 = NULL; + old_tree_oid = NULL; } if (raw) { @@ -449,11 +449,11 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, ctx.page.mimetype = "text/plain"; cgit_print_http_headers(); - if (old_tree_sha1) { - diff_tree_sha1(old_tree_sha1, new_tree_sha1, "", + if (old_tree_oid) { + diff_tree_oid(old_tree_oid, new_tree_oid, "", &diffopt); } else { - diff_root_tree_sha1(new_tree_sha1, "", &diffopt); + diff_root_tree_oid(new_tree_oid, "", &diffopt); } diffcore_std(&diffopt); diff_flush(&diffopt); diff --git a/ui-log.c b/ui-log.c index 3220fd9..2d2bb31 100644 --- a/ui-log.c +++ b/ui-log.c @@ -150,9 +150,9 @@ static int show_commit(struct commit *commit, struct rev_info *revs) rem_lines = 0; DIFF_OPT_SET(&revs->diffopt, RECURSIVE); - diff_tree_sha1(parent->tree->object.oid.hash, - commit->tree->object.oid.hash, - "", &revs->diffopt); + diff_tree_oid(&parent->tree->object.oid, + &commit->tree->object.oid, + "", &revs->diffopt); diffcore_std(&revs->diffopt); found = !diff_queue_is_empty(); @@ -273,7 +273,7 @@ static void print_commit(struct commit *commit, struct rev_info *revs) strbuf_addstr(&msgbuf, info->msg); strbuf_addch(&msgbuf, '\n'); } - format_display_notes(commit->object.oid.hash, + format_display_notes(&commit->object.oid, &msgbuf, PAGE_ENCODING, 0); strbuf_addch(&msgbuf, '\n'); strbuf_ltrim(&msgbuf); @@ -436,7 +436,7 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern setup_revisions(rev_argv.argc, rev_argv.argv, &rev, NULL); load_ref_decorations(DECORATE_FULL_REFS); rev.show_decorations = 1; - rev.grep_filter.regflags |= REG_ICASE; + rev.grep_filter.ignore_case = 1; rev.diffopt.detect_rename = 1; rev.diffopt.rename_limit = ctx.cfg.renamelimit; diff --git a/ui-patch.c b/ui-patch.c index 047e2f9..69aa4a8 100644 --- a/ui-patch.c +++ b/ui-patch.c @@ -33,7 +33,7 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, "Bad object id: %s", new_rev); return; } - commit = lookup_commit_reference(new_rev_oid.hash); + commit = lookup_commit_reference(&new_rev_oid); if (!commit) { cgit_print_error_page(404, "Not found", "Bad commit reference: %s", new_rev); @@ -46,7 +46,7 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, "Bad object id: %s", old_rev); return; } - if (!lookup_commit_reference(old_rev_oid.hash)) { + if (!lookup_commit_reference(&old_rev_oid)) { cgit_print_error_page(404, "Not found", "Bad commit reference: %s", old_rev); return; diff --git a/ui-plain.c b/ui-plain.c index 8d541e3..e45d553 100644 --- a/ui-plain.c +++ b/ui-plain.c @@ -185,7 +185,7 @@ void cgit_print_plain(void) cgit_print_error_page(404, "Not found", "Not found"); return; } - commit = lookup_commit_reference(oid.hash); + commit = lookup_commit_reference(&oid); if (!commit || parse_commit(commit)) { cgit_print_error_page(404, "Not found", "Not found"); return; diff --git a/ui-snapshot.c b/ui-snapshot.c index 9b8cddd..b2d95f7 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c @@ -116,7 +116,7 @@ static int make_snapshot(const struct cgit_snapshot_format *format, "Bad object id: %s", hex); return 1; } - if (!lookup_commit_reference(oid.hash)) { + if (!lookup_commit_reference(&oid)) { cgit_print_error_page(400, "Bad request", "Not a commit reference: %s", hex); return 1; diff --git a/ui-tag.c b/ui-tag.c index afd7d61..909cde0 100644 --- a/ui-tag.c +++ b/ui-tag.c @@ -54,7 +54,7 @@ void cgit_print_tag(char *revname) "Bad tag reference: %s", revname); goto cleanup; } - obj = parse_object(oid.hash); + obj = parse_object(&oid); if (!obj) { cgit_print_error_page(500, "Internal server error", "Bad object id: %s", oid_to_hex(&oid)); @@ -64,7 +64,7 @@ void cgit_print_tag(char *revname) struct tag *tag; struct taginfo *info; - tag = lookup_tag(oid.hash); + tag = lookup_tag(&oid); if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) { cgit_print_error_page(500, "Internal server error", "Bad tag object: %s", revname); diff --git a/ui-tree.c b/ui-tree.c index b310242..ca24a03 100644 --- a/ui-tree.c +++ b/ui-tree.c @@ -157,7 +157,7 @@ static void print_object(const unsigned char *sha1, char *path, const char *base struct single_tree_ctx { struct strbuf *path; - unsigned char sha1[GIT_SHA1_RAWSZ]; + struct object_id oid; char *name; size_t count; }; @@ -177,7 +177,7 @@ static int single_tree_cb(const unsigned char *sha1, struct strbuf *base, } ctx->name = xstrdup(pathname); - hashcpy(ctx->sha1, sha1); + hashcpy(ctx->oid.hash, sha1); strbuf_addf(ctx->path, "/%s", pathname); return 0; } @@ -195,13 +195,13 @@ static void write_tree_link(const unsigned char *sha1, char *name, .nr = 0 }; - hashcpy(tree_ctx.sha1, sha1); + hashcpy(tree_ctx.oid.hash, sha1); while (tree_ctx.count == 1) { cgit_tree_link(name, NULL, "ls-dir", ctx.qry.head, rev, fullpath->buf); - tree = lookup_tree(tree_ctx.sha1); + tree = lookup_tree(&tree_ctx.oid); if (!tree) return; @@ -300,17 +300,17 @@ static void ls_tail(void) cgit_print_layout_end(); } -static void ls_tree(const unsigned char *sha1, char *path, struct walk_tree_context *walk_tree_ctx) +static void ls_tree(const struct object_id *oid, char *path, struct walk_tree_context *walk_tree_ctx) { struct tree *tree; struct pathspec paths = { .nr = 0 }; - tree = parse_tree_indirect(sha1); + tree = parse_tree_indirect(oid); if (!tree) { cgit_print_error_page(404, "Not found", - "Not a tree object: %s", sha1_to_hex(sha1)); + "Not a tree object: %s", sha1_to_hex(oid->hash)); return; } @@ -380,7 +380,7 @@ void cgit_print_tree(const char *rev, char *path) "Invalid revision name: %s", rev); return; } - commit = lookup_commit_reference(oid.hash); + commit = lookup_commit_reference(&oid); if (!commit || parse_commit(commit)) { cgit_print_error_page(404, "Not found", "Invalid commit reference: %s", rev); @@ -390,7 +390,7 @@ void cgit_print_tree(const char *rev, char *path) walk_tree_ctx.curr_rev = xstrdup(rev); if (path == NULL) { - ls_tree(commit->tree->object.oid.hash, NULL, &walk_tree_ctx); + ls_tree(&commit->tree->object.oid, NULL, &walk_tree_ctx); goto cleanup; } From 6d3c8bc37f6124c2193d66587079975d381aa435 Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Sun, 15 Jan 2017 12:29:38 +0000 Subject: [PATCH 213/387] ui-atom: properly escape delimiter in page link If the delimiter here is '&' then it needs to be escaped for inclusion in an attribute. Use html_attrf() to ensure that this happens (we know that hex won't need escaping, but this makes it clearer what's happening. Signed-off-by: John Keeping <john@keeping.me.uk> --- ui-atom.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui-atom.c b/ui-atom.c index 41838d3..3866823 100644 --- a/ui-atom.c +++ b/ui-atom.c @@ -63,7 +63,7 @@ static void add_entry(struct commit *commit, const char *host) html_attr(pageurl); if (ctx.cfg.virtual_root) delim = '?'; - htmlf("%cid=%s", delim, hex); + html_attrf("%cid=%s", delim, hex); html("'/>\n"); free(pageurl); } From 1b4ef6783a71962f8b5da3a23f2830f0f0f55ea0 Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Sun, 19 Feb 2017 12:27:48 +0000 Subject: [PATCH 214/387] ui-shared: don't print path crumbs without a repo cgit_print_path_crumbs() can call repolink() which assumes that ctx.repo is non-null. Currently we don't have any commands that set want_vpath without also setting want_repo so it shouldn't be possible to fail this test, but the check in cgit.c is in the wrong order so it is possible to specify a query string like "?p=log&path=foo/bar" to end up here without a valid repository. This was found by American fuzzy lop [0]. [0] http://lcamtuf.coredump.cx/afl/ Signed-off-by: John Keeping <john@keeping.me.uk> --- ui-shared.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui-shared.c b/ui-shared.c index 2e4fcd9..e5c9a02 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -1039,7 +1039,7 @@ void cgit_print_pageheader(void) free(currenturl); } html("</td></tr></table>\n"); - if (ctx.env.authenticated && ctx.qry.vpath) { + if (ctx.env.authenticated && ctx.repo && ctx.qry.vpath) { html("<div class='path'>"); html("path: "); cgit_print_path_crumbs(ctx.qry.vpath); From c699866699411346c5dba406457581013f85a873 Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Sun, 19 Feb 2017 12:17:05 +0000 Subject: [PATCH 215/387] parsing: clear query path before starting By specifying the "url" query parameter multiple times it is possible to end up with ctx.qry.vpath set while ctx.repo is null, which triggers an invalid code path from cgit_print_pageheader() while printing path crumbs, resulting in a null dereference. The previous patch fixed this segfault, but it makes no sense for us to clear ctx.repo while leaving ctx.qry.path set to the previous value, so let's just clear it here so that the last "url" parameter given takes full effect rather than partially overriding the effect of the previous value. Signed-off-by: John Keeping <john@keeping.me.uk> --- parsing.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parsing.c b/parsing.c index 9dacb16..b8d7f10 100644 --- a/parsing.c +++ b/parsing.c @@ -21,6 +21,7 @@ void cgit_parse_url(const char *url) struct cgit_repo *repo; ctx.repo = NULL; + ctx.qry.page = NULL; if (!url || url[0] == '\0') return; @@ -53,7 +54,6 @@ void cgit_parse_url(const char *url) } if (cmd[1]) ctx.qry.page = xstrdup(cmd + 1); - return; } } From 113f4b85886bc5eb6b319fd048623b8d43b7bce0 Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Sun, 19 Feb 2017 12:02:37 +0000 Subject: [PATCH 216/387] cgit: don't set vpath unless repo is set After the previous two patches, this can be classified as a tidy up rather than a bug fix, but I think it makes sense to group all of the tests together before setting up the environment for the command to execute. Signed-off-by: John Keeping <john@keeping.me.uk> --- cgit.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cgit.c b/cgit.c index 1075753..1dae4b8 100644 --- a/cgit.c +++ b/cgit.c @@ -726,18 +726,18 @@ static void process_request(void) return; } - /* If cmd->want_vpath is set, assume ctx.qry.path contains a "virtual" - * in-project path limit to be made available at ctx.qry.vpath. - * Otherwise, no path limit is in effect (ctx.qry.vpath = NULL). - */ - ctx.qry.vpath = cmd->want_vpath ? ctx.qry.path : NULL; - if (cmd->want_repo && !ctx.repo) { cgit_print_error_page(400, "Bad request", "No repository selected"); return; } + /* If cmd->want_vpath is set, assume ctx.qry.path contains a "virtual" + * in-project path limit to be made available at ctx.qry.vpath. + * Otherwise, no path limit is in effect (ctx.qry.vpath = NULL). + */ + ctx.qry.vpath = cmd->want_vpath ? ctx.qry.path : NULL; + if (ctx.repo && prepare_repo_cmd()) return; From 51cc456b773a3bb7253fad2146c1a0d2b0fa98cb Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Mon, 6 Mar 2017 23:27:23 +0000 Subject: [PATCH 217/387] ui-plain: print symlink content We currently ignore symlinks in ui-plain, leading to a 404. In ui-tree we print the content of the blob (that is, the path to the target of the link), so it makes sense to do the same here. Signed-off-by: John Keeping <john@keeping.me.uk> --- ui-plain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui-plain.c b/ui-plain.c index e45d553..cfdbf73 100644 --- a/ui-plain.c +++ b/ui-plain.c @@ -135,7 +135,7 @@ static int walk_tree(const unsigned char *sha1, struct strbuf *base, struct walk_tree_context *walk_tree_ctx = cbdata; if (base->len == walk_tree_ctx->match_baselen) { - if (S_ISREG(mode)) { + if (S_ISREG(mode) || S_ISLNK(mode)) { if (print_object(sha1, pathname)) walk_tree_ctx->match = 1; } else if (S_ISDIR(mode)) { From de297883385030f4bdcd2f5c3839d1187611b949 Mon Sep 17 00:00:00 2001 From: "Daniel M. Weeks" <dan@danweeks.net> Date: Wed, 20 Sep 2017 11:17:29 -0400 Subject: [PATCH 218/387] Use https for submodule The git protocol provides no transport security. https does provide transport security and should be preferred by default. https is also more likely than git to be permitted by firewalls in restricted environments. Signed-off-by: Daniel M. Weeks <dan@danweeks.net> --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 1daea94..5c6ecb4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "git"] - url = git://git.kernel.org/pub/scm/git/git.git + url = https://git.kernel.org/pub/scm/git/git.git path = git From 3b485cc5422f800d142c7023295e82c0a1c10b19 Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Mon, 24 Apr 2017 19:38:34 +0100 Subject: [PATCH 219/387] cache: flush stdio before restoring FDs As described in commit 2efb59e (ui-patch: Flush stdout after outputting data, 2014-06-11), we need to ensure that stdout is flushed before restoring the file descriptor when writing to the cache. It turns out that it's not just ui-patch that is affected by this but also raw diff which writes to stdout internally. Let's avoid risking more places doing this by ensuring that stdout is flushed after writing in fill_slot(). Signed-off-by: John Keeping <john@keeping.me.uk> --- cache.c | 6 ++++++ ui-patch.c | 2 -- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/cache.c b/cache.c index 6736a01..2ccdc4e 100644 --- a/cache.c +++ b/cache.c @@ -224,6 +224,12 @@ static int fill_slot(struct cache_slot *slot) /* Generate cache content */ slot->fn(); + /* Make sure any buffered data is flushed to the file */ + if (fflush(stdout)) { + close(tmp); + return errno; + } + /* update stat info */ if (fstat(slot->lock_fd, &slot->cache_st)) { close(tmp); diff --git a/ui-patch.c b/ui-patch.c index 69aa4a8..8007a11 100644 --- a/ui-patch.c +++ b/ui-patch.c @@ -92,6 +92,4 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, log_tree_commit(&rev, commit); printf("-- \ncgit %s\n\n", cgit_version); } - - fflush(stdout); } From 70787254b270b1505aa8427813f64131be5df86c Mon Sep 17 00:00:00 2001 From: Jeff Smith <whydoubt@gmail.com> Date: Sun, 1 Oct 2017 23:39:05 -0500 Subject: [PATCH 220/387] html: html_ntxt with no ellipsis For implementing a ui-blame page, there is need for a function that outputs a selection from a block of text, transformed for HTML output, but with no further modifications or additions. Signed-off-by: Jeff Smith <whydoubt@gmail.com> Reviewed-by: John Keeping <john@keeping.me.uk> --- html.c | 32 +++++++++++--------------------- html.h | 2 +- ui-repolist.c | 3 ++- 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/html.c b/html.c index e7e6e07..7f81965 100644 --- a/html.c +++ b/html.c @@ -124,29 +124,20 @@ void html_vtxtf(const char *format, va_list ap) void html_txt(const char *txt) { - const char *t = txt; - while (t && *t) { - int c = *t; - if (c == '<' || c == '>' || c == '&') { - html_raw(txt, t - txt); - if (c == '>') - html(">"); - else if (c == '<') - html("<"); - else if (c == '&') - html("&"); - txt = t + 1; - } - t++; - } - if (t != txt) - html(txt); + if (txt) + html_ntxt(txt, strlen(txt)); } -void html_ntxt(int len, const char *txt) +ssize_t html_ntxt(const char *txt, size_t len) { const char *t = txt; - while (t && *t && len--) { + ssize_t slen; + + if (len > SSIZE_MAX) + return -1; + + slen = (ssize_t) len; + while (t && *t && slen--) { int c = *t; if (c == '<' || c == '>' || c == '&') { html_raw(txt, t - txt); @@ -162,8 +153,7 @@ void html_ntxt(int len, const char *txt) } if (t != txt) html_raw(txt, t - txt); - if (len < 0) - html("..."); + return slen; } void html_attrf(const char *fmt, ...) diff --git a/html.h b/html.h index 1b24e55..fa4de77 100644 --- a/html.h +++ b/html.h @@ -19,7 +19,7 @@ __attribute__((format (printf,1,2))) extern void html_attrf(const char *format,...); extern void html_txt(const char *txt); -extern void html_ntxt(int len, const char *txt); +extern ssize_t html_ntxt(const char *txt, size_t len); extern void html_attr(const char *txt); extern void html_url_path(const char *txt); extern void html_url_arg(const char *txt); diff --git a/ui-repolist.c b/ui-repolist.c index 7272e87..af52f9b 100644 --- a/ui-repolist.c +++ b/ui-repolist.c @@ -329,7 +329,8 @@ void cgit_print_repolist(void) repourl = cgit_repourl(ctx.repo->url); html_link_open(repourl, NULL, NULL); free(repourl); - html_ntxt(ctx.cfg.max_repodesc_len, ctx.repo->desc); + if (html_ntxt(ctx.repo->desc, ctx.cfg.max_repodesc_len) < 0) + html("..."); html_link_close(); html("</td><td>"); if (ctx.cfg.enable_index_owner) { From 9337c7ee83221d48d02c3c7b5c9dcbaca23ad92f Mon Sep 17 00:00:00 2001 From: Jeff Smith <whydoubt@gmail.com> Date: Sun, 1 Oct 2017 23:39:06 -0500 Subject: [PATCH 221/387] ui-tree: move set_title_from_path to ui-shared The ui-blame code will also need to call set_title_from_path, so go ahead and move it to ui-shared. Signed-off-by: Jeff Smith <whydoubt@gmail.com> Reviewed-by: John Keeping <john@keeping.me.uk> --- ui-shared.c | 31 +++++++++++++++++++++++++++++++ ui-shared.h | 2 ++ ui-tree.c | 35 ++--------------------------------- 3 files changed, 35 insertions(+), 33 deletions(-) diff --git a/ui-shared.c b/ui-shared.c index e5c9a02..2547e43 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -1111,3 +1111,34 @@ void cgit_print_snapshot_links(const char *repo, const char *head, } strbuf_release(&filename); } + +void cgit_set_title_from_path(const char *path) +{ + size_t path_len, path_index, path_last_end; + char *new_title; + + if (!path) + return; + + path_len = strlen(path); + new_title = xmalloc(path_len + 3 + strlen(ctx.page.title) + 1); + new_title[0] = '\0'; + + for (path_index = path_len, path_last_end = path_len; path_index-- > 0;) { + if (path[path_index] == '/') { + if (path_index == path_len - 1) { + path_last_end = path_index - 1; + continue; + } + strncat(new_title, &path[path_index + 1], path_last_end - path_index - 1); + strcat(new_title, "\\"); + path_last_end = path_index; + } + } + if (path_last_end) + strncat(new_title, path, path_last_end); + + strcat(new_title, " - "); + strcat(new_title, ctx.page.title); + ctx.page.title = new_title; +} diff --git a/ui-shared.h b/ui-shared.h index 87799f1..40f6207 100644 --- a/ui-shared.h +++ b/ui-shared.h @@ -77,4 +77,6 @@ extern void cgit_print_snapshot_links(const char *repo, const char *head, const char *hex, int snapshots); extern void cgit_add_hidden_formfields(int incl_head, int incl_search, const char *page); + +extern void cgit_set_title_from_path(const char *path); #endif /* UI_SHARED_H */ diff --git a/ui-tree.c b/ui-tree.c index ca24a03..3925809 100644 --- a/ui-tree.c +++ b/ui-tree.c @@ -84,37 +84,6 @@ static void print_binary_buffer(char *buf, unsigned long size) html("</table>\n"); } -static void set_title_from_path(const char *path) -{ - size_t path_len, path_index, path_last_end; - char *new_title; - - if (!path) - return; - - path_len = strlen(path); - new_title = xmalloc(path_len + 3 + strlen(ctx.page.title) + 1); - new_title[0] = '\0'; - - for (path_index = path_len, path_last_end = path_len; path_index-- > 0;) { - if (path[path_index] == '/') { - if (path_index == path_len - 1) { - path_last_end = path_index - 1; - continue; - } - strncat(new_title, &path[path_index + 1], path_last_end - path_index - 1); - strcat(new_title, "\\"); - path_last_end = path_index; - } - } - if (path_last_end) - strncat(new_title, path, path_last_end); - - strcat(new_title, " - "); - strcat(new_title, ctx.page.title); - ctx.page.title = new_title; -} - static void print_object(const unsigned char *sha1, char *path, const char *basename, const char *rev) { enum object_type type; @@ -135,7 +104,7 @@ static void print_object(const unsigned char *sha1, char *path, const char *base return; } - set_title_from_path(path); + cgit_set_title_from_path(path); cgit_print_layout_start(); htmlf("blob: %s (", sha1_to_hex(sha1)); @@ -335,7 +304,7 @@ static int walk_tree(const unsigned char *sha1, struct strbuf *base, if (S_ISDIR(mode)) { walk_tree_ctx->state = 1; - set_title_from_path(buffer.buf); + cgit_set_title_from_path(buffer.buf); strbuf_release(&buffer); ls_head(); return READ_TREE_RECURSIVE; From f6ffe40d1a2c985494e48dc2d36663ffde1e6044 Mon Sep 17 00:00:00 2001 From: Jeff Smith <whydoubt@gmail.com> Date: Sun, 1 Oct 2017 23:39:07 -0500 Subject: [PATCH 222/387] ui-shared: make a char* parameter const All cgit_xxx_link functions take const char* for the 'name' parameter, except for cgit_commit_link, which takes a char* and subsequently modifies the contents. Avoiding the content changes, and making it const char* will avoid the need to make copies of const char* strings being passed to cgit_commit_link. Signed-off-by: Jeff Smith <whydoubt@gmail.com> Reviewed-by: John Keeping <john@keeping.me.uk> --- ui-shared.c | 19 ++++++++----------- ui-shared.h | 2 +- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/ui-shared.c b/ui-shared.c index 2547e43..315dedb 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -347,18 +347,11 @@ void cgit_log_link(const char *name, const char *title, const char *class, html("</a>"); } -void cgit_commit_link(char *name, const char *title, const char *class, +void cgit_commit_link(const char *name, const char *title, const char *class, const char *head, const char *rev, const char *path) { char *delim; - if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) { - name[ctx.cfg.max_msg_len] = '\0'; - name[ctx.cfg.max_msg_len - 1] = '.'; - name[ctx.cfg.max_msg_len - 2] = '.'; - name[ctx.cfg.max_msg_len - 3] = '.'; - } - delim = repolink(title, class, "commit", head, path); if (rev && ctx.qry.head && strcmp(rev, ctx.qry.head)) { html(delim); @@ -387,9 +380,13 @@ void cgit_commit_link(char *name, const char *title, const char *class, html("follow=1"); } html("'>"); - if (name[0] != '\0') - html_txt(name); - else + if (name[0] != '\0') { + if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) { + html_ntxt(name, ctx.cfg.max_msg_len - 3); + html("..."); + } else + html_txt(name); + } else html_txt("(no commit message)"); html("</a>"); } diff --git a/ui-shared.h b/ui-shared.h index 40f6207..2cd7ac9 100644 --- a/ui-shared.h +++ b/ui-shared.h @@ -30,7 +30,7 @@ extern void cgit_log_link(const char *name, const char *title, const char *class, const char *head, const char *rev, const char *path, int ofs, const char *grep, const char *pattern, int showmsg, int follow); -extern void cgit_commit_link(char *name, const char *title, +extern void cgit_commit_link(const char *name, const char *title, const char *class, const char *head, const char *rev, const char *path); extern void cgit_patch_link(const char *name, const char *title, From c1cd290d1f83d3d1c2d081d734e8d213f12cc06b Mon Sep 17 00:00:00 2001 From: Jeff Smith <whydoubt@gmail.com> Date: Sun, 1 Oct 2017 23:39:08 -0500 Subject: [PATCH 223/387] ui-blame: add blame UI Implement a page which provides the blame view of a specified file. This feature is controlled by a new config variable, "enable-blame", which is disabled by default. Signed-off-by: Jeff Smith <whydoubt@gmail.com> Reviewed-by: John Keeping <john@keeping.me.uk> --- cgit.c | 2 + cgit.css | 8 ++ cgit.h | 1 + cgit.mk | 1 + cgitrc.5.txt | 9 ++ cmd.c | 12 ++- ui-blame.c | 227 +++++++++++++++++++++++++++++++++++++++++++++++++++ ui-blame.h | 6 ++ 8 files changed, 265 insertions(+), 1 deletion(-) create mode 100644 ui-blame.c create mode 100644 ui-blame.h diff --git a/cgit.c b/cgit.c index 1dae4b8..972a67e 100644 --- a/cgit.c +++ b/cgit.c @@ -167,6 +167,8 @@ static void config_cb(const char *name, const char *value) ctx.cfg.enable_index_links = atoi(value); else if (!strcmp(name, "enable-index-owner")) ctx.cfg.enable_index_owner = atoi(value); + else if (!strcmp(name, "enable-blame")) + ctx.cfg.enable_blame = atoi(value); else if (!strcmp(name, "enable-commit-graph")) ctx.cfg.enable_commit_graph = atoi(value); else if (!strcmp(name, "enable-log-filecount")) diff --git a/cgit.css b/cgit.css index 1dc2c11..836f8ae 100644 --- a/cgit.css +++ b/cgit.css @@ -329,6 +329,14 @@ div#cgit table.ssdiff td.lineno a:hover { color: black; } +div#cgit table.blame tr:nth-child(even) { + background: #eee; +} + +div#cgit table.blame tr:nth-child(odd) { + background: white; +} + div#cgit table.bin-blob { margin-top: 0.5em; border: solid 1px black; diff --git a/cgit.h b/cgit.h index fbc6c6a..0b88dcd 100644 --- a/cgit.h +++ b/cgit.h @@ -228,6 +228,7 @@ struct cgit_config { int enable_http_clone; int enable_index_links; int enable_index_owner; + int enable_blame; int enable_commit_graph; int enable_log_filecount; int enable_log_linecount; diff --git a/cgit.mk b/cgit.mk index 90a2346..3fcc1ca 100644 --- a/cgit.mk +++ b/cgit.mk @@ -77,6 +77,7 @@ CGIT_OBJ_NAMES += parsing.o CGIT_OBJ_NAMES += scan-tree.o CGIT_OBJ_NAMES += shared.o CGIT_OBJ_NAMES += ui-atom.o +CGIT_OBJ_NAMES += ui-blame.o CGIT_OBJ_NAMES += ui-blob.o CGIT_OBJ_NAMES += ui-clone.o CGIT_OBJ_NAMES += ui-commit.o diff --git a/cgitrc.5.txt b/cgitrc.5.txt index 9fcf445..4da166c 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -141,6 +141,11 @@ embedded:: suitable for embedding in other html pages. Default value: none. See also: "noheader". +enable-blame:: + Flag which, when set to "1", will allow cgit to provide a "blame" page + for files, and will make it generate links to that page in appropriate + places. Default value: "0". + enable-commit-graph:: Flag which, when set to "1", will make cgit print an ASCII-art commit history graph to the left of the commit messages in the repository @@ -799,6 +804,10 @@ enable-http-clone=1 enable-index-links=1 +# Enable blame page and create links to it from tree page +enable-blame=1 + + # Enable ASCII art commit history graph on the log pages enable-commit-graph=1 diff --git a/cmd.c b/cmd.c index d280e95..63f0ae5 100644 --- a/cmd.c +++ b/cmd.c @@ -1,6 +1,6 @@ /* cmd.c: the cgit command dispatcher * - * Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com> + * Copyright (C) 2006-2017 cgit Development Team <cgit@lists.zx2c4.com> * * Licensed under GNU General Public License v2 * (see COPYING for full license text) @@ -11,6 +11,7 @@ #include "cache.h" #include "ui-shared.h" #include "ui-atom.h" +#include "ui-blame.h" #include "ui-blob.h" #include "ui-clone.h" #include "ui-commit.h" @@ -63,6 +64,14 @@ static void about_fn(void) cgit_print_site_readme(); } +static void blame_fn(void) +{ + if (ctx.cfg.enable_blame) + cgit_print_blame(); + else + cgit_print_error_page(403, "Forbidden", "Blame is disabled"); +} + static void blob_fn(void) { cgit_print_blob(ctx.qry.sha1, ctx.qry.path, ctx.qry.head, 0); @@ -164,6 +173,7 @@ struct cgit_cmd *cgit_get_cmd(void) def_cmd(HEAD, 1, 0, 1), def_cmd(atom, 1, 0, 0), def_cmd(about, 0, 0, 0), + def_cmd(blame, 1, 1, 0), def_cmd(blob, 1, 0, 0), def_cmd(commit, 1, 1, 0), def_cmd(diff, 1, 1, 0), diff --git a/ui-blame.c b/ui-blame.c new file mode 100644 index 0000000..62cf431 --- /dev/null +++ b/ui-blame.c @@ -0,0 +1,227 @@ +/* ui-blame.c: functions for blame output + * + * Copyright (C) 2006-2017 cgit Development Team <cgit@lists.zx2c4.com> + * + * Licensed under GNU General Public License v2 + * (see COPYING for full license text) + */ + +#include "cgit.h" +#include "ui-blame.h" +#include "html.h" +#include "ui-shared.h" +#include "argv-array.h" +#include "blame.h" + + +static char *emit_suspect_detail(struct blame_origin *suspect) +{ + struct commitinfo *info; + struct strbuf detail = STRBUF_INIT; + + info = cgit_parse_commit(suspect->commit); + + strbuf_addf(&detail, "author %s", info->author); + if (!ctx.cfg.noplainemail) + strbuf_addf(&detail, " %s", info->author_email); + strbuf_addf(&detail, " %s\n", + show_date(info->author_date, info->author_tz, + cgit_date_mode(DATE_ISO8601))); + + strbuf_addf(&detail, "committer %s", info->committer); + if (!ctx.cfg.noplainemail) + strbuf_addf(&detail, " %s", info->committer_email); + strbuf_addf(&detail, " %s\n\n", + show_date(info->committer_date, info->committer_tz, + cgit_date_mode(DATE_ISO8601))); + + strbuf_addstr(&detail, info->subject); + + cgit_free_commitinfo(info); + return strbuf_detach(&detail, NULL); +} + +static void emit_blame_entry(struct blame_scoreboard *sb, + struct blame_entry *ent) +{ + struct blame_origin *suspect = ent->suspect; + struct object_id *oid = &suspect->commit->object.oid; + const char *numberfmt = "<a id='n%1$d' href='#n%1$d'>%1$d</a>\n"; + const char *cp, *cpend; + + char *detail = emit_suspect_detail(suspect); + + html("<tr><td class='sha1 lines'>"); + cgit_commit_link(find_unique_abbrev(oid->hash, DEFAULT_ABBREV), detail, + NULL, ctx.qry.head, oid_to_hex(oid), suspect->path); + html("</td>\n"); + + free(detail); + + if (ctx.cfg.enable_tree_linenumbers) { + unsigned long lineno = ent->lno; + html("<td class='linenumbers'><pre>"); + while (lineno < ent->lno + ent->num_lines) + htmlf(numberfmt, ++lineno); + html("</pre></td>\n"); + } + + cp = blame_nth_line(sb, ent->lno); + cpend = blame_nth_line(sb, ent->lno + ent->num_lines); + + html("<td class='lines'><pre><code>"); + html_ntxt(cp, cpend - cp); + html("</code></pre></td></tr>\n"); +} + +struct walk_tree_context { + char *curr_rev; + int match_baselen; + int state; +}; + +static void print_object(const unsigned char *sha1, const char *path, + const char *basename, const char *rev) +{ + enum object_type type; + unsigned long size; + struct argv_array rev_argv = ARGV_ARRAY_INIT; + struct rev_info revs; + struct blame_scoreboard sb; + struct blame_origin *o; + struct blame_entry *ent = NULL; + + type = sha1_object_info(sha1, &size); + if (type == OBJ_BAD) { + cgit_print_error_page(404, "Not found", "Bad object name: %s", + sha1_to_hex(sha1)); + return; + } + + argv_array_push(&rev_argv, "blame"); + argv_array_push(&rev_argv, rev); + init_revisions(&revs, NULL); + DIFF_OPT_SET(&revs.diffopt, ALLOW_TEXTCONV); + setup_revisions(rev_argv.argc, rev_argv.argv, &revs, NULL); + init_scoreboard(&sb); + sb.revs = &revs; + setup_scoreboard(&sb, path, &o); + o->suspects = blame_entry_prepend(NULL, 0, sb.num_lines, o); + prio_queue_put(&sb.commits, o->commit); + blame_origin_decref(o); + sb.ent = NULL; + sb.path = path; + assign_blame(&sb, 0); + blame_sort_final(&sb); + blame_coalesce(&sb); + + cgit_set_title_from_path(path); + + cgit_print_layout_start(); + htmlf("blob: %s (", sha1_to_hex(sha1)); + cgit_plain_link("plain", NULL, NULL, ctx.qry.head, rev, path); + html(") ("); + cgit_tree_link("tree", NULL, NULL, ctx.qry.head, rev, path); + html(")\n"); + + if (ctx.cfg.max_blob_size && size / 1024 > ctx.cfg.max_blob_size) { + htmlf("<div class='error'>blob size (%ldKB)" + " exceeds display size limit (%dKB).</div>", + size / 1024, ctx.cfg.max_blob_size); + return; + } + + html("<table class='blame blob'>"); + for (ent = sb.ent; ent; ) { + struct blame_entry *e = ent->next; + emit_blame_entry(&sb, ent); + free(ent); + ent = e; + } + html("</table>\n"); + free((void *)sb.final_buf); + + cgit_print_layout_end(); +} + +static int walk_tree(const unsigned char *sha1, struct strbuf *base, + const char *pathname, unsigned mode, int stage, + void *cbdata) +{ + struct walk_tree_context *walk_tree_ctx = cbdata; + + if (base->len == walk_tree_ctx->match_baselen) { + if (S_ISREG(mode)) { + struct strbuf buffer = STRBUF_INIT; + strbuf_addbuf(&buffer, base); + strbuf_addstr(&buffer, pathname); + print_object(sha1, buffer.buf, pathname, + walk_tree_ctx->curr_rev); + strbuf_release(&buffer); + walk_tree_ctx->state = 1; + } else if (S_ISDIR(mode)) { + walk_tree_ctx->state = 2; + } + } else if (base->len < INT_MAX + && (int)base->len > walk_tree_ctx->match_baselen) { + walk_tree_ctx->state = 2; + } else if (S_ISDIR(mode)) { + return READ_TREE_RECURSIVE; + } + return 0; +} + +static int basedir_len(const char *path) +{ + char *p = strrchr(path, '/'); + if (p) + return p - path + 1; + return 0; +} + +void cgit_print_blame(void) +{ + const char *rev = ctx.qry.sha1; + struct object_id oid; + struct commit *commit; + struct pathspec_item path_items = { + .match = ctx.qry.path, + .len = ctx.qry.path ? strlen(ctx.qry.path) : 0 + }; + struct pathspec paths = { + .nr = 1, + .items = &path_items + }; + struct walk_tree_context walk_tree_ctx = { + .state = 0 + }; + + if (!rev) + rev = ctx.qry.head; + + if (get_oid(rev, &oid)) { + cgit_print_error_page(404, "Not found", + "Invalid revision name: %s", rev); + return; + } + commit = lookup_commit_reference(&oid); + if (!commit || parse_commit(commit)) { + cgit_print_error_page(404, "Not found", + "Invalid commit reference: %s", rev); + return; + } + + walk_tree_ctx.curr_rev = xstrdup(rev); + walk_tree_ctx.match_baselen = (path_items.match) ? + basedir_len(path_items.match) : -1; + + read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, + &walk_tree_ctx); + if (!walk_tree_ctx.state) + cgit_print_error_page(404, "Not found", "Not found"); + else if (walk_tree_ctx.state == 2) + cgit_print_error_page(404, "No blame for folders", + "Blame is not available for folders."); + + free(walk_tree_ctx.curr_rev); +} diff --git a/ui-blame.h b/ui-blame.h new file mode 100644 index 0000000..5b97e03 --- /dev/null +++ b/ui-blame.h @@ -0,0 +1,6 @@ +#ifndef UI_BLAME_H +#define UI_BLAME_H + +extern void cgit_print_blame(void); + +#endif /* UI_BLAME_H */ From 1649afdc9b2febe9ab7e1abe1956c5dcaff93aa1 Mon Sep 17 00:00:00 2001 From: Jeff Smith <whydoubt@gmail.com> Date: Sun, 1 Oct 2017 23:39:09 -0500 Subject: [PATCH 224/387] ui-tree: link to blame UI if enabled Create links to the blame page. Signed-off-by: Jeff Smith <whydoubt@gmail.com> Reviewed-by: John Keeping <john@keeping.me.uk> --- ui-shared.c | 20 +++++++++++++++++--- ui-shared.h | 3 +++ ui-tree.c | 10 +++++++++- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/ui-shared.c b/ui-shared.c index 315dedb..07c78a5 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -1,6 +1,6 @@ /* ui-shared.c: common web output functions * - * Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com> + * Copyright (C) 2006-2017 cgit Development Team <cgit@lists.zx2c4.com> * * Licensed under GNU General Public License v2 * (see COPYING for full license text) @@ -304,6 +304,12 @@ void cgit_plain_link(const char *name, const char *title, const char *class, reporevlink("plain", name, title, class, head, rev, path); } +void cgit_blame_link(const char *name, const char *title, const char *class, + const char *head, const char *rev, const char *path) +{ + reporevlink("blame", name, title, class, head, rev, path); +} + void cgit_log_link(const char *name, const char *title, const char *class, const char *head, const char *rev, const char *path, int ofs, const char *grep, const char *pattern, int showmsg, @@ -478,6 +484,10 @@ static void cgit_self_link(char *name, const char *title, const char *class) cgit_plain_link(name, title, class, ctx.qry.head, ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL, ctx.qry.path); + else if (!strcmp(ctx.qry.page, "blame")) + cgit_blame_link(name, title, class, ctx.qry.head, + ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL, + ctx.qry.path); else if (!strcmp(ctx.qry.page, "log")) cgit_log_link(name, title, class, ctx.qry.head, ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL, @@ -983,8 +993,12 @@ void cgit_print_pageheader(void) cgit_log_link("log", NULL, hc("log"), ctx.qry.head, NULL, ctx.qry.vpath, 0, NULL, NULL, ctx.qry.showmsg, ctx.qry.follow); - cgit_tree_link("tree", NULL, hc("tree"), ctx.qry.head, - ctx.qry.sha1, ctx.qry.vpath); + if (ctx.qry.page && !strcmp(ctx.qry.page, "blame")) + cgit_blame_link("blame", NULL, hc("blame"), ctx.qry.head, + ctx.qry.sha1, ctx.qry.vpath); + else + cgit_tree_link("tree", NULL, hc("tree"), ctx.qry.head, + ctx.qry.sha1, ctx.qry.vpath); cgit_commit_link("commit", NULL, hc("commit"), ctx.qry.head, ctx.qry.sha1, ctx.qry.vpath); cgit_diff_link("diff", NULL, hc("diff"), ctx.qry.head, diff --git a/ui-shared.h b/ui-shared.h index 2cd7ac9..b760a17 100644 --- a/ui-shared.h +++ b/ui-shared.h @@ -26,6 +26,9 @@ extern void cgit_tree_link(const char *name, const char *title, extern void cgit_plain_link(const char *name, const char *title, const char *class, const char *head, const char *rev, const char *path); +extern void cgit_blame_link(const char *name, const char *title, + const char *class, const char *head, + const char *rev, const char *path); extern void cgit_log_link(const char *name, const char *title, const char *class, const char *head, const char *rev, const char *path, int ofs, const char *grep, diff --git a/ui-tree.c b/ui-tree.c index 3925809..67fd1bc 100644 --- a/ui-tree.c +++ b/ui-tree.c @@ -1,6 +1,6 @@ /* ui-tree.c: functions for tree output * - * Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com> + * Copyright (C) 2006-2017 cgit Development Team <cgit@lists.zx2c4.com> * * Licensed under GNU General Public License v2 * (see COPYING for full license text) @@ -110,6 +110,11 @@ static void print_object(const unsigned char *sha1, char *path, const char *base htmlf("blob: %s (", sha1_to_hex(sha1)); cgit_plain_link("plain", NULL, NULL, ctx.qry.head, rev, path); + if (ctx.cfg.enable_blame) { + html(") ("); + cgit_blame_link("blame", NULL, NULL, ctx.qry.head, + rev, path); + } html(")\n"); if (ctx.cfg.max_blob_size && size / 1024 > ctx.cfg.max_blob_size) { @@ -244,6 +249,9 @@ static int ls_item(const unsigned char *sha1, struct strbuf *base, if (!S_ISGITLINK(mode)) cgit_plain_link("plain", NULL, "button", ctx.qry.head, walk_tree_ctx->curr_rev, fullpath.buf); + if (!S_ISDIR(mode) && ctx.cfg.enable_blame) + cgit_blame_link("blame", NULL, "button", ctx.qry.head, + walk_tree_ctx->curr_rev, fullpath.buf); html("</td></tr>\n"); free(name); strbuf_release(&fullpath); From 9d751e7eec4f4bc7292be46f2af774fe1adf336a Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Sat, 14 Oct 2017 13:02:53 +0100 Subject: [PATCH 225/387] parsing: don't clear existing state with empty input Since commit c699866 (parsing: clear query path before starting, 2017-02-19), we clear the "page" variable simply by calling cgit_parse_url() even if the URL is empty. This breaks a URL like: .../cgit?p=about which is generated when using the "root-readme" configuration option. This happens because "page" is set to "about" when parsing the query string before we handle the path (which is empty, but non-null). It turns out that this is not the only case which is broken, but specifying repository and page via query options has been broken since before the commit mentioned above, for example: .../cgit?r=git&p=log Fix both of these by allowing the previous state to persist if PATH_INFO is empty, falling back to the query parameters if no path has been requested. Reported-by: Tom Ryder <tom@sanctum.geek.nz> Signed-off-by: John Keeping <john@keeping.me.uk> --- parsing.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/parsing.c b/parsing.c index b8d7f10..fd1ea99 100644 --- a/parsing.c +++ b/parsing.c @@ -20,11 +20,10 @@ void cgit_parse_url(const char *url) char *c, *cmd, *p; struct cgit_repo *repo; - ctx.repo = NULL; - ctx.qry.page = NULL; if (!url || url[0] == '\0') return; + ctx.qry.page = NULL; ctx.repo = cgit_get_repoinfo(url); if (ctx.repo) { ctx.qry.repo = ctx.repo->url; From fd069b4ca08cb46eb335a1434330b21fbaf84b9c Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Sat, 14 Oct 2017 16:13:07 +0200 Subject: [PATCH 226/387] filter: pipe_fh should be local Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- cgit.h | 1 - filter.c | 13 +++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cgit.h b/cgit.h index 0b88dcd..005ae63 100644 --- a/cgit.h +++ b/cgit.h @@ -71,7 +71,6 @@ struct cgit_exec_filter { char *cmd; char **argv; int old_stdout; - int pipe_fh[2]; int pid; }; diff --git a/filter.c b/filter.c index 949c931..70f5b74 100644 --- a/filter.c +++ b/filter.c @@ -42,6 +42,7 @@ void cgit_cleanup_filters(void) static int open_exec_filter(struct cgit_filter *base, va_list ap) { struct cgit_exec_filter *filter = (struct cgit_exec_filter *)base; + int pipe_fh[2]; int i; for (i = 0; i < filter->base.argument_count; i++) @@ -49,19 +50,19 @@ static int open_exec_filter(struct cgit_filter *base, va_list ap) filter->old_stdout = chk_positive(dup(STDOUT_FILENO), "Unable to duplicate STDOUT"); - chk_zero(pipe(filter->pipe_fh), "Unable to create pipe to subprocess"); + chk_zero(pipe(pipe_fh), "Unable to create pipe to subprocess"); filter->pid = chk_non_negative(fork(), "Unable to create subprocess"); if (filter->pid == 0) { - close(filter->pipe_fh[1]); - chk_non_negative(dup2(filter->pipe_fh[0], STDIN_FILENO), + close(pipe_fh[1]); + chk_non_negative(dup2(pipe_fh[0], STDIN_FILENO), "Unable to use pipe as STDIN"); execvp(filter->cmd, filter->argv); die_errno("Unable to exec subprocess %s", filter->cmd); } - close(filter->pipe_fh[0]); - chk_non_negative(dup2(filter->pipe_fh[1], STDOUT_FILENO), + close(pipe_fh[0]); + chk_non_negative(dup2(pipe_fh[1], STDOUT_FILENO), "Unable to use pipe as STDOUT"); - close(filter->pipe_fh[1]); + close(pipe_fh[1]); return 0; } From 98abe5bb9e6297a5dcbae206e00352c8630d922e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= <ville.skytta@iki.fi> Date: Sat, 14 Oct 2017 22:02:16 +0300 Subject: [PATCH 227/387] ui-shared: use type='search' for the search box MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ville Skyttä <ville.skytta@iki.fi> --- ui-shared.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui-shared.c b/ui-shared.c index 07c78a5..9d8f66b 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -1027,7 +1027,7 @@ void cgit_print_pageheader(void) html_option("committer", "committer", ctx.qry.grep); html_option("range", "range", ctx.qry.grep); html("</select>\n"); - html("<input class='txt' type='text' size='10' name='q' value='"); + html("<input class='txt' type='search' size='10' name='q' value='"); html_attr(ctx.qry.search); html("'/>\n"); html("<input type='submit' value='search'/>\n"); @@ -1042,7 +1042,7 @@ void cgit_print_pageheader(void) html("<form method='get' action='"); html_attr(currenturl); html("'>\n"); - html("<input type='text' name='q' size='10' value='"); + html("<input type='search' name='q' size='10' value='"); html_attr(ctx.qry.search); html("'/>\n"); html("<input type='submit' value='search'/>\n"); From 67d0f870506e3bc3703ae3cb2cb00e19691ce967 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= <ville.skytta@iki.fi> Date: Sat, 14 Oct 2017 22:05:51 +0300 Subject: [PATCH 228/387] global: spelling fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ville Skyttä <ville.skytta@iki.fi> --- cache.c | 2 +- cache.h | 2 +- filters/syntax-highlighting.sh | 2 +- tests/t0109-gitconfig.sh | 10 +++++----- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cache.c b/cache.c index 2ccdc4e..0901e6e 100644 --- a/cache.c +++ b/cache.c @@ -318,7 +318,7 @@ static int process_slot(struct cache_slot *slot) /* If the cache slot does not exist (or its key doesn't match the * current key), lets try to create a new cache slot for this * request. If this fails (for whatever reason), lets just generate - * the content without caching it and fool the caller to belive + * the content without caching it and fool the caller to believe * everything worked out (but print a warning on stdout). */ diff --git a/cache.h b/cache.h index 9392836..470da4f 100644 --- a/cache.h +++ b/cache.h @@ -19,7 +19,7 @@ typedef void (*cache_fill_fn)(void); * fn content generator function for this key * * Return value - * 0 indicates success, everyting else is an error + * 0 indicates success, everything else is an error */ extern int cache_process(int size, const char *path, const char *key, int ttl, cache_fill_fn fn); diff --git a/filters/syntax-highlighting.sh b/filters/syntax-highlighting.sh index 4fa7928..840bc34 100755 --- a/filters/syntax-highlighting.sh +++ b/filters/syntax-highlighting.sh @@ -1,6 +1,6 @@ #!/bin/sh # This script can be used to implement syntax highlighting in the cgit -# tree-view by refering to this file with the source-filter or repo.source- +# tree-view by referring to this file with the source-filter or repo.source- # filter options in cgitrc. # # This script requires a shell supporting the ${var##pattern} syntax. diff --git a/tests/t0109-gitconfig.sh b/tests/t0109-gitconfig.sh index 5a84258..3ba6684 100755 --- a/tests/t0109-gitconfig.sh +++ b/tests/t0109-gitconfig.sh @@ -10,16 +10,16 @@ test -n "$(which strace 2>/dev/null)" || { } test_no_home_access () { - non_existant_path="/path/to/some/place/that/does/not/possibly/exist" - while test -d "$non_existant_path"; do - non_existant_path="$non_existant_path/$(date +%N)" + non_existent_path="/path/to/some/place/that/does/not/possibly/exist" + while test -d "$non_existent_path"; do + non_existent_path="$non_existent_path/$(date +%N)" done && strace \ - -E HOME="$non_existant_path" \ + -E HOME="$non_existent_path" \ -E CGIT_CONFIG="$PWD/cgitrc" \ -E QUERY_STRING="url=$1" \ -e access -f -o strace.out cgit && - test_must_fail grep "$non_existant_path" strace.out + test_must_fail grep "$non_existent_path" strace.out } test_no_home_access_success() { From 5d947ba3f06ec2c7200aab8c22170e7f2bf55a7c Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Wed, 29 Nov 2017 22:25:42 +0100 Subject: [PATCH 229/387] git: update to v2.15.1 Update to git version v2.15.1: With commit 0abe14f6 prepare_packed_git() moved to packfile.[ch]. Signed-off-by: Christian Hesse <mail@eworm.de> Reviewed-by: John Keeping <john@keeping.me.uk> --- Makefile | 2 +- git | 2 +- ui-clone.c | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index f3ee84c..274f37e 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.14.0 +GIT_VER = 2.15.1 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.gz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index 4384e3c..9b185be 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 4384e3cde2ce8ecd194202e171ae16333d241326 +Subproject commit 9b185bef0c15cec1ea8753ce091e42ea041f2c31 diff --git a/ui-clone.c b/ui-clone.c index 0d11672..bc98980 100644 --- a/ui-clone.c +++ b/ui-clone.c @@ -11,6 +11,7 @@ #include "ui-clone.h" #include "html.h" #include "ui-shared.h" +#include "packfile.h" static int print_ref_info(const char *refname, const struct object_id *oid, int flags, void *cb_data) From 1dd53e3a2ffec730ec27ebe15b3d63e0b417a544 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Thu, 18 Jan 2018 09:19:31 +0100 Subject: [PATCH 230/387] git: update to v2.16.0 Update to git version v2.16.0: * refs: convert resolve_ref_unsafe to struct object_id (49e61479be913f67e66bb3fdf8de9475c41b58bd) * diff: remove DIFF_OPT_SET macro (23dcf77f48feb49c54bad09210f093a799816334) * log: add option to choose which refs to decorate (65516f586b69307f977cd67cc45513a296cabc25) * diff: convert flags to be stored in bitfields (02f2f56bc377c287c411947d0e1482aac888f8db) Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- cgit.c | 2 +- git | 2 +- shared.c | 2 +- ui-blame.c | 2 +- ui-commit.c | 2 +- ui-diff.c | 2 +- ui-log.c | 7 +++---- 8 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 274f37e..8321ecc 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.15.1 +GIT_VER = 2.16.0 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.gz INSTALL = install COPYTREE = cp -r diff --git a/cgit.c b/cgit.c index 972a67e..a3702c2 100644 --- a/cgit.c +++ b/cgit.c @@ -478,7 +478,7 @@ static char *guess_defbranch(void) const char *ref, *refname; struct object_id oid; - ref = resolve_ref_unsafe("HEAD", 0, oid.hash, NULL); + ref = resolve_ref_unsafe("HEAD", 0, &oid, NULL); if (!ref || !skip_prefix(ref, "refs/heads/", &refname)) return "master"; return xstrdup(refname); diff --git a/git b/git index 9b185be..2512f15 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 9b185bef0c15cec1ea8753ce091e42ea041f2c31 +Subproject commit 2512f15446149235156528dafbe75930c712b29e diff --git a/shared.c b/shared.c index df3f611..21ac8f4 100644 --- a/shared.c +++ b/shared.c @@ -346,7 +346,7 @@ void cgit_diff_tree(const struct object_id *old_oid, opt.output_format = DIFF_FORMAT_CALLBACK; opt.detect_rename = 1; opt.rename_limit = ctx.cfg.renamelimit; - DIFF_OPT_SET(&opt, RECURSIVE); + opt.flags.recursive = 1; if (ignorews) DIFF_XDL_SET(&opt, IGNORE_WHITESPACE); opt.format_callback = cgit_diff_tree_cb; diff --git a/ui-blame.c b/ui-blame.c index 62cf431..d4a4534 100644 --- a/ui-blame.c +++ b/ui-blame.c @@ -101,7 +101,7 @@ static void print_object(const unsigned char *sha1, const char *path, argv_array_push(&rev_argv, "blame"); argv_array_push(&rev_argv, rev); init_revisions(&revs, NULL); - DIFF_OPT_SET(&revs.diffopt, ALLOW_TEXTCONV); + revs.diffopt.flags.allow_textconv = 1; setup_revisions(rev_argv.argc, rev_argv.argv, &revs, NULL); init_scoreboard(&sb); sb.revs = &revs; diff --git a/ui-commit.c b/ui-commit.c index 586fea0..abf58f6 100644 --- a/ui-commit.c +++ b/ui-commit.c @@ -41,7 +41,7 @@ void cgit_print_commit(char *hex, const char *prefix) format_display_notes(&oid, ¬es, PAGE_ENCODING, 0); - load_ref_decorations(DECORATE_FULL_REFS); + load_ref_decorations(NULL, DECORATE_FULL_REFS); cgit_print_layout_start(); cgit_print_diff_ctrls(); diff --git a/ui-diff.c b/ui-diff.c index c7fb49b..a10ce8a 100644 --- a/ui-diff.c +++ b/ui-diff.c @@ -444,7 +444,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, diff_setup(&diffopt); diffopt.output_format = DIFF_FORMAT_PATCH; - DIFF_OPT_SET(&diffopt, RECURSIVE); + diffopt.flags.recursive = 1; diff_setup_done(&diffopt); ctx.page.mimetype = "text/plain"; diff --git a/ui-log.c b/ui-log.c index 2d2bb31..8e36fba 100644 --- a/ui-log.c +++ b/ui-log.c @@ -119,8 +119,7 @@ static int show_commit(struct commit *commit, struct rev_info *revs) struct commit_list *parents = commit->parents; struct commit *parent; int found = 0, saved_fmt; - unsigned saved_flags = revs->diffopt.flags; - + struct diff_flags saved_flags = revs->diffopt.flags; /* Always show if we're not in "follow" mode with a single file. */ if (!ctx.qry.follow) @@ -149,7 +148,7 @@ static int show_commit(struct commit *commit, struct rev_info *revs) add_lines = 0; rem_lines = 0; - DIFF_OPT_SET(&revs->diffopt, RECURSIVE); + revs->diffopt.flags.recursive = 1; diff_tree_oid(&parent->tree->object.oid, &commit->tree->object.oid, "", &revs->diffopt); @@ -434,7 +433,7 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern rev.ignore_missing = 1; rev.simplify_history = 1; setup_revisions(rev_argv.argc, rev_argv.argv, &rev, NULL); - load_ref_decorations(DECORATE_FULL_REFS); + load_ref_decorations(NULL, DECORATE_FULL_REFS); rev.show_decorations = 1; rev.grep_filter.ignore_case = 1; From 6b5b655f6d2449fe33d8f48f6e98d5e421bf3ff9 Mon Sep 17 00:00:00 2001 From: Jeff Smith <whydoubt@gmail.com> Date: Tue, 17 Oct 2017 23:17:32 -0500 Subject: [PATCH 231/387] ui-blame: Distinguish hashes column from lines column Signed-off-by: Jeff Smith <whydoubt@gmail.com> Reviewed-by: John Keeping <john@keeping.me.uk> --- cgit.css | 1 + ui-blame.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/cgit.css b/cgit.css index 836f8ae..893ebeb 100644 --- a/cgit.css +++ b/cgit.css @@ -300,6 +300,7 @@ div#cgit table.blob { border-top: solid 1px black; } +div#cgit table.blob td.hashes, div#cgit table.blob td.lines { margin: 0; padding: 0 0 0 0.5em; vertical-align: top; diff --git a/ui-blame.c b/ui-blame.c index d4a4534..62647a8 100644 --- a/ui-blame.c +++ b/ui-blame.c @@ -51,7 +51,7 @@ static void emit_blame_entry(struct blame_scoreboard *sb, char *detail = emit_suspect_detail(suspect); - html("<tr><td class='sha1 lines'>"); + html("<tr><td class='sha1 hashes'>"); cgit_commit_link(find_unique_abbrev(oid->hash, DEFAULT_ABBREV), detail, NULL, ctx.qry.head, oid_to_hex(oid), suspect->path); html("</td>\n"); From 2b95c9d49c8581e2b19efca1613ada292f56bf08 Mon Sep 17 00:00:00 2001 From: Jeff Smith <whydoubt@gmail.com> Date: Tue, 17 Oct 2017 23:17:33 -0500 Subject: [PATCH 232/387] ui-blame: Break out emit_blame_entry into component methods Signed-off-by: Jeff Smith <whydoubt@gmail.com> Reviewed-by: John Keeping <john@keeping.me.uk> --- ui-blame.c | 48 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/ui-blame.c b/ui-blame.c index 62647a8..bbaad1c 100644 --- a/ui-blame.c +++ b/ui-blame.c @@ -41,36 +41,52 @@ static char *emit_suspect_detail(struct blame_origin *suspect) return strbuf_detach(&detail, NULL); } -static void emit_blame_entry(struct blame_scoreboard *sb, - struct blame_entry *ent) +static void emit_blame_entry_hash(struct blame_entry *ent) { struct blame_origin *suspect = ent->suspect; struct object_id *oid = &suspect->commit->object.oid; - const char *numberfmt = "<a id='n%1$d' href='#n%1$d'>%1$d</a>\n"; - const char *cp, *cpend; char *detail = emit_suspect_detail(suspect); - - html("<tr><td class='sha1 hashes'>"); cgit_commit_link(find_unique_abbrev(oid->hash, DEFAULT_ABBREV), detail, NULL, ctx.qry.head, oid_to_hex(oid), suspect->path); - html("</td>\n"); - free(detail); +} - if (ctx.cfg.enable_tree_linenumbers) { - unsigned long lineno = ent->lno; - html("<td class='linenumbers'><pre>"); - while (lineno < ent->lno + ent->num_lines) - htmlf(numberfmt, ++lineno); - html("</pre></td>\n"); - } +static void emit_blame_entry_linenumber(struct blame_entry *ent) +{ + const char *numberfmt = "<a id='n%1$d' href='#n%1$d'>%1$d</a>\n"; + + unsigned long lineno = ent->lno; + while (lineno < ent->lno + ent->num_lines) + htmlf(numberfmt, ++lineno); +} + +static void emit_blame_entry_line(struct blame_scoreboard *sb, + struct blame_entry *ent) +{ + const char *cp, *cpend; cp = blame_nth_line(sb, ent->lno); cpend = blame_nth_line(sb, ent->lno + ent->num_lines); - html("<td class='lines'><pre><code>"); html_ntxt(cp, cpend - cp); +} + +static void emit_blame_entry(struct blame_scoreboard *sb, + struct blame_entry *ent) +{ + html("<tr><td class='sha1 hashes'>"); + emit_blame_entry_hash(ent); + html("</td>\n"); + + if (ctx.cfg.enable_tree_linenumbers) { + html("<td class='linenumbers'><pre>"); + emit_blame_entry_linenumber(ent); + html("</pre></td>\n"); + } + + html("<td class='lines'><pre><code>"); + emit_blame_entry_line(sb, ent); html("</code></pre></td></tr>\n"); } From aafc42d8089437db5105feb12d540c33fe9f9e16 Mon Sep 17 00:00:00 2001 From: Jeff Smith <whydoubt@gmail.com> Date: Tue, 17 Oct 2017 23:17:34 -0500 Subject: [PATCH 233/387] ui-blame: Make each column into a single table cell Signed-off-by: Jeff Smith <whydoubt@gmail.com> Reviewed-by: John Keeping <john@keeping.me.uk> --- cgit.css | 19 ++++++++++++++++-- ui-blame.c | 58 ++++++++++++++++++++++++++++++++++-------------------- 2 files changed, 54 insertions(+), 23 deletions(-) diff --git a/cgit.css b/cgit.css index 893ebeb..20b7e86 100644 --- a/cgit.css +++ b/cgit.css @@ -330,11 +330,26 @@ div#cgit table.ssdiff td.lineno a:hover { color: black; } -div#cgit table.blame tr:nth-child(even) { +div#cgit table.blame td.hashes, +div#cgit table.blame td.lines, +div#cgit table.blame td.linenumbers { + padding: 0; +} + +div#cgit table.blame td.hashes div.alt, +div#cgit table.blame td.lines div.alt { + padding: 0 0.5em 0 0.5em; +} + +div#cgit table.blame td.linenumbers div.alt { + padding: 0 0.5em 0 0; +} + +div#cgit table.blame div.alt:nth-child(even) { background: #eee; } -div#cgit table.blame tr:nth-child(odd) { +div#cgit table.blame div.alt:nth-child(odd) { background: white; } diff --git a/ui-blame.c b/ui-blame.c index bbaad1c..d565fff 100644 --- a/ui-blame.c +++ b/ui-blame.c @@ -45,11 +45,17 @@ static void emit_blame_entry_hash(struct blame_entry *ent) { struct blame_origin *suspect = ent->suspect; struct object_id *oid = &suspect->commit->object.oid; + unsigned long line = 0; char *detail = emit_suspect_detail(suspect); + html("<span class='sha1'>"); cgit_commit_link(find_unique_abbrev(oid->hash, DEFAULT_ABBREV), detail, NULL, ctx.qry.head, oid_to_hex(oid), suspect->path); + html("</span>"); free(detail); + + while (line++ < ent->num_lines) + html("\n"); } static void emit_blame_entry_linenumber(struct blame_entry *ent) @@ -72,24 +78,6 @@ static void emit_blame_entry_line(struct blame_scoreboard *sb, html_ntxt(cp, cpend - cp); } -static void emit_blame_entry(struct blame_scoreboard *sb, - struct blame_entry *ent) -{ - html("<tr><td class='sha1 hashes'>"); - emit_blame_entry_hash(ent); - html("</td>\n"); - - if (ctx.cfg.enable_tree_linenumbers) { - html("<td class='linenumbers'><pre>"); - emit_blame_entry_linenumber(ent); - html("</pre></td>\n"); - } - - html("<td class='lines'><pre><code>"); - emit_blame_entry_line(sb, ent); - html("</code></pre></td></tr>\n"); -} - struct walk_tree_context { char *curr_rev; int match_baselen; @@ -147,16 +135,44 @@ static void print_object(const unsigned char *sha1, const char *path, return; } - html("<table class='blame blob'>"); + html("<table class='blame blob'>\n<tr>\n"); + + /* Commit hashes */ + html("<td class='hashes'>"); + for (ent = sb.ent; ent; ent = ent->next) { + html("<div class='alt'><pre>"); + emit_blame_entry_hash(ent); + html("</pre></div>"); + } + html("</td>\n"); + + /* Line numbers */ + if (ctx.cfg.enable_tree_linenumbers) { + html("<td class='linenumbers'>"); + for (ent = sb.ent; ent; ent = ent->next) { + html("<div class='alt'><pre>"); + emit_blame_entry_linenumber(ent); + html("</pre></div>"); + } + html("</td>\n"); + } + + /* Lines */ + html("<td class='lines'>"); for (ent = sb.ent; ent; ) { struct blame_entry *e = ent->next; - emit_blame_entry(&sb, ent); + html("<div class='alt'><pre><code>"); + emit_blame_entry_line(&sb, ent); + html("</code></pre></div>"); free(ent); ent = e; } - html("</table>\n"); + html("</td>\n"); + free((void *)sb.final_buf); + html("</tr>\n</table>\n"); + cgit_print_layout_end(); } From dbaee2672be14374acb17266477c19294c6155f3 Mon Sep 17 00:00:00 2001 From: Jeff Smith <whydoubt@gmail.com> Date: Sat, 28 Oct 2017 21:43:26 -0500 Subject: [PATCH 234/387] ui-blame: Allow syntax highlighting Place file contents into a single block so that syntax highlighting can be applied in the usual fashion. Place the alternating color bars behind the file contents. Force the default syntax highlighting background to transparent. Signed-off-by: Jeff Smith <whydoubt@gmail.com> Reviewed-by: John Keeping <john@keeping.me.uk> --- cgit.css | 10 ++++++ filters/syntax-highlighting.py | 2 +- ui-blame.c | 63 +++++++++++++++++++++++++++------- 3 files changed, 62 insertions(+), 13 deletions(-) diff --git a/cgit.css b/cgit.css index 20b7e86..217a05a 100644 --- a/cgit.css +++ b/cgit.css @@ -353,6 +353,16 @@ div#cgit table.blame div.alt:nth-child(odd) { background: white; } +div#cgit table.blame td.lines > div { + position: relative; +} + +div#cgit table.blame td.lines > div > pre { + padding: 0 0 0 0.5em; + position: absolute; + top: 0; +} + div#cgit table.bin-blob { margin-top: 0.5em; border: solid 1px black; diff --git a/filters/syntax-highlighting.py b/filters/syntax-highlighting.py index 5888b50..e912594 100755 --- a/filters/syntax-highlighting.py +++ b/filters/syntax-highlighting.py @@ -34,7 +34,7 @@ sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8', errors='replace sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace') data = sys.stdin.read() filename = sys.argv[1] -formatter = HtmlFormatter(style='pastie') +formatter = HtmlFormatter(style='pastie', nobackground=True) try: lexer = guess_lexer_for_filename(filename, data) diff --git a/ui-blame.c b/ui-blame.c index d565fff..17e2d60 100644 --- a/ui-blame.c +++ b/ui-blame.c @@ -67,15 +67,29 @@ static void emit_blame_entry_linenumber(struct blame_entry *ent) htmlf(numberfmt, ++lineno); } -static void emit_blame_entry_line(struct blame_scoreboard *sb, - struct blame_entry *ent) +static void emit_blame_entry_line_background(struct blame_scoreboard *sb, + struct blame_entry *ent) { - const char *cp, *cpend; + unsigned long line; + size_t len, maxlen = 2; + const char* pos, *endpos; - cp = blame_nth_line(sb, ent->lno); - cpend = blame_nth_line(sb, ent->lno + ent->num_lines); + for (line = ent->lno; line < ent->lno + ent->num_lines; line++) { + html("\n"); + pos = blame_nth_line(sb, line); + endpos = blame_nth_line(sb, line + 1); + len = 0; + while (pos < endpos) { + len++; + if (*pos++ == '\t') + len = (len + 7) & ~7; + } + if (len > maxlen) + maxlen = len; + } - html_ntxt(cp, cpend - cp); + for (len = 0; len < maxlen - 1; len++) + html(" "); } struct walk_tree_context { @@ -88,6 +102,7 @@ static void print_object(const unsigned char *sha1, const char *path, const char *basename, const char *rev) { enum object_type type; + char *buf; unsigned long size; struct argv_array rev_argv = ARGV_ARRAY_INIT; struct rev_info revs; @@ -102,6 +117,13 @@ static void print_object(const unsigned char *sha1, const char *path, return; } + buf = read_sha1_file(sha1, &type, &size); + if (!buf) { + cgit_print_error_page(500, "Internal server error", + "Error reading object %s", sha1_to_hex(sha1)); + return; + } + argv_array_push(&rev_argv, "blame"); argv_array_push(&rev_argv, rev); init_revisions(&revs, NULL); @@ -157,20 +179,37 @@ static void print_object(const unsigned char *sha1, const char *path, html("</td>\n"); } - /* Lines */ - html("<td class='lines'>"); + html("<td class='lines'><div>"); + + /* Colored bars behind lines */ + html("<div>"); for (ent = sb.ent; ent; ) { struct blame_entry *e = ent->next; - html("<div class='alt'><pre><code>"); - emit_blame_entry_line(&sb, ent); - html("</code></pre></div>"); + html("<div class='alt'><pre>"); + emit_blame_entry_line_background(&sb, ent); + html("</pre></div>"); free(ent); ent = e; } - html("</td>\n"); + html("</div>"); free((void *)sb.final_buf); + /* Lines */ + html("<pre><code>"); + if (ctx.repo->source_filter) { + char *filter_arg = xstrdup(basename); + cgit_open_filter(ctx.repo->source_filter, filter_arg); + html_raw(buf, size); + cgit_close_filter(ctx.repo->source_filter); + free(filter_arg); + } else { + html_txt(buf); + } + html("</code></pre>"); + + html("</div></td>\n"); + html("</tr>\n</table>\n"); cgit_print_layout_end(); From 03f6e34bb9d683723cfc4fe58ee5bb983b95e173 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Mon, 12 Feb 2018 23:23:47 +0100 Subject: [PATCH 235/387] cgit: prepare repo before error pages This fixes a crash when showing a list of all heads in the <select> box in the header. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- cgit.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/cgit.c b/cgit.c index a3702c2..bd9cb3f 100644 --- a/cgit.c +++ b/cgit.c @@ -561,12 +561,8 @@ static void print_no_repo_clone_urls(const char *url) html("</a></td></tr>\n"); } -static int prepare_repo_cmd(void) +static void prepare_repo_env(int *nongit) { - struct object_id oid; - int nongit = 0; - int rc; - /* The path to the git repository. */ setenv("GIT_DIR", ctx.repo->path, 1); @@ -579,8 +575,13 @@ static int prepare_repo_cmd(void) /* Setup the git directory and initialize the notes system. Both of these * load local configuration from the git repository, so we do them both while * the HOME variables are unset. */ - setup_git_directory_gently(&nongit); + setup_git_directory_gently(nongit); init_display_notes(NULL); +} +static int prepare_repo_cmd(int nongit) +{ + struct object_id oid; + int rc; if (nongit) { const char *name = ctx.repo->name; @@ -700,6 +701,7 @@ static inline void authenticate_cookie(void) static void process_request(void) { struct cgit_cmd *cmd; + int nongit = 0; /* If we're not yet authenticated, no matter what page we're on, * display the authentication body from the auth_filter. This should @@ -715,6 +717,9 @@ static void process_request(void) return; } + if (ctx.repo) + prepare_repo_env(&nongit); + cmd = cgit_get_cmd(); if (!cmd) { ctx.page.title = "cgit error"; @@ -740,7 +745,7 @@ static void process_request(void) */ ctx.qry.vpath = cmd->want_vpath ? ctx.qry.path : NULL; - if (ctx.repo && prepare_repo_cmd()) + if (ctx.repo && prepare_repo_cmd(nongit)) return; cmd->fn(); From 33414d7869aa55aaccd45cdb82268d454cb79863 Mon Sep 17 00:00:00 2001 From: Todd Zullinger <tmz@pobox.com> Date: Tue, 20 Feb 2018 20:36:03 -0500 Subject: [PATCH 236/387] doc: use consistent id's when generating html files The html documentation is generated using a2x which calls docbook tools to do the work. The generate.consistent.ids parameter ensures that when the docbook stylesheet assigns an id value to an output element it is consistent as long as the document structure has not changed. Having consistent html files reduces frivolous changes between builds. Distributions can more easily deploy multiple architecture builds and compare changes between package versions. End-users avoid needless changes in files deployed or backed up. The generate.consistent.ids parameter was added in docbook-xsl-1.77.0. Older versions gracefully ignore the parameter, so we can pass the parameter unconditionally. Most distributions contain docbook-xsl newer than 1.77.0. This includes Fedora, Debian, Ubuntu, and RHEL/CentOS 7. RHEL/CentOS 6 and Debian Wheezy (old stable) ship with an older version, unsurprisingly. Signed-off-by: Todd Zullinger <tmz@pobox.com> --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 8321ecc..687069f 100644 --- a/Makefile +++ b/Makefile @@ -134,7 +134,7 @@ doc-pdf: $(DOC_PDF) a2x -f manpage $< $(DOC_HTML): %.html : %.txt - a2x -f xhtml --stylesheet=cgit-doc.css $< + a2x -f xhtml --stylesheet=cgit-doc.css --xsltproc-opts="--param generate.consistent.ids 1" $< $(DOC_PDF): %.pdf : %.txt a2x -f pdf cgitrc.5.txt From 48f175083ae9ee03aa5ed7cddfbf74edf6d75774 Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Sat, 16 Jun 2018 13:11:09 +0100 Subject: [PATCH 237/387] Makefile: drive asciidoc directly for HTML output This is mostly taken from Git's doc/Makefile, although simplified for our use. The output now uses Asciidoc's default CSS which I think looks a bit nicer than the Docbook formatting; as a result of this we no longer need our custom .css file. A side effect of this change is that temporary files generated from the HTML output no longer conflict with the manpage output format (because any temporary HTML output files use names derived from the output filename which includes .html). Signed-off-by: John Keeping <john@keeping.me.uk> --- Makefile | 9 ++++++++- cgit-doc.css | 3 --- 2 files changed, 8 insertions(+), 4 deletions(-) delete mode 100644 cgit-doc.css diff --git a/Makefile b/Makefile index 687069f..70f32a4 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,12 @@ DOC_MAN5 = $(patsubst %.txt,%,$(MAN5_TXT)) DOC_HTML = $(patsubst %.txt,%.html,$(MAN_TXT)) DOC_PDF = $(patsubst %.txt,%.pdf,$(MAN_TXT)) +ASCIIDOC = asciidoc +ASCIIDOC_EXTRA = +ASCIIDOC_HTML = xhtml11 +ASCIIDOC_COMMON = $(ASCIIDOC) $(ASCIIDOC_EXTRA) +TXT_TO_HTML = $(ASCIIDOC_COMMON) -b $(ASCIIDOC_HTML) + # Define NO_C99_FORMAT if your formatted IO functions (printf/scanf et.al.) # do not support the 'size specifiers' introduced by C99, namely ll, hh, # j, z, t. (representing long long int, char, intmax_t, size_t, ptrdiff_t). @@ -134,7 +140,8 @@ doc-pdf: $(DOC_PDF) a2x -f manpage $< $(DOC_HTML): %.html : %.txt - a2x -f xhtml --stylesheet=cgit-doc.css --xsltproc-opts="--param generate.consistent.ids 1" $< + $(TXT_TO_HTML) -o $@+ $< && \ + mv $@+ $@ $(DOC_PDF): %.pdf : %.txt a2x -f pdf cgitrc.5.txt diff --git a/cgit-doc.css b/cgit-doc.css deleted file mode 100644 index 5a399b6..0000000 --- a/cgit-doc.css +++ /dev/null @@ -1,3 +0,0 @@ -div.variablelist dt { - margin-top: 1em; -} From 7708859c4dcebff1e43516c23a8bf80f88fcea35 Mon Sep 17 00:00:00 2001 From: Andy Green <andy@warmcat.com> Date: Wed, 13 Jun 2018 10:02:00 +0800 Subject: [PATCH 238/387] ui-tree: free read_sha1_file() buffer after use Free up the buffer allocated in read_sha1_file() Signed-off-by: Andy Green <andy@warmcat.com> Signed-off-by: John Keeping <john@keeping.me.uk> --- ui-tree.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ui-tree.c b/ui-tree.c index 67fd1bc..524de0f 100644 --- a/ui-tree.c +++ b/ui-tree.c @@ -127,6 +127,8 @@ static void print_object(const unsigned char *sha1, char *path, const char *base print_binary_buffer(buf, size); else print_text_buffer(basename, buf, size); + + free(buf); } struct single_tree_ctx { From 26610aff34b8dbbfa296bb7a9785c39831cfe7e3 Mon Sep 17 00:00:00 2001 From: Jon DeVree <nuxi@vault24.org> Date: Sun, 10 Jun 2018 18:28:49 -0400 Subject: [PATCH 239/387] ui-tag: Fix inconsistent capitalization Way back in 2009 all of these were lower cased except this one occurrence. Signed-off-by: Jon DeVree <nuxi@vault24.org> Signed-off-by: John Keeping <john@keeping.me.uk> --- ui-tag.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui-tag.c b/ui-tag.c index 909cde0..2c216d0 100644 --- a/ui-tag.c +++ b/ui-tag.c @@ -107,7 +107,7 @@ void cgit_print_tag(char *revname) htmlf("<tr><td>tag name</td><td>"); html_txt(revname); html("</td></tr>\n"); - html("<tr><td>Tagged object</td><td class='sha1'>"); + html("<tr><td>tagged object</td><td class='sha1'>"); cgit_object_link(obj); html("</td></tr>\n"); if (ctx.repo->snapshots) From b759189574971eabf98aee73b4e4e4c604e21a94 Mon Sep 17 00:00:00 2001 From: Andy Green <andy@warmcat.com> Date: Tue, 19 Jun 2018 17:02:07 +0800 Subject: [PATCH 240/387] ui-blame: free read_sha1_file() buffer after use Signed-off-by: Andy Green <andy@warmcat.com> Signed-off-by: John Keeping <john@keeping.me.uk> --- ui-blame.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ui-blame.c b/ui-blame.c index 17e2d60..b118a81 100644 --- a/ui-blame.c +++ b/ui-blame.c @@ -154,7 +154,7 @@ static void print_object(const unsigned char *sha1, const char *path, htmlf("<div class='error'>blob size (%ldKB)" " exceeds display size limit (%dKB).</div>", size / 1024, ctx.cfg.max_blob_size); - return; + goto cleanup; } html("<table class='blame blob'>\n<tr>\n"); @@ -213,6 +213,9 @@ static void print_object(const unsigned char *sha1, const char *path, html("</tr>\n</table>\n"); cgit_print_layout_end(); + +cleanup: + free(buf); } static int walk_tree(const unsigned char *sha1, struct strbuf *base, From fb804a353780633b23a5452b3893fcc9f3705431 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Wed, 30 May 2018 10:28:12 +0200 Subject: [PATCH 241/387] git: update to v2.17.1 Update to git version v2.17.1. Required changes: * The function 'typename' has been renamed to 'type_name' (upstream commit debca9d2fe784193dc2d9f98b5edac605ddfefbb) Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- ui-shared.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 70f32a4..be2ed4f 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.16.0 +GIT_VER = 2.17.1 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.gz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index 2512f15..fc54c1a 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 2512f15446149235156528dafbe75930c712b29e +Subproject commit fc54c1af3ec09bab8b8ea09768c2da4069b7f53e diff --git a/ui-shared.c b/ui-shared.c index 9d8f66b..ce806f6 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -545,7 +545,7 @@ void cgit_object_link(struct object *obj) page = "tag"; else page = "blob"; - name = fmt("%s %s...", typename(obj->type), shortrev); + name = fmt("%s %s...", type_name(obj->type), shortrev); reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL); } From e65ea965a07c7d48d269b2d2278d0101f7ac2b48 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Mon, 4 Jun 2018 22:27:46 +0200 Subject: [PATCH 242/387] print git version string in footer This helps tracking what git version cgit uses. The security implications are low as anybody can look up the version of our submodule anyway. The paranoid can use a custom footer. :-p On the other hand this brings potential security issues to the administrators eyes... Signed-off-by: Christian Hesse <mail@eworm.de> --- ui-shared.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ui-shared.c b/ui-shared.c index ce806f6..0c6ca60 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -10,6 +10,7 @@ #include "ui-shared.h" #include "cmd.h" #include "html.h" +#include "version.h" static const char cgit_doctype[] = "<!DOCTYPE html>\n"; @@ -785,8 +786,8 @@ void cgit_print_docend(void) if (ctx.cfg.footer) html_include(ctx.cfg.footer); else { - htmlf("<div class='footer'>generated by <a href='https://git.zx2c4.com/cgit/about/'>cgit %s</a> at ", - cgit_version); + htmlf("<div class='footer'>generated by <a href='https://git.zx2c4.com/cgit/about/'>cgit %s</a> " + "(<a href='https://git-scm.com/'>git %s</a>) at ", cgit_version, git_version_string); html_txt(show_date(time(NULL), 0, cgit_date_mode(DATE_ISO8601))); html("</div>\n"); } From 0bb34ef130f05b865ee2a34d196ea6352590f673 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Tue, 5 Jun 2018 12:46:13 +0200 Subject: [PATCH 243/387] ui-log: highlight annotated tags in different color Annotated tags have some extra information... Descriptive text or signature. Highlighting annotated tags in a different color show what tag may be worth clicking for extra information. Signed-off-by: Christian Hesse <mail@eworm.de> Reviewed-by: John Keeping <john@keeping.me.uk> --- cgit.css | 8 ++++++++ ui-log.c | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/cgit.css b/cgit.css index 217a05a..05c4530 100644 --- a/cgit.css +++ b/cgit.css @@ -685,6 +685,14 @@ div#cgit a.tag-deco { border: solid 1px #777700; } +div#cgit a.tag-annotated-deco { + color: #000; + margin: 0px 0.5em; + padding: 0px 0.25em; + background-color: #ffcc88; + border: solid 1px #777700; +} + div#cgit a.remote-deco { color: #000; margin: 0px 0.5em; diff --git a/ui-log.c b/ui-log.c index 8e36fba..b5cd2f6 100644 --- a/ui-log.c +++ b/ui-log.c @@ -65,6 +65,8 @@ void show_commit_decorations(struct commit *commit) return; html("<span class='decoration'>"); while (deco) { + struct object_id peeled; + int is_annotated = 0; strncpy(buf, prettify_refname(deco->name), sizeof(buf) - 1); switch(deco->type) { case DECORATION_NONE: @@ -77,7 +79,9 @@ void show_commit_decorations(struct commit *commit) ctx.qry.showmsg, 0); break; case DECORATION_REF_TAG: - cgit_tag_link(buf, NULL, "tag-deco", buf); + if (!peel_ref(deco->name, &peeled)) + is_annotated = !oidcmp(&commit->object.oid, &peeled); + cgit_tag_link(buf, NULL, is_annotated ? "tag-annotated-deco" : "tag-deco", buf); break; case DECORATION_REF_REMOTE: if (!ctx.repo->enable_remote_branches) From bd1b281478c8d8ab45f723ac5818d58da4a64dd1 Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Sat, 31 Mar 2018 14:05:02 +0100 Subject: [PATCH 244/387] ui-shared: pass repo object to print_snapshot_links() Both call sites of cgit_print_snapshot_links() use the same values for the snapshot mask and repository name, which are derived from the cgit_repo structure so let's pass in the structure and access the fields directly. Signed-off-by: John Keeping <john@keeping.me.uk> Reviewed-by: Christian Hesse <mail@eworm.de> --- ui-commit.c | 3 +-- ui-shared.c | 8 ++++---- ui-shared.h | 4 ++-- ui-tag.c | 3 +-- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/ui-commit.c b/ui-commit.c index abf58f6..ea17461 100644 --- a/ui-commit.c +++ b/ui-commit.c @@ -110,8 +110,7 @@ void cgit_print_commit(char *hex, const char *prefix) } if (ctx.repo->snapshots) { html("<tr><th>download</th><td colspan='2' class='sha1'>"); - cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head, - hex, ctx.repo->snapshots); + cgit_print_snapshot_links(ctx.repo, ctx.qry.head, hex); html("</td></tr>"); } html("</table>\n"); diff --git a/ui-shared.c b/ui-shared.c index 0c6ca60..e719c1b 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -1103,17 +1103,17 @@ void cgit_compose_snapshot_prefix(struct strbuf *filename, const char *base, strbuf_addf(filename, "%s-%s", base, ref); } -void cgit_print_snapshot_links(const char *repo, const char *head, - const char *hex, int snapshots) +void cgit_print_snapshot_links(const struct cgit_repo *repo, const char *head, + const char *hex) { const struct cgit_snapshot_format* f; struct strbuf filename = STRBUF_INIT; size_t prefixlen; - cgit_compose_snapshot_prefix(&filename, cgit_repobasename(repo), hex); + cgit_compose_snapshot_prefix(&filename, cgit_repobasename(repo->url), hex); prefixlen = filename.len; for (f = cgit_snapshot_formats; f->suffix; f++) { - if (!(snapshots & f->bit)) + if (!(repo->snapshots & f->bit)) continue; strbuf_setlen(&filename, prefixlen); strbuf_addstr(&filename, f->suffix); diff --git a/ui-shared.h b/ui-shared.h index b760a17..b3eb8c5 100644 --- a/ui-shared.h +++ b/ui-shared.h @@ -76,8 +76,8 @@ extern void cgit_print_pageheader(void); extern void cgit_print_filemode(unsigned short mode); extern void cgit_compose_snapshot_prefix(struct strbuf *filename, const char *base, const char *ref); -extern void cgit_print_snapshot_links(const char *repo, const char *head, - const char *hex, int snapshots); +extern void cgit_print_snapshot_links(const struct cgit_repo *repo, + const char *head, const char *hex); extern void cgit_add_hidden_formfields(int incl_head, int incl_search, const char *page); diff --git a/ui-tag.c b/ui-tag.c index 2c216d0..89a46f9 100644 --- a/ui-tag.c +++ b/ui-tag.c @@ -34,8 +34,7 @@ static void print_tag_content(char *buf) static void print_download_links(char *revname) { html("<tr><th>download</th><td class='sha1'>"); - cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head, - revname, ctx.repo->snapshots); + cgit_print_snapshot_links(ctx.repo, ctx.qry.head, revname); html("</td></tr>"); } From d85e8a9810cbfbe5cfe80509a7b47cb39483e6ac Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Sat, 31 Mar 2018 15:18:57 +0100 Subject: [PATCH 245/387] ui-snapshot: pass repo into get_ref_from_filename() Prepare to allow a custom snapshot prefix. Signed-off-by: John Keeping <john@keeping.me.uk> Reviewed-by: Christian Hesse <mail@eworm.de> --- ui-snapshot.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ui-snapshot.c b/ui-snapshot.c index b2d95f7..237a75f 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c @@ -139,7 +139,8 @@ static int make_snapshot(const struct cgit_snapshot_format *format, * pending a 'v' or a 'V' to the remaining snapshot name ("0.7.2" -> * "v0.7.2") gives us something valid. */ -static const char *get_ref_from_filename(const char *url, const char *filename, +static const char *get_ref_from_filename(const struct cgit_repo *repo, + const char *filename, const struct cgit_snapshot_format *format) { const char *reponame; @@ -153,7 +154,7 @@ static const char *get_ref_from_filename(const char *url, const char *filename, if (get_oid(snapshot.buf, &oid) == 0) goto out; - reponame = cgit_repobasename(url); + reponame = cgit_repobasename(repo->url); if (starts_with(snapshot.buf, reponame)) { const char *new_start = snapshot.buf; new_start += strlen(reponame); @@ -200,7 +201,7 @@ void cgit_print_snapshot(const char *head, const char *hex, } if (!hex && dwim) { - hex = get_ref_from_filename(ctx.repo->url, filename, f); + hex = get_ref_from_filename(ctx.repo, filename, f); if (hex == NULL) { cgit_print_error_page(404, "Not found", "Not found"); return; From c1572bb5ec4540b5008490cf471cc4a5e65ef728 Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Sat, 31 Mar 2018 14:20:01 +0100 Subject: [PATCH 246/387] Add "snapshot-prefix" repo configuration Allow using a user-specified value for the prefix in snapshot files instead of the repository basename. For example, files downloaded from the linux-stable.git repository should be named linux-$VERSION and not linux-stable-$VERSION, which can be achieved by setting: repo.snapshot-prefix=linux Signed-off-by: John Keeping <john@keeping.me.uk> Reviewed-by: Christian Hesse <mail@eworm.de> --- cgit.c | 2 ++ cgit.h | 1 + cgitrc.5.txt | 7 +++++++ ui-refs.c | 2 +- ui-shared.c | 10 +++++++++- ui-shared.h | 1 + ui-snapshot.c | 4 ++-- 7 files changed, 23 insertions(+), 4 deletions(-) diff --git a/cgit.c b/cgit.c index bd9cb3f..d2f7b9c 100644 --- a/cgit.c +++ b/cgit.c @@ -79,6 +79,8 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va item->util = xstrdup(value); } else if (!strcmp(name, "section")) repo->section = xstrdup(value); + else if (!strcmp(name, "snapshot-prefix")) + repo->snapshot_prefix = xstrdup(value); else if (!strcmp(name, "readme") && value != NULL) { if (repo->readme.items == ctx.cfg.readme.items) memset(&repo->readme, 0, sizeof(repo->readme)); diff --git a/cgit.h b/cgit.h index 005ae63..847cd2e 100644 --- a/cgit.h +++ b/cgit.h @@ -88,6 +88,7 @@ struct cgit_repo { char *clone_url; char *logo; char *logo_link; + char *snapshot_prefix; int snapshots; int enable_commit_graph; int enable_log_filecount; diff --git a/cgitrc.5.txt b/cgitrc.5.txt index 4da166c..a9d3d0a 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -599,6 +599,13 @@ repo.snapshots:: restricted by the global "snapshots" setting. Default value: <snapshots>. +repo.snapshot-prefix:: + Prefix to use for snapshot links instead of the repository basename. + For example, the "linux-stable" repository may wish to set this to + "linux" so that snapshots are in the format "linux-3.15.4" instead + of "linux-stable-3.15.4". Default value: <empty> meaning to use + the repository basename. + repo.section:: Override the current section name for this repository. Default value: none. diff --git a/ui-refs.c b/ui-refs.c index 75f2789..50d9d30 100644 --- a/ui-refs.c +++ b/ui-refs.c @@ -100,7 +100,7 @@ static void print_tag_downloads(const struct cgit_repo *repo, const char *ref) if (!ref || strlen(ref) < 1) return; - basename = cgit_repobasename(repo->url); + basename = cgit_snapshot_prefix(repo); if (starts_with(ref, basename)) strbuf_addstr(&filename, ref); else diff --git a/ui-shared.c b/ui-shared.c index e719c1b..d857873 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -152,6 +152,14 @@ const char *cgit_repobasename(const char *reponame) return rvbuf; } +const char *cgit_snapshot_prefix(const struct cgit_repo *repo) +{ + if (repo->snapshot_prefix) + return repo->snapshot_prefix; + + return cgit_repobasename(repo->url); +} + static void site_url(const char *page, const char *search, const char *sort, int ofs, int always_root) { char *delim = "?"; @@ -1110,7 +1118,7 @@ void cgit_print_snapshot_links(const struct cgit_repo *repo, const char *head, struct strbuf filename = STRBUF_INIT; size_t prefixlen; - cgit_compose_snapshot_prefix(&filename, cgit_repobasename(repo->url), hex); + cgit_compose_snapshot_prefix(&filename, cgit_snapshot_prefix(repo), hex); prefixlen = filename.len; for (f = cgit_snapshot_formats; f->suffix; f++) { if (!(repo->snapshots & f->bit)) diff --git a/ui-shared.h b/ui-shared.h index b3eb8c5..92a1755 100644 --- a/ui-shared.h +++ b/ui-shared.h @@ -78,6 +78,7 @@ extern void cgit_compose_snapshot_prefix(struct strbuf *filename, const char *base, const char *ref); extern void cgit_print_snapshot_links(const struct cgit_repo *repo, const char *head, const char *hex); +extern const char *cgit_snapshot_prefix(const struct cgit_repo *repo); extern void cgit_add_hidden_formfields(int incl_head, int incl_search, const char *page); diff --git a/ui-snapshot.c b/ui-snapshot.c index 237a75f..b9e2a36 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c @@ -154,7 +154,7 @@ static const char *get_ref_from_filename(const struct cgit_repo *repo, if (get_oid(snapshot.buf, &oid) == 0) goto out; - reponame = cgit_repobasename(repo->url); + reponame = cgit_snapshot_prefix(repo); if (starts_with(snapshot.buf, reponame)) { const char *new_start = snapshot.buf; new_start += strlen(reponame); @@ -214,7 +214,7 @@ void cgit_print_snapshot(const char *head, const char *hex, hex = head; if (!prefix) - prefix = xstrdup(cgit_repobasename(ctx.repo->url)); + prefix = xstrdup(cgit_snapshot_prefix(ctx.repo)); make_snapshot(f, hex, prefix, filename); free(prefix); From 00ad47bbfaf7cc5c372e072a5302e871b5250390 Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Sat, 31 Mar 2018 15:19:52 +0100 Subject: [PATCH 247/387] ui-snapshot: filter permitted snapshot requests Currently the snapshots configuration option only filters which links are displayed, not which snapshots may be generated and downloaded. Apply the filter also to requests to ensure that the system policy is enforced. Signed-off-by: John Keeping <john@keeping.me.uk> Reviewed-by: Christian Hesse <mail@eworm.de> --- ui-snapshot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui-snapshot.c b/ui-snapshot.c index b9e2a36..abf8399 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c @@ -194,7 +194,7 @@ void cgit_print_snapshot(const char *head, const char *hex, } f = get_format(filename); - if (!f) { + if (!f || !(ctx.repo->snapshots & f->bit)) { cgit_print_error_page(400, "Bad request", "Unsupported snapshot format: %s", filename); return; From f0047d2d943788fed2666e1d20c1e0d3c16701d5 Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Sat, 31 Mar 2018 14:57:22 +0100 Subject: [PATCH 248/387] ui-refs: remove unnecessary sanity check There is no way for refinfo::refname to be null, and Git will prevent zero-length refs so this check is unnecessary. Signed-off-by: John Keeping <john@keeping.me.uk> Reviewed-by: Christian Hesse <mail@eworm.de> --- ui-refs.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/ui-refs.c b/ui-refs.c index 50d9d30..7b95e8b 100644 --- a/ui-refs.c +++ b/ui-refs.c @@ -97,9 +97,6 @@ static void print_tag_downloads(const struct cgit_repo *repo, const char *ref) struct strbuf filename = STRBUF_INIT; size_t prefixlen; - if (!ref || strlen(ref) < 1) - return; - basename = cgit_snapshot_prefix(repo); if (starts_with(ref, basename)) strbuf_addstr(&filename, ref); From 63da41a915157d27dcf26e4811bd6b5f8a3abb2b Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Sat, 31 Mar 2018 15:02:21 +0100 Subject: [PATCH 249/387] ui-shared: remove unused parameter The "head" parameter to cgit_print_snapshot_links() is never used, so remove it. Signed-off-by: John Keeping <john@keeping.me.uk> Reviewed-by: Christian Hesse <mail@eworm.de> --- ui-commit.c | 2 +- ui-shared.c | 3 +-- ui-shared.h | 2 +- ui-tag.c | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/ui-commit.c b/ui-commit.c index ea17461..37c7d8d 100644 --- a/ui-commit.c +++ b/ui-commit.c @@ -110,7 +110,7 @@ void cgit_print_commit(char *hex, const char *prefix) } if (ctx.repo->snapshots) { html("<tr><th>download</th><td colspan='2' class='sha1'>"); - cgit_print_snapshot_links(ctx.repo, ctx.qry.head, hex); + cgit_print_snapshot_links(ctx.repo, hex); html("</td></tr>"); } html("</table>\n"); diff --git a/ui-shared.c b/ui-shared.c index d857873..d638bf4 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -1111,8 +1111,7 @@ void cgit_compose_snapshot_prefix(struct strbuf *filename, const char *base, strbuf_addf(filename, "%s-%s", base, ref); } -void cgit_print_snapshot_links(const struct cgit_repo *repo, const char *head, - const char *hex) +void cgit_print_snapshot_links(const struct cgit_repo *repo, const char *hex) { const struct cgit_snapshot_format* f; struct strbuf filename = STRBUF_INIT; diff --git a/ui-shared.h b/ui-shared.h index 92a1755..5c5dc33 100644 --- a/ui-shared.h +++ b/ui-shared.h @@ -77,7 +77,7 @@ extern void cgit_print_filemode(unsigned short mode); extern void cgit_compose_snapshot_prefix(struct strbuf *filename, const char *base, const char *ref); extern void cgit_print_snapshot_links(const struct cgit_repo *repo, - const char *head, const char *hex); + const char *hex); extern const char *cgit_snapshot_prefix(const struct cgit_repo *repo); extern void cgit_add_hidden_formfields(int incl_head, int incl_search, const char *page); diff --git a/ui-tag.c b/ui-tag.c index 89a46f9..f597dfa 100644 --- a/ui-tag.c +++ b/ui-tag.c @@ -34,7 +34,7 @@ static void print_tag_content(char *buf) static void print_download_links(char *revname) { html("<tr><th>download</th><td class='sha1'>"); - cgit_print_snapshot_links(ctx.repo, ctx.qry.head, revname); + cgit_print_snapshot_links(ctx.repo, revname); html("</td></tr>"); } From 82aadcfc51ab9560862b99bfe5833c17f102f0ac Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Sat, 31 Mar 2018 15:03:21 +0100 Subject: [PATCH 250/387] ui-shared: rename parameter to cgit_print_snapshot_links() This is expected to be a ref not a hex object ID, so name it more appropriately. Signed-off-by: John Keeping <john@keeping.me.uk> Reviewed-by: Christian Hesse <mail@eworm.de> --- ui-shared.c | 4 ++-- ui-shared.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ui-shared.c b/ui-shared.c index d638bf4..8ae81d2 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -1111,13 +1111,13 @@ void cgit_compose_snapshot_prefix(struct strbuf *filename, const char *base, strbuf_addf(filename, "%s-%s", base, ref); } -void cgit_print_snapshot_links(const struct cgit_repo *repo, const char *hex) +void cgit_print_snapshot_links(const struct cgit_repo *repo, const char *ref) { const struct cgit_snapshot_format* f; struct strbuf filename = STRBUF_INIT; size_t prefixlen; - cgit_compose_snapshot_prefix(&filename, cgit_snapshot_prefix(repo), hex); + cgit_compose_snapshot_prefix(&filename, cgit_snapshot_prefix(repo), ref); prefixlen = filename.len; for (f = cgit_snapshot_formats; f->suffix; f++) { if (!(repo->snapshots & f->bit)) diff --git a/ui-shared.h b/ui-shared.h index 5c5dc33..d44d7c6 100644 --- a/ui-shared.h +++ b/ui-shared.h @@ -77,7 +77,7 @@ extern void cgit_print_filemode(unsigned short mode); extern void cgit_compose_snapshot_prefix(struct strbuf *filename, const char *base, const char *ref); extern void cgit_print_snapshot_links(const struct cgit_repo *repo, - const char *hex); + const char *ref); extern const char *cgit_snapshot_prefix(const struct cgit_repo *repo); extern void cgit_add_hidden_formfields(int incl_head, int incl_search, const char *page); From 5b1f42ffeec7e315fc4fcff5145e5b0adca30715 Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Sat, 31 Mar 2018 15:06:01 +0100 Subject: [PATCH 251/387] ui-shared: use the same snapshot logic as ui-refs Make snapshot links in the commit UI use the same prefix algorithm as those in the summary UI, so that refs starting with the snapshot prefix are used as-is rather than composed with the prefix repeated. Signed-off-by: John Keeping <john@keeping.me.uk> Reviewed-by: Christian Hesse <mail@eworm.de> --- ui-shared.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ui-shared.c b/ui-shared.c index 8ae81d2..50a168d 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -1115,9 +1115,15 @@ void cgit_print_snapshot_links(const struct cgit_repo *repo, const char *ref) { const struct cgit_snapshot_format* f; struct strbuf filename = STRBUF_INIT; + const char *basename; size_t prefixlen; - cgit_compose_snapshot_prefix(&filename, cgit_snapshot_prefix(repo), ref); + basename = cgit_snapshot_prefix(repo); + if (starts_with(ref, basename)) + strbuf_addstr(&filename, ref); + else + cgit_compose_snapshot_prefix(&filename, basename, ref); + prefixlen = filename.len; for (f = cgit_snapshot_formats; f->suffix; f++) { if (!(repo->snapshots & f->bit)) From e491eaa5df3055dc419d9d3cb75421e8a8c43944 Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Sat, 31 Mar 2018 15:08:59 +0100 Subject: [PATCH 252/387] ui-shared: pass separator in to cgit_print_snapshot_links() cgit_print_snapshot_links() is almost identical to print_tag_downloads(), so let's extract the difference to a parameter in preparation for removing print_tag_downloads() in the next commit. Signed-off-by: John Keeping <john@keeping.me.uk> Reviewed-by: Christian Hesse <mail@eworm.de> --- ui-commit.c | 2 +- ui-shared.c | 5 +++-- ui-shared.h | 2 +- ui-tag.c | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ui-commit.c b/ui-commit.c index 37c7d8d..65b4603 100644 --- a/ui-commit.c +++ b/ui-commit.c @@ -110,7 +110,7 @@ void cgit_print_commit(char *hex, const char *prefix) } if (ctx.repo->snapshots) { html("<tr><th>download</th><td colspan='2' class='sha1'>"); - cgit_print_snapshot_links(ctx.repo, hex); + cgit_print_snapshot_links(ctx.repo, hex, "<br/>"); html("</td></tr>"); } html("</table>\n"); diff --git a/ui-shared.c b/ui-shared.c index 50a168d..9d7ee3d 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -1111,7 +1111,8 @@ void cgit_compose_snapshot_prefix(struct strbuf *filename, const char *base, strbuf_addf(filename, "%s-%s", base, ref); } -void cgit_print_snapshot_links(const struct cgit_repo *repo, const char *ref) +void cgit_print_snapshot_links(const struct cgit_repo *repo, const char *ref, + const char *separator) { const struct cgit_snapshot_format* f; struct strbuf filename = STRBUF_INIT; @@ -1132,7 +1133,7 @@ void cgit_print_snapshot_links(const struct cgit_repo *repo, const char *ref) strbuf_addstr(&filename, f->suffix); cgit_snapshot_link(filename.buf, NULL, NULL, NULL, NULL, filename.buf); - html("<br/>"); + html(separator); } strbuf_release(&filename); } diff --git a/ui-shared.h b/ui-shared.h index d44d7c6..4d5978b 100644 --- a/ui-shared.h +++ b/ui-shared.h @@ -77,7 +77,7 @@ extern void cgit_print_filemode(unsigned short mode); extern void cgit_compose_snapshot_prefix(struct strbuf *filename, const char *base, const char *ref); extern void cgit_print_snapshot_links(const struct cgit_repo *repo, - const char *ref); + const char *ref, const char *separator); extern const char *cgit_snapshot_prefix(const struct cgit_repo *repo); extern void cgit_add_hidden_formfields(int incl_head, int incl_search, const char *page); diff --git a/ui-tag.c b/ui-tag.c index f597dfa..2c96c37 100644 --- a/ui-tag.c +++ b/ui-tag.c @@ -34,7 +34,7 @@ static void print_tag_content(char *buf) static void print_download_links(char *revname) { html("<tr><th>download</th><td class='sha1'>"); - cgit_print_snapshot_links(ctx.repo, revname); + cgit_print_snapshot_links(ctx.repo, revname, "<br/>"); html("</td></tr>"); } From 71d14d9c98c39a6683780060f84429a3a7e5b348 Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Sat, 31 Mar 2018 15:11:05 +0100 Subject: [PATCH 253/387] ui-refs: use shared function to print tag downloads cgit_compose_snapshot_prefix() is identical to print_tag_downloads(), so remove the latter and use the function from ui-shared.c instead. Signed-off-by: John Keeping <john@keeping.me.uk> Reviewed-by: Christian Hesse <mail@eworm.de> --- ui-refs.c | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/ui-refs.c b/ui-refs.c index 7b95e8b..2ec3858 100644 --- a/ui-refs.c +++ b/ui-refs.c @@ -90,31 +90,6 @@ static void print_tag_header(void) "<th class='left' colspan='2'>Age</th></tr>\n"); } -static void print_tag_downloads(const struct cgit_repo *repo, const char *ref) -{ - const struct cgit_snapshot_format* f; - const char *basename; - struct strbuf filename = STRBUF_INIT; - size_t prefixlen; - - basename = cgit_snapshot_prefix(repo); - if (starts_with(ref, basename)) - strbuf_addstr(&filename, ref); - else - cgit_compose_snapshot_prefix(&filename, basename, ref); - prefixlen = filename.len; - for (f = cgit_snapshot_formats; f->suffix; f++) { - if (!(repo->snapshots & f->bit)) - continue; - strbuf_setlen(&filename, prefixlen); - strbuf_addstr(&filename, f->suffix); - cgit_snapshot_link(filename.buf, NULL, NULL, NULL, NULL, filename.buf); - html("  "); - } - - strbuf_release(&filename); -} - static int print_tag(struct refinfo *ref) { struct tag *tag = NULL; @@ -134,7 +109,7 @@ static int print_tag(struct refinfo *ref) cgit_tag_link(name, NULL, NULL, name); html("</td><td>"); if (ctx.repo->snapshots && (obj->type == OBJ_COMMIT)) - print_tag_downloads(ctx.repo, name); + cgit_print_snapshot_links(ctx.repo, name, "  "); else cgit_object_link(obj); html("</td><td>"); From c712d5ac434b9ee8cb4e63a173a2538e1878637f Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Sat, 31 Mar 2018 16:15:48 +0100 Subject: [PATCH 254/387] snapshot: support archive signatures Read signatures from the notes refs refs/notes/signatures/$FORMAT where FORMAT is one of our archive formats ("tar", "tar.gz", ...). The note is expected to simply contain the signature content to be returned when the snapshot "${filename}.asc" is requested, so the signature for cgit-1.1.tar.xz can be stored against the v1.1 tag with: git notes --ref=refs/notes/signatures/tar.xz add -C "$( gpg --output - --armor --detach-sign cgit-1.1.tar.xz | git hash-object -w --stdin )" v1.1 and then downloaded by simply appending ".asc" to the archive URL. Signed-off-by: John Keeping <john@keeping.me.uk> Reviewed-by: Christian Hesse <mail@eworm.de> --- cgit.h | 2 ++ ui-shared.c | 7 +++++ ui-snapshot.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 84 insertions(+), 1 deletion(-) diff --git a/cgit.h b/cgit.h index 847cd2e..a686390 100644 --- a/cgit.h +++ b/cgit.h @@ -374,6 +374,8 @@ extern void cgit_parse_url(const char *url); extern const char *cgit_repobasename(const char *reponame); extern int cgit_parse_snapshots_mask(const char *str); +extern const struct object_id *cgit_snapshot_get_sig(const char *ref, + const struct cgit_snapshot_format *f); extern int cgit_open_filter(struct cgit_filter *filter, ...); extern int cgit_close_filter(struct cgit_filter *filter); diff --git a/ui-shared.c b/ui-shared.c index 9d7ee3d..8a786e0 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -1133,6 +1133,13 @@ void cgit_print_snapshot_links(const struct cgit_repo *repo, const char *ref, strbuf_addstr(&filename, f->suffix); cgit_snapshot_link(filename.buf, NULL, NULL, NULL, NULL, filename.buf); + if (cgit_snapshot_get_sig(ref, f)) { + strbuf_addstr(&filename, ".asc"); + html(" ("); + cgit_snapshot_link("sig", NULL, NULL, NULL, NULL, + filename.buf); + html(")"); + } html(separator); } strbuf_release(&filename); diff --git a/ui-snapshot.c b/ui-snapshot.c index abf8399..c7611e8 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c @@ -94,6 +94,31 @@ const struct cgit_snapshot_format cgit_snapshot_formats[] = { { NULL } }; +static struct notes_tree snapshot_sig_notes[ARRAY_SIZE(cgit_snapshot_formats)]; + +const struct object_id *cgit_snapshot_get_sig(const char *ref, + const struct cgit_snapshot_format *f) +{ + struct notes_tree *tree; + struct object_id oid; + + if (get_oid(ref, &oid)) + return NULL; + + tree = &snapshot_sig_notes[f - &cgit_snapshot_formats[0]]; + if (!tree->initialized) { + struct strbuf notes_ref = STRBUF_INIT; + + strbuf_addf(¬es_ref, "refs/notes/signatures/%s", + f->suffix + 1); + + init_notes(tree, notes_ref.buf, combine_notes_ignore, 0); + strbuf_release(¬es_ref); + } + + return get_note(tree, &oid); +} + static const struct cgit_snapshot_format *get_format(const char *filename) { const struct cgit_snapshot_format *fmt; @@ -129,6 +154,39 @@ static int make_snapshot(const struct cgit_snapshot_format *format, return 0; } +static int write_sig(const struct cgit_snapshot_format *format, + const char *hex, const char *archive, + const char *filename) +{ + const struct object_id *note = cgit_snapshot_get_sig(hex, format); + enum object_type type; + unsigned long size; + char *buf; + + if (!note) { + cgit_print_error_page(404, "Not found", + "No signature for %s", archive); + return 0; + } + + buf = read_sha1_file(note->hash, &type, &size); + if (!buf) { + cgit_print_error_page(404, "Not found", "Not found"); + return 0; + } + + html("X-Content-Type-Options: nosniff\n"); + html("Content-Security-Policy: default-src 'none'\n"); + ctx.page.etag = oid_to_hex(note); + ctx.page.mimetype = xstrdup("application/pgp-signature"); + ctx.page.filename = xstrdup(filename); + cgit_print_http_headers(); + + html_raw(buf, size); + free(buf); + return 0; +} + /* Try to guess the requested revision from the requested snapshot name. * First the format extension is stripped, e.g. "cgit-0.7.2.tar.gz" become * "cgit-0.7.2". If this is a valid commit object name we've got a winner. @@ -185,6 +243,8 @@ void cgit_print_snapshot(const char *head, const char *hex, const char *filename, int dwim) { const struct cgit_snapshot_format* f; + const char *sig_filename = NULL; + char *adj_filename = NULL; char *prefix = NULL; if (!filename) { @@ -193,6 +253,15 @@ void cgit_print_snapshot(const char *head, const char *hex, return; } + if (ends_with(filename, ".asc")) { + sig_filename = filename; + + /* Strip ".asc" from filename for common format processing */ + adj_filename = xstrdup(filename); + adj_filename[strlen(adj_filename) - 4] = '\0'; + filename = adj_filename; + } + f = get_format(filename); if (!f || !(ctx.repo->snapshots & f->bit)) { cgit_print_error_page(400, "Bad request", @@ -216,6 +285,11 @@ void cgit_print_snapshot(const char *head, const char *hex, if (!prefix) prefix = xstrdup(cgit_snapshot_prefix(ctx.repo)); - make_snapshot(f, hex, prefix, filename); + if (sig_filename) + write_sig(f, hex, filename, sig_filename); + else + make_snapshot(f, hex, prefix, filename); + free(prefix); + free(adj_filename); } From 30a378b571c9f826d37c913b32b363f54a8997f4 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Thu, 7 Jun 2018 22:01:50 +0200 Subject: [PATCH 255/387] snapshot: support special value 'all' to enable all formats Signed-off-by: Christian Hesse <mail@eworm.de> Reviewed-by: John Keeping <john@keeping.me.uk> --- cgitrc.5.txt | 1 + shared.c | 3 +++ 2 files changed, 4 insertions(+) diff --git a/cgitrc.5.txt b/cgitrc.5.txt index a9d3d0a..3bfacfa 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -429,6 +429,7 @@ snapshots:: Text which specifies the default set of snapshot formats that cgit generates links for. The value is a space-separated list of zero or more of the values "tar", "tar.gz", "tar.bz2", "tar.xz" and "zip". + The special value "all" enables all snapshot formats. Default value: none. source-filter:: diff --git a/shared.c b/shared.c index 21ac8f4..0a11e68 100644 --- a/shared.c +++ b/shared.c @@ -390,6 +390,9 @@ int cgit_parse_snapshots_mask(const char *str) if (atoi(str)) return 1; + if (strcmp(str, "all") == 0) + return INT_MAX; + string_list_split(&tokens, str, ' ', -1); string_list_remove_empty_items(&tokens, 0); From 2f8648ff7f5c7119ab035c134504f04eefe068fb Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Mon, 11 Jun 2018 08:26:59 +0200 Subject: [PATCH 256/387] snapshot: strip bit from struct cgit_snapshot_format We had a static bit value in struct cgit_snapshot_format. We do not rely on it and things can be calculated on the fly. So strip it. Signed-off-by: Christian Hesse <mail@eworm.de> --- cgit.c | 2 +- cgit.h | 4 +++- shared.c | 2 +- ui-shared.c | 2 +- ui-snapshot.c | 17 +++++++++++------ 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/cgit.c b/cgit.c index d2f7b9c..ca0a89c 100644 --- a/cgit.c +++ b/cgit.c @@ -765,7 +765,7 @@ static char *build_snapshot_setting(int bitmap) struct strbuf result = STRBUF_INIT; for (f = cgit_snapshot_formats; f->suffix; f++) { - if (f->bit & bitmap) { + if (cgit_snapshot_format_bit(f) & bitmap) { if (result.len) strbuf_addch(&result, ' '); strbuf_addstr(&result, f->suffix); diff --git a/cgit.h b/cgit.h index a686390..0798dc5 100644 --- a/cgit.h +++ b/cgit.h @@ -46,6 +46,8 @@ */ #define PAGE_ENCODING "UTF-8" +#define BIT(x) (1U << (x)) + typedef void (*configfn)(const char *name, const char *value); typedef void (*filepair_fn)(struct diff_filepair *pair); typedef void (*linediff_fn)(char *line, int len); @@ -314,7 +316,6 @@ struct cgit_snapshot_format { const char *suffix; const char *mimetype; write_archive_fn_t write_func; - int bit; }; extern const char *cgit_version; @@ -376,6 +377,7 @@ extern const char *cgit_repobasename(const char *reponame); extern int cgit_parse_snapshots_mask(const char *str); extern const struct object_id *cgit_snapshot_get_sig(const char *ref, const struct cgit_snapshot_format *f); +extern const unsigned cgit_snapshot_format_bit(const struct cgit_snapshot_format *f); extern int cgit_open_filter(struct cgit_filter *filter, ...); extern int cgit_close_filter(struct cgit_filter *filter); diff --git a/shared.c b/shared.c index 0a11e68..d59ae7e 100644 --- a/shared.c +++ b/shared.c @@ -400,7 +400,7 @@ int cgit_parse_snapshots_mask(const char *str) for (f = cgit_snapshot_formats; f->suffix; f++) { if (!strcmp(item->string, f->suffix) || !strcmp(item->string, f->suffix + 1)) { - rv |= f->bit; + rv |= cgit_snapshot_format_bit(f); break; } } diff --git a/ui-shared.c b/ui-shared.c index 8a786e0..e8c0723 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -1127,7 +1127,7 @@ void cgit_print_snapshot_links(const struct cgit_repo *repo, const char *ref, prefixlen = filename.len; for (f = cgit_snapshot_formats; f->suffix; f++) { - if (!(repo->snapshots & f->bit)) + if (!(repo->snapshots & cgit_snapshot_format_bit(f))) continue; strbuf_setlen(&filename, prefixlen); strbuf_addstr(&filename, f->suffix); diff --git a/ui-snapshot.c b/ui-snapshot.c index c7611e8..83ce6e8 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c @@ -86,11 +86,11 @@ static int write_tar_xz_archive(const char *hex, const char *prefix) } const struct cgit_snapshot_format cgit_snapshot_formats[] = { - { ".zip", "application/x-zip", write_zip_archive, 0x01 }, - { ".tar.gz", "application/x-gzip", write_tar_gzip_archive, 0x02 }, - { ".tar.bz2", "application/x-bzip2", write_tar_bzip2_archive, 0x04 }, - { ".tar", "application/x-tar", write_tar_archive, 0x08 }, - { ".tar.xz", "application/x-xz", write_tar_xz_archive, 0x10 }, + { ".tar", "application/x-tar", write_tar_archive }, + { ".tar.gz", "application/x-gzip", write_tar_gzip_archive }, + { ".tar.bz2", "application/x-bzip2", write_tar_bzip2_archive }, + { ".tar.xz", "application/x-xz", write_tar_xz_archive }, + { ".zip", "application/x-zip", write_zip_archive }, { NULL } }; @@ -130,6 +130,11 @@ static const struct cgit_snapshot_format *get_format(const char *filename) return NULL; } +const unsigned cgit_snapshot_format_bit(const struct cgit_snapshot_format *f) +{ + return BIT(f - &cgit_snapshot_formats[0]); +} + static int make_snapshot(const struct cgit_snapshot_format *format, const char *hex, const char *prefix, const char *filename) @@ -263,7 +268,7 @@ void cgit_print_snapshot(const char *head, const char *hex, } f = get_format(filename); - if (!f || !(ctx.repo->snapshots & f->bit)) { + if (!f || !(ctx.repo->snapshots & cgit_snapshot_format_bit(f))) { cgit_print_error_page(400, "Bad request", "Unsupported snapshot format: %s", filename); return; From 54d37dc154f5308459df0a90c81dabd0245b6c17 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Mon, 18 Jun 2018 11:48:43 +0200 Subject: [PATCH 257/387] global: remove functionality we deprecated for cgit v1.0 The man page states these were deprecated for v1.0. We are past v1.1, so remove the functionality. Signed-off-by: Christian Hesse <mail@eworm.de> Reviewed-by: John Keeping <john@keeping.me.uk> --- cgit.c | 17 +++-------------- cgit.h | 3 --- cgitrc.5.txt | 21 --------------------- ui-repolist.c | 3 --- ui-shared.c | 2 -- 5 files changed, 3 insertions(+), 43 deletions(-) diff --git a/cgit.c b/cgit.c index ca0a89c..223dfc8 100644 --- a/cgit.c +++ b/cgit.c @@ -111,7 +111,7 @@ static void config_cb(const char *name, const char *value) { const char *arg; - if (!strcmp(name, "section") || !strcmp(name, "repo.group")) + if (!strcmp(name, "section")) ctx.cfg.section = xstrdup(value); else if (!strcmp(name, "repo.url")) ctx.repo = cgit_add_repo(value); @@ -139,20 +139,14 @@ static void config_cb(const char *name, const char *value) ctx.cfg.header = xstrdup(value); else if (!strcmp(name, "logo")) ctx.cfg.logo = xstrdup(value); - else if (!strcmp(name, "index-header")) - ctx.cfg.index_header = xstrdup(value); - else if (!strcmp(name, "index-info")) - ctx.cfg.index_info = xstrdup(value); else if (!strcmp(name, "logo-link")) ctx.cfg.logo_link = xstrdup(value); else if (!strcmp(name, "module-link")) ctx.cfg.module_link = xstrdup(value); else if (!strcmp(name, "strict-export")) ctx.cfg.strict_export = xstrdup(value); - else if (!strcmp(name, "virtual-root")) { + else if (!strcmp(name, "virtual-root")) ctx.cfg.virtual_root = ensure_end(value, '/'); - } else if (!strcmp(name, "nocache")) - ctx.cfg.nocache = atoi(value); else if (!strcmp(name, "noplainemail")) ctx.cfg.noplainemail = atoi(value); else if (!strcmp(name, "noheader")) @@ -236,7 +230,7 @@ static void config_cb(const char *name, const char *value) else if (!strcmp(name, "project-list")) ctx.cfg.project_list = xstrdup(expand_macros(value)); else if (!strcmp(name, "scan-path")) - if (!ctx.cfg.nocache && ctx.cfg.cache_size) + if (ctx.cfg.cache_size) process_cached_repolist(expand_macros(value)); else if (ctx.cfg.project_list) scan_projects(expand_macros(value), @@ -355,7 +349,6 @@ static void prepare_context(void) { memset(&ctx, 0, sizeof(ctx)); ctx.cfg.agefile = "info/web/last-modified"; - ctx.cfg.nocache = 0; ctx.cfg.cache_size = 0; ctx.cfg.cache_max_create_time = 5; ctx.cfg.cache_root = CGIT_CACHE_ROOT; @@ -973,8 +966,6 @@ static void cgit_parse_args(int argc, const char **argv) } if (skip_prefix(argv[i], "--cache=", &arg)) { ctx.cfg.cache_root = xstrdup(arg); - } else if (!strcmp(argv[i], "--nocache")) { - ctx.cfg.nocache = 1; } else if (!strcmp(argv[i], "--nohttp")) { ctx.env.no_http = "1"; } else if (skip_prefix(argv[i], "--query=", &arg)) { @@ -1095,8 +1086,6 @@ int cmd_main(int argc, const char **argv) else ctx.page.expires += ttl * 60; if (!ctx.env.authenticated || (ctx.env.request_method && !strcmp(ctx.env.request_method, "HEAD"))) - ctx.cfg.nocache = 1; - if (ctx.cfg.nocache) ctx.cfg.cache_size = 0; err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root, ctx.qry.raw, ttl, process_request); diff --git a/cgit.h b/cgit.h index 0798dc5..6feca68 100644 --- a/cgit.h +++ b/cgit.h @@ -197,8 +197,6 @@ struct cgit_config { char *footer; char *head_include; char *header; - char *index_header; - char *index_info; char *logo; char *logo_link; char *mimetype_file; @@ -248,7 +246,6 @@ struct cgit_config { int max_repodesc_len; int max_blob_size; int max_stats; - int nocache; int noplainemail; int noheader; int renamelimit; diff --git a/cgitrc.5.txt b/cgitrc.5.txt index 3bfacfa..acfae91 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -238,18 +238,6 @@ include:: Name of a configfile to include before the rest of the current config- file is parsed. Default value: none. See also: "MACRO EXPANSION". -index-header:: - The content of the file specified with this option will be included - verbatim above the repository index. This setting is deprecated, and - will not be supported by cgit-1.0 (use root-readme instead). Default - value: none. - -index-info:: - The content of the file specified with this option will be included - verbatim below the heading on the repository index page. This setting - is deprecated, and will not be supported by cgit-1.0 (use root-desc - instead). Default value: none. - local-time:: Flag which, if set to "1", makes cgit print commit and tag times in the servers timezone. Default value: "0". @@ -323,11 +311,6 @@ module-link:: formatstring are the path and SHA1 of the submodule commit. Default value: none. -nocache:: - If set to the value "1" caching will be disabled. This settings is - deprecated, and will not be honored starting with cgit-1.0. Default - value: "0". - noplainemail:: If set to "1" showing full author email addresses will be disabled. Default value: "0". @@ -359,10 +342,6 @@ renamelimit:: "-1" uses the compiletime value in git (for further info, look at `man git-diff`). Default value: "-1". -repo.group:: - Legacy alias for "section". This option is deprecated and will not be - supported in cgit-1.0. - repository-sort:: The way in which repositories in each section are sorted. Valid values are "name" for sorting by the repo name or "age" for sorting by the diff --git a/ui-repolist.c b/ui-repolist.c index af52f9b..41424c0 100644 --- a/ui-repolist.c +++ b/ui-repolist.c @@ -288,9 +288,6 @@ void cgit_print_repolist(void) cgit_print_docstart(); cgit_print_pageheader(); - if (ctx.cfg.index_header) - html_include(ctx.cfg.index_header); - if (ctx.qry.sort) sorted = sort_repolist(ctx.qry.sort); else if (ctx.cfg.section_sort) diff --git a/ui-shared.c b/ui-shared.c index e8c0723..a63dcb0 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -977,8 +977,6 @@ static void print_header(void) } else { if (ctx.cfg.root_desc) html_txt(ctx.cfg.root_desc); - else if (ctx.cfg.index_info) - html_include(ctx.cfg.index_info); } html("</td></tr></table>\n"); } From 255b78ff5291cef79978b025c9872f801de89e23 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Mon, 4 Jun 2018 18:49:28 +0200 Subject: [PATCH 258/387] git: update to v2.18.0 Update to git version v2.18.0. Required changes follow upstream commits: * Convert find_unique_abbrev* to struct object_id (aab9583f7b5ea5463eb3f653a0b4ecac7539dc94) * sha1_file: convert read_sha1_file to struct object_id (b4f5aca40e6f77cbabcbf4ff003c3cf30a1830c8) * sha1_file: convert sha1_object_info* to object_id (abef9020e3df87c441c9a3a95f592fce5fa49bb9) * object-store: move packed_git and packed_git_mru to object store (a80d72db2a73174b3f22142eb2014b33696fd795) * treewide: rename tree to maybe_tree (891435d55da80ca3654b19834481205be6bdfe33) The changed data types required some of our own functions to be converted to struct object_id: ls_item print_dir print_dir_entry print_object single_tree_cb walk_tree write_tree_link And finally we use new upstream functions that were added for struct object_id: hashcpy -> oidcpy sha1_to_hex -> oid_to_hex Signed-off-by: Christian Hesse <mail@eworm.de> Reviewed-by: John Keeping <john@keeping.me.uk> --- Makefile | 2 +- git | 2 +- parsing.c | 2 +- shared.c | 2 +- ui-blame.c | 20 ++++++++++---------- ui-blob.c | 24 ++++++++++++------------ ui-clone.c | 5 +++-- ui-commit.c | 2 +- ui-diff.c | 8 ++++---- ui-log.c | 4 ++-- ui-plain.c | 28 ++++++++++++++-------------- ui-snapshot.c | 2 +- ui-tree.c | 42 +++++++++++++++++++++--------------------- 13 files changed, 72 insertions(+), 71 deletions(-) diff --git a/Makefile b/Makefile index be2ed4f..137150c 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.17.1 +GIT_VER = 2.18.0 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.gz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index fc54c1a..53f9a3e 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit fc54c1af3ec09bab8b8ea09768c2da4069b7f53e +Subproject commit 53f9a3e157dbbc901a02ac2c73346d375e24978c diff --git a/parsing.c b/parsing.c index fd1ea99..12453c2 100644 --- a/parsing.c +++ b/parsing.c @@ -200,7 +200,7 @@ struct taginfo *cgit_parse_tag(struct tag *tag) const char *p; struct taginfo *ret = NULL; - data = read_sha1_file(tag->object.oid.hash, &type, &size); + data = read_object_file(&tag->object.oid, &type, &size); if (!data || type != OBJ_TAG) goto cleanup; diff --git a/shared.c b/shared.c index d59ae7e..d7c7636 100644 --- a/shared.c +++ b/shared.c @@ -239,7 +239,7 @@ static int load_mmfile(mmfile_t *file, const struct object_id *oid) file->ptr = (char *)""; file->size = 0; } else { - file->ptr = read_sha1_file(oid->hash, &type, + file->ptr = read_object_file(oid, &type, (unsigned long *)&file->size); } return 1; diff --git a/ui-blame.c b/ui-blame.c index b118a81..50d0580 100644 --- a/ui-blame.c +++ b/ui-blame.c @@ -49,7 +49,7 @@ static void emit_blame_entry_hash(struct blame_entry *ent) char *detail = emit_suspect_detail(suspect); html("<span class='sha1'>"); - cgit_commit_link(find_unique_abbrev(oid->hash, DEFAULT_ABBREV), detail, + cgit_commit_link(find_unique_abbrev(oid, DEFAULT_ABBREV), detail, NULL, ctx.qry.head, oid_to_hex(oid), suspect->path); html("</span>"); free(detail); @@ -98,7 +98,7 @@ struct walk_tree_context { int state; }; -static void print_object(const unsigned char *sha1, const char *path, +static void print_object(const struct object_id *oid, const char *path, const char *basename, const char *rev) { enum object_type type; @@ -110,17 +110,17 @@ static void print_object(const unsigned char *sha1, const char *path, struct blame_origin *o; struct blame_entry *ent = NULL; - type = sha1_object_info(sha1, &size); + type = oid_object_info(the_repository, oid, &size); if (type == OBJ_BAD) { cgit_print_error_page(404, "Not found", "Bad object name: %s", - sha1_to_hex(sha1)); + oid_to_hex(oid)); return; } - buf = read_sha1_file(sha1, &type, &size); + buf = read_object_file(oid, &type, &size); if (!buf) { cgit_print_error_page(500, "Internal server error", - "Error reading object %s", sha1_to_hex(sha1)); + "Error reading object %s", oid_to_hex(oid)); return; } @@ -144,7 +144,7 @@ static void print_object(const unsigned char *sha1, const char *path, cgit_set_title_from_path(path); cgit_print_layout_start(); - htmlf("blob: %s (", sha1_to_hex(sha1)); + htmlf("blob: %s (", oid_to_hex(oid)); cgit_plain_link("plain", NULL, NULL, ctx.qry.head, rev, path); html(") ("); cgit_tree_link("tree", NULL, NULL, ctx.qry.head, rev, path); @@ -218,7 +218,7 @@ cleanup: free(buf); } -static int walk_tree(const unsigned char *sha1, struct strbuf *base, +static int walk_tree(const struct object_id *oid, struct strbuf *base, const char *pathname, unsigned mode, int stage, void *cbdata) { @@ -229,7 +229,7 @@ static int walk_tree(const unsigned char *sha1, struct strbuf *base, struct strbuf buffer = STRBUF_INIT; strbuf_addbuf(&buffer, base); strbuf_addstr(&buffer, pathname); - print_object(sha1, buffer.buf, pathname, + print_object(oid, buffer.buf, pathname, walk_tree_ctx->curr_rev); strbuf_release(&buffer); walk_tree_ctx->state = 1; @@ -289,7 +289,7 @@ void cgit_print_blame(void) walk_tree_ctx.match_baselen = (path_items.match) ? basedir_len(path_items.match) : -1; - read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, + read_tree_recursive(commit->maybe_tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); if (!walk_tree_ctx.state) cgit_print_error_page(404, "Not found", "Not found"); diff --git a/ui-blob.c b/ui-blob.c index 761e886..7b6da2a 100644 --- a/ui-blob.c +++ b/ui-blob.c @@ -18,7 +18,7 @@ struct walk_tree_context { unsigned int file_only:1; }; -static int walk_tree(const unsigned char *sha1, struct strbuf *base, +static int walk_tree(const struct object_id *oid, struct strbuf *base, const char *pathname, unsigned mode, int stage, void *cbdata) { struct walk_tree_context *walk_tree_ctx = cbdata; @@ -28,7 +28,7 @@ static int walk_tree(const unsigned char *sha1, struct strbuf *base, if (strncmp(base->buf, walk_tree_ctx->match_path, base->len) || strcmp(walk_tree_ctx->match_path + base->len, pathname)) return READ_TREE_RECURSIVE; - hashcpy(walk_tree_ctx->matched_oid->hash, sha1); + oidcpy(walk_tree_ctx->matched_oid, oid); walk_tree_ctx->found_path = 1; return 0; } @@ -54,9 +54,9 @@ int cgit_ref_path_exists(const char *path, const char *ref, int file_only) if (get_oid(ref, &oid)) goto done; - if (sha1_object_info(oid.hash, &size) != OBJ_COMMIT) + if (oid_object_info(the_repository, &oid, &size) != OBJ_COMMIT) goto done; - read_tree_recursive(lookup_commit_reference(&oid)->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); + read_tree_recursive(lookup_commit_reference(&oid)->maybe_tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); done: free(path_items.match); @@ -87,17 +87,17 @@ int cgit_print_file(char *path, const char *head, int file_only) if (get_oid(head, &oid)) return -1; - type = sha1_object_info(oid.hash, &size); + type = oid_object_info(the_repository, &oid, &size); if (type == OBJ_COMMIT) { commit = lookup_commit_reference(&oid); - read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); + read_tree_recursive(commit->maybe_tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); if (!walk_tree_ctx.found_path) return -1; - type = sha1_object_info(oid.hash, &size); + type = oid_object_info(the_repository, &oid, &size); } if (type == OBJ_BAD) return -1; - buf = read_sha1_file(oid.hash, &type, &size); + buf = read_object_file(&oid, &type, &size); if (!buf) return -1; buf[size] = '\0'; @@ -142,12 +142,12 @@ void cgit_print_blob(const char *hex, char *path, const char *head, int file_onl } } - type = sha1_object_info(oid.hash, &size); + type = oid_object_info(the_repository, &oid, &size); if ((!hex) && type == OBJ_COMMIT && path) { commit = lookup_commit_reference(&oid); - read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); - type = sha1_object_info(oid.hash, &size); + read_tree_recursive(commit->maybe_tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); + type = oid_object_info(the_repository, &oid, &size); } if (type == OBJ_BAD) { @@ -156,7 +156,7 @@ void cgit_print_blob(const char *hex, char *path, const char *head, int file_onl return; } - buf = read_sha1_file(oid.hash, &type, &size); + buf = read_object_file(&oid, &type, &size); if (!buf) { cgit_print_error_page(500, "Internal server error", "Error reading object %s", hex); diff --git a/ui-clone.c b/ui-clone.c index bc98980..2c1ac3d 100644 --- a/ui-clone.c +++ b/ui-clone.c @@ -12,6 +12,7 @@ #include "html.h" #include "ui-shared.h" #include "packfile.h" +#include "object-store.h" static int print_ref_info(const char *refname, const struct object_id *oid, int flags, void *cb_data) @@ -38,8 +39,8 @@ static void print_pack_info(void) ctx.page.mimetype = "text/plain"; ctx.page.filename = "objects/info/packs"; cgit_print_http_headers(); - prepare_packed_git(); - for (pack = packed_git; pack; pack = pack->next) { + reprepare_packed_git(the_repository); + for (pack = get_packed_git(the_repository); pack; pack = pack->next) { if (pack->pack_local) { offset = strrchr(pack->pack_name, '/'); if (offset && offset[1] != '\0') diff --git a/ui-commit.c b/ui-commit.c index 65b4603..995cb93 100644 --- a/ui-commit.c +++ b/ui-commit.c @@ -78,7 +78,7 @@ void cgit_print_commit(char *hex, const char *prefix) html(")</td></tr>\n"); html("<tr><th>tree</th><td colspan='2' class='sha1'>"); tmp = xstrdup(hex); - cgit_tree_link(oid_to_hex(&commit->tree->object.oid), NULL, NULL, + cgit_tree_link(oid_to_hex(&commit->maybe_tree->object.oid), NULL, NULL, ctx.qry.head, tmp, NULL); if (prefix) { html(" /"); diff --git a/ui-diff.c b/ui-diff.c index a10ce8a..e33e9fb 100644 --- a/ui-diff.c +++ b/ui-diff.c @@ -258,8 +258,8 @@ static void header(const struct object_id *oid1, char *path1, int mode1, htmlf("<br/>deleted file mode %.6o", mode1); if (!subproject) { - abbrev1 = xstrdup(find_unique_abbrev(oid1->hash, DEFAULT_ABBREV)); - abbrev2 = xstrdup(find_unique_abbrev(oid2->hash, DEFAULT_ABBREV)); + abbrev1 = xstrdup(find_unique_abbrev(oid1, DEFAULT_ABBREV)); + abbrev2 = xstrdup(find_unique_abbrev(oid2, DEFAULT_ABBREV)); htmlf("<br/>index %s..%s", abbrev1, abbrev2); free(abbrev1); free(abbrev2); @@ -413,7 +413,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, "Bad commit: %s", oid_to_hex(new_rev_oid)); return; } - new_tree_oid = &commit->tree->object.oid; + new_tree_oid = &commit->maybe_tree->object.oid; if (old_rev) { if (get_oid(old_rev, old_rev_oid)) { @@ -434,7 +434,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, "Bad commit: %s", oid_to_hex(old_rev_oid)); return; } - old_tree_oid = &commit2->tree->object.oid; + old_tree_oid = &commit2->maybe_tree->object.oid; } else { old_tree_oid = NULL; } diff --git a/ui-log.c b/ui-log.c index b5cd2f6..d696e20 100644 --- a/ui-log.c +++ b/ui-log.c @@ -153,8 +153,8 @@ static int show_commit(struct commit *commit, struct rev_info *revs) rem_lines = 0; revs->diffopt.flags.recursive = 1; - diff_tree_oid(&parent->tree->object.oid, - &commit->tree->object.oid, + diff_tree_oid(&parent->maybe_tree->object.oid, + &commit->maybe_tree->object.oid, "", &revs->diffopt); diffcore_std(&revs->diffopt); diff --git a/ui-plain.c b/ui-plain.c index cfdbf73..ddb3e48 100644 --- a/ui-plain.c +++ b/ui-plain.c @@ -16,19 +16,19 @@ struct walk_tree_context { int match; }; -static int print_object(const unsigned char *sha1, const char *path) +static int print_object(const struct object_id *oid, const char *path) { enum object_type type; char *buf, *mimetype; unsigned long size; - type = sha1_object_info(sha1, &size); + type = oid_object_info(the_repository, oid, &size); if (type == OBJ_BAD) { cgit_print_error_page(404, "Not found", "Not found"); return 0; } - buf = read_sha1_file(sha1, &type, &size); + buf = read_object_file(oid, &type, &size); if (!buf) { cgit_print_error_page(404, "Not found", "Not found"); return 0; @@ -57,7 +57,7 @@ static int print_object(const unsigned char *sha1, const char *path) } ctx.page.filename = path; ctx.page.size = size; - ctx.page.etag = sha1_to_hex(sha1); + ctx.page.etag = oid_to_hex(oid); cgit_print_http_headers(); html_raw(buf, size); free(mimetype); @@ -73,7 +73,7 @@ static char *buildpath(const char *base, int baselen, const char *path) return fmtalloc("%.*s/", baselen, base); } -static void print_dir(const unsigned char *sha1, const char *base, +static void print_dir(const struct object_id *oid, const char *base, int baselen, const char *path) { char *fullpath, *slash; @@ -81,7 +81,7 @@ static void print_dir(const unsigned char *sha1, const char *base, fullpath = buildpath(base, baselen, path); slash = (fullpath[0] == '/' ? "" : "/"); - ctx.page.etag = sha1_to_hex(sha1); + ctx.page.etag = oid_to_hex(oid); cgit_print_http_headers(); htmlf("<html><head><title>%s", slash); html_txt(fullpath); @@ -106,7 +106,7 @@ static void print_dir(const unsigned char *sha1, const char *base, free(fullpath); } -static void print_dir_entry(const unsigned char *sha1, const char *base, +static void print_dir_entry(const struct object_id *oid, const char *base, int baselen, const char *path, unsigned mode) { char *fullpath; @@ -116,7 +116,7 @@ static void print_dir_entry(const unsigned char *sha1, const char *base, fullpath[strlen(fullpath) - 1] = 0; html(" <li>"); if (S_ISGITLINK(mode)) { - cgit_submodule_link(NULL, fullpath, sha1_to_hex(sha1)); + cgit_submodule_link(NULL, fullpath, oid_to_hex(oid)); } else cgit_plain_link(path, NULL, NULL, ctx.qry.head, ctx.qry.sha1, fullpath); @@ -129,22 +129,22 @@ static void print_dir_tail(void) html(" </ul>\n</body></html>\n"); } -static int walk_tree(const unsigned char *sha1, struct strbuf *base, +static int walk_tree(const struct object_id *oid, struct strbuf *base, const char *pathname, unsigned mode, int stage, void *cbdata) { struct walk_tree_context *walk_tree_ctx = cbdata; if (base->len == walk_tree_ctx->match_baselen) { if (S_ISREG(mode) || S_ISLNK(mode)) { - if (print_object(sha1, pathname)) + if (print_object(oid, pathname)) walk_tree_ctx->match = 1; } else if (S_ISDIR(mode)) { - print_dir(sha1, base->buf, base->len, pathname); + print_dir(oid, base->buf, base->len, pathname); walk_tree_ctx->match = 2; return READ_TREE_RECURSIVE; } } else if (base->len < INT_MAX && (int)base->len > walk_tree_ctx->match_baselen) { - print_dir_entry(sha1, base->buf, base->len, pathname, mode); + print_dir_entry(oid, base->buf, base->len, pathname, mode); walk_tree_ctx->match = 2; } else if (S_ISDIR(mode)) { return READ_TREE_RECURSIVE; @@ -193,12 +193,12 @@ void cgit_print_plain(void) if (!path_items.match) { path_items.match = ""; walk_tree_ctx.match_baselen = -1; - print_dir(commit->tree->object.oid.hash, "", 0, ""); + print_dir(&commit->maybe_tree->object.oid, "", 0, ""); walk_tree_ctx.match = 2; } else walk_tree_ctx.match_baselen = basedir_len(path_items.match); - read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); + read_tree_recursive(commit->maybe_tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); if (!walk_tree_ctx.match) cgit_print_error_page(404, "Not found", "Not found"); else if (walk_tree_ctx.match == 2) diff --git a/ui-snapshot.c b/ui-snapshot.c index 83ce6e8..92c3277 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c @@ -174,7 +174,7 @@ static int write_sig(const struct cgit_snapshot_format *format, return 0; } - buf = read_sha1_file(note->hash, &type, &size); + buf = read_object_file(note, &type, &size); if (!buf) { cgit_print_error_page(404, "Not found", "Not found"); return 0; diff --git a/ui-tree.c b/ui-tree.c index 524de0f..e6b3074 100644 --- a/ui-tree.c +++ b/ui-tree.c @@ -84,30 +84,30 @@ static void print_binary_buffer(char *buf, unsigned long size) html("</table>\n"); } -static void print_object(const unsigned char *sha1, char *path, const char *basename, const char *rev) +static void print_object(const struct object_id *oid, char *path, const char *basename, const char *rev) { enum object_type type; char *buf; unsigned long size; - type = sha1_object_info(sha1, &size); + type = oid_object_info(the_repository, oid, &size); if (type == OBJ_BAD) { cgit_print_error_page(404, "Not found", - "Bad object name: %s", sha1_to_hex(sha1)); + "Bad object name: %s", oid_to_hex(oid)); return; } - buf = read_sha1_file(sha1, &type, &size); + buf = read_object_file(oid, &type, &size); if (!buf) { cgit_print_error_page(500, "Internal server error", - "Error reading object %s", sha1_to_hex(sha1)); + "Error reading object %s", oid_to_hex(oid)); return; } cgit_set_title_from_path(path); cgit_print_layout_start(); - htmlf("blob: %s (", sha1_to_hex(sha1)); + htmlf("blob: %s (", oid_to_hex(oid)); cgit_plain_link("plain", NULL, NULL, ctx.qry.head, rev, path); if (ctx.cfg.enable_blame) { @@ -138,7 +138,7 @@ struct single_tree_ctx { size_t count; }; -static int single_tree_cb(const unsigned char *sha1, struct strbuf *base, +static int single_tree_cb(const struct object_id *oid, struct strbuf *base, const char *pathname, unsigned mode, int stage, void *cbdata) { @@ -153,12 +153,12 @@ static int single_tree_cb(const unsigned char *sha1, struct strbuf *base, } ctx->name = xstrdup(pathname); - hashcpy(ctx->oid.hash, sha1); + oidcpy(&ctx->oid, oid); strbuf_addf(ctx->path, "/%s", pathname); return 0; } -static void write_tree_link(const unsigned char *sha1, char *name, +static void write_tree_link(const struct object_id *oid, char *name, char *rev, struct strbuf *fullpath) { size_t initial_length = fullpath->len; @@ -171,7 +171,7 @@ static void write_tree_link(const unsigned char *sha1, char *name, .nr = 0 }; - hashcpy(tree_ctx.oid.hash, sha1); + oidcpy(&tree_ctx.oid, oid); while (tree_ctx.count == 1) { cgit_tree_link(name, NULL, "ls-dir", ctx.qry.head, rev, @@ -198,7 +198,7 @@ static void write_tree_link(const unsigned char *sha1, char *name, strbuf_setlen(fullpath, initial_length); } -static int ls_item(const unsigned char *sha1, struct strbuf *base, +static int ls_item(const struct object_id *oid, struct strbuf *base, const char *pathname, unsigned mode, int stage, void *cbdata) { struct walk_tree_context *walk_tree_ctx = cbdata; @@ -213,11 +213,11 @@ static int ls_item(const unsigned char *sha1, struct strbuf *base, ctx.qry.path ? "/" : "", name); if (!S_ISGITLINK(mode)) { - type = sha1_object_info(sha1, &size); + type = oid_object_info(the_repository, oid, &size); if (type == OBJ_BAD) { htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", name, - sha1_to_hex(sha1)); + oid_to_hex(oid)); free(name); return 0; } @@ -227,9 +227,9 @@ static int ls_item(const unsigned char *sha1, struct strbuf *base, cgit_print_filemode(mode); html("</td><td>"); if (S_ISGITLINK(mode)) { - cgit_submodule_link("ls-mod", fullpath.buf, sha1_to_hex(sha1)); + cgit_submodule_link("ls-mod", fullpath.buf, oid_to_hex(oid)); } else if (S_ISDIR(mode)) { - write_tree_link(sha1, name, walk_tree_ctx->curr_rev, + write_tree_link(oid, name, walk_tree_ctx->curr_rev, &fullpath); } else { char *ext = strrchr(name, '.'); @@ -289,7 +289,7 @@ static void ls_tree(const struct object_id *oid, char *path, struct walk_tree_co tree = parse_tree_indirect(oid); if (!tree) { cgit_print_error_page(404, "Not found", - "Not a tree object: %s", sha1_to_hex(oid->hash)); + "Not a tree object: %s", oid_to_hex(oid)); return; } @@ -299,7 +299,7 @@ static void ls_tree(const struct object_id *oid, char *path, struct walk_tree_co } -static int walk_tree(const unsigned char *sha1, struct strbuf *base, +static int walk_tree(const struct object_id *oid, struct strbuf *base, const char *pathname, unsigned mode, int stage, void *cbdata) { struct walk_tree_context *walk_tree_ctx = cbdata; @@ -320,12 +320,12 @@ static int walk_tree(const unsigned char *sha1, struct strbuf *base, return READ_TREE_RECURSIVE; } else { walk_tree_ctx->state = 2; - print_object(sha1, buffer.buf, pathname, walk_tree_ctx->curr_rev); + print_object(oid, buffer.buf, pathname, walk_tree_ctx->curr_rev); strbuf_release(&buffer); return 0; } } - ls_item(sha1, base, pathname, mode, stage, walk_tree_ctx); + ls_item(oid, base, pathname, mode, stage, walk_tree_ctx); return 0; } @@ -369,11 +369,11 @@ void cgit_print_tree(const char *rev, char *path) walk_tree_ctx.curr_rev = xstrdup(rev); if (path == NULL) { - ls_tree(&commit->tree->object.oid, NULL, &walk_tree_ctx); + ls_tree(&commit->maybe_tree->object.oid, NULL, &walk_tree_ctx); goto cleanup; } - read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); + read_tree_recursive(commit->maybe_tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); if (walk_tree_ctx.state == 1) ls_tail(); else if (walk_tree_ctx.state == 2) From b31e99887b17f513289fb11227b2484504e85b6c Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Wed, 20 Jun 2018 07:29:14 +0200 Subject: [PATCH 259/387] cache: close race window when unlocking slots We use POSIX advisory record locks to control access to cache slots, but these have an unhelpful behaviour in that they are released when any file descriptor referencing the file is closed by this process. Mostly this is okay, since we know we won't be opening the lock file anywhere else, but there is one place that it does matter: when we restore stdout we dup2() over a file descriptor referring to the file, thus closing that descriptor. Since we restore stdout before unlocking the slot, this creates a window during which the slot content can be overwritten. The fix is reasonably straightforward: simply restore stdout after unlocking the slot, but the diff is a bit bigger because this requires us to move the temporary stdout FD into struct cache_slot. Signed-off-by: John Keeping <john@keeping.me.uk> Reviewed-by: Christian Hesse <mail@eworm.de> --- cache.c | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/cache.c b/cache.c index 0901e6e..2c70be7 100644 --- a/cache.c +++ b/cache.c @@ -29,6 +29,7 @@ struct cache_slot { cache_fill_fn fn; int cache_fd; int lock_fd; + int stdout_fd; const char *cache_name; const char *lock_name; int match; @@ -197,6 +198,13 @@ static int unlock_slot(struct cache_slot *slot, int replace_old_slot) else err = unlink(slot->lock_name); + /* Restore stdout and close the temporary FD. */ + if (slot->stdout_fd >= 0) { + dup2(slot->stdout_fd, STDOUT_FILENO); + close(slot->stdout_fd); + slot->stdout_fd = -1; + } + if (err) return errno; @@ -208,42 +216,24 @@ static int unlock_slot(struct cache_slot *slot, int replace_old_slot) */ static int fill_slot(struct cache_slot *slot) { - int tmp; - /* Preserve stdout */ - tmp = dup(STDOUT_FILENO); - if (tmp == -1) + slot->stdout_fd = dup(STDOUT_FILENO); + if (slot->stdout_fd == -1) return errno; /* Redirect stdout to lockfile */ - if (dup2(slot->lock_fd, STDOUT_FILENO) == -1) { - close(tmp); + if (dup2(slot->lock_fd, STDOUT_FILENO) == -1) return errno; - } /* Generate cache content */ slot->fn(); /* Make sure any buffered data is flushed to the file */ - if (fflush(stdout)) { - close(tmp); + if (fflush(stdout)) return errno; - } /* update stat info */ - if (fstat(slot->lock_fd, &slot->cache_st)) { - close(tmp); - return errno; - } - - /* Restore stdout */ - if (dup2(tmp, STDOUT_FILENO) == -1) { - close(tmp); - return errno; - } - - /* Close the temporary filedescriptor */ - if (close(tmp)) + if (fstat(slot->lock_fd, &slot->cache_st)) return errno; return 0; @@ -393,6 +383,7 @@ int cache_process(int size, const char *path, const char *key, int ttl, strbuf_addstr(&lockname, ".lock"); slot.fn = fn; slot.ttl = ttl; + slot.stdout_fd = -1; slot.cache_name = filename.buf; slot.lock_name = lockname.buf; slot.key = key; From 9086260329a88594474a30e0c2f6e44ae0c149ab Mon Sep 17 00:00:00 2001 From: Andy Green <andy@warmcat.com> Date: Wed, 20 Jun 2018 18:12:03 +0800 Subject: [PATCH 260/387] manpage: fix sorting order You maybe didn't know you had OCD until you saw an alpha sorted list that has stuff out of order in it. Signed-off-by: Andy Green <andy@warmcat.com> Reviewed-by: John Keeping <john@keeping.me.uk> --- cgitrc.5.txt | 176 +++++++++++++++++++++++++-------------------------- 1 file changed, 88 insertions(+), 88 deletions(-) diff --git a/cgitrc.5.txt b/cgitrc.5.txt index acfae91..f6f6502 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -54,14 +54,10 @@ branch-sort:: list, and when set to "name" enables ordering by branch name. Default value: "name". -cache-root:: - Path used to store the cgit cache entries. Default value: - "/var/cache/cgit". See also: "MACRO EXPANSION". - -cache-static-ttl:: +cache-about-ttl:: Number which specifies the time-to-live, in minutes, for the cached - version of repository pages accessed with a fixed SHA1. See also: - "CACHE". Default value: -1". + version of the repository about page. See also: "CACHE". Default + value: "15". cache-dynamic-ttl:: Number which specifies the time-to-live, in minutes, for the cached @@ -73,6 +69,10 @@ cache-repo-ttl:: version of the repository summary page. See also: "CACHE". Default value: "5". +cache-root:: + Path used to store the cgit cache entries. Default value: + "/var/cache/cgit". See also: "MACRO EXPANSION". + cache-root-ttl:: Number which specifies the time-to-live, in minutes, for the cached version of the repository index page. See also: "CACHE". Default @@ -83,22 +83,22 @@ cache-scanrc-ttl:: of scanning a path for git repositories. See also: "CACHE". Default value: "15". -cache-about-ttl:: - Number which specifies the time-to-live, in minutes, for the cached - version of the repository about page. See also: "CACHE". Default - value: "15". - -cache-snapshot-ttl:: - Number which specifies the time-to-live, in minutes, for the cached - version of snapshots. See also: "CACHE". Default value: "5". +case-sensitive-sort:: + Sort items in the repo list case sensitively. Default value: "1". + See also: repository-sort, section-sort. cache-size:: The maximum number of entries in the cgit cache. When set to "0", caching is disabled. See also: "CACHE". Default value: "0" -case-sensitive-sort:: - Sort items in the repo list case sensitively. Default value: "1". - See also: repository-sort, section-sort. +cache-snapshot-ttl:: + Number which specifies the time-to-live, in minutes, for the cached + version of snapshots. See also: "CACHE". Default value: "5". + +cache-static-ttl:: + Number which specifies the time-to-live, in minutes, for the cached + version of repository pages accessed with a fixed SHA1. See also: + "CACHE". Default value: -1". clone-prefix:: Space-separated list of common prefixes which, when combined with a @@ -159,12 +159,29 @@ enable-follow-links:: Flag which, when set to "1", allows users to follow a file in the log view. Default value: "0". +enable-git-config:: + Flag which, when set to "1", will allow cgit to use git config to set + any repo specific settings. This option is used in conjunction with + "scan-path", and must be defined prior, to augment repo-specific + settings. The keys gitweb.owner, gitweb.category, gitweb.description, + and gitweb.homepage will map to the cgit keys repo.owner, repo.section, + repo.desc, and repo.homepage respectively. All git config keys that begin + with "cgit." will be mapped to the corresponding "repo." key in cgit. + Default value: "0". See also: scan-path, section-from-path. + enable-http-clone:: - If set to "1", cgit will act as an dumb HTTP endpoint for git clones. + If set to "1", cgit will act as a dumb HTTP endpoint for git clones. You can add "http://$HTTP_HOST$SCRIPT_NAME/$CGIT_REPO_URL" to clone-url to expose this feature. If you use an alternate way of serving git repositories, you may wish to disable this. Default value: "1". +enable-html-serving:: + Flag which, when set to "1", will allow the /plain handler to serve + mimetype headers that result in the file being treated as HTML by the + browser. When set to "0", such file types are returned instead as + text/plain or application/octet-stream. Default value: "0". See also: + "repo.enable-html-serving". + enable-index-links:: Flag which, when set to "1", will make cgit generate extra links for each repo in the repository index (specifically, to the "summary", @@ -195,27 +212,10 @@ enable-subject-links:: in commit view. Default value: "0". See also: "repo.enable-subject-links". -enable-html-serving:: - Flag which, when set to "1", will allow the /plain handler to serve - mimetype headers that result in the file being treated as HTML by the - browser. When set to "0", such file types are returned instead as - text/plain or application/octet-stream. Default value: "0". See also: - "repo.enable-html-serving". - enable-tree-linenumbers:: Flag which, when set to "1", will make cgit generate linenumber links for plaintext blobs printed in the tree view. Default value: "1". -enable-git-config:: - Flag which, when set to "1", will allow cgit to use git config to set - any repo specific settings. This option is used in conjunction with - "scan-path", and must be defined prior, to augment repo-specific - settings. The keys gitweb.owner, gitweb.category, gitweb.description, - and gitweb.homepage will map to the cgit keys repo.owner, repo.section, - repo.desc, and repo.homepage respectively. All git config keys that begin - with "cgit." will be mapped to the corresponding "repo." key in cgit. - Default value: "0". See also: scan-path, section-from-path. - favicon:: Url used as link to a shortcut icon for cgit. It is suggested to use the value "/favicon.ico" since certain browsers will ignore other @@ -251,19 +251,14 @@ logo-link:: calculated url of the repository index page will be used. Default value: none. -owner-filter:: - Specifies a command which will be invoked to format the Owner - column of the main page. The command will get the owner on STDIN, - and the STDOUT from the command will be included verbatim in the - table. This can be used to link to additional context such as an - owners home page. When active this filter is used instead of the - default owner query url. Default value: none. - See also: "FILTER API". - max-atom-items:: Specifies the number of items to display in atom feeds view. Default value: "10". +max-blob-size:: + Specifies the maximum size of a blob to display HTML for in KBytes. + Default value: "0" (limit disabled). + max-commit-count:: Specifies the number of entries to list per page in "log" view. Default value: "50". @@ -280,10 +275,6 @@ max-repodesc-length:: Specifies the maximum number of repo description characters to display on the repository index page. Default value: "80". -max-blob-size:: - Specifies the maximum size of a blob to display HTML for in KBytes. - Default value: "0" (limit disabled). - max-stats:: Set the default maximum statistics period. Valid values are "week", "month", "quarter" and "year". If unspecified, statistics are @@ -319,6 +310,15 @@ noheader:: Flag which, when set to "1", will make cgit omit the standard header on all pages. Default value: none. See also: "embedded". +owner-filter:: + Specifies a command which will be invoked to format the Owner + column of the main page. The command will get the owner on STDIN, + and the STDOUT from the command will be included verbatim in the + table. This can be used to link to additional context such as an + owners home page. When active this filter is used instead of the + default owner query url. Default value: none. + See also: "FILTER API". + project-list:: A list of subdirectories inside of scan-path, relative to it, that should loaded as git repositories. This must be defined prior to @@ -481,9 +481,6 @@ repo.defbranch:: repo.desc:: The value to show as repository description. Default value: none. -repo.homepage:: - The value to show as repository homepage. Default value: none. - repo.email-filter:: Override the default email-filter. Default value: none. See also: "enable-filter-overrides". See also: "FILTER API". @@ -492,6 +489,10 @@ repo.enable-commit-graph:: A flag which can be used to disable the global setting `enable-commit-graph'. Default value: none. +repo.enable-html-serving:: + A flag which can be used to override the global setting + `enable-html-serving`. Default value: none. + repo.enable-log-filecount:: A flag which can be used to disable the global setting `enable-log-filecount'. Default value: none. @@ -508,15 +509,14 @@ repo.enable-subject-links:: A flag which can be used to override the global setting `enable-subject-links'. Default value: none. -repo.enable-html-serving:: - A flag which can be used to override the global setting - `enable-html-serving`. Default value: none. - repo.hide:: Flag which, when set to "1", hides the repository from the repository index. The repository can still be accessed by providing a direct path. Default value: "0". See also: "repo.ignore". +repo.homepage:: + The value to show as repository homepage. Default value: none. + repo.ignore:: Flag which, when set to "1", ignores the repository. The repository is not shown in the index and cannot be accessed by providing a direct @@ -531,10 +531,6 @@ repo.logo-link:: calculated url of the repository index page will be used. Default value: global logo-link. -repo.owner-filter:: - Override the default owner-filter. Default value: none. See also: - "enable-filter-overrides". See also: "FILTER API". - repo.module-link:: Text which will be used as the formatstring for a hyperlink when a submodule is printed in a directory listing. The arguments for the @@ -559,6 +555,10 @@ repo.owner:: A value used to identify the owner of the repository. Default value: none. +repo.owner-filter:: + Override the default owner-filter. Default value: none. See also: + "enable-filter-overrides". See also: "FILTER API". + repo.path:: An absolute path to the repository directory. For non-bare repositories this is the .git-directory. Default value: none. @@ -574,6 +574,10 @@ repo.readme:: are no non-public files located in the same directory as the readme file. Default value: <readme>. +repo.section:: + Override the current section name for this repository. Default value: + none. + repo.snapshots:: A mask of snapshot formats for this repo that cgit generates links for, restricted by the global "snapshots" setting. Default value: @@ -586,10 +590,6 @@ repo.snapshot-prefix:: of "linux-stable-3.15.4". Default value: <empty> meaning to use the repository basename. -repo.section:: - Override the current section name for this repository. Default value: - none. - repo.source-filter:: Override the default source-filter. Default value: none. See also: "enable-filter-overrides". See also: "FILTER API". @@ -662,30 +662,6 @@ about filter:: The about text that is to be filtered is available on standard input and the filtered text is expected on standard output. -commit filter:: - This filter is given no arguments. The commit message text that is to - be filtered is available on standard input and the filtered text is - expected on standard output. - -email filter:: - This filter is given two parameters: the email address of the relevant - author and a string indicating the originating page. The filter will - then receive the text string to format on standard input and is - expected to write to standard output the formatted text to be included - in the page. - -owner filter:: - This filter is given no arguments. The owner text is available on - standard input and the filter is expected to write to standard - output. The output is included in the Owner column. - -source filter:: - This filter is given a single parameter: the filename of the source - file to filter. The filter can use the filename to determine (for - example) the syntax highlighting mode. The contents of the source - file that is to be filtered is available on standard input and the - filtered contents is expected on standard output. - auth filter:: The authentication filter receives 12 parameters: - filter action, explained below, which specifies which action the @@ -712,6 +688,30 @@ auth filter:: Please see `filters/simple-authentication.lua` for a clear example script that may be modified. +commit filter:: + This filter is given no arguments. The commit message text that is to + be filtered is available on standard input and the filtered text is + expected on standard output. + +email filter:: + This filter is given two parameters: the email address of the relevant + author and a string indicating the originating page. The filter will + then receive the text string to format on standard input and is + expected to write to standard output the formatted text to be included + in the page. + +owner filter:: + This filter is given no arguments. The owner text is available on + standard input and the filter is expected to write to standard + output. The output is included in the Owner column. + +source filter:: + This filter is given a single parameter: the filename of the source + file to filter. The filter can use the filename to determine (for + example) the syntax highlighting mode. The contents of the source + file that is to be filtered is available on standard input and the + filtered contents is expected on standard output. + All filters are handed the following environment variables: From c4fbb99cee30fa295e240b429b2dc7e8ad83d535 Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Wed, 20 Jun 2018 18:12:09 +0800 Subject: [PATCH 261/387] Use string list strdup_strings for mimetypes There's no need to do this manually with the string list API will do it for us. Signed-off-by: John Keeping <john@keeping.me.uk> --- cgit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cgit.c b/cgit.c index 223dfc8..0c9f3e9 100644 --- a/cgit.c +++ b/cgit.c @@ -23,7 +23,7 @@ static void add_mimetype(const char *name, const char *value) { struct string_list_item *item; - item = string_list_insert(&ctx.cfg.mimetypes, xstrdup(name)); + item = string_list_insert(&ctx.cfg.mimetypes, name); item->util = xstrdup(value); } @@ -414,7 +414,7 @@ static void prepare_context(void) ctx.page.modified = time(NULL); ctx.page.expires = ctx.page.modified; ctx.page.etag = NULL; - memset(&ctx.cfg.mimetypes, 0, sizeof(struct string_list)); + string_list_init(&ctx.cfg.mimetypes, 1); if (ctx.env.script_name) ctx.cfg.script_name = xstrdup(ctx.env.script_name); if (ctx.env.query_string) From b522a302c9c4fb9fd9e1ea829ee990afc74980ca Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Mon, 12 Feb 2018 23:10:06 +0100 Subject: [PATCH 262/387] extra-head-content: introduce another option for meta tags This is to support things like go-import meta tags, which are on a per-repo basis. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- cgit.c | 4 ++++ cgit.h | 1 + cgitrc.5.txt | 4 ++++ shared.c | 1 + ui-shared.c | 2 ++ 5 files changed, 12 insertions(+) diff --git a/cgit.c b/cgit.c index 0c9f3e9..e2d7891 100644 --- a/cgit.c +++ b/cgit.c @@ -46,6 +46,8 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va repo->homepage = xstrdup(value); else if (!strcmp(name, "defbranch")) repo->defbranch = xstrdup(value); + else if (!strcmp(name, "extra-head-content")) + repo->extra_head_content = xstrdup(value); else if (!strcmp(name, "snapshots")) repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); else if (!strcmp(name, "enable-commit-graph")) @@ -797,6 +799,8 @@ static void print_repo(FILE *f, struct cgit_repo *repo) } if (repo->defbranch) fprintf(f, "repo.defbranch=%s\n", repo->defbranch); + if (repo->extra_head_content) + fprintf(f, "repo.extra-head-content=%s\n", repo->extra_head_content); if (repo->module_link) fprintf(f, "repo.module-link=%s\n", repo->module_link); if (repo->section) diff --git a/cgit.h b/cgit.h index 6feca68..32dfd7a 100644 --- a/cgit.h +++ b/cgit.h @@ -81,6 +81,7 @@ struct cgit_repo { char *name; char *path; char *desc; + char *extra_head_content; char *owner; char *homepage; char *defbranch; diff --git a/cgitrc.5.txt b/cgitrc.5.txt index f6f6502..6f008cc 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -509,6 +509,10 @@ repo.enable-subject-links:: A flag which can be used to override the global setting `enable-subject-links'. Default value: none. +repo.extra-head-content:: + This value will be added verbatim to the head section of each page + displayed for this repo. Default value: none. + repo.hide:: Flag which, when set to "1", hides the repository from the repository index. The repository can still be accessed by providing a direct path. diff --git a/shared.c b/shared.c index d7c7636..f7b64cf 100644 --- a/shared.c +++ b/shared.c @@ -53,6 +53,7 @@ struct cgit_repo *cgit_add_repo(const char *url) ret->name = ret->url; ret->path = NULL; ret->desc = cgit_default_repo_desc; + ret->extra_head_content = NULL; ret->owner = NULL; ret->homepage = NULL; ret->section = ctx.cfg.section; diff --git a/ui-shared.c b/ui-shared.c index a63dcb0..9a2e382 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -775,6 +775,8 @@ void cgit_print_docstart(void) cgit_add_clone_urls(print_rel_vcs_link); if (ctx.cfg.head_include) html_include(ctx.cfg.head_include); + if (ctx.repo && ctx.repo->extra_head_content) + html(ctx.repo->extra_head_content); html("</head>\n"); html("<body>\n"); if (ctx.cfg.header) From 7ba41963dde175581ae7b395045fd51678237930 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Thu, 7 Jun 2018 21:31:28 +0200 Subject: [PATCH 263/387] snapshot: support tar signature for compressed tar This adds support for kernel.org style signatures where the uncompressed tar archive is signed and compressed later. The signature is valid for all tar* snapshots. We have a filter which snapshots may be generated and downloaded. This has to allow tar signatures now even if tar itself is not allowed. To simplify things we allow all signatures. Signed-off-by: Christian Hesse <mail@eworm.de> --- ui-shared.c | 9 ++++++++- ui-snapshot.c | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ui-shared.c b/ui-shared.c index 9a2e382..066a470 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -1114,7 +1114,7 @@ void cgit_compose_snapshot_prefix(struct strbuf *filename, const char *base, void cgit_print_snapshot_links(const struct cgit_repo *repo, const char *ref, const char *separator) { - const struct cgit_snapshot_format* f; + const struct cgit_snapshot_format *f; struct strbuf filename = STRBUF_INIT; const char *basename; size_t prefixlen; @@ -1139,6 +1139,13 @@ void cgit_print_snapshot_links(const struct cgit_repo *repo, const char *ref, cgit_snapshot_link("sig", NULL, NULL, NULL, NULL, filename.buf); html(")"); + } else if (starts_with(f->suffix, ".tar") && cgit_snapshot_get_sig(ref, &cgit_snapshot_formats[0])) { + strbuf_setlen(&filename, strlen(filename.buf) - strlen(f->suffix)); + strbuf_addstr(&filename, ".tar.asc"); + html(" ("); + cgit_snapshot_link("sig", NULL, NULL, NULL, NULL, + filename.buf); + html(")"); } html(separator); } diff --git a/ui-snapshot.c b/ui-snapshot.c index 92c3277..fa3ceaf 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c @@ -86,6 +86,7 @@ static int write_tar_xz_archive(const char *hex, const char *prefix) } const struct cgit_snapshot_format cgit_snapshot_formats[] = { + /* .tar must remain the 0 index */ { ".tar", "application/x-tar", write_tar_archive }, { ".tar.gz", "application/x-gzip", write_tar_gzip_archive }, { ".tar.bz2", "application/x-bzip2", write_tar_bzip2_archive }, @@ -268,7 +269,7 @@ void cgit_print_snapshot(const char *head, const char *hex, } f = get_format(filename); - if (!f || !(ctx.repo->snapshots & cgit_snapshot_format_bit(f))) { + if (!f || (!sig_filename && !(ctx.repo->snapshots & cgit_snapshot_format_bit(f)))) { cgit_print_error_page(400, "Bad request", "Unsupported snapshot format: %s", filename); return; From c4167cbd65acef801e6132ba1182f6ce246ed630 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Tue, 3 Jul 2018 20:44:08 +0200 Subject: [PATCH 264/387] cgitrc.5: document new signature notes Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- cgitrc.5.txt | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/cgitrc.5.txt b/cgitrc.5.txt index 6f008cc..6b4efa2 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -759,7 +759,7 @@ the environment variables defined in "FILTER API": CACHE ------- +----- All cache ttl values are in minutes. Negative ttl values indicate that a page type will never expire, and thus the first time a URL is accessed, the result @@ -767,6 +767,22 @@ will be cached indefinitely, even if the underlying git repository changes. Conversely, when a ttl value is zero, the cache is disabled for that particular page type, and the page type is never cached. +SIGNATURES +---------- + +Cgit can host .asc signatures corresponding to various snapshot formats, +through use of git notes. For example, the following command may be used to +add a signature to a .tar.xz archive: + + git notes --ref=refs/notes/signatures/tar.xz add -C "$( + gpg --output - --armor --detach-sign cgit-1.1.tar.xz | + git hash-object -w --stdin + )" v1.1 + +If it is instead desirable to attach a signature of the underlying .tar, this +will be linked, as a special case, beside a .tar.* link that does not have its +own signature. + EXAMPLE CGITRC FILE ------------------- From 08a2b1b8f812c6d77489467c8ff120979c297bed Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Wed, 4 Jul 2018 03:13:31 +0200 Subject: [PATCH 265/387] Fix gcc 8.1.1 compiler warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CC ../shared.o ../shared.c: In function ‘expand_macro’: ../shared.c:487:3: warning: ‘strncpy’ specified bound depends on the length of the source argument [-Wstringop-overflow=] strncpy(name, value, len); ^~~~~~~~~~~~~~~~~~~~~~~~~ ../shared.c:484:9: note: length computed here len = strlen(value); ^~~~~~~~~~~~~ ../ui-shared.c: In function ‘cgit_repobasename’: ../ui-shared.c:136:2: warning: ‘strncpy’ specified bound 1024 equals destination size [-Wstringop-truncation] strncpy(rvbuf, reponame, sizeof(rvbuf)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CC ../ui-ssdiff.o ../ui-ssdiff.c: In function ‘replace_tabs’: ../ui-ssdiff.c:142:4: warning: ‘strncat’ output truncated copying between 1 and 8 bytes from a string of length 8 [-Wstringop-truncation] strncat(result, spaces, 8 - (strlen(result) % 8)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- shared.c | 7 ++++--- ui-shared.c | 19 ++++++++++++------- ui-ssdiff.c | 12 +++++++----- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/shared.c b/shared.c index f7b64cf..609bd2a 100644 --- a/shared.c +++ b/shared.c @@ -476,15 +476,16 @@ static int is_token_char(char c) static char *expand_macro(char *name, int maxlength) { char *value; - int len; + size_t len; len = 0; value = getenv(name); if (value) { - len = strlen(value); + len = strlen(value) + 1; if (len > maxlength) len = maxlength; - strncpy(name, value, len); + strlcpy(name, value, len); + --len; } return name + len; } diff --git a/ui-shared.c b/ui-shared.c index 066a470..739505a 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -133,20 +133,25 @@ const char *cgit_repobasename(const char *reponame) static char rvbuf[1024]; int p; const char *rv; - strncpy(rvbuf, reponame, sizeof(rvbuf)); - if (rvbuf[sizeof(rvbuf)-1]) + size_t len; + + len = strlcpy(rvbuf, reponame, sizeof(rvbuf)); + if (len >= sizeof(rvbuf)) die("cgit_repobasename: truncated repository name '%s'", reponame); - p = strlen(rvbuf)-1; + p = len - 1; /* strip trailing slashes */ - while (p && rvbuf[p] == '/') rvbuf[p--] = 0; + while (p && rvbuf[p] == '/') + rvbuf[p--] = '\0'; /* strip trailing .git */ if (p >= 3 && starts_with(&rvbuf[p-3], ".git")) { - p -= 3; rvbuf[p--] = 0; + p -= 3; + rvbuf[p--] = '\0'; } /* strip more trailing slashes if any */ - while ( p && rvbuf[p] == '/') rvbuf[p--] = 0; + while (p && rvbuf[p] == '/') + rvbuf[p--] = '\0'; /* find last slash in the remaining string */ - rv = strrchr(rvbuf,'/'); + rv = strrchr(rvbuf, '/'); if (rv) return ++rv; return rvbuf; diff --git a/ui-ssdiff.c b/ui-ssdiff.c index 7f261ed..68c2044 100644 --- a/ui-ssdiff.c +++ b/ui-ssdiff.c @@ -114,11 +114,10 @@ static char *replace_tabs(char *line) { char *prev_buf = line; char *cur_buf; - int linelen = strlen(line); + size_t linelen = strlen(line); int n_tabs = 0; int i; char *result; - char *spaces = " "; if (linelen == 0) { result = xmalloc(1); @@ -126,20 +125,23 @@ static char *replace_tabs(char *line) return result; } - for (i = 0; i < linelen; i++) + for (i = 0; i < linelen; i++) { if (line[i] == '\t') n_tabs += 1; + } result = xmalloc(linelen + n_tabs * 8 + 1); result[0] = '\0'; - while (1) { + for (;;) { cur_buf = strchr(prev_buf, '\t'); if (!cur_buf) { strcat(result, prev_buf); break; } else { strncat(result, prev_buf, cur_buf - prev_buf); - strncat(result, spaces, 8 - (strlen(result) % 8)); + linelen = strlen(result); + memset(&result[linelen], ' ', 8 - (linelen % 8)); + result[linelen + 8 - (linelen % 8)] = '\0'; } prev_buf = cur_buf + 1; } From 22583c4992852fff08559c35fde7bf6f673d1644 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Thu, 5 Jul 2018 02:38:33 +0200 Subject: [PATCH 266/387] cgitrc.5: add local tar signature example Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- cgitrc.5.txt | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/cgitrc.5.txt b/cgitrc.5.txt index 6b4efa2..34b351b 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -775,14 +775,25 @@ through use of git notes. For example, the following command may be used to add a signature to a .tar.xz archive: git notes --ref=refs/notes/signatures/tar.xz add -C "$( - gpg --output - --armor --detach-sign cgit-1.1.tar.xz | - git hash-object -w --stdin + gpg --output - --armor --detach-sign cgit-1.1.tar.xz | + git hash-object -w --stdin )" v1.1 If it is instead desirable to attach a signature of the underlying .tar, this will be linked, as a special case, beside a .tar.* link that does not have its -own signature. +own signature. For example, a signature of a tarball of the latest tag might +be added with a similar command: + tag="$(git describe --abbrev=0)" + git notes --ref=refs/notes/signatures/tar add -C "$( + git archive --format tar --prefix "cgit-${tag#v}/" "$tag" | + gpg --output - --armor --detach-sign | + git hash-object -w --stdin + )" "$tag" + +Since git-archive(1) is expected to produce stable output between versions, +this allows one to generate a long-term signature of the contents of a given +tag. EXAMPLE CGITRC FILE ------------------- From 089b29a7e14f9115971ccc5c5f5713b3aff1fff6 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Sun, 8 Jul 2018 19:14:44 +0200 Subject: [PATCH 267/387] css: use correct size in annotated decoration Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- cgit.css | 1 + 1 file changed, 1 insertion(+) diff --git a/cgit.css b/cgit.css index 05c4530..d4aadbf 100644 --- a/cgit.css +++ b/cgit.css @@ -711,6 +711,7 @@ div#cgit a.deco { div#cgit div.commit-subject a.branch-deco, div#cgit div.commit-subject a.tag-deco, +div#cgit div.commit-subject a.tag-annotated-deco, div#cgit div.commit-subject a.remote-deco, div#cgit div.commit-subject a.deco { margin-left: 1em; From 5dec7f4a9156b02ebc523e52c85988d81b5dcf73 Mon Sep 17 00:00:00 2001 From: Todd Zullinger <tmz@pobox.com> Date: Tue, 10 Jul 2018 10:03:34 -0400 Subject: [PATCH 268/387] Update COPYING MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The address of the Free Software Foundation has changed since the license was added in 7640d90 ("Add license file and copyright notices", 2006-12-10). Update the license file from gnu.org¹. The only non-whitespace changes are the updated FSF address and two references to the L in LGPL changed from Library to Lesser. ¹ https://www.gnu.org/licenses/old-licenses/gpl-2.0.txt Signed-off-by: Todd Zullinger <tmz@pobox.com> --- COPYING | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/COPYING b/COPYING index 5b6e7c6..d159169 100644 --- a/COPYING +++ b/COPYING @@ -1,12 +1,12 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. - Preamble + Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public @@ -15,7 +15,7 @@ software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to +the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not @@ -55,8 +55,8 @@ patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. - - GNU GENERAL PUBLIC LICENSE + + GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains @@ -110,7 +110,7 @@ above, provided that you also meet all of these conditions: License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) - + These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in @@ -168,7 +168,7 @@ access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. - + 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is @@ -225,7 +225,7 @@ impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. - + 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License @@ -255,7 +255,7 @@ make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. - NO WARRANTY + NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN @@ -277,9 +277,9 @@ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it @@ -303,10 +303,9 @@ the "copyright" line and a pointer to where the full notice is found. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. @@ -336,5 +335,5 @@ necessary. Here is a sample; alter the names: This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General +library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. From c132ef2462b3c5223c77eb68fa372edde85cfb6b Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Fri, 13 Jul 2018 22:40:42 +0200 Subject: [PATCH 269/387] Bump version. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 137150c..4082905 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ all:: -CGIT_VERSION = v1.1 +CGIT_VERSION = v1.2 CGIT_SCRIPT_NAME = cgit.cgi CGIT_SCRIPT_PATH = /var/www/htdocs/cgit CGIT_DATA_PATH = $(CGIT_SCRIPT_PATH) From c3b5b5f648d953307672a4b30e9222787668f708 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Sat, 14 Jul 2018 03:32:00 +0200 Subject: [PATCH 270/387] auth-filters: do not use HMAC-SHA1 Though SHA1 is broken, HMAC-SHA1 is still fine. But let's not push our luck; SHA256 is more sensible anyway. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- filters/gentoo-ldap-authentication.lua | 4 ++-- filters/simple-authentication.lua | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/filters/gentoo-ldap-authentication.lua b/filters/gentoo-ldap-authentication.lua index 6d8eb3e..c1e382f 100644 --- a/filters/gentoo-ldap-authentication.lua +++ b/filters/gentoo-ldap-authentication.lua @@ -271,7 +271,7 @@ function validate_value(expected_field, cookie) end -- Lua hashes strings, so these comparisons are time invariant. - if hmac ~= crypto.hmac.digest("sha1", field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt, secret) then + if hmac ~= crypto.hmac.digest("sha256", field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt, secret) then return nil end @@ -296,7 +296,7 @@ function secure_value(field, value, expiration) value = url_encode(value) field = url_encode(field) authstr = field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt - authstr = authstr .. "|" .. crypto.hmac.digest("sha1", authstr, secret) + authstr = authstr .. "|" .. crypto.hmac.digest("sha256", authstr, secret) return authstr end diff --git a/filters/simple-authentication.lua b/filters/simple-authentication.lua index de34d09..596c041 100644 --- a/filters/simple-authentication.lua +++ b/filters/simple-authentication.lua @@ -231,7 +231,7 @@ function validate_value(expected_field, cookie) end -- Lua hashes strings, so these comparisons are time invariant. - if hmac ~= crypto.hmac.digest("sha1", field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt, secret) then + if hmac ~= crypto.hmac.digest("sha256", field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt, secret) then return nil end @@ -256,7 +256,7 @@ function secure_value(field, value, expiration) value = url_encode(value) field = url_encode(field) authstr = field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt - authstr = authstr .. "|" .. crypto.hmac.digest("sha1", authstr, secret) + authstr = authstr .. "|" .. crypto.hmac.digest("sha256", authstr, secret) return authstr end From 93a2c3305190ca87cc1a6c98868c251ef67c3f37 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Sat, 14 Jul 2018 05:09:27 +0200 Subject: [PATCH 271/387] auth-filter: do not write more than we've read Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- cgit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cgit.c b/cgit.c index e2d7891..fda0aa4 100644 --- a/cgit.c +++ b/cgit.c @@ -659,13 +659,13 @@ static inline void open_auth_filter(const char *function) static inline void authenticate_post(void) { char buffer[MAX_AUTHENTICATION_POST_BYTES]; - unsigned int len; + ssize_t len; open_auth_filter("authenticate-post"); len = ctx.env.content_length; if (len > MAX_AUTHENTICATION_POST_BYTES) len = MAX_AUTHENTICATION_POST_BYTES; - if (read(STDIN_FILENO, buffer, len) < 0) + if ((len = read(STDIN_FILENO, buffer, len)) < 0) die_errno("Could not read POST from stdin"); if (write(STDOUT_FILENO, buffer, len) < 0) die_errno("Could not write POST to stdout"); From c4d23d02ec5a26d09d389dcf7b8928ecd5798ccc Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Sat, 14 Jul 2018 05:10:28 +0200 Subject: [PATCH 272/387] auth-filters: do not crash on nil username Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- filters/gentoo-ldap-authentication.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/filters/gentoo-ldap-authentication.lua b/filters/gentoo-ldap-authentication.lua index c1e382f..3b6564b 100644 --- a/filters/gentoo-ldap-authentication.lua +++ b/filters/gentoo-ldap-authentication.lua @@ -106,7 +106,7 @@ local lualdap = require("lualdap") function gentoo_ldap_user_groups(username, password) -- Ensure the user is alphanumeric - if username:match("%W") then + if username == nil or username:match("%W") then return nil end From b73df8098f261ecbd4bc5ba689f9766a1a75f9a0 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Sun, 15 Jul 2018 03:22:12 +0200 Subject: [PATCH 273/387] auth-filters: generate secret securely This is much better than having the user generate it themselves. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- filters/gentoo-ldap-authentication.lua | 53 +++++++++++++++++++++----- filters/simple-authentication.lua | 50 ++++++++++++++++++++---- 2 files changed, 85 insertions(+), 18 deletions(-) diff --git a/filters/gentoo-ldap-authentication.lua b/filters/gentoo-ldap-authentication.lua index 3b6564b..b4d98c2 100644 --- a/filters/gentoo-ldap-authentication.lua +++ b/filters/gentoo-ldap-authentication.lua @@ -5,7 +5,13 @@ -- <http://mkottman.github.io/luacrypto/> -- lualdap >= 1.2 -- <https://git.zx2c4.com/lualdap/about/> +-- luaposix +-- <https://github.com/luaposix/luaposix> -- +local sysstat = require("posix.sys.stat") +local unistd = require("posix.unistd") +local crypto = require("crypto") +local lualdap = require("lualdap") -- @@ -21,11 +27,9 @@ local protected_repos = { portage = "dev" } - --- All cookies will be authenticated based on this secret. Make it something --- totally random and impossible to guess. It should be large. -local secret = "BE SURE TO CUSTOMIZE THIS STRING TO SOMETHING BIG AND RANDOM" - +-- Set this to a path this script can write to for storing a persistent +-- cookie secret, which should be guarded. +local secret_filename = "/var/cache/cgit/auth-secret" -- @@ -102,8 +106,6 @@ end -- -- -local lualdap = require("lualdap") - function gentoo_ldap_user_groups(username, password) -- Ensure the user is alphanumeric if username == nil or username:match("%W") then @@ -231,7 +233,38 @@ end -- -- -local crypto = require("crypto") +local secret = nil + +-- Loads a secret from a file, creates a secret, or returns one from memory. +function get_secret() + if secret ~= nil then + return secret + end + local secret_file = io.open(secret_filename, "r") + if secret_file == nil then + local old_umask = sysstat.umask(63) + local temporary_filename = secret_filename .. ".tmp." .. crypto.hex(crypto.rand.bytes(16)) + local temporary_file = io.open(temporary_filename, "w") + if temporary_file == nil then + os.exit(177) + end + temporary_file:write(crypto.hex(crypto.rand.bytes(32))) + temporary_file:close() + unistd.link(temporary_filename, secret_filename) -- Intentionally fails in the case that another process is doing the same. + unistd.unlink(temporary_filename) + sysstat.umask(old_umask) + secret_file = io.open(secret_filename, "r") + end + if secret_file == nil then + os.exit(177) + end + secret = secret_file:read() + secret_file:close() + if secret:len() ~= 64 then + os.exit(177) + end + return secret +end -- Returns value of cookie if cookie is valid. Otherwise returns nil. function validate_value(expected_field, cookie) @@ -271,7 +304,7 @@ function validate_value(expected_field, cookie) end -- Lua hashes strings, so these comparisons are time invariant. - if hmac ~= crypto.hmac.digest("sha256", field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt, secret) then + if hmac ~= crypto.hmac.digest("sha256", field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt, get_secret()) then return nil end @@ -296,7 +329,7 @@ function secure_value(field, value, expiration) value = url_encode(value) field = url_encode(field) authstr = field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt - authstr = authstr .. "|" .. crypto.hmac.digest("sha256", authstr, secret) + authstr = authstr .. "|" .. crypto.hmac.digest("sha256", authstr, get_secret()) return authstr end diff --git a/filters/simple-authentication.lua b/filters/simple-authentication.lua index 596c041..bf35632 100644 --- a/filters/simple-authentication.lua +++ b/filters/simple-authentication.lua @@ -3,7 +3,12 @@ -- Requirements: -- luacrypto >= 0.3 -- <http://mkottman.github.io/luacrypto/> +-- luaposix +-- <https://github.com/luaposix/luaposix> -- +local sysstat = require("posix.sys.stat") +local unistd = require("posix.unistd") +local crypto = require("crypto") -- @@ -31,11 +36,9 @@ local users = { bob = "ilikelua" } --- All cookies will be authenticated based on this secret. Make it something --- totally random and impossible to guess. It should be large. -local secret = "BE SURE TO CUSTOMIZE THIS STRING TO SOMETHING BIG AND RANDOM" - - +-- Set this to a path this script can write to for storing a persistent +-- cookie secret, which should be guarded. +local secret_filename = "/var/cache/cgit/auth-secret" -- -- @@ -191,7 +194,38 @@ end -- -- -local crypto = require("crypto") +local secret = nil + +-- Loads a secret from a file, creates a secret, or returns one from memory. +function get_secret() + if secret ~= nil then + return secret + end + local secret_file = io.open(secret_filename, "r") + if secret_file == nil then + local old_umask = sysstat.umask(63) + local temporary_filename = secret_filename .. ".tmp." .. crypto.hex(crypto.rand.bytes(16)) + local temporary_file = io.open(temporary_filename, "w") + if temporary_file == nil then + os.exit(177) + end + temporary_file:write(crypto.hex(crypto.rand.bytes(32))) + temporary_file:close() + unistd.link(temporary_filename, secret_filename) -- Intentionally fails in the case that another process is doing the same. + unistd.unlink(temporary_filename) + sysstat.umask(old_umask) + secret_file = io.open(secret_filename, "r") + end + if secret_file == nil then + os.exit(177) + end + secret = secret_file:read() + secret_file:close() + if secret:len() ~= 64 then + os.exit(177) + end + return secret +end -- Returns value of cookie if cookie is valid. Otherwise returns nil. function validate_value(expected_field, cookie) @@ -231,7 +265,7 @@ function validate_value(expected_field, cookie) end -- Lua hashes strings, so these comparisons are time invariant. - if hmac ~= crypto.hmac.digest("sha256", field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt, secret) then + if hmac ~= crypto.hmac.digest("sha256", field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt, get_secret()) then return nil end @@ -256,7 +290,7 @@ function secure_value(field, value, expiration) value = url_encode(value) field = url_encode(field) authstr = field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt - authstr = authstr .. "|" .. crypto.hmac.digest("sha256", authstr, secret) + authstr = authstr .. "|" .. crypto.hmac.digest("sha256", authstr, get_secret()) return authstr end From 82856923bffaac3ac88a90a797ddb33dcee8635a Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Sun, 15 Jul 2018 04:18:03 +0200 Subject: [PATCH 274/387] auth-filters: use crypt() in simple-authentication There's no use in giving a silly example to folks who will just copy it, so instead try to do something slightly better. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- filters/simple-authentication.lua | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/filters/simple-authentication.lua b/filters/simple-authentication.lua index bf35632..77d1fd0 100644 --- a/filters/simple-authentication.lua +++ b/filters/simple-authentication.lua @@ -23,17 +23,11 @@ local protected_repos = { qt = { jason = true, bob = true } } --- Please note that, in production, you'll want to replace this simple lookup --- table with either a table of salted and hashed passwords (using something --- smart like scrypt), or replace this table lookup with an external support, --- such as consulting your system's pam / shadow system, or an external --- database, or an external validating web service. For testing, or for --- extremely low-security usage, you may be able, however, to get away with --- compromising on hardcoding the passwords in cleartext, as we have done here. +-- A list of users and hashes, generated with `mkpasswd -m sha-512 -R 300000`. local users = { - jason = "secretpassword", - laurent = "s3cr3t", - bob = "ilikelua" + jason = "$6$rounds=300000$YYJct3n/o.ruYK$HhpSeuCuW1fJkpvMZOZzVizeLsBKcGA/aF2UPuV5v60JyH2MVSG6P511UMTj2F3H75.IT2HIlnvXzNb60FcZH1", + laurent = "$6$rounds=300000$dP0KNHwYb3JKigT$pN/LG7rWxQ4HniFtx5wKyJXBJUKP7R01zTNZ0qSK/aivw8ywGAOdfYiIQFqFhZFtVGvr11/7an.nesvm8iJUi.", + bob = "$6$rounds=300000$jCLCCt6LUpTz$PI1vvd1yaVYcCzqH8QAJFcJ60b6W/6sjcOsU7mAkNo7IE8FRGW1vkjF8I/T5jt/auv5ODLb1L4S2s.CAyZyUC" } -- Set this to a path this script can write to for storing a persistent @@ -48,7 +42,7 @@ local secret_filename = "/var/cache/cgit/auth-secret" -- Sets HTTP cookie headers based on post and sets up redirection. function authenticate_post() - local password = users[post["username"]] + local hash = users[post["username"]] local redirect = validate_value("redirect", post["redirect"]) if redirect == nil then @@ -58,8 +52,7 @@ function authenticate_post() redirect_to(redirect) - -- Lua hashes strings, so these comparisons are time invariant. - if password == nil or password ~= post["password"] then + if hash == nil or hash ~= unistd.crypt(post["password"], hash) then set_cookie("cgitauth", "") else -- One week expiration time From 77b6f833441dda1dd50f5a51a81036b1fde815d5 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Sun, 15 Jul 2018 04:45:11 +0200 Subject: [PATCH 275/387] auth-filters: add simple file-based authentication scheme Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- filters/file-authentication.lua | 352 ++++++++++++++++++++++++++++++++ 1 file changed, 352 insertions(+) create mode 100644 filters/file-authentication.lua diff --git a/filters/file-authentication.lua b/filters/file-authentication.lua new file mode 100644 index 0000000..6ee1e19 --- /dev/null +++ b/filters/file-authentication.lua @@ -0,0 +1,352 @@ +-- This script may be used with the auth-filter. +-- +-- Requirements: +-- luacrypto >= 0.3 +-- <http://mkottman.github.io/luacrypto/> +-- luaposix +-- <https://github.com/luaposix/luaposix> +-- +local sysstat = require("posix.sys.stat") +local unistd = require("posix.unistd") +local crypto = require("crypto") + + +-- This file should contain a series of lines in the form of: +-- username1:hash1 +-- username2:hash2 +-- username3:hash3 +-- ... +-- Hashes can be generated using something like `mkpasswd -m sha-512 -R 300000`. +-- This file should not be world-readable. +local users_filename = "/etc/cgit-auth/users" + +-- This file should contain a series of lines in the form of: +-- groupname1:username1,username2,username3,... +-- ... +local groups_filename = "/etc/cgit-auth/groups" + +-- This file should contain a series of lines in the form of: +-- reponame1:groupname1,groupname2,groupname3,... +-- ... +local repos_filename = "/etc/cgit-auth/repos" + +-- Set this to a path this script can write to for storing a persistent +-- cookie secret, which should not be world-readable. +local secret_filename = "/var/cache/cgit/auth-secret" + +-- +-- +-- Authentication functions follow below. Swap these out if you want different authentication semantics. +-- +-- + +-- Looks up a hash for a given user. +function lookup_hash(user) + local line + for line in io.lines(users_filename) do + local u, h = string.match(line, "(.-):(.+)") + if u:lower() == user:lower() then + return h + end + end + return nil +end + +-- Looks up users for a given repo. +function lookup_users(repo) + local users = nil + local groups = nil + local line, group, user + for line in io.lines(repos_filename) do + local r, g = string.match(line, "(.-):(.+)") + if r == repo then + groups = { } + for group in string.gmatch(g, "([^,]+)") do + groups[group:lower()] = true + end + break + end + end + if groups == nil then + return nil + end + for line in io.lines(groups_filename) do + local g, u = string.match(line, "(.-):(.+)") + if groups[g:lower()] then + if users == nil then + users = { } + end + for user in string.gmatch(u, "([^,]+)") do + users[user:lower()] = true + end + end + end + return users +end + + +-- Sets HTTP cookie headers based on post and sets up redirection. +function authenticate_post() + local hash = lookup_hash(post["username"]) + local redirect = validate_value("redirect", post["redirect"]) + + if redirect == nil then + not_found() + return 0 + end + + redirect_to(redirect) + + if hash == nil or hash ~= unistd.crypt(post["password"], hash) then + set_cookie("cgitauth", "") + else + -- One week expiration time + local username = secure_value("username", post["username"], os.time() + 604800) + set_cookie("cgitauth", username) + end + + html("\n") + return 0 +end + + +-- Returns 1 if the cookie is valid and 0 if it is not. +function authenticate_cookie() + accepted_users = lookup_users(cgit["repo"]) + if accepted_users == nil then + -- We return as valid if the repo is not protected. + return 1 + end + + local username = validate_value("username", get_cookie(http["cookie"], "cgitauth")) + if username == nil or not accepted_users[username:lower()] then + return 0 + else + return 1 + end +end + +-- Prints the html for the login form. +function body() + html("<h2>Authentication Required</h2>") + html("<form method='post' action='") + html_attr(cgit["login"]) + html("'>") + html("<input type='hidden' name='redirect' value='") + html_attr(secure_value("redirect", cgit["url"], 0)) + html("' />") + html("<table>") + html("<tr><td><label for='username'>Username:</label></td><td><input id='username' name='username' autofocus /></td></tr>") + html("<tr><td><label for='password'>Password:</label></td><td><input id='password' name='password' type='password' /></td></tr>") + html("<tr><td colspan='2'><input value='Login' type='submit' /></td></tr>") + html("</table></form>") + + return 0 +end + + + +-- +-- +-- Wrapper around filter API, exposing the http table, the cgit table, and the post table to the above functions. +-- +-- + +local actions = {} +actions["authenticate-post"] = authenticate_post +actions["authenticate-cookie"] = authenticate_cookie +actions["body"] = body + +function filter_open(...) + action = actions[select(1, ...)] + + http = {} + http["cookie"] = select(2, ...) + http["method"] = select(3, ...) + http["query"] = select(4, ...) + http["referer"] = select(5, ...) + http["path"] = select(6, ...) + http["host"] = select(7, ...) + http["https"] = select(8, ...) + + cgit = {} + cgit["repo"] = select(9, ...) + cgit["page"] = select(10, ...) + cgit["url"] = select(11, ...) + cgit["login"] = select(12, ...) + +end + +function filter_close() + return action() +end + +function filter_write(str) + post = parse_qs(str) +end + + +-- +-- +-- Utility functions based on keplerproject/wsapi. +-- +-- + +function url_decode(str) + if not str then + return "" + end + str = string.gsub(str, "+", " ") + str = string.gsub(str, "%%(%x%x)", function(h) return string.char(tonumber(h, 16)) end) + str = string.gsub(str, "\r\n", "\n") + return str +end + +function url_encode(str) + if not str then + return "" + end + str = string.gsub(str, "\n", "\r\n") + str = string.gsub(str, "([^%w ])", function(c) return string.format("%%%02X", string.byte(c)) end) + str = string.gsub(str, " ", "+") + return str +end + +function parse_qs(qs) + local tab = {} + for key, val in string.gmatch(qs, "([^&=]+)=([^&=]*)&?") do + tab[url_decode(key)] = url_decode(val) + end + return tab +end + +function get_cookie(cookies, name) + cookies = string.gsub(";" .. cookies .. ";", "%s*;%s*", ";") + return url_decode(string.match(cookies, ";" .. name .. "=(.-);")) +end + + +-- +-- +-- Cookie construction and validation helpers. +-- +-- + +local secret = nil + +-- Loads a secret from a file, creates a secret, or returns one from memory. +function get_secret() + if secret ~= nil then + return secret + end + local secret_file = io.open(secret_filename, "r") + if secret_file == nil then + local old_umask = sysstat.umask(63) + local temporary_filename = secret_filename .. ".tmp." .. crypto.hex(crypto.rand.bytes(16)) + local temporary_file = io.open(temporary_filename, "w") + if temporary_file == nil then + os.exit(177) + end + temporary_file:write(crypto.hex(crypto.rand.bytes(32))) + temporary_file:close() + unistd.link(temporary_filename, secret_filename) -- Intentionally fails in the case that another process is doing the same. + unistd.unlink(temporary_filename) + sysstat.umask(old_umask) + secret_file = io.open(secret_filename, "r") + end + if secret_file == nil then + os.exit(177) + end + secret = secret_file:read() + secret_file:close() + if secret:len() ~= 64 then + os.exit(177) + end + return secret +end + +-- Returns value of cookie if cookie is valid. Otherwise returns nil. +function validate_value(expected_field, cookie) + local i = 0 + local value = "" + local field = "" + local expiration = 0 + local salt = "" + local hmac = "" + + if cookie == nil or cookie:len() < 3 or cookie:sub(1, 1) == "|" then + return nil + end + + for component in string.gmatch(cookie, "[^|]+") do + if i == 0 then + field = component + elseif i == 1 then + value = component + elseif i == 2 then + expiration = tonumber(component) + if expiration == nil then + expiration = -1 + end + elseif i == 3 then + salt = component + elseif i == 4 then + hmac = component + else + break + end + i = i + 1 + end + + if hmac == nil or hmac:len() == 0 then + return nil + end + + -- Lua hashes strings, so these comparisons are time invariant. + if hmac ~= crypto.hmac.digest("sha256", field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt, get_secret()) then + return nil + end + + if expiration == -1 or (expiration ~= 0 and expiration <= os.time()) then + return nil + end + + if url_decode(field) ~= expected_field then + return nil + end + + return url_decode(value) +end + +function secure_value(field, value, expiration) + if value == nil or value:len() <= 0 then + return "" + end + + local authstr = "" + local salt = crypto.hex(crypto.rand.bytes(16)) + value = url_encode(value) + field = url_encode(field) + authstr = field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt + authstr = authstr .. "|" .. crypto.hmac.digest("sha256", authstr, get_secret()) + return authstr +end + +function set_cookie(cookie, value) + html("Set-Cookie: " .. cookie .. "=" .. value .. "; HttpOnly") + if http["https"] == "yes" or http["https"] == "on" or http["https"] == "1" then + html("; secure") + end + html("\n") +end + +function redirect_to(url) + html("Status: 302 Redirect\n") + html("Cache-Control: no-cache, no-store\n") + html("Location: " .. url .. "\n") +end + +function not_found() + html("Status: 404 Not Found\n") + html("Cache-Control: no-cache, no-store\n\n") +end From c679d9010451b986bae719a6abe0458af2b2dfb9 Mon Sep 17 00:00:00 2001 From: Konstantin Ryabitsev <konstantin@linuxfoundation.org> Date: Tue, 17 Jul 2018 12:38:22 -0400 Subject: [PATCH 276/387] config: record repo.snapshot-prefix in the per-repo config Even if we find snapshot-prefix in the repo configuration, we are not writing it out into the rc- file, so setting the value does not have any effect. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org> --- cgit.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cgit.c b/cgit.c index fda0aa4..6301b87 100644 --- a/cgit.c +++ b/cgit.c @@ -830,6 +830,8 @@ static void print_repo(FILE *f, struct cgit_repo *repo) fprintf(f, "repo.snapshots=%s\n", tmp ? tmp : ""); free(tmp); } + if (repo->snapshot_prefix) + fprintf(f, "repo.snapshot-prefix=%s\n", repo->snapshot_prefix); if (repo->max_stats != ctx.cfg.max_stats) fprintf(f, "repo.max-stats=%s\n", cgit_find_stats_periodname(repo->max_stats)); From 53efaf30b50f095cad8c160488c74bba3e3b2680 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Fri, 3 Aug 2018 15:46:11 +0200 Subject: [PATCH 277/387] clone: fix directory traversal This was introduced in the initial version of this code, way back when in 2008. $ curl http://127.0.0.1/cgit/repo/objects/?path=../../../../../../../../../etc/passwd root:x:0:0:root:/root:/bin/sh ... Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> Reported-by: Jann Horn <jannh@google.com> --- ui-clone.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/ui-clone.c b/ui-clone.c index 2c1ac3d..6ba8f36 100644 --- a/ui-clone.c +++ b/ui-clone.c @@ -92,17 +92,32 @@ void cgit_clone_info(void) void cgit_clone_objects(void) { - if (!ctx.qry.path) { - cgit_print_error_page(400, "Bad request", "Bad request"); - return; - } + char *p; + + if (!ctx.qry.path) + goto err; if (!strcmp(ctx.qry.path, "info/packs")) { print_pack_info(); return; } + /* Avoid directory traversal by forbidding "..", but also work around + * other funny business by just specifying a fairly strict format. For + * example, now we don't have to stress out about the Cygwin port. + */ + for (p = ctx.qry.path; *p; ++p) { + if (*p == '.' && *(p + 1) == '.') + goto err; + if (!isalnum(*p) && *p != '/' && *p != '.' && *p != '-') + goto err; + } + send_file(git_path("objects/%s", ctx.qry.path)); + return; + +err: + cgit_print_error_page(400, "Bad request", "Bad request"); } void cgit_clone_head(void) From 824138e59194acaf5efe53690d4ef6eaf38e1549 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Fri, 3 Aug 2018 16:26:14 +0200 Subject: [PATCH 278/387] Bump version. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 4082905..05ea71f 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ all:: -CGIT_VERSION = v1.2 +CGIT_VERSION = v1.2.1 CGIT_SCRIPT_NAME = cgit.cgi CGIT_SCRIPT_PATH = /var/www/htdocs/cgit CGIT_DATA_PATH = $(CGIT_SCRIPT_PATH) From b0fc647fe61c19338aec65ffcab513cc84599b18 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Fri, 13 Jul 2018 21:44:50 +0200 Subject: [PATCH 279/387] filters: generate anchor links from markdown This makes the markdown filter generate anchor links for headings. Signed-off-by: Christian Hesse <mail@eworm.de> Tested-by: jean-christophe manciot <actionmystique@gmail.com> --- filters/html-converters/md2html | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/filters/html-converters/md2html b/filters/html-converters/md2html index ebf3856..dc20f42 100755 --- a/filters/html-converters/md2html +++ b/filters/html-converters/md2html @@ -3,6 +3,7 @@ import markdown import sys import io from pygments.formatters import HtmlFormatter +from markdown.extensions.toc import TocExtension sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8') sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') sys.stdout.write(''' @@ -48,10 +49,14 @@ sys.stdout.write(''' line-height: 1; padding-left: 0; margin-left: -22px; - top: 15%} + top: 15%; +} .markdown-body h1:hover a.anchor .mini-icon-link, .markdown-body h2:hover a.anchor .mini-icon-link, .markdown-body h3:hover a.anchor .mini-icon-link, .markdown-body h4:hover a.anchor .mini-icon-link, .markdown-body h5:hover a.anchor .mini-icon-link, .markdown-body h6:hover a.anchor .mini-icon-link { display: inline-block; } +div#cgit .markdown-body h1 a.toclink, div#cgit .markdown-body h2 a.toclink, div#cgit .markdown-body h3 a.toclink, div#cgit .markdown-body h4 a.toclink, div#cgit .markdown-body h5 a.toclink, div#cgit .markdown-body h6 a.toclink { + color: black; +} .markdown-body h1 tt, .markdown-body h1 code, .markdown-body h2 tt, .markdown-body h2 code, .markdown-body h3 tt, .markdown-body h3 code, .markdown-body h4 tt, .markdown-body h4 code, .markdown-body h5 tt, .markdown-body h5 code, .markdown-body h6 tt, .markdown-body h6 code { font-size: inherit; } @@ -290,5 +295,13 @@ sys.stdout.write(''' sys.stdout.write("<div class='markdown-body'>") sys.stdout.flush() # Note: you may want to run this through bleach for sanitization -markdown.markdownFromFile(output_format="html5", extensions=["markdown.extensions.fenced_code", "markdown.extensions.codehilite", "markdown.extensions.tables"], extension_configs={"markdown.extensions.codehilite":{"css_class":"highlight"}}) +markdown.markdownFromFile( + output_format="html5", + extensions=[ + "markdown.extensions.fenced_code", + "markdown.extensions.codehilite", + "markdown.extensions.tables", + TocExtension(anchorlink=True)], + extension_configs={ + "markdown.extensions.codehilite":{"css_class":"highlight"}}) sys.stdout.write("</div>") From 7cde5885d8ce53359ee665bb930b1da956e8369a Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Tue, 28 Aug 2018 18:11:50 +0200 Subject: [PATCH 280/387] parsing: ban strncpy() Git upstream bans strncpy() with commit: banned.h: mark strncpy() as banned e488b7aba743d23b830d239dcc33d9ca0745a9ad Signed-off-by: Christian Hesse <mail@eworm.de> --- parsing.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/parsing.c b/parsing.c index 12453c2..e224564 100644 --- a/parsing.c +++ b/parsing.c @@ -63,8 +63,7 @@ static char *substr(const char *head, const char *tail) if (tail < head) return xstrdup(""); buf = xmalloc(tail - head + 1); - strncpy(buf, head, tail - head); - buf[tail - head] = '\0'; + strlcpy(buf, head, tail - head + 1); return buf; } From 60a930044d57faae4fcb84cba9d85310b0c767a7 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Tue, 28 Aug 2018 18:14:32 +0200 Subject: [PATCH 281/387] parsing: ban sprintf() Git upstream bans sprintf() with commit: banned.h: mark sprintf() as banned cc8fdaee1eeaf05d8dd55ff11f111b815f673c58 Signed-off-by: Christian Hesse <mail@eworm.de> --- parsing.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parsing.c b/parsing.c index e224564..9e73e70 100644 --- a/parsing.c +++ b/parsing.c @@ -77,7 +77,7 @@ static void parse_user(const char *t, char **name, char **email, unsigned long * email_len = ident.mail_end - ident.mail_begin; *email = xmalloc(strlen("<") + email_len + strlen(">") + 1); - sprintf(*email, "<%.*s>", email_len, ident.mail_begin); + xsnprintf(*email, email_len + 3, "<%.*s>", email_len, ident.mail_begin); if (ident.date_begin) *date = strtoul(ident.date_begin, NULL, 10); From 71ba7187e5eeeaf2f66bc27bc3b48a2014d37bb7 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Tue, 28 Aug 2018 18:08:33 +0200 Subject: [PATCH 282/387] ui-log: ban strcpy() Git upstream bans strcpy() with commit: automatically ban strcpy() c8af66ab8ad7cd78557f0f9f5ef6a52fd46ee6dd Signed-off-by: Christian Hesse <mail@eworm.de> --- ui-log.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui-log.c b/ui-log.c index d696e20..c2f92fe 100644 --- a/ui-log.c +++ b/ui-log.c @@ -234,7 +234,7 @@ static void print_commit(struct commit *commit, struct rev_info *revs) strbuf_add(&msgbuf, "\n\n", 2); /* Place wrap_symbol at position i in info->subject */ - strcpy(info->subject + i, wrap_symbol); + strlcpy(info->subject + i, wrap_symbol, subject_len - i + 1); } } cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head, From 7f75647b5565076b70d7c619df08e6c64dac9386 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Tue, 28 Aug 2018 18:16:11 +0200 Subject: [PATCH 283/387] ui-log: ban strncpy() Git upstream bans strncpy() with commit: banned.h: mark strncpy() as banned e488b7aba743d23b830d239dcc33d9ca0745a9ad Signed-off-by: Christian Hesse <mail@eworm.de> --- ui-log.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui-log.c b/ui-log.c index c2f92fe..3bcb657 100644 --- a/ui-log.c +++ b/ui-log.c @@ -67,7 +67,7 @@ void show_commit_decorations(struct commit *commit) while (deco) { struct object_id peeled; int is_annotated = 0; - strncpy(buf, prettify_refname(deco->name), sizeof(buf) - 1); + strlcpy(buf, prettify_refname(deco->name), sizeof(buf)); switch(deco->type) { case DECORATION_NONE: /* If the git-core doesn't recognize it, From edb3403f00f14ac5cc23b9ba3a122cb4ee8b81fa Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Tue, 28 Aug 2018 18:18:37 +0200 Subject: [PATCH 284/387] ui-patch: ban sprintf() Git upstream bans sprintf() with commit: banned.h: mark sprintf() as banned cc8fdaee1eeaf05d8dd55ff11f111b815f673c58 Signed-off-by: Christian Hesse <mail@eworm.de> --- ui-patch.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ui-patch.c b/ui-patch.c index 8007a11..82f125b 100644 --- a/ui-patch.c +++ b/ui-patch.c @@ -11,13 +11,16 @@ #include "html.h" #include "ui-shared.h" +/* two commit hashes with two dots in between and termination */ +#define REV_RANGE_LEN 2 * GIT_MAX_HEXSZ + 3 + void cgit_print_patch(const char *new_rev, const char *old_rev, const char *prefix) { struct rev_info rev; struct commit *commit; struct object_id new_rev_oid, old_rev_oid; - char rev_range[2 * 40 + 3]; + char rev_range[REV_RANGE_LEN]; const char *rev_argv[] = { NULL, "--reverse", "--format=email", rev_range, "--", prefix, NULL }; int rev_argc = ARRAY_SIZE(rev_argv) - 1; char *patchname; @@ -60,7 +63,7 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, if (is_null_oid(&old_rev_oid)) { memcpy(rev_range, oid_to_hex(&new_rev_oid), GIT_SHA1_HEXSZ + 1); } else { - sprintf(rev_range, "%s..%s", oid_to_hex(&old_rev_oid), + xsnprintf(rev_range, REV_RANGE_LEN, "%s..%s", oid_to_hex(&old_rev_oid), oid_to_hex(&new_rev_oid)); } From 2fc008d6dea2456548825c973a5516b5cdfd9c8c Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Tue, 28 Aug 2018 20:33:02 +0200 Subject: [PATCH 285/387] ui-shared: ban strcat() Git upstream bans strcat() with commit: banned.h: mark strcat() as banned 1b11b64b815db62f93a04242e4aed5687a448748 To avoid compiler warnings from gcc 8.1.x we get the hard way. Signed-off-by: Christian Hesse <mail@eworm.de> --- ui-shared.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ui-shared.c b/ui-shared.c index 739505a..b53c56d 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -1159,7 +1159,7 @@ void cgit_print_snapshot_links(const struct cgit_repo *repo, const char *ref, void cgit_set_title_from_path(const char *path) { - size_t path_len, path_index, path_last_end; + size_t path_len, path_index, path_last_end, line_len; char *new_title; if (!path) @@ -1176,14 +1176,18 @@ void cgit_set_title_from_path(const char *path) continue; } strncat(new_title, &path[path_index + 1], path_last_end - path_index - 1); - strcat(new_title, "\\"); + line_len = strlen(new_title); + new_title[line_len++] = '\\'; + new_title[line_len] = '\0'; path_last_end = path_index; } } if (path_last_end) strncat(new_title, path, path_last_end); - strcat(new_title, " - "); - strcat(new_title, ctx.page.title); + line_len = strlen(new_title); + memcpy(&new_title[line_len], " - ", 3); + new_title[line_len + 3] = '\0'; + strncat(new_title, ctx.page.title, sizeof(new_title) - strlen(new_title) - 1); ctx.page.title = new_title; } From 0899eb644fab415e9a3b304f53da9da50aaf91aa Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Tue, 28 Aug 2018 18:22:26 +0200 Subject: [PATCH 286/387] ui-ssdiff: ban strncpy() Git upstream bans strncpy() with commit: banned.h: mark strncpy() as banned e488b7aba743d23b830d239dcc33d9ca0745a9ad Signed-off-by: Christian Hesse <mail@eworm.de> --- ui-ssdiff.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ui-ssdiff.c b/ui-ssdiff.c index 68c2044..a3dd059 100644 --- a/ui-ssdiff.c +++ b/ui-ssdiff.c @@ -103,8 +103,7 @@ static int line_from_hunk(char *line, char type) return 0; len = buf2 - buf1; buf2 = xmalloc(len + 1); - strncpy(buf2, buf1, len); - buf2[len] = '\0'; + strlcpy(buf2, buf1, len + 1); res = atoi(buf2); free(buf2); return res; From a96f2890f41e0b9b0ffa1bcdb1dddbef28c01662 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Tue, 28 Aug 2018 18:23:36 +0200 Subject: [PATCH 287/387] ui-ssdiff: ban strcat() Git upstream bans strcat() with commit: banned.h: mark strcat() as banned 1b11b64b815db62f93a04242e4aed5687a448748 Signed-off-by: Christian Hesse <mail@eworm.de> --- ui-ssdiff.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ui-ssdiff.c b/ui-ssdiff.c index a3dd059..c456033 100644 --- a/ui-ssdiff.c +++ b/ui-ssdiff.c @@ -117,6 +117,7 @@ static char *replace_tabs(char *line) int n_tabs = 0; int i; char *result; + int result_len; if (linelen == 0) { result = xmalloc(1); @@ -128,13 +129,14 @@ static char *replace_tabs(char *line) if (line[i] == '\t') n_tabs += 1; } - result = xmalloc(linelen + n_tabs * 8 + 1); + result_len = linelen + n_tabs * 8; + result = xmalloc(result_len + 1); result[0] = '\0'; for (;;) { cur_buf = strchr(prev_buf, '\t'); if (!cur_buf) { - strcat(result, prev_buf); + strncat(result, prev_buf, result_len); break; } else { strncat(result, prev_buf, cur_buf - prev_buf); From 2c9f56f3e1c754f60ccffbc6c745b9d5a81ea005 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Tue, 28 Aug 2018 18:27:00 +0200 Subject: [PATCH 288/387] git: update to v2.19.1 Update to git version v2.19.1. Required changes follow upstream commits: * commit: add repository argument to get_cached_commit_buffer (3ce85f7e5a41116145179f0fae2ce6d86558d099) * commit: add repository argument to lookup_commit_reference (2122f6754c93be8f02bfb5704ed96c88fc9837a8) * object: add repository argument to parse_object (109cd76dd3467bd05f8d2145b857006649741d5c) * tag: add repository argument to deref_tag (a74093da5ed601a09fa158e5ba6f6f14c1142a3e) * tag: add repository argument to lookup_tag (ce71efb713f97f476a2d2ab541a0c73f684a5db3) * tree: add repository argument to lookup_tree (f86bcc7b2ce6cad68ba1a48a528e380c6126705e) * archive.c: avoid access to the_index (b612ee202a48f129f81f8f6a5af6cf71d1a9caef) * for_each_*_object: move declarations to object-store.h (0889aae1cd18c1804ba01c1a4229e516dfb9fe9b) Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- cgit.h | 1 + git | 2 +- parsing.c | 2 +- shared.c | 2 +- ui-blame.c | 2 +- ui-blob.c | 6 +++--- ui-clone.c | 4 ++-- ui-commit.c | 4 ++-- ui-diff.c | 4 ++-- ui-patch.c | 4 ++-- ui-plain.c | 2 +- ui-snapshot.c | 4 ++-- ui-tag.c | 4 ++-- ui-tree.c | 4 ++-- 15 files changed, 24 insertions(+), 23 deletions(-) diff --git a/Makefile b/Makefile index 05ea71f..1c49b50 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.18.0 +GIT_VER = 2.19.1 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.gz INSTALL = install COPYTREE = cp -r diff --git a/cgit.h b/cgit.h index 32dfd7a..bcc4fce 100644 --- a/cgit.h +++ b/cgit.h @@ -8,6 +8,7 @@ #include <cache.h> #include <grep.h> #include <object.h> +#include <object-store.h> #include <tree.h> #include <commit.h> #include <tag.h> diff --git a/git b/git index 53f9a3e..cae598d 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 53f9a3e157dbbc901a02ac2c73346d375e24978c +Subproject commit cae598d9980661a978e2df4fb338518f7bf09572 diff --git a/parsing.c b/parsing.c index 9e73e70..7b3980e 100644 --- a/parsing.c +++ b/parsing.c @@ -129,7 +129,7 @@ struct commitinfo *cgit_parse_commit(struct commit *commit) { const int sha1hex_len = 40; struct commitinfo *ret; - const char *p = get_cached_commit_buffer(commit, NULL); + const char *p = get_cached_commit_buffer(the_repository, commit, NULL); const char *t; ret = xcalloc(1, sizeof(struct commitinfo)); diff --git a/shared.c b/shared.c index 609bd2a..7560f5f 100644 --- a/shared.c +++ b/shared.c @@ -161,7 +161,7 @@ static struct refinfo *cgit_mk_refinfo(const char *refname, const struct object_ ref = xmalloc(sizeof (struct refinfo)); ref->refname = xstrdup(refname); - ref->object = parse_object(oid); + ref->object = parse_object(the_repository, oid); switch (ref->object->type) { case OBJ_TAG: ref->tag = cgit_parse_tag((struct tag *)ref->object); diff --git a/ui-blame.c b/ui-blame.c index 50d0580..6dc555f 100644 --- a/ui-blame.c +++ b/ui-blame.c @@ -278,7 +278,7 @@ void cgit_print_blame(void) "Invalid revision name: %s", rev); return; } - commit = lookup_commit_reference(&oid); + commit = lookup_commit_reference(the_repository, &oid); if (!commit || parse_commit(commit)) { cgit_print_error_page(404, "Not found", "Invalid commit reference: %s", rev); diff --git a/ui-blob.c b/ui-blob.c index 7b6da2a..4b6b462 100644 --- a/ui-blob.c +++ b/ui-blob.c @@ -56,7 +56,7 @@ int cgit_ref_path_exists(const char *path, const char *ref, int file_only) goto done; if (oid_object_info(the_repository, &oid, &size) != OBJ_COMMIT) goto done; - read_tree_recursive(lookup_commit_reference(&oid)->maybe_tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); + read_tree_recursive(lookup_commit_reference(the_repository, &oid)->maybe_tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); done: free(path_items.match); @@ -89,7 +89,7 @@ int cgit_print_file(char *path, const char *head, int file_only) return -1; type = oid_object_info(the_repository, &oid, &size); if (type == OBJ_COMMIT) { - commit = lookup_commit_reference(&oid); + commit = lookup_commit_reference(the_repository, &oid); read_tree_recursive(commit->maybe_tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); if (!walk_tree_ctx.found_path) return -1; @@ -145,7 +145,7 @@ void cgit_print_blob(const char *hex, char *path, const char *head, int file_onl type = oid_object_info(the_repository, &oid, &size); if ((!hex) && type == OBJ_COMMIT && path) { - commit = lookup_commit_reference(&oid); + commit = lookup_commit_reference(the_repository, &oid); read_tree_recursive(commit->maybe_tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); type = oid_object_info(the_repository, &oid, &size); } diff --git a/ui-clone.c b/ui-clone.c index 6ba8f36..5dccb63 100644 --- a/ui-clone.c +++ b/ui-clone.c @@ -19,12 +19,12 @@ static int print_ref_info(const char *refname, const struct object_id *oid, { struct object *obj; - if (!(obj = parse_object(oid))) + if (!(obj = parse_object(the_repository, oid))) return 0; htmlf("%s\t%s\n", oid_to_hex(oid), refname); if (obj->type == OBJ_TAG) { - if (!(obj = deref_tag(obj, refname, 0))) + if (!(obj = deref_tag(the_repository, obj, refname, 0))) return 0; htmlf("%s\t%s^{}\n", oid_to_hex(&obj->oid), refname); } diff --git a/ui-commit.c b/ui-commit.c index 995cb93..9a47b54 100644 --- a/ui-commit.c +++ b/ui-commit.c @@ -31,7 +31,7 @@ void cgit_print_commit(char *hex, const char *prefix) "Bad object id: %s", hex); return; } - commit = lookup_commit_reference(&oid); + commit = lookup_commit_reference(the_repository, &oid); if (!commit) { cgit_print_error_page(404, "Not found", "Bad commit reference: %s", hex); @@ -87,7 +87,7 @@ void cgit_print_commit(char *hex, const char *prefix) free(tmp); html("</td></tr>\n"); for (p = commit->parents; p; p = p->next) { - parent = lookup_commit_reference(&p->item->object.oid); + parent = lookup_commit_reference(the_repository, &p->item->object.oid); if (!parent) { html("<tr><td colspan='3'>"); cgit_print_error("Error reading parent commit"); diff --git a/ui-diff.c b/ui-diff.c index e33e9fb..70dcc91 100644 --- a/ui-diff.c +++ b/ui-diff.c @@ -407,7 +407,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, "Bad object name: %s", new_rev); return; } - commit = lookup_commit_reference(new_rev_oid); + commit = lookup_commit_reference(the_repository, new_rev_oid); if (!commit || parse_commit(commit)) { cgit_print_error_page(404, "Not found", "Bad commit: %s", oid_to_hex(new_rev_oid)); @@ -428,7 +428,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, } if (!is_null_oid(old_rev_oid)) { - commit2 = lookup_commit_reference(old_rev_oid); + commit2 = lookup_commit_reference(the_repository, old_rev_oid); if (!commit2 || parse_commit(commit2)) { cgit_print_error_page(404, "Not found", "Bad commit: %s", oid_to_hex(old_rev_oid)); diff --git a/ui-patch.c b/ui-patch.c index 82f125b..5a96410 100644 --- a/ui-patch.c +++ b/ui-patch.c @@ -36,7 +36,7 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, "Bad object id: %s", new_rev); return; } - commit = lookup_commit_reference(&new_rev_oid); + commit = lookup_commit_reference(the_repository, &new_rev_oid); if (!commit) { cgit_print_error_page(404, "Not found", "Bad commit reference: %s", new_rev); @@ -49,7 +49,7 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, "Bad object id: %s", old_rev); return; } - if (!lookup_commit_reference(&old_rev_oid)) { + if (!lookup_commit_reference(the_repository, &old_rev_oid)) { cgit_print_error_page(404, "Not found", "Bad commit reference: %s", old_rev); return; diff --git a/ui-plain.c b/ui-plain.c index ddb3e48..070c34b 100644 --- a/ui-plain.c +++ b/ui-plain.c @@ -185,7 +185,7 @@ void cgit_print_plain(void) cgit_print_error_page(404, "Not found", "Not found"); return; } - commit = lookup_commit_reference(&oid); + commit = lookup_commit_reference(the_repository, &oid); if (!commit || parse_commit(commit)) { cgit_print_error_page(404, "Not found", "Not found"); return; diff --git a/ui-snapshot.c b/ui-snapshot.c index fa3ceaf..85efe64 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c @@ -37,7 +37,7 @@ static int write_archive_type(const char *format, const char *hex, const char *p /* argv_array guarantees a trailing NULL entry. */ memcpy(nargv, argv.argv, sizeof(char *) * (argv.argc + 1)); - result = write_archive(argv.argc, nargv, NULL, NULL, 0); + result = write_archive(argv.argc, nargv, NULL, the_repository, NULL, 0); argv_array_clear(&argv); free(nargv); return result; @@ -147,7 +147,7 @@ static int make_snapshot(const struct cgit_snapshot_format *format, "Bad object id: %s", hex); return 1; } - if (!lookup_commit_reference(&oid)) { + if (!lookup_commit_reference(the_repository, &oid)) { cgit_print_error_page(400, "Bad request", "Not a commit reference: %s", hex); return 1; diff --git a/ui-tag.c b/ui-tag.c index 2c96c37..f530224 100644 --- a/ui-tag.c +++ b/ui-tag.c @@ -53,7 +53,7 @@ void cgit_print_tag(char *revname) "Bad tag reference: %s", revname); goto cleanup; } - obj = parse_object(&oid); + obj = parse_object(the_repository, &oid); if (!obj) { cgit_print_error_page(500, "Internal server error", "Bad object id: %s", oid_to_hex(&oid)); @@ -63,7 +63,7 @@ void cgit_print_tag(char *revname) struct tag *tag; struct taginfo *info; - tag = lookup_tag(&oid); + tag = lookup_tag(the_repository, &oid); if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) { cgit_print_error_page(500, "Internal server error", "Bad tag object: %s", revname); diff --git a/ui-tree.c b/ui-tree.c index e6b3074..df8ad82 100644 --- a/ui-tree.c +++ b/ui-tree.c @@ -177,7 +177,7 @@ static void write_tree_link(const struct object_id *oid, char *name, cgit_tree_link(name, NULL, "ls-dir", ctx.qry.head, rev, fullpath->buf); - tree = lookup_tree(&tree_ctx.oid); + tree = lookup_tree(the_repository, &tree_ctx.oid); if (!tree) return; @@ -359,7 +359,7 @@ void cgit_print_tree(const char *rev, char *path) "Invalid revision name: %s", rev); return; } - commit = lookup_commit_reference(&oid); + commit = lookup_commit_reference(the_repository, &oid); if (!commit || parse_commit(commit)) { cgit_print_error_page(404, "Not found", "Invalid commit reference: %s", rev); From a22855747e97e55a7b7a2622fe671b8ca9af0981 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Tue, 20 Nov 2018 23:55:03 +0100 Subject: [PATCH 289/387] git: use xz compressed archive for download Upstream will stop providing gz compressed source tarballs [0], so stop using them. [0] https://lists.zx2c4.com/pipermail/cgit/2018-November/004254.html Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 1c49b50..4aaf2dc 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> GIT_VER = 2.19.1 -GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.gz +GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r MAN5_TXT = $(wildcard *.5.txt) @@ -157,7 +157,7 @@ clean-doc: $(RM) cgitrc.5 cgitrc.5.html cgitrc.5.pdf cgitrc.5.xml cgitrc.5.fo get-git: - curl -L $(GIT_URL) | tar -xzf - && rm -rf git && mv git-$(GIT_VER) git + curl -L $(GIT_URL) | tar -xJf - && rm -rf git && mv git-$(GIT_VER) git tags: $(QUIET_TAGS)find . -name '*.[ch]' | xargs ctags From 898b9e19e0eacd67456ddcc91ff173055e1c0e99 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Wed, 21 Nov 2018 03:16:11 +0100 Subject: [PATCH 290/387] auth-filter: pass url with query string attached Otherwise redirections come out wrong. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- cgit.c | 2 +- ui-shared.c | 37 +++++++++++++++++++++++++++++++++++-- ui-shared.h | 1 + 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/cgit.c b/cgit.c index 6301b87..2f07e6d 100644 --- a/cgit.c +++ b/cgit.c @@ -645,7 +645,7 @@ static inline void open_auth_filter(const char *function) ctx.env.https ? ctx.env.https : "", ctx.qry.repo ? ctx.qry.repo : "", ctx.qry.page ? ctx.qry.page : "", - ctx.qry.url ? ctx.qry.url : "", + cgit_currentfullurl(), cgit_loginurl()); } diff --git a/ui-shared.c b/ui-shared.c index b53c56d..7a4c726 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -68,15 +68,48 @@ char *cgit_hosturl(void) char *cgit_currenturl(void) { const char *root = cgit_rooturl(); - size_t len = strlen(root); if (!ctx.qry.url) return xstrdup(root); - if (len && root[len - 1] == '/') + if (root[0] && root[strlen(root) - 1] == '/') return fmtalloc("%s%s", root, ctx.qry.url); return fmtalloc("%s/%s", root, ctx.qry.url); } +char *cgit_currentfullurl(void) +{ + const char *root = cgit_rooturl(); + const char *orig_query = ctx.env.query_string ? ctx.env.query_string : ""; + size_t len = strlen(orig_query); + char *query = xmalloc(len + 2), *start_url, *ret; + + /* Remove all url=... parts from query string */ + memcpy(query + 1, orig_query, len + 1); + query[0] = '?'; + start_url = query; + while ((start_url = strstr(start_url, "url=")) != NULL) { + if (start_url[-1] == '?' || start_url[-1] == '&') { + const char *end_url = strchr(start_url, '&'); + if (end_url) + memmove(start_url, end_url + 1, strlen(end_url)); + else + start_url[0] = '\0'; + } else + ++start_url; + } + if (!query[1]) + query[0] = '\0'; + + if (!ctx.qry.url) + ret = fmtalloc("%s%s", root, query); + else if (root[0] && root[strlen(root) - 1] == '/') + ret = fmtalloc("%s%s%s", root, ctx.qry.url, query); + else + ret = fmtalloc("%s/%s%s", root, ctx.qry.url, query); + free(query); + return ret; +} + const char *cgit_rooturl(void) { if (ctx.cfg.virtual_root) diff --git a/ui-shared.h b/ui-shared.h index 4d5978b..6964873 100644 --- a/ui-shared.h +++ b/ui-shared.h @@ -5,6 +5,7 @@ extern const char *cgit_httpscheme(void); extern char *cgit_hosturl(void); extern const char *cgit_rooturl(void); extern char *cgit_currenturl(void); +extern char *cgit_currentfullurl(void); extern const char *cgit_loginurl(void); extern char *cgit_repourl(const char *reponame); extern char *cgit_fileurl(const char *reponame, const char *pagename, From 441dac1d747dab43e3559ee68f18a273512064cd Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Thu, 22 Nov 2018 01:49:55 +0100 Subject: [PATCH 291/387] ui-blame: set repo for sb Otherwise recent git complains and crashes with: "BUG: blame.c:1787: repo is NULL". Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- ui-blame.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ui-blame.c b/ui-blame.c index 6dc555f..c52cb9b 100644 --- a/ui-blame.c +++ b/ui-blame.c @@ -131,6 +131,7 @@ static void print_object(const struct object_id *oid, const char *path, setup_revisions(rev_argv.argc, rev_argv.argv, &revs, NULL); init_scoreboard(&sb); sb.revs = &revs; + sb.repo = the_repository; setup_scoreboard(&sb, path, &o); o->suspects = blame_entry_prepend(NULL, 0, sb.num_lines, o); prio_queue_put(&sb.commits, o->commit); From 55ebd5e97ccd0da9424d68f1e0f301551cf4b47a Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Tue, 20 Nov 2018 17:31:21 +0100 Subject: [PATCH 292/387] git: update to v2.20.0 Update to git version v2.20.0. Required changes follow upstream commits: * 00436bf1b1c2a8fe6cf5d2c2457d419d683042f4 (archive: initialize archivers earlier) * 611e42a5980a3a9f8bb3b1b49c1abde63c7a191e (xdiff: provide a separate emit callback for hunks) Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- shared.c | 2 +- ui-snapshot.c | 1 + 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 4aaf2dc..e690c7f 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.19.1 +GIT_VER = 2.20.0 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index cae598d..5d826e9 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit cae598d9980661a978e2df4fb338518f7bf09572 +Subproject commit 5d826e972970a784bd7a7bdf587512510097b8c7 diff --git a/shared.c b/shared.c index 7560f5f..a2c0d03 100644 --- a/shared.c +++ b/shared.c @@ -325,7 +325,7 @@ int cgit_diff_files(const struct object_id *old_oid, diff_params.flags |= XDF_IGNORE_WHITESPACE; emit_params.ctxlen = context > 0 ? context : 3; emit_params.flags = XDL_EMIT_FUNCNAMES; - emit_cb.outf = filediff_cb; + emit_cb.out_line = filediff_cb; emit_cb.priv = fn; xdl_diff(&file1, &file2, &diff_params, &emit_params, &emit_cb); if (file1.size) diff --git a/ui-snapshot.c b/ui-snapshot.c index 85efe64..9461d51 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c @@ -156,6 +156,7 @@ static int make_snapshot(const struct cgit_snapshot_format *format, ctx.page.mimetype = xstrdup(format->mimetype); ctx.page.filename = xstrdup(filename); cgit_print_http_headers(); + init_archivers(); format->write_func(hex, prefix); return 0; } From e23f63461f17aeb770d47d9c3134414e549d1f0e Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Wed, 2 Jan 2019 07:52:12 +0100 Subject: [PATCH 293/387] ui-shared: fix broken sizeof in title setting and rewrite MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The old algorithm was totally incorrect. While we're at it, use « instead of \, since it makes more sense. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- ui-shared.c | 34 ++++++++-------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/ui-shared.c b/ui-shared.c index 7a4c726..d27a5fd 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -1192,35 +1192,17 @@ void cgit_print_snapshot_links(const struct cgit_repo *repo, const char *ref, void cgit_set_title_from_path(const char *path) { - size_t path_len, path_index, path_last_end, line_len; - char *new_title; + struct strbuf sb = STRBUF_INIT; + const char *slash, *last_slash; if (!path) return; - path_len = strlen(path); - new_title = xmalloc(path_len + 3 + strlen(ctx.page.title) + 1); - new_title[0] = '\0'; - - for (path_index = path_len, path_last_end = path_len; path_index-- > 0;) { - if (path[path_index] == '/') { - if (path_index == path_len - 1) { - path_last_end = path_index - 1; - continue; - } - strncat(new_title, &path[path_index + 1], path_last_end - path_index - 1); - line_len = strlen(new_title); - new_title[line_len++] = '\\'; - new_title[line_len] = '\0'; - path_last_end = path_index; - } + for (last_slash = path + strlen(path); (slash = memrchr(path, '/', last_slash - path)) != NULL; last_slash = slash) { + strbuf_add(&sb, slash + 1, last_slash - slash - 1); + strbuf_addstr(&sb, " \xc2\xab "); } - if (path_last_end) - strncat(new_title, path, path_last_end); - - line_len = strlen(new_title); - memcpy(&new_title[line_len], " - ", 3); - new_title[line_len + 3] = '\0'; - strncat(new_title, ctx.page.title, sizeof(new_title) - strlen(new_title) - 1); - ctx.page.title = new_title; + strbuf_add(&sb, path, last_slash - path); + strbuf_addf(&sb, " - %s", ctx.page.title); + ctx.page.title = strbuf_detach(&sb, NULL); } From 7d87cd3a215976a480b3c71b017a191597e5cb44 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Thu, 3 Jan 2019 02:11:14 +0100 Subject: [PATCH 294/387] filters: migrate from luacrypto to luaossl luaossl has no upstream anymore and doesn't support OpenSSL 1.1, whereas luaossl is quite active. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- filters/email-gravatar.lua | 17 ++++++++++---- filters/email-libravatar.lua | 17 ++++++++++---- filters/file-authentication.lua | 31 ++++++++++++++++---------- filters/gentoo-ldap-authentication.lua | 31 ++++++++++++++++---------- filters/simple-authentication.lua | 31 ++++++++++++++++---------- 5 files changed, 83 insertions(+), 44 deletions(-) diff --git a/filters/email-gravatar.lua b/filters/email-gravatar.lua index 52cf426..c39b490 100644 --- a/filters/email-gravatar.lua +++ b/filters/email-gravatar.lua @@ -3,15 +3,24 @@ -- prefix in filters. It is much faster than the corresponding python script. -- -- Requirements: --- luacrypto >= 0.3 --- <http://mkottman.github.io/luacrypto/> +-- luaossl +-- <http://25thandclement.com/~william/projects/luaossl.html> -- -local crypto = require("crypto") +local digest = require("openssl.digest") + +function md5_hex(input) + local b = digest.new("md5"):final(input) + local x = "" + for i = 1, #b do + x = x .. string.format("%.2x", string.byte(b, i)) + end + return x +end function filter_open(email, page) buffer = "" - md5 = crypto.digest("md5", email:sub(2, -2):lower()) + md5 = md5_hex(email:sub(2, -2):lower()) end function filter_close() diff --git a/filters/email-libravatar.lua b/filters/email-libravatar.lua index b0e2447..7336baf 100644 --- a/filters/email-libravatar.lua +++ b/filters/email-libravatar.lua @@ -3,15 +3,24 @@ -- prefix in filters. -- -- Requirements: --- luacrypto >= 0.3 --- <http://mkottman.github.io/luacrypto/> +-- luaossl +-- <http://25thandclement.com/~william/projects/luaossl.html> -- -local crypto = require("crypto") +local digest = require("openssl.digest") + +function md5_hex(input) + local b = digest.new("md5"):final(input) + local x = "" + for i = 1, #b do + x = x .. string.format("%.2x", string.byte(b, i)) + end + return x +end function filter_open(email, page) buffer = "" - md5 = crypto.digest("md5", email:sub(2, -2):lower()) + md5 = md5_hex(email:sub(2, -2):lower()) end function filter_close() diff --git a/filters/file-authentication.lua b/filters/file-authentication.lua index 6ee1e19..0248804 100644 --- a/filters/file-authentication.lua +++ b/filters/file-authentication.lua @@ -1,15 +1,15 @@ -- This script may be used with the auth-filter. -- -- Requirements: --- luacrypto >= 0.3 --- <http://mkottman.github.io/luacrypto/> +-- luaossl +-- <http://25thandclement.com/~william/projects/luaossl.html> -- luaposix -- <https://github.com/luaposix/luaposix> -- local sysstat = require("posix.sys.stat") local unistd = require("posix.unistd") -local crypto = require("crypto") - +local rand = require("openssl.rand") +local hmac = require("openssl.hmac") -- This file should contain a series of lines in the form of: -- username1:hash1 @@ -225,6 +225,13 @@ function get_cookie(cookies, name) return url_decode(string.match(cookies, ";" .. name .. "=(.-);")) end +function tohex(b) + local x = "" + for i = 1, #b do + x = x .. string.format("%.2x", string.byte(b, i)) + end + return x +end -- -- @@ -242,12 +249,12 @@ function get_secret() local secret_file = io.open(secret_filename, "r") if secret_file == nil then local old_umask = sysstat.umask(63) - local temporary_filename = secret_filename .. ".tmp." .. crypto.hex(crypto.rand.bytes(16)) + local temporary_filename = secret_filename .. ".tmp." .. tohex(rand.bytes(16)) local temporary_file = io.open(temporary_filename, "w") if temporary_file == nil then os.exit(177) end - temporary_file:write(crypto.hex(crypto.rand.bytes(32))) + temporary_file:write(tohex(rand.bytes(32))) temporary_file:close() unistd.link(temporary_filename, secret_filename) -- Intentionally fails in the case that another process is doing the same. unistd.unlink(temporary_filename) @@ -272,7 +279,7 @@ function validate_value(expected_field, cookie) local field = "" local expiration = 0 local salt = "" - local hmac = "" + local chmac = "" if cookie == nil or cookie:len() < 3 or cookie:sub(1, 1) == "|" then return nil @@ -291,19 +298,19 @@ function validate_value(expected_field, cookie) elseif i == 3 then salt = component elseif i == 4 then - hmac = component + chmac = component else break end i = i + 1 end - if hmac == nil or hmac:len() == 0 then + if chmac == nil or chmac:len() == 0 then return nil end -- Lua hashes strings, so these comparisons are time invariant. - if hmac ~= crypto.hmac.digest("sha256", field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt, get_secret()) then + if chmac ~= tohex(hmac.new(get_secret(), "sha256"):final(field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt)) then return nil end @@ -324,11 +331,11 @@ function secure_value(field, value, expiration) end local authstr = "" - local salt = crypto.hex(crypto.rand.bytes(16)) + local salt = tohex(rand.bytes(16)) value = url_encode(value) field = url_encode(field) authstr = field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt - authstr = authstr .. "|" .. crypto.hmac.digest("sha256", authstr, get_secret()) + authstr = authstr .. "|" .. tohex(hmac.new(get_secret(), "sha256"):final(authstr)) return authstr end diff --git a/filters/gentoo-ldap-authentication.lua b/filters/gentoo-ldap-authentication.lua index b4d98c2..673c88d 100644 --- a/filters/gentoo-ldap-authentication.lua +++ b/filters/gentoo-ldap-authentication.lua @@ -1,8 +1,8 @@ -- This script may be used with the auth-filter. Be sure to configure it as you wish. -- -- Requirements: --- luacrypto >= 0.3 --- <http://mkottman.github.io/luacrypto/> +-- luaossl +-- <http://25thandclement.com/~william/projects/luaossl.html> -- lualdap >= 1.2 -- <https://git.zx2c4.com/lualdap/about/> -- luaposix @@ -10,9 +10,9 @@ -- local sysstat = require("posix.sys.stat") local unistd = require("posix.unistd") -local crypto = require("crypto") local lualdap = require("lualdap") - +local rand = require("openssl.rand") +local hmac = require("openssl.hmac") -- -- @@ -226,6 +226,13 @@ function get_cookie(cookies, name) return string.match(cookies, ";" .. name .. "=(.-);") end +function tohex(b) + local x = "" + for i = 1, #b do + x = x .. string.format("%.2x", string.byte(b, i)) + end + return x +end -- -- @@ -243,12 +250,12 @@ function get_secret() local secret_file = io.open(secret_filename, "r") if secret_file == nil then local old_umask = sysstat.umask(63) - local temporary_filename = secret_filename .. ".tmp." .. crypto.hex(crypto.rand.bytes(16)) + local temporary_filename = secret_filename .. ".tmp." .. tohex(rand.bytes(16)) local temporary_file = io.open(temporary_filename, "w") if temporary_file == nil then os.exit(177) end - temporary_file:write(crypto.hex(crypto.rand.bytes(32))) + temporary_file:write(tohex(rand.bytes(32))) temporary_file:close() unistd.link(temporary_filename, secret_filename) -- Intentionally fails in the case that another process is doing the same. unistd.unlink(temporary_filename) @@ -273,7 +280,7 @@ function validate_value(expected_field, cookie) local field = "" local expiration = 0 local salt = "" - local hmac = "" + local chmac = "" if cookie == nil or cookie:len() < 3 or cookie:sub(1, 1) == "|" then return nil @@ -292,19 +299,19 @@ function validate_value(expected_field, cookie) elseif i == 3 then salt = component elseif i == 4 then - hmac = component + chmac = component else break end i = i + 1 end - if hmac == nil or hmac:len() == 0 then + if chmac == nil or chmac:len() == 0 then return nil end -- Lua hashes strings, so these comparisons are time invariant. - if hmac ~= crypto.hmac.digest("sha256", field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt, get_secret()) then + if chmac ~= tohex(hmac.new(get_secret(), "sha256"):final(field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt)) then return nil end @@ -325,11 +332,11 @@ function secure_value(field, value, expiration) end local authstr = "" - local salt = crypto.hex(crypto.rand.bytes(16)) + local salt = tohex(rand.bytes(16)) value = url_encode(value) field = url_encode(field) authstr = field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt - authstr = authstr .. "|" .. crypto.hmac.digest("sha256", authstr, get_secret()) + authstr = authstr .. "|" .. tohex(hmac.new(get_secret(), "sha256"):final(authstr)) return authstr end diff --git a/filters/simple-authentication.lua b/filters/simple-authentication.lua index 77d1fd0..23d3457 100644 --- a/filters/simple-authentication.lua +++ b/filters/simple-authentication.lua @@ -1,15 +1,15 @@ -- This script may be used with the auth-filter. Be sure to configure it as you wish. -- -- Requirements: --- luacrypto >= 0.3 --- <http://mkottman.github.io/luacrypto/> +-- luaossl +-- <http://25thandclement.com/~william/projects/luaossl.html> -- luaposix -- <https://github.com/luaposix/luaposix> -- local sysstat = require("posix.sys.stat") local unistd = require("posix.unistd") -local crypto = require("crypto") - +local rand = require("openssl.rand") +local hmac = require("openssl.hmac") -- -- @@ -180,6 +180,13 @@ function get_cookie(cookies, name) return url_decode(string.match(cookies, ";" .. name .. "=(.-);")) end +function tohex(b) + local x = "" + for i = 1, #b do + x = x .. string.format("%.2x", string.byte(b, i)) + end + return x +end -- -- @@ -197,12 +204,12 @@ function get_secret() local secret_file = io.open(secret_filename, "r") if secret_file == nil then local old_umask = sysstat.umask(63) - local temporary_filename = secret_filename .. ".tmp." .. crypto.hex(crypto.rand.bytes(16)) + local temporary_filename = secret_filename .. ".tmp." .. tohex(rand.bytes(16)) local temporary_file = io.open(temporary_filename, "w") if temporary_file == nil then os.exit(177) end - temporary_file:write(crypto.hex(crypto.rand.bytes(32))) + temporary_file:write(tohex(rand.bytes(32))) temporary_file:close() unistd.link(temporary_filename, secret_filename) -- Intentionally fails in the case that another process is doing the same. unistd.unlink(temporary_filename) @@ -227,7 +234,7 @@ function validate_value(expected_field, cookie) local field = "" local expiration = 0 local salt = "" - local hmac = "" + local chmac = "" if cookie == nil or cookie:len() < 3 or cookie:sub(1, 1) == "|" then return nil @@ -246,19 +253,19 @@ function validate_value(expected_field, cookie) elseif i == 3 then salt = component elseif i == 4 then - hmac = component + chmac = component else break end i = i + 1 end - if hmac == nil or hmac:len() == 0 then + if chmac == nil or chmac:len() == 0 then return nil end -- Lua hashes strings, so these comparisons are time invariant. - if hmac ~= crypto.hmac.digest("sha256", field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt, get_secret()) then + if chmac ~= tohex(hmac.new(get_secret(), "sha256"):final(field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt)) then return nil end @@ -279,11 +286,11 @@ function secure_value(field, value, expiration) end local authstr = "" - local salt = crypto.hex(crypto.rand.bytes(16)) + local salt = tohex(rand.bytes(16)) value = url_encode(value) field = url_encode(field) authstr = field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt - authstr = authstr .. "|" .. crypto.hmac.digest("sha256", authstr, get_secret()) + authstr = authstr .. "|" .. tohex(hmac.new(get_secret(), "sha256"):final(authstr)) return authstr end From 5bd7e9bc1b6749bbb5220d6c3a990469a7b839ae Mon Sep 17 00:00:00 2001 From: Chris Mayo <aklhfex@gmail.com> Date: Thu, 21 Feb 2019 19:56:05 +0000 Subject: [PATCH 295/387] ui-ssdiff: resolve HTML5 validation errors - Remove ids from anchor elements. They were unusable because they were duplicated between files and versions of files. - Always close span, with html(). - Fix missing / on closing tr element in cgit_ssdiff_header_end(). Signed-off-by: Chris Mayo <aklhfex@gmail.com> --- ui-ssdiff.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ui-ssdiff.c b/ui-ssdiff.c index c456033..b6dc5b0 100644 --- a/ui-ssdiff.c +++ b/ui-ssdiff.c @@ -207,11 +207,13 @@ static void print_part_with_lcs(char *class, char *line, char *lcs) } } else if (line[i] == lcs[j]) { same = 1; - htmlf("</span>"); + html("</span>"); j += 1; } html_txt(c); } + if (!same) + html("</span>"); } static void print_ssdiff_line(char *class, @@ -236,7 +238,7 @@ static void print_ssdiff_line(char *class, char *fileurl = cgit_fileurl(ctx.repo->url, "tree", old_file->path, id_str); html("<td class='lineno'><a href='"); html(fileurl); - htmlf("' id='%s'>%s</a>", lineno_str, lineno_str + 1); + htmlf("'>%s</a>", lineno_str + 1); html("</td>"); htmlf("<td class='%s'>", class); free(fileurl); @@ -259,7 +261,7 @@ static void print_ssdiff_line(char *class, char *fileurl = cgit_fileurl(ctx.repo->url, "tree", new_file->path, id_str); html("<td class='lineno'><a href='"); html(fileurl); - htmlf("' id='%s'>%s</a>", lineno_str, lineno_str + 1); + htmlf("'>%s</a>", lineno_str + 1); html("</td>"); htmlf("<td class='%s'>", class); free(fileurl); @@ -405,7 +407,7 @@ void cgit_ssdiff_header_begin(void) void cgit_ssdiff_header_end(void) { - html("</td><tr>"); + html("</td></tr>"); } void cgit_ssdiff_footer(void) From bd0293f57015ede637b630fcaf4fc11e7697d777 Mon Sep 17 00:00:00 2001 From: Chris Mayo <aklhfex@gmail.com> Date: Thu, 21 Feb 2019 19:57:23 +0000 Subject: [PATCH 296/387] ui-diff,ui-tag: don't use htmlf with non-formatted strings Signed-off-by: Chris Mayo <aklhfex@gmail.com> --- ui-diff.c | 2 +- ui-tag.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ui-diff.c b/ui-diff.c index 70dcc91..c60aefd 100644 --- a/ui-diff.c +++ b/ui-diff.c @@ -82,7 +82,7 @@ static void print_fileinfo(struct fileinfo *info) } html("<tr>"); - htmlf("<td class='mode'>"); + html("<td class='mode'>"); if (is_null_oid(info->new_oid)) { cgit_print_filemode(info->old_mode); } else { diff --git a/ui-tag.c b/ui-tag.c index f530224..846d5b1 100644 --- a/ui-tag.c +++ b/ui-tag.c @@ -71,7 +71,7 @@ void cgit_print_tag(char *revname) } cgit_print_layout_start(); html("<table class='commit-info'>\n"); - htmlf("<tr><td>tag name</td><td>"); + html("<tr><td>tag name</td><td>"); html_txt(revname); htmlf(" (%s)</td></tr>\n", oid_to_hex(&oid)); if (info->tagger_date > 0) { @@ -103,7 +103,7 @@ void cgit_print_tag(char *revname) } else { cgit_print_layout_start(); html("<table class='commit-info'>\n"); - htmlf("<tr><td>tag name</td><td>"); + html("<tr><td>tag name</td><td>"); html_txt(revname); html("</td></tr>\n"); html("<tr><td>tagged object</td><td class='sha1'>"); From 54c407a74a35d4ee9ffae94cc5bc9096c9f7f54a Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Mon, 20 May 2019 21:45:12 +0200 Subject: [PATCH 297/387] ui-shared: restrict to 15 levels Perhaps a more ideal version of this would be to not print breadcrumbs at all for paths that don't exist in the given repo at the given oid. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> Reported-by: Fydor Wire Snark <wsnark@tuta.io> --- ui-shared.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ui-shared.c b/ui-shared.c index d27a5fd..d2358f2 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -945,12 +945,13 @@ static void cgit_print_path_crumbs(char *path) { char *old_path = ctx.qry.path; char *p = path, *q, *end = path + strlen(path); + int levels = 0; ctx.qry.path = NULL; cgit_self_link("root", NULL, NULL); ctx.qry.path = p = path; while (p < end) { - if (!(q = strchr(p, '/'))) + if (!(q = strchr(p, '/')) || levels > 15) q = end; *q = '\0'; html_txt("/"); @@ -958,6 +959,7 @@ static void cgit_print_path_crumbs(char *path) if (q < end) *q = '/'; p = q + 1; + ++levels; } ctx.qry.path = old_path; } From ccba7eb9d0c43ffe99178ab6632dc3794f887309 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Wed, 2 Jan 2019 17:25:01 +0100 Subject: [PATCH 298/387] global: make 'char *path' const where possible Signed-off-by: Christian Hesse <mail@eworm.de> --- ui-atom.c | 2 +- ui-atom.h | 2 +- ui-log.c | 2 +- ui-log.h | 2 +- ui-refs.c | 2 +- ui-repolist.c | 2 +- ui-summary.c | 2 +- ui-summary.h | 2 +- ui-tree.c | 4 ++-- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ui-atom.c b/ui-atom.c index 3866823..cd66f82 100644 --- a/ui-atom.c +++ b/ui-atom.c @@ -83,7 +83,7 @@ static void add_entry(struct commit *commit, const char *host) } -void cgit_print_atom(char *tip, char *path, int max_count) +void cgit_print_atom(char *tip, const char *path, int max_count) { char *host; const char *argv[] = {NULL, tip, NULL, NULL, NULL}; diff --git a/ui-atom.h b/ui-atom.h index 749ffd3..dda953b 100644 --- a/ui-atom.h +++ b/ui-atom.h @@ -1,6 +1,6 @@ #ifndef UI_ATOM_H #define UI_ATOM_H -extern void cgit_print_atom(char *tip, char *path, int max_count); +extern void cgit_print_atom(char *tip, const char *path, int max_count); #endif diff --git a/ui-log.c b/ui-log.c index 3bcb657..8c65425 100644 --- a/ui-log.c +++ b/ui-log.c @@ -362,7 +362,7 @@ static char *next_token(char **src) } void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, - char *path, int pager, int commit_graph, int commit_sort) + const char *path, int pager, int commit_graph, int commit_sort) { struct rev_info rev; struct commit *commit; diff --git a/ui-log.h b/ui-log.h index d324c92..325607c 100644 --- a/ui-log.h +++ b/ui-log.h @@ -2,7 +2,7 @@ #define UI_LOG_H extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, - char *pattern, char *path, int pager, + char *pattern, const char *path, int pager, int commit_graph, int commit_sort); extern void show_commit_decorations(struct commit *commit); diff --git a/ui-refs.c b/ui-refs.c index 2ec3858..456f610 100644 --- a/ui-refs.c +++ b/ui-refs.c @@ -136,7 +136,7 @@ static int print_tag(struct refinfo *ref) return 0; } -static void print_refs_link(char *path) +static void print_refs_link(const char *path) { html("<tr class='nohover'><td colspan='5'>"); cgit_refs_link("[...]", NULL, NULL, ctx.qry.head, NULL, path); diff --git a/ui-repolist.c b/ui-repolist.c index 41424c0..7cf7638 100644 --- a/ui-repolist.c +++ b/ui-repolist.c @@ -11,7 +11,7 @@ #include "html.h" #include "ui-shared.h" -static time_t read_agefile(char *path) +static time_t read_agefile(const char *path) { time_t result; size_t size; diff --git a/ui-summary.c b/ui-summary.c index 8e81ac4..947812a 100644 --- a/ui-summary.c +++ b/ui-summary.c @@ -99,7 +99,7 @@ static char* append_readme_path(const char *filename, const char *ref, const cha return full_path; } -void cgit_print_repo_readme(char *path) +void cgit_print_repo_readme(const char *path) { char *filename, *ref, *mimetype; int free_filename = 0; diff --git a/ui-summary.h b/ui-summary.h index 0896650..cba696a 100644 --- a/ui-summary.h +++ b/ui-summary.h @@ -2,6 +2,6 @@ #define UI_SUMMARY_H extern void cgit_print_summary(void); -extern void cgit_print_repo_readme(char *path); +extern void cgit_print_repo_readme(const char *path); #endif /* UI_SUMMARY_H */ diff --git a/ui-tree.c b/ui-tree.c index df8ad82..314ac52 100644 --- a/ui-tree.c +++ b/ui-tree.c @@ -84,7 +84,7 @@ static void print_binary_buffer(char *buf, unsigned long size) html("</table>\n"); } -static void print_object(const struct object_id *oid, char *path, const char *basename, const char *rev) +static void print_object(const struct object_id *oid, const char *path, const char *basename, const char *rev) { enum object_type type; char *buf; @@ -279,7 +279,7 @@ static void ls_tail(void) cgit_print_layout_end(); } -static void ls_tree(const struct object_id *oid, char *path, struct walk_tree_context *walk_tree_ctx) +static void ls_tree(const struct object_id *oid, const char *path, struct walk_tree_context *walk_tree_ctx) { struct tree *tree; struct pathspec paths = { From 68de710c1c0e9b823a156b1398643601a682fbf9 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Tue, 12 Feb 2019 21:53:02 +0100 Subject: [PATCH 299/387] ui-ssdiff: ban strncat() Git version v2.21.0 marks strncat() as banned (commit ace5707a803eda0f1dde3d776dc3729d3bc7759a), so replace it. Signed-off-by: Christian Hesse <mail@eworm.de> --- ui-ssdiff.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ui-ssdiff.c b/ui-ssdiff.c index b6dc5b0..af8bc9e 100644 --- a/ui-ssdiff.c +++ b/ui-ssdiff.c @@ -117,7 +117,7 @@ static char *replace_tabs(char *line) int n_tabs = 0; int i; char *result; - int result_len; + size_t result_len; if (linelen == 0) { result = xmalloc(1); @@ -136,10 +136,12 @@ static char *replace_tabs(char *line) for (;;) { cur_buf = strchr(prev_buf, '\t'); if (!cur_buf) { - strncat(result, prev_buf, result_len); + linelen = strlen(result); + strlcpy(&result[linelen], prev_buf, result_len - linelen + 1); break; } else { - strncat(result, prev_buf, cur_buf - prev_buf); + linelen = strlen(result); + strlcpy(&result[linelen], prev_buf, cur_buf - prev_buf + 1); linelen = strlen(result); memset(&result[linelen], ' ', 8 - (linelen % 8)); result[linelen + 8 - (linelen % 8)] = '\0'; From 985fba80d06f37fdba5e72d738ce21ab5ab5a76d Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Sun, 24 Feb 2019 21:19:46 +0100 Subject: [PATCH 300/387] git: update to v2.21.0 Update to git version v2.21.0. Required changes follow upstream commits: * 6a7895fd8a3bd409f2b71ffc355d5142172cc2a0 (commit: prepare free_commit_buffer and release_commit_memory for any repo) * e092073d643b17c82d72cf692fbfaea9c9796f11 (tree.c: make read_tree*() take 'struct repository *') Signed-off-by: Christian Hesse <mail@eworm.de> Reviewed-by: John Keeping <john@keeping.me.uk> --- Makefile | 2 +- git | 2 +- ui-atom.c | 2 +- ui-blame.c | 4 ++-- ui-blob.c | 9 ++++++--- ui-log.c | 4 ++-- ui-plain.c | 3 ++- ui-stats.c | 2 +- ui-tree.c | 10 ++++++---- 9 files changed, 22 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index e690c7f..40f4fd8 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.20.0 +GIT_VER = 2.21.0 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index 5d826e9..8104ec9 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 5d826e972970a784bd7a7bdf587512510097b8c7 +Subproject commit 8104ec994ea3849a968b4667d072fedd1e688642 diff --git a/ui-atom.c b/ui-atom.c index cd66f82..1056f36 100644 --- a/ui-atom.c +++ b/ui-atom.c @@ -140,7 +140,7 @@ void cgit_print_atom(char *tip, const char *path, int max_count) } while ((commit = get_revision(&rev)) != NULL) { add_entry(commit, host); - free_commit_buffer(commit); + free_commit_buffer(the_repository->parsed_objects, commit); free_commit_list(commit->parents); commit->parents = NULL; } diff --git a/ui-blame.c b/ui-blame.c index c52cb9b..644c30a 100644 --- a/ui-blame.c +++ b/ui-blame.c @@ -290,8 +290,8 @@ void cgit_print_blame(void) walk_tree_ctx.match_baselen = (path_items.match) ? basedir_len(path_items.match) : -1; - read_tree_recursive(commit->maybe_tree, "", 0, 0, &paths, walk_tree, - &walk_tree_ctx); + read_tree_recursive(the_repository, commit->maybe_tree, "", 0, 0, + &paths, walk_tree, &walk_tree_ctx); if (!walk_tree_ctx.state) cgit_print_error_page(404, "Not found", "Not found"); else if (walk_tree_ctx.state == 2) diff --git a/ui-blob.c b/ui-blob.c index 4b6b462..30e2d4b 100644 --- a/ui-blob.c +++ b/ui-blob.c @@ -56,7 +56,8 @@ int cgit_ref_path_exists(const char *path, const char *ref, int file_only) goto done; if (oid_object_info(the_repository, &oid, &size) != OBJ_COMMIT) goto done; - read_tree_recursive(lookup_commit_reference(the_repository, &oid)->maybe_tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); + read_tree_recursive(the_repository, lookup_commit_reference(the_repository, &oid)->maybe_tree, + "", 0, 0, &paths, walk_tree, &walk_tree_ctx); done: free(path_items.match); @@ -90,7 +91,8 @@ int cgit_print_file(char *path, const char *head, int file_only) type = oid_object_info(the_repository, &oid, &size); if (type == OBJ_COMMIT) { commit = lookup_commit_reference(the_repository, &oid); - read_tree_recursive(commit->maybe_tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); + read_tree_recursive(the_repository, commit->maybe_tree, + "", 0, 0, &paths, walk_tree, &walk_tree_ctx); if (!walk_tree_ctx.found_path) return -1; type = oid_object_info(the_repository, &oid, &size); @@ -146,7 +148,8 @@ void cgit_print_blob(const char *hex, char *path, const char *head, int file_onl if ((!hex) && type == OBJ_COMMIT && path) { commit = lookup_commit_reference(the_repository, &oid); - read_tree_recursive(commit->maybe_tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); + read_tree_recursive(the_repository, commit->maybe_tree, + "", 0, 0, &paths, walk_tree, &walk_tree_ctx); type = oid_object_info(the_repository, &oid, &size); } diff --git a/ui-log.c b/ui-log.c index 8c65425..dc5cb1e 100644 --- a/ui-log.c +++ b/ui-log.c @@ -488,7 +488,7 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; /* nop */) { if (show_commit(commit, &rev)) i++; - free_commit_buffer(commit); + free_commit_buffer(the_repository->parsed_objects, commit); free_commit_list(commit->parents); commit->parents = NULL; } @@ -510,7 +510,7 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern i++; print_commit(commit, &rev); } - free_commit_buffer(commit); + free_commit_buffer(the_repository->parsed_objects, commit); free_commit_list(commit->parents); commit->parents = NULL; } diff --git a/ui-plain.c b/ui-plain.c index 070c34b..b73c1cf 100644 --- a/ui-plain.c +++ b/ui-plain.c @@ -198,7 +198,8 @@ void cgit_print_plain(void) } else walk_tree_ctx.match_baselen = basedir_len(path_items.match); - read_tree_recursive(commit->maybe_tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); + read_tree_recursive(the_repository, commit->maybe_tree, + "", 0, 0, &paths, walk_tree, &walk_tree_ctx); if (!walk_tree_ctx.match) cgit_print_error_page(404, "Not found", "Not found"); else if (walk_tree_ctx.match == 2) diff --git a/ui-stats.c b/ui-stats.c index 7acd358..7272a61 100644 --- a/ui-stats.c +++ b/ui-stats.c @@ -241,7 +241,7 @@ static struct string_list collect_stats(const struct cgit_period *period) memset(&authors, 0, sizeof(authors)); while ((commit = get_revision(&rev)) != NULL) { add_commit(&authors, commit, period); - free_commit_buffer(commit); + free_commit_buffer(the_repository->parsed_objects, commit); free_commit_list(commit->parents); commit->parents = NULL; } diff --git a/ui-tree.c b/ui-tree.c index 314ac52..4be89c8 100644 --- a/ui-tree.c +++ b/ui-tree.c @@ -185,8 +185,8 @@ static void write_tree_link(const struct object_id *oid, char *name, tree_ctx.name = NULL; tree_ctx.count = 0; - read_tree_recursive(tree, "", 0, 1, &paths, single_tree_cb, - &tree_ctx); + read_tree_recursive(the_repository, tree, "", 0, 1, + &paths, single_tree_cb, &tree_ctx); if (tree_ctx.count != 1) break; @@ -294,7 +294,8 @@ static void ls_tree(const struct object_id *oid, const char *path, struct walk_t } ls_head(); - read_tree_recursive(tree, "", 0, 1, &paths, ls_item, walk_tree_ctx); + read_tree_recursive(the_repository, tree, "", 0, 1, + &paths, ls_item, walk_tree_ctx); ls_tail(); } @@ -373,7 +374,8 @@ void cgit_print_tree(const char *rev, char *path) goto cleanup; } - read_tree_recursive(commit->maybe_tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); + read_tree_recursive(the_repository, commit->maybe_tree, "", 0, 0, + &paths, walk_tree, &walk_tree_ctx); if (walk_tree_ctx.state == 1) ls_tail(); else if (walk_tree_ctx.state == 2) From 27a6d69ab38825602bdbd5a5d0161e465326ea8d Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Tue, 4 Jun 2019 13:49:36 +0200 Subject: [PATCH 301/387] tests: successfully validate rc versions For testing versions the version string differs for git tag (v2.22.0-rc3) and tarball file name (2.22.0.rc3). Let's fix validation for testing versions. Signed-off-by: Christian Hesse <mail@eworm.de> --- tests/t0001-validate-git-versions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/t0001-validate-git-versions.sh b/tests/t0001-validate-git-versions.sh index a65b35e..3200f31 100755 --- a/tests/t0001-validate-git-versions.sh +++ b/tests/t0001-validate-git-versions.sh @@ -33,7 +33,7 @@ test_expect_success 'test submodule version matches Makefile' ' sed -e "s/^[0-9]* \\([0-9a-f]*\\) [0-9] .*$/\\1/") && cd git && git describe --match "v[0-9]*" $sm_sha1 - ) | sed -e "s/^v//" >sm_version && + ) | sed -e "s/^v//" -e "s/-/./" >sm_version && test_cmp sm_version makefile_version fi ' From e1ad15d368bdeb1bffea588b93a29055c5dfb7f4 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Tue, 26 Feb 2019 17:08:31 +0100 Subject: [PATCH 302/387] ui-tree: allow per repository override for enable-blame The blame operation can cause high cost in terms of CPU load for huge repositories. Let's add a per repository override for enable-blame. Signed-off-by: Christian Hesse <mail@eworm.de> --- cgit.c | 4 ++++ cgit.h | 1 + cgitrc.5.txt | 4 ++++ cmd.c | 2 +- shared.c | 1 + ui-tree.c | 4 ++-- 6 files changed, 13 insertions(+), 3 deletions(-) diff --git a/cgit.c b/cgit.c index 2f07e6d..2910d4b 100644 --- a/cgit.c +++ b/cgit.c @@ -50,6 +50,8 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va repo->extra_head_content = xstrdup(value); else if (!strcmp(name, "snapshots")) repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); + else if (!strcmp(name, "enable-blame")) + repo->enable_blame = atoi(value); else if (!strcmp(name, "enable-commit-graph")) repo->enable_commit_graph = atoi(value); else if (!strcmp(name, "enable-log-filecount")) @@ -809,6 +811,8 @@ static void print_repo(FILE *f, struct cgit_repo *repo) fprintf(f, "repo.homepage=%s\n", repo->homepage); if (repo->clone_url) fprintf(f, "repo.clone-url=%s\n", repo->clone_url); + fprintf(f, "repo.enable-blame=%d\n", + repo->enable_blame); fprintf(f, "repo.enable-commit-graph=%d\n", repo->enable_commit_graph); fprintf(f, "repo.enable-log-filecount=%d\n", diff --git a/cgit.h b/cgit.h index bcc4fce..7ec46b4 100644 --- a/cgit.h +++ b/cgit.h @@ -94,6 +94,7 @@ struct cgit_repo { char *logo_link; char *snapshot_prefix; int snapshots; + int enable_blame; int enable_commit_graph; int enable_log_filecount; int enable_log_linecount; diff --git a/cgitrc.5.txt b/cgitrc.5.txt index 34b351b..ba77826 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -485,6 +485,10 @@ repo.email-filter:: Override the default email-filter. Default value: none. See also: "enable-filter-overrides". See also: "FILTER API". +repo.enable-blame:: + A flag which can be used to disable the global setting + `enable-blame'. Default value: none. + repo.enable-commit-graph:: A flag which can be used to disable the global setting `enable-commit-graph'. Default value: none. diff --git a/cmd.c b/cmd.c index 63f0ae5..bf6d8f5 100644 --- a/cmd.c +++ b/cmd.c @@ -66,7 +66,7 @@ static void about_fn(void) static void blame_fn(void) { - if (ctx.cfg.enable_blame) + if (ctx.repo->enable_blame) cgit_print_blame(); else cgit_print_error_page(403, "Forbidden", "Blame is disabled"); diff --git a/shared.c b/shared.c index a2c0d03..8115469 100644 --- a/shared.c +++ b/shared.c @@ -58,6 +58,7 @@ struct cgit_repo *cgit_add_repo(const char *url) ret->homepage = NULL; ret->section = ctx.cfg.section; ret->snapshots = ctx.cfg.snapshots; + ret->enable_blame = ctx.cfg.enable_blame; ret->enable_commit_graph = ctx.cfg.enable_commit_graph; ret->enable_log_filecount = ctx.cfg.enable_log_filecount; ret->enable_log_linecount = ctx.cfg.enable_log_linecount; diff --git a/ui-tree.c b/ui-tree.c index 4be89c8..84eb17d 100644 --- a/ui-tree.c +++ b/ui-tree.c @@ -110,7 +110,7 @@ static void print_object(const struct object_id *oid, const char *path, const ch htmlf("blob: %s (", oid_to_hex(oid)); cgit_plain_link("plain", NULL, NULL, ctx.qry.head, rev, path); - if (ctx.cfg.enable_blame) { + if (ctx.repo->enable_blame) { html(") ("); cgit_blame_link("blame", NULL, NULL, ctx.qry.head, rev, path); @@ -251,7 +251,7 @@ static int ls_item(const struct object_id *oid, struct strbuf *base, if (!S_ISGITLINK(mode)) cgit_plain_link("plain", NULL, "button", ctx.qry.head, walk_tree_ctx->curr_rev, fullpath.buf); - if (!S_ISDIR(mode) && ctx.cfg.enable_blame) + if (!S_ISDIR(mode) && ctx.repo->enable_blame) cgit_blame_link("blame", NULL, "button", ctx.qry.head, walk_tree_ctx->curr_rev, fullpath.buf); html("</td></tr>\n"); From 034e3c7d56ba71ce281886fe8525b16d4559fac1 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Mon, 13 May 2019 21:41:37 +0200 Subject: [PATCH 303/387] git: update to v2.22.0 Update to git version v2.22.0. Upstream commit bce9db6d ("trace2: use system/global config for default trace2 settings") caused a regression. We have to unset HOME and XDG_CONFIG_HOME before early loading of config from trace2 code kicks in. Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- cgit.c | 17 +++++++++++------ git | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 40f4fd8..b2bd351 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.21.0 +GIT_VER = 2.22.0 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/cgit.c b/cgit.c index 2910d4b..ac8c641 100644 --- a/cgit.c +++ b/cgit.c @@ -19,6 +19,16 @@ const char *cgit_version = CGIT_VERSION; +__attribute__((constructor)) +static void constructor_environment() +{ + /* Do not look in /etc/ for gitconfig and gitattributes. */ + setenv("GIT_CONFIG_NOSYSTEM", "1", 1); + setenv("GIT_ATTR_NOSYSTEM", "1", 1); + unsetenv("HOME"); + unsetenv("XDG_CONFIG_HOME"); +} + static void add_mimetype(const char *name, const char *value) { struct string_list_item *item; @@ -565,18 +575,13 @@ static void prepare_repo_env(int *nongit) /* The path to the git repository. */ setenv("GIT_DIR", ctx.repo->path, 1); - /* Do not look in /etc/ for gitconfig and gitattributes. */ - setenv("GIT_CONFIG_NOSYSTEM", "1", 1); - setenv("GIT_ATTR_NOSYSTEM", "1", 1); - unsetenv("HOME"); - unsetenv("XDG_CONFIG_HOME"); - /* Setup the git directory and initialize the notes system. Both of these * load local configuration from the git repository, so we do them both while * the HOME variables are unset. */ setup_git_directory_gently(nongit); init_display_notes(NULL); } + static int prepare_repo_cmd(int nongit) { struct object_id oid; diff --git a/git b/git index 8104ec9..b697d92 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 8104ec994ea3849a968b4667d072fedd1e688642 +Subproject commit b697d92f56511e804b8ba20ccbe7bdc85dc66810 From 8fc0c81bbbed21ee30e8a48b2ab1066a029b7b32 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Thu, 13 Jun 2019 21:41:37 +0200 Subject: [PATCH 304/387] git: update to v2.23.0 Update to git version v2.23.0. No changes required. Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index b2bd351..96ad7cd 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.22.0 +GIT_VER = 2.23.0 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index b697d92..5fa0f52 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit b697d92f56511e804b8ba20ccbe7bdc85dc66810 +Subproject commit 5fa0f5238b0cd46cfe7f6fa76c3f526ea98148d9 From bfabd4519c80f39eedba3dd5d522563899e364c9 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Wed, 23 Oct 2019 23:21:54 +0200 Subject: [PATCH 305/387] git: update to v2.24.0 Update to git version v2.24.0. Never use get_cached_commit_buffer() directly, use repo_get_commit_buffer() instead. The latter calls the former anyway. This fixes segmentation fault when commit-graph is enabled and get_cached_commit_buffer() does not return the expected result. Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- parsing.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 96ad7cd..8a29dd9 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.23.0 +GIT_VER = 2.24.0 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index 5fa0f52..da72936 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 5fa0f5238b0cd46cfe7f6fa76c3f526ea98148d9 +Subproject commit da72936f544fec5a335e66432610e4cef4430991 diff --git a/parsing.c b/parsing.c index 7b3980e..93b4767 100644 --- a/parsing.c +++ b/parsing.c @@ -129,7 +129,7 @@ struct commitinfo *cgit_parse_commit(struct commit *commit) { const int sha1hex_len = 40; struct commitinfo *ret; - const char *p = get_cached_commit_buffer(the_repository, commit, NULL); + const char *p = repo_get_commit_buffer(the_repository, commit, NULL); const char *t; ret = xcalloc(1, sizeof(struct commitinfo)); From 583aa5d80eb01075c0f3f35df37b9144a0c9651e Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Fri, 22 Nov 2019 11:09:50 +0100 Subject: [PATCH 306/387] ui-repolist: do not return unsigned (negative) value The function read_agefile() returns time_t, which is a signed datatime. We should not return unsigned (negative) value here. Reported-by: Johannes Stezenbach <js@linuxtv.org> Signed-off-by: Christian Hesse <mail@eworm.de> --- ui-repolist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui-repolist.c b/ui-repolist.c index 7cf7638..529a203 100644 --- a/ui-repolist.c +++ b/ui-repolist.c @@ -20,7 +20,7 @@ static time_t read_agefile(const char *path) if (readfile(path, &buf, &size)) { free(buf); - return -1; + return 0; } if (parse_date(buf, &date_buf) == 0) From d8e5dd25a0d2e32ef3453a96112eea817336e4d7 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Tue, 10 Dec 2019 20:40:45 +0100 Subject: [PATCH 307/387] git: update to v2.24.1 Update to git version v2.24.1. No changes required. Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 8a29dd9..9dada6b 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.24.0 +GIT_VER = 2.24.1 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index da72936..53a06cf 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit da72936f544fec5a335e66432610e4cef4430991 +Subproject commit 53a06cf39b756eddfe4a2a34da93e3d04eb7b728 From ca98c9e7bf31617efc3ff7d3575efe5bba3cde1a Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Wed, 11 Dec 2019 10:55:24 +0100 Subject: [PATCH 308/387] tests: skip tests if strace is not functional Chances are that strace is available but not functional due to restricted permissions: strace: test_ptrace_get_syscall_info: PTRACE_TRACEME: Operation not permitted strace: ptrace(PTRACE_TRACEME, ...): Operation not permitted +++ exited with 1 +++ Just skip the tests then. Signed-off-by: Christian Hesse <mail@eworm.de> --- tests/t0109-gitconfig.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/t0109-gitconfig.sh b/tests/t0109-gitconfig.sh index 3ba6684..8cee75c 100755 --- a/tests/t0109-gitconfig.sh +++ b/tests/t0109-gitconfig.sh @@ -9,6 +9,12 @@ test -n "$(which strace 2>/dev/null)" || { exit } +strace true 2>/dev/null || { + skip_all='Skipping access validation tests: strace not functional' + test_done + exit +} + test_no_home_access () { non_existent_path="/path/to/some/place/that/does/not/possibly/exist" while test -d "$non_existent_path"; do From bd68c98879ecc8ce9f7f6d3e01bc4ffeb9182b04 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Thu, 26 Dec 2019 00:02:23 +0100 Subject: [PATCH 309/387] git: update to v2.25.0 Update to git version v2.25.0. Upstream renamed 'init_display_notes()' to 'load_display_notes()' in commit 1e6ed5441a61b5085978e0429691e2e2425f6846 ("notes: rename to load_display_notes()"). Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- cgit.c | 2 +- git | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 9dada6b..c970429 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.24.1 +GIT_VER = 2.25.0 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/cgit.c b/cgit.c index ac8c641..c4320f0 100644 --- a/cgit.c +++ b/cgit.c @@ -579,7 +579,7 @@ static void prepare_repo_env(int *nongit) * load local configuration from the git repository, so we do them both while * the HOME variables are unset. */ setup_git_directory_gently(nongit); - init_display_notes(NULL); + load_display_notes(NULL); } static int prepare_repo_cmd(int nongit) diff --git a/git b/git index 53a06cf..d0654dc 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 53a06cf39b756eddfe4a2a34da93e3d04eb7b728 +Subproject commit d0654dc308b0ba76dd8ed7bbb33c8d8f7aacd783 From fa146ccabdd0de746a7076f0630af550e43d9088 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Mon, 13 Jan 2020 15:04:14 -0500 Subject: [PATCH 310/387] Bump version Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index c970429..b51de6f 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ all:: -CGIT_VERSION = v1.2.1 +CGIT_VERSION = v1.2.2 CGIT_SCRIPT_NAME = cgit.cgi CGIT_SCRIPT_PATH = /var/www/htdocs/cgit CGIT_DATA_PATH = $(CGIT_SCRIPT_PATH) From 5e49023b01e5dfaacfc89199159e53c0c6e41331 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Mon, 13 Jan 2020 21:04:46 +0100 Subject: [PATCH 311/387] tests: allow to skip git version tests This allows to run tests non-tagged git checkout or when bisecting. Signed-off-by: Christian Hesse <mail@eworm.de> --- tests/t0001-validate-git-versions.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/t0001-validate-git-versions.sh b/tests/t0001-validate-git-versions.sh index 3200f31..73bd32f 100755 --- a/tests/t0001-validate-git-versions.sh +++ b/tests/t0001-validate-git-versions.sh @@ -1,5 +1,9 @@ #!/bin/sh +if [ "${CGIT_TEST_NO_GIT_VERSION}" = "YesPlease" ]; then + exit 0 +fi + test_description='Check Git version is correct' CGIT_TEST_NO_CREATE_REPOS=YesPlease . ./setup.sh From fde897b8171ed2e925b44ec6f69590ec07241017 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Mon, 17 Feb 2020 09:08:02 +0100 Subject: [PATCH 312/387] git: update to v2.25.1 Update to git version v2.25.1. No changes required. --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index b51de6f..23f79cf 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.25.0 +GIT_VER = 2.25.1 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index d0654dc..c522f06 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit d0654dc308b0ba76dd8ed7bbb33c8d8f7aacd783 +Subproject commit c522f061d551c9bb8684a7c3859b2ece4499b56b From 06671f4b2167951c6b46401b0f5ac8af4d48d50a Mon Sep 17 00:00:00 2001 From: Hanspeter Portner <dev@open-music-kontrollers.ch> Date: Fri, 16 Aug 2019 23:40:19 +0200 Subject: [PATCH 313/387] ui-snapshot: add support for lzip compression This patch adds support for lzip [1] compressed snapshots (*.tar.lz) [1] https://www.nongnu.org/lzip/ Signed-off-by: Hanspeter Portner <dev@open-music-kontrollers.ch> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- cgitrc.5.txt | 4 ++-- tests/setup.sh | 2 +- tests/t0107-snapshot.sh | 42 +++++++++++++++++++++++++++++++++++++++++ ui-snapshot.c | 7 +++++++ 4 files changed, 52 insertions(+), 3 deletions(-) diff --git a/cgitrc.5.txt b/cgitrc.5.txt index ba77826..4ad3e64 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -407,8 +407,8 @@ side-by-side-diffs:: snapshots:: Text which specifies the default set of snapshot formats that cgit generates links for. The value is a space-separated list of zero or - more of the values "tar", "tar.gz", "tar.bz2", "tar.xz" and "zip". - The special value "all" enables all snapshot formats. + more of the values "tar", "tar.gz", "tar.bz2", "tar.xz", "tar.lz" and + "zip". The special value "all" enables all snapshot formats. Default value: none. source-filter:: diff --git a/tests/setup.sh b/tests/setup.sh index 7590f04..69e47e6 100755 --- a/tests/setup.sh +++ b/tests/setup.sh @@ -104,7 +104,7 @@ virtual-root=/ cache-root=$PWD/cache cache-size=1021 -snapshots=tar.gz tar.bz zip +snapshots=tar.gz tar.bz tar.lz zip enable-log-filecount=1 enable-log-linecount=1 summary-log=5 diff --git a/tests/t0107-snapshot.sh b/tests/t0107-snapshot.sh index 6cf7aaa..a845ad9 100755 --- a/tests/t0107-snapshot.sh +++ b/tests/t0107-snapshot.sh @@ -38,6 +38,48 @@ test_expect_success 'verify untarred file-5' ' test_line_count = 1 master/file-5 ' +if test -n "$(which lzip 2>/dev/null)"; then + test_set_prereq LZIP +else + say 'Skipping LZIP validation tests: lzip not found' +fi + +test_expect_success LZIP 'get foo/snapshot/master.tar.lz' ' + cgit_url "foo/snapshot/master.tar.lz" >tmp +' + +test_expect_success LZIP 'check html headers' ' + head -n 1 tmp | + grep "Content-Type: application/x-lzip" && + + head -n 2 tmp | + grep "Content-Disposition: inline; filename=.master.tar.lz." +' + +test_expect_success LZIP 'strip off the header lines' ' + strip_headers <tmp >master.tar.lz +' + +test_expect_success LZIP 'verify lzip format' ' + lzip --test master.tar.lz && + cp master.tar.lz /tmp/. +' + +test_expect_success LZIP 'untar' ' + rm -rf master && + tar --lzip -xf master.tar.lz +' + +test_expect_success LZIP 'count files' ' + ls master/ >output && + test_line_count = 5 output +' + +test_expect_success LZIP 'verify untarred file-5' ' + grep "^5$" master/file-5 && + test_line_count = 1 master/file-5 +' + test_expect_success 'get foo/snapshot/master.zip' ' cgit_url "foo/snapshot/master.zip" >tmp ' diff --git a/ui-snapshot.c b/ui-snapshot.c index 9461d51..92cde42 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c @@ -79,6 +79,12 @@ static int write_tar_bzip2_archive(const char *hex, const char *prefix) return write_compressed_tar_archive(hex, prefix, argv); } +static int write_tar_lzip_archive(const char *hex, const char *prefix) +{ + char *argv[] = { "lzip", NULL }; + return write_compressed_tar_archive(hex, prefix, argv); +} + static int write_tar_xz_archive(const char *hex, const char *prefix) { char *argv[] = { "xz", NULL }; @@ -90,6 +96,7 @@ const struct cgit_snapshot_format cgit_snapshot_formats[] = { { ".tar", "application/x-tar", write_tar_archive }, { ".tar.gz", "application/x-gzip", write_tar_gzip_archive }, { ".tar.bz2", "application/x-bzip2", write_tar_bzip2_archive }, + { ".tar.lz", "application/x-lzip", write_tar_lzip_archive }, { ".tar.xz", "application/x-xz", write_tar_xz_archive }, { ".zip", "application/x-zip", write_zip_archive }, { NULL } From cc230bf04456cc0ca82c6251b1624425eb7a7153 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Wed, 26 Feb 2020 09:19:00 +0100 Subject: [PATCH 314/387] tests: add tests for xz compressed snapshots Signed-off-by: Christian Hesse <mail@eworm.de> --- tests/setup.sh | 2 +- tests/t0107-snapshot.sh | 42 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/tests/setup.sh b/tests/setup.sh index 69e47e6..334cca6 100755 --- a/tests/setup.sh +++ b/tests/setup.sh @@ -104,7 +104,7 @@ virtual-root=/ cache-root=$PWD/cache cache-size=1021 -snapshots=tar.gz tar.bz tar.lz zip +snapshots=tar.gz tar.bz tar.lz tar.xz zip enable-log-filecount=1 enable-log-linecount=1 summary-log=5 diff --git a/tests/t0107-snapshot.sh b/tests/t0107-snapshot.sh index a845ad9..84995d1 100755 --- a/tests/t0107-snapshot.sh +++ b/tests/t0107-snapshot.sh @@ -80,6 +80,48 @@ test_expect_success LZIP 'verify untarred file-5' ' test_line_count = 1 master/file-5 ' +if test -n "$(which xz 2>/dev/null)"; then + test_set_prereq XZ +else + say 'Skipping XZ validation tests: xz not found' +fi + +test_expect_success XZ 'get foo/snapshot/master.tar.xz' ' + cgit_url "foo/snapshot/master.tar.xz" >tmp +' + +test_expect_success XZ 'check html headers' ' + head -n 1 tmp | + grep "Content-Type: application/x-xz" && + + head -n 2 tmp | + grep "Content-Disposition: inline; filename=.master.tar.xz." +' + +test_expect_success XZ 'strip off the header lines' ' + strip_headers <tmp >master.tar.xz +' + +test_expect_success XZ 'verify xz format' ' + xz --test master.tar.xz && + cp master.tar.xz /tmp/. +' + +test_expect_success XZ 'untar' ' + rm -rf master && + tar --xz -xf master.tar.xz +' + +test_expect_success XZ 'count files' ' + ls master/ >output && + test_line_count = 5 output +' + +test_expect_success XZ 'verify untarred file-5' ' + grep "^5$" master/file-5 && + test_line_count = 1 master/file-5 +' + test_expect_success 'get foo/snapshot/master.zip' ' cgit_url "foo/snapshot/master.zip" >tmp ' From 892ba8c3cc0617d2087a2337d8c6e71524d7b49c Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Wed, 26 Feb 2020 09:12:21 +0100 Subject: [PATCH 315/387] ui-snapshot: add support for zstd compression This patch adds support for zstd [0] compressed snapshots (*.tar.zst). We enable multiple working threads (-T0), but keep default compression level. The latter can be influenced by environment variable. [0] https://www.zstd.net/ Signed-off-by: Christian Hesse <mail@eworm.de> --- cgitrc.5.txt | 9 ++++++--- tests/setup.sh | 2 +- tests/t0107-snapshot.sh | 42 +++++++++++++++++++++++++++++++++++++++++ ui-snapshot.c | 7 +++++++ 4 files changed, 56 insertions(+), 4 deletions(-) diff --git a/cgitrc.5.txt b/cgitrc.5.txt index 4ad3e64..33a6a8c 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -407,9 +407,12 @@ side-by-side-diffs:: snapshots:: Text which specifies the default set of snapshot formats that cgit generates links for. The value is a space-separated list of zero or - more of the values "tar", "tar.gz", "tar.bz2", "tar.xz", "tar.lz" and - "zip". The special value "all" enables all snapshot formats. - Default value: none. + more of the values "tar", "tar.gz", "tar.bz2", "tar.lz", "tar.xz", + "tar.zst" and "zip". The special value "all" enables all snapshot + formats. Default value: none. + All compressors use default settings. Some settings can be influenced + with environment variables, for example set ZSTD_CLEVEL=10 in web + server environment for higher (but slower) zstd compression. source-filter:: Specifies a command which will be invoked to format plaintext blobs diff --git a/tests/setup.sh b/tests/setup.sh index 334cca6..5879348 100755 --- a/tests/setup.sh +++ b/tests/setup.sh @@ -104,7 +104,7 @@ virtual-root=/ cache-root=$PWD/cache cache-size=1021 -snapshots=tar.gz tar.bz tar.lz tar.xz zip +snapshots=tar.gz tar.bz tar.lz tar.xz tar.zst zip enable-log-filecount=1 enable-log-linecount=1 summary-log=5 diff --git a/tests/t0107-snapshot.sh b/tests/t0107-snapshot.sh index 84995d1..c164d3e 100755 --- a/tests/t0107-snapshot.sh +++ b/tests/t0107-snapshot.sh @@ -122,6 +122,48 @@ test_expect_success XZ 'verify untarred file-5' ' test_line_count = 1 master/file-5 ' +if test -n "$(which zstd 2>/dev/null)"; then + test_set_prereq ZSTD +else + say 'Skipping ZSTD validation tests: zstd not found' +fi + +test_expect_success ZSTD 'get foo/snapshot/master.tar.zst' ' + cgit_url "foo/snapshot/master.tar.zst" >tmp +' + +test_expect_success ZSTD 'check html headers' ' + head -n 1 tmp | + grep "Content-Type: application/x-zstd" && + + head -n 2 tmp | + grep "Content-Disposition: inline; filename=.master.tar.zst." +' + +test_expect_success ZSTD 'strip off the header lines' ' + strip_headers <tmp >master.tar.zst +' + +test_expect_success ZSTD 'verify zstd format' ' + zstd --test master.tar.zst && + cp master.tar.zst /tmp/. +' + +test_expect_success ZSTD 'untar' ' + rm -rf master && + tar --zstd -xf master.tar.zst +' + +test_expect_success ZSTD 'count files' ' + ls master/ >output && + test_line_count = 5 output +' + +test_expect_success ZSTD 'verify untarred file-5' ' + grep "^5$" master/file-5 && + test_line_count = 1 master/file-5 +' + test_expect_success 'get foo/snapshot/master.zip' ' cgit_url "foo/snapshot/master.zip" >tmp ' diff --git a/ui-snapshot.c b/ui-snapshot.c index 92cde42..556d3ed 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c @@ -91,6 +91,12 @@ static int write_tar_xz_archive(const char *hex, const char *prefix) return write_compressed_tar_archive(hex, prefix, argv); } +static int write_tar_zstd_archive(const char *hex, const char *prefix) +{ + char *argv[] = { "zstd", "-T0", NULL }; + return write_compressed_tar_archive(hex, prefix, argv); +} + const struct cgit_snapshot_format cgit_snapshot_formats[] = { /* .tar must remain the 0 index */ { ".tar", "application/x-tar", write_tar_archive }, @@ -98,6 +104,7 @@ const struct cgit_snapshot_format cgit_snapshot_formats[] = { { ".tar.bz2", "application/x-bzip2", write_tar_bzip2_archive }, { ".tar.lz", "application/x-lzip", write_tar_lzip_archive }, { ".tar.xz", "application/x-xz", write_tar_xz_archive }, + { ".tar.zst", "application/x-zstd", write_tar_zstd_archive }, { ".zip", "application/x-zip", write_zip_archive }, { NULL } }; From 6a8d6d4b5021af6c90ca0da806691987df449469 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Thu, 12 Mar 2020 20:52:35 -0600 Subject: [PATCH 316/387] global: use proper accessors for maybe_tree A previous commit changed ->tree to ->maybe_tree throughout, which may have worked at the time, but wasn't safe, because maybe_tree is loaded lazily. This manifested itself in crashes when using the "follow" log feature. The proper fix is to use the correct contextual accessors everytime we want access to maybe_tree. Thankfully, the commit.cocci script takes care of creating mostly-correct patches that we could then fix up, resulting in this commit here. Fixes: 255b78f ("git: update to v2.18.0") Reviewed-by: Christian Hesse <mail@eworm.de> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- ui-blame.c | 6 ++++-- ui-blob.c | 17 +++++++++++------ ui-commit.c | 2 +- ui-diff.c | 4 ++-- ui-log.c | 4 ++-- ui-plain.c | 7 ++++--- ui-tree.c | 8 +++++--- 7 files changed, 29 insertions(+), 19 deletions(-) diff --git a/ui-blame.c b/ui-blame.c index 644c30a..f28eea0 100644 --- a/ui-blame.c +++ b/ui-blame.c @@ -290,8 +290,10 @@ void cgit_print_blame(void) walk_tree_ctx.match_baselen = (path_items.match) ? basedir_len(path_items.match) : -1; - read_tree_recursive(the_repository, commit->maybe_tree, "", 0, 0, - &paths, walk_tree, &walk_tree_ctx); + read_tree_recursive(the_repository, + repo_get_commit_tree(the_repository, commit), + "", 0, 0, + &paths, walk_tree, &walk_tree_ctx); if (!walk_tree_ctx.state) cgit_print_error_page(404, "Not found", "Not found"); else if (walk_tree_ctx.state == 2) diff --git a/ui-blob.c b/ui-blob.c index 30e2d4b..f76c641 100644 --- a/ui-blob.c +++ b/ui-blob.c @@ -56,8 +56,9 @@ int cgit_ref_path_exists(const char *path, const char *ref, int file_only) goto done; if (oid_object_info(the_repository, &oid, &size) != OBJ_COMMIT) goto done; - read_tree_recursive(the_repository, lookup_commit_reference(the_repository, &oid)->maybe_tree, - "", 0, 0, &paths, walk_tree, &walk_tree_ctx); + read_tree_recursive(the_repository, + repo_get_commit_tree(the_repository, lookup_commit_reference(the_repository, &oid)), + "", 0, 0, &paths, walk_tree, &walk_tree_ctx); done: free(path_items.match); @@ -91,8 +92,10 @@ int cgit_print_file(char *path, const char *head, int file_only) type = oid_object_info(the_repository, &oid, &size); if (type == OBJ_COMMIT) { commit = lookup_commit_reference(the_repository, &oid); - read_tree_recursive(the_repository, commit->maybe_tree, - "", 0, 0, &paths, walk_tree, &walk_tree_ctx); + read_tree_recursive(the_repository, + repo_get_commit_tree(the_repository, commit), + "", 0, 0, &paths, walk_tree, + &walk_tree_ctx); if (!walk_tree_ctx.found_path) return -1; type = oid_object_info(the_repository, &oid, &size); @@ -148,8 +151,10 @@ void cgit_print_blob(const char *hex, char *path, const char *head, int file_onl if ((!hex) && type == OBJ_COMMIT && path) { commit = lookup_commit_reference(the_repository, &oid); - read_tree_recursive(the_repository, commit->maybe_tree, - "", 0, 0, &paths, walk_tree, &walk_tree_ctx); + read_tree_recursive(the_repository, + repo_get_commit_tree(the_repository, commit), + "", 0, 0, &paths, walk_tree, + &walk_tree_ctx); type = oid_object_info(the_repository, &oid, &size); } diff --git a/ui-commit.c b/ui-commit.c index 9a47b54..783211f 100644 --- a/ui-commit.c +++ b/ui-commit.c @@ -78,7 +78,7 @@ void cgit_print_commit(char *hex, const char *prefix) html(")</td></tr>\n"); html("<tr><th>tree</th><td colspan='2' class='sha1'>"); tmp = xstrdup(hex); - cgit_tree_link(oid_to_hex(&commit->maybe_tree->object.oid), NULL, NULL, + cgit_tree_link(oid_to_hex(get_commit_tree_oid(commit)), NULL, NULL, ctx.qry.head, tmp, NULL); if (prefix) { html(" /"); diff --git a/ui-diff.c b/ui-diff.c index c60aefd..329c350 100644 --- a/ui-diff.c +++ b/ui-diff.c @@ -413,7 +413,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, "Bad commit: %s", oid_to_hex(new_rev_oid)); return; } - new_tree_oid = &commit->maybe_tree->object.oid; + new_tree_oid = get_commit_tree_oid(commit); if (old_rev) { if (get_oid(old_rev, old_rev_oid)) { @@ -434,7 +434,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, "Bad commit: %s", oid_to_hex(old_rev_oid)); return; } - old_tree_oid = &commit2->maybe_tree->object.oid; + old_tree_oid = get_commit_tree_oid(commit2); } else { old_tree_oid = NULL; } diff --git a/ui-log.c b/ui-log.c index dc5cb1e..2939c01 100644 --- a/ui-log.c +++ b/ui-log.c @@ -153,8 +153,8 @@ static int show_commit(struct commit *commit, struct rev_info *revs) rem_lines = 0; revs->diffopt.flags.recursive = 1; - diff_tree_oid(&parent->maybe_tree->object.oid, - &commit->maybe_tree->object.oid, + diff_tree_oid(get_commit_tree_oid(parent), + get_commit_tree_oid(commit), "", &revs->diffopt); diffcore_std(&revs->diffopt); diff --git a/ui-plain.c b/ui-plain.c index b73c1cf..2a7b18c 100644 --- a/ui-plain.c +++ b/ui-plain.c @@ -193,13 +193,14 @@ void cgit_print_plain(void) if (!path_items.match) { path_items.match = ""; walk_tree_ctx.match_baselen = -1; - print_dir(&commit->maybe_tree->object.oid, "", 0, ""); + print_dir(get_commit_tree_oid(commit), "", 0, ""); walk_tree_ctx.match = 2; } else walk_tree_ctx.match_baselen = basedir_len(path_items.match); - read_tree_recursive(the_repository, commit->maybe_tree, - "", 0, 0, &paths, walk_tree, &walk_tree_ctx); + read_tree_recursive(the_repository, + repo_get_commit_tree(the_repository, commit), + "", 0, 0, &paths, walk_tree, &walk_tree_ctx); if (!walk_tree_ctx.match) cgit_print_error_page(404, "Not found", "Not found"); else if (walk_tree_ctx.match == 2) diff --git a/ui-tree.c b/ui-tree.c index 84eb17d..1e4efb2 100644 --- a/ui-tree.c +++ b/ui-tree.c @@ -370,12 +370,14 @@ void cgit_print_tree(const char *rev, char *path) walk_tree_ctx.curr_rev = xstrdup(rev); if (path == NULL) { - ls_tree(&commit->maybe_tree->object.oid, NULL, &walk_tree_ctx); + ls_tree(get_commit_tree_oid(commit), NULL, &walk_tree_ctx); goto cleanup; } - read_tree_recursive(the_repository, commit->maybe_tree, "", 0, 0, - &paths, walk_tree, &walk_tree_ctx); + read_tree_recursive(the_repository, + repo_get_commit_tree(the_repository, commit), + "", 0, 0, + &paths, walk_tree, &walk_tree_ctx); if (walk_tree_ctx.state == 1) ls_tail(); else if (walk_tree_ctx.state == 2) From 55fa25adb097d2681607d8b0f51a0c393cc9af1a Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Fri, 13 Mar 2020 17:49:52 -0600 Subject: [PATCH 317/387] Bump version Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 23f79cf..49109ad 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ all:: -CGIT_VERSION = v1.2.2 +CGIT_VERSION = v1.2.3 CGIT_SCRIPT_NAME = cgit.cgi CGIT_SCRIPT_PATH = /var/www/htdocs/cgit CGIT_DATA_PATH = $(CGIT_SCRIPT_PATH) From 0462f08d8508978256118769b3e6dc89773a1367 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Mon, 9 Mar 2020 09:51:05 +0100 Subject: [PATCH 318/387] git: update to v2.26.0 Update to git version v2.26.0. No changes required. Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 49109ad..b50159f 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.25.1 +GIT_VER = 2.26.0 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index c522f06..274b9cc 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit c522f061d551c9bb8684a7c3859b2ece4499b56b +Subproject commit 274b9cc25322d9ee79aa8e6d4e86f0ffe5ced925 From f780396c0afa6015a05025c6404a560252605319 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Tue, 2 Jun 2020 10:10:15 +0200 Subject: [PATCH 319/387] git: update to v2.27.0 Update to git version v2.27.0. No changes required. Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index b50159f..5c8fa8c 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.26.0 +GIT_VER = 2.27.0 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index 274b9cc..b3d7a52 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 274b9cc25322d9ee79aa8e6d4e86f0ffe5ced925 +Subproject commit b3d7a52fac39193503a0b6728771d1bf6a161464 From 205837d4684f331afa93c946cbdfa1fa9b3d1ce9 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Mon, 27 Jul 2020 20:36:14 +0200 Subject: [PATCH 320/387] git: update to v2.28.0 Update to git version v2.28.0. No changes required. Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 5c8fa8c..84822f0 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.27.0 +GIT_VER = 2.28.0 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index b3d7a52..47ae905 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit b3d7a52fac39193503a0b6728771d1bf6a161464 +Subproject commit 47ae905ffb98cc4d4fd90083da6bc8dab55d9ecc From 629659d2cffbf059374fc53e6400ff0bebe1ddde Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Tue, 6 Oct 2020 16:32:08 +0200 Subject: [PATCH 321/387] git: update to v2.29.0 Update to git version v2.29.0, this requires changes for these upstream commits: * dbbcd44fb47347a3fdbee88ea21805b7f4ac0b98 strvec: rename files from argv-array to strvec * 873cd28a8b17ff21908c78c7929a7615f8c94992 argv-array: rename to strvec * d70a9eb611a9d242c1d26847d223b8677609305b strvec: rename struct fields * 6a67c759489e1025665adf78326e9e0d0981bab5 test-lib-functions: restrict test_must_fail usage Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- cgit.h | 2 +- git | 2 +- tests/t0109-gitconfig.sh | 2 +- ui-blame.c | 10 +++++----- ui-log.c | 30 +++++++++++++++--------------- ui-snapshot.c | 24 ++++++++++++------------ 7 files changed, 36 insertions(+), 36 deletions(-) diff --git a/Makefile b/Makefile index 84822f0..c947b63 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.28.0 +GIT_VER = 2.29.0 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/cgit.h b/cgit.h index 7ec46b4..f5db364 100644 --- a/cgit.h +++ b/cgit.h @@ -14,7 +14,7 @@ #include <tag.h> #include <diff.h> #include <diffcore.h> -#include <argv-array.h> +#include <strvec.h> #include <refs.h> #include <revision.h> #include <log-tree.h> diff --git a/git b/git index 47ae905..69986e1 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 47ae905ffb98cc4d4fd90083da6bc8dab55d9ecc +Subproject commit 69986e19ffcfb9af674ae5180689ab7bbf92ed28 diff --git a/tests/t0109-gitconfig.sh b/tests/t0109-gitconfig.sh index 8cee75c..189ef28 100755 --- a/tests/t0109-gitconfig.sh +++ b/tests/t0109-gitconfig.sh @@ -25,7 +25,7 @@ test_no_home_access () { -E CGIT_CONFIG="$PWD/cgitrc" \ -E QUERY_STRING="url=$1" \ -e access -f -o strace.out cgit && - test_must_fail grep "$non_existent_path" strace.out + ! grep "$non_existent_path" strace.out } test_no_home_access_success() { diff --git a/ui-blame.c b/ui-blame.c index f28eea0..c3662bb 100644 --- a/ui-blame.c +++ b/ui-blame.c @@ -10,7 +10,7 @@ #include "ui-blame.h" #include "html.h" #include "ui-shared.h" -#include "argv-array.h" +#include "strvec.h" #include "blame.h" @@ -104,7 +104,7 @@ static void print_object(const struct object_id *oid, const char *path, enum object_type type; char *buf; unsigned long size; - struct argv_array rev_argv = ARGV_ARRAY_INIT; + struct strvec rev_argv = STRVEC_INIT; struct rev_info revs; struct blame_scoreboard sb; struct blame_origin *o; @@ -124,11 +124,11 @@ static void print_object(const struct object_id *oid, const char *path, return; } - argv_array_push(&rev_argv, "blame"); - argv_array_push(&rev_argv, rev); + strvec_push(&rev_argv, "blame"); + strvec_push(&rev_argv, rev); init_revisions(&revs, NULL); revs.diffopt.flags.allow_textconv = 1; - setup_revisions(rev_argv.argc, rev_argv.argv, &revs, NULL); + setup_revisions(rev_argv.nr, rev_argv.v, &revs, NULL); init_scoreboard(&sb); sb.revs = &revs; sb.repo = the_repository; diff --git a/ui-log.c b/ui-log.c index 2939c01..fd07409 100644 --- a/ui-log.c +++ b/ui-log.c @@ -10,7 +10,7 @@ #include "ui-log.h" #include "html.h" #include "ui-shared.h" -#include "argv-array.h" +#include "strvec.h" static int files, add_lines, rem_lines, lines_counted; @@ -366,23 +366,23 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern { struct rev_info rev; struct commit *commit; - struct argv_array rev_argv = ARGV_ARRAY_INIT; + struct strvec rev_argv = STRVEC_INIT; int i, columns = commit_graph ? 4 : 3; int must_free_tip = 0; /* rev_argv.argv[0] will be ignored by setup_revisions */ - argv_array_push(&rev_argv, "log_rev_setup"); + strvec_push(&rev_argv, "log_rev_setup"); if (!tip) tip = ctx.qry.head; tip = disambiguate_ref(tip, &must_free_tip); - argv_array_push(&rev_argv, tip); + strvec_push(&rev_argv, tip); if (grep && pattern && *pattern) { pattern = xstrdup(pattern); if (!strcmp(grep, "grep") || !strcmp(grep, "author") || !strcmp(grep, "committer")) { - argv_array_pushf(&rev_argv, "--%s=%s", grep, pattern); + strvec_pushf(&rev_argv, "--%s=%s", grep, pattern); } else if (!strcmp(grep, "range")) { char *arg; /* Split the pattern at whitespace and add each token @@ -390,14 +390,14 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern * rev-list options. Also, replace the previously * pushed tip (it's no longer relevant). */ - argv_array_pop(&rev_argv); + strvec_pop(&rev_argv); while ((arg = next_token(&pattern))) { if (*arg == '-') { fprintf(stderr, "Bad range expr: %s\n", arg); break; } - argv_array_push(&rev_argv, arg); + strvec_push(&rev_argv, arg); } } } @@ -412,22 +412,22 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern } if (commit_graph && !ctx.qry.follow) { - argv_array_push(&rev_argv, "--graph"); - argv_array_push(&rev_argv, "--color"); + strvec_push(&rev_argv, "--graph"); + strvec_push(&rev_argv, "--color"); graph_set_column_colors(column_colors_html, COLUMN_COLORS_HTML_MAX); } if (commit_sort == 1) - argv_array_push(&rev_argv, "--date-order"); + strvec_push(&rev_argv, "--date-order"); else if (commit_sort == 2) - argv_array_push(&rev_argv, "--topo-order"); + strvec_push(&rev_argv, "--topo-order"); if (path && ctx.qry.follow) - argv_array_push(&rev_argv, "--follow"); - argv_array_push(&rev_argv, "--"); + strvec_push(&rev_argv, "--follow"); + strvec_push(&rev_argv, "--"); if (path) - argv_array_push(&rev_argv, path); + strvec_push(&rev_argv, path); init_revisions(&rev, NULL); rev.abbrev = DEFAULT_ABBREV; @@ -436,7 +436,7 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern rev.show_root_diff = 0; rev.ignore_missing = 1; rev.simplify_history = 1; - setup_revisions(rev_argv.argc, rev_argv.argv, &rev, NULL); + setup_revisions(rev_argv.nr, rev_argv.v, &rev, NULL); load_ref_decorations(NULL, DECORATE_FULL_REFS); rev.show_decorations = 1; rev.grep_filter.ignore_case = 1; diff --git a/ui-snapshot.c b/ui-snapshot.c index 556d3ed..18361a6 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c @@ -13,32 +13,32 @@ static int write_archive_type(const char *format, const char *hex, const char *prefix) { - struct argv_array argv = ARGV_ARRAY_INIT; + struct strvec argv = STRVEC_INIT; const char **nargv; int result; - argv_array_push(&argv, "snapshot"); - argv_array_push(&argv, format); + strvec_push(&argv, "snapshot"); + strvec_push(&argv, format); if (prefix) { struct strbuf buf = STRBUF_INIT; strbuf_addstr(&buf, prefix); strbuf_addch(&buf, '/'); - argv_array_push(&argv, "--prefix"); - argv_array_push(&argv, buf.buf); + strvec_push(&argv, "--prefix"); + strvec_push(&argv, buf.buf); strbuf_release(&buf); } - argv_array_push(&argv, hex); + strvec_push(&argv, hex); /* * Now we need to copy the pointers to arguments into a new * structure because write_archive will rearrange its arguments * which may result in duplicated/missing entries causing leaks - * or double-frees in argv_array_clear. + * or double-frees in strvec_clear. */ - nargv = xmalloc(sizeof(char *) * (argv.argc + 1)); - /* argv_array guarantees a trailing NULL entry. */ - memcpy(nargv, argv.argv, sizeof(char *) * (argv.argc + 1)); + nargv = xmalloc(sizeof(char *) * (argv.nr + 1)); + /* strvec guarantees a trailing NULL entry. */ + memcpy(nargv, argv.v, sizeof(char *) * (argv.nr + 1)); - result = write_archive(argv.argc, nargv, NULL, the_repository, NULL, 0); - argv_array_clear(&argv); + result = write_archive(argv.nr, nargv, NULL, the_repository, NULL, 0); + strvec_clear(&argv); free(nargv); return result; } From 779631c6dc23c15bbbf45a7c7ab9fffb619037b7 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Tue, 20 Oct 2020 23:32:45 +0200 Subject: [PATCH 322/387] global: replace references to 'sha1' with 'oid' For some time now sha1 is considered broken and upstream is working to replace it with sha256. Replace all references to 'sha1' with 'oid', just as upstream does. Signed-off-by: Christian Hesse <mail@eworm.de> --- cgit.c | 16 +++++------ cgit.css | 2 +- cgit.h | 6 ++--- cmd.c | 18 ++++++------- parsing.c | 6 ++--- tests/t0001-validate-git-versions.sh | 4 +-- ui-blame.c | 4 +-- ui-commit.c | 10 +++---- ui-diff.c | 8 +++--- ui-log.c | 6 ++--- ui-plain.c | 6 ++--- ui-shared.c | 40 ++++++++++++++-------------- ui-tag.c | 6 ++--- 13 files changed, 66 insertions(+), 66 deletions(-) diff --git a/cgit.c b/cgit.c index c4320f0..08d81a1 100644 --- a/cgit.c +++ b/cgit.c @@ -324,11 +324,11 @@ static void querystring_cb(const char *name, const char *value) ctx.qry.head = xstrdup(value); ctx.qry.has_symref = 1; } else if (!strcmp(name, "id")) { - ctx.qry.sha1 = xstrdup(value); - ctx.qry.has_sha1 = 1; + ctx.qry.oid = xstrdup(value); + ctx.qry.has_oid = 1; } else if (!strcmp(name, "id2")) { - ctx.qry.sha2 = xstrdup(value); - ctx.qry.has_sha1 = 1; + ctx.qry.oid2 = xstrdup(value); + ctx.qry.has_oid = 1; } else if (!strcmp(name, "ofs")) { ctx.qry.ofs = atoi(value); } else if (!strcmp(name, "path")) { @@ -992,9 +992,9 @@ static void cgit_parse_args(int argc, const char **argv) } else if (skip_prefix(argv[i], "--head=", &arg)) { ctx.qry.head = xstrdup(arg); ctx.qry.has_symref = 1; - } else if (skip_prefix(argv[i], "--sha1=", &arg)) { - ctx.qry.sha1 = xstrdup(arg); - ctx.qry.has_sha1 = 1; + } else if (skip_prefix(argv[i], "--oid=", &arg)) { + ctx.qry.oid = xstrdup(arg); + ctx.qry.has_oid = 1; } else if (skip_prefix(argv[i], "--ofs=", &arg)) { ctx.qry.ofs = atoi(arg); } else if (skip_prefix(argv[i], "--scan-tree=", &arg) || @@ -1037,7 +1037,7 @@ static int calc_ttl(void) if (!strcmp(ctx.qry.page, "snapshot")) return ctx.cfg.cache_snapshot_ttl; - if (ctx.qry.has_sha1) + if (ctx.qry.has_oid) return ctx.cfg.cache_static_ttl; if (ctx.qry.has_symref) diff --git a/cgit.css b/cgit.css index d4aadbf..dfa144d 100644 --- a/cgit.css +++ b/cgit.css @@ -561,7 +561,7 @@ div#cgit table.diff td div.del { color: red; } -div#cgit .sha1 { +div#cgit .oid { font-family: monospace; font-size: 90%; } diff --git a/cgit.h b/cgit.h index f5db364..69b5c13 100644 --- a/cgit.h +++ b/cgit.h @@ -164,7 +164,7 @@ struct reflist { struct cgit_query { int has_symref; - int has_sha1; + int has_oid; int has_difftype; char *raw; char *repo; @@ -172,8 +172,8 @@ struct cgit_query { char *search; char *grep; char *head; - char *sha1; - char *sha2; + char *oid; + char *oid2; char *path; char *name; char *url; diff --git a/cmd.c b/cmd.c index bf6d8f5..0eb75b1 100644 --- a/cmd.c +++ b/cmd.c @@ -74,22 +74,22 @@ static void blame_fn(void) static void blob_fn(void) { - cgit_print_blob(ctx.qry.sha1, ctx.qry.path, ctx.qry.head, 0); + cgit_print_blob(ctx.qry.oid, ctx.qry.path, ctx.qry.head, 0); } static void commit_fn(void) { - cgit_print_commit(ctx.qry.sha1, ctx.qry.path); + cgit_print_commit(ctx.qry.oid, ctx.qry.path); } static void diff_fn(void) { - cgit_print_diff(ctx.qry.sha1, ctx.qry.sha2, ctx.qry.path, 1, 0); + cgit_print_diff(ctx.qry.oid, ctx.qry.oid2, ctx.qry.path, 1, 0); } static void rawdiff_fn(void) { - cgit_print_diff(ctx.qry.sha1, ctx.qry.sha2, ctx.qry.path, 1, 1); + cgit_print_diff(ctx.qry.oid, ctx.qry.oid2, ctx.qry.path, 1, 1); } static void info_fn(void) @@ -99,7 +99,7 @@ static void info_fn(void) static void log_fn(void) { - cgit_print_log(ctx.qry.sha1, ctx.qry.ofs, ctx.cfg.max_commit_count, + cgit_print_log(ctx.qry.oid, ctx.qry.ofs, ctx.cfg.max_commit_count, ctx.qry.grep, ctx.qry.search, ctx.qry.path, 1, ctx.repo->enable_commit_graph, ctx.repo->commit_sort); @@ -125,7 +125,7 @@ static void repolist_fn(void) static void patch_fn(void) { - cgit_print_patch(ctx.qry.sha1, ctx.qry.sha2, ctx.qry.path); + cgit_print_patch(ctx.qry.oid, ctx.qry.oid2, ctx.qry.path); } static void plain_fn(void) @@ -140,7 +140,7 @@ static void refs_fn(void) static void snapshot_fn(void) { - cgit_print_snapshot(ctx.qry.head, ctx.qry.sha1, ctx.qry.path, + cgit_print_snapshot(ctx.qry.head, ctx.qry.oid, ctx.qry.path, ctx.qry.nohead); } @@ -156,12 +156,12 @@ static void summary_fn(void) static void tag_fn(void) { - cgit_print_tag(ctx.qry.sha1); + cgit_print_tag(ctx.qry.oid); } static void tree_fn(void) { - cgit_print_tree(ctx.qry.sha1, ctx.qry.path); + cgit_print_tree(ctx.qry.oid, ctx.qry.path); } #define def_cmd(name, want_repo, want_vpath, is_clone) \ diff --git a/parsing.c b/parsing.c index 93b4767..e647dba 100644 --- a/parsing.c +++ b/parsing.c @@ -127,7 +127,7 @@ static int end_of_header(const char *p) struct commitinfo *cgit_parse_commit(struct commit *commit) { - const int sha1hex_len = 40; + const int oid_hex_len = 40; struct commitinfo *ret; const char *p = repo_get_commit_buffer(the_repository, commit, NULL); const char *t; @@ -140,10 +140,10 @@ struct commitinfo *cgit_parse_commit(struct commit *commit) if (!skip_prefix(p, "tree ", &p)) die("Bad commit: %s", oid_to_hex(&commit->object.oid)); - p += sha1hex_len + 1; + p += oid_hex_len + 1; while (skip_prefix(p, "parent ", &p)) - p += sha1hex_len + 1; + p += oid_hex_len + 1; if (p && skip_prefix(p, "author ", &p)) { parse_user(p, &ret->author, &ret->author_email, diff --git a/tests/t0001-validate-git-versions.sh b/tests/t0001-validate-git-versions.sh index 73bd32f..dd84fe3 100755 --- a/tests/t0001-validate-git-versions.sh +++ b/tests/t0001-validate-git-versions.sh @@ -33,10 +33,10 @@ test_expect_success 'test submodule version matches Makefile' ' else ( cd ../.. && - sm_sha1=$(git ls-files --stage -- git | + sm_oid=$(git ls-files --stage -- git | sed -e "s/^[0-9]* \\([0-9a-f]*\\) [0-9] .*$/\\1/") && cd git && - git describe --match "v[0-9]*" $sm_sha1 + git describe --match "v[0-9]*" $sm_oid ) | sed -e "s/^v//" -e "s/-/./" >sm_version && test_cmp sm_version makefile_version fi diff --git a/ui-blame.c b/ui-blame.c index c3662bb..cfab7fb 100644 --- a/ui-blame.c +++ b/ui-blame.c @@ -48,7 +48,7 @@ static void emit_blame_entry_hash(struct blame_entry *ent) unsigned long line = 0; char *detail = emit_suspect_detail(suspect); - html("<span class='sha1'>"); + html("<span class='oid'>"); cgit_commit_link(find_unique_abbrev(oid, DEFAULT_ABBREV), detail, NULL, ctx.qry.head, oid_to_hex(oid), suspect->path); html("</span>"); @@ -256,7 +256,7 @@ static int basedir_len(const char *path) void cgit_print_blame(void) { - const char *rev = ctx.qry.sha1; + const char *rev = ctx.qry.oid; struct object_id oid; struct commit *commit; struct pathspec_item path_items = { diff --git a/ui-commit.c b/ui-commit.c index 783211f..948118c 100644 --- a/ui-commit.c +++ b/ui-commit.c @@ -70,13 +70,13 @@ void cgit_print_commit(char *hex, const char *prefix) html_txt(show_date(info->committer_date, info->committer_tz, cgit_date_mode(DATE_ISO8601))); html("</td></tr>\n"); - html("<tr><th>commit</th><td colspan='2' class='sha1'>"); + html("<tr><th>commit</th><td colspan='2' class='oid'>"); tmp = oid_to_hex(&commit->object.oid); cgit_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp, prefix); html(" ("); cgit_patch_link("patch", NULL, NULL, NULL, tmp, prefix); html(")</td></tr>\n"); - html("<tr><th>tree</th><td colspan='2' class='sha1'>"); + html("<tr><th>tree</th><td colspan='2' class='oid'>"); tmp = xstrdup(hex); cgit_tree_link(oid_to_hex(get_commit_tree_oid(commit)), NULL, NULL, ctx.qry.head, tmp, NULL); @@ -95,7 +95,7 @@ void cgit_print_commit(char *hex, const char *prefix) continue; } html("<tr><th>parent</th>" - "<td colspan='2' class='sha1'>"); + "<td colspan='2' class='oid'>"); tmp = tmp2 = oid_to_hex(&p->item->object.oid); if (ctx.repo->enable_subject_links) { parent_info = cgit_parse_commit(parent); @@ -109,7 +109,7 @@ void cgit_print_commit(char *hex, const char *prefix) parents++; } if (ctx.repo->snapshots) { - html("<tr><th>download</th><td colspan='2' class='sha1'>"); + html("<tr><th>download</th><td colspan='2' class='oid'>"); cgit_print_snapshot_links(ctx.repo, hex, "<br/>"); html("</td></tr>"); } @@ -139,7 +139,7 @@ void cgit_print_commit(char *hex, const char *prefix) tmp = oid_to_hex(&commit->parents->item->object.oid); else tmp = NULL; - cgit_print_diff(ctx.qry.sha1, tmp, prefix, 0, 0); + cgit_print_diff(ctx.qry.oid, tmp, prefix, 0, 0); } strbuf_release(¬es); cgit_free_commitinfo(info); diff --git a/ui-diff.c b/ui-diff.c index 329c350..5ed5990 100644 --- a/ui-diff.c +++ b/ui-diff.c @@ -97,8 +97,8 @@ static void print_fileinfo(struct fileinfo *info) html("]</span>"); } htmlf("</td><td class='%s'>", class); - cgit_diff_link(info->new_path, NULL, NULL, ctx.qry.head, ctx.qry.sha1, - ctx.qry.sha2, info->new_path); + cgit_diff_link(info->new_path, NULL, NULL, ctx.qry.head, ctx.qry.oid, + ctx.qry.oid2, info->new_path); if (info->status == DIFF_STATUS_COPIED || info->status == DIFF_STATUS_RENAMED) { htmlf(" (%s from ", info->status == DIFF_STATUS_COPIED ? "copied" : "renamed"); @@ -194,8 +194,8 @@ static void cgit_print_diffstat(const struct object_id *old_oid, int i; html("<div class='diffstat-header'>"); - cgit_diff_link("Diffstat", NULL, NULL, ctx.qry.head, ctx.qry.sha1, - ctx.qry.sha2, NULL); + cgit_diff_link("Diffstat", NULL, NULL, ctx.qry.head, ctx.qry.oid, + ctx.qry.oid2, NULL); if (prefix) { html(" (limited to '"); html_txt(prefix); diff --git a/ui-log.c b/ui-log.c index fd07409..6914f75 100644 --- a/ui-log.c +++ b/ui-log.c @@ -463,7 +463,7 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern if (pager) { html(" ("); cgit_log_link(ctx.qry.showmsg ? "Collapse" : "Expand", NULL, - NULL, ctx.qry.head, ctx.qry.sha1, + NULL, ctx.qry.head, ctx.qry.oid, ctx.qry.vpath, ctx.qry.ofs, ctx.qry.grep, ctx.qry.search, ctx.qry.showmsg ? 0 : 1, ctx.qry.follow); @@ -519,7 +519,7 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern if (ofs > 0) { html("<li>"); cgit_log_link("[prev]", NULL, NULL, ctx.qry.head, - ctx.qry.sha1, ctx.qry.vpath, + ctx.qry.oid, ctx.qry.vpath, ofs - cnt, ctx.qry.grep, ctx.qry.search, ctx.qry.showmsg, ctx.qry.follow); @@ -528,7 +528,7 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern if ((commit = get_revision(&rev)) != NULL) { html("<li>"); cgit_log_link("[next]", NULL, NULL, ctx.qry.head, - ctx.qry.sha1, ctx.qry.vpath, + ctx.qry.oid, ctx.qry.vpath, ofs + cnt, ctx.qry.grep, ctx.qry.search, ctx.qry.showmsg, ctx.qry.follow); diff --git a/ui-plain.c b/ui-plain.c index 2a7b18c..001001c 100644 --- a/ui-plain.c +++ b/ui-plain.c @@ -99,7 +99,7 @@ static void print_dir(const struct object_id *oid, const char *base, fullpath = NULL; } html("<li>"); - cgit_plain_link("../", NULL, NULL, ctx.qry.head, ctx.qry.sha1, + cgit_plain_link("../", NULL, NULL, ctx.qry.head, ctx.qry.oid, fullpath); html("</li>\n"); } @@ -118,7 +118,7 @@ static void print_dir_entry(const struct object_id *oid, const char *base, if (S_ISGITLINK(mode)) { cgit_submodule_link(NULL, fullpath, oid_to_hex(oid)); } else - cgit_plain_link(path, NULL, NULL, ctx.qry.head, ctx.qry.sha1, + cgit_plain_link(path, NULL, NULL, ctx.qry.head, ctx.qry.oid, fullpath); html("</li>\n"); free(fullpath); @@ -163,7 +163,7 @@ static int basedir_len(const char *path) void cgit_print_plain(void) { - const char *rev = ctx.qry.sha1; + const char *rev = ctx.qry.oid; struct object_id oid; struct commit *commit; struct pathspec_item path_items = { diff --git a/ui-shared.c b/ui-shared.c index d2358f2..151ac17 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -521,45 +521,45 @@ static void cgit_self_link(char *name, const char *title, const char *class) else if (!strcmp(ctx.qry.page, "summary")) cgit_summary_link(name, title, class, ctx.qry.head); else if (!strcmp(ctx.qry.page, "tag")) - cgit_tag_link(name, title, class, ctx.qry.has_sha1 ? - ctx.qry.sha1 : ctx.qry.head); + cgit_tag_link(name, title, class, ctx.qry.has_oid ? + ctx.qry.oid : ctx.qry.head); else if (!strcmp(ctx.qry.page, "tree")) cgit_tree_link(name, title, class, ctx.qry.head, - ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL, + ctx.qry.has_oid ? ctx.qry.oid : NULL, ctx.qry.path); else if (!strcmp(ctx.qry.page, "plain")) cgit_plain_link(name, title, class, ctx.qry.head, - ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL, + ctx.qry.has_oid ? ctx.qry.oid : NULL, ctx.qry.path); else if (!strcmp(ctx.qry.page, "blame")) cgit_blame_link(name, title, class, ctx.qry.head, - ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL, + ctx.qry.has_oid ? ctx.qry.oid : NULL, ctx.qry.path); else if (!strcmp(ctx.qry.page, "log")) cgit_log_link(name, title, class, ctx.qry.head, - ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL, + ctx.qry.has_oid ? ctx.qry.oid : NULL, ctx.qry.path, ctx.qry.ofs, ctx.qry.grep, ctx.qry.search, ctx.qry.showmsg, ctx.qry.follow); else if (!strcmp(ctx.qry.page, "commit")) cgit_commit_link(name, title, class, ctx.qry.head, - ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL, + ctx.qry.has_oid ? ctx.qry.oid : NULL, ctx.qry.path); else if (!strcmp(ctx.qry.page, "patch")) cgit_patch_link(name, title, class, ctx.qry.head, - ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL, + ctx.qry.has_oid ? ctx.qry.oid : NULL, ctx.qry.path); else if (!strcmp(ctx.qry.page, "refs")) cgit_refs_link(name, title, class, ctx.qry.head, - ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL, + ctx.qry.has_oid ? ctx.qry.oid : NULL, ctx.qry.path); else if (!strcmp(ctx.qry.page, "snapshot")) cgit_snapshot_link(name, title, class, ctx.qry.head, - ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL, + ctx.qry.has_oid ? ctx.qry.oid : NULL, ctx.qry.path); else if (!strcmp(ctx.qry.page, "diff")) cgit_diff_link(name, title, class, ctx.qry.head, - ctx.qry.sha1, ctx.qry.sha2, + ctx.qry.oid, ctx.qry.oid2, ctx.qry.path); else if (!strcmp(ctx.qry.page, "stats")) cgit_stats_link(name, title, class, ctx.qry.head, @@ -918,10 +918,10 @@ void cgit_add_hidden_formfields(int incl_head, int incl_search, strcmp(ctx.qry.head, ctx.repo->defbranch)) html_hidden("h", ctx.qry.head); - if (ctx.qry.sha1) - html_hidden("id", ctx.qry.sha1); - if (ctx.qry.sha2) - html_hidden("id2", ctx.qry.sha2); + if (ctx.qry.oid) + html_hidden("id", ctx.qry.oid); + if (ctx.qry.oid2) + html_hidden("id2", ctx.qry.oid2); if (ctx.qry.showmsg) html_hidden("showmsg", "1"); @@ -1038,20 +1038,20 @@ void cgit_print_pageheader(void) cgit_summary_link("summary", NULL, hc("summary"), ctx.qry.head); cgit_refs_link("refs", NULL, hc("refs"), ctx.qry.head, - ctx.qry.sha1, NULL); + ctx.qry.oid, NULL); cgit_log_link("log", NULL, hc("log"), ctx.qry.head, NULL, ctx.qry.vpath, 0, NULL, NULL, ctx.qry.showmsg, ctx.qry.follow); if (ctx.qry.page && !strcmp(ctx.qry.page, "blame")) cgit_blame_link("blame", NULL, hc("blame"), ctx.qry.head, - ctx.qry.sha1, ctx.qry.vpath); + ctx.qry.oid, ctx.qry.vpath); else cgit_tree_link("tree", NULL, hc("tree"), ctx.qry.head, - ctx.qry.sha1, ctx.qry.vpath); + ctx.qry.oid, ctx.qry.vpath); cgit_commit_link("commit", NULL, hc("commit"), - ctx.qry.head, ctx.qry.sha1, ctx.qry.vpath); + ctx.qry.head, ctx.qry.oid, ctx.qry.vpath); cgit_diff_link("diff", NULL, hc("diff"), ctx.qry.head, - ctx.qry.sha1, ctx.qry.sha2, ctx.qry.vpath); + ctx.qry.oid, ctx.qry.oid2, ctx.qry.vpath); if (ctx.repo->max_stats) cgit_stats_link("stats", NULL, hc("stats"), ctx.qry.head, ctx.qry.vpath); diff --git a/ui-tag.c b/ui-tag.c index 846d5b1..424bbcc 100644 --- a/ui-tag.c +++ b/ui-tag.c @@ -33,7 +33,7 @@ static void print_tag_content(char *buf) static void print_download_links(char *revname) { - html("<tr><th>download</th><td class='sha1'>"); + html("<tr><th>download</th><td class='oid'>"); cgit_print_snapshot_links(ctx.repo, revname, "<br/>"); html("</td></tr>"); } @@ -91,7 +91,7 @@ void cgit_print_tag(char *revname) cgit_close_filter(ctx.repo->email_filter); html("</td></tr>\n"); } - html("<tr><td>tagged object</td><td class='sha1'>"); + html("<tr><td>tagged object</td><td class='oid'>"); cgit_object_link(tag->tagged); html("</td></tr>\n"); if (ctx.repo->snapshots) @@ -106,7 +106,7 @@ void cgit_print_tag(char *revname) html("<tr><td>tag name</td><td>"); html_txt(revname); html("</td></tr>\n"); - html("<tr><td>tagged object</td><td class='sha1'>"); + html("<tr><td>tagged object</td><td class='oid'>"); cgit_object_link(obj); html("</td></tr>\n"); if (ctx.repo->snapshots) From a4de0e810b69710c3b32f6d253d80d16dec09f36 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Tue, 20 Oct 2020 23:46:09 +0200 Subject: [PATCH 323/387] global: replace hard coded hash length With sha1 we had a guaranteed length of 40 hex chars. This changes now that we have to support sha256 with 64 hex chars... Support both. Signed-off-by: Christian Hesse <mail@eworm.de> --- filters/commit-links.sh | 2 +- parsing.c | 5 ++--- tests/t0105-commit.sh | 2 +- ui-patch.c | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/filters/commit-links.sh b/filters/commit-links.sh index 5881952..796ac30 100755 --- a/filters/commit-links.sh +++ b/filters/commit-links.sh @@ -19,7 +19,7 @@ regex='' # This expression generates links to commits referenced by their SHA1. regex=$regex' -s|\b([0-9a-fA-F]{7,40})\b|<a href="./?id=\1">\1</a>|g' +s|\b([0-9a-fA-F]{7,64})\b|<a href="./?id=\1">\1</a>|g' # This expression generates links to a fictional bugtracker. regex=$regex' diff --git a/parsing.c b/parsing.c index e647dba..72b59b3 100644 --- a/parsing.c +++ b/parsing.c @@ -127,7 +127,6 @@ static int end_of_header(const char *p) struct commitinfo *cgit_parse_commit(struct commit *commit) { - const int oid_hex_len = 40; struct commitinfo *ret; const char *p = repo_get_commit_buffer(the_repository, commit, NULL); const char *t; @@ -140,10 +139,10 @@ struct commitinfo *cgit_parse_commit(struct commit *commit) if (!skip_prefix(p, "tree ", &p)) die("Bad commit: %s", oid_to_hex(&commit->object.oid)); - p += oid_hex_len + 1; + p += the_hash_algo->hexsz + 1; while (skip_prefix(p, "parent ", &p)) - p += oid_hex_len + 1; + p += the_hash_algo->hexsz + 1; if (p && skip_prefix(p, "author ", &p)) { parse_user(p, &ret->author, &ret->author_email, diff --git a/tests/t0105-commit.sh b/tests/t0105-commit.sh index 9cdf55c..1a12ee3 100755 --- a/tests/t0105-commit.sh +++ b/tests/t0105-commit.sh @@ -25,7 +25,7 @@ test_expect_success 'get root commit' ' ' test_expect_success 'root commit contains diffstat' ' - grep "<a href=./foo/diff/file-1.id=[0-9a-f]\{40\}.>file-1</a>" tmp + grep "<a href=./foo/diff/file-1.id=[0-9a-f]\{40,64\}.>file-1</a>" tmp ' test_expect_success 'root commit contains diff' ' diff --git a/ui-patch.c b/ui-patch.c index 5a96410..4ac03cb 100644 --- a/ui-patch.c +++ b/ui-patch.c @@ -61,7 +61,7 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, } if (is_null_oid(&old_rev_oid)) { - memcpy(rev_range, oid_to_hex(&new_rev_oid), GIT_SHA1_HEXSZ + 1); + memcpy(rev_range, oid_to_hex(&new_rev_oid), the_hash_algo->hexsz + 1); } else { xsnprintf(rev_range, REV_RANGE_LEN, "%s..%s", oid_to_hex(&old_rev_oid), oid_to_hex(&new_rev_oid)); From a1039ab17591cc531c877bc693088fd2e45c97ff Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Wed, 21 Oct 2020 21:31:52 +0200 Subject: [PATCH 324/387] tests: do not copy snapshots to /tmp/ No idea why this was added... Possibly to inspect the snapshot manually? Let's drop it. Signed-off-by: Christian Hesse <mail@eworm.de> --- tests/t0107-snapshot.sh | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/tests/t0107-snapshot.sh b/tests/t0107-snapshot.sh index c164d3e..89b9159 100755 --- a/tests/t0107-snapshot.sh +++ b/tests/t0107-snapshot.sh @@ -61,8 +61,7 @@ test_expect_success LZIP 'strip off the header lines' ' ' test_expect_success LZIP 'verify lzip format' ' - lzip --test master.tar.lz && - cp master.tar.lz /tmp/. + lzip --test master.tar.lz ' test_expect_success LZIP 'untar' ' @@ -103,8 +102,7 @@ test_expect_success XZ 'strip off the header lines' ' ' test_expect_success XZ 'verify xz format' ' - xz --test master.tar.xz && - cp master.tar.xz /tmp/. + xz --test master.tar.xz ' test_expect_success XZ 'untar' ' @@ -145,8 +143,7 @@ test_expect_success ZSTD 'strip off the header lines' ' ' test_expect_success ZSTD 'verify zstd format' ' - zstd --test master.tar.zst && - cp master.tar.zst /tmp/. + zstd --test master.tar.zst ' test_expect_success ZSTD 'untar' ' From adcc4f822fe11836e5f942fc1ae0f00db4eb8d5f Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Wed, 21 Oct 2020 22:16:57 +0200 Subject: [PATCH 325/387] tests: try with commit-graph Git 2.24.0 enabled commit-graph by default and caused crashes without necessary update. Let's test to work with commit-graph. Signed-off-by: Christian Hesse <mail@eworm.de> --- tests/setup.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/setup.sh b/tests/setup.sh index 5879348..8db810f 100755 --- a/tests/setup.sh +++ b/tests/setup.sh @@ -80,13 +80,17 @@ mkrepo() { git commit -m "commit $n" n=$(expr $n + 1) done - if test "$3" = "testplus" - then + case "$3" in + testplus) echo "hello" >a+b git add a+b git commit -m "add a+b" git branch "1+2" - fi + ;; + commit-graph) + git commit-graph write + ;; + esac ) } @@ -95,7 +99,7 @@ setup_repos() rm -rf cache mkdir -p cache mkrepo repos/foo 5 >/dev/null - mkrepo repos/bar 50 >/dev/null + mkrepo repos/bar 50 commit-graph >/dev/null mkrepo repos/foo+bar 10 testplus >/dev/null mkrepo "repos/with space" 2 >/dev/null mkrepo repos/filter 5 testplus >/dev/null From fe99c76ee477f91d6d983486491603109c7b2599 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Tue, 27 Oct 2020 10:39:46 +0100 Subject: [PATCH 326/387] git: update to v2.29.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update to git version v2.29.1. No functional change, but we want latest and greated version number, no? 😜 Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index c947b63..eb60388 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.29.0 +GIT_VER = 2.29.1 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index 69986e1..b927c80 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 69986e19ffcfb9af674ae5180689ab7bbf92ed28 +Subproject commit b927c80531cca9b9107754186532e8cb00884008 From b1739247b17524460282f63fa240b3f34501e000 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Fri, 30 Oct 2020 22:22:32 +0100 Subject: [PATCH 327/387] git: update to v2.29.2 Update to git version v2.29.2. No changes required. Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index eb60388..1a8f496 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.29.1 +GIT_VER = 2.29.2 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index b927c80..898f807 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit b927c80531cca9b9107754186532e8cb00884008 +Subproject commit 898f80736c75878acc02dc55672317fcc0e0a5a6 From cef27b670a66c9840bb6120260864e4b3a701dc2 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Mon, 28 Dec 2020 23:27:13 +0100 Subject: [PATCH 328/387] git: update to v2.30.0 Update to git version v2.30.0, this requires changes for these upstream commits: * 88894aaeeae92e8cb41143cc2e045f50289dc790 blame: simplify 'setup_scoreboard' interface * 1fbfdf556f2abc708183caca53ae4e2881b46ae2 banned.h: mark non-reentrant gmtime, etc as banned Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- cache.c | 6 +++--- git | 2 +- ui-blame.c | 3 ++- ui-shared.c | 9 +++++---- ui-stats.c | 48 ++++++++++++++++++++++++------------------------ 6 files changed, 36 insertions(+), 34 deletions(-) diff --git a/Makefile b/Makefile index 1a8f496..6dfc003 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.29.2 +GIT_VER = 2.30.0 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/cache.c b/cache.c index 2c70be7..55199e8 100644 --- a/cache.c +++ b/cache.c @@ -401,12 +401,12 @@ int cache_process(int size, const char *path, const char *key, int ttl, static char *sprintftime(const char *format, time_t time) { static char buf[64]; - struct tm *tm; + struct tm tm; if (!time) return NULL; - tm = gmtime(&time); - strftime(buf, sizeof(buf)-1, format, tm); + gmtime_r(&time, &tm); + strftime(buf, sizeof(buf)-1, format, &tm); return buf; } diff --git a/git b/git index 898f807..71ca53e 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 898f80736c75878acc02dc55672317fcc0e0a5a6 +Subproject commit 71ca53e8125e36efbda17293c50027d31681a41f diff --git a/ui-blame.c b/ui-blame.c index cfab7fb..ec1d888 100644 --- a/ui-blame.c +++ b/ui-blame.c @@ -132,7 +132,8 @@ static void print_object(const struct object_id *oid, const char *path, init_scoreboard(&sb); sb.revs = &revs; sb.repo = the_repository; - setup_scoreboard(&sb, path, &o); + sb.path = path; + setup_scoreboard(&sb, &o); o->suspects = blame_entry_prepend(NULL, 0, sb.num_lines, o); prio_queue_put(&sb.commits, o->commit); blame_origin_decref(o); diff --git a/ui-shared.c b/ui-shared.c index 151ac17..acd8ab5 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -22,10 +22,11 @@ static char *http_date(time_t t) static char month[][4] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; - struct tm *tm = gmtime(&t); - return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday], - tm->tm_mday, month[tm->tm_mon], 1900 + tm->tm_year, - tm->tm_hour, tm->tm_min, tm->tm_sec); + struct tm tm; + gmtime_r(&t, &tm); + return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm.tm_wday], + tm.tm_mday, month[tm.tm_mon], 1900 + tm.tm_year, + tm.tm_hour, tm.tm_min, tm.tm_sec); } void cgit_print_error(const char *fmt, ...) diff --git a/ui-stats.c b/ui-stats.c index 7272a61..09b3625 100644 --- a/ui-stats.c +++ b/ui-stats.c @@ -166,7 +166,7 @@ static void add_commit(struct string_list *authors, struct commit *commit, struct authorstat *authorstat; struct string_list *items; char *tmp; - struct tm *date; + struct tm date; time_t t; uintptr_t *counter; @@ -180,9 +180,9 @@ static void add_commit(struct string_list *authors, struct commit *commit, authorstat = author->util; items = &authorstat->list; t = info->committer_date; - date = gmtime(&t); - period->trunc(date); - tmp = xstrdup(period->pretty(date)); + gmtime_r(&t, &date); + period->trunc(&date); + tmp = xstrdup(period->pretty(&date)); item = string_list_insert(items, tmp); counter = (uintptr_t *)&item->util; if (*counter) @@ -215,15 +215,15 @@ static struct string_list collect_stats(const struct cgit_period *period) int argc = 3; time_t now; long i; - struct tm *tm; + struct tm tm; char tmp[11]; time(&now); - tm = gmtime(&now); - period->trunc(tm); + gmtime_r(&now, &tm); + period->trunc(&tm); for (i = 1; i < period->count; i++) - period->dec(tm); - strftime(tmp, sizeof(tmp), "%Y-%m-%d", tm); + period->dec(&tm); + strftime(tmp, sizeof(tmp), "%Y-%m-%d", &tm); argv[2] = xstrdup(fmt("--since=%s", tmp)); if (ctx.qry.path) { argv[3] = "--"; @@ -261,21 +261,21 @@ static void print_combined_authorrow(struct string_list *authors, int from, struct string_list_item *date; time_t now; long i, j, total, subtotal; - struct tm *tm; + struct tm tm; char *tmp; time(&now); - tm = gmtime(&now); - period->trunc(tm); + gmtime_r(&now, &tm); + period->trunc(&tm); for (i = 1; i < period->count; i++) - period->dec(tm); + period->dec(&tm); total = 0; htmlf("<tr><td class='%s'>%s</td>", leftclass, fmt(name, to - from + 1)); for (j = 0; j < period->count; j++) { - tmp = period->pretty(tm); - period->inc(tm); + tmp = period->pretty(&tm); + period->inc(&tm); subtotal = 0; for (i = from; i <= to; i++) { author = &authors->items[i]; @@ -300,20 +300,20 @@ static void print_authors(struct string_list *authors, int top, struct string_list_item *date; time_t now; long i, j, total; - struct tm *tm; + struct tm tm; char *tmp; time(&now); - tm = gmtime(&now); - period->trunc(tm); + gmtime_r(&now, &tm); + period->trunc(&tm); for (i = 1; i < period->count; i++) - period->dec(tm); + period->dec(&tm); html("<table class='stats'><tr><th>Author</th>"); for (j = 0; j < period->count; j++) { - tmp = period->pretty(tm); + tmp = period->pretty(&tm); htmlf("<th>%s</th>", tmp); - period->inc(tm); + period->inc(&tm); } html("<th>Total</th></tr>\n"); @@ -329,10 +329,10 @@ static void print_authors(struct string_list *authors, int top, items = &authorstat->list; total = 0; for (j = 0; j < period->count; j++) - period->dec(tm); + period->dec(&tm); for (j = 0; j < period->count; j++) { - tmp = period->pretty(tm); - period->inc(tm); + tmp = period->pretty(&tm); + period->inc(&tm); date = string_list_lookup(items, tmp); if (!date) html("<td>0</td>"); From f69626c68eb64e1a2f6b4ba055409d7205e72757 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" <Jason@zx2c4.com> Date: Fri, 4 Dec 2020 13:13:23 +0100 Subject: [PATCH 329/387] md2html: use sane_lists extension This allows for cleaner nesting semantics and matches github more closely. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- filters/html-converters/md2html | 1 + 1 file changed, 1 insertion(+) diff --git a/filters/html-converters/md2html b/filters/html-converters/md2html index dc20f42..f505cb2 100755 --- a/filters/html-converters/md2html +++ b/filters/html-converters/md2html @@ -301,6 +301,7 @@ markdown.markdownFromFile( "markdown.extensions.fenced_code", "markdown.extensions.codehilite", "markdown.extensions.tables", + "markdown.extensions.sane_lists", TocExtension(anchorlink=True)], extension_configs={ "markdown.extensions.codehilite":{"css_class":"highlight"}}) From bd6f5683f6cde4212364354b3139c1d521f40f39 Mon Sep 17 00:00:00 2001 From: Todd Zullinger <tmz@pobox.com> Date: Tue, 29 Dec 2020 14:18:01 -0500 Subject: [PATCH 330/387] tests: t0107: support older and/or non-GNU tar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The untar tests for various compression algorithms use shortcut options from GNU tar to handle decompression. These options may not be provided by non-GNU tar nor even by slightly older GNU tar versions which ship on many systems. An example of the latter case is the --zstd option. This was added in GNU tar-1.32 (2019-02-23)¹. This version of tar is not provided by CentOS/RHEL, in particular. In Debian, --zstd has been backported to the tar-1.30 release. Avoid the requirement on any specific implementations or versions of tar by piping decompressed output to tar. This is compatible with older GNU tar releases as well as tar implementations from other vendors. (It may also be a slight benefit that this more closely matches what the snapshot creation code does.) ¹ Technically, the --zstd option was first released in tar-1.31 (2019-01-02), but this release was very short-lived and is no longer listed on the GNU Tar release page. Signed-off-by: Todd Zullinger <tmz@pobox.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- tests/t0107-snapshot.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/t0107-snapshot.sh b/tests/t0107-snapshot.sh index 89b9159..0811ec4 100755 --- a/tests/t0107-snapshot.sh +++ b/tests/t0107-snapshot.sh @@ -25,7 +25,7 @@ test_expect_success 'verify gzip format' ' test_expect_success 'untar' ' rm -rf master && - tar -xzf master.tar.gz + gzip -dc master.tar.gz | tar -xf - ' test_expect_success 'count files' ' @@ -66,7 +66,7 @@ test_expect_success LZIP 'verify lzip format' ' test_expect_success LZIP 'untar' ' rm -rf master && - tar --lzip -xf master.tar.lz + lzip -dc master.tar.lz | tar -xf - ' test_expect_success LZIP 'count files' ' @@ -107,7 +107,7 @@ test_expect_success XZ 'verify xz format' ' test_expect_success XZ 'untar' ' rm -rf master && - tar --xz -xf master.tar.xz + xz -dc master.tar.xz | tar -xf - ' test_expect_success XZ 'count files' ' @@ -148,7 +148,7 @@ test_expect_success ZSTD 'verify zstd format' ' test_expect_success ZSTD 'untar' ' rm -rf master && - tar --zstd -xf master.tar.zst + zstd -dc master.tar.zst | tar -xf - ' test_expect_success ZSTD 'count files' ' From 4ffadc1e0c589f9bcfb4a721f5625914ef2d496d Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Wed, 10 Feb 2021 16:13:53 +0100 Subject: [PATCH 331/387] git: update to v2.30.1 Update to git version v2.30.1, no additional changes required. Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 6dfc003..a4e597b 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.30.0 +GIT_VER = 2.30.1 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index 71ca53e..773e25a 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 71ca53e8125e36efbda17293c50027d31681a41f +Subproject commit 773e25afc41b1b6533fa9ae2cd825d0b4a697fad From d889cae811f27a052317ac5aea23890cba414760 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Mon, 15 Mar 2021 22:48:26 +0100 Subject: [PATCH 332/387] git: update to v2.31.0 Update to git version v2.31.0, this requires changes for these upstream commits: * 36a317929b8f0c67d77d54235f2d20751c576cbb refs: switch peel_ref() to peel_iterated_oid() Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- ui-log.c | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index a4e597b..11b437b 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.30.1 +GIT_VER = 2.31.0 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index 773e25a..a5828ae 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 773e25afc41b1b6533fa9ae2cd825d0b4a697fad +Subproject commit a5828ae6b52137b913b978e16cd2334482eb4c1f diff --git a/ui-log.c b/ui-log.c index 6914f75..20774bf 100644 --- a/ui-log.c +++ b/ui-log.c @@ -65,8 +65,9 @@ void show_commit_decorations(struct commit *commit) return; html("<span class='decoration'>"); while (deco) { - struct object_id peeled; + struct object_id oid_tag, peeled; int is_annotated = 0; + strlcpy(buf, prettify_refname(deco->name), sizeof(buf)); switch(deco->type) { case DECORATION_NONE: @@ -79,8 +80,8 @@ void show_commit_decorations(struct commit *commit) ctx.qry.showmsg, 0); break; case DECORATION_REF_TAG: - if (!peel_ref(deco->name, &peeled)) - is_annotated = !oidcmp(&commit->object.oid, &peeled); + if (!read_ref(deco->name, &oid_tag) && !peel_iterated_oid(&oid_tag, &peeled)) + is_annotated = !oideq(&oid_tag, &peeled); cgit_tag_link(buf, NULL, is_annotated ? "tag-annotated-deco" : "tag-deco", buf); break; case DECORATION_REF_REMOTE: From 62eb8db4527e6803df4a26056db8ab9eaf5a79ba Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Tue, 31 Mar 2020 14:53:42 +0200 Subject: [PATCH 333/387] md2html: use proper formatting for hr This addressed a non-existent background image and made the element invisible. Drop the style and use something sane. Signed-off-by: Christian Hesse <mail@eworm.de> --- filters/html-converters/md2html | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/filters/html-converters/md2html b/filters/html-converters/md2html index f505cb2..59f43a8 100755 --- a/filters/html-converters/md2html +++ b/filters/html-converters/md2html @@ -86,11 +86,7 @@ div#cgit .markdown-body h1 a.toclink, div#cgit .markdown-body h2 a.toclink, div# margin: 15px 0; } .markdown-body hr { - background: transparent url("/dirty-shade.png") repeat-x 0 0; - border: 0 none; - color: #ccc; - height: 4px; - padding: 0; + border: 2px solid #ccc; } .markdown-body>h2:first-child, .markdown-body>h1:first-child, .markdown-body>h1:first-child+h2, .markdown-body>h3:first-child, .markdown-body>h4:first-child, .markdown-body>h5:first-child, .markdown-body>h6:first-child { margin-top: 0; From 6dbbffe01533a91c79c4497c80f46af8e1581e25 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Tue, 18 May 2021 21:54:23 +0200 Subject: [PATCH 334/387] git: update to v2.31.1 Update to git version v2.31.1, no additional changes required. Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 11b437b..abc52bc 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.31.0 +GIT_VER = 2.31.1 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index a5828ae..48bf2fa 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit a5828ae6b52137b913b978e16cd2334482eb4c1f +Subproject commit 48bf2fa8bad054d66bd79c6ba903c89c704201f7 From 5258c297ba6fb604ae1415fbc19a3fe42457e49e Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Tue, 18 May 2021 22:49:13 +0200 Subject: [PATCH 335/387] git: update to v2.32.0 Update to git version v2.32.0, this requires changes for these upstream commits: * 47957485b3b731a7860e0554d2bd12c0dce1c75a tree.h API: simplify read_tree_recursive() signature Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- ui-blame.c | 9 +++------ ui-blob.c | 20 ++++++++------------ ui-plain.c | 7 +++---- ui-tree.c | 21 ++++++++------------- 6 files changed, 24 insertions(+), 37 deletions(-) diff --git a/Makefile b/Makefile index abc52bc..d13c5bd 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.31.1 +GIT_VER = 2.32.0 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index 48bf2fa..ebf3c04 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 48bf2fa8bad054d66bd79c6ba903c89c704201f7 +Subproject commit ebf3c04b262aa27fbb97f8a0156c2347fecafafb diff --git a/ui-blame.c b/ui-blame.c index ec1d888..03136f7 100644 --- a/ui-blame.c +++ b/ui-blame.c @@ -221,8 +221,7 @@ cleanup: } static int walk_tree(const struct object_id *oid, struct strbuf *base, - const char *pathname, unsigned mode, int stage, - void *cbdata) + const char *pathname, unsigned mode, void *cbdata) { struct walk_tree_context *walk_tree_ctx = cbdata; @@ -291,10 +290,8 @@ void cgit_print_blame(void) walk_tree_ctx.match_baselen = (path_items.match) ? basedir_len(path_items.match) : -1; - read_tree_recursive(the_repository, - repo_get_commit_tree(the_repository, commit), - "", 0, 0, - &paths, walk_tree, &walk_tree_ctx); + read_tree(the_repository, repo_get_commit_tree(the_repository, commit), + &paths, walk_tree, &walk_tree_ctx); if (!walk_tree_ctx.state) cgit_print_error_page(404, "Not found", "Not found"); else if (walk_tree_ctx.state == 2) diff --git a/ui-blob.c b/ui-blob.c index f76c641..c10ae42 100644 --- a/ui-blob.c +++ b/ui-blob.c @@ -19,7 +19,7 @@ struct walk_tree_context { }; static int walk_tree(const struct object_id *oid, struct strbuf *base, - const char *pathname, unsigned mode, int stage, void *cbdata) + const char *pathname, unsigned mode, void *cbdata) { struct walk_tree_context *walk_tree_ctx = cbdata; @@ -56,9 +56,9 @@ int cgit_ref_path_exists(const char *path, const char *ref, int file_only) goto done; if (oid_object_info(the_repository, &oid, &size) != OBJ_COMMIT) goto done; - read_tree_recursive(the_repository, - repo_get_commit_tree(the_repository, lookup_commit_reference(the_repository, &oid)), - "", 0, 0, &paths, walk_tree, &walk_tree_ctx); + read_tree(the_repository, + repo_get_commit_tree(the_repository, lookup_commit_reference(the_repository, &oid)), + &paths, walk_tree, &walk_tree_ctx); done: free(path_items.match); @@ -92,10 +92,8 @@ int cgit_print_file(char *path, const char *head, int file_only) type = oid_object_info(the_repository, &oid, &size); if (type == OBJ_COMMIT) { commit = lookup_commit_reference(the_repository, &oid); - read_tree_recursive(the_repository, - repo_get_commit_tree(the_repository, commit), - "", 0, 0, &paths, walk_tree, - &walk_tree_ctx); + read_tree(the_repository, repo_get_commit_tree(the_repository, commit), + &paths, walk_tree, &walk_tree_ctx); if (!walk_tree_ctx.found_path) return -1; type = oid_object_info(the_repository, &oid, &size); @@ -151,10 +149,8 @@ void cgit_print_blob(const char *hex, char *path, const char *head, int file_onl if ((!hex) && type == OBJ_COMMIT && path) { commit = lookup_commit_reference(the_repository, &oid); - read_tree_recursive(the_repository, - repo_get_commit_tree(the_repository, commit), - "", 0, 0, &paths, walk_tree, - &walk_tree_ctx); + read_tree(the_repository, repo_get_commit_tree(the_repository, commit), + &paths, walk_tree, &walk_tree_ctx); type = oid_object_info(the_repository, &oid, &size); } diff --git a/ui-plain.c b/ui-plain.c index 001001c..65a205f 100644 --- a/ui-plain.c +++ b/ui-plain.c @@ -130,7 +130,7 @@ static void print_dir_tail(void) } static int walk_tree(const struct object_id *oid, struct strbuf *base, - const char *pathname, unsigned mode, int stage, void *cbdata) + const char *pathname, unsigned mode, void *cbdata) { struct walk_tree_context *walk_tree_ctx = cbdata; @@ -198,9 +198,8 @@ void cgit_print_plain(void) } else walk_tree_ctx.match_baselen = basedir_len(path_items.match); - read_tree_recursive(the_repository, - repo_get_commit_tree(the_repository, commit), - "", 0, 0, &paths, walk_tree, &walk_tree_ctx); + read_tree(the_repository, repo_get_commit_tree(the_repository, commit), + &paths, walk_tree, &walk_tree_ctx); if (!walk_tree_ctx.match) cgit_print_error_page(404, "Not found", "Not found"); else if (walk_tree_ctx.match == 2) diff --git a/ui-tree.c b/ui-tree.c index 1e4efb2..b61f6f5 100644 --- a/ui-tree.c +++ b/ui-tree.c @@ -139,8 +139,7 @@ struct single_tree_ctx { }; static int single_tree_cb(const struct object_id *oid, struct strbuf *base, - const char *pathname, unsigned mode, int stage, - void *cbdata) + const char *pathname, unsigned mode, void *cbdata) { struct single_tree_ctx *ctx = cbdata; @@ -185,8 +184,7 @@ static void write_tree_link(const struct object_id *oid, char *name, tree_ctx.name = NULL; tree_ctx.count = 0; - read_tree_recursive(the_repository, tree, "", 0, 1, - &paths, single_tree_cb, &tree_ctx); + read_tree(the_repository, tree, &paths, single_tree_cb, &tree_ctx); if (tree_ctx.count != 1) break; @@ -199,7 +197,7 @@ static void write_tree_link(const struct object_id *oid, char *name, } static int ls_item(const struct object_id *oid, struct strbuf *base, - const char *pathname, unsigned mode, int stage, void *cbdata) + const char *pathname, unsigned mode, void *cbdata) { struct walk_tree_context *walk_tree_ctx = cbdata; char *name; @@ -294,14 +292,13 @@ static void ls_tree(const struct object_id *oid, const char *path, struct walk_t } ls_head(); - read_tree_recursive(the_repository, tree, "", 0, 1, - &paths, ls_item, walk_tree_ctx); + read_tree(the_repository, tree, &paths, ls_item, walk_tree_ctx); ls_tail(); } static int walk_tree(const struct object_id *oid, struct strbuf *base, - const char *pathname, unsigned mode, int stage, void *cbdata) + const char *pathname, unsigned mode, void *cbdata) { struct walk_tree_context *walk_tree_ctx = cbdata; @@ -326,7 +323,7 @@ static int walk_tree(const struct object_id *oid, struct strbuf *base, return 0; } } - ls_item(oid, base, pathname, mode, stage, walk_tree_ctx); + ls_item(oid, base, pathname, mode, walk_tree_ctx); return 0; } @@ -374,10 +371,8 @@ void cgit_print_tree(const char *rev, char *path) goto cleanup; } - read_tree_recursive(the_repository, - repo_get_commit_tree(the_repository, commit), - "", 0, 0, - &paths, walk_tree, &walk_tree_ctx); + read_tree(the_repository, repo_get_commit_tree(the_repository, commit), + &paths, walk_tree, &walk_tree_ctx); if (walk_tree_ctx.state == 1) ls_tail(); else if (walk_tree_ctx.state == 2) From 45eff406554f3ff31bdf7d54daae1da5635db72e Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Sun, 8 Aug 2021 17:55:53 +0200 Subject: [PATCH 336/387] git: update to v2.33.0 Update to git version v2.33.0, no additional changes required. Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index d13c5bd..b030ff9 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.32.0 +GIT_VER = 2.33.0 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index ebf3c04..225bc32 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit ebf3c04b262aa27fbb97f8a0156c2347fecafafb +Subproject commit 225bc32a989d7a22fa6addafd4ce7dcd04675dbf From b8f2b675df61e3a4ff4db7073fe7142fc07e8b7a Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Wed, 3 Nov 2021 15:32:17 +0100 Subject: [PATCH 337/387] git: update to v2.34.0 Update to git version v2.34.0, this requires changes for these upstream commits: * abf897bacd2d36b9dbd07c70b4a2f97a084704ee string-list.[ch]: remove string_list_init() compatibility function Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- cgit.c | 2 +- git | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index b030ff9..9153a39 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.33.0 +GIT_VER = 2.34.0 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/cgit.c b/cgit.c index 08d81a1..4b2d86c 100644 --- a/cgit.c +++ b/cgit.c @@ -428,7 +428,7 @@ static void prepare_context(void) ctx.page.modified = time(NULL); ctx.page.expires = ctx.page.modified; ctx.page.etag = NULL; - string_list_init(&ctx.cfg.mimetypes, 1); + string_list_init_dup(&ctx.cfg.mimetypes); if (ctx.env.script_name) ctx.cfg.script_name = xstrdup(ctx.env.script_name); if (ctx.env.query_string) diff --git a/git b/git index 225bc32..cd3e606 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 225bc32a989d7a22fa6addafd4ce7dcd04675dbf +Subproject commit cd3e606211bb1cf8bc57f7d76bab98cc17a150bc From 11be5b8182fc71c00c1c00c693f64c97769d77bb Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Wed, 24 Nov 2021 21:12:12 +0100 Subject: [PATCH 338/387] git: update to v2.34.1 Update to git version v2.34.1, no additional changes required. Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 9153a39..baa7c2d 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.34.0 +GIT_VER = 2.34.1 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index cd3e606..e9d7761 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit cd3e606211bb1cf8bc57f7d76bab98cc17a150bc +Subproject commit e9d7761bb94f20acc98824275e317fa82436c25d From 73e98c16e8c63f0061d2b7e792c3b7d0552c05a9 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Tue, 11 Jan 2022 11:03:29 +0100 Subject: [PATCH 339/387] git: update to v2.35.0 Update to git version v2.35.0, no additional changes required. Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index baa7c2d..e82e328 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.34.1 +GIT_VER = 2.35.0 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index e9d7761..89bece5 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit e9d7761bb94f20acc98824275e317fa82436c25d +Subproject commit 89bece5c8c96f0b962cfc89e63f82d603fd60bed From bbbaa29a96fbeccad7e09702309251bef7905496 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Sat, 29 Jan 2022 10:20:25 +0100 Subject: [PATCH 340/387] git: update to v2.35.1 Update to git version v2.35.1, no additional changes required. Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index e82e328..2d9198d 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.35.0 +GIT_VER = 2.35.1 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index 89bece5..4c53a8c 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 89bece5c8c96f0b962cfc89e63f82d603fd60bed +Subproject commit 4c53a8c20f8984adb226293a3ffd7b88c3f4ac1a From 9761994243a283e1447bdf7f7a11dba9f5f2ddc9 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Tue, 12 Apr 2022 19:01:23 +0200 Subject: [PATCH 341/387] git: update to v2.35.2 Update to git version v2.35.2, no additional changes required. Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 2d9198d..e9c4e39 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.35.1 +GIT_VER = 2.35.2 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index 4c53a8c..53ef17d 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 4c53a8c20f8984adb226293a3ffd7b88c3f4ac1a +Subproject commit 53ef17d3ee0f7fcb151f428ee3bd736b8046825f From cc9b717c875dcd33460b77383b417455b007061e Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Mon, 18 Apr 2022 22:10:41 +0200 Subject: [PATCH 342/387] git: update to v2.35.3 Update to git version v2.35.3, no additional changes required. Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index e9c4e39..de72176 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.35.2 +GIT_VER = 2.35.3 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index 53ef17d..d516b2d 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 53ef17d3ee0f7fcb151f428ee3bd736b8046825f +Subproject commit d516b2db0af2221bd6b13e7347abdcb5830b2829 From bb02e24ec23d7f1893fc746c8199e88ab849cf86 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Mon, 4 Apr 2022 21:00:33 +0200 Subject: [PATCH 343/387] git: update to v2.36.0 Update to git version v2.36.0, this requires changes for these upstream commits: * 95433eeed9eac439eb21eb30105354b15e71302e diff: add ability to insert additional headers for paths Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- ui-log.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index de72176..2509d21 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.35.3 +GIT_VER = 2.36.0 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index d516b2d..6cd33dc 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit d516b2db0af2221bd6b13e7347abdcb5830b2829 +Subproject commit 6cd33dceed60949e2dbc32e3f0f5e67c4c882e1e diff --git a/ui-log.c b/ui-log.c index 20774bf..565929f 100644 --- a/ui-log.c +++ b/ui-log.c @@ -159,7 +159,7 @@ static int show_commit(struct commit *commit, struct rev_info *revs) "", &revs->diffopt); diffcore_std(&revs->diffopt); - found = !diff_queue_is_empty(); + found = !diff_queue_is_empty(&revs->diffopt); saved_fmt = revs->diffopt.output_format; revs->diffopt.output_format = DIFF_FORMAT_CALLBACK; revs->diffopt.format_callback = cgit_diff_tree_cb; From b9ff119549f6018adc54c8447ad87943c6bcb55e Mon Sep 17 00:00:00 2001 From: June McEnroe <june@causal.agency> Date: Tue, 17 May 2022 21:50:53 +0000 Subject: [PATCH 344/387] shared: fix bad free in cgit_diff_tree Since git commit 244c27242f44e6b88e3a381c90bde08d134c274b, > diff.[ch]: have diff_free() call clear_pathspec(opts.pathspec) calling diff_flush calls free(3) on opts.pathspec.items, so it can't be a pointer to a stack variable. Signed-off-by: Christian Hesse <mail@eworm.de> --- shared.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/shared.c b/shared.c index 8115469..0bceb98 100644 --- a/shared.c +++ b/shared.c @@ -341,9 +341,8 @@ void cgit_diff_tree(const struct object_id *old_oid, filepair_fn fn, const char *prefix, int ignorews) { struct diff_options opt; - struct pathspec_item item; + struct pathspec_item *item; - memset(&item, 0, sizeof(item)); diff_setup(&opt); opt.output_format = DIFF_FORMAT_CALLBACK; opt.detect_rename = 1; @@ -354,10 +353,11 @@ void cgit_diff_tree(const struct object_id *old_oid, opt.format_callback = cgit_diff_tree_cb; opt.format_callback_data = fn; if (prefix) { - item.match = xstrdup(prefix); - item.len = strlen(prefix); + item = xcalloc(1, sizeof(*item)); + item->match = xstrdup(prefix); + item->len = strlen(prefix); opt.pathspec.nr = 1; - opt.pathspec.items = &item; + opt.pathspec.items = item; } diff_setup_done(&opt); @@ -367,8 +367,6 @@ void cgit_diff_tree(const struct object_id *old_oid, diff_root_tree_oid(new_oid, "", &opt); diffcore_std(&opt); diff_flush(&opt); - - free(item.match); } void cgit_diff_commit(struct commit *commit, filepair_fn fn, const char *prefix) From bcdfb2197facb8fcd4ec2283bda0905a9169fa45 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Mon, 9 May 2022 09:29:05 +0200 Subject: [PATCH 345/387] git: update to v2.36.1 Update to git version v2.36.1, no additional changes required. Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 2509d21..93a61fd 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.36.0 +GIT_VER = 2.36.1 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index 6cd33dc..e54793a 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 6cd33dceed60949e2dbc32e3f0f5e67c4c882e1e +Subproject commit e54793a95afeea1e10de1e5ad7eab914e7416250 From 2486d70752959f24f50a6399f15bfb9c7640a25b Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Tue, 14 Jun 2022 12:48:56 +0200 Subject: [PATCH 346/387] git: update to v2.37.0 Update to git version v2.37.0, no additional changes required. Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 93a61fd..b4e3f51 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.36.1 +GIT_VER = 2.37.0 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index e54793a..e4a4b31 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit e54793a95afeea1e10de1e5ad7eab914e7416250 +Subproject commit e4a4b31577c7419497ac30cebe30d755b97752c5 From 89ee51712233369e571daf75552166487d9ef9be Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Tue, 12 Jul 2022 21:16:29 +0200 Subject: [PATCH 347/387] git: update to v2.37.1 Update to git version v2.37.1, no additional changes required. Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index b4e3f51..09b0519 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.37.0 +GIT_VER = 2.37.1 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index e4a4b31..bbea4dc 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit e4a4b31577c7419497ac30cebe30d755b97752c5 +Subproject commit bbea4dcf42b28eb7ce64a6306cdde875ae5d09ca From 43df01c10feb1c7deace56e93a43a4fb93b55e27 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Thu, 11 Aug 2022 22:07:02 +0200 Subject: [PATCH 348/387] git: update to v2.37.2 Update to git version v2.37.2, no additional changes required. Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 09b0519..bbd532c 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.37.1 +GIT_VER = 2.37.2 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index bbea4dc..ad60ddd 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit bbea4dcf42b28eb7ce64a6306cdde875ae5d09ca +Subproject commit ad60dddad72dfb8367bd695028b5b8dc6c33661b From e5c868f1098015b877c1c9a4581516bfab00e0a6 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Tue, 30 Aug 2022 22:42:19 +0200 Subject: [PATCH 349/387] git: update to v2.37.3 Update to git version v2.37.3, no additional changes required. Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index bbd532c..6928e16 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.37.2 +GIT_VER = 2.37.3 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index ad60ddd..ac8035a 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit ad60dddad72dfb8367bd695028b5b8dc6c33661b +Subproject commit ac8035a2affdf30f2c691ad760826d955bba0507 From 33efb5fec5b8c6c6f3a02866514945d3d56867e7 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Fri, 16 Sep 2022 11:31:24 +0200 Subject: [PATCH 350/387] git: update to v2.38.0 Update to git version v2.38.0, no additional changes required. Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 6928e16..e71be39 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.37.3 +GIT_VER = 2.38.0 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index ac8035a..3dcec76 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit ac8035a2affdf30f2c691ad760826d955bba0507 +Subproject commit 3dcec76d9df911ed8321007b1d197c1a206dc164 From 6ac984b51df06aae105054ce36e7d0f190564ccd Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Tue, 18 Oct 2022 21:22:41 +0200 Subject: [PATCH 351/387] git: update to v2.38.1 Update to git version v2.38.1, no additional changes required. Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index e71be39..414a724 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.38.0 +GIT_VER = 2.38.1 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index 3dcec76..d5b4139 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 3dcec76d9df911ed8321007b1d197c1a206dc164 +Subproject commit d5b41391a472dcf9486055fd5b8517f893e88daf From 979cf4a753945ef5f3428693863d66eb33be7e2d Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Mon, 12 Dec 2022 16:18:28 +0100 Subject: [PATCH 352/387] git: update to v2.38.2 Update to git version v2.38.2, no additional changes required. Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 414a724..b9bdaf8 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.38.1 +GIT_VER = 2.38.2 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index d5b4139..8706a59 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit d5b41391a472dcf9486055fd5b8517f893e88daf +Subproject commit 8706a59933d09354c5e3eb09a543453655a97183 From e10159691e799d0f31f5314c73f47511cc974f46 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Mon, 12 Dec 2022 16:21:23 +0100 Subject: [PATCH 353/387] git: update to v2.39.0 Update to git version v2.39.0, no additional changes required. Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index b9bdaf8..cd7639c 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.38.2 +GIT_VER = 2.39.0 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index 8706a59..c48035d 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 8706a59933d09354c5e3eb09a543453655a97183 +Subproject commit c48035d29b4e524aed3a32f0403676f0d9128863 From cc6d9cc7fc010db9be6c2d90fd054fb2d189d629 Mon Sep 17 00:00:00 2001 From: June McEnroe <june@causal.agency> Date: Wed, 18 Dec 2019 21:30:12 +0000 Subject: [PATCH 354/387] ui-tree,ui-blame: bail from blame if blob is binary This avoids piping binary blobs through the source-filter. Also prevent robots from crawling it, since it's expensive. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- robots.txt | 1 + ui-blame.c | 4 ++++ ui-tree.c | 6 ++++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/robots.txt b/robots.txt index 4ce948f..1b33266 100644 --- a/robots.txt +++ b/robots.txt @@ -1,3 +1,4 @@ User-agent: * Disallow: /*/snapshot/* +Disallow: /*/blame/* Allow: / diff --git a/ui-blame.c b/ui-blame.c index 03136f7..4adec2b 100644 --- a/ui-blame.c +++ b/ui-blame.c @@ -152,6 +152,10 @@ static void print_object(const struct object_id *oid, const char *path, cgit_tree_link("tree", NULL, NULL, ctx.qry.head, rev, path); html(")\n"); + if (buffer_is_binary(buf, size)) { + html("<div class='error'>blob is binary.</div>"); + goto cleanup; + } if (ctx.cfg.max_blob_size && size / 1024 > ctx.cfg.max_blob_size) { htmlf("<div class='error'>blob size (%ldKB)" " exceeds display size limit (%dKB).</div>", diff --git a/ui-tree.c b/ui-tree.c index b61f6f5..034c4c8 100644 --- a/ui-tree.c +++ b/ui-tree.c @@ -89,6 +89,7 @@ static void print_object(const struct object_id *oid, const char *path, const ch enum object_type type; char *buf; unsigned long size; + bool is_binary; type = oid_object_info(the_repository, oid, &size); if (type == OBJ_BAD) { @@ -103,6 +104,7 @@ static void print_object(const struct object_id *oid, const char *path, const ch "Error reading object %s", oid_to_hex(oid)); return; } + is_binary = buffer_is_binary(buf, size); cgit_set_title_from_path(path); @@ -110,7 +112,7 @@ static void print_object(const struct object_id *oid, const char *path, const ch htmlf("blob: %s (", oid_to_hex(oid)); cgit_plain_link("plain", NULL, NULL, ctx.qry.head, rev, path); - if (ctx.repo->enable_blame) { + if (ctx.repo->enable_blame && !is_binary) { html(") ("); cgit_blame_link("blame", NULL, NULL, ctx.qry.head, rev, path); @@ -123,7 +125,7 @@ static void print_object(const struct object_id *oid, const char *path, const ch return; } - if (buffer_is_binary(buf, size)) + if (is_binary) print_binary_buffer(buf, size); else print_text_buffer(basename, buf, size); From bcffc523669e00abd949778d4defce37532a3855 Mon Sep 17 00:00:00 2001 From: June McEnroe <june@causal.agency> Date: Thu, 19 Dec 2019 21:55:05 +0000 Subject: [PATCH 355/387] ui-tree: show symlink targets in tree listing Add links to symbolic link targets in tree listings, formatted like "ls -l". Path normalization collapses any ".." components of the link. Also fix up memory link on error path. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- ui-tree.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/ui-tree.c b/ui-tree.c index 034c4c8..98ce1ca 100644 --- a/ui-tree.c +++ b/ui-tree.c @@ -204,9 +204,11 @@ static int ls_item(const struct object_id *oid, struct strbuf *base, struct walk_tree_context *walk_tree_ctx = cbdata; char *name; struct strbuf fullpath = STRBUF_INIT; + struct strbuf linkpath = STRBUF_INIT; struct strbuf class = STRBUF_INIT; enum object_type type; unsigned long size = 0; + char *buf; name = xstrdup(pathname); strbuf_addf(&fullpath, "%s%s%s", ctx.qry.path ? ctx.qry.path : "", @@ -218,8 +220,7 @@ static int ls_item(const struct object_id *oid, struct strbuf *base, htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", name, oid_to_hex(oid)); - free(name); - return 0; + goto cleanup; } } @@ -239,6 +240,21 @@ static int ls_item(const struct object_id *oid, struct strbuf *base, cgit_tree_link(name, NULL, class.buf, ctx.qry.head, walk_tree_ctx->curr_rev, fullpath.buf); } + if (S_ISLNK(mode)) { + html(" -> "); + buf = read_object_file(oid, &type, &size); + if (!buf) { + htmlf("Error reading object: %s", oid_to_hex(oid)); + goto cleanup; + } + strbuf_addbuf(&linkpath, &fullpath); + strbuf_addf(&linkpath, "/../%s", buf); + strbuf_normalize_path(&linkpath); + cgit_tree_link(buf, NULL, class.buf, ctx.qry.head, + walk_tree_ctx->curr_rev, linkpath.buf); + free(buf); + strbuf_release(&linkpath); + } htmlf("</td><td class='ls-size'>%li</td>", size); html("<td>"); @@ -255,6 +271,8 @@ static int ls_item(const struct object_id *oid, struct strbuf *base, cgit_blame_link("blame", NULL, "button", ctx.qry.head, walk_tree_ctx->curr_rev, fullpath.buf); html("</td></tr>\n"); + +cleanup: free(name); strbuf_release(&fullpath); strbuf_release(&class); From fd20a5475e33d5b7198cc22b6a5a6940c4a1ac90 Mon Sep 17 00:00:00 2001 From: June McEnroe <june@causal.agency> Date: Fri, 21 Feb 2020 08:07:50 +0000 Subject: [PATCH 356/387] ui-commit: show subject in commit page title Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- ui-commit.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ui-commit.c b/ui-commit.c index 948118c..5e88544 100644 --- a/ui-commit.c +++ b/ui-commit.c @@ -43,6 +43,7 @@ void cgit_print_commit(char *hex, const char *prefix) load_ref_decorations(NULL, DECORATE_FULL_REFS); + ctx.page.title = fmtalloc("%s - %s", info->subject, ctx.page.title); cgit_print_layout_start(); cgit_print_diff_ctrls(); html("<table summary='commit info' class='commit-info'>\n"); From afffc3e772a7b0c9d729f330ef2c9900c4343b63 Mon Sep 17 00:00:00 2001 From: Chris Mayo <aklhfex@gmail.com> Date: Fri, 15 Mar 2019 20:17:05 +0000 Subject: [PATCH 357/387] ui-repolist,ui-shared: remove redundant title on repo anchors The title attribute was being set to the same value as the anchor element text. Signed-off-by: Chris Mayo <aklhfex@gmail.com> Reviewed-by: Eric Wong <e@80x24.org> Reviewed-by: Petr Vorel <petr.vorel@gmail.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- ui-repolist.c | 2 +- ui-shared.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ui-repolist.c b/ui-repolist.c index 529a203..d12e3dd 100644 --- a/ui-repolist.c +++ b/ui-repolist.c @@ -321,7 +321,7 @@ void cgit_print_repolist(void) } htmlf("<tr><td class='%s'>", !sorted && section ? "sublevel-repo" : "toplevel-repo"); - cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL); + cgit_summary_link(ctx.repo->name, NULL, NULL, NULL); html("</td><td>"); repourl = cgit_repourl(ctx.repo->url); html_link_open(repourl, NULL, NULL); diff --git a/ui-shared.c b/ui-shared.c index acd8ab5..f880c4e 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -995,7 +995,7 @@ static void print_header(void) if (ctx.repo) { cgit_index_link("index", NULL, NULL, NULL, NULL, 0, 1); html(" : "); - cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL); + cgit_summary_link(ctx.repo->name, NULL, NULL, NULL); if (ctx.env.authenticated) { html("</td><td class='form'>"); html("<form method='get'>\n"); From e32f8416e87503aef2cd2698e15f3dc5e8c40d7e Mon Sep 17 00:00:00 2001 From: Chris Mayo <aklhfex@gmail.com> Date: Sun, 26 May 2019 17:57:01 +0100 Subject: [PATCH 358/387] ui-commit: use git raw note format Currently a commit note is shown as: Notes Notes: <note text> Change to: Notes <note text> Signed-off-by: Chris Mayo <aklhfex@gmail.com> Reviewed-by: Alyssa Ross <hi@alyssa.is> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- ui-commit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui-commit.c b/ui-commit.c index 5e88544..0787237 100644 --- a/ui-commit.c +++ b/ui-commit.c @@ -39,7 +39,7 @@ void cgit_print_commit(char *hex, const char *prefix) } info = cgit_parse_commit(commit); - format_display_notes(&oid, ¬es, PAGE_ENCODING, 0); + format_display_notes(&oid, ¬es, PAGE_ENCODING, 1); load_ref_decorations(NULL, DECORATE_FULL_REFS); From 3295155a0caf68d33fecb15f499d205c8e87cd41 Mon Sep 17 00:00:00 2001 From: June McEnroe <june@causal.agency> Date: Thu, 4 Feb 2021 17:10:14 -0500 Subject: [PATCH 359/387] ui-shared: use owner-filter for repo page headers Previously it was only used if owners were displayed on the index. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- ui-shared.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ui-shared.c b/ui-shared.c index f880c4e..fbf5a2d 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -1016,7 +1016,13 @@ static void print_header(void) if (ctx.repo) { html_txt(ctx.repo->desc); html("</td><td class='sub right'>"); - html_txt(ctx.repo->owner); + if (ctx.repo->owner_filter) { + cgit_open_filter(ctx.repo->owner_filter); + html_txt(ctx.repo->owner); + cgit_close_filter(ctx.repo->owner_filter); + } else { + html_txt(ctx.repo->owner); + } } else { if (ctx.cfg.root_desc) html_txt(ctx.cfg.root_desc); From 4e4b30effb773e8cb0c9c23fd664a11bbe5b4076 Mon Sep 17 00:00:00 2001 From: June McEnroe <june@causal.agency> Date: Tue, 8 Jun 2021 20:21:10 +0000 Subject: [PATCH 360/387] ui-atom: generate valid Atom feeds Fixes several RFC 4287 violations: > 4.1.1. The "atom:feed" Element > o atom:feed elements MUST contain exactly one atom:id element. > o atom:feed elements SHOULD contain one atom:link element with a rel > attribute value of "self". This is the preferred URI for > retrieving Atom Feed Documents representing this Atom feed. > o atom:feed elements MUST contain exactly one atom:updated element. An atom:id element is generated from cgit_currentfullurl(), and an atom:link element with a rel attribute of "self" is generated with the same URL. An atom:updated element is generated from the date of the first commit in the revision walk. > 4.1.2. The "atom:entry" Element > o atom:entry elements MUST NOT contain more than one atom:content > element. The second atom:content element with the type of "xhtml" is removed. > 4.2.6. The "atom:id" Element > Its content MUST be an IRI, as defined by [RFC3987]. Note that the > definition of "IRI" excludes relative references. Though the IRI > might use a dereferencable scheme, Atom Processors MUST NOT assume it > can be dereferenced. The atom:id elements for commits now use URNs in the "sha1" or "sha256" namespaces. Although these are not registered URN namespaces, they see use in the wild, for instance as part of magnet URIs. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- ui-atom.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/ui-atom.c b/ui-atom.c index 1056f36..541660d 100644 --- a/ui-atom.c +++ b/ui-atom.c @@ -67,17 +67,12 @@ static void add_entry(struct commit *commit, const char *host) html("'/>\n"); free(pageurl); } - htmlf("<id>%s</id>\n", hex); + html("<id>"); + html_txtf("urn:%s:%s", the_hash_algo->name, hex); + html("</id>\n"); html("<content type='text'>\n"); html_txt(info->msg); html("</content>\n"); - html("<content type='xhtml'>\n"); - html("<div xmlns='http://www.w3.org/1999/xhtml'>\n"); - html("<pre>\n"); - html_txt(info->msg); - html("</pre>\n"); - html("</div>\n"); - html("</content>\n"); html("</entry>\n"); cgit_free_commitinfo(info); } @@ -90,6 +85,7 @@ void cgit_print_atom(char *tip, const char *path, int max_count) struct commit *commit; struct rev_info rev; int argc = 2; + bool first = true; if (ctx.qry.show_all) argv[1] = "--all"; @@ -130,15 +126,28 @@ void cgit_print_atom(char *tip, const char *path, int max_count) html_txt(ctx.repo->desc); html("</subtitle>\n"); if (host) { + char *fullurl = cgit_currentfullurl(); char *repourl = cgit_repourl(ctx.repo->url); - html("<link rel='alternate' type='text/html' href='"); - html(cgit_httpscheme()); - html_attr(host); - html_attr(repourl); + html("<id>"); + html_txtf("%s%s%s", cgit_httpscheme(), host, fullurl); + html("</id>\n"); + html("<link rel='self' href='"); + html_attrf("%s%s%s", cgit_httpscheme(), host, fullurl); html("'/>\n"); + html("<link rel='alternate' type='text/html' href='"); + html_attrf("%s%s%s", cgit_httpscheme(), host, repourl); + html("'/>\n"); + free(fullurl); free(repourl); } while ((commit = get_revision(&rev)) != NULL) { + if (first) { + html("<updated>"); + html_txt(show_date(commit->date, 0, + date_mode_from_type(DATE_ISO8601_STRICT))); + html("</updated>\n"); + first = false; + } add_entry(commit, host); free_commit_buffer(the_repository->parsed_objects, commit); free_commit_list(commit->parents); From ce2062d9e29bf165ba8a70bfc92ff3ab08338d53 Mon Sep 17 00:00:00 2001 From: Peter Prohaska <pitrp@web.de> Date: Wed, 11 Nov 2020 22:16:21 +0100 Subject: [PATCH 361/387] html: fix handling of null byte A return value of `len` or more means that the output was truncated. Signed-off-by: Peter Prohaska <pitrp@web.de> Signed-off-by: Christian Hesse <mail@eworm.de> --- html.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html.c b/html.c index 7f81965..0bac34b 100644 --- a/html.c +++ b/html.c @@ -59,7 +59,7 @@ char *fmt(const char *format, ...) va_start(args, format); len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args); va_end(args); - if (len > sizeof(buf[bufidx])) { + if (len >= sizeof(buf[bufidx])) { fprintf(stderr, "[html.c] string truncated: %s\n", format); exit(1); } From a0f6669bdb74e58b0ddb3f4283209cd5e58c0eb9 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Mon, 10 Jan 2022 10:15:33 +0100 Subject: [PATCH 362/387] about: allow to give head from query Reading the README from repository used to be limited to default branch or a branch given in configuration. Let's allow a branch from query if not specified explicitly. Signed-off-by: Christian Hesse <mail@eworm.de> --- cgit.c | 8 +++++--- cgitrc.5.txt | 10 +++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/cgit.c b/cgit.c index 4b2d86c..2de6d7f 100644 --- a/cgit.c +++ b/cgit.c @@ -507,9 +507,11 @@ static inline void parse_readme(const char *readme, char **filename, char **ref, /* Check if the readme is tracked in the git repo. */ colon = strchr(readme, ':'); if (colon && strlen(colon) > 1) { - /* If it starts with a colon, we want to use - * the default branch */ - if (colon == readme && repo->defbranch) + /* If it starts with a colon, we want to use head given + * from query or the default branch */ + if (colon == readme && ctx.qry.head) + *ref = xstrdup(ctx.qry.head); + else if (colon == readme && repo->defbranch) *ref = xstrdup(repo->defbranch); else *ref = xstrndup(readme, colon - readme); diff --git a/cgitrc.5.txt b/cgitrc.5.txt index 33a6a8c..d9eb3b0 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -579,11 +579,11 @@ repo.readme:: verbatim as the "About" page for this repo. You may also specify a git refspec by head or by hash by prepending the refspec followed by a colon. For example, "master:docs/readme.mkd". If the value begins - with a colon, i.e. ":docs/readme.rst", the default branch of the - repository will be used. Sharing any file will expose that entire - directory tree to the "/about/PATH" endpoints, so be sure that there - are no non-public files located in the same directory as the readme - file. Default value: <readme>. + with a colon, i.e. ":docs/readme.rst", the head giving in query or + the default branch of the repository will be used. Sharing any file + will expose that entire directory tree to the "/about/PATH" endpoints, + so be sure that there are no non-public files located in the same + directory as the readme file. Default value: <readme>. repo.section:: Override the current section name for this repository. Default value: From c1a1d23111b4918798f2605c33130f2ab71bbe7a Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Sun, 13 Feb 2022 15:29:06 +0000 Subject: [PATCH 363/387] ui-blame: add a link to the parent commit in blame When walking through the history, it is useful to quickly see the same file at the previous revision, so add a link to do this. It would be nice to link to the correct line with an additional fragment, but this requires significantly more work so it can be done as an enhancement later. (ent->s_lno is mostly the right thing, but it is the line number in the post-image of the target commit whereas the link is to the parent of that commit, i.e. the pre-image of the target.) Suggested-by: Alejandro Colomar <alx.manpages@gmail.com> Signed-off-by: John Keeping <john@keeping.me.uk> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- ui-blame.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ui-blame.c b/ui-blame.c index 4adec2b..aedce8d 100644 --- a/ui-blame.c +++ b/ui-blame.c @@ -54,6 +54,15 @@ static void emit_blame_entry_hash(struct blame_entry *ent) html("</span>"); free(detail); + if (!parse_commit(suspect->commit) && suspect->commit->parents) { + struct commit *parent = suspect->commit->parents->item; + + html(" "); + cgit_blame_link("^", "Blame the previous revision", NULL, + ctx.qry.head, oid_to_hex(&parent->object.oid), + suspect->path); + } + while (line++ < ent->num_lines) html("\n"); } From d071f28cfa9a49f3aa6355b17e9d9fa7224ff49f Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Sun, 13 Feb 2022 15:35:29 +0000 Subject: [PATCH 364/387] css: reset font size for blame oid In Firefox, the hashes in the blame UI are out of step with the line number and content leading to ever increasing vertical misalignment. This is caused by the .oid class setting font-size to 90%, so override this back to 100% for the blame case, bringing the height of lines in all three columns of the table back into step. Signed-off-by: John Keeping <john@keeping.me.uk> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- cgit.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cgit.css b/cgit.css index dfa144d..1b848cf 100644 --- a/cgit.css +++ b/cgit.css @@ -363,6 +363,10 @@ div#cgit table.blame td.lines > div > pre { top: 0; } +div#cgit table.blame .oid { + font-size: 100%; +} + div#cgit table.bin-blob { margin-top: 0.5em; border: solid 1px black; From 4c520cefc90b10566fcc8a0b006287494a7770e1 Mon Sep 17 00:00:00 2001 From: John Keeping <john@keeping.me.uk> Date: Sun, 13 Feb 2022 15:34:50 +0000 Subject: [PATCH 365/387] global: use release_commit_memory() Instead of calling two separate Git functions to free memory associated with a commit object, use Git's wrapper which does this. This also counts as a potential future bug fix since release_commit_memory() also resets the parsed state of the commit, meaning any attempt to use it in the future will correctly fill out the fields again. release_commit_memory() does not set parents to zero, so keep that for additional safety in case CGit checks this without calling parse_commit() again. Signed-off-by: John Keeping <john@keeping.me.uk> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- ui-atom.c | 3 +-- ui-log.c | 6 ++---- ui-stats.c | 3 +-- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/ui-atom.c b/ui-atom.c index 541660d..5f4ad7d 100644 --- a/ui-atom.c +++ b/ui-atom.c @@ -149,8 +149,7 @@ void cgit_print_atom(char *tip, const char *path, int max_count) first = false; } add_entry(commit, host); - free_commit_buffer(the_repository->parsed_objects, commit); - free_commit_list(commit->parents); + release_commit_memory(the_repository->parsed_objects, commit); commit->parents = NULL; } html("</feed>\n"); diff --git a/ui-log.c b/ui-log.c index 565929f..311304a 100644 --- a/ui-log.c +++ b/ui-log.c @@ -489,8 +489,7 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; /* nop */) { if (show_commit(commit, &rev)) i++; - free_commit_buffer(the_repository->parsed_objects, commit); - free_commit_list(commit->parents); + release_commit_memory(the_repository->parsed_objects, commit); commit->parents = NULL; } @@ -511,8 +510,7 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern i++; print_commit(commit, &rev); } - free_commit_buffer(the_repository->parsed_objects, commit); - free_commit_list(commit->parents); + release_commit_memory(the_repository->parsed_objects, commit); commit->parents = NULL; } if (pager) { diff --git a/ui-stats.c b/ui-stats.c index 09b3625..40ed6c2 100644 --- a/ui-stats.c +++ b/ui-stats.c @@ -241,8 +241,7 @@ static struct string_list collect_stats(const struct cgit_period *period) memset(&authors, 0, sizeof(authors)); while ((commit = get_revision(&rev)) != NULL) { add_commit(&authors, commit, period); - free_commit_buffer(the_repository->parsed_objects, commit); - free_commit_list(commit->parents); + release_commit_memory(the_repository->parsed_objects, commit); commit->parents = NULL; } return authors; From 852cb3b0e267dd2ddfd2eeef6275435098c606e7 Mon Sep 17 00:00:00 2001 From: Hristo Venev <hristo@venev.name> Date: Sat, 7 May 2022 20:07:00 +0300 Subject: [PATCH 366/387] cache: tolerate short writes in print_slot sendfile() can return after a short read/write, so we may need to call it more than once. As suggested in the manual page, we fall back to read/write if sendfile fails with EINVAL or ENOSYS. On the read/write path, use write_in_full which deals with short writes. Signed-off-by: Hristo Venev <hristo@venev.name> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- cache.c | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/cache.c b/cache.c index 55199e8..1c843ba 100644 --- a/cache.c +++ b/cache.c @@ -85,40 +85,45 @@ static int close_slot(struct cache_slot *slot) /* Print the content of the active cache slot (but skip the key). */ static int print_slot(struct cache_slot *slot) { + off_t off; #ifdef HAVE_LINUX_SENDFILE - off_t start_off; - int ret; + off_t size; +#endif - start_off = slot->keylen + 1; + off = slot->keylen + 1; + +#ifdef HAVE_LINUX_SENDFILE + size = slot->cache_st.st_size; do { - ret = sendfile(STDOUT_FILENO, slot->cache_fd, &start_off, - slot->cache_st.st_size - start_off); + ssize_t ret; + ret = sendfile(STDOUT_FILENO, slot->cache_fd, &off, size - off); if (ret < 0) { if (errno == EAGAIN || errno == EINTR) continue; + /* Fall back to read/write on EINVAL or ENOSYS */ + if (errno == EINVAL || errno == ENOSYS) + break; return errno; } - return 0; + if (off == size) + return 0; } while (1); -#else - ssize_t i, j; +#endif - i = lseek(slot->cache_fd, slot->keylen + 1, SEEK_SET); - if (i != slot->keylen + 1) + if (lseek(slot->cache_fd, off, SEEK_SET) != off) return errno; do { - i = j = xread(slot->cache_fd, slot->buf, sizeof(slot->buf)); - if (i > 0) - j = xwrite(STDOUT_FILENO, slot->buf, i); - } while (i > 0 && j == i); - - if (i < 0 || j != i) - return errno; - else - return 0; -#endif + ssize_t ret; + ret = xread(slot->cache_fd, slot->buf, sizeof(slot->buf)); + if (ret < 0) + return errno; + if (ret == 0) + return 0; + if (write_in_full(STDOUT_FILENO, slot->buf, ret) < 0) + return errno; + } while (1); } /* Check if the slot has expired */ From 91f25909b9572ebdf3a0fed8224bf03d0d9bf3db Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Mon, 16 Jul 2018 16:27:39 +0200 Subject: [PATCH 367/387] cgitrc: handle value "0" for max-repo-count Setting max-repo-count to "0" makes cgit loop forever generating page links. Make this a special value to show all repositories. Signed-off-by: Christian Hesse <mail@eworm.de> --- cgit.c | 6 ++++-- cgitrc.5.txt | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cgit.c b/cgit.c index 2de6d7f..133f454 100644 --- a/cgit.c +++ b/cgit.c @@ -237,9 +237,11 @@ static void config_cb(const char *name, const char *value) ctx.cfg.max_repodesc_len = atoi(value); else if (!strcmp(name, "max-blob-size")) ctx.cfg.max_blob_size = atoi(value); - else if (!strcmp(name, "max-repo-count")) + else if (!strcmp(name, "max-repo-count")) { ctx.cfg.max_repo_count = atoi(value); - else if (!strcmp(name, "max-commit-count")) + if (ctx.cfg.max_repo_count <= 0) + ctx.cfg.max_repo_count = INT_MAX; + } else if (!strcmp(name, "max-commit-count")) ctx.cfg.max_commit_count = atoi(value); else if (!strcmp(name, "project-list")) ctx.cfg.project_list = xstrdup(expand_macros(value)); diff --git a/cgitrc.5.txt b/cgitrc.5.txt index d9eb3b0..463d90c 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -269,7 +269,8 @@ max-message-length:: max-repo-count:: Specifies the number of entries to list per page on the repository - index page. Default value: "50". + index page. The value "0" shows all repositories without limitation. + Default value: "50". max-repodesc-length:: Specifies the maximum number of repo description characters to display From 093ac9697068833a15cae2dbbd5ffbc0203741c0 Mon Sep 17 00:00:00 2001 From: Andy Green <andy@warmcat.com> Date: Tue, 3 Jul 2018 11:33:59 +0800 Subject: [PATCH 368/387] css: change to be a list Without changing the default behaviour of including /cgit.css if nothing declared, allow the "css" config to be given multiple times listing one or more alternative URL paths to be included in the document head area. Signed-off-by: Andy Green <andy@warmcat.com> Signed-off-by: Christian Hesse <mail@eworm.de> --- cgit.c | 3 +-- cgit.h | 2 +- cgitrc.5.txt | 3 ++- ui-shared.c | 21 ++++++++++++++++++--- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/cgit.c b/cgit.c index 133f454..75d9926 100644 --- a/cgit.c +++ b/cgit.c @@ -142,7 +142,7 @@ static void config_cb(const char *name, const char *value) else if (!strcmp(name, "root-readme")) ctx.cfg.root_readme = xstrdup(value); else if (!strcmp(name, "css")) - ctx.cfg.css = xstrdup(value); + string_list_append(&ctx.cfg.css, xstrdup(value)); else if (!strcmp(name, "favicon")) ctx.cfg.favicon = xstrdup(value); else if (!strcmp(name, "footer")) @@ -378,7 +378,6 @@ static void prepare_context(void) ctx.cfg.case_sensitive_sort = 1; ctx.cfg.branch_sort = 0; ctx.cfg.commit_sort = 0; - ctx.cfg.css = "/cgit.css"; ctx.cfg.logo = "/cgit.png"; ctx.cfg.favicon = "/favicon.ico"; ctx.cfg.local_time = 0; diff --git a/cgit.h b/cgit.h index 69b5c13..1d88396 100644 --- a/cgit.h +++ b/cgit.h @@ -195,7 +195,6 @@ struct cgit_config { char *cache_root; char *clone_prefix; char *clone_url; - char *css; char *favicon; char *footer; char *head_include; @@ -206,6 +205,7 @@ struct cgit_config { char *module_link; char *project_list; struct string_list readme; + struct string_list css; char *robots; char *root_title; char *root_desc; diff --git a/cgitrc.5.txt b/cgitrc.5.txt index 463d90c..45288bc 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -126,7 +126,8 @@ commit-sort:: css:: Url which specifies the css document to include in all cgit pages. - Default value: "/cgit.css". + Default value: "/cgit.css". May be given multiple times, each + css URL path is added in the head section of the document in turn. email-filter:: Specifies a command which will be invoked to format names and email diff --git a/ui-shared.c b/ui-shared.c index fbf5a2d..7c7a537 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -768,6 +768,18 @@ static void print_rel_vcs_link(const char *url) html(" Git repository'/>\n"); } +static int emit_css_link(struct string_list_item *s, void *arg) +{ + html("<link rel='stylesheet' type='text/css' href='"); + if (s) + html_attr(s->string); + else + html_attr((const char *)arg); + html("'/>\n"); + + return 0; +} + void cgit_print_docstart(void) { char *host = cgit_hosturl(); @@ -787,9 +799,12 @@ void cgit_print_docstart(void) htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); if (ctx.cfg.robots && *ctx.cfg.robots) htmlf("<meta name='robots' content='%s'/>\n", ctx.cfg.robots); - html("<link rel='stylesheet' type='text/css' href='"); - html_attr(ctx.cfg.css); - html("'/>\n"); + + if (ctx.cfg.css.items) + for_each_string_list(&ctx.cfg.css, emit_css_link, NULL); + else + emit_css_link(NULL, "/cgit.css"); + if (ctx.cfg.favicon) { html("<link rel='shortcut icon' href='"); html_attr(ctx.cfg.favicon); From aee39b4e9a45e1ba507c0017de50bb9dbbae7af8 Mon Sep 17 00:00:00 2001 From: Andy Green <andy@warmcat.com> Date: Sat, 23 Jun 2018 18:25:53 +0800 Subject: [PATCH 369/387] config: add js Just like the config allows setting css URL path, add a config for setting the js URL path Signed-off-by: Andy Green <andy@warmcat.com> Reviewed-by: John Keeping <john@keeping.me.uk> Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 1 + cgit.c | 2 ++ cgit.h | 1 + cgit.js | 7 +++++++ cgitrc.5.txt | 5 +++++ ui-shared.c | 17 +++++++++++++++++ 6 files changed, 33 insertions(+) create mode 100644 cgit.js diff --git a/Makefile b/Makefile index cd7639c..ad825be 100644 --- a/Makefile +++ b/Makefile @@ -87,6 +87,7 @@ install: all $(INSTALL) -m 0755 cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) $(INSTALL) -m 0755 -d $(DESTDIR)$(CGIT_DATA_PATH) $(INSTALL) -m 0644 cgit.css $(DESTDIR)$(CGIT_DATA_PATH)/cgit.css + $(INSTALL) -m 0644 cgit.js $(DESTDIR)$(CGIT_DATA_PATH)/cgit.js $(INSTALL) -m 0644 cgit.png $(DESTDIR)$(CGIT_DATA_PATH)/cgit.png $(INSTALL) -m 0644 favicon.ico $(DESTDIR)$(CGIT_DATA_PATH)/favicon.ico $(INSTALL) -m 0644 robots.txt $(DESTDIR)$(CGIT_DATA_PATH)/robots.txt diff --git a/cgit.c b/cgit.c index 75d9926..57d7097 100644 --- a/cgit.c +++ b/cgit.c @@ -143,6 +143,8 @@ static void config_cb(const char *name, const char *value) ctx.cfg.root_readme = xstrdup(value); else if (!strcmp(name, "css")) string_list_append(&ctx.cfg.css, xstrdup(value)); + else if (!strcmp(name, "js")) + string_list_append(&ctx.cfg.js, xstrdup(value)); else if (!strcmp(name, "favicon")) ctx.cfg.favicon = xstrdup(value); else if (!strcmp(name, "footer")) diff --git a/cgit.h b/cgit.h index 1d88396..a0cf5e9 100644 --- a/cgit.h +++ b/cgit.h @@ -264,6 +264,7 @@ struct cgit_config { int branch_sort; int commit_sort; struct string_list mimetypes; + struct string_list js; struct cgit_filter *about_filter; struct cgit_filter *commit_filter; struct cgit_filter *source_filter; diff --git a/cgit.js b/cgit.js new file mode 100644 index 0000000..b35e0bc --- /dev/null +++ b/cgit.js @@ -0,0 +1,7 @@ +/* cgit.js: javacript functions for cgit + * + * Copyright (C) 2006-2018 cgit Development Team <cgit@lists.zx2c4.com> + * + * Licensed under GNU General Public License v2 + * (see COPYING for full license text) + */ diff --git a/cgitrc.5.txt b/cgitrc.5.txt index 45288bc..6f3e952 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -239,6 +239,11 @@ include:: Name of a configfile to include before the rest of the current config- file is parsed. Default value: none. See also: "MACRO EXPANSION". +js:: + Url which specifies the javascript script document to include in all cgit + pages. Default value: "/cgit.js". Setting this to an empty string will + disable generation of the link to this file in the head section. + local-time:: Flag which, if set to "1", makes cgit print commit and tag times in the servers timezone. Default value: "0". diff --git a/ui-shared.c b/ui-shared.c index 7c7a537..c50b3e6 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -780,6 +780,18 @@ static int emit_css_link(struct string_list_item *s, void *arg) return 0; } +static int emit_js_link(struct string_list_item *s, void *arg) +{ + html("<script type='text/javascript' src='"); + if (s) + html_attr(s->string); + else + html_attr((const char *)arg); + html("'></script>\n"); + + return 0; +} + void cgit_print_docstart(void) { char *host = cgit_hosturl(); @@ -805,6 +817,11 @@ void cgit_print_docstart(void) else emit_css_link(NULL, "/cgit.css"); + if (ctx.cfg.js.items) + for_each_string_list(&ctx.cfg.js, emit_js_link, NULL); + else + emit_js_link(NULL, "/cgit.js"); + if (ctx.cfg.favicon) { html("<link rel='shortcut icon' href='"); html_attr(ctx.cfg.favicon); From 907134b7a29177cb45aa461c549c004b1ae875af Mon Sep 17 00:00:00 2001 From: Andy Green <andy@warmcat.com> Date: Sun, 24 Jun 2018 15:05:20 +0800 Subject: [PATCH 370/387] js: add dynamic age update This patch updates the emitted "ages" dynamically on the client side. After updating on completion of the document load, it sets a timer to update according to the smallest age it found. If there are any ages listed in minutes, then it will update again in 10s. When the most recent age is in hours, it updates every 5m. If days, then every 30m and so on. This keeps the cost of the dynamic updates at worst once per 10s. The updates are done entirely on the client side without contact with the server. To make this work reliably, since parsing datetimes is unreliable in browser js, the unix time is added as an attribute to all age spans. To make that reliable cross-platform, the unix time is treated as a uint64_t when it is formatted for printing. The rules for display conversion of the age is aligned with the existing server-side rules in ui-shared.h. If the client or server-side time are not synchronized by ntpd etc, ages shown on the client will not relate to the original ages computed at the server. The client updates the ages immediately when the DOM has finished loading, so in the case the times at the server and client are not aligned, this patch changes what the user sees on the page to reflect patch age compared to client time. If the server and client clocks are aligned, this patch makes no difference to what is seen on the page. Signed-off-by: Andy Green <andy@warmcat.com> Signed-off-by: Christian Hesse <mail@eworm.de> --- cgit.h | 1 + cgit.js | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++ ui-shared.c | 2 +- 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/cgit.h b/cgit.h index a0cf5e9..ddd2ccb 100644 --- a/cgit.h +++ b/cgit.h @@ -25,6 +25,7 @@ #include <utf8.h> #include <notes.h> #include <graph.h> +#include <inttypes.h> /* Add isgraph(x) to Git's sane ctype support (see git-compat-util.h) */ #undef isgraph diff --git a/cgit.js b/cgit.js index b35e0bc..df3ad4e 100644 --- a/cgit.js +++ b/cgit.js @@ -5,3 +5,64 @@ * Licensed under GNU General Public License v2 * (see COPYING for full license text) */ + +(function () { + +/* This follows the logic and suffixes used in ui-shared.c */ + +var age_classes = [ "age-mins", "age-hours", "age-days", "age-weeks", "age-months", "age-years" ]; +var age_suffix = [ "min.", "hours", "days", "weeks", "months", "years", "years" ]; +var age_next = [ 60, 3600, 24 * 3600, 7 * 24 * 3600, 30 * 24 * 3600, 365 * 24 * 3600, 365 * 24 * 3600 ]; +var age_limit = [ 7200, 24 * 7200, 7 * 24 * 7200, 30 * 24 * 7200, 365 * 25 * 7200, 365 * 25 * 7200 ]; +var update_next = [ 10, 5 * 60, 1800, 24 * 3600, 24 * 3600, 24 * 3600, 24 * 3600 ]; + +function render_age(e, age) { + var t, n; + + for (n = 0; n < age_classes.length; n++) + if (age < age_limit[n]) + break; + + t = Math.round(age / age_next[n]) + " " + age_suffix[n]; + + if (e.textContent != t) { + e.textContent = t; + if (n == age_classes.length) + n--; + if (e.className != age_classes[n]) + e.className = age_classes[n]; + } +} + +function aging() { + var n, next = 24 * 3600, + now_ut = Math.round((new Date().getTime() / 1000)); + + for (n = 0; n < age_classes.length; n++) { + var m, elems = document.getElementsByClassName(age_classes[n]); + + if (elems.length && update_next[n] < next) + next = update_next[n]; + + for (m = 0; m < elems.length; m++) { + var age = now_ut - elems[m].getAttribute("data-ut"); + + render_age(elems[m], age); + } + } + + /* + * We only need to come back when the age might have changed. + * Eg, if everything is counted in hours already, once per + * 5 minutes is accurate enough. + */ + + window.setTimeout(aging, next * 1000); +} + +document.addEventListener("DOMContentLoaded", function() { + /* we can do the aging on DOM content load since no layout dependency */ + aging(); +}, false); + +})(); diff --git a/ui-shared.c b/ui-shared.c index c50b3e6..11aed19 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -673,7 +673,7 @@ const struct date_mode *cgit_date_mode(enum date_mode_type type) static void print_rel_date(time_t t, int tz, double value, const char *class, const char *suffix) { - htmlf("<span class='%s' title='", class); + htmlf("<span class='%s' data-ut='%" PRIu64 "' title='", class, (uint64_t)t); html_attr(show_date(t, tz, cgit_date_mode(DATE_ISO8601))); htmlf("'>%.0f %s</span>", value, suffix); } From 00ecfaadea2c40cc62b7a43e246384329e6ddb98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20Lid=C3=A9n=20Borell?= <samuel@kodafritt.se> Date: Sat, 7 Jan 2023 10:32:07 +0100 Subject: [PATCH 371/387] config: make empty js= omit script tag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit According to the cgitrc man page, an empty js= value should cause the script tag to be omitted. But instead, a script tag with an empty URL is emitted. The same applies to css. So, skip emitting a tag if the specified string is empty. Signed-off-by: Samuel Lidén Borell <samuel@kodafritt.se> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- ui-shared.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ui-shared.c b/ui-shared.c index 11aed19..baea6f2 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -770,6 +770,10 @@ static void print_rel_vcs_link(const char *url) static int emit_css_link(struct string_list_item *s, void *arg) { + /* Do not emit anything if css= is specified. */ + if (s && *s->string == '\0') + return 0; + html("<link rel='stylesheet' type='text/css' href='"); if (s) html_attr(s->string); @@ -782,6 +786,10 @@ static int emit_css_link(struct string_list_item *s, void *arg) static int emit_js_link(struct string_list_item *s, void *arg) { + /* Do not emit anything if js= is specified. */ + if (s && *s->string == '\0') + return 0; + html("<script type='text/javascript' src='"); if (s) html_attr(s->string); From 6feb1b669b381452c1c2b4723bfd18275ecae350 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Wed, 18 Jan 2023 07:58:23 +0100 Subject: [PATCH 372/387] git: update to v2.39.1 Update to git version v2.39.1, no additional changes required. Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index ad825be..7b6065a 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.39.0 +GIT_VER = 2.39.1 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index c48035d..01443f0 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit c48035d29b4e524aed3a32f0403676f0d9128863 +Subproject commit 01443f01b7c6a3c6ef03268b649b119027743115 From 4dee601bb6042cf7db2472b9c34530850345f680 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Tue, 14 Feb 2023 20:55:47 +0100 Subject: [PATCH 373/387] git: update to v2.39.2 Update to git version v2.39.2, no additional changes required. Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 7b6065a..97b870b 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.39.1 +GIT_VER = 2.39.2 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index 01443f0..cbf0493 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 01443f01b7c6a3c6ef03268b649b119027743115 +Subproject commit cbf04937d5b9fcf0a76c28f69e6294e9e3ecd7e6 From 2593cd813860d71bd85db48c919de3d6e41b8b57 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Wed, 1 Mar 2023 22:07:18 +0100 Subject: [PATCH 374/387] git: update to v2.40.0 Update to git version v2.40.0, no additional changes required. Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 97b870b..5cc4a9d 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.39.2 +GIT_VER = 2.40.0 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index cbf0493..73876f4 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit cbf04937d5b9fcf0a76c28f69e6294e9e3ecd7e6 +Subproject commit 73876f4861cd3d187a4682290ab75c9dccadbc56 From 0e6744b3082f576be21dd1b88f519a3c1f7d3931 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Tue, 25 Apr 2023 19:12:11 +0200 Subject: [PATCH 375/387] git: update to v2.40.1 Update to git version v2.40.1, no additional changes required. Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 5cc4a9d..3fc1d5a 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.40.0 +GIT_VER = 2.40.1 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index 73876f4..0d1bd1d 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 73876f4861cd3d187a4682290ab75c9dccadbc56 +Subproject commit 0d1bd1dfb37ef25e1911777c94129fc769ffec38 From a6da40bf84527cbe77d1ec504e1fefb982b9a52a Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Tue, 16 May 2023 17:02:27 +0200 Subject: [PATCH 376/387] git: update to v2.41.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update to git version v2.41.0, with lots of changes... This requires changes for these upstream commits: * 60ff56f50372c1498718938ef504e744fe011ffb banned.h: mark `strtok()` and `strtok_r()` as banned * 52acddf36c8cb3778ab2098a0d95cc2e375a4069 string-list: multi-delimiter `string_list_split_in_place()` * d850b7a545fcfbd97460a921c7f7c59d933eb0f7 cocci: apply the "cache.h" part of "the_repository.pending" * cb338c23d6d518947bf6f7240bf30e2ec232bd3b cocci: apply the "commit-reach.h" part of "the_repository.pending" * ecb5091fd4301ac647db0bd2504112b38f7ee06d cocci: apply the "commit.h" part of "the_repository.pending" * 085390328f5fe1dfba67039b1fd6cc51546a4e41 cocci: apply the "diff.h" part of "the_repository.pending" * bc726bd075929aab6b3e09d4dd5c2b0726fd5350 cocci: apply the "object-store.h" part of "the_repository.pending" * bab821646a74c446370fa8d01ca851f247df5033 cocci: apply the "pretty.h" part of "the_repository.pending" * afe27c889429438829bc8818ed17e4960bd3ef02 cocci: apply the "packfile.h" part of "the_repository.pending" * 12cb1c10a64170a5d600dd1c6c8abfeec105fb6b cocci: apply the "refs.h" part of "the_repository.pending" * 035c7de9e9ea11d26df5f9e4bb117f91ed11a9fd cocci: apply the "revision.h" part of "the_repository.pending" ... and some more I missed to list 😜 - for example the move and cleanup of headers and includes (see changes in `cgit.h`) comes to mind... Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- cgit.c | 2 +- cgit.h | 34 +++++++++++++++++++--------------- git | 2 +- parsing.c | 2 +- shared.c | 17 +++++++++++------ ui-atom.c | 2 +- ui-blame.c | 12 ++++++------ ui-blob.c | 10 +++++----- ui-commit.c | 2 +- ui-diff.c | 14 +++++++------- ui-log.c | 6 +++--- ui-patch.c | 6 +++--- ui-plain.c | 6 +++--- ui-shared.c | 8 ++++---- ui-snapshot.c | 14 +++++++------- ui-stats.c | 2 +- ui-tag.c | 2 +- ui-tree.c | 8 ++++---- 19 files changed, 80 insertions(+), 71 deletions(-) diff --git a/Makefile b/Makefile index 3fc1d5a..b0de0ee 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.40.1 +GIT_VER = 2.41.0 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/cgit.c b/cgit.c index 57d7097..e616292 100644 --- a/cgit.c +++ b/cgit.c @@ -631,7 +631,7 @@ static int prepare_repo_cmd(int nongit) return 1; } - if (get_oid(ctx.qry.head, &oid)) { + if (repo_get_oid(the_repository, ctx.qry.head, &oid)) { char *old_head = ctx.qry.head; ctx.qry.head = xstrdup(ctx.repo->defbranch); cgit_print_error_page(404, "Not found", diff --git a/cgit.h b/cgit.h index ddd2ccb..f788fd2 100644 --- a/cgit.h +++ b/cgit.h @@ -1,31 +1,35 @@ #ifndef CGIT_H #define CGIT_H - -#include <git-compat-util.h> #include <stdbool.h> +#include <git-compat-util.h> + +#include <archive.h> #include <cache.h> -#include <grep.h> -#include <object.h> -#include <object-store.h> -#include <tree.h> #include <commit.h> -#include <tag.h> -#include <diff.h> #include <diffcore.h> -#include <strvec.h> +#include <diff.h> +#include <environment.h> +#include <graph.h> +#include <grep.h> +#include <hex.h> +#include <log-tree.h> +#include <notes.h> +#include <object.h> +#include <object-name.h> +#include <object-store.h> #include <refs.h> #include <revision.h> -#include <log-tree.h> -#include <archive.h> +#include <setup.h> #include <string-list.h> +#include <strvec.h> +#include <tag.h> +#include <tree.h> +#include <utf8.h> +#include <wrapper.h> #include <xdiff-interface.h> #include <xdiff/xdiff.h> -#include <utf8.h> -#include <notes.h> -#include <graph.h> -#include <inttypes.h> /* Add isgraph(x) to Git's sane ctype support (see git-compat-util.h) */ #undef isgraph diff --git a/git b/git index 0d1bd1d..fe86abd 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 0d1bd1dfb37ef25e1911777c94129fc769ffec38 +Subproject commit fe86abd7511a9a6862d5706c6fa1d9b57a63ba09 diff --git a/parsing.c b/parsing.c index 72b59b3..dc44ffd 100644 --- a/parsing.c +++ b/parsing.c @@ -198,7 +198,7 @@ struct taginfo *cgit_parse_tag(struct tag *tag) const char *p; struct taginfo *ret = NULL; - data = read_object_file(&tag->object.oid, &type, &size); + data = repo_read_object_file(the_repository, &tag->object.oid, &type, &size); if (!data || type != OBJ_TAG) goto cleanup; diff --git a/shared.c b/shared.c index 0bceb98..26b6ddb 100644 --- a/shared.c +++ b/shared.c @@ -241,7 +241,7 @@ static int load_mmfile(mmfile_t *file, const struct object_id *oid) file->ptr = (char *)""; file->size = 0; } else { - file->ptr = read_object_file(oid, &type, + file->ptr = repo_read_object_file(the_repository, oid, &type, (unsigned long *)&file->size); } return 1; @@ -343,7 +343,7 @@ void cgit_diff_tree(const struct object_id *old_oid, struct diff_options opt; struct pathspec_item *item; - diff_setup(&opt); + repo_diff_setup(the_repository, &opt); opt.output_format = DIFF_FORMAT_CALLBACK; opt.detect_rename = 1; opt.rename_limit = ctx.cfg.renamelimit; @@ -539,7 +539,9 @@ char *expand_macros(const char *txt) char *get_mimetype_for_filename(const char *filename) { - char *ext, *mimetype, *token, line[1024], *saveptr; + char *ext, *mimetype, line[1024]; + struct string_list list = STRING_LIST_INIT_NODUP; + int i; FILE *file; struct string_list_item *mime; @@ -564,13 +566,16 @@ char *get_mimetype_for_filename(const char *filename) while (fgets(line, sizeof(line), file)) { if (!line[0] || line[0] == '#') continue; - mimetype = strtok_r(line, " \t\r\n", &saveptr); - while ((token = strtok_r(NULL, " \t\r\n", &saveptr))) { - if (!strcasecmp(ext, token)) { + string_list_split_in_place(&list, line, " \t\r\n", -1); + string_list_remove_empty_items(&list, 0); + mimetype = list.items[0].string; + for (i = 1; i < list.nr; i++) { + if (!strcasecmp(ext, list.items[i].string)) { fclose(file); return xstrdup(mimetype); } } + string_list_clear(&list, 0); } fclose(file); return NULL; diff --git a/ui-atom.c b/ui-atom.c index 5f4ad7d..636cb7e 100644 --- a/ui-atom.c +++ b/ui-atom.c @@ -97,7 +97,7 @@ void cgit_print_atom(char *tip, const char *path, int max_count) argv[argc++] = path; } - init_revisions(&rev, NULL); + repo_init_revisions(the_repository, &rev, NULL); rev.abbrev = DEFAULT_ABBREV; rev.commit_format = CMIT_FMT_DEFAULT; rev.verbose_header = 1; diff --git a/ui-blame.c b/ui-blame.c index aedce8d..e0f0593 100644 --- a/ui-blame.c +++ b/ui-blame.c @@ -49,12 +49,12 @@ static void emit_blame_entry_hash(struct blame_entry *ent) char *detail = emit_suspect_detail(suspect); html("<span class='oid'>"); - cgit_commit_link(find_unique_abbrev(oid, DEFAULT_ABBREV), detail, + cgit_commit_link(repo_find_unique_abbrev(the_repository, oid, DEFAULT_ABBREV), detail, NULL, ctx.qry.head, oid_to_hex(oid), suspect->path); html("</span>"); free(detail); - if (!parse_commit(suspect->commit) && suspect->commit->parents) { + if (!repo_parse_commit(the_repository, suspect->commit) && suspect->commit->parents) { struct commit *parent = suspect->commit->parents->item; html(" "); @@ -126,7 +126,7 @@ static void print_object(const struct object_id *oid, const char *path, return; } - buf = read_object_file(oid, &type, &size); + buf = repo_read_object_file(the_repository, oid, &type, &size); if (!buf) { cgit_print_error_page(500, "Internal server error", "Error reading object %s", oid_to_hex(oid)); @@ -135,7 +135,7 @@ static void print_object(const struct object_id *oid, const char *path, strvec_push(&rev_argv, "blame"); strvec_push(&rev_argv, rev); - init_revisions(&revs, NULL); + repo_init_revisions(the_repository, &revs, NULL); revs.diffopt.flags.allow_textconv = 1; setup_revisions(rev_argv.nr, rev_argv.v, &revs, NULL); init_scoreboard(&sb); @@ -287,13 +287,13 @@ void cgit_print_blame(void) if (!rev) rev = ctx.qry.head; - if (get_oid(rev, &oid)) { + if (repo_get_oid(the_repository, rev, &oid)) { cgit_print_error_page(404, "Not found", "Invalid revision name: %s", rev); return; } commit = lookup_commit_reference(the_repository, &oid); - if (!commit || parse_commit(commit)) { + if (!commit || repo_parse_commit(the_repository, commit)) { cgit_print_error_page(404, "Not found", "Invalid commit reference: %s", rev); return; diff --git a/ui-blob.c b/ui-blob.c index c10ae42..08f94ee 100644 --- a/ui-blob.c +++ b/ui-blob.c @@ -52,7 +52,7 @@ int cgit_ref_path_exists(const char *path, const char *ref, int file_only) .file_only = file_only }; - if (get_oid(ref, &oid)) + if (repo_get_oid(the_repository, ref, &oid)) goto done; if (oid_object_info(the_repository, &oid, &size) != OBJ_COMMIT) goto done; @@ -87,7 +87,7 @@ int cgit_print_file(char *path, const char *head, int file_only) .file_only = file_only }; - if (get_oid(head, &oid)) + if (repo_get_oid(the_repository, head, &oid)) return -1; type = oid_object_info(the_repository, &oid, &size); if (type == OBJ_COMMIT) { @@ -100,7 +100,7 @@ int cgit_print_file(char *path, const char *head, int file_only) } if (type == OBJ_BAD) return -1; - buf = read_object_file(&oid, &type, &size); + buf = repo_read_object_file(the_repository, &oid, &type, &size); if (!buf) return -1; buf[size] = '\0'; @@ -138,7 +138,7 @@ void cgit_print_blob(const char *hex, char *path, const char *head, int file_onl return; } } else { - if (get_oid(head, &oid)) { + if (repo_get_oid(the_repository, head, &oid)) { cgit_print_error_page(404, "Not found", "Bad ref: %s", head); return; @@ -160,7 +160,7 @@ void cgit_print_blob(const char *hex, char *path, const char *head, int file_onl return; } - buf = read_object_file(&oid, &type, &size); + buf = repo_read_object_file(the_repository, &oid, &type, &size); if (!buf) { cgit_print_error_page(500, "Internal server error", "Error reading object %s", hex); diff --git a/ui-commit.c b/ui-commit.c index 0787237..30672d0 100644 --- a/ui-commit.c +++ b/ui-commit.c @@ -26,7 +26,7 @@ void cgit_print_commit(char *hex, const char *prefix) if (!hex) hex = ctx.qry.head; - if (get_oid(hex, &oid)) { + if (repo_get_oid(the_repository, hex, &oid)) { cgit_print_error_page(400, "Bad request", "Bad object id: %s", hex); return; diff --git a/ui-diff.c b/ui-diff.c index 5ed5990..6f42dd4 100644 --- a/ui-diff.c +++ b/ui-diff.c @@ -258,8 +258,8 @@ static void header(const struct object_id *oid1, char *path1, int mode1, htmlf("<br/>deleted file mode %.6o", mode1); if (!subproject) { - abbrev1 = xstrdup(find_unique_abbrev(oid1, DEFAULT_ABBREV)); - abbrev2 = xstrdup(find_unique_abbrev(oid2, DEFAULT_ABBREV)); + abbrev1 = xstrdup(repo_find_unique_abbrev(the_repository, oid1, DEFAULT_ABBREV)); + abbrev2 = xstrdup(repo_find_unique_abbrev(the_repository, oid2, DEFAULT_ABBREV)); htmlf("<br/>index %s..%s", abbrev1, abbrev2); free(abbrev1); free(abbrev2); @@ -402,13 +402,13 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, if (!new_rev) new_rev = ctx.qry.head; - if (get_oid(new_rev, new_rev_oid)) { + if (repo_get_oid(the_repository, new_rev, new_rev_oid)) { cgit_print_error_page(404, "Not found", "Bad object name: %s", new_rev); return; } commit = lookup_commit_reference(the_repository, new_rev_oid); - if (!commit || parse_commit(commit)) { + if (!commit || repo_parse_commit(the_repository, commit)) { cgit_print_error_page(404, "Not found", "Bad commit: %s", oid_to_hex(new_rev_oid)); return; @@ -416,7 +416,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, new_tree_oid = get_commit_tree_oid(commit); if (old_rev) { - if (get_oid(old_rev, old_rev_oid)) { + if (repo_get_oid(the_repository, old_rev, old_rev_oid)) { cgit_print_error_page(404, "Not found", "Bad object name: %s", old_rev); return; @@ -429,7 +429,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, if (!is_null_oid(old_rev_oid)) { commit2 = lookup_commit_reference(the_repository, old_rev_oid); - if (!commit2 || parse_commit(commit2)) { + if (!commit2 || repo_parse_commit(the_repository, commit2)) { cgit_print_error_page(404, "Not found", "Bad commit: %s", oid_to_hex(old_rev_oid)); return; @@ -442,7 +442,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, if (raw) { struct diff_options diffopt; - diff_setup(&diffopt); + repo_diff_setup(the_repository, &diffopt); diffopt.output_format = DIFF_FORMAT_PATCH; diffopt.flags.recursive = 1; diff_setup_done(&diffopt); diff --git a/ui-log.c b/ui-log.c index 311304a..50d479d 100644 --- a/ui-log.c +++ b/ui-log.c @@ -146,7 +146,7 @@ static int show_commit(struct commit *commit, struct rev_info *revs) /* When we get here we have precisely one parent. */ parent = parents->item; /* If we can't parse the commit, let print_commit() report an error. */ - if (parse_commit(parent)) + if (repo_parse_commit(the_repository, parent)) return 1; files = 0; @@ -330,7 +330,7 @@ static const char *disambiguate_ref(const char *ref, int *must_free_result) struct strbuf longref = STRBUF_INIT; strbuf_addf(&longref, "refs/heads/%s", ref); - if (get_oid(longref.buf, &oid) == 0) { + if (repo_get_oid(the_repository, longref.buf, &oid) == 0) { *must_free_result = 1; return strbuf_detach(&longref, NULL); } @@ -430,7 +430,7 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern if (path) strvec_push(&rev_argv, path); - init_revisions(&rev, NULL); + repo_init_revisions(the_repository, &rev, NULL); rev.abbrev = DEFAULT_ABBREV; rev.commit_format = CMIT_FMT_DEFAULT; rev.verbose_header = 1; diff --git a/ui-patch.c b/ui-patch.c index 4ac03cb..3819a81 100644 --- a/ui-patch.c +++ b/ui-patch.c @@ -31,7 +31,7 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, if (!new_rev) new_rev = ctx.qry.head; - if (get_oid(new_rev, &new_rev_oid)) { + if (repo_get_oid(the_repository, new_rev, &new_rev_oid)) { cgit_print_error_page(404, "Not found", "Bad object id: %s", new_rev); return; @@ -44,7 +44,7 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, } if (old_rev) { - if (get_oid(old_rev, &old_rev_oid)) { + if (repo_get_oid(the_repository, old_rev, &old_rev_oid)) { cgit_print_error_page(404, "Not found", "Bad object id: %s", old_rev); return; @@ -78,7 +78,7 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, "%s%n%n%w(0)%b"; } - init_revisions(&rev, NULL); + repo_init_revisions(the_repository, &rev, NULL); rev.abbrev = DEFAULT_ABBREV; rev.verbose_header = 1; rev.diff = 1; diff --git a/ui-plain.c b/ui-plain.c index 65a205f..a66c5a1 100644 --- a/ui-plain.c +++ b/ui-plain.c @@ -28,7 +28,7 @@ static int print_object(const struct object_id *oid, const char *path) return 0; } - buf = read_object_file(oid, &type, &size); + buf = repo_read_object_file(the_repository, oid, &type, &size); if (!buf) { cgit_print_error_page(404, "Not found", "Not found"); return 0; @@ -181,12 +181,12 @@ void cgit_print_plain(void) if (!rev) rev = ctx.qry.head; - if (get_oid(rev, &oid)) { + if (repo_get_oid(the_repository, rev, &oid)) { cgit_print_error_page(404, "Not found", "Not found"); return; } commit = lookup_commit_reference(the_repository, &oid); - if (!commit || parse_commit(commit)) { + if (!commit || repo_parse_commit(the_repository, commit)) { cgit_print_error_page(404, "Not found", "Not found"); return; } diff --git a/ui-shared.c b/ui-shared.c index baea6f2..eef2aa8 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -1188,11 +1188,11 @@ void cgit_compose_snapshot_prefix(struct strbuf *filename, const char *base, * name starts with {v,V}[0-9] and the prettify mapping is injective, * i.e. each stripped tag can be inverted without ambiguities. */ - if (get_oid(fmt("refs/tags/%s", ref), &oid) == 0 && + if (repo_get_oid(the_repository, fmt("refs/tags/%s", ref), &oid) == 0 && (ref[0] == 'v' || ref[0] == 'V') && isdigit(ref[1]) && - ((get_oid(fmt("refs/tags/%s", ref + 1), &oid) == 0) + - (get_oid(fmt("refs/tags/v%s", ref + 1), &oid) == 0) + - (get_oid(fmt("refs/tags/V%s", ref + 1), &oid) == 0) == 1)) + ((repo_get_oid(the_repository, fmt("refs/tags/%s", ref + 1), &oid) == 0) + + (repo_get_oid(the_repository, fmt("refs/tags/v%s", ref + 1), &oid) == 0) + + (repo_get_oid(the_repository, fmt("refs/tags/V%s", ref + 1), &oid) == 0) == 1)) ref++; strbuf_addf(filename, "%s-%s", base, ref); diff --git a/ui-snapshot.c b/ui-snapshot.c index 18361a6..9f629a9 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c @@ -117,7 +117,7 @@ const struct object_id *cgit_snapshot_get_sig(const char *ref, struct notes_tree *tree; struct object_id oid; - if (get_oid(ref, &oid)) + if (repo_get_oid(the_repository, ref, &oid)) return NULL; tree = &snapshot_sig_notes[f - &cgit_snapshot_formats[0]]; @@ -156,7 +156,7 @@ static int make_snapshot(const struct cgit_snapshot_format *format, { struct object_id oid; - if (get_oid(hex, &oid)) { + if (repo_get_oid(the_repository, hex, &oid)) { cgit_print_error_page(404, "Not found", "Bad object id: %s", hex); return 1; @@ -190,7 +190,7 @@ static int write_sig(const struct cgit_snapshot_format *format, return 0; } - buf = read_object_file(note, &type, &size); + buf = repo_read_object_file(the_repository, note, &type, &size); if (!buf) { cgit_print_error_page(404, "Not found", "Not found"); return 0; @@ -230,7 +230,7 @@ static const char *get_ref_from_filename(const struct cgit_repo *repo, strbuf_addstr(&snapshot, filename); strbuf_setlen(&snapshot, snapshot.len - strlen(format->suffix)); - if (get_oid(snapshot.buf, &oid) == 0) + if (repo_get_oid(the_repository, snapshot.buf, &oid) == 0) goto out; reponame = cgit_snapshot_prefix(repo); @@ -242,15 +242,15 @@ static const char *get_ref_from_filename(const struct cgit_repo *repo, strbuf_splice(&snapshot, 0, new_start - snapshot.buf, "", 0); } - if (get_oid(snapshot.buf, &oid) == 0) + if (repo_get_oid(the_repository, snapshot.buf, &oid) == 0) goto out; strbuf_insert(&snapshot, 0, "v", 1); - if (get_oid(snapshot.buf, &oid) == 0) + if (repo_get_oid(the_repository, snapshot.buf, &oid) == 0) goto out; strbuf_splice(&snapshot, 0, 1, "V", 1); - if (get_oid(snapshot.buf, &oid) == 0) + if (repo_get_oid(the_repository, snapshot.buf, &oid) == 0) goto out; result = 0; diff --git a/ui-stats.c b/ui-stats.c index 40ed6c2..9aed4ac 100644 --- a/ui-stats.c +++ b/ui-stats.c @@ -230,7 +230,7 @@ static struct string_list collect_stats(const struct cgit_period *period) argv[4] = ctx.qry.path; argc += 2; } - init_revisions(&rev, NULL); + repo_init_revisions(the_repository, &rev, NULL); rev.abbrev = DEFAULT_ABBREV; rev.commit_format = CMIT_FMT_DEFAULT; rev.max_parents = 1; diff --git a/ui-tag.c b/ui-tag.c index 424bbcc..5354827 100644 --- a/ui-tag.c +++ b/ui-tag.c @@ -48,7 +48,7 @@ void cgit_print_tag(char *revname) revname = ctx.qry.head; strbuf_addf(&fullref, "refs/tags/%s", revname); - if (get_oid(fullref.buf, &oid)) { + if (repo_get_oid(the_repository, fullref.buf, &oid)) { cgit_print_error_page(404, "Not found", "Bad tag reference: %s", revname); goto cleanup; diff --git a/ui-tree.c b/ui-tree.c index 98ce1ca..0640336 100644 --- a/ui-tree.c +++ b/ui-tree.c @@ -98,7 +98,7 @@ static void print_object(const struct object_id *oid, const char *path, const ch return; } - buf = read_object_file(oid, &type, &size); + buf = repo_read_object_file(the_repository, oid, &type, &size); if (!buf) { cgit_print_error_page(500, "Internal server error", "Error reading object %s", oid_to_hex(oid)); @@ -242,7 +242,7 @@ static int ls_item(const struct object_id *oid, struct strbuf *base, } if (S_ISLNK(mode)) { html(" -> "); - buf = read_object_file(oid, &type, &size); + buf = repo_read_object_file(the_repository, oid, &type, &size); if (!buf) { htmlf("Error reading object: %s", oid_to_hex(oid)); goto cleanup; @@ -372,13 +372,13 @@ void cgit_print_tree(const char *rev, char *path) if (!rev) rev = ctx.qry.head; - if (get_oid(rev, &oid)) { + if (repo_get_oid(the_repository, rev, &oid)) { cgit_print_error_page(404, "Not found", "Invalid revision name: %s", rev); return; } commit = lookup_commit_reference(the_repository, &oid); - if (!commit || parse_commit(commit)) { + if (!commit || repo_parse_commit(the_repository, commit)) { cgit_print_error_page(404, "Not found", "Invalid commit reference: %s", rev); return; From 2f50b47c72cbc4270bbd12ae7f520486d5f42736 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Wed, 9 Aug 2023 01:45:58 +0200 Subject: [PATCH 377/387] git: update to v2.42.0 Update to git version v2.42.0, this requires changes for these upstream commits: * bc5c5ec0446895f5c4139cd470066beb3c4ac6d5 cache.h: remove this no-longer-used header * aba070683295a20bdf4f49146384984961c794b2 path: move related function to path * a4e7e317f8f27f861321e6eb08b9c8c0f3ab570c config: add ctx arg to config_fn_t Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- cgit.h | 2 +- git | 2 +- scan-tree.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index b0de0ee..036a8e9 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.41.0 +GIT_VER = 2.42.0 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/cgit.h b/cgit.h index f788fd2..dbc461f 100644 --- a/cgit.h +++ b/cgit.h @@ -6,7 +6,6 @@ #include <git-compat-util.h> #include <archive.h> -#include <cache.h> #include <commit.h> #include <diffcore.h> #include <diff.h> @@ -19,6 +18,7 @@ #include <object.h> #include <object-name.h> #include <object-store.h> +#include <path.h> #include <refs.h> #include <revision.h> #include <setup.h> diff --git a/git b/git index fe86abd..43c8a30 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit fe86abd7511a9a6862d5706c6fa1d9b57a63ba09 +Subproject commit 43c8a30d150ecede9709c1f2527c8fba92c65f40 diff --git a/scan-tree.c b/scan-tree.c index 6a2f65a..84da86e 100644 --- a/scan-tree.c +++ b/scan-tree.c @@ -54,7 +54,7 @@ static void scan_tree_repo_config(const char *name, const char *value) config_fn(repo, name, value); } -static int gitconfig_config(const char *key, const char *value, void *cb) +static int gitconfig_config(const char *key, const char *value, const struct config_context *, void *cb) { const char *name; From a95762af1ab8b4286a515630f750892d85bd6540 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Thu, 2 Nov 2023 21:26:06 +0100 Subject: [PATCH 378/387] git: update to v2.42.1 Update to git version v2.42.1, no additional changes required. Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 036a8e9..3c080fc 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.42.0 +GIT_VER = 2.42.1 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index 43c8a30..61a22dd 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 43c8a30d150ecede9709c1f2527c8fba92c65f40 +Subproject commit 61a22ddaf0626111193a17ac12f366bd6d167dff From 793c420897e18eb3474c751d54cf4e0983f85433 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Tue, 7 Nov 2023 16:13:22 +0100 Subject: [PATCH 379/387] git: update to v2.43.0 Update to git version v2.43.0, no additional changes required. Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 3c080fc..5e8b85a 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.42.1 +GIT_VER = 2.43.0 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index 61a22dd..564d025 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 61a22ddaf0626111193a17ac12f366bd6d167dff +Subproject commit 564d0252ca632e0264ed670534a51d18a689ef5d From 63d35e556f294f60891c0611d9944202dc10e662 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Wed, 14 Feb 2024 20:40:39 +0100 Subject: [PATCH 380/387] git: update to v2.43.2 Update to git version v2.43.2, no additional changes required. (Git v2.43.1 fails to build, thus skipping.) Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 5e8b85a..17a40b1 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.43.0 +GIT_VER = 2.43.2 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index 564d025..efb050b 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 564d0252ca632e0264ed670534a51d18a689ef5d +Subproject commit efb050becb6bc703f76382e1f1b6273100e6ace3 From 8905003cba637e5b18069e625cd4f4c05ac30251 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Fri, 23 Feb 2024 18:28:47 +0100 Subject: [PATCH 381/387] git: update to v2.44.0 Update to git version v2.44.0, no additional changes required. Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 17a40b1..c3ee267 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.43.2 +GIT_VER = 2.44.0 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index efb050b..3c2a3fd 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit efb050becb6bc703f76382e1f1b6273100e6ace3 +Subproject commit 3c2a3fdc388747b9eaf4a4a4f2035c1c9ddb26d0 From dbadd856ba0537110338cfe58256b152d01388c0 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Fri, 19 Apr 2024 22:39:20 +0200 Subject: [PATCH 382/387] git: update to v2.45.0 Update to git version v2.45.0, this requires changes for these upstream commits: * 9720d23e8caf4adee44b3a32803a9bb0480118bd date: make DATE_MODE thread-safe Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- ui-shared.c | 4 ++-- ui-shared.h | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index c3ee267..2612a75 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.44.0 +GIT_VER = 2.45.0 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index 3c2a3fd..786a3e4 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 3c2a3fdc388747b9eaf4a4a4f2035c1c9ddb26d0 +Subproject commit 786a3e4b8d754d2b14b1208b98eeb0a554ef19a8 diff --git a/ui-shared.c b/ui-shared.c index eef2aa8..d5b5b20 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -662,12 +662,12 @@ void cgit_submodule_link(const char *class, char *path, const char *rev) path[len - 1] = tail; } -const struct date_mode *cgit_date_mode(enum date_mode_type type) +const struct date_mode cgit_date_mode(enum date_mode_type type) { static struct date_mode mode; mode.type = type; mode.local = ctx.cfg.local_time; - return &mode; + return mode; } static void print_rel_date(time_t t, int tz, double value, diff --git a/ui-shared.h b/ui-shared.h index 6964873..f12fa99 100644 --- a/ui-shared.h +++ b/ui-shared.h @@ -65,7 +65,7 @@ __attribute__((format (printf,1,2))) extern void cgit_print_error(const char *fmt, ...); __attribute__((format (printf,1,0))) extern void cgit_vprint_error(const char *fmt, va_list ap); -extern const struct date_mode *cgit_date_mode(enum date_mode_type type); +extern const struct date_mode cgit_date_mode(enum date_mode_type type); extern void cgit_print_age(time_t t, int tz, time_t max_relative); extern void cgit_print_http_headers(void); extern void cgit_redirect(const char *url, bool permanent); From 92a8f1676a2cbe57fd9d9c9b40a5ccd23dc0b842 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Tue, 14 May 2024 19:59:11 +0200 Subject: [PATCH 383/387] git: update to v2.45.1 Update to git version v2.45.1, no additional changes required. Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 2612a75..ecfebaf 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.45.0 +GIT_VER = 2.45.1 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index 786a3e4..2c7b491 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 786a3e4b8d754d2b14b1208b98eeb0a554ef19a8 +Subproject commit 2c7b491c1d3107be35c375f59e040b0f13d0cc0c From b2c939af4bbd24882fcd28aa6b75319ca61c7c5b Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Sat, 1 Jun 2024 23:29:44 +0200 Subject: [PATCH 384/387] git: update to v2.45.2 Update to git version v2.45.2, no additional changes required. Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- git | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index ecfebaf..1eb64ea 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.45.1 +GIT_VER = 2.45.2 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/git b/git index 2c7b491..bea9ecd 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit 2c7b491c1d3107be35c375f59e040b0f13d0cc0c +Subproject commit bea9ecd24b0c3bf06cab4a851694fe09e7e51408 From 34c30d12fc917d9853135f6e9d4c8e531efddaeb Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Tue, 16 Jul 2024 12:06:55 +0200 Subject: [PATCH 385/387] ui-stats: add missing source header Signed-off-by: Christian Hesse <mail@eworm.de> --- ui-stats.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ui-stats.c b/ui-stats.c index 9aed4ac..1ac67da 100644 --- a/ui-stats.c +++ b/ui-stats.c @@ -1,3 +1,11 @@ +/* ui-stats.c: generate stats view + * + * Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com> + * + * Licensed under GNU General Public License v2 + * (see COPYING for full license text) + */ + #include "cgit.h" #include "ui-stats.h" #include "html.h" From fb87de795b9f1b1e21825243716ff1156097adf2 Mon Sep 17 00:00:00 2001 From: Denis Pronin <dannftk@yandex.ru> Date: Sun, 9 Jun 2024 09:41:36 +0300 Subject: [PATCH 386/387] fix building with clang fix error that is given because of macro overlapping cgit_filter member: ../filter.c:388:10: error: no member named '__fprintf_chk' in 'struct cgit_filter' 388 | filter->fprintf(filter, f, prefix); | ~~~~~~ ^ /usr/include/bits/stdio2.h:92:3: note: expanded from macro 'fprintf' 92 | __fprintf_chk (stream, __USE_FORTIFY_LEVEL - 1, __VA_ARGS__) | ^ 1 error generated. Signed-off-by: Denis Pronin <dannftk@yandex.ru> Signed-off-by: Christian Hesse <mail@eworm.de> --- cgit.h | 2 +- filter.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cgit.h b/cgit.h index dbc461f..e0d286d 100644 --- a/cgit.h +++ b/cgit.h @@ -69,7 +69,7 @@ typedef enum { struct cgit_filter { int (*open)(struct cgit_filter *, va_list ap); int (*close)(struct cgit_filter *); - void (*fprintf)(struct cgit_filter *, FILE *, const char *prefix); + void (*fprintfp)(struct cgit_filter *, FILE *, const char *prefix); void (*cleanup)(struct cgit_filter *); int argument_count; }; diff --git a/filter.c b/filter.c index 70f5b74..22b4970 100644 --- a/filter.c +++ b/filter.c @@ -128,7 +128,7 @@ void cgit_exec_filter_init(struct cgit_exec_filter *filter, char *cmd, char **ar memset(filter, 0, sizeof(*filter)); filter->base.open = open_exec_filter; filter->base.close = close_exec_filter; - filter->base.fprintf = fprintf_exec_filter; + filter->base.fprintfp = fprintf_exec_filter; filter->base.cleanup = cleanup_exec_filter; filter->cmd = cmd; filter->argv = argv; @@ -353,7 +353,7 @@ static struct cgit_filter *new_lua_filter(const char *cmd, int argument_count) memset(filter, 0, sizeof(*filter)); filter->base.open = open_lua_filter; filter->base.close = close_lua_filter; - filter->base.fprintf = fprintf_lua_filter; + filter->base.fprintfp = fprintf_lua_filter; filter->base.cleanup = cleanup_lua_filter; filter->base.argument_count = argument_count; filter->script_file = xstrdup(cmd); @@ -385,7 +385,7 @@ int cgit_close_filter(struct cgit_filter *filter) void cgit_fprintf_filter(struct cgit_filter *filter, FILE *f, const char *prefix) { - filter->fprintf(filter, f, prefix); + filter->fprintfp(filter, f, prefix); } From 09d24d7cd0b7e85633f2f43808b12871bb209d69 Mon Sep 17 00:00:00 2001 From: Christian Hesse <mail@eworm.de> Date: Tue, 16 Jul 2024 09:45:13 +0200 Subject: [PATCH 387/387] git: update to v2.46.0 Update to git version v2.46.0, this requires changes for these upstream commits: * e7da9385708accf518a80a1e17969020fb361048 global: introduce `USE_THE_REPOSITORY_VARIABLE` macro * 9da95bda74cf10e1475384a71fd20914c3b99784 hash: require hash algorithm in `oidread()` and `oidclr()` * 30aaff437fddd889ba429b50b96ea4c151c502c5 refs: pass repo when peeling objects * c8f815c2083c4b340d4148a15d45c55f2fcc7d3f refs: remove functions without ref store Signed-off-by: Christian Hesse <mail@eworm.de> --- Makefile | 2 +- cgit.c | 8 ++++++-- git | 2 +- parsing.c | 2 ++ shared.c | 2 ++ ui-atom.c | 2 ++ ui-blame.c | 2 ++ ui-blob.c | 2 ++ ui-clone.c | 5 ++++- ui-commit.c | 2 ++ ui-diff.c | 4 +++- ui-log.c | 5 ++++- ui-patch.c | 4 +++- ui-plain.c | 2 ++ ui-refs.c | 11 ++++++++--- ui-shared.c | 8 ++++++-- ui-snapshot.c | 2 ++ ui-stats.c | 2 ++ ui-tag.c | 2 ++ ui-tree.c | 2 ++ 20 files changed, 58 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 1eb64ea..7f8a5cb 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ htmldir = $(docdir) pdfdir = $(docdir) mandir = $(prefix)/share/man SHA1_HEADER = <openssl/sha.h> -GIT_VER = 2.45.2 +GIT_VER = 2.46.0 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz INSTALL = install COPYTREE = cp -r diff --git a/cgit.c b/cgit.c index e616292..2efa962 100644 --- a/cgit.c +++ b/cgit.c @@ -6,6 +6,8 @@ * (see COPYING for full license text) */ +#define USE_THE_REPOSITORY_VARIABLE + #include "cgit.h" #include "cache.h" #include "cmd.h" @@ -473,7 +475,8 @@ static char *find_default_branch(struct cgit_repo *repo) info.req_ref = repo->defbranch; info.first_ref = NULL; info.match = 0; - for_each_branch_ref(find_current_ref, &info); + refs_for_each_branch_ref(get_main_ref_store(the_repository), + find_current_ref, &info); if (info.match) ref = info.req_ref; else @@ -490,7 +493,8 @@ static char *guess_defbranch(void) const char *ref, *refname; struct object_id oid; - ref = resolve_ref_unsafe("HEAD", 0, &oid, NULL); + ref = refs_resolve_ref_unsafe(get_main_ref_store(the_repository), + "HEAD", 0, &oid, NULL); if (!ref || !skip_prefix(ref, "refs/heads/", &refname)) return "master"; return xstrdup(refname); diff --git a/git b/git index bea9ecd..39bf06a 160000 --- a/git +++ b/git @@ -1 +1 @@ -Subproject commit bea9ecd24b0c3bf06cab4a851694fe09e7e51408 +Subproject commit 39bf06adf96da25b87c9aa7d35a32ef3683eb4a4 diff --git a/parsing.c b/parsing.c index dc44ffd..5616d43 100644 --- a/parsing.c +++ b/parsing.c @@ -6,6 +6,8 @@ * (see COPYING for full license text) */ +#define USE_THE_REPOSITORY_VARIABLE + #include "cgit.h" /* diff --git a/shared.c b/shared.c index 26b6ddb..ae3f6c1 100644 --- a/shared.c +++ b/shared.c @@ -6,6 +6,8 @@ * (see COPYING for full license text) */ +#define USE_THE_REPOSITORY_VARIABLE + #include "cgit.h" struct cgit_repolist cgit_repolist; diff --git a/ui-atom.c b/ui-atom.c index 636cb7e..0659e96 100644 --- a/ui-atom.c +++ b/ui-atom.c @@ -6,6 +6,8 @@ * (see COPYING for full license text) */ +#define USE_THE_REPOSITORY_VARIABLE + #include "cgit.h" #include "ui-atom.h" #include "html.h" diff --git a/ui-blame.c b/ui-blame.c index e0f0593..d07b67f 100644 --- a/ui-blame.c +++ b/ui-blame.c @@ -6,6 +6,8 @@ * (see COPYING for full license text) */ +#define USE_THE_REPOSITORY_VARIABLE + #include "cgit.h" #include "ui-blame.h" #include "html.h" diff --git a/ui-blob.c b/ui-blob.c index 08f94ee..e554fe9 100644 --- a/ui-blob.c +++ b/ui-blob.c @@ -6,6 +6,8 @@ * (see COPYING for full license text) */ +#define USE_THE_REPOSITORY_VARIABLE + #include "cgit.h" #include "ui-blob.h" #include "html.h" diff --git a/ui-clone.c b/ui-clone.c index 5dccb63..df196a0 100644 --- a/ui-clone.c +++ b/ui-clone.c @@ -7,6 +7,8 @@ * (see COPYING for full license text) */ +#define USE_THE_REPOSITORY_VARIABLE + #include "cgit.h" #include "ui-clone.h" #include "html.h" @@ -87,7 +89,8 @@ void cgit_clone_info(void) ctx.page.mimetype = "text/plain"; ctx.page.filename = "info/refs"; cgit_print_http_headers(); - for_each_ref(print_ref_info, NULL); + refs_for_each_ref(get_main_ref_store(the_repository), + print_ref_info, NULL); } void cgit_clone_objects(void) diff --git a/ui-commit.c b/ui-commit.c index 30672d0..972e9bc 100644 --- a/ui-commit.c +++ b/ui-commit.c @@ -6,6 +6,8 @@ * (see COPYING for full license text) */ +#define USE_THE_REPOSITORY_VARIABLE + #include "cgit.h" #include "ui-commit.h" #include "html.h" diff --git a/ui-diff.c b/ui-diff.c index 6f42dd4..a824546 100644 --- a/ui-diff.c +++ b/ui-diff.c @@ -6,6 +6,8 @@ * (see COPYING for full license text) */ +#define USE_THE_REPOSITORY_VARIABLE + #include "cgit.h" #include "ui-diff.h" #include "html.h" @@ -424,7 +426,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, } else if (commit->parents && commit->parents->item) { oidcpy(old_rev_oid, &commit->parents->item->object.oid); } else { - oidclr(old_rev_oid); + oidclr(old_rev_oid, the_repository->hash_algo); } if (!is_null_oid(old_rev_oid)) { diff --git a/ui-log.c b/ui-log.c index 50d479d..ee2a607 100644 --- a/ui-log.c +++ b/ui-log.c @@ -6,6 +6,8 @@ * (see COPYING for full license text) */ +#define USE_THE_REPOSITORY_VARIABLE + #include "cgit.h" #include "ui-log.h" #include "html.h" @@ -80,7 +82,8 @@ void show_commit_decorations(struct commit *commit) ctx.qry.showmsg, 0); break; case DECORATION_REF_TAG: - if (!read_ref(deco->name, &oid_tag) && !peel_iterated_oid(&oid_tag, &peeled)) + if (!refs_read_ref(get_main_ref_store(the_repository), deco->name, &oid_tag) && + !peel_iterated_oid(the_repository, &oid_tag, &peeled)) is_annotated = !oideq(&oid_tag, &peeled); cgit_tag_link(buf, NULL, is_annotated ? "tag-annotated-deco" : "tag-deco", buf); break; diff --git a/ui-patch.c b/ui-patch.c index 3819a81..f9d2eeb 100644 --- a/ui-patch.c +++ b/ui-patch.c @@ -6,6 +6,8 @@ * (see COPYING for full license text) */ +#define USE_THE_REPOSITORY_VARIABLE + #include "cgit.h" #include "ui-patch.h" #include "html.h" @@ -57,7 +59,7 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, } else if (commit->parents && commit->parents->item) { oidcpy(&old_rev_oid, &commit->parents->item->object.oid); } else { - oidclr(&old_rev_oid); + oidclr(&old_rev_oid, the_repository->hash_algo); } if (is_null_oid(&old_rev_oid)) { diff --git a/ui-plain.c b/ui-plain.c index a66c5a1..4d69607 100644 --- a/ui-plain.c +++ b/ui-plain.c @@ -6,6 +6,8 @@ * (see COPYING for full license text) */ +#define USE_THE_REPOSITORY_VARIABLE + #include "cgit.h" #include "ui-plain.h" #include "html.h" diff --git a/ui-refs.c b/ui-refs.c index 456f610..11fb9fc 100644 --- a/ui-refs.c +++ b/ui-refs.c @@ -6,6 +6,8 @@ * (see COPYING for full license text) */ +#define USE_THE_REPOSITORY_VARIABLE + #include "cgit.h" #include "ui-refs.h" #include "html.h" @@ -155,9 +157,11 @@ void cgit_print_branches(int maxcount) list.refs = NULL; list.alloc = list.count = 0; - for_each_branch_ref(cgit_refs_cb, &list); + refs_for_each_branch_ref(get_main_ref_store(the_repository), + cgit_refs_cb, &list); if (ctx.repo->enable_remote_branches) - for_each_remote_ref(cgit_refs_cb, &list); + refs_for_each_remote_ref(get_main_ref_store(the_repository), + cgit_refs_cb, &list); if (maxcount == 0 || maxcount > list.count) maxcount = list.count; @@ -182,7 +186,8 @@ void cgit_print_tags(int maxcount) list.refs = NULL; list.alloc = list.count = 0; - for_each_tag_ref(cgit_refs_cb, &list); + refs_for_each_tag_ref(get_main_ref_store(the_repository), + cgit_refs_cb, &list); if (list.count == 0) return; qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age); diff --git a/ui-shared.c b/ui-shared.c index d5b5b20..6fae72d 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -6,6 +6,8 @@ * (see COPYING for full license text) */ +#define USE_THE_REPOSITORY_VARIABLE + #include "cgit.h" #include "ui-shared.h" #include "cmd.h" @@ -1041,9 +1043,11 @@ static void print_header(void) html("<form method='get'>\n"); cgit_add_hidden_formfields(0, 1, ctx.qry.page); html("<select name='h' onchange='this.form.submit();'>\n"); - for_each_branch_ref(print_branch_option, ctx.qry.head); + refs_for_each_branch_ref(get_main_ref_store(the_repository), + print_branch_option, ctx.qry.head); if (ctx.repo->enable_remote_branches) - for_each_remote_ref(print_branch_option, ctx.qry.head); + refs_for_each_remote_ref(get_main_ref_store(the_repository), + print_branch_option, ctx.qry.head); html("</select> "); html("<input type='submit' value='switch'/>"); html("</form>"); diff --git a/ui-snapshot.c b/ui-snapshot.c index 9f629a9..3e38cd5 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c @@ -6,6 +6,8 @@ * (see COPYING for full license text) */ +#define USE_THE_REPOSITORY_VARIABLE + #include "cgit.h" #include "ui-snapshot.h" #include "html.h" diff --git a/ui-stats.c b/ui-stats.c index 1ac67da..02c60ef 100644 --- a/ui-stats.c +++ b/ui-stats.c @@ -6,6 +6,8 @@ * (see COPYING for full license text) */ +#define USE_THE_REPOSITORY_VARIABLE + #include "cgit.h" #include "ui-stats.h" #include "html.h" diff --git a/ui-tag.c b/ui-tag.c index 5354827..3b11226 100644 --- a/ui-tag.c +++ b/ui-tag.c @@ -6,6 +6,8 @@ * (see COPYING for full license text) */ +#define USE_THE_REPOSITORY_VARIABLE + #include "cgit.h" #include "ui-tag.h" #include "html.h" diff --git a/ui-tree.c b/ui-tree.c index 0640336..3d8a2eb 100644 --- a/ui-tree.c +++ b/ui-tree.c @@ -6,6 +6,8 @@ * (see COPYING for full license text) */ + #define USE_THE_REPOSITORY_VARIABLE + #include "cgit.h" #include "ui-tree.h" #include "html.h"