Merge branch 'stable'

This commit is contained in:
Lars Hjemli 2011-05-23 23:26:10 +02:00
commit 652a5a18db
9 fájl változott, egészen pontosan 61 új sor hozzáadva és 29 régi sor törölve

5
cgit.c
Fájl megtekintése

@ -767,8 +767,11 @@ int main(int argc, const char **argv)
* that virtual-root equals SCRIPT_NAME, minus any possibly * that virtual-root equals SCRIPT_NAME, minus any possibly
* trailing slashes. * trailing slashes.
*/ */
if (!ctx.cfg.virtual_root) if (!ctx.cfg.virtual_root && ctx.cfg.script_name) {
ctx.cfg.virtual_root = trim_end(ctx.cfg.script_name, '/'); ctx.cfg.virtual_root = trim_end(ctx.cfg.script_name, '/');
if (!ctx.cfg.virtual_root)
ctx.cfg.virtual_root = "";
}
/* If no url parameter is specified on the querystring, lets /* If no url parameter is specified on the querystring, lets
* use PATH_INFO as url. This allows cgit to work with virtual * use PATH_INFO as url. This allows cgit to work with virtual

15
html.c
Fájl megtekintése

@ -18,7 +18,7 @@ static const char* url_escape_table[256] = {
"%00", "%01", "%02", "%03", "%04", "%05", "%06", "%07", "%08", "%09", "%00", "%01", "%02", "%03", "%04", "%05", "%06", "%07", "%08", "%09",
"%0a", "%0b", "%0c", "%0d", "%0e", "%0f", "%10", "%11", "%12", "%13", "%0a", "%0b", "%0c", "%0d", "%0e", "%0f", "%10", "%11", "%12", "%13",
"%14", "%15", "%16", "%17", "%18", "%19", "%1a", "%1b", "%1c", "%1d", "%14", "%15", "%16", "%17", "%18", "%19", "%1a", "%1b", "%1c", "%1d",
"%1e", "%1f", "+", 0, "%22", "%23", 0, "%25", "%26", "%27", 0, 0, 0, "%1e", "%1f", "%20", 0, "%22", "%23", 0, "%25", "%26", "%27", 0, 0, 0,
"%2b", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "%3c", "%3d", "%2b", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "%3c", "%3d",
"%3e", "%3f", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "%3e", "%3f", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, "%5c", 0, "%5e", 0, "%60", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "%5c", 0, "%5e", 0, "%60", 0, 0, 0, 0, 0,
@ -162,9 +162,9 @@ void html_url_path(const char *txt)
while(t && *t){ while(t && *t){
int c = *t; int c = *t;
const char *e = url_escape_table[c]; const char *e = url_escape_table[c];
if (e && c!='+' && c!='&' && c!='+') { if (e && c!='+' && c!='&') {
html_raw(txt, t - txt); html_raw(txt, t - txt);
html_raw(e, 3); html(e);
txt = t+1; txt = t+1;
} }
t++; t++;
@ -179,9 +179,11 @@ void html_url_arg(const char *txt)
while(t && *t){ while(t && *t){
int c = *t; int c = *t;
const char *e = url_escape_table[c]; const char *e = url_escape_table[c];
if (c == ' ')
e = "+";
if (e) { if (e) {
html_raw(txt, t - txt); html_raw(txt, t - txt);
html_raw(e, strlen(e)); html(e);
txt = t+1; txt = t+1;
} }
t++; t++;
@ -288,12 +290,12 @@ char *convert_query_hexchar(char *txt)
int http_parse_querystring(const char *txt_, void (*fn)(const char *name, const char *value)) int http_parse_querystring(const char *txt_, void (*fn)(const char *name, const char *value))
{ {
char *t, *txt, *value = NULL, c; char *o, *t, *txt, *value = NULL, c;
if (!txt_) if (!txt_)
return 0; return 0;
t = txt = strdup(txt_); o = t = txt = strdup(txt_);
if (t == NULL) { if (t == NULL) {
printf("Out of memory\n"); printf("Out of memory\n");
exit(1); exit(1);
@ -316,5 +318,6 @@ int http_parse_querystring(const char *txt_, void (*fn)(const char *name, const
} }
if (t!=txt) if (t!=txt)
(*fn)(txt, value); (*fn)(txt, value);
free(o);
return 0; return 0;
} }

Fájl megtekintése

@ -103,7 +103,10 @@ const char *reencode(char **txt, const char *src_enc, const char *dst_enc)
{ {
char *tmp; char *tmp;
if (!txt || !*txt || !src_enc || !dst_enc) if (!txt)
return NULL;
if (!*txt || !src_enc || !dst_enc)
return *txt; return *txt;
/* no encoding needed if src_enc equals dst_enc */ /* no encoding needed if src_enc equals dst_enc */

Fájl megtekintése

@ -100,23 +100,15 @@ void *cgit_free_commitinfo(struct commitinfo *info)
char *trim_end(const char *str, char c) char *trim_end(const char *str, char c)
{ {
int len; int len;
char *s, *t;
if (str == NULL) if (str == NULL)
return NULL; return NULL;
t = (char *)str; len = strlen(str);
len = strlen(t); while(len > 0 && str[len - 1] == c)
while(len > 0 && t[len - 1] == c)
len--; len--;
if (len == 0) if (len == 0)
return NULL; return NULL;
return xstrndup(str, len);
c = t[len];
t[len] = '\0';
s = xstrdup(t);
t[len] = c;
return s;
} }
char *strlpart(char *txt, int maxlen) char *strlpart(char *txt, int maxlen)
@ -311,7 +303,6 @@ void cgit_diff_tree(const unsigned char *old_sha1,
filepair_fn fn, const char *prefix, int ignorews) filepair_fn fn, const char *prefix, int ignorews)
{ {
struct diff_options opt; struct diff_options opt;
int ret;
int prefixlen; int prefixlen;
diff_setup(&opt); diff_setup(&opt);
@ -332,9 +323,9 @@ void cgit_diff_tree(const unsigned char *old_sha1,
diff_setup_done(&opt); diff_setup_done(&opt);
if (old_sha1 && !is_null_sha1(old_sha1)) if (old_sha1 && !is_null_sha1(old_sha1))
ret = diff_tree_sha1(old_sha1, new_sha1, "", &opt); diff_tree_sha1(old_sha1, new_sha1, "", &opt);
else else
ret = diff_root_tree_sha1(new_sha1, "", &opt); diff_root_tree_sha1(new_sha1, "", &opt);
diffcore_std(&opt); diffcore_std(&opt);
diff_flush(&opt); diff_flush(&opt);
} }

Fájl megtekintése

@ -20,10 +20,10 @@ mkrepo() {
name=$1 name=$1
count=$2 count=$2
dir=$PWD dir=$PWD
test -d $name && return test -d "$name" && return
printf "Creating testrepo %s\n" $name printf "Creating testrepo %s\n" $name
mkdir -p $name mkdir -p "$name"
cd $name cd "$name"
git init git init
n=1 n=1
while test $n -le $count while test $n -le $count
@ -50,6 +50,7 @@ setup_repos()
mkrepo trash/repos/foo 5 >/dev/null mkrepo trash/repos/foo 5 >/dev/null
mkrepo trash/repos/bar 50 >/dev/null mkrepo trash/repos/bar 50 >/dev/null
mkrepo trash/repos/foo+bar 10 testplus >/dev/null mkrepo trash/repos/foo+bar 10 testplus >/dev/null
mkrepo "trash/repos/with space" 2 >/dev/null
cat >trash/cgitrc <<EOF cat >trash/cgitrc <<EOF
virtual-root=/ virtual-root=/
cache-root=$PWD/trash/cache cache-root=$PWD/trash/cache
@ -75,6 +76,10 @@ repo.desc=the bar repo
repo.url=foo+bar repo.url=foo+bar
repo.path=$PWD/trash/repos/foo+bar/.git repo.path=$PWD/trash/repos/foo+bar/.git
repo.desc=the foo+bar repo repo.desc=the foo+bar repo
repo.url=with space
repo.path=$PWD/trash/repos/with space/.git
repo.desc=spaced repo
EOF EOF
} }
@ -101,6 +106,12 @@ tests_done()
run_test() run_test()
{ {
bug=0
if test "$1" = "BUG"
then
bug=1
shift
fi
desc=$1 desc=$1
script=$2 script=$2
test_count=$(expr $test_count + 1) test_count=$(expr $test_count + 1)
@ -109,9 +120,15 @@ run_test()
eval "$2" >>test-output.log 2>>test-output.log eval "$2" >>test-output.log 2>>test-output.log
res=$? res=$?
printf "test %d: exitcode=%d\n" $test_count $res >>test-output.log printf "test %d: exitcode=%d\n" $test_count $res >>test-output.log
if test $res = 0 if test $res = 0 -a $bug = 0
then then
printf " %2d) %-60s [ok]\n" $test_count "$desc" printf " %2d) %-60s [ok]\n" $test_count "$desc"
elif test $res = 0 -a $bug = 1
then
printf " %2d) %-60s [BUG FIXED]\n" $test_count "$desc"
elif test $bug = 1
then
printf " %2d) %-60s [KNOWN BUG]\n" $test_count "$desc"
else else
test_failed=$(expr $test_failed + 1) test_failed=$(expr $test_failed + 1)
printf " %2d) %-60s [failed]\n" $test_count "$desc" printf " %2d) %-60s [failed]\n" $test_count "$desc"

Fájl megtekintése

@ -11,6 +11,7 @@ run_test 'find bar repo' 'grep -e "bar" trash/tmp'
run_test 'find bar description' 'grep -e "the bar repo" trash/tmp' run_test 'find bar description' 'grep -e "the bar repo" trash/tmp'
run_test 'find foo+bar repo' 'grep -e ">foo+bar<" trash/tmp' run_test 'find foo+bar repo' 'grep -e ">foo+bar<" trash/tmp'
run_test 'verify foo+bar link' 'grep -e "/foo+bar/" trash/tmp' run_test 'verify foo+bar link' 'grep -e "/foo+bar/" trash/tmp'
run_test 'verify "with%20space" link' 'grep -e "/with%20space/" trash/tmp'
run_test 'no tree-link' '! grep -e "foo/tree" trash/tmp' run_test 'no tree-link' '! grep -e "foo/tree" trash/tmp'
run_test 'no log-link' '! grep -e "foo/log" trash/tmp' run_test 'no log-link' '! grep -e "foo/log" trash/tmp'

Fájl megtekintése

@ -12,4 +12,14 @@ run_test 'generate bar/log' 'cgit_url "bar/log" >trash/tmp'
run_test 'find commit 1' 'grep -e "commit 1" trash/tmp' run_test 'find commit 1' 'grep -e "commit 1" trash/tmp'
run_test 'find commit 50' 'grep -e "commit 50" trash/tmp' run_test 'find commit 50' 'grep -e "commit 50" trash/tmp'
run_test 'generate "with%20space/log?qt=grep&q=commit+1"' '
cgit_url "with+space/log&qt=grep&q=commit+1" >trash/tmp
'
run_test 'find commit 1' 'grep -e "commit 1" trash/tmp'
run_test 'find link with %20 in path' 'grep -e "/with%20space/log/?qt=grep" trash/tmp'
run_test 'find link with + in arg' 'grep -e "/log/?qt=grep&q=commit+1" trash/tmp'
run_test BUG 'no links with space in path' '! grep -e "href=./with space/" trash/tmp'
run_test 'no links with space in arg' '! grep -e "q=commit 1" trash/tmp'
run_test 'commit 2 is not visible' '! grep -e "commit 2" trash/tmp'
tests_done tests_done

Fájl megtekintése

@ -345,8 +345,10 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefi
return; return;
} }
commit = lookup_commit_reference(new_rev_sha1); commit = lookup_commit_reference(new_rev_sha1);
if (!commit || parse_commit(commit)) if (!commit || parse_commit(commit)) {
cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(new_rev_sha1))); cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(new_rev_sha1)));
return;
}
if (old_rev) if (old_rev)
get_sha1(old_rev, old_rev_sha1); get_sha1(old_rev, old_rev_sha1);
@ -362,8 +364,10 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefi
return; return;
} }
commit2 = lookup_commit_reference(old_rev_sha1); commit2 = lookup_commit_reference(old_rev_sha1);
if (!commit2 || parse_commit(commit2)) if (!commit2 || parse_commit(commit2)) {
cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(old_rev_sha1))); cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(old_rev_sha1)));
return;
}
} }
if ((ctx.qry.ssdiff && !ctx.cfg.ssdiff) || (!ctx.qry.ssdiff && ctx.cfg.ssdiff)) if ((ctx.qry.ssdiff && !ctx.cfg.ssdiff) || (!ctx.qry.ssdiff && ctx.cfg.ssdiff))

Fájl megtekintése

@ -20,7 +20,7 @@ time_t read_agefile(char *path)
if (readfile(path, &buf, &size)) if (readfile(path, &buf, &size))
return -1; return -1;
if (parse_date(buf, buf2, sizeof(buf2))) if (parse_date(buf, buf2, sizeof(buf2)) > 0)
result = strtoul(buf2, NULL, 10); result = strtoul(buf2, NULL, 10);
else else
result = 0; result = 0;