* Remove whitespace at the end of lines.
* Replace space indentation by tabs.
* Add whitespace before/after several operators ("+", "-", "*", ...)
* Add whitespace to assignments ("foo = bar;").
* Fix whitespace in parameter lists ("foobar(foo, bar, 42)").
Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de>
if (slot->ttl < 0)
return 0;
else
- return slot->cache_st.st_mtime + slot->ttl*60 < time(NULL);
+ return slot->cache_st.st_mtime + slot->ttl * 60 < time(NULL);
}
/* Check if the slot has been modified since we opened it.
*/
static int lock_slot(struct cache_slot *slot)
{
- slot->lock_fd = open(slot->lock_name, O_RDWR|O_CREAT|O_EXCL,
- S_IRUSR|S_IWUSR);
+ slot->lock_fd = open(slot->lock_name, O_RDWR | O_CREAT | O_EXCL,
+ S_IRUSR | S_IWUSR);
if (slot->lock_fd == -1)
return errno;
if (xwrite(slot->lock_fd, slot->key, slot->keylen + 1) < 0)
for (i = 1; i < argc; i++) {
if (!strncmp(argv[i], "--cache=", 8)) {
- ctx.cfg.cache_root = xstrdup(argv[i]+8);
+ ctx.cfg.cache_root = xstrdup(argv[i] + 8);
}
if (!strcmp(argv[i], "--nocache")) {
ctx.cfg.nocache = 1;
ctx.env.no_http = "1";
}
if (!strncmp(argv[i], "--query=", 8)) {
- ctx.qry.raw = xstrdup(argv[i]+8);
+ ctx.qry.raw = xstrdup(argv[i] + 8);
}
if (!strncmp(argv[i], "--repo=", 7)) {
- ctx.qry.repo = xstrdup(argv[i]+7);
+ ctx.qry.repo = xstrdup(argv[i] + 7);
}
if (!strncmp(argv[i], "--page=", 7)) {
- ctx.qry.page = xstrdup(argv[i]+7);
+ ctx.qry.page = xstrdup(argv[i] + 7);
}
if (!strncmp(argv[i], "--head=", 7)) {
- ctx.qry.head = xstrdup(argv[i]+7);
+ ctx.qry.head = xstrdup(argv[i] + 7);
ctx.qry.has_symref = 1;
}
if (!strncmp(argv[i], "--sha1=", 7)) {
- ctx.qry.sha1 = xstrdup(argv[i]+7);
+ ctx.qry.sha1 = xstrdup(argv[i] + 7);
ctx.qry.has_sha1 = 1;
}
if (!strncmp(argv[i], "--ofs=", 6)) {
- ctx.qry.ofs = atoi(argv[i]+6);
+ ctx.qry.ofs = atoi(argv[i] + 6);
}
if (!strncmp(argv[i], "--scan-tree=", 12) ||
!strncmp(argv[i], "--scan-path=", 12)) {
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
* use PATH_INFO as url. This allows cgit to work with virtual
}
ttl = calc_ttl();
- ctx.page.expires += ttl*60;
+ ctx.page.expires += ttl * 60;
if (ctx.env.request_method && !strcmp(ctx.env.request_method, "HEAD"))
ctx.cfg.nocache = 1;
if (ctx.cfg.nocache)
int next_char(FILE *f)
{
int c = fgetc(f);
- if (c=='\r') {
+ if (c == '\r') {
c = fgetc(f);
- if (c!='\n') {
+ if (c != '\n') {
ungetc(c, f);
c = '\r';
}
{
int c;
- while((c=next_char(f)) && c!='\n' && c!=EOF)
+ while((c = next_char(f)) && c != '\n' && c != EOF)
;
}
int i = 0, isname = 0;
*value = NULL;
- while(i<bufsize-1) {
+ while(i < bufsize - 1) {
int c = next_char(f);
- if (!isname && (c=='#' || c==';')) {
+ if (!isname && (c == '#' || c == ';')) {
skip_line(f);
continue;
}
if (!isname && isspace(c))
continue;
- if (c=='=' && !*value) {
+ if (c == '=' && !*value) {
line[i] = 0;
- *value = &line[i+1];
- } else if (c=='\n' && !isname) {
+ *value = &line[i + 1];
+ } else if (c == '\n' && !isname) {
i = 0;
continue;
- } else if (c=='\n' || c==EOF) {
+ } else if (c == '\n' || c == EOF) {
line[i] = 0;
break;
} else {
- line[i]=c;
+ line[i] = c;
}
isname = 1;
i++;
}
- line[i+1] = 0;
+ line[i + 1] = 0;
return i;
}
va_start(args, format);
len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args);
va_end(args);
- if (len>sizeof(buf[bufidx])) {
+ if (len > sizeof(buf[bufidx])) {
fprintf(stderr, "[html.c] string truncated: %s\n", format);
exit(1);
}
const char *t = txt;
while(t && *t){
int c = *t;
- if (c=='<' || c=='>' || c=='&') {
+ if (c == '<' || c == '>' || c == '&') {
html_raw(txt, t - txt);
- if (c=='>')
+ if (c == '>')
html(">");
- else if (c=='<')
+ else if (c == '<')
html("<");
- else if (c=='&')
+ else if (c == '&')
html("&");
- txt = t+1;
+ txt = t + 1;
}
t++;
}
- if (t!=txt)
+ if (t != txt)
html(txt);
}
const char *t = txt;
while(t && *t && len--){
int c = *t;
- if (c=='<' || c=='>' || c=='&') {
+ if (c == '<' || c == '>' || c == '&') {
html_raw(txt, t - txt);
- if (c=='>')
+ if (c == '>')
html(">");
- else if (c=='<')
+ else if (c == '<')
html("<");
- else if (c=='&')
+ else if (c == '&')
html("&");
- txt = t+1;
+ txt = t + 1;
}
t++;
}
- if (t!=txt)
+ if (t != txt)
html_raw(txt, t - txt);
- if (len<0)
+ if (len < 0)
html("...");
}
const char *t = txt;
while(t && *t){
int c = *t;
- if (c=='<' || c=='>' || c=='\'' || c=='\"' || c=='&') {
+ if (c == '<' || c == '>' || c == '\'' || c == '\"' || c == '&') {
html_raw(txt, t - txt);
- if (c=='>')
+ if (c == '>')
html(">");
- else if (c=='<')
+ else if (c == '<')
html("<");
- else if (c=='\'')
+ else if (c == '\'')
html("'");
- else if (c=='"')
+ else if (c == '"')
html(""");
- else if (c=='&')
+ else if (c == '&')
html("&");
- txt = t+1;
+ txt = t + 1;
}
t++;
}
- if (t!=txt)
+ if (t != txt)
html(txt);
}
while(t && *t){
unsigned char c = *t;
const char *e = url_escape_table[c];
- if (e && c!='+' && c!='&') {
+ if (e && c != '+' && c != '&') {
html_raw(txt, t - txt);
html(e);
- txt = t+1;
+ txt = t + 1;
}
t++;
}
- if (t!=txt)
+ if (t != txt)
html(txt);
}
if (e) {
html_raw(txt, t - txt);
html(e);
- txt = t+1;
+ txt = t + 1;
}
t++;
}
- if (t!=txt)
+ if (t != txt)
html(txt);
}
*txt = '\0';
return txt-1;
}
- d1 = hextoint(*(txt+1));
- d2 = hextoint(*(txt+2));
- if (d1<0 || d2<0) {
- memmove(txt, txt+3, n-2);
+ d1 = hextoint(*(txt + 1));
+ d2 = hextoint(*(txt + 2));
+ if (d1 < 0 || d2 < 0) {
+ memmove(txt, txt + 3, n - 2);
return txt-1;
} else {
*txt = d1 * 16 + d2;
- memmove(txt+1, txt+3, n-2);
+ memmove(txt + 1, txt + 3, n - 2);
return txt;
}
}
exit(1);
}
while((c=*t) != '\0') {
- if (c=='=') {
+ if (c == '=') {
*t = '\0';
- value = t+1;
- } else if (c=='+') {
+ value = t + 1;
+ } else if (c == '+') {
*t = ' ';
- } else if (c=='%') {
+ } else if (c == '%') {
t = convert_query_hexchar(t);
- } else if (c=='&') {
+ } else if (c == '&') {
*t = '\0';
(*fn)(txt, value);
- txt = t+1;
+ txt = t + 1;
value = NULL;
}
t++;
}
- if (t!=txt)
+ if (t != txt)
(*fn)(txt, value);
free(o);
return 0;
config_fn = fn;
if (ctx.cfg.enable_git_config)
git_config_from_file(gitconfig_config, fmt("%s/config", path), NULL);
-
+
if (ctx.cfg.remove_suffix)
if ((p = strrchr(repo->url, '.')) && !strcmp(p, ".git"))
*p = '\0';
char line[MAX_PATH * 2], *z;
FILE *projects;
int err;
-
+
projects = fopen(projectsfile, "r");
if (!projects) {
fprintf(stderr, "Error opening projectsfile %s: %s (%d)\n",
int chk_non_negative(int result, char *msg)
{
- if (result < 0)
- die("%s: %s",msg, strerror(errno));
+ if (result < 0)
+ die("%s: %s", msg, strerror(errno));
return result;
}
int i;
struct cgit_repo *repo;
- for (i=0; i<cgit_repolist.count; i++) {
+ for (i = 0; i < cgit_repolist.count; i++) {
repo = &cgit_repolist.repos[i];
if (!strcmp(repo->url, url))
return repo;
file->ptr = (char *)"";
file->size = 0;
} else {
- file->ptr = read_sha1_file(sha1, &type,
+ file->ptr = read_sha1_file(sha1, &type,
(unsigned long *)&file->size);
}
return 1;
if(atoi(str))
return 1;
for(;;) {
- str += strspn(str,delim);
- tl = strcspn(str,delim);
+ str += strspn(str, delim);
+ tl = strcspn(str, delim);
if (!tl)
break;
for (f = cgit_snapshot_formats; f->suffix; f++) {
sl = strlen(f->suffix);
if((tl == sl && !strncmp(f->suffix, str, tl)) ||
- (tl == sl-1 && !strncmp(f->suffix+1, str, tl-1))) {
+ (tl == sl - 1 && !strncmp(f->suffix + 1, str, tl - 1))) {
rv |= f->bit;
break;
}
static unsigned char *matched_sha1;
static int found_path;
-static int walk_tree(const unsigned char *sha1, const char *base,int baselen,
+static int walk_tree(const unsigned char *sha1, const char *base, int baselen,
const char *pathname, unsigned mode, int stage, void *cbdata) {
- if(strncmp(base,match_path,baselen)
- || strcmp(match_path+baselen,pathname) )
+ if(strncmp(base, match_path, baselen)
+ || strcmp(match_path + baselen, pathname))
return READ_TREE_RECURSIVE;
- memmove(matched_sha1,sha1,20);
+ memmove(matched_sha1, sha1, 20);
found_path = 1;
return 0;
}
return;
}
} else {
- if (get_sha1(head,sha1)) {
+ if (get_sha1(head, sha1)) {
cgit_print_error(fmt("Bad ref: %s", head));
return;
}
format_note(NULL, sha1, ¬es, PAGE_ENCODING, 0);
load_ref_decorations(DECORATE_FULL_REFS);
-
+
cgit_print_diff_ctrls();
html("<table summary='commit info' class='commit-info'>\n");
html("<tr><th>author</th><td>");
cgit_tree_link(prefix, NULL, NULL, ctx.qry.head, tmp, prefix);
}
html("</td></tr>\n");
- for (p = commit->parents; p ; p = p->next) {
+ for (p = commit->parents; p; p = p->next) {
parent = lookup_commit_reference(p->item->object.sha1);
if (!parent) {
html("<tr><td colspan='3'>");
qsort(list.refs, maxcount, sizeof(*list.refs), cmp_ref_name);
}
- for(i=0; i<maxcount; i++)
+ for(i = 0; i < maxcount; i++)
print_branch(list.refs[i]);
if (maxcount < list.count)
else if (maxcount > list.count)
maxcount = list.count;
print_tag_header();
- for(i=0; i<maxcount; i++)
+ for(i = 0; i < maxcount; i++)
print_tag(list.refs[i]);
if (maxcount < list.count)
html("<div class='pager'>");
for(i = 0, ofs = 0; ofs < items; i++, ofs = i * pagelen) {
class = (ctx.qry.ofs == ofs) ? "current" : NULL;
- cgit_index_link(fmt("[%d]", i+1), fmt("Page %d", i+1), class,
- search, sort, ofs);
+ cgit_index_link(fmt("[%d]", i + 1), fmt("Page %d", i + 1),
+ class, search, sort, ofs);
}
html("</div>");
}
sort_repolist("section");
html("<table summary='repository list' class='list nowrap'>");
- for (i=0; i<cgit_repolist.count; i++) {
+ for (i = 0; i < cgit_repolist.count; i++) {
ctx.repo = &cgit_repolist.repos[i];
if (!(is_match(ctx.repo) && is_in_url(ctx.repo)))
continue;
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
struct tm *tm = gmtime(&t);
return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday],
- tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year,
+ tm->tm_mday, month[tm->tm_mon], 1900 + tm->tm_year,
tm->tm_hour, tm->tm_min, tm->tm_sec);
}
char *cgit_pageurl(const char *reponame, const char *pagename,
const char *query)
{
- return cgit_fileurl(reponame,pagename,0,query);
+ return cgit_fileurl(reponame, pagename, 0, query);
}
const char *cgit_repobasename(const char *reponame)
static char rvbuf[1024];
int p;
const char *rv;
- strncpy(rvbuf,reponame,sizeof(rvbuf));
+ strncpy(rvbuf, reponame, sizeof(rvbuf));
if(rvbuf[sizeof(rvbuf)-1])
die("cgit_repobasename: truncated repository name '%s'", reponame);
p = strlen(rvbuf)-1;
/* strip trailing slashes */
- while(p && rvbuf[p]=='/') rvbuf[p--]=0;
+ while(p && rvbuf[p] == '/') rvbuf[p--] = 0;
/* strip trailing .git */
- if(p>=3 && !strncmp(&rvbuf[p-3],".git",4)) {
+ if(p >= 3 && !strncmp(&rvbuf[p-3], ".git", 4)) {
p -= 3; rvbuf[p--] = 0;
}
/* strip more trailing slashes if any */
- while( p && rvbuf[p]=='/') rvbuf[p--]=0;
+ while( p && rvbuf[p] == '/') rvbuf[p--] = 0;
/* find last slash in the remaining string */
rv = strrchr(rvbuf,'/');
if(rv)
shortrev = xstrdup(fullrev);
shortrev[10] = '\0';
if (obj->type == OBJ_COMMIT) {
- cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL,
+ cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL,
ctx.qry.head, fullrev, NULL, 0);
return;
} else if (obj->type == OBJ_TREE)
if (prefixcmp(refname, "refs/archives"))
return 0;
- strncpy(buf, refname+14, sizeof(buf));
+ strncpy(buf, refname + 14, sizeof(buf));
obj = parse_object(sha1);
if (!obj)
return 1;
{
const struct cgit_snapshot_format* f;
char *prefix;
- char *filename;
+ char *filename;
unsigned char sha1[20];
if (get_sha1(fmt("refs/tags/%s", hex), sha1) == 0 &&
{
time_t t = timegm(tm);
t -= ((tm->tm_wday + 6) % 7) * DAY_SECS;
- gmtime_r(&t, tm);
+ gmtime_r(&t, tm);
}
static void dec_week(struct tm *tm)
{
time_t t = timegm(tm);
t -= WEEK_SECS;
- gmtime_r(&t, tm);
+ gmtime_r(&t, tm);
}
static void inc_week(struct tm *tm)
{
time_t t = timegm(tm);
t += WEEK_SECS;
- gmtime_r(&t, tm);
+ gmtime_r(&t, tm);
}
static char *pretty_week(struct tm *tm)
if (periods[i].code == code || !strcmp(periods[i].name, expr)) {
if (period)
*period = &periods[i];
- return i+1;
+ return i + 1;
}
return 0;
}
if (ctx.repo->snapshots)
print_download_links(revname);
html("</table>\n");
- }
+ }
return;
}
html("<tr><td class='linenumbers'><pre>");
idx = 0;
lineno = 0;
-
+
if (size) {
htmlf(numberfmt, ++lineno);
while(idx < size - 1) { // skip absolute last newline
if (state == 0) {
memcpy(buffer, base, baselen);
- strcpy(buffer+baselen, pathname);
+ strcpy(buffer + baselen, pathname);
if (strcmp(match_path, buffer))
return READ_TREE_RECURSIVE;