List for cgit developers and users
 help / color / mirror / Atom feed
* [PATCH 0/4] some miscellaneous features
@ 2012-10-30 13:07 plenz
  2012-10-30 13:07 ` [PATCH 1/4] tree view: imitate proper permissions plenz
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: plenz @ 2012-10-30 13:07 UTC (permalink / raw)


Here's a collection of patches we use in production. If there's any
useful idea in there, feel free to integrate it into the mainline.

Julius Plenz (4):
  tree view: imitate proper permissions
  Introduce "dont-display-suffix" option
  Make number of columns in stat overview configurable
  Introduce a fallback encoding (eg. for blobs)

 cgit.c      |  4 ++++
 cgit.h      |  6 +++++-
 parsing.c   | 11 +++++++++++
 scan-tree.c | 11 ++++++++---
 ui-diff.c   |  2 +-
 ui-plain.c  |  2 ++
 ui-refs.c   |  2 +-
 ui-shared.c | 15 +++++++++------
 ui-ssdiff.c | 10 +++++-----
 ui-stats.c  | 26 +++++++++++++++++++++-----
 ui-tag.c    |  4 ++--
 ui-tree.c   |  2 +-
 12 files changed, 70 insertions(+), 25 deletions(-)

-- 
1.7.12.3-zedat





^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/4] tree view: imitate proper permissions
  2012-10-30 13:07 [PATCH 0/4] some miscellaneous features plenz
@ 2012-10-30 13:07 ` plenz
  2012-10-30 13:07 ` [PATCH 2/4] Introduce "dont-display-suffix" option plenz
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: plenz @ 2012-10-30 13:07 UTC (permalink / raw)



Signed-off-by: Julius Plenz <plenz at cis.fu-berlin.de>
---
 ui-shared.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/ui-shared.c b/ui-shared.c
index 43166af..e1f6124 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -946,17 +946,20 @@ void cgit_print_pageheader(struct cgit_context *ctx)
 
 void cgit_print_filemode(unsigned short mode)
 {
-	if (S_ISDIR(mode))
+	unsigned short m = mode;
+	if (S_ISDIR(mode)) {
 		html("d");
-	else if (S_ISLNK(mode))
+		m = 0755;
+	} else if (S_ISLNK(mode)) {
 		html("l");
-	else if (S_ISGITLINK(mode))
+		m = 0777;
+	} else if (S_ISGITLINK(mode))
 		html("m");
 	else
 		html("-");
-	html_fileperm(mode >> 6);
-	html_fileperm(mode >> 3);
-	html_fileperm(mode);
+	html_fileperm(m >> 6);
+	html_fileperm(m >> 3);
+	html_fileperm(m);
 }
 
 void cgit_print_snapshot_links(const char *repo, const char *head,
-- 
1.7.12.3-zedat





^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 2/4] Introduce "dont-display-suffix" option
  2012-10-30 13:07 [PATCH 0/4] some miscellaneous features plenz
  2012-10-30 13:07 ` [PATCH 1/4] tree view: imitate proper permissions plenz
@ 2012-10-30 13:07 ` plenz
  2012-11-01  4:03   ` mathstuf
  2012-11-01  4:22   ` Jason
  2012-10-30 13:07 ` [PATCH 3/4] Make number of columns in stat overview configurable plenz
  2012-10-30 13:07 ` [PATCH 4/4] Introduce a fallback encoding (eg. for blobs) plenz
  3 siblings, 2 replies; 8+ messages in thread
From: plenz @ 2012-10-30 13:07 UTC (permalink / raw)


This will make the scan-path run return a repository name without .git
suffix (as remove-suffix would do), but leaves this suffix in the URL
parameter.

Signed-off-by: Julius Plenz <plenz at cis.fu-berlin.de>
---
 cgit.c      |  2 ++
 cgit.h      |  1 +
 scan-tree.c | 11 ++++++++---
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/cgit.c b/cgit.c
index b9b3a66..f1105fb 100644
--- a/cgit.c
+++ b/cgit.c
@@ -247,6 +247,8 @@ void config_cb(const char *name, const char *value)
 		ctx.cfg.renamelimit = atoi(value);
 	else if (!strcmp(name, "remove-suffix"))
 		ctx.cfg.remove_suffix = atoi(value);
+	else if (!strcmp(name, "dont-display-suffix"))
+		ctx.cfg.dont_display_suffix = atoi(value);
 	else if (!strcmp(name, "robots"))
 		ctx.cfg.robots = xstrdup(value);
 	else if (!strcmp(name, "clone-prefix"))
diff --git a/cgit.h b/cgit.h
index 6ee6769..5692224 100644
--- a/cgit.h
+++ b/cgit.h
@@ -221,6 +221,7 @@ struct cgit_config {
 	int noheader;
 	int renamelimit;
 	int remove_suffix;
+	int dont_display_suffix;
 	int scan_hidden_path;
 	int section_from_path;
 	int snapshots;
diff --git a/scan-tree.c b/scan-tree.c
index 378d795..e33927e 100644
--- a/scan-tree.c
+++ b/scan-tree.c
@@ -100,10 +100,15 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn)
 		rel[strlen(rel) - 5] = '\0';
 
 	repo = cgit_add_repo(rel);
-	if (ctx.cfg.remove_suffix)
-		if ((p = strrchr(repo->url, '.')) && !strcmp(p, ".git"))
+	if ((p = strrchr(repo->url, '.')) && !strcmp(p, ".git")) {
+		if (ctx.cfg.remove_suffix)
 			*p = '\0';
-	repo->name = repo->url;
+		else if (ctx.cfg.dont_display_suffix) {
+			repo->name = xstrdup(repo->url);
+			repo->name[strlen(repo->name) - 4] = '\0';
+		}
+	} else
+		repo->name = repo->url;
 	repo->path = xstrdup(path);
 	while (!owner) {
 		if ((pwd = getpwuid(st.st_uid)) == NULL) {
-- 
1.7.12.3-zedat





^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 3/4] Make number of columns in stat overview configurable
  2012-10-30 13:07 [PATCH 0/4] some miscellaneous features plenz
  2012-10-30 13:07 ` [PATCH 1/4] tree view: imitate proper permissions plenz
  2012-10-30 13:07 ` [PATCH 2/4] Introduce "dont-display-suffix" option plenz
@ 2012-10-30 13:07 ` plenz
  2012-10-30 13:07 ` [PATCH 4/4] Introduce a fallback encoding (eg. for blobs) plenz
  3 siblings, 0 replies; 8+ messages in thread
From: plenz @ 2012-10-30 13:07 UTC (permalink / raw)


I'm pretty sure this constitutes a violation of how the data structure
cgit_period's use was intended, but that's much easier than passing the
"count" parameter to all the functions that need it.

Signed-off-by: Julius Plenz <plenz at cis.fu-berlin.de>
---
 cgit.c     |  2 ++
 cgit.h     |  1 +
 ui-stats.c | 26 +++++++++++++++++++++-----
 3 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/cgit.c b/cgit.c
index f1105fb..04637ab 100644
--- a/cgit.c
+++ b/cgit.c
@@ -305,6 +305,8 @@ static void querystring_cb(const char *name, const char *value)
 		ctx.qry.showmsg = atoi(value);
 	} else if (!strcmp(name, "period")) {
 		ctx.qry.period = xstrdup(value);
+	} else if (!strcmp(name, "nr_periods")) {
+		ctx.qry.nr_periods = atoi(value);
 	} else if (!strcmp(name, "ss")) {
 		ctx.qry.ssdiff = atoi(value);
 		ctx.qry.has_ssdiff = 1;
diff --git a/cgit.h b/cgit.h
index 5692224..4a3f528 100644
--- a/cgit.h
+++ b/cgit.h
@@ -161,6 +161,7 @@ struct cgit_query {
 	int context;
 	int ignorews;
 	char *vpath;
+	int nr_periods;
 };
 
 struct cgit_config {
diff --git a/ui-stats.c b/ui-stats.c
index 59f4c1e..4ca8c4a 100644
--- a/ui-stats.c
+++ b/ui-stats.c
@@ -128,10 +128,10 @@ static char *pretty_year(struct tm *tm)
 }
 
 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},
-	{'y', "year", 12, 4, trunc_year, dec_year, inc_year, pretty_year},
+	{'w', "week", 24, 4, trunc_week, dec_week, inc_week, pretty_week},
+	{'m', "month", 24, 4, trunc_month, dec_month, inc_month, pretty_month},
+	{'q', "quarter", 24, 4, trunc_quarter, dec_quarter, inc_quarter, pretty_quarter},
+	{'y', "year", 24, 4, trunc_year, dec_year, inc_year, pretty_year},
 };
 
 /* Given a period code or name, return a period index (1, 2, 3 or 4)
@@ -363,7 +363,7 @@ void cgit_show_stats(struct cgit_context *ctx)
 {
 	struct string_list authors;
 	struct cgit_period *period;
-	int top, i;
+	int top, cols, i;
 	const char *code = "w";
 
 	if (ctx->qry.period)
@@ -379,6 +379,13 @@ void cgit_show_stats(struct cgit_context *ctx)
 				     period->name));
 		return;
 	}
+
+	cols = ctx->qry.nr_periods;
+	if(!cols || cols > period->max_periods)
+		cols = period->count;
+	else
+		period->count = cols;
+
 	authors = collect_stats(ctx, period);
 	qsort(authors.items, authors.nr, sizeof(struct string_list_item),
 		cmp_total_commits);
@@ -408,6 +415,15 @@ void cgit_show_stats(struct cgit_context *ctx)
 	html_intoption(100, "100", top);
 	html_intoption(-1, "all", top);
 	html("</select></td></tr>");
+
+	html("<tr><td class='label'>Columns:</td>");
+	html("<td class='ctrl'><select name='nr_periods' onchange='this.form.submit();'>");
+	html_intoption(1, "1", cols);
+	html_intoption(4, "4", cols);
+	html_intoption(12, "12", cols);
+	html_intoption(24, "24", cols);
+	html("</select></td></tr>");
+
 	html("<tr><td/><td class='ctrl'>");
 	html("<noscript><input type='submit' value='Reload'/></noscript>");
 	html("</td></tr></table>");
-- 
1.7.12.3-zedat





^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 4/4] Introduce a fallback encoding (eg. for blobs)
  2012-10-30 13:07 [PATCH 0/4] some miscellaneous features plenz
                   ` (2 preceding siblings ...)
  2012-10-30 13:07 ` [PATCH 3/4] Make number of columns in stat overview configurable plenz
@ 2012-10-30 13:07 ` plenz
  3 siblings, 0 replies; 8+ messages in thread
From: plenz @ 2012-10-30 13:07 UTC (permalink / raw)


Usually you'll want to deliver the web pages using UTF-8. It's no
problem to convert Git's commit information to the PAGE_ENCODING since
if it's not UTF-8, the encoding that was used is specified.

In the case of blobs, Git by design doesn't want to know anything about
the encoding. But to make the file appear "normal" in the browser, the
FALLBACK_ENCODING (default: latin1) has a hint as to from which
encoding the string originates. In case the plain file is delivered, the
encoding will be set to the fallback specified if the blob's contents
are not valid UTF-8.

The same applies to the "Tagger" information, since tag objects don't
have an "encoding" field. (See:
http://git.661346.n2.nabble.com/PATCH-RFC-Document-format-of-basic-Git-objects-tp7287428p7288762.html )

Signed-off-by: Julius Plenz <plenz at cis.fu-berlin.de>
---
 cgit.h      |  4 +++-
 parsing.c   | 11 +++++++++++
 ui-diff.c   |  2 +-
 ui-plain.c  |  2 ++
 ui-refs.c   |  2 +-
 ui-ssdiff.c | 10 +++++-----
 ui-tag.c    |  4 ++--
 ui-tree.c   |  2 +-
 8 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/cgit.h b/cgit.h
index 4a3f528..fb7b9db 100644
--- a/cgit.h
+++ b/cgit.h
@@ -43,9 +43,11 @@
 
 
 /*
- * Default encoding
+ * Default encoding and fallback encoding in case blobs are not valid UTF-8
  */
 #define PAGE_ENCODING "UTF-8"
+#define FALLBACK_ENCODING "latin1"
+extern const char *to_pageencoding(const char *txt);
 
 typedef void (*configfn)(const char *name, const char *value);
 typedef void (*filepair_fn)(struct diff_filepair *pair);
diff --git a/parsing.c b/parsing.c
index 602e3de..2a03b11 100644
--- a/parsing.c
+++ b/parsing.c
@@ -98,6 +98,7 @@ char *parse_user(char *t, char **name, char **email, unsigned long *date)
 
 #ifdef NO_ICONV
 #define reencode(a, b, c)
+#define to_pageencoding(a)
 #else
 const char *reencode(char **txt, const char *src_enc, const char *dst_enc)
 {
@@ -120,6 +121,16 @@ const char *reencode(char **txt, const char *src_enc, const char *dst_enc)
 	}
 	return *txt;
 }
+const char *to_pageencoding(const char *txt)
+{
+	if(is_encoding_utf8(PAGE_ENCODING) && !is_utf8(txt)) {
+		char *tmp = xstrdup(txt);
+		reencode(&tmp, FALLBACK_ENCODING, PAGE_ENCODING);
+		return tmp;
+	}
+	return txt;
+}
+
 #endif
 
 struct commitinfo *cgit_parse_commit(struct commit *commit)
diff --git a/ui-diff.c b/ui-diff.c
index c6bad63..2d90a46 100644
--- a/ui-diff.c
+++ b/ui-diff.c
@@ -211,7 +211,7 @@ static void print_line(char *line, int len)
 
 	htmlf("<div class='%s'>", class);
 	line[len-1] = '\0';
-	html_txt(line);
+	html_txt(to_pageencoding(line));
 	html("</div>");
 	line[len-1] = c;
 }
diff --git a/ui-plain.c b/ui-plain.c
index 85877d7..baa5a2f 100644
--- a/ui-plain.c
+++ b/ui-plain.c
@@ -95,6 +95,8 @@ static void print_object(const unsigned char *sha1, const char *path)
 	ctx.page.filename = fmt("%s", path);
 	ctx.page.size = size;
 	ctx.page.etag = sha1_to_hex(sha1);
+	if(is_encoding_utf8(PAGE_ENCODING) && !is_utf8(buf)) /* best guess */
+		ctx.page.charset = FALLBACK_ENCODING;
 	cgit_print_http_headers(&ctx);
 	html_raw(buf, size);
 	match = 1;
diff --git a/ui-refs.c b/ui-refs.c
index caddfbc..15cfe0b 100644
--- a/ui-refs.c
+++ b/ui-refs.c
@@ -143,7 +143,7 @@ static int print_tag(struct refinfo *ref)
 			cgit_object_link(tag->tagged);
 		html("</td><td>");
 		if (info->tagger)
-			html(info->tagger);
+			html(to_pageencoding(info->tagger));
 		html("</td><td colspan='2'>");
 		if (info->tagger_date > 0)
 			cgit_print_age(info->tagger_date, -1, NULL);
diff --git a/ui-ssdiff.c b/ui-ssdiff.c
index fbb46cf..a60112e 100644
--- a/ui-ssdiff.c
+++ b/ui-ssdiff.c
@@ -208,7 +208,7 @@ static void print_part_with_lcs(char *class, char *line, char *lcs)
 			htmlf("</span>");
 			j += 1;
 		}
-		html_txt(c);
+		html_txt(to_pageencoding(c));
 	}
 }
 
@@ -244,7 +244,7 @@ static void print_ssdiff_line(char *class,
 		if (lcs)
 			print_part_with_lcs("del", old_line, lcs);
 		else
-			html_txt(old_line);
+			html_txt(to_pageencoding(old_line));
 	}
 
 	html("</td>\n");
@@ -265,7 +265,7 @@ static void print_ssdiff_line(char *class,
 		if (lcs)
 			print_part_with_lcs("add", new_line, lcs);
 		else
-			html_txt(new_line);
+			html_txt(to_pageencoding(new_line));
 	}
 
 	html("</td></tr>");
@@ -379,11 +379,11 @@ void cgit_ssdiff_line_cb(char *line, int len)
 		current_old_line += 1;
 	} else if (line[0] == '@') {
 		html("<tr><td colspan='4' class='hunk'>");
-		html_txt(line);
+		html_txt(to_pageencoding(line));
 		html("</td></tr>");
 	} else {
 		html("<tr><td colspan='4' class='ctx'>");
-		html_txt(line);
+		html_txt(to_pageencoding(line));
 		html("</td></tr>");
 	}
 	line[len - 1] = c;
diff --git a/ui-tag.c b/ui-tag.c
index 39e4cb8..de88880 100644
--- a/ui-tag.c
+++ b/ui-tag.c
@@ -21,7 +21,7 @@ static void print_tag_content(char *buf)
 	p = strchr(buf, '\n');
 	if (p)
 		*p = '\0';
-	html_txt(buf);
+	html_txt(to_pageencoding(buf));
 	html("</div>");
 	if (p) {
 		html("<div class='commit-msg'>");
@@ -74,7 +74,7 @@ void cgit_print_tag(char *revname)
 		}
 		if (info->tagger) {
 			html("<tr><td>tagged by</td><td>");
-			html_txt(info->tagger);
+			html_txt(to_pageencoding(info->tagger));
 			if (info->tagger_email && !ctx.cfg.noplainemail) {
 				html(" ");
 				html_txt(info->tagger_email);
diff --git a/ui-tree.c b/ui-tree.c
index b1adcc7..35f1ad5 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -55,7 +55,7 @@ static void print_text_buffer(const char *name, char *buf, unsigned long size)
 	}
 
 	html("<td class='lines'><pre><code>");
-	html_txt(buf);
+	html_txt(to_pageencoding(buf));
 	html("</code></pre></td></tr></table>\n");
 }
 
-- 
1.7.12.3-zedat





^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 2/4] Introduce "dont-display-suffix" option
  2012-10-30 13:07 ` [PATCH 2/4] Introduce "dont-display-suffix" option plenz
@ 2012-11-01  4:03   ` mathstuf
  2012-11-01  4:22   ` Jason
  1 sibling, 0 replies; 8+ messages in thread
From: mathstuf @ 2012-11-01  4:03 UTC (permalink / raw)


On Tue, Oct 30, 2012 at 13:07:16 GMT, Julius Plenz wrote:
> +	else if (!strcmp(name, "dont-display-suffix"))
> +		ctx.cfg.dont_display_suffix = atoi(value);

Negated configuration names are icky. Could this perhaps be
"preserve-suffix" or "trim-display-suffix"?

-- Ben





^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 2/4] Introduce "dont-display-suffix" option
  2012-10-30 13:07 ` [PATCH 2/4] Introduce "dont-display-suffix" option plenz
  2012-11-01  4:03   ` mathstuf
@ 2012-11-01  4:22   ` Jason
  2012-11-01 10:52     ` plenz
  1 sibling, 1 reply; 8+ messages in thread
From: Jason @ 2012-11-01  4:22 UTC (permalink / raw)


On Tue, Oct 30, 2012 at 7:07 AM, Julius Plenz <plenz at cis.fu-berlin.de> wrote:
> This will make the scan-path run return a repository name without .git
> suffix (as remove-suffix would do), but leaves this suffix in the URL
> parameter.


What's the use case of this? Why not do completely without suffixes?
Not many folks like suffixes anywhere ever.




^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 2/4] Introduce "dont-display-suffix" option
  2012-11-01  4:22   ` Jason
@ 2012-11-01 10:52     ` plenz
  0 siblings, 0 replies; 8+ messages in thread
From: plenz @ 2012-11-01 10:52 UTC (permalink / raw)


Hi, Jason!

* Jason A. Donenfeld <Jason at zx2c4.com> [2012-11-01 05:24]:
> What's the use case of this? Why not do completely without suffixes?
> Not many folks like suffixes anywhere ever.

Without suffixes in the URL, there's a name clash if you have a
subdirectory "A" as well as "A.git". Take for example a repository
"exim.git" and "exim/exim-helpers.git", "exim/config.git".

What should http://cgit-server/exim display? -> Don't display
suffixes, but use them in the URL do avoid ambiguity in a case like
the one mentioned.

Julius




^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-11-01 10:52 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-30 13:07 [PATCH 0/4] some miscellaneous features plenz
2012-10-30 13:07 ` [PATCH 1/4] tree view: imitate proper permissions plenz
2012-10-30 13:07 ` [PATCH 2/4] Introduce "dont-display-suffix" option plenz
2012-11-01  4:03   ` mathstuf
2012-11-01  4:22   ` Jason
2012-11-01 10:52     ` plenz
2012-10-30 13:07 ` [PATCH 3/4] Make number of columns in stat overview configurable plenz
2012-10-30 13:07 ` [PATCH 4/4] Introduce a fallback encoding (eg. for blobs) plenz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).