From 5aa2eb80475c4821eed89ae0b6a4585e3be3af60 Mon Sep 17 00:00:00 2001 From: lookshe Date: Mon, 8 Feb 2016 14:17:38 +0100 Subject: normalized indenting --- cgit.c | 2 +- ui-shared.c | 18 +++---- ui-tree.c | 158 ++++++++++++++++++++++++++++++------------------------------ 3 files changed, 89 insertions(+), 89 deletions(-) diff --git a/cgit.c b/cgit.c index 1c68cb0..4eaa7ab 100644 --- a/cgit.c +++ b/cgit.c @@ -345,7 +345,7 @@ static void querystring_cb(const char *name, const char *value) static void prepare_context(void) { memset(&ctx, 0, sizeof(ctx)); - ctx.qry.ignorews = 1; + ctx.qry.ignorews = 1; ctx.cfg.agefile = "info/web/last-modified"; ctx.cfg.nocache = 0; ctx.cfg.cache_size = 0; diff --git a/ui-shared.c b/ui-shared.c index 0c6d748..15bcb3f 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -1107,13 +1107,13 @@ void cgit_print_snapshot_links(const char *repo, const char *head, extern void cgit_author_link(const char *author, const char *head) { - char *delim; - - delim = repolink(NULL, NULL, "log", head ? head : ctx.qry.head, NULL); - html(delim); - htmlf("qt=author&q="); - html_url_arg(author); - html("'>"); - html_txt(author); - html(""); + char *delim; + + delim = repolink(NULL, NULL, "log", head ? head : ctx.qry.head, NULL); + html(delim); + htmlf("qt=author&q="); + html_url_arg(author); + html("'>"); + html_txt(author); + html(""); } diff --git a/ui-tree.c b/ui-tree.c index 6dc3dcb..eac1f2e 100644 --- a/ui-tree.c +++ b/ui-tree.c @@ -15,15 +15,15 @@ struct walk_tree_context { char *curr_rev; char *match_path; int state; - bool dir_mode; + bool dir_mode; }; struct flatten_walk_tree_context { - int counter; - int path_added; - unsigned char last_sha1[20]; - char* path; - char* last_path; + int counter; + int path_added; + unsigned char last_sha1[20]; + char* path; + char* last_path; }; static void print_text_buffer(const char *name, char *buf, unsigned long size) @@ -167,34 +167,34 @@ static void print_object(const unsigned char *sha1, char *path, const char *base static int flatten_tree_item(const unsigned char *sha1, struct strbuf *base, const char *pathname, unsigned mode, int stage, void *cbdata) { - struct flatten_walk_tree_context* fwt_ctx = cbdata; - // increment counter of child elements - fwt_ctx->counter++; - if (!S_ISDIR(mode) || fwt_ctx->counter > 1) { - if (fwt_ctx->counter > 1) { - // if the first child element was a directory we have to use the path before - free(fwt_ctx->path); - fwt_ctx->path = xstrdup(fwt_ctx->last_path); - } - // flag that we ended - fwt_ctx->counter = -1; - // -1 to break read_tree_recursive - return -1; - } - // save last path and concatenate new one - char* tmp = xstrdup(fwt_ctx->path); - free(fwt_ctx->path); - free(fwt_ctx->last_path); - fwt_ctx->last_path = xstrdup(tmp); - fwt_ctx->path = (char*) malloc(sizeof(char) * (2 + strlen(tmp) + strlen(pathname))); - strcpy(fwt_ctx->path, tmp); - strcat(fwt_ctx->path, "/"); - strcat(fwt_ctx->path, pathname); - free(tmp); - fwt_ctx->path_added++; - // save hash of found element - hashcpy(fwt_ctx->last_sha1, sha1); - return 0; + struct flatten_walk_tree_context* fwt_ctx = cbdata; + // increment counter of child elements + fwt_ctx->counter++; + if (!S_ISDIR(mode) || fwt_ctx->counter > 1) { + if (fwt_ctx->counter > 1) { + // if the first child element was a directory we have to use the path before + free(fwt_ctx->path); + fwt_ctx->path = xstrdup(fwt_ctx->last_path); + } + // flag that we ended + fwt_ctx->counter = -1; + // -1 to break read_tree_recursive + return -1; + } + // save last path and concatenate new one + char* tmp = xstrdup(fwt_ctx->path); + free(fwt_ctx->path); + free(fwt_ctx->last_path); + fwt_ctx->last_path = xstrdup(tmp); + fwt_ctx->path = (char*) malloc(sizeof(char) * (2 + strlen(tmp) + strlen(pathname))); + strcpy(fwt_ctx->path, tmp); + strcat(fwt_ctx->path, "/"); + strcat(fwt_ctx->path, pathname); + free(tmp); + fwt_ctx->path_added++; + // save hash of found element + hashcpy(fwt_ctx->last_sha1, sha1); + return 0; } static int ls_item(const unsigned char *sha1, struct strbuf *base, @@ -207,9 +207,9 @@ static int ls_item(const unsigned char *sha1, struct strbuf *base, enum object_type type; unsigned long size = 0; - if ((!S_ISDIR(mode) && walk_tree_ctx->dir_mode) || (S_ISDIR(mode) && !walk_tree_ctx->dir_mode)) { - return 0; - } + if ((!S_ISDIR(mode) && walk_tree_ctx->dir_mode) || (S_ISDIR(mode) && !walk_tree_ctx->dir_mode)) { + return 0; + } name = xstrdup(pathname); strbuf_addf(&fullpath, "%s%s%s", ctx.qry.path ? ctx.qry.path : "", @@ -232,36 +232,36 @@ static int ls_item(const unsigned char *sha1, struct strbuf *base, if (S_ISGITLINK(mode)) { cgit_submodule_link("ls-mod", fullpath.buf, sha1_to_hex(sha1)); } else if (S_ISDIR(mode)) { - struct flatten_walk_tree_context fwt_ctx; - // initialize paths - fwt_ctx.path = (char*) malloc(sizeof(char) * 1); - strcpy(fwt_ctx.path, ""); - fwt_ctx.last_path = (char*) malloc(sizeof(char) * 1); - strcpy(fwt_ctx.last_path, ""); - // start at actual position - hashcpy(fwt_ctx.last_sha1, sha1); - do { - fwt_ctx.counter = 0; - struct tree* tree; - struct pathspec path = { - .nr = 0 - }; - tree = parse_tree_indirect(fwt_ctx.last_sha1); - read_tree_recursive(tree, "", 0, 1, &path, flatten_tree_item, &fwt_ctx); - } while (fwt_ctx.counter != -1); - if (fwt_ctx.path_added) { - // append found path to fullpath and name - strbuf_addf(&fullpath, "%s", fwt_ctx.path); - char* tmp = xstrdup(name); - free(name); - name = (char*) malloc(sizeof(char) * (1 + strlen(tmp) + strlen(fwt_ctx.path))); - strcpy(name, tmp); - strcat(name, fwt_ctx.path); - free(tmp); - } - // cleanup - free(fwt_ctx.path); - free(fwt_ctx.last_path); + struct flatten_walk_tree_context fwt_ctx; + // initialize paths + fwt_ctx.path = (char*) malloc(sizeof(char) * 1); + strcpy(fwt_ctx.path, ""); + fwt_ctx.last_path = (char*) malloc(sizeof(char) * 1); + strcpy(fwt_ctx.last_path, ""); + // start at actual position + hashcpy(fwt_ctx.last_sha1, sha1); + do { + fwt_ctx.counter = 0; + struct tree* tree; + struct pathspec path = { + .nr = 0 + }; + tree = parse_tree_indirect(fwt_ctx.last_sha1); + read_tree_recursive(tree, "", 0, 1, &path, flatten_tree_item, &fwt_ctx); + } while (fwt_ctx.counter != -1); + if (fwt_ctx.path_added) { + // append found path to fullpath and name + strbuf_addf(&fullpath, "%s", fwt_ctx.path); + char* tmp = xstrdup(name); + free(name); + name = (char*) malloc(sizeof(char) * (1 + strlen(tmp) + strlen(fwt_ctx.path))); + strcpy(name, tmp); + strcat(name, fwt_ctx.path); + free(tmp); + } + // cleanup + free(fwt_ctx.path); + free(fwt_ctx.last_path); cgit_tree_link(name, NULL, "ls-dir", ctx.qry.head, walk_tree_ctx->curr_rev, fullpath.buf); } else { @@ -324,9 +324,9 @@ static void ls_tree(const unsigned char *sha1, char *path, struct walk_tree_cont } ls_head(); - walk_tree_ctx->dir_mode = true; + walk_tree_ctx->dir_mode = true; read_tree_recursive(tree, "", 0, 1, &paths, ls_item, walk_tree_ctx); - walk_tree_ctx->dir_mode = false; + walk_tree_ctx->dir_mode = false; read_tree_recursive(tree, "", 0, 1, &paths, ls_item, walk_tree_ctx); ls_tail(); } @@ -346,16 +346,16 @@ static int walk_tree(const unsigned char *sha1, struct strbuf *base, if (S_ISDIR(mode)) { walk_tree_ctx->state = 1; - if (walk_tree_ctx->dir_mode) { - set_title_from_path(buffer); - ls_head(); - } + if (walk_tree_ctx->dir_mode) { + set_title_from_path(buffer); + ls_head(); + } return READ_TREE_RECURSIVE; } else { walk_tree_ctx->state = 2; - if (walk_tree_ctx->dir_mode) { - print_object(sha1, buffer, pathname, walk_tree_ctx->curr_rev); - } + if (walk_tree_ctx->dir_mode) { + print_object(sha1, buffer, pathname, walk_tree_ctx->curr_rev); + } return 0; } } @@ -407,10 +407,10 @@ void cgit_print_tree(const char *rev, char *path) goto cleanup; } - walk_tree_ctx.dir_mode = true; + walk_tree_ctx.dir_mode = true; read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); - walk_tree_ctx.state = 0; - walk_tree_ctx.dir_mode = false; + walk_tree_ctx.state = 0; + walk_tree_ctx.dir_mode = false; read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); if (walk_tree_ctx.state == 1) ls_tail(); -- cgit v1.2.3