[PATCH 2/3] ui-shared: add cgit_blame_link()

John Keeping john at keeping.me.uk
Wed Aug 12 15:03:35 CEST 2015


---
 ui-shared.c | 40 ++++++++++++++++++++++++++++++++++++++++
 ui-shared.h |  3 +++
 2 files changed, 43 insertions(+)

diff --git a/ui-shared.c b/ui-shared.c
index ac5a287..da9c3d0 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -338,6 +338,46 @@ void cgit_log_link(const char *name, const char *title, const char *class,
 	html("</a>");
 }
 
+void cgit_blame_link(char *name, const char *title, const char *class,
+		     const char *head, const char *rev, const char *path,
+		     long line)
+{
+	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] = '.';
+	}
+
+	char *delim;
+
+	delim = repolink(title, class, "blame", head, path);
+	if (rev && ctx.qry.head && strcmp(rev, ctx.qry.head)) {
+		html(delim);
+		html("id=");
+		html_url_arg(rev);
+		delim = "&";
+	}
+	if (ctx.qry.difftype) {
+		html(delim);
+		htmlf("dt=%d", ctx.qry.difftype);
+		delim = "&";
+	}
+	if (ctx.qry.ignorews) {
+		html(delim);
+		html("ignorews=1");
+		delim = "&";
+	}
+	if (line >= 0)
+		htmlf("#l%ld", line);
+	html("'>");
+	if (name[0] != '\0')
+		html_txt(name);
+	else
+		html_txt("(no commit message)");
+	html("</a>");
+}
+
 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-shared.h b/ui-shared.h
index 1b8ecb5..9a406d0 100644
--- a/ui-shared.h
+++ b/ui-shared.h
@@ -30,6 +30,9 @@ 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);
+extern void cgit_blame_link(char *name, const char *title,
+			    const char *class, const char *head,
+			    const char *rev, const char *path, long line);
 extern void cgit_commit_link(char *name, const char *title,
 			     const char *class, const char *head,
 			     const char *rev, const char *path);
-- 
2.5.0.466.g9af26fa



More information about the CGit mailing list