]> gitweb.ps.run Git - ps-cgit/commitdiff
Merge branch 'stable'
authorLars Hjemli <hjemli@gmail.com>
Thu, 8 Nov 2007 11:22:39 +0000 (12:22 +0100)
committerLars Hjemli <hjemli@gmail.com>
Thu, 8 Nov 2007 11:22:39 +0000 (12:22 +0100)
* stable:
  Support "/" as virtual-root

Makefile
cgit.h
parsing.c
shared.c
ui-log.c
ui-shared.c

index 6abd82a11bed5edcdf190d098f1d61c93e599db5..dbc34a263625557d1c439687b8eff453da49082e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -19,6 +19,11 @@ OBJECTS = shared.o cache.o parsing.o html.o ui-shared.o ui-repolist.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 force-version get-git
 
 all: cgit git
diff --git a/cgit.h b/cgit.h
index 163f355a022dab2dbbdb6f61b6040bacf3730c68..6291c585d57536ac69e00993e347152b096ad949 100644 (file)
--- a/cgit.h
+++ b/cgit.h
@@ -16,6 +16,7 @@
 #include <log-tree.h>
 #include <archive.h>
 #include <xdiff/xdiff.h>
+#include <utf8.h>
 
 
 /*
 #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);
@@ -90,6 +96,7 @@ struct commitinfo {
        unsigned long committer_date;
        char *subject;
        char *msg;
+       char *msg_encoding;
 };
 
 struct taginfo {
index 30e7648958789fb72930c405d1ba8d8c5a382f27..e8c7ab986ae563424c98d1d21fe3549e2f27b22f 100644 (file)
--- a/parsing.c
+++ b/parsing.c
@@ -199,6 +199,7 @@ struct commitinfo *cgit_parse_commit(struct commit *commit)
        ret->committer_email = NULL;
        ret->subject = NULL;
        ret->msg = NULL;
+       ret->msg_encoding = NULL;
 
        if (p == NULL)
                return ret;
@@ -233,6 +234,14 @@ struct commitinfo *cgit_parse_commit(struct commit *commit)
                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
 
@@ -253,6 +262,22 @@ struct commitinfo *cgit_parse_commit(struct commit *commit)
        } 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;
 }
 
index 6117f5c7ae0ebf7cebcda1c48ab2d2b6aa4b5c2f..8cb480889bc83fbd577614935c162ad2836c55bd 100644 (file)
--- a/shared.c
+++ b/shared.c
@@ -267,6 +267,8 @@ void *cgit_free_commitinfo(struct commitinfo *info)
        free(info->committer);
        free(info->committer_email);
        free(info->subject);
+       free(info->msg);
+       free(info->msg_encoding);
        free(info);
        return NULL;
 }
index 9f5fdf6dbbaf43bca750a4040302cea5169f39da..e5f3c574038273869ec695a739e1863af801ef6e 100644 (file)
--- a/ui-log.c
+++ b/ui-log.c
@@ -8,12 +8,18 @@
 
 #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)
@@ -35,13 +41,14 @@ void print_commit(struct commit *commit)
                         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>");
@@ -88,9 +95,9 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
             "<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");
 
index 72a7b44472ddb483b9bc6640d029380ac11afd8b..7c69f60f80a5a8dd495b73497132693297496a81 100644 (file)
@@ -352,7 +352,7 @@ void cgit_print_age(time_t t, time_t max_relative, char *format)
 
 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)));