List for cgit developers and users
 help / color / mirror / Atom feed
* [PATCH 1/3] snapshots: Don't allow sneaked in snapshots requests
@ 2012-06-21  7:09 cgit
  2012-06-21  7:09 ` [PATCH 2/3] cache: use sendfile() instead of a pair of read() + write() cgit
  2012-06-21  7:09 ` [PATCH 3/3] summary: Add tag head line in the dowload section cgit
  0 siblings, 2 replies; 5+ messages in thread
From: cgit @ 2012-06-21  7:09 UTC (permalink / raw)


From: Sebastian Andrzej Siewior <sebastian at breakpoint.cc>

If the snapshots are not enabled then the frontend won't show a link to it.
The skilled user however may construct the URL on his own and the frontend
will obey the request.
This patch adds a check for this case so the requst won't be served.

Signed-off-by: Sebastian Andrzej Siewior <sebastian at breakpoint.cc>
---
 ui-snapshot.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/ui-snapshot.c b/ui-snapshot.c
index 07cc944..5034c19 100644
--- a/ui-snapshot.c
+++ b/ui-snapshot.c
@@ -168,6 +168,12 @@ void cgit_print_snapshot(const char *head, const char *hex,
 		return;
 	}
 
+	if (!(f->bit & snapshots)) {
+		show_error(xstrdup(fmt("Snapshot format %s is not enabled.",
+						f->suffix)));
+		return;
+	}
+
 	if (!hex && dwim) {
 		hex = get_ref_from_filename(ctx.repo->url, filename, f);
 		if (hex == NULL) {
-- 
1.7.2.5





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

* [PATCH 2/3] cache: use sendfile() instead of a pair of read() + write()
  2012-06-21  7:09 [PATCH 1/3] snapshots: Don't allow sneaked in snapshots requests cgit
@ 2012-06-21  7:09 ` cgit
  2012-06-23 10:27   ` mathstuf
  2012-06-21  7:09 ` [PATCH 3/3] summary: Add tag head line in the dowload section cgit
  1 sibling, 1 reply; 5+ messages in thread
From: cgit @ 2012-06-21  7:09 UTC (permalink / raw)


From: Sebastian Andrzej Siewior <sebastian at breakpoint.cc>

sendfile() does the same job and avoids to copy the content into userland
and back. One has to define NO_SENDFILE in case the OS (kernel / libc)
does not supported. It is disabled by default on non-linux environemnts.
According to the glibc, sendfile64() was added in Linux 2.4 (so it has
been there for a while) but after browsing over the mapage of FreeBSD's I
noticed that the prototype is little different.

Signed-off-by: Sebastian Andrzej Siewior <sebastian at breakpoint.cc>
---
 Makefile |   10 ++++++++++
 cache.c  |   26 +++++++++++++++++++++++++-
 2 files changed, 35 insertions(+), 1 deletions(-)

diff --git a/Makefile b/Makefile
index eac24ad..5cc84f4 100644
--- a/Makefile
+++ b/Makefile
@@ -33,6 +33,9 @@ DOC_PDF  = $(patsubst %.txt,%.pdf,$(MAN_TXT))
 # j, z, t. (representing long long int, char, intmax_t, size_t, ptrdiff_t).
 # some C compilers supported these specifiers prior to C99 as an extension.
 #
+# Define NO_SENDFILE to avoid using the sendfile() offered by libc. Use this
+# if your OS does not provide support for sendfile()
+#
 
 #-include config.mak
 
@@ -49,6 +52,10 @@ ifeq ($(uname_O),Cygwin)
 	NEEDS_LIBICONV = YesPlease
 endif
 
+ifneq ($(uname_S),Linux)
+	NO_SENDFILE = YesPlease
+endif
+
 #
 # Let the user override the above settings.
 #
@@ -157,6 +164,9 @@ ifdef NO_OPENSSL
 else
 	EXTLIBS += -lcrypto
 endif
+ifdef NO_SENDFILE
+	CFLAGS	+= -DNO_SENDFILE
+endif
 
 cgit: $(OBJECTS) libgit
 	$(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o cgit $(OBJECTS) $(EXTLIBS)
diff --git a/cache.c b/cache.c
index d7a8d5a..19bbc11 100644
--- a/cache.c
+++ b/cache.c
@@ -13,6 +13,9 @@
  *
  */
 
+#ifndef NO_SENDFILE
+#include <sys/sendfile.h>
+#endif
 #include "cgit.h"
 #include "cache.h"
 
@@ -30,7 +33,6 @@ struct cache_slot {
 	const char *lock_name;
 	int match;
 	struct stat cache_st;
-	struct stat lock_st;
 	int bufsize;
 	char buf[CACHE_BUFSIZE];
 };
@@ -81,6 +83,7 @@ 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)
 {
+#ifdef NO_SENDFILE
 	ssize_t i, j;
 
 	i = lseek(slot->cache_fd, slot->keylen + 1, SEEK_SET);
@@ -97,6 +100,23 @@ static int print_slot(struct cache_slot *slot)
 		return errno;
 	else
 		return 0;
+#else
+	off_t start_off;
+	int ret;
+
+	start_off = slot->keylen + 1;
+
+	do {
+		ret = sendfile(STDOUT_FILENO, slot->cache_fd, &start_off,
+				slot->cache_st.st_size - start_off);
+		if (ret < 0) {
+			if (errno == EAGAIN || errno == EINTR)
+				continue;
+			return errno;
+		}
+		return 0;
+	} while (1);
+#endif
 }
 
 /* Check if the slot has expired */
@@ -188,6 +208,10 @@ static int fill_slot(struct cache_slot *slot)
 	/* Generate cache content */
 	slot->fn(slot->cbdata);
 
+	/* update stat info */
+	if (fstat(slot->lock_fd, &slot->cache_st))
+		return errno;
+
 	/* Restore stdout */
 	if (dup2(tmp, STDOUT_FILENO) == -1)
 		return errno;
-- 
1.7.2.5





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

* [PATCH 3/3] summary: Add tag head line in the dowload section
  2012-06-21  7:09 [PATCH 1/3] snapshots: Don't allow sneaked in snapshots requests cgit
  2012-06-21  7:09 ` [PATCH 2/3] cache: use sendfile() instead of a pair of read() + write() cgit
@ 2012-06-21  7:09 ` cgit
  1 sibling, 0 replies; 5+ messages in thread
From: cgit @ 2012-06-21  7:09 UTC (permalink / raw)


From: Sebastian Andrzej Siewior <sebastian at breakpoint.cc>

If the downloads are disabled one gets only ugly "commit sha1". With
downloads enabled you see the file name with different extensions a few
times.
This patches changes it a little. Instead of printing the hash number it
prints the first line of the tag i.e. the head line / commit subject if
available. With downloads enabled it prints additionally the extension
of the archive type (i.e. .tar, .tar.xz) next to it.

Signed-off-by: Sebastian Andrzej Siewior <sebastian at breakpoint.cc>
---
 ui-refs.c |    7 ++++---
 ui-tag.c  |   34 ++++++++++++++++++++++++++++++++++
 ui-tag.h  |    1 +
 3 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/ui-refs.c b/ui-refs.c
index caddfbc..9336703 100644
--- a/ui-refs.c
+++ b/ui-refs.c
@@ -9,6 +9,7 @@
 #include "cgit.h"
 #include "html.h"
 #include "ui-shared.h"
+#include "ui-tag.h"
 
 static int header;
 
@@ -119,7 +120,7 @@ static void print_tag_downloads(const struct cgit_repo *repo, const char *ref)
 		if (!(repo->snapshots & f->bit))
 			continue;
 		filename = fmt("%s%s", ref, f->suffix);
-		cgit_snapshot_link(filename, NULL, NULL, NULL, NULL, filename);
+		cgit_snapshot_link(f->suffix, NULL, NULL, NULL, NULL, filename);
 		html("&nbsp;&nbsp;");
 	}
 }
@@ -137,10 +138,10 @@ static int print_tag(struct refinfo *ref)
 		html("<tr><td>");
 		cgit_tag_link(name, NULL, NULL, ctx.qry.head, name);
 		html("</td><td>");
+		cgit_print_tag_subject(name);
+		html(" ");
 		if (ctx.repo->snapshots && (tag->tagged->type == OBJ_COMMIT))
 			print_tag_downloads(ctx.repo, name);
-		else
-			cgit_object_link(tag->tagged);
 		html("</td><td>");
 		if (info->tagger)
 			html(info->tagger);
diff --git a/ui-tag.c b/ui-tag.c
index 39e4cb8..18c3361 100644
--- a/ui-tag.c
+++ b/ui-tag.c
@@ -38,6 +38,40 @@ void print_download_links(char *revname)
 	html("</td></tr>");
 }
 
+void cgit_print_tag_subject(char *revname)
+{
+	unsigned char sha1[20];
+	struct object *obj;
+	struct taginfo *info;
+	struct tag *tag;
+	char *p;
+	size_t len;
+
+	if (get_sha1(fmt("refs/tags/%s", revname), sha1)) {
+		cgit_print_error(fmt("Bad tag reference: %s", revname));
+		return;
+	}
+	obj = parse_object(sha1);
+	if (!obj) {
+		cgit_print_error(fmt("Bad object id: %s", sha1_to_hex(sha1)));
+		return;
+	}
+
+	tag = lookup_tag(sha1);
+	if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) {
+		cgit_print_error(fmt("Bad tag object: %s", revname));
+		return;
+	}
+	p = strchr(info->msg, '\n');
+	if (p)
+		*p = '\0';
+	len = strlen(info->msg);
+	if (len > 74)
+	    info->msg[74] = '\0';
+
+	html_txt(info->msg);
+}
+
 void cgit_print_tag(char *revname)
 {
 	unsigned char sha1[20];
diff --git a/ui-tag.h b/ui-tag.h
index d295cdc..352e0fd 100644
--- a/ui-tag.h
+++ b/ui-tag.h
@@ -2,5 +2,6 @@
 #define UI_TAG_H
 
 extern void cgit_print_tag(char *revname);
+void cgit_print_tag_subject(char *revname);
 
 #endif /* UI_TAG_H */
-- 
1.7.2.5





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

* [PATCH 2/3] cache: use sendfile() instead of a pair of read() + write()
  2012-06-21  7:09 ` [PATCH 2/3] cache: use sendfile() instead of a pair of read() + write() cgit
@ 2012-06-23 10:27   ` mathstuf
  2012-06-23 19:25     ` [PATCH 2/3 v2] " cgit
  0 siblings, 1 reply; 5+ messages in thread
From: mathstuf @ 2012-06-23 10:27 UTC (permalink / raw)


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

On Thu, Jun 21, 2012 at 07:09:47 GMT, cgit at ml.breakpoint.cc wrote:
> From: Sebastian Andrzej Siewior <sebastian at breakpoint.cc>
> +ifneq ($(uname_S),Linux)
> +	NO_SENDFILE = YesPlease
> +endif

Double negatives suck. Can the option be made HAVE_SENDFILE?

- --Ben

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iQIcBAEBCgAGBQJP5HsGAAoJEKaxavVX4C1XWsMQAM3rrvAmNE37u1OcfP9ovLZH
kXwOHxeWu+ikzKiZ/V8cnXU/kQCHpz0lqgD8MnSnvQlpEraTNw0Z315ZBb6776FY
XdV6RBitlXRMvQvPnL21fSEiHZrPsqLKD9VqG3Q9hYcDR2WZvtMIJubHRsnSD42a
KodYQc8zrjtUBuY5Vp9eQgH7ZF4f+yrMWGeB3E0oPF4UXL/6w7DNZB9XoZznfLvt
IvKUd+nV6z5PvvxNeq9wBAIlrQyhj5QGqWeHmQguAEtBOin/B/bgdx1vta5UYo2c
kKYloWclpyi8pzCfU8Zn90o3AivXSUu7RM+8F96r65q4a3rWxb5IGEXWQEjotmiN
A89AeYvFJJmsi//STxuXxNoSgDF796lIeo+y1CRmDaW1eOJdBdA9wQEMYH2vtY3h
rjDY8Pg21Ng8bowBv13J7d1Qz8R0mGT0AzmX3hyiN6cqgCu2g5MgNyr2y5WgkCBM
WhdV7v5b5xxrlhyIjtZbQM81m3D6s8g2rnb+gGR0IRGqXTTLFWUPiIx6QGPMsG2s
0VWGftwGql10YQ7qH53pCIyuXnqihyOmYVieA/C9KAnIL9l0dBmhvg5gqkHmCD/z
eubYXAm7sMzxqYZ/MS7WCMZiHPkQAz7CXMJT2Qku8j36pROuu9C9OXHNkUqxDb4v
/PC27P7JVkLcI5roLL89
=Jg5k
-----END PGP SIGNATURE-----





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

* [PATCH 2/3 v2] cache: use sendfile() instead of a pair of read() + write()
  2012-06-23 10:27   ` mathstuf
@ 2012-06-23 19:25     ` cgit
  0 siblings, 0 replies; 5+ messages in thread
From: cgit @ 2012-06-23 19:25 UTC (permalink / raw)


From: Sebastian Andrzej Siewior <sebastian at breakpoint.cc>

sendfile() does the same job and avoids to copy the content into userland
and back. One has to define HAVE_LINUX_SENDFILE in case the OS (kernel & libc)
supports the Linux/glibc interface. It is disabled by default on non-linux
environments. According to the glibc, sendfile64() was added in Linux 2.4 (so
it has been there for a while) but after browsing over the mapage of FreeBSD's I
noticed that the prototype is little different.

Signed-off-by: Sebastian Andrzej Siewior <sebastian at breakpoint.cc>
---
On Sat, Jun 23, 2012 at 10:27:25AM +0000, Ben Boeckel wrote:
> On Thu, Jun 21, 2012 at 07:09:47 GMT, cgit at ml.breakpoint.cc wrote:
> > From: Sebastian Andrzej Siewior <sebastian at breakpoint.cc>
> > +ifneq ($(uname_S),Linux)
> > +	NO_SENDFILE = YesPlease
> > +endif
> 
> Double negatives suck. Can the option be made HAVE_SENDFILE?
Yes it does. What about this.

 Makefile |    9 +++++++++
 cache.c  |   26 +++++++++++++++++++++++++-
 2 files changed, 34 insertions(+), 1 deletions(-)

diff --git a/Makefile b/Makefile
index eac24ad..20cae98 100644
--- a/Makefile
+++ b/Makefile
@@ -33,6 +33,8 @@ DOC_PDF  = $(patsubst %.txt,%.pdf,$(MAN_TXT))
 # j, z, t. (representing long long int, char, intmax_t, size_t, ptrdiff_t).
 # some C compilers supported these specifiers prior to C99 as an extension.
 #
+# Define HAVE_LINUX_SENDFILE to use sendfile() as offered by glibc on Linux.
+#
 
 #-include config.mak
 
@@ -49,6 +51,10 @@ ifeq ($(uname_O),Cygwin)
 	NEEDS_LIBICONV = YesPlease
 endif
 
+ifeq ($(uname_S),Linux)
+	HAVE_LINUX_SENDFILE = YesPlease
+endif
+
 #
 # Let the user override the above settings.
 #
@@ -157,6 +163,9 @@ ifdef NO_OPENSSL
 else
 	EXTLIBS += -lcrypto
 endif
+ifdef HAVE_LINUX_SENDFILE
+	CFLAGS	+= -DHAVE_LINUX_SENDFILE
+endif
 
 cgit: $(OBJECTS) libgit
 	$(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o cgit $(OBJECTS) $(EXTLIBS)
diff --git a/cache.c b/cache.c
index d7a8d5a..963ec3a 100644
--- a/cache.c
+++ b/cache.c
@@ -13,6 +13,9 @@
  *
  */
 
+#ifdef HAVE_LINUX_SENDFILE
+#include <sys/sendfile.h>
+#endif
 #include "cgit.h"
 #include "cache.h"
 
@@ -30,7 +33,6 @@ struct cache_slot {
 	const char *lock_name;
 	int match;
 	struct stat cache_st;
-	struct stat lock_st;
 	int bufsize;
 	char buf[CACHE_BUFSIZE];
 };
@@ -81,6 +83,23 @@ 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)
 {
+#ifdef HAVE_LINUX_SENDFILE
+	off_t start_off;
+	int ret;
+
+	start_off = slot->keylen + 1;
+
+	do {
+		ret = sendfile(STDOUT_FILENO, slot->cache_fd, &start_off,
+				slot->cache_st.st_size - start_off);
+		if (ret < 0) {
+			if (errno == EAGAIN || errno == EINTR)
+				continue;
+			return errno;
+		}
+		return 0;
+	} while (1);
+#else
 	ssize_t i, j;
 
 	i = lseek(slot->cache_fd, slot->keylen + 1, SEEK_SET);
@@ -97,6 +116,7 @@ static int print_slot(struct cache_slot *slot)
 		return errno;
 	else
 		return 0;
+#endif
 }
 
 /* Check if the slot has expired */
@@ -188,6 +208,10 @@ static int fill_slot(struct cache_slot *slot)
 	/* Generate cache content */
 	slot->fn(slot->cbdata);
 
+	/* update stat info */
+	if (fstat(slot->lock_fd, &slot->cache_st))
+		return errno;
+
 	/* Restore stdout */
 	if (dup2(tmp, STDOUT_FILENO) == -1)
 		return errno;
-- 
1.7.2.5





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

end of thread, other threads:[~2012-06-23 19:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-21  7:09 [PATCH 1/3] snapshots: Don't allow sneaked in snapshots requests cgit
2012-06-21  7:09 ` [PATCH 2/3] cache: use sendfile() instead of a pair of read() + write() cgit
2012-06-23 10:27   ` mathstuf
2012-06-23 19:25     ` [PATCH 2/3 v2] " cgit
2012-06-21  7:09 ` [PATCH 3/3] summary: Add tag head line in the dowload section cgit

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).