summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--Makefile5
-rw-r--r--cgit.css11
-rw-r--r--cgit.h7
-rw-r--r--parsing.c25
-rw-r--r--shared.c2
-rw-r--r--ui-log.c21
-rw-r--r--ui-shared.c2
7 files changed, 55 insertions, 18 deletions
diff --git a/Makefile b/Makefile
index 27e966d..685e662 100644
--- a/Makefile
+++ b/Makefile
@@ -1,45 +1,50 @@
CGIT_VERSION = v0.7.1
CGIT_SCRIPT_NAME = cgit.cgi
CGIT_SCRIPT_PATH = /var/www/htdocs/cgit
CGIT_CONFIG = /etc/cgitrc
CACHE_ROOT = /var/cache/cgit
SHA1_HEADER = <openssl/sha.h>
GIT_VER = 1.5.3.5
GIT_URL = http://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.bz2
#
# Let the user override the above settings.
#
-include cgit.conf
EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto
OBJECTS = shared.o cache.o parsing.o html.o ui-shared.o ui-repolist.o \
ui-summary.o ui-log.o ui-tree.o ui-commit.o ui-diff.o \
ui-snapshot.o ui-blob.o ui-tag.o ui-refs.o
+ifdef NEEDS_LIBICONV
+ EXTLIBS += -liconv
+endif
+
+
.PHONY: all git install clean distclean emptycache force-version get-git
all: cgit git
VERSION: force-version
@./gen-version.sh "$(CGIT_VERSION)"
-include VERSION
CFLAGS += -g -Wall -Igit
CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)'
CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"'
CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"'
CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"'
CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"'
cgit: cgit.c $(OBJECTS)
$(CC) $(CFLAGS) cgit.c -o cgit $(OBJECTS) $(EXTLIBS)
$(OBJECTS): cgit.h git/xdiff/lib.a git/libgit.a VERSION
git/xdiff/lib.a: | git
diff --git a/cgit.css b/cgit.css
index 1b2e9d6..f1003b4 100644
--- a/cgit.css
+++ b/cgit.css
@@ -88,91 +88,82 @@ div#sidebar {
div#logo {
margin: 0px;
padding: 4px 0px 4px 0px;
text-align: center;
background-color: #ccc;
border-top: solid 1px #eee;
border-left: solid 1px #eee;
border-right: solid 1px #aaa;
border-bottom: solid 1px #aaa;
}
div#sidebar div.infobox {
margin: 0px 0px 0px 0px;
padding: 0.5em;
text-align: left;
background-color: #ccc;
border-top: solid 1px #eee;
border-left: solid 1px #eee;
border-right: solid 1px #aaa;
border-bottom: solid 1px #aaa;
}
div#sidebar div.infobox h1 {
- font-size: 11pt;
+ font-size: 10pt;
font-weight: bold;
margin: 0px;
}
div#sidebar div.infobox a.menu {
display: block;
background-color: #ccc;
padding: 0.1em 0.5em;
text-decoration: none;
}
div#sidebar div.infobox a.menu:hover {
background-color: #bbb;
text-decoration: none;
}
div#sidebar div.infobox select {
width: 100%;
- border: solid 1px #aaa;
- background-color: #bbb;
margin: 2px 0px 0px 0px;
- padding: 0px;
}
td#branch-dropdown-cell {
width: 99%;
}
input#switch-btn {
width: 20px;
- border: solid 1px #aaa;
- background-color: #bbb;
margin: 2px 0px 0px 0px;
- padding: 0px;
}
div#sidebar div.infobox input.txt {
width: 100%;
- border: solid 1px #aaa;
- background-color: #bbb;
margin: 2px 0px 0px 0px;
- padding: 0;
}
table#grid {
margin: 0px;
}
td#content {
vertical-align: top;
padding: 1em 2em 1em 1em;
border: none;
}
div#summary {
vertical-align: top;
margin-bottom: 1em;
}
table#downloads {
float: right;
border-collapse: collapse;
border: solid 1px #777;
margin-left: 0.5em;
margin-bottom: 0.5em;
}
diff --git a/cgit.h b/cgit.h
index 163f355..6291c58 100644
--- a/cgit.h
+++ b/cgit.h
@@ -1,116 +1,123 @@
#ifndef CGIT_H
#define CGIT_H
#include <git-compat-util.h>
#include <cache.h>
#include <grep.h>
#include <object.h>
#include <tree.h>
#include <commit.h>
#include <tag.h>
#include <diff.h>
#include <diffcore.h>
#include <refs.h>
#include <revision.h>
#include <log-tree.h>
#include <archive.h>
#include <xdiff/xdiff.h>
+#include <utf8.h>
/*
* The valid cgit repo-commands
*/
#define CMD_LOG 1
#define CMD_COMMIT 2
#define CMD_DIFF 3
#define CMD_TREE 4
#define CMD_BLOB 5
#define CMD_SNAPSHOT 6
#define CMD_TAG 7
#define CMD_REFS 8
/*
* Dateformats used on misc. pages
*/
#define FMT_LONGDATE "%Y-%m-%d %H:%M:%S"
#define FMT_SHORTDATE "%Y-%m-%d"
/*
* Limits used for relative dates
*/
#define TM_MIN 60
#define TM_HOUR (TM_MIN * 60)
#define TM_DAY (TM_HOUR * 24)
#define TM_WEEK (TM_DAY * 7)
#define TM_YEAR (TM_DAY * 365)
#define TM_MONTH (TM_YEAR / 12.0)
+/*
+ * Default encoding
+ */
+#define PAGE_ENCODING "UTF-8"
+
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);
struct cacheitem {
char *name;
struct stat st;
int ttl;
int fd;
};
struct repoinfo {
char *url;
char *name;
char *path;
char *desc;
char *owner;
char *defbranch;
char *group;
char *module_link;
char *readme;
int snapshots;
int enable_log_filecount;
int enable_log_linecount;
};
struct repolist {
int length;
int count;
struct repoinfo *repos;
};
struct commitinfo {
struct commit *commit;
char *author;
char *author_email;
unsigned long author_date;
char *committer;
char *committer_email;
unsigned long committer_date;
char *subject;
char *msg;
+ char *msg_encoding;
};
struct taginfo {
char *tagger;
char *tagger_email;
int tagger_date;
char *msg;
};
struct refinfo {
const char *refname;
struct object *object;
union {
struct taginfo *tag;
struct commitinfo *commit;
};
};
struct reflist {
struct refinfo **refs;
int alloc;
int count;
};
diff --git a/parsing.c b/parsing.c
index 30e7648..e8c7ab9 100644
--- a/parsing.c
+++ b/parsing.c
@@ -178,102 +178,127 @@ void cgit_parse_url(const char *url)
char *substr(const char *head, const char *tail)
{
char *buf;
buf = xmalloc(tail - head + 1);
strncpy(buf, head, tail - head);
buf[tail - head] = '\0';
return buf;
}
struct commitinfo *cgit_parse_commit(struct commit *commit)
{
struct commitinfo *ret;
char *p = commit->buffer, *t = commit->buffer;
ret = xmalloc(sizeof(*ret));
ret->commit = commit;
ret->author = NULL;
ret->author_email = NULL;
ret->committer = NULL;
ret->committer_email = NULL;
ret->subject = NULL;
ret->msg = NULL;
+ ret->msg_encoding = NULL;
if (p == NULL)
return ret;
if (strncmp(p, "tree ", 5))
die("Bad commit: %s", sha1_to_hex(commit->object.sha1));
else
p += 46; // "tree " + hex[40] + "\n"
while (!strncmp(p, "parent ", 7))
p += 48; // "parent " + hex[40] + "\n"
if (!strncmp(p, "author ", 7)) {
p += 7;
t = strchr(p, '<') - 1;
ret->author = substr(p, t);
p = t;
t = strchr(t, '>') + 1;
ret->author_email = substr(p, t);
ret->author_date = atol(++t);
p = strchr(t, '\n') + 1;
}
if (!strncmp(p, "committer ", 9)) {
p += 9;
t = strchr(p, '<') - 1;
ret->committer = substr(p, t);
p = t;
t = strchr(t, '>') + 1;
ret->committer_email = substr(p, t);
ret->committer_date = atol(++t);
p = strchr(t, '\n') + 1;
}
+ if (!strncmp(p, "encoding ", 9)) {
+ p += 9;
+ t = strchr(p, '\n') + 1;
+ ret->msg_encoding = substr(p, t);
+ p = t;
+ } else
+ ret->msg_encoding = xstrdup(PAGE_ENCODING);
+
while (*p && (*p != '\n'))
p = strchr(p, '\n') + 1; // skip unknown header fields
while (*p == '\n')
p = strchr(p, '\n') + 1;
t = strchr(p, '\n');
if (t) {
if (*t == '\0')
ret->subject = "** empty **";
else
ret->subject = substr(p, t);
p = t + 1;
while (*p == '\n')
p = strchr(p, '\n') + 1;
ret->msg = xstrdup(p);
} else
ret->subject = substr(p, p+strlen(p));
+ if(strcmp(ret->msg_encoding, PAGE_ENCODING)) {
+ t = reencode_string(ret->subject, PAGE_ENCODING,
+ ret->msg_encoding);
+ if(t) {
+ free(ret->subject);
+ ret->subject = t;
+ }
+
+ t = reencode_string(ret->msg, PAGE_ENCODING,
+ ret->msg_encoding);
+ if(t) {
+ free(ret->msg);
+ ret->msg = t;
+ }
+ }
+
return ret;
}
struct taginfo *cgit_parse_tag(struct tag *tag)
{
void *data;
enum object_type type;
unsigned long size;
char *p, *t;
struct taginfo *ret;
data = read_sha1_file(tag->object.sha1, &type, &size);
if (!data || type != OBJ_TAG) {
free(data);
return 0;
}
ret = xmalloc(sizeof(*ret));
ret->tagger = NULL;
ret->tagger_email = NULL;
ret->tagger_date = 0;
ret->msg = NULL;
diff --git a/shared.c b/shared.c
index 6117f5c..8cb4808 100644
--- a/shared.c
+++ b/shared.c
@@ -246,48 +246,50 @@ void cgit_querystring_cb(const char *name, const char *value)
cgit_query_head = xstrdup(value);
cgit_query_has_symref = 1;
} else if (!strcmp(name, "id")) {
cgit_query_sha1 = xstrdup(value);
cgit_query_has_sha1 = 1;
} else if (!strcmp(name, "id2")) {
cgit_query_sha2 = xstrdup(value);
cgit_query_has_sha1 = 1;
} else if (!strcmp(name, "ofs")) {
cgit_query_ofs = atoi(value);
} else if (!strcmp(name, "path")) {
cgit_query_path = trim_end(value, '/');
} else if (!strcmp(name, "name")) {
cgit_query_name = xstrdup(value);
}
}
void *cgit_free_commitinfo(struct commitinfo *info)
{
free(info->author);
free(info->author_email);
free(info->committer);
free(info->committer_email);
free(info->subject);
+ free(info->msg);
+ free(info->msg_encoding);
free(info);
return NULL;
}
int hextoint(char c)
{
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;
}
char *trim_end(const char *str, char c)
{
int len;
char *s, *t;
if (str == NULL)
return NULL;
t = (char *)str;
diff --git a/ui-log.c b/ui-log.c
index 9f5fdf6..e5f3c57 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -1,117 +1,124 @@
/* ui-log.c: functions for log output
*
* Copyright (C) 2006 Lars Hjemli
*
* Licensed under GNU General Public License v2
* (see COPYING for full license text)
*/
#include "cgit.h"
-int files, lines;
+int files, add_lines, rem_lines;
void count_lines(char *line, int size)
{
- if (size>0 && (line[0] == '+' || line[0] == '-'))
- lines++;
+ if (size <= 0)
+ return;
+
+ if (line[0] == '+')
+ add_lines++;
+
+ else if (line[0] == '-')
+ rem_lines++;
}
void inspect_files(struct diff_filepair *pair)
{
files++;
if (cgit_repo->enable_log_linecount)
cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines);
}
void print_commit(struct commit *commit)
{
struct commitinfo *info;
info = cgit_parse_commit(commit);
html("<tr><td>");
cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE);
html("</td><td>");
cgit_commit_link(info->subject, NULL, NULL, cgit_query_head,
sha1_to_hex(commit->object.sha1));
if (cgit_repo->enable_log_filecount) {
files = 0;
- lines = 0;
+ add_lines = 0;
+ rem_lines = 0;
cgit_diff_commit(commit, inspect_files);
html("</td><td class='right'>");
htmlf("%d", files);
if (cgit_repo->enable_log_linecount) {
html("</td><td class='right'>");
- htmlf("%d", lines);
+ htmlf("-%d/+%d", rem_lines, add_lines);
}
}
html("</td><td>");
html_txt(info->author);
html("</td></tr>\n");
cgit_free_commitinfo(info);
}
void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, char *path, int pager)
{
struct rev_info rev;
struct commit *commit;
const char *argv[] = {NULL, tip, NULL, NULL, NULL};
int argc = 2;
int i;
if (!tip)
argv[1] = cgit_query_head;
if (grep && pattern && (!strcmp(grep, "grep") ||
!strcmp(grep, "author") ||
!strcmp(grep, "committer")))
argv[argc++] = fmt("--%s=%s", grep, pattern);
if (path) {
argv[argc++] = "--";
argv[argc++] = path;
}
init_revisions(&rev, NULL);
rev.abbrev = DEFAULT_ABBREV;
rev.commit_format = CMIT_FMT_DEFAULT;
rev.verbose_header = 1;
rev.show_root_diff = 0;
setup_revisions(argc, argv, &rev, NULL);
if (rev.grep_filter) {
rev.grep_filter->regflags |= REG_ICASE;
compile_grep_patterns(rev.grep_filter);
}
prepare_revision_walk(&rev);
html("<table class='list nowrap'>");
html("<tr class='nohover'><th class='left'>Age</th>"
"<th class='left'>Message</th>");
if (cgit_repo->enable_log_filecount) {
- html("<th class='left'>Files</th>");
+ html("<th class='right'>Files</th>");
if (cgit_repo->enable_log_linecount)
- html("<th class='left'>Lines</th>");
+ html("<th class='right'>Lines</th>");
}
html("<th class='left'>Author</th></tr>\n");
if (ofs<0)
ofs = 0;
for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) {
free(commit->buffer);
commit->buffer = NULL;
free_commit_list(commit->parents);
commit->parents = NULL;
}
for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) {
print_commit(commit);
free(commit->buffer);
commit->buffer = NULL;
free_commit_list(commit->parents);
commit->parents = NULL;
}
html("</table>\n");
if (pager) {
html("<div class='pager'>");
diff --git a/ui-shared.c b/ui-shared.c
index 72a7b44..7c69f60 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -331,49 +331,49 @@ void cgit_print_age(time_t t, time_t max_relative, char *format)
secs * 1.0 / TM_HOUR);
return;
}
if (secs < TM_WEEK * 2) {
htmlf("<span class='age-days'>%.0f days</span>",
secs * 1.0 / TM_DAY);
return;
}
if (secs < TM_MONTH * 2) {
htmlf("<span class='age-weeks'>%.0f weeks</span>",
secs * 1.0 / TM_WEEK);
return;
}
if (secs < TM_YEAR * 2) {
htmlf("<span class='age-months'>%.0f months</span>",
secs * 1.0 / TM_MONTH);
return;
}
htmlf("<span class='age-years'>%.0f years</span>",
secs * 1.0 / TM_YEAR);
}
void cgit_print_docstart(char *title, struct cacheitem *item)
{
- html("Content-Type: text/html; charset=utf-8\n");
+ html("Content-Type: text/html; charset=" PAGE_ENCODING "\n");
htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime));
htmlf("Expires: %s\n", http_date(item->st.st_mtime +
ttl_seconds(item->ttl)));
html("\n");
html(cgit_doctype);
html("<html>\n");
html("<head>\n");
html("<title>");
html_txt(title);
html("</title>\n");
htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version);
html("<link rel='stylesheet' type='text/css' href='");
html_attr(cgit_css);
html("'/>\n");
html("</head>\n");
html("<body>\n");
}
void cgit_print_docend()
{
html("</td>\n</tr>\n<table>\n</body>\n</html>\n");
}
int print_branch_option(const char *refname, const unsigned char *sha1,