diff options
68 files changed, 762 insertions, 1317 deletions
@@ -73,8 +73,7 @@ cgit: $(CGIT_ROOT)/$(BUILDDIR)/cgit $(EXTRA_GIT_TARGETS) $(GIT_BUILD_FLAGS) sparse: - +@$(MAKE) -C $(GITDIR) -f $(CGIT_ROOT)/$(SRCDIR)/cgit.mk \ - $(GIT_BUILD_FLAGS) cgit-sparse + +@$(MAKE) -C $(GITDIR) -f $(CGIT_ROOT)/$(SRCDIR)/cgit.mk $(GIT_BUILD_FLAGS) cgit-sparse test: cgit-with-git +@$(MAKE) -C tests all @@ -86,14 +85,11 @@ cgit-with-git: install: all $(INSTALL) -m 0755 -d $(DESTDIR)$(CGIT_SCRIPT_PATH) - $(INSTALL) -m 0755 $(BUILDDIR)/cgit \ - $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) + $(INSTALL) -m 0755 $(BUILDDIR)/cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) $(INSTALL) -m 0755 -d $(DESTDIR)$(CGIT_DATA_PATH) - $(INSTALL) -m 0644 $(addprefix $(ASSETDIR)/,$(ASSETS)) \ - $(DESTDIR)$(CGIT_DATA_PATH) + $(INSTALL) -m 0644 $(addprefix $(ASSETDIR)/,$(ASSETS)) $(DESTDIR)$(CGIT_DATA_PATH) $(INSTALL) -m 0755 -d $(DESTDIR)$(filterdir) - $(INSTALL) -m 0644 $(addprefix $(EXTDIR)/,$(FILTER_FILES)) \ - $(DESTDIR)$(filterdir) + $(INSTALL) -m 0644 $(addprefix $(EXTDIR)/,$(FILTER_FILES)) $(DESTDIR)$(filterdir) uninstall: $(RM) $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) diff --git a/assets/cgit.js b/assets/cgit.js index 29b9745..78adfd0 100644 --- a/assets/cgit.js +++ b/assets/cgit.js @@ -24,13 +24,10 @@ var MONTH = YEAR / 12; // The search in render_age can stop one place past the last class, so // age_suffix and age_unit repeat their final entry. Each limit is twice the // next unit up, matching the thresholds cgit_print_age compares against. -var age_classes = [ "age-mins", "age-hours", "age-days", "age-weeks", - "age-months", "age-years" ]; -var age_suffix = [ "min.", "hours", "days", "weeks", "months", "years", - "years" ]; +var age_classes = [ "age-mins", "age-hours", "age-days", "age-weeks", "age-months", "age-years" ]; +var age_suffix = [ "min.", "hours", "days", "weeks", "months", "years", "years" ]; var age_unit = [ MINUTE, HOUR, DAY, WEEK, MONTH, YEAR, YEAR ]; -var age_limit = [ 2 * HOUR, 2 * DAY, 2 * WEEK, 2 * MONTH, 2 * YEAR, - 2 * YEAR ]; +var age_limit = [ 2 * HOUR, 2 * DAY, 2 * WEEK, 2 * MONTH, 2 * YEAR, 2 * YEAR ]; var update_delay = [ 10, 5 * MINUTE, 30 * MINUTE, DAY, DAY, DAY ]; function render_age(element, age) { diff --git a/custom/cgitrc b/custom/cgitrc index 8cb1831..6de214f 100644 --- a/custom/cgitrc +++ b/custom/cgitrc @@ -12,8 +12,7 @@ # # About pages (markdown, man and plain-text readmes) can render through the # bundled about-render.lua about-filter in the filter section below. Source -# syntax -# highlighting is optional and ships as a source-filter there too. +# syntax highlighting is optional and ships as a source-filter there too. # # One key=value pair per line. Lines starting with # are comments. @@ -277,8 +276,8 @@ enable-filter-overrides=0 # Filter command used to format plaintext blobs in the tree view. The shipped # filter uses the Scintillua lexers and needs lpeg, and missing either means -# plain uncolored text, not an error. -# Value is a command optionally prefixed with exec or lua. Default is none. +# plain uncolored text, not an error. Value is a command optionally prefixed +# with exec or lua. Default is none. #source-filter=lua:/usr/local/lib/cgit/filters/syntax-highlight.lua # Filter command invoked to authenticate access, gating repositories behind a diff --git a/custom/extensions/about-render.lua b/custom/extensions/about-render.lua index f4e7685..805265e 100644 --- a/custom/extensions/about-render.lua +++ b/custom/extensions/about-render.lua @@ -259,20 +259,17 @@ if has_lpeg then local lang_char = R("az", "AZ", "09") + S("_.+#-") local heading_line = C(P("#") * P("#") ^ -5) * space ^ 1 * C(P(1) ^ 0) local function thematic(mark) - return space ^ 0 * P(mark) * (space ^ 0 * P(mark)) ^ 2 - * space ^ 0 * eol + return space ^ 0 * P(mark) * (space ^ 0 * P(mark)) ^ 2 * space ^ 0 * eol end local break_line = thematic("-") + thematic("*") + thematic("_") - local fence_line = space ^ 0 * (C(P("`") ^ 3) + C(P("~") ^ 3)) - * space ^ 0 * C(lang_char ^ 0) + local fence_line = space ^ 0 * (C(P("`") ^ 3) + C(P("~") ^ 3)) * space ^ 0 * C(lang_char ^ 0) local close_backtick = space ^ 0 * P("`") ^ 3 * space ^ 0 * eol local close_tilde = space ^ 0 * P("~") ^ 3 * space ^ 0 * eol local quote_line = space ^ 0 * P(">") local bullet = S("-*+") local number = R("09") ^ 1 * S(".)") local item_line = space ^ 0 * C(bullet + number) * space ^ 1 * C(P(1) ^ 0) - local dash_cell = space ^ 0 * P(":") ^ -1 * P("-") ^ 1 * P(":") ^ -1 - * space ^ 0 + local dash_cell = space ^ 0 * P(":") ^ -1 * P("-") ^ 1 * P(":") ^ -1 * space ^ 0 -- A delimiter row is dash-cells joined by pipes. Require at least one -- pipe, a leading one or one between cells, so a bare rule of dashes -- stays a thematic break and an ordinary paragraph line is never taken @@ -299,8 +296,7 @@ if has_lpeg then if line:match("^%s*$") then i = i + 1 elseif fence then - local close = (fence:sub(1, 1) == "`") - and close_backtick or close_tilde + local close = (fence:sub(1, 1) == "`") and close_backtick or close_tilde local code = {} i = i + 1 while i <= n and not close:match(lines[i]) do @@ -345,16 +341,14 @@ if has_lpeg then lines = paragraph, } end - elseif i + 1 <= n and line:find("|", 1, true) - and table_delimiter:match(lines[i + 1]) then + elseif i + 1 <= n and line:find("|", 1, true) and table_delimiter:match(lines[i + 1]) then local head = {} for _, cell in ipairs(split_cells(line)) do head[#head + 1] = parse_inline(cell) end local rows = {} i = i + 2 - while i <= n and lines[i]:find("|", 1, true) - and not lines[i]:match("^%s*$") do + while i <= n and lines[i]:find("|", 1, true) and not lines[i]:match("^%s*$") do local row = {} for _, cell in ipairs(split_cells(lines[i])) do row[#row + 1] = parse_inline(cell) @@ -386,8 +380,7 @@ if has_lpeg then else local paragraph = { parse_inline(line) } i = i + 1 - while i <= n and not lines[i]:match("^%s*$") - and not block_start:match(lines[i]) do + while i <= n and not lines[i]:match("^%s*$") and not block_start:match(lines[i]) do paragraph[#paragraph + 1] = parse_inline(lines[i]) i = i + 1 end @@ -416,8 +409,7 @@ if has_lpeg then -- Roff fonts are a current state carried across a run rather than -- opened and closed, so the inline pass tokenises to a flat list -- and folds it into the nodes markdown emits, instead of nesting. - local macro_line = S(".'") * space ^ 0 * C((1 - space) ^ 1) - * space ^ 0 * C(P(1) ^ 0) + local macro_line = S(".'") * space ^ 0 * C((1 - space) ^ 1) * space ^ 0 * C(P(1) ^ 0) local one_font = { B = "B", I = "I" } local two_font = { CB = "B", BI = "B", CI = "I" } @@ -535,8 +527,7 @@ if has_lpeg then flush_paragraph(); nofill = true; nofill_lines = {} elseif macro == "fi" then flush_nofill() - elseif macro == "B" or macro == "BR" or macro == "RB" - or macro == "BI" or macro == "IB" then + elseif macro == "B" or macro == "BR" or macro == "RB" or macro == "BI" or macro == "IB" then add_line({ { kind = "strong", kids = man_inline(rest) } }) elseif macro == "I" or macro == "IR" or macro == "RI" then add_line({ { kind = "em", kids = man_inline(rest) } }) diff --git a/custom/extensions/auth-file.lua b/custom/extensions/auth-file.lua index cd0f338..230aa6d 100644 --- a/custom/extensions/auth-file.lua +++ b/custom/extensions/auth-file.lua @@ -242,21 +242,18 @@ function get_secret() -- created readable by anyone but the user cgit runs as, and -- the old mask goes back on every way out. local old_umask = sysstat.umask(63) - local temporary_filename = secret_filename .. ".tmp." .. - tohex(rand.bytes(16)) + local temporary_filename = secret_filename .. ".tmp." .. tohex(rand.bytes(16)) local temporary_file = io.open(temporary_filename, "w") if temporary_file == nil then sysstat.umask(old_umask) - error("cgit auth: cannot create secret file " .. - secret_filename) + error("cgit auth: cannot create secret file " .. secret_filename) end local wrote = temporary_file:write(tohex(rand.bytes(32))) local closed = temporary_file:close() if not wrote or not closed then os.remove(temporary_filename) sysstat.umask(old_umask) - error("cgit auth: failed writing secret file " .. - secret_filename) + error("cgit auth: failed writing secret file " .. secret_filename) end -- The link is meant to fail when another worker won the race, -- which leaves that worker's secret in place rather than @@ -273,8 +270,7 @@ function get_secret() secret_file:close() if secret == nil or secret:len() ~= 64 then secret = nil - error("cgit auth: secret file " .. secret_filename .. - " is malformed, expected 64 hex characters") + error("cgit auth: secret file " .. secret_filename .. " is malformed, expected 64 hex characters") end return secret end @@ -334,10 +330,8 @@ function validate_value(expected_field, cookie) return nil end - local payload = field .. "|" .. value .. "|" .. - tostring(expiration) .. "|" .. salt - local expected_signature = - tohex(hmac.new(get_secret(), "sha256"):final(payload)) + local payload = field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt + local expected_signature = tohex(hmac.new(get_secret(), "sha256"):final(payload)) if not constant_equals(signature, expected_signature) then return nil end @@ -370,8 +364,7 @@ function secure_value(field, value, expiration) local salt = tohex(rand.bytes(16)) value = url_encode(value) field = url_encode(field) - local payload = field .. "|" .. value .. "|" .. - tostring(expiration) .. "|" .. salt + local payload = field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt local signature = tohex(hmac.new(get_secret(), "sha256"):final(payload)) return payload .. "|" .. signature end @@ -406,11 +399,9 @@ function set_cookie(cookie, value) if value == "" then attributes = attributes .. "; Max-Age=0" elseif session_seconds > 0 then - attributes = attributes .. - "; Max-Age=" .. tostring(session_seconds) + attributes = attributes .. "; Max-Age=" .. tostring(session_seconds) end - html("Set-Cookie: " .. cookie .. "=" .. - strip_controls(value) .. attributes .. "\n") + html("Set-Cookie: " .. cookie .. "=" .. strip_controls(value) .. attributes .. "\n") end function redirect_to(url) @@ -454,8 +445,7 @@ function authenticate_post() end if ok then - set_cookie(cookie_name, secure_value("username", username, - os.time() + session_seconds)) + set_cookie(cookie_name, secure_value("username", username, os.time() + session_seconds)) else set_cookie(cookie_name, "") end @@ -473,8 +463,7 @@ function authenticate_cookie() return 1 end - local username = validate_value("username", - get_cookie(http["cookie"], cookie_name)) + local username = validate_value("username", get_cookie(http["cookie"], cookie_name)) if username == nil or not accepted_users[username:lower()] then return 0 end diff --git a/custom/extensions/auth-inline.lua b/custom/extensions/auth-inline.lua index e26fa57..0ae2cb8 100644 --- a/custom/extensions/auth-inline.lua +++ b/custom/extensions/auth-inline.lua @@ -203,21 +203,18 @@ function get_secret() -- created readable by anyone but the user cgit runs as, and -- the old mask goes back on every way out. local old_umask = sysstat.umask(63) - local temporary_filename = secret_filename .. ".tmp." .. - tohex(rand.bytes(16)) + local temporary_filename = secret_filename .. ".tmp." .. tohex(rand.bytes(16)) local temporary_file = io.open(temporary_filename, "w") if temporary_file == nil then sysstat.umask(old_umask) - error("cgit auth: cannot create secret file " .. - secret_filename) + error("cgit auth: cannot create secret file " .. secret_filename) end local wrote = temporary_file:write(tohex(rand.bytes(32))) local closed = temporary_file:close() if not wrote or not closed then os.remove(temporary_filename) sysstat.umask(old_umask) - error("cgit auth: failed writing secret file " .. - secret_filename) + error("cgit auth: failed writing secret file " .. secret_filename) end -- The link is meant to fail when another worker won the race, -- which leaves that worker's secret in place rather than @@ -234,8 +231,7 @@ function get_secret() secret_file:close() if secret == nil or secret:len() ~= 64 then secret = nil - error("cgit auth: secret file " .. secret_filename .. - " is malformed, expected 64 hex characters") + error("cgit auth: secret file " .. secret_filename .. " is malformed, expected 64 hex characters") end return secret end @@ -295,10 +291,8 @@ function validate_value(expected_field, cookie) return nil end - local payload = field .. "|" .. value .. "|" .. - tostring(expiration) .. "|" .. salt - local expected_signature = - tohex(hmac.new(get_secret(), "sha256"):final(payload)) + local payload = field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt + local expected_signature = tohex(hmac.new(get_secret(), "sha256"):final(payload)) if not constant_equals(signature, expected_signature) then return nil end @@ -331,8 +325,7 @@ function secure_value(field, value, expiration) local salt = tohex(rand.bytes(16)) value = url_encode(value) field = url_encode(field) - local payload = field .. "|" .. value .. "|" .. - tostring(expiration) .. "|" .. salt + local payload = field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt local signature = tohex(hmac.new(get_secret(), "sha256"):final(payload)) return payload .. "|" .. signature end @@ -367,11 +360,9 @@ function set_cookie(cookie, value) if value == "" then attributes = attributes .. "; Max-Age=0" elseif session_seconds > 0 then - attributes = attributes .. - "; Max-Age=" .. tostring(session_seconds) + attributes = attributes .. "; Max-Age=" .. tostring(session_seconds) end - html("Set-Cookie: " .. cookie .. "=" .. - strip_controls(value) .. attributes .. "\n") + html("Set-Cookie: " .. cookie .. "=" .. strip_controls(value) .. attributes .. "\n") end function redirect_to(url) @@ -415,8 +406,7 @@ function authenticate_post() end if ok then - set_cookie(cookie_name, secure_value("username", username, - os.time() + session_seconds)) + set_cookie(cookie_name, secure_value("username", username, os.time() + session_seconds)) else set_cookie(cookie_name, "") end @@ -434,8 +424,7 @@ function authenticate_cookie() return 1 end - local username = validate_value("username", - get_cookie(http["cookie"], cookie_name)) + local username = validate_value("username", get_cookie(http["cookie"], cookie_name)) if username == nil or not accepted_users[username:lower()] then return 0 end diff --git a/custom/extensions/link-commits.lua b/custom/extensions/link-commits.lua index 42252f3..8dc0bc3 100644 --- a/custom/extensions/link-commits.lua +++ b/custom/extensions/link-commits.lua @@ -81,8 +81,7 @@ local function collect(text) pcall(function() local init = 1 while init <= #text do - local start, stop, capture = - string.find(text, rule.pattern, init) + local start, stop, capture = string.find(text, rule.pattern, init) if not start then break end if capture == nil then capture = string.sub(text, start, stop) @@ -91,8 +90,7 @@ local function collect(text) start = start, stop = stop, priority = priority, - link = make_link(rule.url, capture, - string.sub(text, start, stop)), + link = make_link(rule.url, capture, string.sub(text, start, stop)), } -- An empty match still has to advance the -- scan, or it never reaches the end. @@ -104,11 +102,9 @@ local function collect(text) local priority = #rules + 1 local init = 1 while init <= #text do - local start, stop, run = - string.find(text, "%f[%w](%x+)%f[%W]", init) + local start, stop, run = string.find(text, "%f[%w](%x+)%f[%W]", init) if not start then break end - if #run >= objects.min_length - and #run <= objects.max_length then + if #run >= objects.min_length and #run <= objects.max_length then candidates[#candidates + 1] = { start = start, stop = stop, @@ -145,8 +141,7 @@ function filter_close() -- A candidate reaching back into one already emitted is -- dropped, so no run of text is ever wrapped twice. if candidate.start >= pos then - out[#out + 1] = - string.sub(text, pos, candidate.start - 1) + out[#out + 1] = string.sub(text, pos, candidate.start - 1) out[#out + 1] = candidate.link pos = candidate.stop + 1 end diff --git a/custom/extensions/syntax-highlight.lua b/custom/extensions/syntax-highlight.lua index e2032aa..2bff263 100644 --- a/custom/extensions/syntax-highlight.lua +++ b/custom/extensions/syntax-highlight.lua @@ -111,8 +111,7 @@ local function scintillua_path() if config then local dir = string.match(config, "^(.*)/[^/]+$") if dir then - candidates[#candidates + 1] = - dir .. "/scintillua/lexers" + candidates[#candidates + 1] = dir .. "/scintillua/lexers" end end for _, dir in ipairs(scintillua_dirs) do @@ -201,8 +200,7 @@ local function highlight(text) local part = escape(string.sub(text, pos, stop - 1)) local class = css[string.match(tag, "^[%w_]+")] if class and part ~= "" then - part = "<span class='" .. class .. "'>" - .. part .. "</span>" + part = "<span class='" .. class .. "'>" .. part .. "</span>" end out[#out + 1] = part pos = stop diff --git a/custom/hooks/post-receive.cgit-age b/custom/hooks/post-receive.cgit-age index b91f950..48b17fc 100755 --- a/custom/hooks/post-receive.cgit-age +++ b/custom/hooks/post-receive.cgit-age @@ -22,8 +22,7 @@ agefile="$(git rev-parse --git-dir)"/info/web/last-modified # history still counts as recent activity. Branch tips only, since an # annotated tag carries no committer date of its own and would sort in as an # empty line. -date="$(git for-each-ref --sort=-committerdate --count=1 \ - --format='%(committerdate:iso8601)' refs/heads/)" +date="$(git for-each-ref --sort=-committerdate --count=1 --format='%(committerdate:iso8601)' refs/heads/)" # A repository with no branches keeps whatever cgit already had, rather than # being handed an empty file. diff --git a/custom/hooks/post-receive.cgit-cache b/custom/hooks/post-receive.cgit-cache index 4825a44..21550a9 100755 --- a/custom/hooks/post-receive.cgit-cache +++ b/custom/hooks/post-receive.cgit-cache @@ -33,5 +33,4 @@ cache_root=/var/cache/cgit # Everything directly under the cache root is a cache file, so the only thing # worth keeping is the lock files, which belong to writers still working. # The "! -name . -prune" pair is how POSIX find stays out of subdirectories. -find "$cache_root"/. ! -name . -prune \ - ! -name '*.lock' -type f -exec rm -f {} + || exit 0 +find "$cache_root"/. ! -name . -prune ! -name '*.lock' -type f -exec rm -f {} + || exit 0 diff --git a/source/cache.c b/source/cache.c index 2d546bb..28558b1 100644 --- a/source/cache.c +++ b/source/cache.c @@ -88,9 +88,10 @@ static int open_slot(struct cache_slot *slot) keylen = nul - slot->buf; if (slot->key) - slot->key_matches = keylen >= 0 && - (size_t)keylen == slot->keylen && - !memcmp(slot->key, slot->buf, keylen + 1); + slot->key_matches = + keylen >= 0 && + (size_t)keylen == slot->keylen && + !memcmp(slot->key, slot->buf, keylen + 1); return 0; } @@ -168,10 +169,7 @@ static int serve_slot(struct cache_slot *slot) err = print_slot(slot); if (err) - log_error("[cgit] Error printing slot %s: %s (%d)\n", - slot->path, - strerror(err), - err); + log_error("[cgit] Error printing slot %s: %s (%d)\n", slot->path, strerror(err), err); return err; } @@ -192,9 +190,11 @@ static int is_modified(struct cache_slot *slot) if (stat(slot->path, ¤t)) return 1; - return (current.st_ino != slot->st.st_ino || - current.st_mtime != slot->st.st_mtime || - current.st_size != slot->st.st_size); + return ( + current.st_ino != slot->st.st_ino || + current.st_mtime != slot->st.st_mtime || + current.st_size != slot->st.st_size + ); } static int close_lock(struct cache_slot *slot) @@ -225,8 +225,7 @@ static int lock_slot(struct cache_slot *slot) }; struct stat held, named; - slot->lock_fd = open(slot->lock_path, O_RDWR | O_CREAT, - S_IRUSR | S_IWUSR); + slot->lock_fd = open(slot->lock_path, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); if (slot->lock_fd == -1) return errno; if (fcntl(slot->lock_fd, F_SETLK, &lock) < 0) { @@ -239,8 +238,12 @@ static int lock_slot(struct cache_slot *slot) // finishing in between renames that inode into place as the live // slot, and once the path is confirmed to still name this file that // rename can no longer happen, because it takes the lock held here. - if (fstat(slot->lock_fd, &held) || stat(slot->lock_path, &named) || - held.st_ino != named.st_ino || held.st_dev != named.st_dev) { + if ( + fstat(slot->lock_fd, &held) || + stat(slot->lock_path, &named) || + held.st_ino != named.st_ino || + held.st_dev != named.st_dev + ) { close(slot->lock_fd); slot->lock_fd = -1; return EAGAIN; @@ -386,23 +389,20 @@ static int process_slot(struct cache_slot *slot) // and two popular pages sharing one slot evict each other on every // alternating visit. if (!err) - log_error("[cgit] Cache slot %s holds a different key, " - "consider a larger cache-size\n", slot->path); + log_error("[cgit] Cache slot %s holds a different key, consider a larger cache-size\n", slot->path); // If any part of creating a slot fails the page is still rendered // straight to the client and the caller is told the request succeeded, // because it did. close_slot(slot); if ((err = lock_slot(slot)) != 0) { - log_error("[cgit] Error locking slot %s: %s (%d)\n", - slot->lock_path, strerror(err), err); + log_error("[cgit] Error locking slot %s: %s (%d)\n", slot->lock_path, strerror(err), err); slot->fn(); return 0; } if ((err = fill_slot(slot)) != 0) { - log_error("[cgit] Error filling slot %s: %s (%d)\n", - slot->lock_path, strerror(err), err); + log_error("[cgit] Error filling slot %s: %s (%d)\n", slot->lock_path, strerror(err), err); unlock_slot(slot, 0); close_lock(slot); // Rendering again is only right when nothing was delivered, @@ -459,8 +459,7 @@ unsigned long cache_hash_str(const char *str) return h; } -int cache_process(int size, const char *path, const char *key, int ttl, - cache_fill_fn fn) +int cache_process(int size, const char *path, const char *key, int ttl, cache_fill_fn fn) { unsigned long hash; int i; @@ -482,8 +481,7 @@ int cache_process(int size, const char *path, const char *key, int ttl, if (!key) key = ""; if (!key_fits_slot(key)) { - log_error("[cgit] Cache key too long for a slot, caching is " - "disabled for this request\n"); + log_error("[cgit] Cache key too long for a slot, caching is disabled for this request\n"); fn(); return 0; } @@ -531,8 +529,7 @@ int cache_ls(const char *path) dir = opendir(path); if (!dir) { err = errno; - log_error("[cgit] Error opening %s: %s (%d)\n", - path, strerror(err), err); + log_error("[cgit] Error opening %s: %s (%d)\n", path, strerror(err), err); return err; } strbuf_addstr(&slot_path, path); @@ -545,20 +542,18 @@ int cache_ls(const char *path) strbuf_addstr(&slot_path, ent->d_name); slot.path = slot_path.buf; if ((err = open_slot(&slot)) != 0) { - log_error("[cgit] Error opening %s: %s (%d)\n", - slot_path.buf, strerror(err), err); + log_error("[cgit] Error opening %s: %s (%d)\n", slot_path.buf, strerror(err), err); continue; } // A truncated or corrupt slot may hold no NUL, so the print is // bounded by what was read and cannot run off the end. nul = memchr(slot.buf, 0, slot.buflen); keylen = nul ? (int)(nul - slot.buf) : slot.buflen; - htmlf("%s %s %10"PRIuMAX" %.*s\n", - slot_path.buf, - format_time("%Y-%m-%d %H:%M:%S", - slot.st.st_mtime), - (uintmax_t)slot.st.st_size, - keylen, slot.buf); + htmlf( + "%s %s %10"PRIuMAX" %.*s\n", slot_path.buf, + format_time("%Y-%m-%d %H:%M:%S", slot.st.st_mtime), + (uintmax_t)slot.st.st_size, keylen, slot.buf + ); close_slot(&slot); } closedir(dir); diff --git a/source/cache.h b/source/cache.h index db77999..a653108 100644 --- a/source/cache.h +++ b/source/cache.h @@ -17,8 +17,7 @@ typedef void (*cache_fill_fn)(void); * ttl never expires and a ttl of zero skips the cache for this request. * Returns 0 when the page was written, and an errno value when it was not. */ -extern int cache_process(int size, const char *path, const char *key, int ttl, - cache_fill_fn fn); +extern int cache_process(int size, const char *path, const char *key, int ttl, cache_fill_fn fn); // Write one line per cache slot to stdout, giving its path, modification // time, size and key. diff --git a/source/cgit.c b/source/cgit.c index dc56a0e..e6e8613 100644 --- a/source/cgit.c +++ b/source/cgit.c @@ -153,8 +153,7 @@ static void prepare_context(void) ctx.env.server_port = getenv("SERVER_PORT"); ctx.env.http_cookie = getenv("HTTP_COOKIE"); ctx.env.http_referer = getenv("HTTP_REFERER"); - ctx.env.content_length = getenv("CONTENT_LENGTH") ? - strtoul(getenv("CONTENT_LENGTH"), NULL, 10) : 0; + ctx.env.content_length = getenv("CONTENT_LENGTH") ? strtoul(getenv("CONTENT_LENGTH"), NULL, 10) : 0; ctx.env.authenticated = 0; ctx.page.mimetype = "text/html"; ctx.page.charset = PAGE_ENCODING; @@ -171,8 +170,7 @@ static void prepare_context(void) static void print_version(void) { - printf("CGit %s | https://github.com/brycekwon/cgit\n\n" - "Compiled in features:\n", CGIT_VERSION); + printf("CGit %s | https://github.com/brycekwon/cgit\n\nCompiled in features:\n", CGIT_VERSION); #ifdef NO_LUA printf("[-] "); #else @@ -257,8 +255,7 @@ static void print_repo(FILE *f, struct cgit_repo *repo) if (repo->snapshot_prefix) fprintf(f, "repo.snapshot-prefix=%s\n", repo->snapshot_prefix); if (repo->max_stats != ctx.cfg.max_stats) - fprintf(f, "repo.max-stats=%s\n", - cgit_find_stats_periodname(repo->max_stats)); + fprintf(f, "repo.max-stats=%s\n", cgit_find_stats_periodname(repo->max_stats)); if (repo->logo) fprintf(f, "repo.logo=%s\n", repo->logo); if (repo->logo_link) @@ -316,8 +313,7 @@ static void parse_args(int argc, const char **argv) ctx.qry.has_oid = 1; } else if (skip_prefix(argv[i], "--ofs=", &arg)) { ctx.qry.ofs = atoi(arg); - } else if (skip_prefix(argv[i], "--scan-tree=", &arg) || - skip_prefix(argv[i], "--scan-path=", &arg)) { + } else if (skip_prefix(argv[i], "--scan-tree=", &arg) || skip_prefix(argv[i], "--scan-path=", &arg)) { // A repository's snapshots setting is masked with the // global one, and cgitrc has not been read here, so an // empty mask would discard what the repository set. @@ -327,8 +323,7 @@ static void parse_args(int argc, const char **argv) } } if (scanned) { - qsort(cgit_repolist.repos, cgit_repolist.count, - sizeof(struct cgit_repo), cmp_repos); + qsort(cgit_repolist.repos, cgit_repolist.count, sizeof(struct cgit_repo), cmp_repos); print_repolist(stdout, &cgit_repolist, 0); exit(0); } @@ -358,8 +353,7 @@ static int generate_cached_repolist(const char *path, const char *cached_rc) fd = open(locked_rc.buf, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); if (fd == -1) { err = errno; - fprintf(stderr, "[cgit] Error opening %s: %s (%d)\n", - locked_rc.buf, strerror(err), err); + fprintf(stderr, "[cgit] Error opening %s: %s (%d)\n", locked_rc.buf, strerror(err), err); goto out; } if (fcntl(fd, F_SETLK, &lock) < 0) { @@ -369,8 +363,7 @@ static int generate_cached_repolist(const char *path, const char *cached_rc) // on every request and does deserve one. err = errno; if (err != EACCES && err != EAGAIN) - fprintf(stderr, "[cgit] Error locking %s: %s (%d)\n", - locked_rc.buf, strerror(err), err); + fprintf(stderr, "[cgit] Error locking %s: %s (%d)\n", locked_rc.buf, strerror(err), err); close(fd); goto out; } @@ -378,8 +371,12 @@ static int generate_cached_repolist(const char *path, const char *cached_rc) // finishing in between renames that inode into place as the live // list, and once the path is confirmed to still name this file that // rename can no longer happen, because it takes the lock held here. - if (fstat(fd, &held) || stat(locked_rc.buf, &named) || - held.st_ino != named.st_ino || held.st_dev != named.st_dev) { + if ( + fstat(fd, &held) || + stat(locked_rc.buf, &named) || + held.st_ino != named.st_ino || + held.st_dev != named.st_dev + ) { err = EAGAIN; close(fd); goto out; @@ -388,8 +385,7 @@ static int generate_cached_repolist(const char *path, const char *cached_rc) // start from empty now that nobody else can be writing it. if (ftruncate(fd, 0) < 0 || !(f = fdopen(fd, "w"))) { err = errno; - fprintf(stderr, "[cgit] Error writing %s: %s (%d)\n", - locked_rc.buf, strerror(err), err); + fprintf(stderr, "[cgit] Error writing %s: %s (%d)\n", locked_rc.buf, strerror(err), err); unlink(locked_rc.buf); close(fd); goto out; @@ -405,8 +401,7 @@ static int generate_cached_repolist(const char *path, const char *cached_rc) // that stops wherever the buffer happened to end. if (fflush(f) || ferror(f)) { err = errno; - fprintf(stderr, "[cgit] Error writing %s: %s (%d)\n", - locked_rc.buf, strerror(err), err); + fprintf(stderr, "[cgit] Error writing %s: %s (%d)\n", locked_rc.buf, strerror(err), err); unlink(locked_rc.buf); fclose(f); goto out; @@ -635,8 +630,7 @@ static void apply_config(const char *name, const char *value) if (ctx.cfg.cache_size) process_cached_repolist(cgit_expand_macros(value)); else if (ctx.cfg.project_list) - scan_projects(cgit_expand_macros(value), - ctx.cfg.project_list); + scan_projects(cgit_expand_macros(value), ctx.cfg.project_list); else scan_tree(cgit_expand_macros(value)); } else if (!strcmp(name, "scan-hidden-path")) @@ -763,8 +757,7 @@ static void apply_query_param(const char *name, const char *value) ctx.qry.has_difftype = 1; } else if (!strcmp(name, "ss")) { // No longer generated, but old links still carry it. - ctx.qry.difftype = query_int(value, INT_MIN, INT_MAX) ? - DIFF_SSDIFF : DIFF_UNIFIED; + ctx.qry.difftype = query_int(value, INT_MIN, INT_MAX) ? DIFF_SSDIFF : DIFF_UNIFIED; ctx.qry.has_difftype = 1; } else if (!strcmp(name, "all")) { ctx.qry.show_all = query_int(value, INT_MIN, INT_MAX); @@ -825,9 +818,13 @@ static void authenticate_cookie(void) return; } - if (ctx.env.request_method && ctx.qry.page && !ctx.repo && - !strcmp(ctx.env.request_method, "POST") && - !strcmp(ctx.qry.page, "login")) { + if ( + ctx.env.request_method && + ctx.qry.page && + !ctx.repo && + !strcmp(ctx.env.request_method, "POST") && + !strcmp(ctx.qry.page, "login") + ) { authenticate_post(); return; } @@ -869,9 +866,11 @@ static int calc_ttl(void) // Checked ahead of the snapshot ttl, because a tarball pinned to an // object id can never come out differently and is the most expensive // page to rebuild. - if (ctx.qry.has_oid && - (!ctx.qry.oid || is_full_oid(ctx.qry.oid)) && - (!ctx.qry.oid2 || is_full_oid(ctx.qry.oid2))) + if ( + ctx.qry.has_oid && + (!ctx.qry.oid || is_full_oid(ctx.qry.oid)) && + (!ctx.qry.oid2 || is_full_oid(ctx.qry.oid2)) + ) return ctx.cfg.cache_static_ttl; if (!strcmp(ctx.qry.page, "snapshot")) @@ -927,8 +926,7 @@ static char *find_default_branch(struct cgit_repo *repo) match.wanted = repo->defbranch; match.first = NULL; match.found = 0; - refs_for_each_branch_ref(get_main_ref_store(the_repository), - find_current_ref, &match); + refs_for_each_branch_ref(get_main_ref_store(the_repository), find_current_ref, &match); if (match.found) ref = match.wanted; else @@ -945,8 +943,7 @@ static char *guess_defbranch(void) const char *ref, *refname; struct object_id oid; - ref = refs_resolve_ref_unsafe(get_main_ref_store(the_repository), - "HEAD", 0, &oid, NULL); + ref = refs_resolve_ref_unsafe(get_main_ref_store(the_repository), "HEAD", 0, &oid, NULL); if (!ref || !skip_prefix(ref, "refs/heads/", &refname)) return "master"; return xstrdup(refname); @@ -956,8 +953,7 @@ static char *guess_defbranch(void) * Split one readme setting into the file it names and the ref that file is * read from, leaving the ref NULL for a file on disk. The caller frees both. */ -static void parse_readme(const char *readme, char **filename, char **ref, - struct cgit_repo *repo) +static void parse_readme(const char *readme, char **filename, char **ref, struct cgit_repo *repo) { const char *colon; @@ -1007,8 +1003,7 @@ static void choose_readme(struct cgit_repo *repo) found = 1; break; } - } - else if (!access(filename, R_OK)) { + } else if (!access(filename, R_OK)) { found = 1; break; } @@ -1042,14 +1037,12 @@ static int prepare_repo_cmd(int nongit) if (nongit) { const char *name = ctx.repo->name; err = errno; - ctx.page.title = cgit_fmtalloc("%s - %s", ctx.cfg.root_title, - "config error"); + ctx.page.title = cgit_fmtalloc("%s - %s", ctx.cfg.root_title, "config error"); ctx.repo = NULL; cgit_print_http_headers(); cgit_print_docstart(); cgit_print_pageheader(); - cgit_print_error("Failed to open %s: %s", name, - err ? strerror(err) : "Not a valid git repository"); + cgit_print_error("Failed to open %s: %s", name, err ? strerror(err) : "Not a valid git repository"); cgit_print_docend(); return 1; } @@ -1080,8 +1073,7 @@ static int prepare_repo_cmd(int nongit) if (repo_get_oid(the_repository, ctx.qry.head, &oid)) { char *old_head = ctx.qry.head; ctx.qry.head = xstrdup(ctx.repo->defbranch); - cgit_print_error_page(404, "Not Found", - "Invalid branch: %s", old_head); + cgit_print_error_page(404, "Not Found", "Invalid branch: %s", old_head); free(old_head); return 1; } @@ -1126,8 +1118,7 @@ static void process_request(void) } if (cmd->want_repo && !ctx.repo) { - cgit_print_error_page(400, "Bad Request", - "No repository selected"); + cgit_print_error_page(400, "Bad Request", "No repository selected"); return; } @@ -1191,8 +1182,7 @@ void cgit_repo_config(struct cgit_repo *repo, const char *name, const char *valu else if (!strcmp(name, "module-link")) repo->module_link = cgit_strdup_first_line(value); else if (skip_prefix(name, "module-link.", &path)) { - item = string_list_append(&repo->submodules, - cgit_strdup_first_line(path)); + item = string_list_append(&repo->submodules, cgit_strdup_first_line(path)); item->util = cgit_strdup_first_line(value); } else if (!strcmp(name, "section")) repo->section = cgit_strdup_first_line(value); @@ -1210,11 +1200,14 @@ void cgit_repo_config(struct cgit_repo *repo, const char *name, const char *valu repo->hide = atoi(value); else if (!strcmp(name, "ignore")) repo->ignore = atoi(value); - else if (!strcmp(name, "about-filter") || !strcmp(name, "commit-filter") || - !strcmp(name, "source-filter") || !strcmp(name, "email-filter")) { + else if ( + !strcmp(name, "about-filter") || + !strcmp(name, "commit-filter") || + !strcmp(name, "source-filter") || + !strcmp(name, "email-filter") + ) { if (!ctx.cfg.enable_filter_overrides) - fprintf(stderr, "[cgit] Ignoring repo %s: " - "enable-filter-overrides is not set\n", name); + fprintf(stderr, "[cgit] Ignoring repo %s: enable-filter-overrides is not set\n", name); else if (!strcmp(name, "about-filter")) repo->about_filter = cgit_new_filter(value, ABOUT); else if (!strcmp(name, "commit-filter")) @@ -1282,13 +1275,11 @@ int cmd_main(int argc, const char **argv) ctx.cfg.cache_size = 0; build_cache_key(&cache_key); - err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root, - cache_key.buf, ttl, process_request); + err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root, cache_key.buf, ttl, process_request); strbuf_release(&cache_key); cgit_cleanup_filters(); if (err) - cgit_print_error("Error processing page: %s (%d)", - strerror(err), err); + cgit_print_error("Error processing page: %s (%d)", strerror(err), err); return err; } diff --git a/source/cgit.h b/source/cgit.h index 308fda2..cc4ac02 100644 --- a/source/cgit.h +++ b/source/cgit.h @@ -312,7 +312,6 @@ extern const char *cgit_version; extern struct cgit_repolist cgit_repolist; extern struct cgit_context ctx; -extern void cgit_repo_config(struct cgit_repo *repo, const char *name, - const char *value); +extern void cgit_repo_config(struct cgit_repo *repo, const char *name, const char *value); #endif // CGIT_H diff --git a/source/cgit.mk b/source/cgit.mk index 1106b64..1199278 100644 --- a/source/cgit.mk +++ b/source/cgit.mk @@ -137,8 +137,7 @@ CGIT_OBJS := $(addprefix $(CGIT_BUILD)/,$(CGIT_OBJ_NAMES)) # version changes. CGIT_VERSION_OBJS := $(addprefix $(CGIT_BUILD)/,cgit.o cgit.sp) $(CGIT_VERSION_OBJS): $(CGIT_BUILD)/VERSION -$(CGIT_VERSION_OBJS): EXTRA_CPPFLAGS = \ - -DCGIT_VERSION='"$(CGIT_VERSION)"' +$(CGIT_VERSION_OBJS): EXTRA_CPPFLAGS = -DCGIT_VERSION='"$(CGIT_VERSION)"' # Git builds its list of dependency files with := before this file adds the # cgit objects, so those are missing from it and have to be picked up here. @@ -163,10 +162,8 @@ $(CGIT_BUILD)/CGIT-CFLAGS: FORCE echo "$$FLAGS" >$(CGIT_BUILD)/CGIT-CFLAGS; \ fi -$(CGIT_OBJS): $(CGIT_BUILD)/%.o: $(CGIT_SRC)/%.c GIT-CFLAGS \ - $(CGIT_BUILD)/CGIT-CFLAGS $(missing_dep_dirs) - $(QUIET_CC)$(CC) -o $@ -c $(dep_args) $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) \ - $(CGIT_CFLAGS) $< +$(CGIT_OBJS): $(CGIT_BUILD)/%.o: $(CGIT_SRC)/%.c GIT-CFLAGS $(CGIT_BUILD)/CGIT-CFLAGS $(missing_dep_dirs) + $(QUIET_CC)$(CC) -o $@ -c $(dep_args) $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) $(CGIT_CFLAGS) $< $(CGIT_BUILD)/cgit: $(CGIT_OBJS) GIT-LDFLAGS $(GITLIBS) @echo 1>&2 " * $(LUA_MESSAGE)" diff --git a/source/cmd.c b/source/cmd.c index b6b1c67..2c6406f 100644 --- a/source/cmd.c +++ b/source/cmd.c @@ -46,9 +46,8 @@ static void about_fn(void) // only works with a trailing slash. path_info_len = ctx.env.path_info ? strlen(ctx.env.path_info) : 0; if (!ctx.qry.path && - (!ctx.qry.url || !*ctx.qry.url || - ctx.qry.url[strlen(ctx.qry.url) - 1] != '/') && - (!path_info_len || ctx.env.path_info[path_info_len - 1] != '/')) { + (!ctx.qry.url || !*ctx.qry.url || ctx.qry.url[strlen(ctx.qry.url) - 1] != '/') && + (!path_info_len || ctx.env.path_info[path_info_len - 1] != '/')) { currenturl = cgit_currenturl(); redirect = cgit_fmtalloc("%s/", currenturl); cgit_redirect(redirect, true); @@ -100,10 +99,11 @@ static void info_fn(void) static void log_fn(void) { - cgit_print_log(ctx.qry.oid, ctx.qry.ofs, ctx.cfg.max_commit_count, - ctx.qry.grep, ctx.qry.search, ctx.qry.path, 1, - ctx.repo->enable_commit_graph, - ctx.repo->commit_sort); + cgit_print_log( + ctx.qry.oid, ctx.qry.ofs, ctx.cfg.max_commit_count, ctx.qry.grep, + ctx.qry.search, ctx.qry.path, 1, ctx.repo->enable_commit_graph, + ctx.repo->commit_sort + ); } static void ls_cache_fn(void) @@ -156,8 +156,7 @@ static void repolist_fn(void) static void snapshot_fn(void) { - cgit_print_snapshot(ctx.qry.head, ctx.qry.oid, ctx.qry.path, - ctx.qry.nohead); + cgit_print_snapshot(ctx.qry.head, ctx.qry.oid, ctx.qry.path, ctx.qry.nohead); } static void stats_fn(void) diff --git a/source/cmd.h b/source/cmd.h index 7299028..a75cdd0 100644 --- a/source/cmd.h +++ b/source/cmd.h @@ -13,9 +13,7 @@ typedef void (*cgit_cmd_fn)(void); struct cgit_cmd { const char *name; cgit_cmd_fn fn; - unsigned int want_repo:1, - want_vpath:1, - is_clone:1; + unsigned int want_repo:1, want_vpath:1, is_clone:1; }; // The entry naming ctx.qry.page, or NULL when no page goes by that name. diff --git a/source/filter.c b/source/filter.c index a7efe56..2731d58 100644 --- a/source/filter.c +++ b/source/filter.c @@ -27,22 +27,17 @@ static int open_exec_filter(struct cgit_filter *base, va_list ap) for (i = 0; i < filter->base.argument_count; i++) filter->argv[i + 1] = va_arg(ap, char *); - filter->old_stdout = cgit_die_unless_positive(dup(STDOUT_FILENO), - "Unable to duplicate STDOUT"); - cgit_die_unless_zero(pipe(pipefd), - "Unable to create pipe to subprocess"); - filter->pid = cgit_die_unless_non_negative(fork(), - "Unable to create subprocess"); + filter->old_stdout = cgit_die_unless_positive(dup(STDOUT_FILENO), "Unable to duplicate STDOUT"); + cgit_die_unless_zero(pipe(pipefd), "Unable to create pipe to subprocess"); + filter->pid = cgit_die_unless_non_negative(fork(), "Unable to create subprocess"); if (filter->pid == 0) { close(pipefd[1]); - cgit_die_unless_non_negative(dup2(pipefd[0], STDIN_FILENO), - "Unable to use pipe as STDIN"); + cgit_die_unless_non_negative(dup2(pipefd[0], STDIN_FILENO), "Unable to use pipe as STDIN"); execvp(filter->cmd, filter->argv); die_errno("Unable to exec subprocess %s", filter->cmd); } close(pipefd[0]); - cgit_die_unless_non_negative(dup2(pipefd[1], STDOUT_FILENO), - "Unable to use pipe as STDOUT"); + cgit_die_unless_non_negative(dup2(pipefd[1], STDOUT_FILENO), "Unable to use pipe as STDOUT"); close(pipefd[1]); return 0; } @@ -52,8 +47,7 @@ static int close_exec_filter(struct cgit_filter *base) struct cgit_exec_filter *filter = (struct cgit_exec_filter *)base; int i, exit_status = 0; - cgit_die_unless_non_negative(dup2(filter->old_stdout, STDOUT_FILENO), - "Unable to restore STDOUT"); + cgit_die_unless_non_negative(dup2(filter->old_stdout, STDOUT_FILENO), "Unable to restore STDOUT"); close(filter->old_stdout); if (filter->pid < 0) goto done; @@ -68,8 +62,7 @@ done: return WEXITSTATUS(exit_status); } -static void fprintf_exec_filter(struct cgit_filter *base, FILE *f, - const char *prefix) +static void fprintf_exec_filter(struct cgit_filter *base, FILE *f, const char *prefix) { struct cgit_exec_filter *filter = (struct cgit_exec_filter *)base; fprintf(f, "%sexec:%s\n", prefix, filter->cmd); @@ -101,8 +94,7 @@ static struct cgit_filter *new_exec_filter(const char *cmd, int argument_count) return &filter->base; } -void cgit_exec_filter_init(struct cgit_exec_filter *filter, char *cmd, - char **argv) +void cgit_exec_filter_init(struct cgit_exec_filter *filter, char *cmd, char **argv) { memset(filter, 0, sizeof(*filter)); filter->base.open = open_exec_filter; @@ -127,8 +119,7 @@ struct lua_filter { lua_State *lua_state; }; -typedef ssize_t (*filter_write_fn)(struct cgit_filter *base, const void *buf, - size_t count); +typedef ssize_t (*filter_write_fn)(struct cgit_filter *base, const void *buf, size_t count); static ssize_t (*libc_write)(int fd, const void *buf, size_t count); static filter_write_fn filter_write = NULL; @@ -152,8 +143,7 @@ ssize_t write(int fd, const void *buf, size_t count) return filter_write(current_write_filter, buf, count); } -static inline void hook_write(struct cgit_filter *filter, - filter_write_fn write_fn) +static inline void hook_write(struct cgit_filter *filter, filter_write_fn write_fn) { // Filters cannot nest, because there is one stdout and one hook, so a // second one would strand the first. @@ -178,12 +168,10 @@ static NORETURN void die_lua_error(struct lua_filter *filter) // page would be fed back into the broken filter. if (filter_write) unhook_write(); - die("Lua error in %s: %s", filter->script_file, - lua_tostring(filter->lua_state, -1)); + die("Lua error in %s: %s", filter->script_file, lua_tostring(filter->lua_state, -1)); } -static ssize_t write_lua_filter(struct cgit_filter *base, const void *buf, - size_t count) +static ssize_t write_lua_filter(struct cgit_filter *base, const void *buf, size_t count) { struct lua_filter *filter = (struct lua_filter *)base; @@ -199,8 +187,7 @@ static ssize_t write_lua_filter(struct cgit_filter *base, const void *buf, * so the hook comes off around the call. The zero returned is Lua's count * of values pushed, not a success code. */ -static inline int emit_unfiltered(lua_State *lua_state, - void (*emit)(const char *text)) +static inline int emit_unfiltered(lua_State *lua_state, void (*emit)(const char *text)) { const char *text; filter_write_fn saved_write; @@ -330,8 +317,7 @@ static int close_lua_filter(struct cgit_filter *base) return ret; } -static void fprintf_lua_filter(struct cgit_filter *base, FILE *f, - const char *prefix) +static void fprintf_lua_filter(struct cgit_filter *base, FILE *f, const char *prefix) { struct lua_filter *filter = (struct lua_filter *)base; fprintf(f, "%slua:%s\n", prefix, filter->script_file); @@ -391,8 +377,7 @@ int cgit_close_filter(struct cgit_filter *filter) return filter->close(filter); } -void cgit_fprintf_filter(struct cgit_filter *filter, FILE *f, - const char *prefix) +void cgit_fprintf_filter(struct cgit_filter *filter, FILE *f, const char *prefix) { filter->fprintfp(filter, f, prefix); } @@ -469,8 +454,7 @@ struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype) return new_exec_filter(cmd, argument_count); for (i = 0; i < ARRAY_SIZE(filter_specs); i++) { - if (len == strlen(filter_specs[i].prefix) && - !strncmp(filter_specs[i].prefix, cmd, len)) + if (len == strlen(filter_specs[i].prefix) && !strncmp(filter_specs[i].prefix, cmd, len)) return filter_specs[i].create(colon + 1, argument_count); } diff --git a/source/html.c b/source/html.c index 2e3a3b7..b97fdbb 100644 --- a/source/html.c +++ b/source/html.c @@ -324,8 +324,7 @@ void html_hidden(const char *name, const char *value) html("'>"); } -void html_option(const char *value, const char *text, - const char *selected_value) +void html_option(const char *value, const char *text, const char *selected_value) { html("<option value='"); html_attr(value); @@ -339,8 +338,7 @@ void html_option(const char *value, const char *text, void html_intoption(int value, const char *text, int selected_value) { - htmlf("<option value='%d'%s>", value, - value == selected_value ? " selected" : ""); + htmlf("<option value='%d'%s>", value, value == selected_value ? " selected" : ""); html_txt(text); html("</option>\n"); } @@ -371,8 +369,7 @@ void html_link_close(void) */ void html_fileperm(unsigned short mode) { - htmlf("%c%c%c", (mode & 4 ? 'r' : '-'), - (mode & 2 ? 'w' : '-'), (mode & 1 ? 'x' : '-')); + htmlf("%c%c%c", (mode & 4 ? 'r' : '-'), (mode & 2 ? 'w' : '-'), (mode & 1 ? 'x' : '-')); } int html_include(const char *filename) @@ -382,8 +379,7 @@ int html_include(const char *filename) size_t len; if (!(f = fopen(filename, "r"))) { - fprintf(stderr, "[cgit] Error including file %s: %s (%d)\n", - filename, strerror(errno), errno); + fprintf(stderr, "[cgit] Error including file %s: %s (%d)\n", filename, strerror(errno), errno); return -1; } while ((len = fread(buf, 1, sizeof(buf), f)) > 0) @@ -392,8 +388,7 @@ int html_include(const char *filename) return 0; } -void http_parse_querystring(const char *txt, - void (*fn)(const char *name, const char *value)) +void http_parse_querystring(const char *txt, void (*fn)(const char *name, const char *value)) { const char *p = txt; diff --git a/source/html.h b/source/html.h index 3bbb30e..410661b 100644 --- a/source/html.h +++ b/source/html.h @@ -67,17 +67,13 @@ extern char *cgit_fmt(const char *format, ...); __attribute__((format (printf,1,2))) extern char *cgit_fmtalloc(const char *format, ...); -extern void html_option(const char *value, const char *text, - const char *selected_value); +extern void html_option(const char *value, const char *text, const char *selected_value); extern void html_intoption(int value, const char *text, int selected_value); -extern void html_link_open(const char *url, const char *title, - const char *class); +extern void html_link_open(const char *url, const char *title, const char *class); extern void html_link_close(void); extern void html_fileperm(unsigned short mode); extern int html_include(const char *filename); -extern void http_parse_querystring(const char *txt, - void (*fn)(const char *name, - const char *value)); +extern void http_parse_querystring(const char *txt, void (*fn)(const char *name, const char *value)); #endif // CGIT_HTML_H diff --git a/source/parsing.c b/source/parsing.c index 745bbba..c992538 100644 --- a/source/parsing.c +++ b/source/parsing.c @@ -29,8 +29,7 @@ static char *substr(const char *start, const char *end) return buf; } -static void parse_user(const char *line, char **name, char **email, - timestamp_t *date, int *tz) +static void parse_user(const char *line, char **name, char **email, timestamp_t *date, int *tz) { struct ident_split ident; struct strbuf address = STRBUF_INIT; @@ -158,14 +157,12 @@ struct commitinfo *cgit_parse_commit(struct commit *commit) p += the_hash_algo->hexsz + 1; if (skip_prefix(p, "author ", &p)) { - parse_user(p, &info->author, &info->author_email, - &info->author_date, &info->author_tz); + parse_user(p, &info->author, &info->author_email, &info->author_date, &info->author_tz); p = next_header_line(p); } if (p && skip_prefix(p, "committer ", &p)) { - parse_user(p, &info->committer, &info->committer_email, - &info->committer_date, &info->committer_tz); + parse_user(p, &info->committer, &info->committer_email, &info->committer_date, &info->committer_tz); p = next_header_line(p); } @@ -218,8 +215,7 @@ struct taginfo *cgit_parse_tag(struct tag *tag) const char *p; struct taginfo *info = NULL; - data = odb_read_object(the_repository->objects, &tag->object.oid, - &type, &size); + data = odb_read_object(the_repository->objects, &tag->object.oid, &type, &size); if (!data || type != OBJ_TAG) goto cleanup; @@ -227,8 +223,7 @@ struct taginfo *cgit_parse_tag(struct tag *tag) for (p = data; !end_of_header(p); p = next_header_line(p)) { if (skip_prefix(p, "tagger ", &p)) { - parse_user(p, &info->tagger, &info->tagger_email, - &info->tagger_date, &info->tagger_tz); + parse_user(p, &info->tagger, &info->tagger_email, &info->tagger_date, &info->tagger_tz); } } diff --git a/source/scan-tree.c b/source/scan-tree.c index f72a5be..c46b47d 100644 --- a/source/scan-tree.c +++ b/source/scan-tree.c @@ -16,8 +16,7 @@ // Git writes this line into the description file of every repository it // creates, so a repository still carrying it gets cgit's own default instead. static const char *default_git_desc = - "Unnamed repository; edit this file 'description' to name the " - "repository."; + "Unnamed repository; edit this file 'description' to name the repository."; // The config callbacks are handed only a name and a value, so the repository // being filled in waits here for the length of one add_repo call. @@ -33,8 +32,7 @@ static int stat_entry(const char *dir, const char *name, struct stat *st) // A missing entry is the ordinary answer for a directory that is not a // repository, so only some other failure is worth reporting. if (err && errno != ENOENT) - fprintf(stderr, "[cgit] Error checking path %s: %s (%d)\n", - dir, strerror(errno), errno); + fprintf(stderr, "[cgit] Error checking path %s: %s (%d)\n", dir, strerror(errno), errno); strbuf_release(&path); return err; } @@ -51,8 +49,7 @@ static int is_git_dir(const char *path) } static int apply_gitconfig(const char *key, const char *value, - const __attribute__((unused)) struct config_context *cfg_ctx, - void *cb) + const __attribute__((unused)) struct config_context *cfg_ctx, void *cb) { const char *name; @@ -94,8 +91,7 @@ static char *section_slash(struct strbuf *relpath, int depth) depth--; } else { slash = relpath->buf + relpath->len; - while (slash && depth && - (slash = find_char_back(relpath->buf, slash - 1, '/'))) + while (slash && depth && (slash = find_char_back(relpath->buf, slash - 1, '/'))) depth++; } return slash && !depth ? slash : NULL; @@ -127,8 +123,7 @@ static void add_repo(const char *base, struct strbuf *path) size_t desc_size; if (stat(path->buf, &st)) { - fprintf(stderr, "[cgit] Error accessing %s: %s (%d)\n", - path->buf, strerror(errno), errno); + fprintf(stderr, "[cgit] Error accessing %s: %s (%d)\n", path->buf, strerror(errno), errno); return; } @@ -184,18 +179,15 @@ static void add_repo(const char *base, struct strbuf *path) if (pwd->pw_gecos) if ((comma = strchr(pwd->pw_gecos, ','))) *comma = '\0'; - current_repo->owner = cgit_strdup_first_line( - pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name); + current_repo->owner = cgit_strdup_first_line(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name); } if (current_repo->desc == cgit_default_repo_desc || !current_repo->desc) { strbuf_addstr(path, "description"); if (!stat(path->buf, &st)) - cgit_read_first_line(path->buf, ¤t_repo->desc, - &desc_size); + cgit_read_first_line(path->buf, ¤t_repo->desc, &desc_size); strbuf_setlen(path, pathlen); - if (current_repo->desc && - !strcmp(current_repo->desc, default_git_desc)) { + if (current_repo->desc && !strcmp(current_repo->desc, default_git_desc)) { free(current_repo->desc); current_repo->desc = cgit_default_repo_desc; } @@ -231,8 +223,7 @@ static void scan_path(const char *base, const char *path) struct stat st; if (!dir) { - fprintf(stderr, "[cgit] Error opening directory %s: %s (%d)\n", - path, strerror(errno), errno); + fprintf(stderr, "[cgit] Error opening directory %s: %s (%d)\n", path, strerror(errno), errno); return; } @@ -255,8 +246,7 @@ static void scan_path(const char *base, const char *path) strbuf_setlen(&pathbuf, pathlen); strbuf_addstr(&pathbuf, ent->d_name); if (stat(pathbuf.buf, &st)) { - fprintf(stderr, "[cgit] Error checking path %s: %s (%d)\n", - pathbuf.buf, strerror(errno), errno); + fprintf(stderr, "[cgit] Error checking path %s: %s (%d)\n", pathbuf.buf, strerror(errno), errno); continue; } if (S_ISDIR(st.st_mode)) diff --git a/source/shared.c b/source/shared.c index fab5c13..beda48b 100644 --- a/source/shared.c +++ b/source/shared.c @@ -45,8 +45,7 @@ static void free_refinfo(struct refinfo *ref) free(ref); } -static struct refinfo *make_refinfo(const char *refname, - const struct object_id *oid) +static struct refinfo *make_refinfo(const char *refname, const struct object_id *oid) { struct refinfo *ref; @@ -81,8 +80,7 @@ static int load_mmfile(mmfile_t *file, const struct object_id *oid) return 1; } - file->ptr = odb_read_object(the_repository->objects, oid, &type, - (unsigned long *)&file->size); + file->ptr = odb_read_object(the_repository->objects, oid, &type, (unsigned long *)&file->size); // odb_read_object leaves size untouched when it fails, so the caller // has to be told rather than handed a buffer with an unset length. return file->ptr != NULL; @@ -194,9 +192,7 @@ struct cgit_repo *cgit_add_repo(const char *url) cgit_repolist.length = 8; else cgit_repolist.length *= 2; - cgit_repolist.repos = xrealloc(cgit_repolist.repos, - cgit_repolist.length * - sizeof(struct cgit_repo)); + cgit_repolist.repos = xrealloc(cgit_repolist.repos, cgit_repolist.length * sizeof(struct cgit_repo)); } repo = &cgit_repolist.repos[cgit_repolist.count-1]; @@ -342,8 +338,7 @@ int cgit_refs_cb(const struct reference *ref, void *cb_data) return 0; } -void cgit_diff_tree_cb(struct diff_queue_struct *q, - struct diff_options *options, void *data) +void cgit_diff_tree_cb(struct diff_queue_struct *q, struct diff_options *options, void *data) { filepair_fn fn = (filepair_fn)data; int i; @@ -356,10 +351,9 @@ void cgit_diff_tree_cb(struct diff_queue_struct *q, } } -int cgit_diff_files(const struct object_id *old_oid, - const struct object_id *new_oid, unsigned long *old_size, - unsigned long *new_size, int *binary, int context, - int ignorews, linediff_fn fn) +int cgit_diff_files(const struct object_id *old_oid, const struct object_id *new_oid, + unsigned long *old_size, unsigned long *new_size, int *binary, int context, int ignorews, + linediff_fn fn) { mmfile_t old_file, new_file; xpparam_t diff_params; @@ -370,19 +364,17 @@ int cgit_diff_files(const struct object_id *old_oid, // Read the object headers first so an oversized blob is never inflated // into memory just to be diffed. Reporting it as binary suppresses // inlining the same way max-blob-size does in the other views. - if (!is_null_oid(old_oid) && - odb_read_object_info(the_repository->objects, old_oid, &old_bytes) < 0) + if (!is_null_oid(old_oid) && odb_read_object_info(the_repository->objects, old_oid, &old_bytes) < 0) return 1; - if (!is_null_oid(new_oid) && - odb_read_object_info(the_repository->objects, new_oid, &new_bytes) < 0) + if (!is_null_oid(new_oid) && odb_read_object_info(the_repository->objects, new_oid, &new_bytes) < 0) return 1; *old_size = old_bytes; *new_size = new_bytes; if (ctx.cfg.max_blob_size && - (old_bytes / 1024 > (unsigned long)ctx.cfg.max_blob_size || - new_bytes / 1024 > (unsigned long)ctx.cfg.max_blob_size)) { + (old_bytes / 1024 > (unsigned long)ctx.cfg.max_blob_size || + new_bytes / 1024 > (unsigned long)ctx.cfg.max_blob_size)) { *binary = 1; return 0; } @@ -394,8 +386,7 @@ int cgit_diff_files(const struct object_id *old_oid, return 1; } - if (buffer_is_binary(old_file.ptr, old_file.size) || - buffer_is_binary(new_file.ptr, new_file.size)) { + if (buffer_is_binary(old_file.ptr, old_file.size) || buffer_is_binary(new_file.ptr, new_file.size)) { *binary = 1; release_mmfile(&old_file, old_oid); release_mmfile(&new_file, new_oid); @@ -418,9 +409,8 @@ int cgit_diff_files(const struct object_id *old_oid, return 0; } -void cgit_diff_tree(const struct object_id *old_oid, - const struct object_id *new_oid, - filepair_fn fn, const char *prefix, int ignorews) +void cgit_diff_tree(const struct object_id *old_oid, const struct object_id *new_oid, + filepair_fn fn, const char *prefix, int ignorews) { struct diff_options opt; struct pathspec_item *item; @@ -457,8 +447,7 @@ void cgit_diff_commit(struct commit *commit, filepair_fn fn, const char *prefix) if (commit->parents) old_oid = &commit->parents->item->object.oid; - cgit_diff_tree(old_oid, &commit->object.oid, fn, prefix, - ctx.qry.ignorews); + cgit_diff_tree(old_oid, &commit->object.oid, fn, prefix, ctx.qry.ignorews); } /* @@ -508,10 +497,8 @@ void cgit_prepare_repo_env(struct cgit_repo *repo) for (i = 0; i < ARRAY_SIZE(vars); i++) if (vars[i].value && setenv(vars[i].name, vars[i].value, 1)) - fprintf(stderr, - "[cgit] Error setting env %s=%s: %s (%d)\n", - vars[i].name, vars[i].value, - strerror(errno), errno); + fprintf(stderr, "[cgit] Error setting env %s=%s: %s (%d)\n", + vars[i].name, vars[i].value, strerror(errno), errno); } int cgit_read_first_line(const char *path, char **buf, size_t *size) diff --git a/source/shared.h b/source/shared.h index 9f4cba3..b9f6ecf 100644 --- a/source/shared.h +++ b/source/shared.h @@ -44,8 +44,7 @@ extern int cgit_refs_cb(const struct reference *ref, void *cb_data); extern void cgit_free_commitinfo(struct commitinfo *info); extern void cgit_free_taginfo(struct taginfo *info); -extern void cgit_diff_tree_cb(struct diff_queue_struct *q, - struct diff_options *options, void *data); +extern void cgit_diff_tree_cb(struct diff_queue_struct *q, struct diff_options *options, void *data); /* * Diff two blobs and hand fn one line at a time. Returns non-zero when either @@ -53,17 +52,13 @@ extern void cgit_diff_tree_cb(struct diff_queue_struct *q, * sets binary instead, and produces no lines, so the caller can offer a link * in place of the content. */ -extern int cgit_diff_files(const struct object_id *old_oid, - const struct object_id *new_oid, - unsigned long *old_size, unsigned long *new_size, - int *binary, int context, int ignorews, - linediff_fn fn); +extern int cgit_diff_files(const struct object_id *old_oid, const struct object_id *new_oid, + unsigned long *old_size, unsigned long *new_size, int *binary, int context, int ignorews, + linediff_fn fn); -extern void cgit_diff_tree(const struct object_id *old_oid, - const struct object_id *new_oid, - filepair_fn fn, const char *prefix, int ignorews); -extern void cgit_diff_commit(struct commit *commit, filepair_fn fn, - const char *prefix); +extern void cgit_diff_tree(const struct object_id *old_oid, const struct object_id *new_oid, + filepair_fn fn, const char *prefix, int ignorews); +extern void cgit_diff_commit(struct commit *commit, filepair_fn fn, const char *prefix); // Accept only the date formats cgit documents, leaving mode unchanged for // anything else. diff --git a/source/ui-atom.c b/source/ui-atom.c index 3eb4332..46039a0 100644 --- a/source/ui-atom.c +++ b/source/ui-atom.c @@ -87,8 +87,7 @@ static void xml_txt(const char *txt) strbuf_addstr(&sb, XML_REPLACEMENT); } else if ((seq = utf8_seq_len(p, left))) { // U+FFFE and U+FFFF are valid UTF-8 but not XML. - if (seq == 3 && p[0] == 0xef && p[1] == 0xbf && - p[2] >= 0xbe) + if (seq == 3 && p[0] == 0xef && p[1] == 0xbf && p[2] >= 0xbe) strbuf_addstr(&sb, XML_REPLACEMENT); else strbuf_add(&sb, p, seq); diff --git a/source/ui-blame.c b/source/ui-blame.c index 8a7f8f0..7248120 100644 --- a/source/ui-blame.c +++ b/source/ui-blame.c @@ -52,7 +52,7 @@ static void free_suspect_details(void) * keep them alive together. */ static void run_blame(struct blame_scoreboard *sb, struct rev_info *revs, - const char *path, const char *rev) + const char *path, const char *rev) { struct strvec argv = STRVEC_INIT; struct blame_origin *origin; @@ -120,15 +120,13 @@ static char *suspect_detail(struct blame_origin *suspect) if (ctx.cfg.enable_plain_email) strbuf_addf(&detail, " %s", info->author_email); strbuf_addf(&detail, " %s\n", - show_date(info->author_date, info->author_tz, - cgit_date_mode(DATE_ISO8601))); + show_date(info->author_date, info->author_tz, cgit_date_mode(DATE_ISO8601))); strbuf_addf(&detail, "committer %s", info->committer); if (ctx.cfg.enable_plain_email) strbuf_addf(&detail, " %s", info->committer_email); strbuf_addf(&detail, " %s\n\n", - show_date(info->committer_date, info->committer_tz, - cgit_date_mode(DATE_ISO8601))); + show_date(info->committer_date, info->committer_tz, cgit_date_mode(DATE_ISO8601))); strbuf_addstr(&detail, info->subject); @@ -145,20 +143,20 @@ static void emit_entry_hash(struct blame_entry *ent) const char *detail = suspect_detail(suspect); html("<span class='oid'>"); - cgit_commit_link(repo_find_unique_abbrev(the_repository, oid, - DEFAULT_ABBREV), - detail, NULL, ctx.qry.head, oid_to_hex(oid), - suspect->path); + cgit_commit_link( + repo_find_unique_abbrev(the_repository, oid, DEFAULT_ABBREV), + detail, NULL, ctx.qry.head, oid_to_hex(oid), suspect->path + ); html("</span>"); - if (!repo_parse_commit(the_repository, suspect->commit) && - suspect->commit->parents) { + if (!repo_parse_commit(the_repository, suspect->commit) && suspect->commit->parents) { struct commit *parent = suspect->commit->parents->item; html(" "); - cgit_blame_link("^", "Blame the previous revision", NULL, - ctx.qry.head, oid_to_hex(&parent->object.oid), - suspect->path); + cgit_blame_link( + "^", "Blame the previous revision", NULL, ctx.qry.head, + oid_to_hex(&parent->object.oid), suspect->path + ); } // The stripes only line up across the columns if each column gives an @@ -228,8 +226,7 @@ static size_t line_width(struct blame_scoreboard *sb, int line) * these blocks, so each block has to be padded to the height and width of * the lines it stands behind. */ -static void emit_entry_background(struct blame_scoreboard *sb, - struct blame_entry *ent) +static void emit_entry_background(struct blame_scoreboard *sb, struct blame_entry *ent) { size_t widest = 2; int line; @@ -267,7 +264,7 @@ static void emit_line_backgrounds(struct blame_scoreboard *sb) } static void print_blame_page(const struct object_id *oid, const char *path, - const char *filename, const char *rev) + const char *filename, const char *rev) { enum object_type type; char *buf; @@ -277,21 +274,20 @@ static void print_blame_page(const struct object_id *oid, const char *path, type = odb_read_object_info(the_repository->objects, oid, &size); if (type == OBJ_BAD) { - cgit_print_error_page(404, "Not Found", "Bad object name: %s", - oid_to_hex(oid)); + cgit_print_error_page(404, "Not Found", "Bad object name: %s", oid_to_hex(oid)); return; } if (ctx.cfg.max_blob_size && size / 1024 > (unsigned long)ctx.cfg.max_blob_size) { - cgit_print_error_page(413, "Content Too Large", - "blob size (%luKB) exceeds display size limit (%dKB)", - size / 1024, ctx.cfg.max_blob_size); + cgit_print_error_page( + 413, "Content Too Large", "blob size (%luKB) exceeds display size limit (%dKB)", + size / 1024, ctx.cfg.max_blob_size + ); return; } buf = odb_read_object(the_repository->objects, oid, &type, &size); if (!buf) { - cgit_print_error_page(500, "Internal Server Error", - "Error reading object %s", oid_to_hex(oid)); + cgit_print_error_page(500, "Internal Server Error", "Error reading object %s", oid_to_hex(oid)); return; } @@ -357,27 +353,24 @@ cleanup: } static int walk_tree(const struct object_id *oid, struct strbuf *base, - const char *pathname, unsigned mode, void *data) + const char *pathname, unsigned mode, void *data) { struct walk_tree_context *walk = data; // match_baselen is -1 when no path was given, which no length equals. - if (walk->match_baselen >= 0 && - base->len == (size_t)walk->match_baselen) { + if (walk->match_baselen >= 0 && base->len == (size_t)walk->match_baselen) { if (S_ISREG(mode)) { struct strbuf fullpath = STRBUF_INIT; strbuf_addbuf(&fullpath, base); strbuf_addstr(&fullpath, pathname); - print_blame_page(oid, fullpath.buf, pathname, - walk->rev); + print_blame_page(oid, fullpath.buf, pathname, walk->rev); strbuf_release(&fullpath); walk->found = TARGET_FILE; } else if (S_ISDIR(mode)) { walk->found = TARGET_FOLDER; } - } else if (base->len < INT_MAX - && (int)base->len > walk->match_baselen) { + } else if (base->len < INT_MAX && (int)base->len > walk->match_baselen) { walk->found = TARGET_FOLDER; } else if (S_ISDIR(mode)) { return READ_TREE_RECURSIVE; @@ -419,28 +412,23 @@ void cgit_print_blame(void) rev = ctx.qry.head; if (repo_get_oid(the_repository, rev, &oid)) { - cgit_print_error_page(404, "Not Found", - "Invalid revision name: %s", rev); + cgit_print_error_page(404, "Not Found", "Invalid revision name: %s", rev); return; } commit = lookup_commit_reference(the_repository, &oid); if (!commit || repo_parse_commit(the_repository, commit)) { - cgit_print_error_page(404, "Not Found", - "Invalid commit reference: %s", rev); + cgit_print_error_page(404, "Not Found", "Invalid commit reference: %s", rev); return; } walk.rev = xstrdup(rev); - walk.match_baselen = path_items.match ? - basedir_len(path_items.match) : -1; + walk.match_baselen = path_items.match ? basedir_len(path_items.match) : -1; - read_tree(the_repository, repo_get_commit_tree(the_repository, commit), - &paths, walk_tree, &walk); + read_tree(the_repository, repo_get_commit_tree(the_repository, commit), &paths, walk_tree, &walk); if (walk.found == TARGET_MISSING) cgit_print_error_page(404, "Not Found", "Not found"); else if (walk.found == TARGET_FOLDER) - cgit_print_error_page(404, "Not Found", - "Blame is not available for folders."); + cgit_print_error_page(404, "Not Found", "Blame is not available for folders."); free(walk.rev); } diff --git a/source/ui-blob.c b/source/ui-blob.c index 67af675..a298e54 100644 --- a/source/ui-blob.c +++ b/source/ui-blob.c @@ -26,14 +26,13 @@ struct walk_tree_context { * READ_TREE_RECURSIVE means step into this entry and zero means step over it. */ static int walk_tree(const struct object_id *oid, struct strbuf *base, - const char *pathname, unsigned mode, void *context) + const char *pathname, unsigned mode, void *context) { struct walk_tree_context *walk = context; if (walk->file_only && !S_ISREG(mode)) return READ_TREE_RECURSIVE; - if (strncmp(base->buf, walk->match_path, base->len) - || strcmp(walk->match_path + base->len, pathname)) + if (strncmp(base->buf, walk->match_path, base->len) || strcmp(walk->match_path + base->len, pathname)) return READ_TREE_RECURSIVE; oidcpy(walk->matched_oid, oid); walk->found_path = 1; @@ -66,8 +65,7 @@ static int find_path_oid(struct object_id *oid, char *path, int file_only) .file_only = file_only }; - read_tree(the_repository, repo_get_commit_tree(the_repository, commit), - &paths, walk_tree, &walk); + read_tree(the_repository, repo_get_commit_tree(the_repository, commit), &paths, walk_tree, &walk); return walk.found_path; } @@ -77,8 +75,7 @@ static int find_path_oid(struct object_id *oid, char *path, int file_only) */ static int over_size_limit(unsigned long size) { - return ctx.cfg.max_blob_size && - size / 1024 > (unsigned long)ctx.cfg.max_blob_size; + return ctx.cfg.max_blob_size && size / 1024 > (unsigned long)ctx.cfg.max_blob_size; } int cgit_ref_path_exists(const char *path, const char *ref, int file_only) @@ -155,14 +152,12 @@ void cgit_print_blob(const char *hex, char *path, const char *head, int file_onl if (hex) { if (get_oid_hex(hex, &oid)) { - cgit_print_error_page(400, "Bad Request", - "Bad hex value: %s", hex); + cgit_print_error_page(400, "Bad Request", "Bad hex value: %s", hex); return; } } else { if (repo_get_oid(the_repository, head, &oid)) { - cgit_print_error_page(404, "Not Found", - "Bad ref: %s", head); + cgit_print_error_page(404, "Not Found", "Bad ref: %s", head); return; } } @@ -171,30 +166,26 @@ void cgit_print_blob(const char *hex, char *path, const char *head, int file_onl if (!hex && type == OBJ_COMMIT && path) { if (!find_path_oid(&oid, path, file_only)) { - cgit_print_error_page(404, "Not Found", - "Path not found: %s", path); + cgit_print_error_page(404, "Not Found", "Path not found: %s", path); return; } type = odb_read_object_info(the_repository->objects, &oid, &size); } if (type == OBJ_BAD) { - cgit_print_error_page(404, "Not Found", - "Bad object name: %s", hex ? hex : path); + cgit_print_error_page(404, "Not Found", "Bad object name: %s", hex ? hex : path); return; } if (over_size_limit(size)) { - cgit_print_error_page(413, "Content Too Large", - "Object size (%luKB) exceeds limit (%dKB)", - size / 1024, ctx.cfg.max_blob_size); + cgit_print_error_page(413, "Content Too Large", "Object size (%luKB) exceeds limit (%dKB)", + size / 1024, ctx.cfg.max_blob_size); return; } buf = odb_read_object(the_repository->objects, &oid, &type, &size); if (!buf) { - cgit_print_error_page(500, "Internal Server Error", - "Error reading object %s", hex ? hex : path); + cgit_print_error_page(500, "Internal Server Error", "Error reading object %s", hex ? hex : path); return; } diff --git a/source/ui-blob.h b/source/ui-blob.h index eb3dbd1..2eab0db 100644 --- a/source/ui-blob.h +++ b/source/ui-blob.h @@ -8,11 +8,8 @@ #ifndef CGIT_UI_BLOB_H #define CGIT_UI_BLOB_H -extern int cgit_ref_path_exists(const char *path, const char *ref, - int file_only); -extern int cgit_print_file(char *path, const char *head, int file_only, - int html_escape); -extern void cgit_print_blob(const char *hex, char *path, const char *head, - int file_only); +extern int cgit_ref_path_exists(const char *path, const char *ref, int file_only); +extern int cgit_print_file(char *path, const char *head, int file_only, int html_escape); +extern void cgit_print_blob(const char *hex, char *path, const char *head, int file_only); #endif // CGIT_UI_BLOB_H diff --git a/source/ui-clone.c b/source/ui-clone.c index f5c4d59..4329e9d 100644 --- a/source/ui-clone.c +++ b/source/ui-clone.c @@ -70,12 +70,10 @@ static void print_pack_info(void) // because a pack the multi-pack-index already covers joins that // list only when the accessor loads it, and reading the field // directly leaves those packs unfindable. - for (entry = packfile_store_get_packs(files->packed); entry; - entry = entry->next) { + for (entry = packfile_store_get_packs(files->packed); entry; entry = entry->next) { struct packed_git *pack = entry->pack; if (pack->pack_local) - htmlf("P %s\n", - last_path_component(pack->pack_name)); + htmlf("P %s\n", last_path_component(pack->pack_name)); } } } @@ -134,8 +132,7 @@ void cgit_clone_info(void) ctx.page.mimetype = "text/plain"; ctx.page.filename = "info/refs"; cgit_print_http_headers(); - refs_for_each_ref(get_main_ref_store(the_repository), - print_ref, NULL); + refs_for_each_ref(get_main_ref_store(the_repository), print_ref, NULL); } void cgit_clone_objects(void) diff --git a/source/ui-commit.c b/source/ui-commit.c index a35fcec..6055509 100644 --- a/source/ui-commit.c +++ b/source/ui-commit.c @@ -23,8 +23,8 @@ // many parents or more is shown without a diff at all. #define OCTOPUS_PARENTS 3 -static void print_ident_row(const char *role, const char *name, - const char *email, timestamp_t date, int tz) +static void print_ident_row(const char *role, const char *name, const char *email, + timestamp_t date, int tz) { htmlf("<tr><th>%s</th><td>", role); cgit_open_filter(ctx.repo->email_filter, email, "commit"); @@ -41,8 +41,7 @@ static void print_ident_row(const char *role, const char *name, html("</time></td></tr>\n"); } -static int print_parent_rows(struct commit *commit, const char *rev, - const char *prefix) +static int print_parent_rows(struct commit *commit, const char *rev, const char *prefix) { struct commit_list *p; struct commit *parent; @@ -50,24 +49,20 @@ static int print_parent_rows(struct commit *commit, const char *rev, int parents = 0; for (p = commit->parents; p; p = p->next) { - parent = lookup_commit_reference(the_repository, - &p->item->object.oid); + parent = lookup_commit_reference(the_repository, &p->item->object.oid); if (!parent) { html("<tr><td colspan='3'>"); cgit_print_error("Error reading parent commit"); html("</td></tr>\n"); continue; } - html("<tr><th>parent</th>" - "<td colspan='2' class='oid'>"); + html("<tr><th>parent</th><td colspan='2' class='oid'>"); parent_hex = label = oid_to_hex(&p->item->object.oid); if (ctx.repo->enable_subject_links) label = cgit_parse_commit(parent)->subject; - cgit_commit_link(label, NULL, NULL, ctx.qry.head, parent_hex, - prefix); + cgit_commit_link(label, NULL, NULL, ctx.qry.head, parent_hex, prefix); html(" ("); - cgit_diff_link("diff", NULL, NULL, ctx.qry.head, rev, - oid_to_hex(&p->item->object.oid), prefix); + cgit_diff_link("diff", NULL, NULL, ctx.qry.head, rev, oid_to_hex(&p->item->object.oid), prefix); html(")</td></tr>\n"); parents++; } @@ -95,14 +90,12 @@ void cgit_print_commit(char *hex, const char *prefix) hex = ctx.qry.head; if (repo_get_oid(the_repository, hex, &oid)) { - cgit_print_error_page(400, "Bad Request", - "Bad object id: %s", hex); + cgit_print_error_page(400, "Bad Request", "Bad object id: %s", hex); return; } commit = lookup_commit_reference(the_repository, &oid); if (!commit) { - cgit_print_error_page(404, "Not Found", - "Bad commit reference: %s", hex); + cgit_print_error_page(404, "Not Found", "Bad commit reference: %s", hex); return; } info = cgit_parse_commit(commit); @@ -116,15 +109,13 @@ void cgit_print_commit(char *hex, const char *prefix) cgit_print_diff_ctrls(); html("<table class='commit-info'>\n"); - print_ident_row("author", info->author, info->author_email, - info->author_date, info->author_tz); + print_ident_row("author", info->author, info->author_email, info->author_date, info->author_tz); print_ident_row("committer", info->committer, info->committer_email, - info->committer_date, info->committer_tz); + info->committer_date, info->committer_tz); html("<tr><th>commit</th><td colspan='2' class='oid'>"); commit_hex = oid_to_hex(&commit->object.oid); - cgit_commit_link(commit_hex, NULL, NULL, ctx.qry.head, commit_hex, - prefix); + cgit_commit_link(commit_hex, NULL, NULL, ctx.qry.head, commit_hex, prefix); html(" ("); cgit_patch_link("patch", NULL, NULL, NULL, commit_hex, prefix); html(")</td></tr>\n"); @@ -135,12 +126,10 @@ void cgit_print_commit(char *hex, const char *prefix) html("<tr><th>tree</th><td colspan='2' class='oid'>"); tree_rev = xstrdup(hex); - cgit_tree_link(oid_to_hex(get_commit_tree_oid(commit)), NULL, NULL, - ctx.qry.head, tree_rev, NULL); + cgit_tree_link(oid_to_hex(get_commit_tree_oid(commit)), NULL, NULL, ctx.qry.head, tree_rev, NULL); if (prefix) { html(" /"); - cgit_tree_link(prefix, NULL, NULL, ctx.qry.head, tree_rev, - prefix); + cgit_tree_link(prefix, NULL, NULL, ctx.qry.head, tree_rev, prefix); } free(tree_rev); html("</td></tr>\n"); @@ -169,8 +158,7 @@ void cgit_print_commit(char *hex, const char *prefix) if (parents < OCTOPUS_PARENTS) { if (parents) - first_parent = - oid_to_hex(&commit->parents->item->object.oid); + first_parent = oid_to_hex(&commit->parents->item->object.oid); else first_parent = NULL; cgit_print_diff(ctx.qry.oid, first_parent, prefix, 0, 0); diff --git a/source/ui-diff.c b/source/ui-diff.c index 3c7d8d2..fb86a96 100644 --- a/source/ui-diff.c +++ b/source/ui-diff.c @@ -131,26 +131,21 @@ static void print_fileinfo(struct fileinfo *info) cgit_print_filemode(info->new_mode); } - if (info->old_mode != info->new_mode && - !is_null_oid(info->old_oid) && - !is_null_oid(info->new_oid)) { + if (info->old_mode != info->new_mode && !is_null_oid(info->old_oid) && !is_null_oid(info->new_oid)) { html("<span class='modechange'>["); cgit_print_filemode(info->old_mode); html("]</span>"); } htmlf("</td><td class='%s'>", class); - cgit_diff_link(info->new_path, NULL, NULL, ctx.qry.head, ctx.qry.oid, - ctx.qry.oid2, info->new_path); + cgit_diff_link(info->new_path, NULL, NULL, ctx.qry.head, ctx.qry.oid, ctx.qry.oid2, info->new_path); if (info->status == DIFF_STATUS_COPIED || info->status == DIFF_STATUS_RENAMED) { - htmlf(" (%s from ", - info->status == DIFF_STATUS_COPIED ? "copied" : "renamed"); + htmlf(" (%s from ", info->status == DIFF_STATUS_COPIED ? "copied" : "renamed"); html_txt(info->old_path); html(")"); } html("</td><td class='right'>"); if (info->binary) { - htmlf("bin</td><td class='graph'>%lu -> %lu bytes</td></tr>\n", - info->old_size, info->new_size); + htmlf("bin</td><td class='graph'>%lu -> %lu bytes</td></tr>\n", info->old_size, info->new_size); return; } htmlf("%d", info->added + info->removed); @@ -178,8 +173,7 @@ static void count_diff_lines(char *line, int len) } if (!render_line_fn || render_suppressed) return; - if (cap_diffs && ctx.cfg.max_diff_lines > 0 && - lines_added + lines_removed > ctx.cfg.max_diff_lines) { + if (cap_diffs && ctx.cfg.max_diff_lines > 0 && lines_added + lines_removed > ctx.cfg.max_diff_lines) { render_suppressed = 1; return; } @@ -190,8 +184,7 @@ static int show_filepair(struct diff_filepair *pair) { if (!current_prefix) return 1; - return starts_with(pair->one->path, current_prefix) || - starts_with(pair->two->path, current_prefix); + return starts_with(pair->one->path, current_prefix) || starts_with(pair->two->path, current_prefix); } /* @@ -224,13 +217,11 @@ static void print_line(char *line, int len) */ static char *abbrev_oid(const struct object_id *oid) { - return xstrdup(repo_find_unique_abbrev(the_repository, oid, - DEFAULT_ABBREV)); + return xstrdup(repo_find_unique_abbrev(the_repository, oid, DEFAULT_ABBREV)); } -static void print_file_header(const struct object_id *old_oid, char *old_path, - int old_mode, const struct object_id *new_oid, - char *new_path, int new_mode) +static void print_file_header(const struct object_id *old_oid, char *old_path, int old_mode, + const struct object_id *new_oid, char *new_path, int new_mode) { char *old_abbrev, *new_abbrev; int subproject; @@ -265,8 +256,7 @@ static void print_file_header(const struct object_id *old_oid, char *old_path, } else html("<br>--- a/"); if (old_mode != 0) - cgit_tree_link(old_path, NULL, NULL, ctx.qry.head, - oid_to_hex(old_rev_oid), old_path); + cgit_tree_link(old_path, NULL, NULL, ctx.qry.head, oid_to_hex(old_rev_oid), old_path); else html_txt(old_path); if (is_null_oid(new_oid)) { @@ -275,8 +265,7 @@ static void print_file_header(const struct object_id *old_oid, char *old_path, } else html("<br>+++ b/"); if (new_mode != 0) - cgit_tree_link(new_path, NULL, NULL, ctx.qry.head, - oid_to_hex(new_rev_oid), new_path); + cgit_tree_link(new_path, NULL, NULL, ctx.qry.head, oid_to_hex(new_rev_oid), new_path); else html_txt(new_path); } @@ -287,17 +276,14 @@ static void print_file_header(const struct object_id *old_oid, char *old_path, * The length passed counts the terminator, because a renderer strips the last * byte of every line it is given. */ -static void print_subproject_lines(struct diff_filepair *pair, - linediff_fn line_fn) +static void print_subproject_lines(struct diff_filepair *pair, linediff_fn line_fn) { if (S_ISGITLINK(pair->one->mode)) { - char *text = cgit_fmt("-Subproject %s", - oid_to_hex(&pair->one->oid)); + char *text = cgit_fmt("-Subproject %s", oid_to_hex(&pair->one->oid)); line_fn(text, strlen(text) + 1); } if (S_ISGITLINK(pair->two->mode)) { - char *text = cgit_fmt("+Subproject %s", - oid_to_hex(&pair->two->oid)); + char *text = cgit_fmt("+Subproject %s", oid_to_hex(&pair->two->oid)); line_fn(text, strlen(text) + 1); } } @@ -317,8 +303,7 @@ static void print_truncated(const char *path) else html("<div class='truncated'>"); html("This diff is too large to be rendered inline. "); - cgit_diff_link("View it on its own page", NULL, NULL, ctx.qry.head, - ctx.qry.oid, ctx.qry.oid2, path); + cgit_diff_link("View it on its own page", NULL, NULL, ctx.qry.head, ctx.qry.oid, ctx.qry.oid2, path); html("."); if (use_ssdiff) { html("</td></tr>"); @@ -346,9 +331,8 @@ static struct fileinfo *reserve_item(void) * Renders one file's body into its own buffer, the way filepair_cb would have * written it straight out on a second walk. */ -static void collect_body(struct diff_filepair *pair, struct fileinfo *item, - int *binary, unsigned long *old_size, - unsigned long *new_size) +static void collect_body(struct diff_filepair *pair, struct fileinfo *item, int *binary, + unsigned long *old_size, unsigned long *new_size) { struct strbuf *body = &item->body; linediff_fn line_fn = use_ssdiff ? cgit_ssdiff_line_cb : print_line; @@ -360,7 +344,7 @@ static void collect_body(struct diff_filepair *pair, struct fileinfo *item, if (use_ssdiff) cgit_ssdiff_header_begin(); print_file_header(&pair->one->oid, pair->one->path, pair->one->mode, - &pair->two->oid, pair->two->path, pair->two->mode); + &pair->two->oid, pair->two->path, pair->two->mode); if (use_ssdiff) cgit_ssdiff_header_end(); header_len = body->len; @@ -376,15 +360,13 @@ static void collect_body(struct diff_filepair *pair, struct fileinfo *item, // than the two lines the body shows, so run that diff for // the count alone. render_line_fn = NULL; - cgit_diff_files(&pair->one->oid, &pair->two->oid, old_size, - new_size, binary, 0, ctx.qry.ignorews, - count_diff_lines); + cgit_diff_files(&pair->one->oid, &pair->two->oid, old_size, new_size, + binary, 0, ctx.qry.ignorews, count_diff_lines); print_subproject_lines(pair, line_fn); } else { render_line_fn = line_fn; - if (cgit_diff_files(&pair->one->oid, &pair->two->oid, old_size, - new_size, binary, ctx.qry.context, - ctx.qry.ignorews, count_diff_lines)) + if (cgit_diff_files(&pair->one->oid, &pair->two->oid, old_size, new_size, + binary, ctx.qry.context, ctx.qry.ignorews, count_diff_lines)) cgit_print_error("Error running diff"); render_line_fn = NULL; if (*binary) @@ -429,9 +411,8 @@ static void inspect_filepair(struct diff_filepair *pair) if (bodies_usable) collect_body(pair, item, &binary, &old_size, &new_size); else - cgit_diff_files(&pair->one->oid, &pair->two->oid, &old_size, - &new_size, &binary, 0, ctx.qry.ignorews, - count_diff_lines); + cgit_diff_files(&pair->one->oid, &pair->two->oid, &old_size, &new_size, + &binary, 0, ctx.qry.ignorews, count_diff_lines); item->status = pair->status; oidcpy(item->old_oid, &pair->one->oid); @@ -451,14 +432,13 @@ static void inspect_filepair(struct diff_filepair *pair) total_rems += lines_removed; } -static void print_diffstat(const struct object_id *old_oid, - const struct object_id *new_oid, const char *prefix) +static void print_diffstat(const struct object_id *old_oid, const struct object_id *new_oid, + const char *prefix) { int i; html("<div class='diffstat-header'>"); - cgit_diff_link("Diffstat", NULL, NULL, ctx.qry.head, ctx.qry.oid, - ctx.qry.oid2, NULL); + cgit_diff_link("Diffstat", NULL, NULL, ctx.qry.head, ctx.qry.oid, ctx.qry.oid2, NULL); if (prefix) { html(" (limited to '"); html_txt(prefix); @@ -467,8 +447,7 @@ static void print_diffstat(const struct object_id *old_oid, html("</div>\n"); html("<table class='diffstat'>\n"); max_changes = 0; - cgit_diff_tree(old_oid, new_oid, inspect_filepair, prefix, - ctx.qry.ignorews); + cgit_diff_tree(old_oid, new_oid, inspect_filepair, prefix, ctx.qry.ignorews); for (i = 0; i < files; i++) print_fileinfo(&items[i]); html("</table>\n"); @@ -483,9 +462,8 @@ static void print_diffstat(const struct object_id *old_oid, static int over_line_cap(int idx) { return cap_diffs && ctx.cfg.max_diff_lines > 0 && - idx < files && !items[idx].binary && - items[idx].added + items[idx].removed > - (unsigned int)ctx.cfg.max_diff_lines; + idx < files && !items[idx].binary && + items[idx].added + items[idx].removed > (unsigned int)ctx.cfg.max_diff_lines; } static void filepair_cb(struct diff_filepair *pair) @@ -506,7 +484,7 @@ static void filepair_cb(struct diff_filepair *pair) line_fn = cgit_ssdiff_line_cb; } print_file_header(&pair->one->oid, pair->one->path, pair->one->mode, - &pair->two->oid, pair->two->path, pair->two->mode); + &pair->two->oid, pair->two->path, pair->two->mode); if (use_ssdiff) cgit_ssdiff_header_end(); @@ -520,9 +498,8 @@ static void filepair_cb(struct diff_filepair *pair) cgit_ssdiff_footer(); return; } - if (cgit_diff_files(&pair->one->oid, &pair->two->oid, &old_size, - &new_size, &binary, ctx.qry.context, - ctx.qry.ignorews, line_fn)) + if (cgit_diff_files(&pair->one->oid, &pair->two->oid, &old_size, &new_size, + &binary, ctx.qry.context, ctx.qry.ignorews, line_fn)) cgit_print_error("Error running diff"); if (binary) print_binary_differs(); @@ -530,8 +507,7 @@ static void filepair_cb(struct diff_filepair *pair) cgit_ssdiff_footer(); } -static void print_raw_patch(const struct object_id *old_tree_oid, - const struct object_id *new_tree_oid) +static void print_raw_patch(const struct object_id *old_tree_oid, const struct object_id *new_tree_oid) { struct diff_options diffopt; @@ -607,8 +583,8 @@ void cgit_print_diff_ctrls(void) html("</div>\n"); } -void cgit_print_diff(const char *new_rev, const char *old_rev, - const char *prefix, int show_ctrls, int raw) +void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefix, + int show_ctrls, int raw) { struct commit *new_commit, *old_commit; const struct object_id *old_tree_oid, *new_tree_oid; @@ -631,22 +607,19 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, if (!new_rev) new_rev = ctx.qry.head; if (repo_get_oid(the_repository, new_rev, new_rev_oid)) { - cgit_print_error_page(404, "Not Found", - "Bad object name: %s", new_rev); + cgit_print_error_page(404, "Not Found", "Bad object name: %s", new_rev); return; } new_commit = lookup_commit_reference(the_repository, new_rev_oid); if (!new_commit || repo_parse_commit(the_repository, new_commit)) { - cgit_print_error_page(404, "Not Found", - "Bad commit: %s", oid_to_hex(new_rev_oid)); + cgit_print_error_page(404, "Not Found", "Bad commit: %s", oid_to_hex(new_rev_oid)); return; } new_tree_oid = get_commit_tree_oid(new_commit); if (old_rev) { if (repo_get_oid(the_repository, old_rev, old_rev_oid)) { - cgit_print_error_page(404, "Not Found", - "Bad object name: %s", old_rev); + cgit_print_error_page(404, "Not Found", "Bad object name: %s", old_rev); return; } } else if (new_commit->parents && new_commit->parents->item) { @@ -656,12 +629,9 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, } if (!is_null_oid(old_rev_oid)) { - old_commit = lookup_commit_reference(the_repository, - old_rev_oid); - if (!old_commit || - repo_parse_commit(the_repository, old_commit)) { - cgit_print_error_page(404, "Not Found", - "Bad commit: %s", oid_to_hex(old_rev_oid)); + old_commit = lookup_commit_reference(the_repository, old_rev_oid); + if (!old_commit || repo_parse_commit(the_repository, old_commit)) { + cgit_print_error_page(404, "Not Found", "Bad commit: %s", oid_to_hex(old_rev_oid)); return; } old_tree_oid = get_commit_tree_oid(old_commit); @@ -680,8 +650,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, // it came from, which for a side by side diff is several times the blob // itself, and the budget cannot help there because it is only reached // once a body is complete. - bodies_usable = difftype != DIFF_STATONLY && cap_diffs && - ctx.cfg.max_diff_lines > 0; + bodies_usable = difftype != DIFF_STATONLY && cap_diffs && ctx.cfg.max_diff_lines > 0; if (show_ctrls) { cgit_print_layout_start(); @@ -702,11 +671,9 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, return; } - if (cap_diffs && ctx.cfg.max_diff_files > 0 && - files > ctx.cfg.max_diff_files) { + if (cap_diffs && ctx.cfg.max_diff_files > 0 && files > ctx.cfg.max_diff_files) { html("<div class='truncated'>"); - html("This diff is too large to be rendered inline. " - "Follow a file above, or the "); + html("This diff is too large to be rendered inline. Follow a file above, or the "); cgit_patch_link("patch", NULL, NULL, NULL, ctx.qry.oid, NULL); html(" link for the whole commit."); html("</div>"); @@ -730,8 +697,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, release_bodies(); } else { item_idx = 0; - cgit_diff_tree(old_rev_oid, new_rev_oid, filepair_cb, prefix, - ctx.qry.ignorews); + cgit_diff_tree(old_rev_oid, new_rev_oid, filepair_cb, prefix, ctx.qry.ignorews); } if (!use_ssdiff) html("</td></tr>\n"); diff --git a/source/ui-diff.h b/source/ui-diff.h index 67d33ba..467c79f 100644 --- a/source/ui-diff.h +++ b/source/ui-diff.h @@ -17,8 +17,8 @@ extern void cgit_print_diff_ctrls(void); -extern void cgit_print_diff(const char *new_hex, const char *old_hex, - const char *prefix, int show_ctrls, int raw); +extern void cgit_print_diff(const char *new_hex, const char *old_hex, const char *prefix, + int show_ctrls, int raw); extern struct diff_filespec *cgit_get_current_old_file(void); extern struct diff_filespec *cgit_get_current_new_file(void); diff --git a/source/ui-log.c b/source/ui-log.c index 5b5dd32..8fe58f9 100644 --- a/source/ui-log.c +++ b/source/ui-log.c @@ -64,9 +64,8 @@ static void count_file(struct diff_filepair *pair) file_count++; if (ctx.repo->enable_log_linecount) - cgit_diff_files(&pair->one->oid, &pair->two->oid, &old_size, - &new_size, &binary, 0, ctx.qry.ignorews, - count_line); + cgit_diff_files(&pair->one->oid, &pair->two->oid, &old_size, &new_size, + &binary, 0, ctx.qry.ignorews, count_line); } /* @@ -122,9 +121,7 @@ static int should_show(struct commit *commit, struct rev_info *revs) removed_lines = 0; revs->diffopt.flags.recursive = 1; - diff_tree_oid(get_commit_tree_oid(parent), - get_commit_tree_oid(commit), - "", &revs->diffopt); + diff_tree_oid(get_commit_tree_oid(parent), get_commit_tree_oid(commit), "", &revs->diffopt); diffcore_std(&revs->diffopt); found = !diff_queue_is_empty(&revs->diffopt); @@ -146,8 +143,7 @@ static int should_show(struct commit *commit, struct rev_info *revs) * commit itself stays in graph for the caller to place in the commit's own * row. */ -static void print_graph_above(struct rev_info *revs, struct strbuf *graph, - int columns) +static void print_graph_above(struct rev_info *revs, struct strbuf *graph, int columns) { while (!graph_next_line(revs->graph, graph)) { html("<tr class='nohover'><td class='commitgraph'>"); @@ -171,8 +167,7 @@ static void wrap_subject(struct commitinfo *info, struct strbuf *msg) size_t subject_len = strlen(info->subject); int cut; - if (ctx.cfg.max_msg_len < MIN_WRAP_LEN || - subject_len <= (size_t)ctx.cfg.max_msg_len) + if (ctx.cfg.max_msg_len < MIN_WRAP_LEN || subject_len <= (size_t)ctx.cfg.max_msg_len) return; cut = ctx.cfg.max_msg_len - strlen(wrap_symbol); @@ -199,8 +194,7 @@ static int line_count(const char *text) return lines; } -static void print_graph_padding(struct rev_info *revs, struct strbuf *graph, - int lines) +static void print_graph_padding(struct rev_info *revs, struct strbuf *graph, int lines) { html("<td class='commitgraph'>"); while (lines > 0 || !graph_is_commit_finished(revs->graph)) { @@ -237,11 +231,9 @@ static void print_commit(struct commit *commit, struct rev_info *revs) html(graphbuf.buf); html("</td>"); strbuf_setlen(&graphbuf, 0); - } - else { + } else { html("<td>"); - cgit_print_age(info->committer_date, info->committer_tz, - MAX_RELATIVE_AGE); + cgit_print_age(info->committer_date, info->committer_tz, MAX_RELATIVE_AGE); html("</td>"); } @@ -249,7 +241,7 @@ static void print_commit(struct commit *commit, struct rev_info *revs) if (ctx.qry.showmsg) wrap_subject(info, &msgbuf); cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head, - oid_to_hex(&commit->object.oid), ctx.qry.vpath); + oid_to_hex(&commit->object.oid), ctx.qry.vpath); cgit_print_commit_decorations(commit); html("</td><td class='col-author'>"); cgit_open_filter(ctx.repo->email_filter, info->author_email, "log"); @@ -258,12 +250,10 @@ static void print_commit(struct commit *commit, struct rev_info *revs) if (revs->graph) { html("</td><td>"); - cgit_print_age(info->committer_date, info->committer_tz, - MAX_RELATIVE_AGE); + cgit_print_age(info->committer_date, info->committer_tz, MAX_RELATIVE_AGE); } - if (!counts_ready && (ctx.repo->enable_log_filecount || - ctx.repo->enable_log_linecount)) { + if (!counts_ready && (ctx.repo->enable_log_filecount || ctx.repo->enable_log_linecount)) { file_count = 0; added_lines = 0; removed_lines = 0; @@ -274,13 +264,11 @@ static void print_commit(struct commit *commit, struct rev_info *revs) htmlf("</td><td class='col-count'>%d", file_count); if (ctx.repo->enable_log_linecount) htmlf("</td><td class='col-count'><span class='deletions'>-%d</span>/" - "<span class='insertions'>+%d</span>", - removed_lines, added_lines); + "<span class='insertions'>+%d</span>", removed_lines, added_lines); html("</td></tr>\n"); - if ((revs->graph && !graph_is_commit_finished(revs->graph)) - || ctx.qry.showmsg) { + if ((revs->graph && !graph_is_commit_finished(revs->graph)) || ctx.qry.showmsg) { html("<tr class='nohover-highlight'>"); if (ctx.qry.showmsg) { @@ -288,26 +276,22 @@ static void print_commit(struct commit *commit, struct rev_info *revs) strbuf_addstr(&msgbuf, info->msg); strbuf_addch(&msgbuf, '\n'); } - format_display_notes(&commit->object.oid, - &msgbuf, PAGE_ENCODING, 0); + format_display_notes(&commit->object.oid, &msgbuf, PAGE_ENCODING, 0); strbuf_addch(&msgbuf, '\n'); strbuf_ltrim(&msgbuf); } // With no graph the empty cell stands in for the age column. if (revs->graph) { - int msg_lines = ctx.qry.showmsg ? - line_count(msgbuf.buf) : 0; + int msg_lines = ctx.qry.showmsg ? line_count(msgbuf.buf) : 0; print_graph_padding(revs, &graphbuf, msg_lines); - } - else + } else html("<td></td>"); // Either way one cell is already on the row, so the message // spans the remaining columns. - htmlf("<td colspan='%d'%s>\n", columns - 1, - ctx.qry.showmsg ? " class='logmsg'" : ""); + htmlf("<td colspan='%d'%s>\n", columns - 1, ctx.qry.showmsg ? " class='logmsg'" : ""); html_txt(msgbuf.buf); html("</td></tr>\n"); } @@ -370,20 +354,18 @@ static void print_pager(struct rev_info *revs, int ofs, int cnt) html("<ul class='pager'>"); if (ofs > 0) { html("<li>"); - cgit_log_link("[prev]", NULL, NULL, ctx.qry.head, - ctx.qry.oid, ctx.qry.vpath, - ofs - cnt, ctx.qry.grep, - ctx.qry.search, ctx.qry.showmsg, - ctx.qry.follow); + cgit_log_link( + "[prev]", NULL, NULL, ctx.qry.head, ctx.qry.oid, ctx.qry.vpath, + ofs - cnt, ctx.qry.grep, ctx.qry.search, ctx.qry.showmsg, ctx.qry.follow + ); html("</li>"); } if (more) { html("<li>"); - cgit_log_link("[next]", NULL, NULL, ctx.qry.head, - ctx.qry.oid, ctx.qry.vpath, - ofs + cnt, ctx.qry.grep, - ctx.qry.search, ctx.qry.showmsg, - ctx.qry.follow); + cgit_log_link( + "[next]", NULL, NULL, ctx.qry.head, ctx.qry.oid, ctx.qry.vpath, + ofs + cnt, ctx.qry.grep, ctx.qry.search, ctx.qry.showmsg, ctx.qry.follow + ); html("</li>"); } html("</ul>"); @@ -411,31 +393,25 @@ void cgit_print_commit_decorations(struct commit *commit) case DECORATION_NONE: break; case DECORATION_REF_LOCAL: - cgit_log_link(buf, NULL, "branch-deco", buf, NULL, - ctx.qry.vpath, 0, NULL, NULL, - ctx.qry.showmsg, 0); + cgit_log_link(buf, NULL, "branch-deco", buf, NULL, ctx.qry.vpath, 0, NULL, NULL, ctx.qry.showmsg, 0); break; case DECORATION_REF_TAG: - if (!refs_read_ref(get_main_ref_store(the_repository), - deco->name, &oid_tag) && - !peel_object(the_repository, &oid_tag, &peeled, - PEEL_OBJECT_VERIFY_TAGGED_OBJECT_TYPE)) + if (!refs_read_ref(get_main_ref_store(the_repository), deco->name, &oid_tag) && + !peel_object(the_repository, &oid_tag, &peeled, + PEEL_OBJECT_VERIFY_TAGGED_OBJECT_TYPE)) is_annotated = !oideq(&oid_tag, &peeled); - cgit_tag_link(buf, NULL, is_annotated ? - "tag-annotated-deco" : "tag-deco", buf); + cgit_tag_link(buf, NULL, is_annotated ? "tag-annotated-deco" : "tag-deco", buf); break; case DECORATION_REF_REMOTE: if (!ctx.repo->enable_remote_branches) break; - cgit_log_link(buf, NULL, "remote-deco", NULL, - oid_to_hex(&commit->object.oid), - ctx.qry.vpath, 0, NULL, NULL, - ctx.qry.showmsg, 0); + cgit_log_link( + buf, NULL, "remote-deco", NULL, oid_to_hex(&commit->object.oid), + ctx.qry.vpath, 0, NULL, NULL, ctx.qry.showmsg, 0 + ); break; default: - cgit_commit_link(buf, NULL, "deco", ctx.qry.head, - oid_to_hex(&commit->object.oid), - ctx.qry.vpath); + cgit_commit_link(buf, NULL, "deco", ctx.qry.head, oid_to_hex(&commit->object.oid), ctx.qry.vpath); break; } deco = deco->next; @@ -443,9 +419,8 @@ void cgit_print_commit_decorations(struct commit *commit) html("</span>"); } -void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, - char *pattern, const char *path, int pager, - int commit_graph, int commit_sort) +void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, + const char *path, int pager, int commit_graph, int commit_sort) { struct rev_info rev; struct commit *commit; @@ -475,8 +450,7 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, if (grep && pattern && *pattern) { pattern = xstrdup(pattern); - if (!strcmp(grep, "grep") || !strcmp(grep, "author") || - !strcmp(grep, "committer")) { + if (!strcmp(grep, "grep") || !strcmp(grep, "author") || !strcmp(grep, "committer")) { strvec_pushf(&rev_argv, "--%s=%s", grep, pattern); } else if (!strcmp(grep, "range")) { char *arg; @@ -489,8 +463,7 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, strvec_pop(&rev_argv); while ((arg = next_token(&pattern))) { if (*arg == '-') { - fprintf(stderr, "[cgit] Bad range expression: %s\n", - arg); + fprintf(stderr, "[cgit] Bad range expression: %s\n", arg); break; } strvec_push(&rev_argv, arg); @@ -504,8 +477,7 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, if (commit_graph && !ctx.qry.follow) { strvec_push(&rev_argv, "--graph"); strvec_push(&rev_argv, "--color"); - graph_set_column_colors(column_colors_html, - COLUMN_COLORS_HTML_MAX); + graph_set_column_colors(column_colors_html, COLUMN_COLORS_HTML_MAX); } if (commit_sort == 1) @@ -552,11 +524,11 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, html("<th class='left'>Commit message"); if (pager) { html(" ("); - cgit_log_link(ctx.qry.showmsg ? "Collapse" : "Expand", NULL, - NULL, ctx.qry.head, ctx.qry.oid, - ctx.qry.vpath, ctx.qry.ofs, ctx.qry.grep, - ctx.qry.search, ctx.qry.showmsg ? 0 : 1, - ctx.qry.follow); + cgit_log_link( + ctx.qry.showmsg ? "Collapse" : "Expand", NULL, NULL, ctx.qry.head, + ctx.qry.oid, ctx.qry.vpath, ctx.qry.ofs, ctx.qry.grep, ctx.qry.search, + ctx.qry.showmsg ? 0 : 1, ctx.qry.follow + ); html(")"); } html("</th><th class='left col-author'>Author</th>"); @@ -598,9 +570,10 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, cgit_print_layout_end(); } else if ((commit = get_revision(&rev)) != NULL) { htmlf("<tr class='nohover'><td colspan='%d'>", columns); - cgit_log_link("[...]", NULL, NULL, ctx.qry.head, NULL, - ctx.qry.vpath, 0, NULL, NULL, ctx.qry.showmsg, - ctx.qry.follow); + cgit_log_link( + "[...]", NULL, NULL, ctx.qry.head, NULL, ctx.qry.vpath, 0, + NULL, NULL, ctx.qry.showmsg, ctx.qry.follow + ); html("</td></tr>\n"); } diff --git a/source/ui-log.h b/source/ui-log.h index ecfe85d..8e6e3db 100644 --- a/source/ui-log.h +++ b/source/ui-log.h @@ -8,9 +8,8 @@ #ifndef CGIT_UI_LOG_H #define CGIT_UI_LOG_H -extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, - char *pattern, const char *path, int pager, - int commit_graph, int commit_sort); +extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, + const char *path, int pager, int commit_graph, int commit_sort); extern void cgit_print_commit_decorations(struct commit *commit); #endif // CGIT_UI_LOG_H diff --git a/source/ui-patch.c b/source/ui-patch.c index bc98f2e..baa87c9 100644 --- a/source/ui-patch.c +++ b/source/ui-patch.c @@ -25,31 +25,27 @@ * for that one commit instead. */ static int resolve_range(const char *new_rev, const char *old_rev, - struct object_id *new_oid, struct object_id *old_oid) + struct object_id *new_oid, struct object_id *old_oid) { struct commit *commit; if (repo_get_oid(the_repository, new_rev, new_oid)) { - cgit_print_error_page(404, "Not Found", - "Bad object id: %s", new_rev); + cgit_print_error_page(404, "Not Found", "Bad object id: %s", new_rev); return -1; } commit = lookup_commit_reference(the_repository, new_oid); if (!commit) { - cgit_print_error_page(404, "Not Found", - "Bad commit reference: %s", new_rev); + cgit_print_error_page(404, "Not Found", "Bad commit reference: %s", new_rev); return -1; } if (old_rev) { if (repo_get_oid(the_repository, old_rev, old_oid)) { - cgit_print_error_page(404, "Not Found", - "Bad object id: %s", old_rev); + cgit_print_error_page(404, "Not Found", "Bad object id: %s", old_rev); return -1; } if (!lookup_commit_reference(the_repository, old_oid)) { - cgit_print_error_page(404, "Not Found", - "Bad commit reference: %s", old_rev); + cgit_print_error_page(404, "Not Found", "Bad commit reference: %s", old_rev); return -1; } } else if (commit->parents && commit->parents->item) { @@ -60,8 +56,7 @@ static int resolve_range(const char *new_rev, const char *old_rev, return 0; } -void cgit_print_patch(const char *new_rev, const char *old_rev, - const char *prefix) +void cgit_print_patch(const char *new_rev, const char *old_rev, const char *prefix) { struct rev_info rev; struct commit *commit; @@ -71,8 +66,7 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, // first entry stands in for the program name and is skipped, and the // array has to stay null terminated because the path after the double // dash is picked up past the count. - const char *rev_argv[] = { NULL, "--reverse", "--format=email", - rev_range, "--", prefix, NULL }; + const char *rev_argv[] = { NULL, "--reverse", "--format=email", rev_range, "--", prefix, NULL }; int rev_argc = ARRAY_SIZE(rev_argv) - 1; if (!prefix) @@ -87,8 +81,7 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, if (is_null_oid(&old_oid)) { memcpy(rev_range, oid_to_hex(&new_oid), the_hash_algo->hexsz + 1); } else { - xsnprintf(rev_range, REV_RANGE_LEN, "%s..%s", - oid_to_hex(&old_oid), oid_to_hex(&new_oid)); + xsnprintf(rev_range, REV_RANGE_LEN, "%s..%s", oid_to_hex(&old_oid), oid_to_hex(&new_oid)); } ctx.page.mimetype = "text/plain"; @@ -97,9 +90,8 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, if (!ctx.cfg.enable_plain_email) { rev_argv[FORMAT_ARG] = - "--format=format:From %H Mon Sep 17 00:00:00 " - "2001%nFrom: %an%nDate: %aD%n%w(78,0,1)Subject: " - "%s%n%n%w(0)%b"; + "--format=format:From %H Mon Sep 17 00:00:00 2001%n" + "From: %an%nDate: %aD%n%w(78,0,1)Subject: %s%n%n%w(0)%b"; } repo_init_revisions(the_repository, &rev, NULL); @@ -108,15 +100,13 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, rev.diff = 1; rev.show_root_diff = 1; rev.max_parents = 1; - rev.diffopt.output_format |= DIFF_FORMAT_DIFFSTAT | - DIFF_FORMAT_PATCH | DIFF_FORMAT_SUMMARY; + rev.diffopt.output_format |= DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_PATCH | DIFF_FORMAT_SUMMARY; if (prefix) // Allocated rather than formatted into cgit_fmt's fixed // buffer, because the path comes from the request and a long // one would abort the process here, with the headers for a // successful response already on the wire. - rev.diffopt.stat_sep = cgit_fmtalloc("(limited to '%s')\n\n", - prefix); + rev.diffopt.stat_sep = cgit_fmtalloc("(limited to '%s')\n\n", prefix); setup_revisions(rev_argc, rev_argv, &rev, NULL); // A single commit resolves to a range starting at its parent, so this // only ever cuts an explicit range short and keeps one request from diff --git a/source/ui-patch.h b/source/ui-patch.h index 4dfe8bc..4575d1b 100644 --- a/source/ui-patch.h +++ b/source/ui-patch.h @@ -8,7 +8,6 @@ #ifndef CGIT_UI_PATCH_H #define CGIT_UI_PATCH_H -extern void cgit_print_patch(const char *new_rev, const char *old_rev, - const char *prefix); +extern void cgit_print_patch(const char *new_rev, const char *old_rev, const char *prefix); #endif // CGIT_UI_PATCH_H diff --git a/source/ui-plain.c b/source/ui-plain.c index d3b4771..6b45637 100644 --- a/source/ui-plain.c +++ b/source/ui-plain.c @@ -62,10 +62,8 @@ static void print_object(const struct object_id *oid, const char *path) // The limit counts kilobytes and is checked before the read, so a huge // blob is kept out of memory rather than noticed once it is there. - if (ctx.cfg.max_blob_size && - size / 1024 > (unsigned long)ctx.cfg.max_blob_size) { - cgit_print_error_page(413, "Content Too Large", - "Object size (%luKB) exceeds limit (%dKB)", + if (ctx.cfg.max_blob_size && size / 1024 > (unsigned long)ctx.cfg.max_blob_size) { + cgit_print_error_page(413, "Content Too Large", "Object size (%luKB) exceeds limit (%dKB)", size / 1024, ctx.cfg.max_blob_size); return; } @@ -142,15 +140,14 @@ static void print_dir(const char *base, int baselen, const char *path) fullpath = NULL; } html("<li>"); - cgit_plain_link("../", NULL, NULL, ctx.qry.head, ctx.qry.oid, - fullpath); + cgit_plain_link("../", NULL, NULL, ctx.qry.head, ctx.qry.oid, fullpath); html("</li>\n"); } free(fullpath); } static void print_dir_entry(const struct object_id *oid, const char *base, - int baselen, const char *path, unsigned mode) + int baselen, const char *path, unsigned mode) { char *fullpath; @@ -161,8 +158,7 @@ static void print_dir_entry(const struct object_id *oid, const char *base, if (S_ISGITLINK(mode)) cgit_submodule_link(NULL, fullpath, oid_to_hex(oid)); else - cgit_plain_link(path, NULL, NULL, ctx.qry.head, ctx.qry.oid, - fullpath); + cgit_plain_link(path, NULL, NULL, ctx.qry.head, ctx.qry.oid, fullpath); html("</li>\n"); free(fullpath); } @@ -177,7 +173,7 @@ static void print_dir_tail(void) * READ_TREE_RECURSIVE means step into this entry and zero means step over it. */ static int walk_tree(const struct object_id *oid, struct strbuf *base, - const char *pathname, unsigned mode, void *context) + const char *pathname, unsigned mode, void *context) { struct walk_tree_context *walk = context; @@ -252,8 +248,7 @@ void cgit_print_plain(void) } else { walk.dir_len = dir_prefix_len(path_items.match); } - read_tree(the_repository, repo_get_commit_tree(the_repository, commit), - &paths, walk_tree, &walk); + read_tree(the_repository, repo_get_commit_tree(the_repository, commit), &paths, walk_tree, &walk); if (walk.response == RESPONSE_NONE) cgit_print_error_page(404, "Not Found", "Not found"); else if (walk.response == RESPONSE_LISTING) diff --git a/source/ui-refs.c b/source/ui-refs.c index 1b32088..42a3cfb 100644 --- a/source/ui-refs.c +++ b/source/ui-refs.c @@ -73,11 +73,9 @@ static void collect_branches(struct reflist *list) { list->refs = NULL; list->alloc = list->count = 0; - refs_for_each_branch_ref(get_main_ref_store(the_repository), - cgit_refs_cb, list); + refs_for_each_branch_ref(get_main_ref_store(the_repository), cgit_refs_cb, list); if (ctx.repo->enable_remote_branches) - refs_for_each_remote_ref(get_main_ref_store(the_repository), - cgit_refs_cb, list); + refs_for_each_remote_ref(get_main_ref_store(the_repository), cgit_refs_cb, list); } static void print_branch_header(void) @@ -96,8 +94,7 @@ static int print_branch(struct refinfo *ref) if (!info) return 1; html("<tr><td>"); - cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0, NULL, NULL, - ctx.qry.showmsg, 0); + cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0, NULL, NULL, ctx.qry.showmsg, 0); html("</td><td>"); if (ref->object->type == OBJ_COMMIT) { @@ -122,8 +119,7 @@ static void collect_tags(struct reflist *list) { list->refs = NULL; list->alloc = list->count = 0; - refs_for_each_tag_ref(get_main_ref_store(the_repository), - cgit_refs_cb, list); + refs_for_each_tag_ref(get_main_ref_store(the_repository), cgit_refs_cb, list); } static void print_tag_header(void) @@ -197,18 +193,15 @@ static void print_ref_pager(int ofs, int pagesize, int count, const char *path) if (ofs > 0) { int prev_ofs = ofs > pagesize ? ofs - pagesize : 0; - url = cgit_pageurl(ctx.qry.repo, cgit_fmt("refs/%s", path), - cgit_fmt("ofs=%d", prev_ofs)); + url = cgit_pageurl(ctx.qry.repo, cgit_fmt("refs/%s", path), cgit_fmt("ofs=%d", prev_ofs)); html("<a href='"); html_attr(url); html("'>[prev]</a> "); free(url); } - htmlf("%d - %d of %d", ofs + 1, - ofs + pagesize < count ? ofs + pagesize : count, count); + htmlf("%d - %d of %d", ofs + 1, ofs + pagesize < count ? ofs + pagesize : count, count); if (ofs + pagesize < count) { - url = cgit_pageurl(ctx.qry.repo, cgit_fmt("refs/%s", path), - cgit_fmt("ofs=%d", ofs + pagesize)); + url = cgit_pageurl(ctx.qry.repo, cgit_fmt("refs/%s", path), cgit_fmt("ofs=%d", ofs + pagesize)); html(" <a href='"); html_attr(url); html("'>[next]</a>"); @@ -225,8 +218,7 @@ static struct ref_page page_bounds(int pagesize, int count) page.start = ctx.qry.ofs > 0 ? ctx.qry.ofs : 0; if (page.start > count) page.start = count; - page.end = page.start + page.size < count ? - page.start + page.size : count; + page.end = page.start + page.size < count ? page.start + page.size : count; return page; } diff --git a/source/ui-repolist.c b/source/ui-repolist.c index 9f60228..cd22afd 100644 --- a/source/ui-repolist.c +++ b/source/ui-repolist.c @@ -177,8 +177,7 @@ static int any_repos_visible(void) // currenturl is passed in because it is the same for every heading and every // row, and working it out here would mean an allocation and a free per cell. -static void print_column_header(const char *title, const char *column, - const char *currenturl) +static void print_column_header(const char *title, const char *column, const char *currenturl) { htmlf("<th class='left col-%s'><a href='", column); html_attr(currenturl); @@ -214,8 +213,7 @@ static int section_changed(const char *section, const char *last) static void print_section_row(const char *section, int columns) { - htmlf("<tr class='nohover-highlight'><td colspan='%d' class='reposection'>", - columns); + htmlf("<tr class='nohover-highlight'><td colspan='%d' class='reposection'>", columns); html_txt(section); html("</td></tr>\n"); } @@ -224,8 +222,7 @@ static void print_repo_row(const char *currenturl, int sublevel) { char *repourl; - htmlf("<tr><td class='col-name %s'>", - sublevel ? "sublevel-repo" : "toplevel-repo"); + htmlf("<tr><td class='col-name %s'>", sublevel ? "sublevel-repo" : "toplevel-repo"); cgit_summary_link(ctx.repo->name, NULL, NULL, NULL); html("</td><td class='col-desc'>"); repourl = cgit_repourl(ctx.repo->url); @@ -256,8 +253,7 @@ static void print_repo_row(const char *currenturl, int sublevel) if (ctx.cfg.enable_index_links) { html("<td class='col-links'>"); cgit_summary_link("summary", NULL, "button", NULL); - cgit_log_link("log", NULL, "button", NULL, NULL, NULL, - 0, NULL, NULL, ctx.qry.showmsg, 0); + cgit_log_link("log", NULL, "button", NULL, NULL, NULL, 0, NULL, NULL, ctx.qry.showmsg, 0); cgit_tree_link("tree", NULL, "button", NULL, NULL, NULL); html("</td>"); } @@ -273,8 +269,7 @@ static void print_pager(int total, int pagelen, char *search, char *sort) for (i = 0, ofs = 0; ofs < total; i++, ofs = i * pagelen) { class = (ctx.qry.ofs == ofs) ? "current" : NULL; html("<li>"); - cgit_index_link(cgit_fmt("[%d]", i + 1), cgit_fmt("Page %d", i + 1), - class, search, sort, ofs, 0); + cgit_index_link(cgit_fmt("[%d]", i + 1), cgit_fmt("Page %d", i + 1), class, search, sort, ofs, 0); html("</li>"); } html("</ul>\n"); @@ -385,8 +380,7 @@ static int sort_repolist(char *field) continue; if (column->cmp == cmp_idle || column->cmp == cmp_section) resolve_modtimes(); - qsort(cgit_repolist.repos, cgit_repolist.count, - sizeof(struct cgit_repo), column->cmp); + qsort(cgit_repolist.repos, cgit_repolist.count, sizeof(struct cgit_repo), column->cmp); return 1; } return 0; diff --git a/source/ui-shared.c b/source/ui-shared.c index 2ec9d0e..58e7f03 100644 --- a/source/ui-shared.c +++ b/source/ui-shared.c @@ -73,8 +73,7 @@ static const char *root_url(void) return ctx.cfg.script_name; } -static void site_url(const char *page, const char *search, const char *sort, - int ofs, int always_root) +static void site_url(const char *page, const char *search, const char *sort, int ofs, int always_root) { const char *delim = "?"; @@ -109,8 +108,7 @@ static void site_url(const char *page, const char *search, const char *sort, } static void site_link(const char *page, const char *name, const char *title, - const char *class, const char *search, const char *sort, - int ofs, int always_root) + const char *class, const char *search, const char *sort, int ofs, int always_root) { html("<a"); if (title) { @@ -136,9 +134,8 @@ static void site_link(const char *page, const char *name, const char *title, * arguments and close. The return is the delimiter to put before the first of * those, which is still a question mark unless a query string has been opened. */ -static const char *repolink(const char *title, const char *class, - const char *page, const char *head, - const char *path) +static const char *repolink(const char *title, const char *class, const char *page, + const char *head, const char *path) { const char *delim = "?"; @@ -200,8 +197,7 @@ static const char *emit_rev_arg(const char *delim, const char *rev) } static void reporevlink(const char *page, const char *name, const char *title, - const char *class, const char *head, const char *rev, - const char *path) + const char *class, const char *head, const char *rev, const char *path) { const char *delim; @@ -236,8 +232,7 @@ static void emit_diff_args(const char *delim) } } -static struct string_list_item *lookup_path(struct string_list *list, - const char *path) +static struct string_list_item *lookup_path(struct string_list *list, const char *path) { struct string_list_item *item; @@ -307,8 +302,7 @@ static void print_abs_date(time_t t, int tz) html("</time>"); } -static void print_rel_date(time_t t, int tz, double count, const char *class, - const char *suffix) +static void print_rel_date(time_t t, int tz, double count, const char *class, const char *suffix) { htmlf("<time class='%s' datetime='", class); html_attr(show_date(t, tz, cgit_date_mode(DATE_ISO8601_STRICT))); @@ -407,7 +401,7 @@ static const struct object_id *pinned_oid(void) if (!ctx.repo || !ctx.qry.has_oid || !ctx.qry.oid || !ctx.qry.head) return NULL; if (repo_get_oid(the_repository, ctx.qry.oid, &oid) || - repo_get_oid(the_repository, ctx.qry.head, &head_oid)) + repo_get_oid(the_repository, ctx.qry.head, &head_oid)) return NULL; // A full hex id resolves without being looked up, so only peeling to a // commit proves the pin names history, and a tag pinned to the tip @@ -533,16 +527,13 @@ static void print_header(void) if (pinned) { const char *hex = oid_to_hex(pinned); - html_option(hex, cgit_fmt("%.*s (detached)", - SHORT_HASH_LEN, hex), hex); + html_option(hex, cgit_fmt("%.*s (detached)", SHORT_HASH_LEN, hex), hex); } else if (!head_is_listed_branch()) { print_detached_head_option(); } - refs_for_each_branch_ref(get_main_ref_store(the_repository), - print_branch_option, &opt); + refs_for_each_branch_ref(get_main_ref_store(the_repository), print_branch_option, &opt); if (ctx.repo->enable_remote_branches) - refs_for_each_remote_ref(get_main_ref_store(the_repository), - print_branch_option, &opt); + refs_for_each_remote_ref(get_main_ref_store(the_repository), print_branch_option, &opt); html("</select> "); html("<input type='submit' value='switch'>"); html("</form>\n"); @@ -572,8 +563,7 @@ static const char *tab_class(const char *page) return strcmp(ctx.qry.page, page) ? NULL : "active"; } -static const char *tab_title(const char *format, const char *fallback, - const char *path) +static const char *tab_title(const char *format, const char *fallback, const char *path) { if (!path || !*path || strlen(path) > MAX_TITLE_PATH_LEN) return fallback; @@ -587,47 +577,44 @@ static void print_repo_tabs(void) html("<ul>\n"); if (ctx.repo->readme.nr) { html("<li>"); - reporevlink("about", "about", "About this repository", - tab_class("about"), ctx.qry.head, NULL, NULL); + reporevlink("about", "about", "About this repository", tab_class("about"), ctx.qry.head, NULL, NULL); html("</li>\n"); } html("<li>"); - cgit_summary_link("summary", "Repository summary", tab_class("summary"), - ctx.qry.head); + cgit_summary_link("summary", "Repository summary", tab_class("summary"), ctx.qry.head); html("</li>\n<li>"); - cgit_refs_link("refs", "Branches and tags", tab_class("refs"), - ctx.qry.head, ctx.qry.oid, NULL); + cgit_refs_link("refs", "Branches and tags", tab_class("refs"), ctx.qry.head, ctx.qry.oid, NULL); html("</li>\n<li>"); - cgit_log_link("log", - tab_title("Commit history of %s", "Commit history", vpath), - tab_class("log"), ctx.qry.head, - NULL, ctx.qry.vpath, 0, NULL, NULL, - ctx.qry.showmsg, ctx.qry.follow); + cgit_log_link( + "log", tab_title("Commit history of %s", "Commit history", vpath), + tab_class("log"), ctx.qry.head, NULL, ctx.qry.vpath, 0, NULL, NULL, + ctx.qry.showmsg, ctx.qry.follow + ); html("</li>\n<li>"); if (ctx.qry.page && !strcmp(ctx.qry.page, "blame")) - cgit_blame_link("blame", - tab_title("Line-by-line blame of %s", "Blame", vpath), - tab_class("blame"), ctx.qry.head, - ctx.qry.oid, ctx.qry.vpath); + cgit_blame_link( + "blame", tab_title("Line-by-line blame of %s", "Blame", vpath), + tab_class("blame"), ctx.qry.head, ctx.qry.oid, ctx.qry.vpath + ); else - cgit_tree_link("tree", - tab_title("Browse the tree at %s", - "Browse the file tree", vpath), - tab_class("tree"), ctx.qry.head, - ctx.qry.oid, ctx.qry.vpath); + cgit_tree_link( + "tree", tab_title("Browse the tree at %s", "Browse the file tree", vpath), + tab_class("tree"), ctx.qry.head, ctx.qry.oid, ctx.qry.vpath + ); html("</li>\n<li>"); - cgit_commit_link("commit", "The current commit", tab_class("commit"), - ctx.qry.head, ctx.qry.oid, ctx.qry.vpath); + cgit_commit_link( + "commit", "The current commit", tab_class("commit"), + ctx.qry.head, ctx.qry.oid, ctx.qry.vpath + ); html("</li>\n<li>"); - cgit_diff_link("diff", - tab_title("Changes to %s", "Changes in the current commit", vpath), - tab_class("diff"), ctx.qry.head, - ctx.qry.oid, ctx.qry.oid2, ctx.qry.vpath); + cgit_diff_link( + "diff", tab_title("Changes to %s", "Changes in the current commit", vpath), + tab_class("diff"), ctx.qry.head, ctx.qry.oid, ctx.qry.oid2, ctx.qry.vpath + ); html("</li>\n"); if (ctx.repo->max_stats) { html("<li>"); - cgit_stats_link("stats", "Commit activity", tab_class("stats"), - ctx.qry.head, ctx.qry.vpath); + cgit_stats_link("stats", "Commit activity", tab_class("stats"), ctx.qry.head, ctx.qry.vpath); html("</li>\n"); } html("</ul>\n"); @@ -637,8 +624,7 @@ static void print_repo_search(void) { html("<form class='search' method='get' action='"); if (ctx.cfg.virtual_root) { - char *fileurl = cgit_fileurl(ctx.qry.repo, "log", - ctx.qry.vpath, NULL); + char *fileurl = cgit_fileurl(ctx.qry.repo, "log", ctx.qry.vpath, NULL); html_url_path(fileurl); free(fileurl); } @@ -660,13 +646,11 @@ static void print_repo_search(void) static void print_site_tabs(void) { html("<ul>\n<li>"); - site_link(NULL, "index", "Repository index", tab_class("repolist"), - NULL, NULL, 0, 1); + site_link(NULL, "index", "Repository index", tab_class("repolist"), NULL, NULL, 0, 1); html("</li>\n"); if (ctx.cfg.root_readme) { html("<li>"); - site_link("about", "about", "About this site", - tab_class("about"), NULL, NULL, 0, 1); + site_link("about", "about", "About this site", tab_class("about"), NULL, NULL, 0, 1); html("</li>\n"); } html("</ul>\n"); @@ -688,8 +672,7 @@ static void print_site_search(void) } static void snapshot_link(const char *name, const char *title, const char *class, - const char *head, const char *rev, - const char *archivename) + const char *head, const char *rev, const char *archivename) { reporevlink("snapshot", name, title, class, head, rev, archivename); } @@ -699,54 +682,35 @@ static void snapshot_link(const char *name, const char *title, const char *class static void self_link(const char *name, const char *title, const char *class) { if (!strcmp(ctx.qry.page, "repolist")) - cgit_index_link(name, title, class, ctx.qry.search, ctx.qry.sort, - ctx.qry.ofs, 1); + cgit_index_link(name, title, class, ctx.qry.search, ctx.qry.sort, ctx.qry.ofs, 1); else if (!strcmp(ctx.qry.page, "summary")) cgit_summary_link(name, title, class, ctx.qry.head); else if (!strcmp(ctx.qry.page, "tag")) - cgit_tag_link(name, title, class, ctx.qry.has_oid ? - ctx.qry.oid : ctx.qry.head); + cgit_tag_link(name, title, class, ctx.qry.has_oid ? ctx.qry.oid : ctx.qry.head); else if (!strcmp(ctx.qry.page, "tree")) - cgit_tree_link(name, title, class, ctx.qry.head, - ctx.qry.has_oid ? ctx.qry.oid : NULL, - ctx.qry.path); + cgit_tree_link(name, title, class, ctx.qry.head, ctx.qry.has_oid ? ctx.qry.oid : NULL, ctx.qry.path); else if (!strcmp(ctx.qry.page, "plain")) - cgit_plain_link(name, title, class, ctx.qry.head, - ctx.qry.has_oid ? ctx.qry.oid : NULL, - ctx.qry.path); + cgit_plain_link(name, title, class, ctx.qry.head, ctx.qry.has_oid ? ctx.qry.oid : NULL, ctx.qry.path); else if (!strcmp(ctx.qry.page, "blame")) - cgit_blame_link(name, title, class, ctx.qry.head, - ctx.qry.has_oid ? ctx.qry.oid : NULL, - ctx.qry.path); + cgit_blame_link(name, title, class, ctx.qry.head, ctx.qry.has_oid ? ctx.qry.oid : NULL, ctx.qry.path); else if (!strcmp(ctx.qry.page, "log")) - cgit_log_link(name, title, class, ctx.qry.head, - ctx.qry.has_oid ? ctx.qry.oid : NULL, - ctx.qry.path, ctx.qry.ofs, - ctx.qry.grep, ctx.qry.search, - ctx.qry.showmsg, ctx.qry.follow); + cgit_log_link( + name, title, class, ctx.qry.head, ctx.qry.has_oid ? ctx.qry.oid : NULL, + ctx.qry.path, ctx.qry.ofs, ctx.qry.grep, ctx.qry.search, + ctx.qry.showmsg, ctx.qry.follow + ); else if (!strcmp(ctx.qry.page, "commit")) - cgit_commit_link(name, title, class, ctx.qry.head, - ctx.qry.has_oid ? ctx.qry.oid : NULL, - ctx.qry.path); + cgit_commit_link(name, title, class, ctx.qry.head, ctx.qry.has_oid ? ctx.qry.oid : NULL, ctx.qry.path); else if (!strcmp(ctx.qry.page, "patch")) - cgit_patch_link(name, title, class, ctx.qry.head, - ctx.qry.has_oid ? ctx.qry.oid : NULL, - ctx.qry.path); + cgit_patch_link(name, title, class, ctx.qry.head, ctx.qry.has_oid ? ctx.qry.oid : NULL, ctx.qry.path); else if (!strcmp(ctx.qry.page, "refs")) - cgit_refs_link(name, title, class, ctx.qry.head, - ctx.qry.has_oid ? ctx.qry.oid : NULL, - ctx.qry.path); + cgit_refs_link(name, title, class, ctx.qry.head, ctx.qry.has_oid ? ctx.qry.oid : NULL, ctx.qry.path); else if (!strcmp(ctx.qry.page, "snapshot")) - snapshot_link(name, title, class, ctx.qry.head, - ctx.qry.has_oid ? ctx.qry.oid : NULL, - ctx.qry.path); + snapshot_link(name, title, class, ctx.qry.head, ctx.qry.has_oid ? ctx.qry.oid : NULL, ctx.qry.path); else if (!strcmp(ctx.qry.page, "diff")) - cgit_diff_link(name, title, class, ctx.qry.head, - ctx.qry.oid, ctx.qry.oid2, - ctx.qry.path); + cgit_diff_link(name, title, class, ctx.qry.head, ctx.qry.oid, ctx.qry.oid2, ctx.qry.path); else if (!strcmp(ctx.qry.page, "stats")) - cgit_stats_link(name, title, class, ctx.qry.head, - ctx.qry.path); + cgit_stats_link(name, title, class, ctx.qry.head, ctx.qry.path); else { // A page name this switch does not know still gets a plain // repolink, which covers any simple page added later. @@ -824,8 +788,7 @@ char *cgit_hosturl(void) return xstrdup(ctx.env.http_host); if (!ctx.env.server_name) return NULL; - if (!ctx.env.server_port || - atoi(ctx.env.server_port) == DEFAULT_HTTP_PORT) + if (!ctx.env.server_port || atoi(ctx.env.server_port) == DEFAULT_HTTP_PORT) return xstrdup(ctx.env.server_name); return cgit_fmtalloc("%s:%s", ctx.env.server_name, ctx.env.server_port); } @@ -895,8 +858,8 @@ char *cgit_repourl(const char *reponame) return cgit_fmtalloc("?r=%s", reponame); } -char *cgit_fileurl(const char *reponame, const char *pagename, - const char *filename, const char *query) +char *cgit_fileurl(const char *reponame, const char *pagename, const char *filename, + const char *query) { struct strbuf sb = STRBUF_INIT; const char *delim; @@ -904,12 +867,11 @@ char *cgit_fileurl(const char *reponame, const char *pagename, // The result is a raw URL, so the query joiner is a bare ampersand // and each sink escapes the whole string for wherever it lands. if (ctx.cfg.virtual_root) { - strbuf_addf(&sb, "%s%s/%s/%s", ctx.cfg.virtual_root, reponame, - pagename, (filename ? filename:"")); + strbuf_addf(&sb, "%s%s/%s/%s", ctx.cfg.virtual_root, reponame, pagename, + (filename ? filename:"")); delim = "?"; } else { - strbuf_addf(&sb, "?url=%s/%s/%s", reponame, pagename, - (filename ? filename : "")); + strbuf_addf(&sb, "?url=%s/%s/%s", reponame, pagename, (filename ? filename : "")); delim = "&"; } if (query) @@ -917,8 +879,7 @@ char *cgit_fileurl(const char *reponame, const char *pagename, return strbuf_detach(&sb, NULL); } -char *cgit_pageurl(const char *reponame, const char *pagename, - const char *query) +char *cgit_pageurl(const char *reponame, const char *pagename, const char *query) { return cgit_fileurl(reponame, pagename, NULL, query); } @@ -932,46 +893,42 @@ const char *cgit_snapshot_prefix(const struct cgit_repo *repo) } void cgit_index_link(const char *name, const char *title, const char *class, - const char *pattern, const char *sort, int ofs, - int always_root) + const char *pattern, const char *sort, int ofs, int always_root) { site_link(NULL, name, title, class, pattern, sort, ofs, always_root); } -void cgit_summary_link(const char *name, const char *title, const char *class, - const char *head) +void cgit_summary_link(const char *name, const char *title, const char *class, const char *head) { reporevlink(NULL, name, title, class, head, NULL, NULL); } -void cgit_tag_link(const char *name, const char *title, const char *class, - const char *tag) +void cgit_tag_link(const char *name, const char *title, const char *class, const char *tag) { reporevlink("tag", name, title, class, tag, NULL, NULL); } void cgit_tree_link(const char *name, const char *title, const char *class, - const char *head, const char *rev, const char *path) + const char *head, const char *rev, const char *path) { reporevlink("tree", name, title, class, head, rev, path); } void cgit_plain_link(const char *name, const char *title, const char *class, - const char *head, const char *rev, const char *path) + const char *head, const char *rev, const char *path) { reporevlink("plain", name, title, class, head, rev, path); } void cgit_blame_link(const char *name, const char *title, const char *class, - const char *head, const char *rev, const char *path) + const char *head, const char *rev, const char *path) { reporevlink("blame", name, title, class, head, rev, path); } void cgit_log_link(const char *name, const char *title, const char *class, - const char *head, const char *rev, const char *path, - int ofs, const char *grep, const char *pattern, int showmsg, - int follow) + const char *head, const char *rev, const char *path, int ofs, const char *grep, + const char *pattern, int showmsg, int follow) { const char *delim; @@ -1007,7 +964,7 @@ void cgit_log_link(const char *name, const char *title, const char *class, } void cgit_commit_link(const char *name, const char *title, const char *class, - const char *head, const char *rev, const char *path) + const char *head, const char *rev, const char *path) { const char *delim; @@ -1016,8 +973,7 @@ void cgit_commit_link(const char *name, const char *title, const char *class, emit_diff_args(delim); html("'>"); if (name && name[0] != '\0') { - if (ctx.cfg.max_msg_len >= MIN_TRUNCATE_LEN && - strlen(name) > (size_t)ctx.cfg.max_msg_len) { + if (ctx.cfg.max_msg_len >= MIN_TRUNCATE_LEN && strlen(name) > (size_t)ctx.cfg.max_msg_len) { html_ntxt(name, ctx.cfg.max_msg_len - ELLIPSIS_LEN); html("..."); } else @@ -1028,14 +984,13 @@ void cgit_commit_link(const char *name, const char *title, const char *class, } void cgit_refs_link(const char *name, const char *title, const char *class, - const char *head, const char *rev, const char *path) + const char *head, const char *rev, const char *path) { reporevlink("refs", name, title, class, head, rev, path); } void cgit_diff_link(const char *name, const char *title, const char *class, - const char *head, const char *new_rev, const char *old_rev, - const char *path) + const char *head, const char *new_rev, const char *old_rev, const char *path) { const char *delim; @@ -1054,13 +1009,13 @@ void cgit_diff_link(const char *name, const char *title, const char *class, } void cgit_patch_link(const char *name, const char *title, const char *class, - const char *head, const char *rev, const char *path) + const char *head, const char *rev, const char *path) { reporevlink("patch", name, title, class, head, rev, path); } void cgit_stats_link(const char *name, const char *title, const char *class, - const char *head, const char *path) + const char *head, const char *path) { reporevlink("stats", name, title, class, head, NULL, path); } @@ -1074,8 +1029,7 @@ void cgit_object_link(struct object *obj) shortrev = xstrdup(fullrev); shortrev[SHORT_HASH_LEN] = '\0'; if (obj->type == OBJ_COMMIT) { - cgit_commit_link(cgit_fmt("commit %s...", shortrev), NULL, NULL, - ctx.qry.head, fullrev, NULL); + cgit_commit_link(cgit_fmt("commit %s...", shortrev), NULL, NULL, ctx.qry.head, fullrev, NULL); return; } else if (obj->type == OBJ_TREE) page = "tree"; @@ -1128,18 +1082,19 @@ static char *submodule_url_path(const char *url) strbuf_release(&sb); return NULL; } - } else if (skip_prefix(url, "http://", &rest) || - skip_prefix(url, "https://", &rest) || - skip_prefix(url, "git://", &rest) || - skip_prefix(url, "ssh://", &rest)) { + } else if ( + skip_prefix(url, "http://", &rest) || + skip_prefix(url, "https://", &rest) || + skip_prefix(url, "git://", &rest) || + skip_prefix(url, "ssh://", &rest) + ) { rest = strchr(rest, '/'); if (!rest) return NULL; strbuf_addstr(&sb, rest); } else if (skip_prefix(url, "file://", &rest)) { strbuf_addstr(&sb, rest); - } else if ((colon = strchr(url, ':')) && - !memchr(url, '/', colon - url)) { + } else if ((colon = strchr(url, ':')) && !memchr(url, '/', colon - url)) { // scp syntax, user@host:path strbuf_addstr(&sb, colon + 1); } else { @@ -1216,8 +1171,7 @@ static const struct forge *forge_for_host(const char *host, size_t len) size_t i; for (i = 0; i < ARRAY_SIZE(forges); i++) - if (strlen(forges[i].host) == len && - !strncasecmp(forges[i].host, host, len)) + if (strlen(forges[i].host) == len && !strncasecmp(forges[i].host, host, len)) return &forges[i]; return NULL; } @@ -1228,9 +1182,8 @@ static const struct forge *forge_for_host(const char *host, size_t len) * relative urls still land on an internal page when their target is served * here, and a scheme cgit cannot vouch for is left unlinked as a tooltip. */ -static void gitmodules_link(const char *path, const char *rev, - char **module, char **commit, - const char **tooltip) +static void gitmodules_link(const char *path, const char *rev, char **module, + char **commit, const char **tooltip) { const struct object_id *treeish = page_treeish(); const struct submodule *sub; @@ -1256,8 +1209,7 @@ static void gitmodules_link(const char *path, const char *rev, return; } - if (skip_prefix(url, "http://", &rest) || - skip_prefix(url, "https://", &rest)) { + if (skip_prefix(url, "http://", &rest) || skip_prefix(url, "https://", &rest)) { *module = xstrdup(url); forge = forge_for_host(rest, strcspn(rest, "/")); if (forge) { @@ -1284,8 +1236,7 @@ static void gitmodules_link(const char *path, const char *rev, rest = colon + 1; while (*rest == '/') rest++; - strbuf_addf(&sb, "https://%.*s/%s", - (int)(colon - host), host, rest); + strbuf_addf(&sb, "https://%.*s/%s", (int)(colon - host), host, rest); while (sb.len && sb.buf[sb.len - 1] == '/') strbuf_setlen(&sb, sb.len - 1); if (!forge->keep_dot_git) @@ -1322,8 +1273,7 @@ void cgit_submodule_link(const char *class, char *path, const char *rev) } } - if (!item && !ctx.repo->module_link && - ctx.repo->enable_gitmodules_links) + if (!item && !ctx.repo->module_link && ctx.repo->enable_gitmodules_links) gitmodules_link(path, rev, &module, &commit, &tooltip); // The row shows the entry's own name, like every other row, while @@ -1398,39 +1348,32 @@ void cgit_print_age(time_t t, int tz, time_t max_relative) if (secs < 0) secs = 0; - if (!ctx.cfg.enable_relative_dates || - (secs > max_relative && max_relative >= 0)) { + if (!ctx.cfg.enable_relative_dates || (secs > max_relative && max_relative >= 0)) { print_abs_date(t, tz); return; } if (secs < SECONDS_PER_HOUR * 2) { - print_rel_date(t, tz, secs * 1.0 / SECONDS_PER_MINUTE, - "age-mins", "min."); + print_rel_date(t, tz, secs * 1.0 / SECONDS_PER_MINUTE, "age-mins", "min."); return; } if (secs < SECONDS_PER_DAY * 2) { - print_rel_date(t, tz, secs * 1.0 / SECONDS_PER_HOUR, - "age-hours", "hours"); + print_rel_date(t, tz, secs * 1.0 / SECONDS_PER_HOUR, "age-hours", "hours"); return; } if (secs < SECONDS_PER_WEEK * 2) { - print_rel_date(t, tz, secs * 1.0 / SECONDS_PER_DAY, - "age-days", "days"); + print_rel_date(t, tz, secs * 1.0 / SECONDS_PER_DAY, "age-days", "days"); return; } if (secs < SECONDS_PER_MONTH * 2) { - print_rel_date(t, tz, secs * 1.0 / SECONDS_PER_WEEK, - "age-weeks", "weeks"); + print_rel_date(t, tz, secs * 1.0 / SECONDS_PER_WEEK, "age-weeks", "weeks"); return; } if (secs < SECONDS_PER_YEAR * 2) { - print_rel_date(t, tz, secs * 1.0 / SECONDS_PER_MONTH, - "age-months", "months"); + print_rel_date(t, tz, secs * 1.0 / SECONDS_PER_MONTH, "age-months", "months"); return; } - print_rel_date(t, tz, secs * 1.0 / SECONDS_PER_YEAR, - "age-years", "years"); + print_rel_date(t, tz, secs * 1.0 / SECONDS_PER_YEAR, "age-years", "years"); } void cgit_print_http_headers(void) @@ -1445,8 +1388,7 @@ void cgit_print_http_headers(void) else html("Status: 200 OK\n"); if (ctx.page.mimetype && ctx.page.charset) - htmlf("Content-Type: %s; charset=%s\n", ctx.page.mimetype, - ctx.page.charset); + htmlf("Content-Type: %s; charset=%s\n", ctx.page.mimetype, ctx.page.charset); else if (ctx.page.mimetype) htmlf("Content-Type: %s\n", ctx.page.mimetype); if (ctx.page.size) @@ -1475,8 +1417,7 @@ void cgit_print_http_headers(void) void cgit_redirect(const char *url, bool permanent) { - htmlf("Status: %d %s\n", permanent ? 301 : 302, - permanent ? "Moved Permanently" : "Found"); + htmlf("Status: %d %s\n", permanent ? 301 : 302, permanent ? "Moved Permanently" : "Found"); html("Location: "); html_url_path(url); html("\n\n"); @@ -1499,10 +1440,8 @@ void cgit_print_docstart(void) html("<meta charset='UTF-8'>\n"); html("<meta name='viewport' content='width=device-width, initial-scale=1'>\n"); html("<meta name='color-scheme' content='light dark'>\n"); - html("<meta name='theme-color' media='(prefers-color-scheme: light)'" - " content='#ffffff'>\n"); - html("<meta name='theme-color' media='(prefers-color-scheme: dark)'" - " content='#1b1b1b'>\n"); + html("<meta name='theme-color' media='(prefers-color-scheme: light)' content='#ffffff'>\n"); + html("<meta name='theme-color' media='(prefers-color-scheme: dark)' content='#1b1b1b'>\n"); html("<title>"); // An error page reached before a title was chosen still has to name // itself, since an empty title element is not valid. @@ -1514,8 +1453,7 @@ void cgit_print_docstart(void) html("</title>\n"); // The placeholder a scanned repository carries instead of a description // is left out, since it describes nothing. - if (ctx.repo && ctx.repo->desc && *ctx.repo->desc && - ctx.repo->desc != cgit_default_repo_desc) { + if (ctx.repo && ctx.repo->desc && *ctx.repo->desc && ctx.repo->desc != cgit_default_repo_desc) { html("<meta name='description' content='"); html_attr(ctx.repo->desc); html("'>\n"); @@ -1554,8 +1492,7 @@ void cgit_print_docstart(void) html("<link rel='alternate' title='Atom feed' href='"); html(cgit_httpscheme()); html_attr(host); - fileurl = cgit_fileurl(ctx.repo->url, "atom", ctx.qry.vpath, - sb.buf); + fileurl = cgit_fileurl(ctx.repo->url, "atom", ctx.qry.vpath, sb.buf); html_attr(fileurl); html("' type='application/atom+xml'>\n"); strbuf_release(&sb); @@ -1603,8 +1540,7 @@ void cgit_print_error_page(int code, const char *msg, const char *fmt, ...) va_end(ap); } -void cgit_vprint_error_page(int code, const char *msg, const char *fmt, - va_list ap) +void cgit_vprint_error_page(int code, const char *msg, const char *fmt, va_list ap) { // An error page describes a condition that may not outlast the slot // holding it. A request naming a commit not yet pushed would cache its @@ -1688,8 +1624,7 @@ void cgit_print_clone_row(const char *url, int colspan) free(fallback); } -void cgit_add_hidden_formfields(int incl_head, int incl_search, - const char *page) +void cgit_add_hidden_formfields(int incl_head, int incl_search, const char *page) { if (!ctx.cfg.virtual_root) { struct strbuf url = STRBUF_INIT; @@ -1701,8 +1636,7 @@ void cgit_add_hidden_formfields(int incl_head, int incl_search, strbuf_release(&url); } - if (incl_head && ctx.qry.head && ctx.repo->defbranch && - strcmp(ctx.qry.head, ctx.repo->defbranch)) + if (incl_head && ctx.qry.head && ctx.repo->defbranch && strcmp(ctx.qry.head, ctx.repo->defbranch)) html_hidden("h", ctx.qry.head); if (ctx.qry.oid) @@ -1734,8 +1668,7 @@ void cgit_print_pageheader(void) // Every other tab needs a commit to render and the search form // has nothing to search, so an empty repo gets summary alone. html("<ul>\n<li>"); - cgit_summary_link("summary", "Repository summary", - tab_class("summary"), ctx.qry.head); + cgit_summary_link("summary", "Repository summary", tab_class("summary"), ctx.qry.head); html("</li>\n</ul>\n"); } else if (ctx.env.authenticated && ctx.repo) { print_repo_tabs(); @@ -1749,8 +1682,7 @@ void cgit_print_pageheader(void) pinned = ctx.env.authenticated && ctx.repo ? pinned_oid() : NULL; // The commit and diff pages name the commit they show as their own // content, so the rev crumb would only repeat them. - if (pinned && ctx.qry.page && (!strcmp(ctx.qry.page, "commit") || - !strcmp(ctx.qry.page, "diff"))) + if (pinned && ctx.qry.page && (!strcmp(ctx.qry.page, "commit") || !strcmp(ctx.qry.page, "diff"))) pinned = NULL; if ((ctx.env.authenticated && ctx.repo && ctx.qry.vpath) || pinned) { html("<nav class='path' aria-label='"); @@ -1762,12 +1694,10 @@ void cgit_print_pageheader(void) // between them, so the run stays inline in a span. html("<span>path: "); print_path_crumbs(ctx.qry.vpath); - if (ctx.repo->enable_follow_links && - !strcmp(ctx.qry.page, "log")) { + if (ctx.repo->enable_follow_links && !strcmp(ctx.qry.page, "log")) { html(" ("); ctx.qry.follow = !ctx.qry.follow; - self_link(ctx.qry.follow ? "follow" : "unfollow", - NULL, NULL); + self_link(ctx.qry.follow ? "follow" : "unfollow", NULL, NULL); ctx.qry.follow = !ctx.qry.follow; html(")"); } @@ -1779,8 +1709,7 @@ void cgit_print_pageheader(void) html("<span class='rev'>rev: "); cgit_commit_link(cgit_fmt("%.*s", SHORT_HASH_LEN, hex), - NULL, NULL, ctx.qry.head, hex, - ctx.qry.vpath); + NULL, NULL, ctx.qry.head, hex, ctx.qry.vpath); html(" ("); // self_link reads the pin out of ctx.qry, so lifting // it is what makes the link land back on the tip of @@ -1812,8 +1741,7 @@ void cgit_print_filemode(unsigned short mode) html_fileperm(mode); } -static void compose_snapshot_prefix(struct strbuf *filename, const char *base, - const char *ref) +static void compose_snapshot_prefix(struct strbuf *filename, const char *base, const char *ref) { struct object_id oid; @@ -1831,8 +1759,7 @@ static void compose_snapshot_prefix(struct strbuf *filename, const char *base, strbuf_addf(filename, "%s-%s", base, ref); } -void cgit_print_snapshot_links(const struct cgit_repo *repo, const char *ref, - const char *separator) +void cgit_print_snapshot_links(const struct cgit_repo *repo, const char *ref, const char *separator) { const struct cgit_snapshot_format *f; struct strbuf filename = STRBUF_INIT; @@ -1851,25 +1778,20 @@ void cgit_print_snapshot_links(const struct cgit_repo *repo, const char *ref, continue; strbuf_setlen(&filename, prefixlen); strbuf_addstr(&filename, f->suffix); - snapshot_link(filename.buf, NULL, NULL, NULL, NULL, - filename.buf); + snapshot_link(filename.buf, NULL, NULL, NULL, NULL, filename.buf); if (cgit_snapshot_get_sig(ref, f)) { strbuf_addstr(&filename, ".asc"); html(" ("); - snapshot_link("sig", NULL, NULL, NULL, NULL, - filename.buf); + snapshot_link("sig", NULL, NULL, NULL, NULL, filename.buf); html(")"); - } else if (starts_with(f->suffix, ".tar") && - cgit_snapshot_get_sig(ref, &cgit_snapshot_formats[0])) { + } else if (starts_with(f->suffix, ".tar") && cgit_snapshot_get_sig(ref, &cgit_snapshot_formats[0])) { // A compressed tarball offers the signature made for // the plain tar it expands to, which is the first // format in the table. - strbuf_setlen(&filename, - filename.len - strlen(f->suffix)); + strbuf_setlen(&filename, filename.len - strlen(f->suffix)); strbuf_addstr(&filename, ".tar.asc"); html(" ("); - snapshot_link("sig", NULL, NULL, NULL, NULL, - filename.buf); + snapshot_link("sig", NULL, NULL, NULL, NULL, filename.buf); html(")"); } html(separator); diff --git a/source/ui-shared.h b/source/ui-shared.h index c421178..8a1a2b8 100644 --- a/source/ui-shared.h +++ b/source/ui-shared.h @@ -25,10 +25,9 @@ extern char *cgit_currentfullurl(void); extern const char *cgit_loginurl(void); extern char *cgit_repourl(const char *reponame); extern void cgit_print_clone_row(const char *url, int colspan); -extern char *cgit_fileurl(const char *reponame, const char *pagename, - const char *filename, const char *query); -extern char *cgit_pageurl(const char *reponame, const char *pagename, - const char *query); +extern char *cgit_fileurl(const char *reponame, const char *pagename, const char *filename, + const char *query); +extern char *cgit_pageurl(const char *reponame, const char *pagename, const char *query); // Call fn once for every URL this repository can be cloned from. extern void cgit_add_clone_urls(void (*fn)(const char *)); @@ -38,46 +37,32 @@ extern void cgit_add_clone_urls(void (*fn)(const char *)); * as the text a reader sees. A NULL title or class leaves that attribute out, * and what follows them is the state the target page should open in. */ -extern void cgit_index_link(const char *name, const char *title, - const char *class, const char *pattern, - const char *sort, int ofs, int always_root); -extern void cgit_summary_link(const char *name, const char *title, - const char *class, const char *head); -extern void cgit_tag_link(const char *name, const char *title, - const char *class, const char *tag); -extern void cgit_tree_link(const char *name, const char *title, - const char *class, const char *head, - const char *rev, const char *path); -extern void cgit_plain_link(const char *name, const char *title, - const char *class, const char *head, - const char *rev, const char *path); -extern void cgit_blame_link(const char *name, const char *title, - const char *class, const char *head, - const char *rev, const char *path); -extern void cgit_log_link(const char *name, const char *title, - const char *class, const char *head, const char *rev, - const char *path, int ofs, const char *grep, - const char *pattern, int showmsg, int follow); -extern void cgit_commit_link(const char *name, const char *title, - const char *class, const char *head, - const char *rev, const char *path); -extern void cgit_patch_link(const char *name, const char *title, - const char *class, const char *head, - const char *rev, const char *path); -extern void cgit_refs_link(const char *name, const char *title, - const char *class, const char *head, - const char *rev, const char *path); -extern void cgit_diff_link(const char *name, const char *title, - const char *class, const char *head, - const char *new_rev, const char *old_rev, - const char *path); -extern void cgit_stats_link(const char *name, const char *title, - const char *class, const char *head, - const char *path); +extern void cgit_index_link(const char *name, const char *title, const char *class, + const char *pattern, const char *sort, int ofs, int always_root); +extern void cgit_summary_link(const char *name, const char *title, const char *class, const char *head); +extern void cgit_tag_link(const char *name, const char *title, const char *class, const char *tag); +extern void cgit_tree_link(const char *name, const char *title, const char *class, + const char *head, const char *rev, const char *path); +extern void cgit_plain_link(const char *name, const char *title, const char *class, + const char *head, const char *rev, const char *path); +extern void cgit_blame_link(const char *name, const char *title, const char *class, + const char *head, const char *rev, const char *path); +extern void cgit_log_link(const char *name, const char *title, const char *class, + const char *head, const char *rev, const char *path, int ofs, const char *grep, + const char *pattern, int showmsg, int follow); +extern void cgit_commit_link(const char *name, const char *title, const char *class, + const char *head, const char *rev, const char *path); +extern void cgit_patch_link(const char *name, const char *title, const char *class, + const char *head, const char *rev, const char *path); +extern void cgit_refs_link(const char *name, const char *title, const char *class, + const char *head, const char *rev, const char *path); +extern void cgit_diff_link(const char *name, const char *title, const char *class, + const char *head, const char *new_rev, const char *old_rev, const char *path); +extern void cgit_stats_link(const char *name, const char *title, const char *class, + const char *head, const char *path); extern void cgit_object_link(struct object *obj); -extern void cgit_submodule_link(const char *class, char *path, - const char *rev); +extern void cgit_submodule_link(const char *class, char *path, const char *rev); extern void cgit_print_layout_start(void); extern void cgit_print_layout_end(void); @@ -98,14 +83,11 @@ extern void cgit_redirect(const char *url, bool permanent); extern void cgit_print_docstart(void); extern void cgit_print_docend(void); __attribute__((format (printf,3,4))) -extern void cgit_print_error_page(int code, const char *msg, const char *fmt, - ...); -extern void cgit_vprint_error_page(int code, const char *msg, const char *fmt, - va_list ap); +extern void cgit_print_error_page(int code, const char *msg, const char *fmt, ...); +extern void cgit_vprint_error_page(int code, const char *msg, const char *fmt, va_list ap); extern void cgit_print_pageheader(void); extern void cgit_print_filemode(unsigned short mode); -extern void cgit_print_snapshot_links(const struct cgit_repo *repo, - const char *ref, const char *separator); +extern void cgit_print_snapshot_links(const struct cgit_repo *repo, const char *ref, const char *separator); // The name a snapshot of this repository is downloaded under, which is the // configured prefix or the last component of the repository URL. @@ -117,8 +99,7 @@ extern const char *cgit_snapshot_prefix(const struct cgit_repo *repo); * terms are carried only when the caller asks for them, since a form with a * field of its own for either would otherwise submit that name twice. */ -extern void cgit_add_hidden_formfields(int incl_head, int incl_search, - const char *page); +extern void cgit_add_hidden_formfields(int incl_head, int incl_search, const char *page); // Put path in front of the page title, its last component first. extern void cgit_set_title_from_path(const char *path); diff --git a/source/ui-snapshot.c b/source/ui-snapshot.c index af985f4..a9bf858 100644 --- a/source/ui-snapshot.c +++ b/source/ui-snapshot.c @@ -20,8 +20,7 @@ #define SIG_SUFFIX ".asc" -static int write_archive_format(const char *format_arg, const char *hex, - const char *prefix) +static int write_archive_format(const char *format_arg, const char *hex, const char *prefix) { struct strvec argv = STRVEC_INIT; const char **args; @@ -62,8 +61,7 @@ static int write_zip_archive(const char *hex, const char *prefix) return write_archive_format("--format=zip", hex, prefix); } -static int write_compressed_tar_archive(const char *hex, const char *prefix, - char *argv[]) +static int write_compressed_tar_archive(const char *hex, const char *prefix, char *argv[]) { struct cgit_exec_filter filter; int result; @@ -147,9 +145,8 @@ static int resolves(const char *rev) return repo_get_oid(the_repository, rev, &oid) == 0; } -static const char *ref_from_filename(const struct cgit_repo *repo, - const char *filename, - const struct cgit_snapshot_format *format) +static const char *ref_from_filename(const struct cgit_repo *repo, const char *filename, + const struct cgit_snapshot_format *format) { struct strbuf rev = STRBUF_INIT; const char *repo_prefix; @@ -190,20 +187,17 @@ out: return found ? strbuf_detach(&rev, NULL) : NULL; } -static int send_snapshot(const struct cgit_snapshot_format *format, - const char *hex, const char *prefix, - const char *filename) +static int send_snapshot(const struct cgit_snapshot_format *format, const char *hex, + const char *prefix, const char *filename) { struct object_id oid; if (repo_get_oid(the_repository, hex, &oid)) { - cgit_print_error_page(404, "Not Found", - "Bad object id: %s", hex); + cgit_print_error_page(404, "Not Found", "Bad object id: %s", hex); return 1; } if (!lookup_commit_reference(the_repository, &oid)) { - cgit_print_error_page(400, "Bad Request", - "Not a commit reference: %s", hex); + cgit_print_error_page(400, "Bad Request", "Not a commit reference: %s", hex); return 1; } ctx.page.mimetype = xstrdup(format->mimetype); @@ -214,9 +208,8 @@ static int send_snapshot(const struct cgit_snapshot_format *format, return 0; } -static int send_sig(const struct cgit_snapshot_format *format, - const char *hex, const char *archive_name, - const char *sig_filename) +static int send_sig(const struct cgit_snapshot_format *format, const char *hex, + const char *archive_name, const char *sig_filename) { const struct object_id *note = cgit_snapshot_get_sig(hex, format); enum object_type type; @@ -224,8 +217,7 @@ static int send_sig(const struct cgit_snapshot_format *format, char *buf; if (!note) { - cgit_print_error_page(404, "Not Found", - "No signature for %s", archive_name); + cgit_print_error_page(404, "Not Found", "No signature for %s", archive_name); return 0; } @@ -245,8 +237,7 @@ static int send_sig(const struct cgit_snapshot_format *format, return 0; } -const struct object_id *cgit_snapshot_get_sig(const char *ref, - const struct cgit_snapshot_format *f) +const struct object_id *cgit_snapshot_get_sig(const char *ref, const struct cgit_snapshot_format *f) { struct notes_tree *tree; struct object_id oid; @@ -260,8 +251,7 @@ const struct object_id *cgit_snapshot_get_sig(const char *ref, // Signatures live under the format suffix with the leading dot // dropped, so plain tar is refs/notes/signatures/tar. - strbuf_addf(¬es_ref, "refs/notes/signatures/%s", - f->suffix + 1); + strbuf_addf(¬es_ref, "refs/notes/signatures/%s", f->suffix + 1); init_notes(tree, notes_ref.buf, combine_notes_ignore, 0); strbuf_release(¬es_ref); @@ -295,8 +285,7 @@ int cgit_parse_snapshots_mask(const char *str) for_each_string_list_item(item, &tokens) { for (f = cgit_snapshot_formats; f->suffix; f++) { - if (!strcmp(item->string, f->suffix) || - !strcmp(item->string, f->suffix + 1)) { + if (!strcmp(item->string, f->suffix) || !strcmp(item->string, f->suffix + 1)) { mask |= cgit_snapshot_format_bit(f); break; } @@ -307,8 +296,7 @@ int cgit_parse_snapshots_mask(const char *str) return mask; } -void cgit_print_snapshot(const char *head, const char *hex, - const char *filename, int dwim) +void cgit_print_snapshot(const char *head, const char *hex, const char *filename, int dwim) { const struct cgit_snapshot_format *f; const char *sig_filename = NULL; @@ -316,8 +304,7 @@ void cgit_print_snapshot(const char *head, const char *hex, char *prefix = NULL; if (!filename) { - cgit_print_error_page(400, "Bad Request", - "No snapshot name specified"); + cgit_print_error_page(400, "Bad Request", "No snapshot name specified"); return; } @@ -329,10 +316,8 @@ void cgit_print_snapshot(const char *head, const char *hex, } f = find_format(filename); - if (!f || (!sig_filename && - !(ctx.repo->snapshots & cgit_snapshot_format_bit(f)))) { - cgit_print_error_page(400, "Bad Request", - "Unsupported snapshot format: %s", filename); + if (!f || (!sig_filename && !(ctx.repo->snapshots & cgit_snapshot_format_bit(f)))) { + cgit_print_error_page(400, "Bad Request", "Unsupported snapshot format: %s", filename); return; } diff --git a/source/ui-snapshot.h b/source/ui-snapshot.h index 9d2910f..c594168 100644 --- a/source/ui-snapshot.h +++ b/source/ui-snapshot.h @@ -36,7 +36,6 @@ extern int cgit_parse_snapshots_mask(const char *str); extern const struct object_id *cgit_snapshot_get_sig( const char *ref, const struct cgit_snapshot_format *f); -extern void cgit_print_snapshot(const char *head, const char *hex, - const char *filename, int dwim); +extern void cgit_print_snapshot(const char *head, const char *hex, const char *filename, int dwim); #endif // CGIT_UI_SNAPSHOT_H diff --git a/source/ui-ssdiff.c b/source/ui-ssdiff.c index 759a77b..2ea4751 100644 --- a/source/ui-ssdiff.c +++ b/source/ui-ssdiff.c @@ -53,8 +53,7 @@ static void create_lcs_table(void) * owns. A line too long for the table gets NULL back and is shown whole * instead. */ -static char *longest_common_subsequence(const char *old_line, - const char *new_line) +static char *longest_common_subsequence(const char *old_line, const char *new_line) { int old_len = strlen(old_line); int new_len = strlen(new_line); @@ -76,8 +75,7 @@ static char *longest_common_subsequence(const char *old_line, int drop_old = lcs_table[i + 1][j]; int drop_new = lcs_table[i][j + 1]; - lcs_table[i][j] = (drop_old > drop_new ? - drop_old : drop_new); + lcs_table[i][j] = (drop_old > drop_new ? drop_old : drop_new); } } } @@ -116,8 +114,7 @@ static char *expand_tabs(const char *line) for (p = line; *p; p++) { if (*p == '\t') - strbuf_addchars(&out, ' ', - TAB_WIDTH - (out.len % TAB_WIDTH)); + strbuf_addchars(&out, ' ', TAB_WIDTH - (out.len % TAB_WIDTH)); else strbuf_addch(&out, *p); } @@ -136,8 +133,7 @@ static void flush_run(struct strbuf *run) * A stretch the other side does not share is escaped in one call, so a * changed line does not go through the output path a byte at a time. */ -static void print_line_with_lcs(const char *class, const char *line, - const char *lcs) +static void print_line_with_lcs(const char *class, const char *line, const char *lcs) { int len = strlen(line); int in_common = 1; @@ -168,8 +164,7 @@ static void print_line_with_lcs(const char *class, const char *line, strbuf_release(&run); } -static void print_lineno_cell(struct diff_filespec *file, - const struct object_id *rev, int line_no) +static void print_lineno_cell(struct diff_filespec *file, const struct object_id *rev, int line_no) { struct strbuf path = STRBUF_INIT; char *anchor, *query, *fileurl; @@ -191,10 +186,8 @@ static void print_lineno_cell(struct diff_filespec *file, strbuf_release(&path); } -static void print_row(const char *class, - int old_line_no, char *old_line, - int new_line_no, char *new_line, - int highlight_chars) +static void print_row(const char *class, int old_line_no, char *old_line, + int new_line_no, char *new_line, int highlight_chars) { char *lcs = NULL; @@ -207,8 +200,7 @@ static void print_row(const char *class, lcs = longest_common_subsequence(old_line, new_line); html("<tr>\n"); if (old_line_no > 0) { - print_lineno_cell(cgit_get_current_old_file(), old_rev_oid, - old_line_no); + print_lineno_cell(cgit_get_current_old_file(), old_rev_oid, old_line_no); htmlf("<td class='%s'>", class); } else if (old_line) htmlf("<td class='lineno'></td><td class='%s'>", class); @@ -223,8 +215,7 @@ static void print_row(const char *class, html("</td>\n"); if (new_line_no > 0) { - print_lineno_cell(cgit_get_current_new_file(), new_rev_oid, - new_line_no); + print_lineno_cell(cgit_get_current_new_file(), new_rev_oid, new_line_no); htmlf("<td class='%s'>", class); } else if (new_line) htmlf("<td class='lineno'></td><td class='%s'>", class); @@ -243,9 +234,8 @@ static void print_row(const char *class, free(old_line); } -static void defer_line(struct deferred_line **head, - struct deferred_line **last, - const char *line, int line_no) +static void defer_line(struct deferred_line **head, struct deferred_line **last, + const char *line, int line_no) { struct deferred_line *item = xmalloc(sizeof(*item)); @@ -321,15 +311,12 @@ static void print_deferred_changed_lines(void) highlight_chars = count_deferred(old_item) == count_deferred(new_item); while (old_item || new_item) { if (old_item && new_item) - print_row("changed", old_item->line_no, - old_item->line, new_item->line_no, - new_item->line, highlight_chars); + print_row("changed", old_item->line_no, old_item->line, + new_item->line_no, new_item->line, highlight_chars); else if (old_item) - print_row("changed", old_item->line_no, - old_item->line, -1, NULL, 0); + print_row("changed", old_item->line_no, old_item->line, -1, NULL, 0); else if (new_item) - print_row("changed", -1, NULL, - new_item->line_no, new_item->line, 0); + print_row("changed", -1, NULL, new_item->line_no, new_item->line, 0); if (old_item) { next = old_item->next; free_deferred(old_item); @@ -395,17 +382,14 @@ void cgit_ssdiff_line_cb(char *line, int len) if (line[0] == ' ') { print_deferred_lines(); - print_row("ctx", current_old_line, line, - current_new_line, line, 0); + print_row("ctx", current_old_line, line, current_new_line, line, 0); current_old_line += 1; current_new_line += 1; } else if (line[0] == '+') { - defer_line(&deferred_new, &deferred_new_last, line, - current_new_line); + defer_line(&deferred_new, &deferred_new_last, line, current_new_line); current_new_line += 1; } else if (line[0] == '-') { - defer_line(&deferred_old, &deferred_old_last, line, - current_old_line); + defer_line(&deferred_old, &deferred_old_last, line, current_old_line); current_old_line += 1; } else if (line[0] == '@') { html("<tr><td colspan='4' class='hunk'>"); diff --git a/source/ui-stats.c b/source/ui-stats.c index 62aac56..a04b189 100644 --- a/source/ui-stats.c +++ b/source/ui-stats.c @@ -168,7 +168,7 @@ static void window_start(const struct cgit_period *period, struct tm *tm) } static void add_commit(struct string_list *authors, struct commitinfo *info, - const struct cgit_period *period) + const struct cgit_period *period) { struct string_list_item *author, *bucket; struct authorstat *stats; @@ -296,11 +296,9 @@ static struct string_list build_period_labels(const struct cgit_period *period) * The run of authors to sum is given as a start and a count rather than as * two indices, so that an empty author list cannot describe a run that wraps. */ -static void print_summary_row(struct string_list *authors, size_t from, - size_t count, const char *label_format, - const char *leftclass, const char *centerclass, - const char *rightclass, - const struct string_list *labels) +static void print_summary_row(struct string_list *authors, size_t from, size_t count, + const char *label_format, const char *leftclass, const char *centerclass, + const char *rightclass, const struct string_list *labels) { struct authorstat *stats; struct string_list_item *bucket; @@ -308,8 +306,7 @@ static void print_summary_row(struct string_list *authors, size_t from, long total, subtotal; total = 0; - htmlf("<tr><td class='%s'>%s</td>", leftclass, - cgit_fmt(label_format, (long)count)); + htmlf("<tr><td class='%s'>%s</td>", leftclass, cgit_fmt(label_format, (long)count)); for (column = 0; column < labels->nr; column++) { const char *label = labels->items[column].string; @@ -326,8 +323,7 @@ static void print_summary_row(struct string_list *authors, size_t from, htmlf("<td class='%s'>%ld</td></tr>\n", rightclass, total); } -static void print_authors(struct string_list *authors, int max_rows, - const struct string_list *labels) +static void print_authors(struct string_list *authors, int max_rows, const struct string_list *labels) { struct string_list_item *author, *bucket; struct authorstat *stats; @@ -340,8 +336,7 @@ static void print_authors(struct string_list *authors, int max_rows, html("<th>Total</th></tr>\n"); // The row count arrives through ofs, which carries -1 for "all". - rows = (max_rows <= 0 || (size_t)max_rows > authors->nr) - ? authors->nr : (size_t)max_rows; + rows = (max_rows <= 0 || (size_t)max_rows > authors->nr) ? authors->nr : (size_t)max_rows; for (i = 0; i < rows; i++) { author = &authors->items[i]; @@ -365,11 +360,9 @@ static void print_authors(struct string_list *authors, int max_rows, } if (rows < authors->nr) - print_summary_row(authors, rows, authors->nr - rows, - "Others (%ld)", "left", "", "sum", labels); + print_summary_row(authors, rows, authors->nr - rows, "Others (%ld)", "left", "", "sum", labels); - print_summary_row(authors, 0, authors->nr, "Total", - "total", "sum", "sum", labels); + print_summary_row(authors, 0, authors->nr, "Total", "total", "sum", "sum", labels); html("</table>\n"); } @@ -387,9 +380,7 @@ static void print_options_form(const struct cgit_period *period, int top) html("<tr><td class='label'>Period:</td>"); html("<td class='ctrl'><select name='period'>"); for (i = 0; i < choices; i++) - html_option(cgit_fmt("%c", periods[i].code), - periods[i].name, - cgit_fmt("%c", period->code)); + html_option(cgit_fmt("%c", periods[i].code), periods[i].name, cgit_fmt("%c", period->code)); html("</select></td></tr>\n"); } html("<tr><td class='label'>Authors:</td>"); @@ -447,18 +438,15 @@ void cgit_show_stats(void) period_index = cgit_find_stats_period(code, &period); if (!period_index) { - cgit_print_error_page(404, "Not Found", - "Unknown statistics type: %c", code[0]); + cgit_print_error_page(404, "Not Found", "Unknown statistics type: %c", code[0]); return; } if (period_index > ctx.repo->max_stats) { - cgit_print_error_page(400, "Bad Request", - "Statistics type disabled: %s", period->name); + cgit_print_error_page(400, "Bad Request", "Statistics type disabled: %s", period->name); return; } authors = collect_stats(period); - qsort(authors.items, authors.nr, sizeof(struct string_list_item), - cmp_total_commits); + qsort(authors.items, authors.nr, sizeof(struct string_list_item), cmp_total_commits); top = ctx.qry.ofs; if (!top) diff --git a/source/ui-stats.h b/source/ui-stats.h index 1b20e6c..feee741 100644 --- a/source/ui-stats.h +++ b/source/ui-stats.h @@ -36,8 +36,7 @@ struct cgit_period { * table runs from the finest window to the coarsest, the index is what * max-stats is compared against. */ -extern int cgit_find_stats_period(const char *expr, - const struct cgit_period **period); +extern int cgit_find_stats_period(const char *expr, const struct cgit_period **period); // The name of the period at a one based index, or an empty string when the // index names no period. diff --git a/source/ui-summary.c b/source/ui-summary.c index 197cd07..ea8f783 100644 --- a/source/ui-summary.c +++ b/source/ui-summary.c @@ -59,8 +59,7 @@ static int path_within(const char *base, const char *path) { size_t len = strlen(base); - return starts_with(path, base) && - (path[len] == '\0' || path[len] == '/'); + return starts_with(path, base) && (path[len] == '\0' || path[len] == '/'); } /* @@ -69,8 +68,7 @@ static int path_within(const char *base, const char *path) * such a readme is confined to its own directory, so one named without a * directory is refused. */ -static char *resolve_about_path(const char *filename, const char *ref, - const char *path) +static char *resolve_about_path(const char *filename, const char *ref, const char *path) { char *copy, *base_dir, *full_path; char *resolved_base = NULL, *resolved_full = NULL; @@ -91,8 +89,7 @@ static char *resolve_about_path(const char *filename, const char *ref, if (!ref) { resolved_base = realpath(base_dir, NULL); resolved_full = realpath(full_path, NULL); - if (!resolved_base || !resolved_full || - !path_within(resolved_base, resolved_full)) { + if (!resolved_base || !resolved_full || !path_within(resolved_base, resolved_full)) { free(full_path); full_path = NULL; } @@ -116,8 +113,7 @@ void cgit_print_summary(void) cgit_print_tags(ctx.cfg.summary_tags); if (ctx.cfg.summary_log > 0) { htmlf("<tr class='nohover'><td colspan='%d'></td></tr>\n", columns); - cgit_print_log(ctx.qry.head, 0, ctx.cfg.summary_log, NULL, - NULL, NULL, 0, 0, 0); + cgit_print_log(ctx.qry.head, 0, ctx.cfg.summary_log, NULL, NULL, NULL, 0, 0, 0); } clone_urls_printed = 0; cgit_add_clone_urls(print_clone_url); @@ -131,8 +127,7 @@ void cgit_print_repo_readme(const char *path) int free_filename = 0; mimetype = cgit_get_mimetype_for_filename(path); - if (mimetype && (starts_with(mimetype, "image/") || - starts_with(mimetype, "video/"))) { + if (mimetype && (starts_with(mimetype, "image/") || starts_with(mimetype, "video/"))) { ctx.page.mimetype = mimetype; ctx.page.charset = NULL; cgit_print_plain(); diff --git a/source/ui-tag.c b/source/ui-tag.c index 469f209..ec8cd54 100644 --- a/source/ui-tag.c +++ b/source/ui-tag.c @@ -55,17 +55,14 @@ static void print_message(char *msg) } } -static void print_annotated_tag(const char *revname, - const struct object_id *oid) +static void print_annotated_tag(const char *revname, const struct object_id *oid) { struct tag *tag; struct taginfo *info; tag = lookup_tag(the_repository, oid); - if (!tag || parse_tag(the_repository, tag) || - !(info = cgit_parse_tag(tag))) { - cgit_print_error_page(500, "Internal Server Error", - "Bad tag object: %s", revname); + if (!tag || parse_tag(the_repository, tag) || !(info = cgit_parse_tag(tag))) { + cgit_print_error_page(500, "Internal Server Error", "Bad tag object: %s", revname); return; } @@ -76,20 +73,16 @@ static void print_annotated_tag(const char *revname, htmlf(" (<span class='oid'>%s</span>)</td></tr>\n", oid_to_hex(oid)); if (info->tagger_date > 0) { html("<tr><th>tag date</th><td><time datetime='"); - html_attr(show_date(info->tagger_date, info->tagger_tz, - cgit_date_mode(DATE_ISO8601_STRICT))); + html_attr(show_date(info->tagger_date, info->tagger_tz, cgit_date_mode(DATE_ISO8601_STRICT))); html("'>"); - html_txt(show_date(info->tagger_date, info->tagger_tz, - cgit_date_mode(DATE_ISO8601))); + html_txt(show_date(info->tagger_date, info->tagger_tz, cgit_date_mode(DATE_ISO8601))); html("</time></td></tr>\n"); } if (info->tagger) { html("<tr><th>tagged by</th><td>"); // A tag can carry a tagger with no address, and a filter must // not be handed a NULL argument. - cgit_open_filter(ctx.repo->email_filter, - info->tagger_email ? info->tagger_email : "", - "tag"); + cgit_open_filter(ctx.repo->email_filter, info->tagger_email ? info->tagger_email : "", "tag"); html_txt(info->tagger); if (info->tagger_email && ctx.cfg.enable_plain_email) { html(" "); @@ -132,14 +125,12 @@ void cgit_print_tag(char *revname) strbuf_addf(&fullref, "refs/tags/%s", revname); if (repo_get_oid(the_repository, fullref.buf, &oid)) { - cgit_print_error_page(404, "Not Found", - "Bad tag reference: %s", revname); + cgit_print_error_page(404, "Not Found", "Bad tag reference: %s", revname); goto cleanup; } obj = parse_object(the_repository, &oid); if (!obj) { - cgit_print_error_page(500, "Internal Server Error", - "Bad object id: %s", oid_to_hex(&oid)); + cgit_print_error_page(500, "Internal Server Error", "Bad object id: %s", oid_to_hex(&oid)); goto cleanup; } if (obj->type == OBJ_TAG) diff --git a/source/ui-tree.c b/source/ui-tree.c index 26a3fd1..aab448e 100644 --- a/source/ui-tree.c +++ b/source/ui-tree.c @@ -82,8 +82,7 @@ static void print_linenumbers(const char *buf, unsigned long size) strbuf_release(&numbers); } -static void print_text_buffer(const char *filename, char *buf, - unsigned long size) +static void print_text_buffer(const char *filename, char *buf, unsigned long size) { html("<table class='blob'>\n"); @@ -131,8 +130,7 @@ static void print_binary_buffer(char *buf, unsigned long size) html("<tr><th>ofs</th><th>hex dump</th><th>ascii</th></tr>\n"); // A row goes out in one write rather than a write per byte. - for (offset = 0; offset < size; - offset += HEXDUMP_ROW_BYTES, buf += HEXDUMP_ROW_BYTES) { + for (offset = 0; offset < size; offset += HEXDUMP_ROW_BYTES, buf += HEXDUMP_ROW_BYTES) { strbuf_reset(&row); strbuf_addf(&row, "<tr><td class='right'>%04lx</td><td class='hex'>", offset); for (idx = 0; idx < HEXDUMP_ROW_BYTES && offset + idx < size; idx++) { @@ -159,7 +157,7 @@ static void print_binary_buffer(char *buf, unsigned long size) * may be added to it. */ static bool print_object(const struct object_id *oid, const char *path, - const char *filename, const char *rev) + const char *filename, const char *rev) { enum object_type type; char *buf; @@ -168,22 +166,21 @@ static bool print_object(const struct object_id *oid, const char *path, type = odb_read_object_info(the_repository->objects, oid, &size); if (type == OBJ_BAD) { - cgit_print_error_page(404, "Not Found", - "Bad object name: %s", oid_to_hex(oid)); + cgit_print_error_page(404, "Not Found", "Bad object name: %s", oid_to_hex(oid)); return false; } if (ctx.cfg.max_blob_size && size / 1024 > (unsigned long)ctx.cfg.max_blob_size) { - cgit_print_error_page(413, "Content Too Large", - "blob size (%luKB) exceeds display size limit (%dKB)", - size / 1024, ctx.cfg.max_blob_size); + cgit_print_error_page( + 413, "Content Too Large", "blob size (%luKB) exceeds display size limit (%dKB)", + size / 1024, ctx.cfg.max_blob_size + ); return false; } buf = odb_read_object(the_repository->objects, oid, &type, &size); if (!buf) { - cgit_print_error_page(500, "Internal Server Error", - "Error reading object %s", oid_to_hex(oid)); + cgit_print_error_page(500, "Internal Server Error", "Error reading object %s", oid_to_hex(oid)); return false; } // buffer_is_binary only sniffs the front of the blob, and a NUL past @@ -195,12 +192,10 @@ static bool print_object(const struct object_id *oid, const char *path, cgit_print_layout_start(); htmlf("blob: %s (", oid_to_hex(oid)); - cgit_plain_link("plain", NULL, NULL, ctx.qry.head, - rev, path); + cgit_plain_link("plain", NULL, NULL, ctx.qry.head, rev, path); if (ctx.repo->enable_blame && !is_binary) { html(") ("); - cgit_blame_link("blame", NULL, NULL, ctx.qry.head, - rev, path); + cgit_blame_link("blame", NULL, NULL, ctx.qry.head, rev, path); } html(")\n"); @@ -214,7 +209,7 @@ static bool print_object(const struct object_id *oid, const char *path, } static int only_child_cb(const struct object_id *oid, struct strbuf *base, - const char *pathname, unsigned mode, void *data) + const char *pathname, unsigned mode, void *data) { struct only_child *child = data; @@ -232,8 +227,8 @@ static int only_child_cb(const struct object_id *oid, struct strbuf *base, return 0; } -static void print_dir_chain(const struct object_id *oid, char *name, - char *rev, struct strbuf *fullpath) +static void print_dir_chain(const struct object_id *oid, char *name, char *rev, + struct strbuf *fullpath) { size_t initial_length = fullpath->len; struct tree *tree; @@ -248,8 +243,7 @@ static void print_dir_chain(const struct object_id *oid, char *name, oidcpy(&child.oid, oid); while (child.count == 1) { - cgit_tree_link(name, NULL, "ls-dir", ctx.qry.head, rev, - fullpath->buf); + cgit_tree_link(name, NULL, "ls-dir", ctx.qry.head, rev, fullpath->buf); tree = lookup_tree(the_repository, &child.oid); if (!tree) @@ -272,7 +266,7 @@ static void print_dir_chain(const struct object_id *oid, char *name, } static void print_ls_row(const struct object_id *oid, const char *pathname, - unsigned mode, struct walk_tree_context *walk) + unsigned mode, struct walk_tree_context *walk) { char *name; struct strbuf fullpath = STRBUF_INIT; @@ -283,8 +277,7 @@ static void print_ls_row(const struct object_id *oid, const char *pathname, char *buf; name = xstrdup(pathname); - strbuf_addf(&fullpath, "%s%s%s", ctx.qry.path ? ctx.qry.path : "", - ctx.qry.path ? "/" : "", name); + strbuf_addf(&fullpath, "%s%s%s", ctx.qry.path ? ctx.qry.path : "", ctx.qry.path ? "/" : "", name); if (!S_ISGITLINK(mode)) { type = odb_read_object_info(the_repository->objects, oid, &size); @@ -310,8 +303,7 @@ static void print_ls_row(const struct object_id *oid, const char *pathname, strbuf_addstr(&class, "ls-blob"); if (ext) strbuf_addf(&class, " %s", ext + 1); - cgit_tree_link(name, NULL, class.buf, ctx.qry.head, - walk->rev, fullpath.buf); + cgit_tree_link(name, NULL, class.buf, ctx.qry.head, walk->rev, fullpath.buf); } if (S_ISLNK(mode)) { html(" -> "); @@ -323,8 +315,7 @@ static void print_ls_row(const struct object_id *oid, const char *pathname, strbuf_addbuf(&linkpath, &fullpath); strbuf_addf(&linkpath, "/../%s", buf); strbuf_normalize_path(&linkpath); - cgit_tree_link(buf, NULL, class.buf, ctx.qry.head, - walk->rev, linkpath.buf); + cgit_tree_link(buf, NULL, class.buf, ctx.qry.head, walk->rev, linkpath.buf); free(buf); strbuf_release(&linkpath); } @@ -334,18 +325,14 @@ static void print_ls_row(const struct object_id *oid, const char *pathname, htmlf("</td><td class='ls-size'>%lu</td>", size); html("<td class='ls-links'>"); - cgit_log_link("log", NULL, "button", ctx.qry.head, - walk->rev, fullpath.buf, 0, NULL, NULL, - ctx.qry.showmsg, 0); + cgit_log_link("log", NULL, "button", ctx.qry.head, walk->rev, fullpath.buf, + 0, NULL, NULL, ctx.qry.showmsg, 0); if (ctx.repo->max_stats) - cgit_stats_link("stats", NULL, "button", ctx.qry.head, - fullpath.buf); + cgit_stats_link("stats", NULL, "button", ctx.qry.head, fullpath.buf); if (!S_ISGITLINK(mode)) - cgit_plain_link("plain", NULL, "button", ctx.qry.head, - walk->rev, fullpath.buf); + cgit_plain_link("plain", NULL, "button", ctx.qry.head, walk->rev, fullpath.buf); if (!S_ISDIR(mode) && !S_ISGITLINK(mode) && ctx.repo->enable_blame) - cgit_blame_link("blame", NULL, "button", ctx.qry.head, - walk->rev, fullpath.buf); + cgit_blame_link("blame", NULL, "button", ctx.qry.head, walk->rev, fullpath.buf); html("</td></tr>\n"); cleanup: @@ -355,7 +342,7 @@ cleanup: } static int ls_item(const struct object_id *oid, struct strbuf *base, - const char *pathname, unsigned mode, void *data) + const char *pathname, unsigned mode, void *data) { struct walk_tree_context *walk = data; @@ -364,8 +351,7 @@ static int ls_item(const struct object_id *oid, struct strbuf *base, if (ctx.cfg.enable_tree_group_dirs) { struct ls_entry *entry; - ALLOC_GROW(walk->entries, walk->entries_nr + 1, - walk->entries_alloc); + ALLOC_GROW(walk->entries, walk->entries_nr + 1, walk->entries_alloc); entry = &walk->entries[walk->entries_nr++]; oidcpy(&entry->oid, oid); entry->name = xstrdup(pathname); @@ -419,8 +405,7 @@ static void ls_tail(void) cgit_print_layout_end(); } -static void ls_tree(const struct object_id *oid, - struct walk_tree_context *walk) +static void ls_tree(const struct object_id *oid, struct walk_tree_context *walk) { struct tree *tree; struct pathspec paths = { @@ -429,8 +414,7 @@ static void ls_tree(const struct object_id *oid, tree = parse_tree_indirect(oid); if (!tree) { - cgit_print_error_page(404, "Not Found", - "Not a tree object: %s", oid_to_hex(oid)); + cgit_print_error_page(404, "Not Found", "Not a tree object: %s", oid_to_hex(oid)); return; } @@ -441,7 +425,7 @@ static void ls_tree(const struct object_id *oid, } static int walk_tree(const struct object_id *oid, struct strbuf *base, - const char *pathname, unsigned mode, void *data) + const char *pathname, unsigned mode, void *data) { struct walk_tree_context *walk = data; @@ -460,8 +444,7 @@ static int walk_tree(const struct object_id *oid, struct strbuf *base, ls_head(); return READ_TREE_RECURSIVE; } else { - bool shown = print_object(oid, fullpath.buf, - pathname, walk->rev); + bool shown = print_object(oid, fullpath.buf, pathname, walk->rev); walk->state = shown ? WALK_BLOB_SHOWN : WALK_ERROR_SHOWN; strbuf_release(&fullpath); @@ -499,14 +482,12 @@ void cgit_print_tree(const char *rev, char *path) rev = ctx.qry.head; if (repo_get_oid(the_repository, rev, &oid)) { - cgit_print_error_page(404, "Not Found", - "Invalid revision name: %s", rev); + cgit_print_error_page(404, "Not Found", "Invalid revision name: %s", rev); return; } commit = lookup_commit_reference(the_repository, &oid); if (!commit || repo_parse_commit(the_repository, commit)) { - cgit_print_error_page(404, "Not Found", - "Invalid commit reference: %s", rev); + cgit_print_error_page(404, "Not Found", "Invalid commit reference: %s", rev); return; } @@ -517,8 +498,7 @@ void cgit_print_tree(const char *rev, char *path) goto cleanup; } - read_tree(the_repository, repo_get_commit_tree(the_repository, commit), - &paths, walk_tree, &walk); + read_tree(the_repository, repo_get_commit_tree(the_repository, commit), &paths, walk_tree, &walk); if (walk.state == WALK_LISTING) { ls_flush(&walk); ls_tail(); diff --git a/tests/extensions/harness.lua b/tests/extensions/harness.lua index d0299e3..d9318ee 100644 --- a/tests/extensions/harness.lua +++ b/tests/extensions/harness.lua @@ -198,8 +198,7 @@ function harness.stub_auth_modules() new = function(key, algorithm) return { final = function(self, payload) - return fake_digest_bytes(key .. "\1" .. - algorithm .. "\1" .. payload) + return fake_digest_bytes(key .. "\1" .. algorithm .. "\1" .. payload) end, } end, @@ -227,26 +226,21 @@ end function harness.equals(name, got, want) checks = checks + 1 if got ~= want then - fail(name, "wanted " .. tostring(want) .. - "\n got " .. tostring(got)) + fail(name, "wanted " .. tostring(want) .. "\n got " .. tostring(got)) end end function harness.contains(name, haystack, needle) checks = checks + 1 - if type(haystack) ~= "string" - or not haystack:find(needle, 1, true) then - fail(name, "wanted " .. needle .. - "\nwithin " .. tostring(haystack)) + if type(haystack) ~= "string" or not haystack:find(needle, 1, true) then + fail(name, "wanted " .. needle .. "\nwithin " .. tostring(haystack)) end end function harness.excludes(name, haystack, needle) checks = checks + 1 - if type(haystack) ~= "string" - or haystack:find(needle, 1, true) then - fail(name, "did not want " .. needle .. - "\nwithin " .. tostring(haystack)) + if type(haystack) ~= "string" or haystack:find(needle, 1, true) then + fail(name, "did not want " .. needle .. "\nwithin " .. tostring(haystack)) end end diff --git a/tests/extensions/lib.sh b/tests/extensions/lib.sh index f472faf..26fcbec 100644 --- a/tests/extensions/lib.sh +++ b/tests/extensions/lib.sh @@ -64,6 +64,5 @@ repo.url=lua-probe repo.path=$cgit_lua_probe_gitdir repo.commit-filter=lua:$PWD/lua-probe.lua EOF - CGIT_CONFIG="$PWD/lua-probe-cgitrc" QUERY_STRING="url=lua-probe/commit/" \ - cgit | grep -q LUA_PROBE_YES + CGIT_CONFIG="$PWD/lua-probe-cgitrc" QUERY_STRING="url=lua-probe/commit/" cgit | grep -q LUA_PROBE_YES } diff --git a/tests/extensions/test-about-render.lua b/tests/extensions/test-about-render.lua index aa7e6ad..338949a 100644 --- a/tests/extensions/test-about-render.lua +++ b/tests/extensions/test-about-render.lua @@ -37,8 +37,7 @@ h.contains("no extension renders as plain text", out, h.equals("close answers zero", ret, 0) out = render("notes.txt", "just text") -h.contains("an unknown extension renders as plain text", out, - "<pre class='plaintext'>just text</pre>") +h.contains("an unknown extension renders as plain text", out, "<pre class='plaintext'>just text</pre>") out = render(nil, "no name at all") h.contains("a missing filename renders as plain text", out, @@ -56,11 +55,9 @@ h.contains("writes are joined before rendering", out, "two writes") if mode == "nolpeg" then out = render("README.md", "# Title") - h.contains("markdown without lpeg falls back to plain text", out, - "<pre class='plaintext'># Title</pre>") + h.contains("markdown without lpeg falls back to plain text", out, "<pre class='plaintext'># Title</pre>") out = render("page.1", ".SH NAME") - h.contains("man without lpeg falls back to plain text", out, - "<pre class='plaintext'>.SH NAME</pre>") + h.contains("man without lpeg falls back to plain text", out, "<pre class='plaintext'>.SH NAME</pre>") h.finish() end @@ -71,27 +68,22 @@ end -- Markdown. out = render("README.md", "# Title") -h.contains("a heading renders inside the wrapper", - out, "<div class='markdown'><h1>Title</h1></div>") +h.contains("a heading renders inside the wrapper", out, "<div class='markdown'><h1>Title</h1></div>") out = render("README.md", "## Sub ##") -h.contains("trailing hashes are stripped from a heading", out, - "<h2>Sub</h2>") +h.contains("trailing hashes are stripped from a heading", out, "<h2>Sub</h2>") out = render("README.MD", "# Upper") h.contains("the extension matches whatever its case", out, "<h1>Upper</h1>") out = render("readme.markdown", "# Long") -h.contains("the long markdown extension dispatches too", out, - "<h1>Long</h1>") +h.contains("the long markdown extension dispatches too", out, "<h1>Long</h1>") out = render("README.md", "line one\nline two") -h.contains("a paragraph keeps its line break", out, - "<p>line one<br>line two</p>") +h.contains("a paragraph keeps its line break", out, "<p>line one<br>line two</p>") out = render("README.md", "first para\r\nsecond line") -h.contains("crlf line endings are normalised", out, - "<p>first para<br>second line</p>") +h.contains("crlf line endings are normalised", out, "<p>first para<br>second line</p>") out = render("README.md", "a **bold** and *leaning* word") h.contains("double stars embolden", out, "<strong>bold</strong>") @@ -105,21 +97,17 @@ out = render("README.md", "run `x < y` here") h.contains("inline code is escaped", out, "<code>x < y</code>") out = render("README.md", "raw <script>alert(1)</script> here") -h.contains("markup in text reaches the page escaped", out, - "<script>alert(1)</script>") +h.contains("markup in text reaches the page escaped", out, "<script>alert(1)</script>") h.excludes("no live tag slips through", out, "<script>") out = render("README.md", "[docs](https://example.com/docs)") -h.contains("an https link renders as an anchor", out, - "<a href='https://example.com/docs'>docs</a>") +h.contains("an https link renders as an anchor", out, "<a href='https://example.com/docs'>docs</a>") out = render("README.md", "[docs](docs/page.html)") -h.contains("a relative link renders as an anchor", out, - "<a href='docs/page.html'>docs</a>") +h.contains("a relative link renders as an anchor", out, "<a href='docs/page.html'>docs</a>") out = render("README.md", "[mail](mailto:a@example.com)") -h.contains("a mailto link renders as an anchor", out, - "<a href='mailto:a@example.com'>mail</a>") +h.contains("a mailto link renders as an anchor", out, "<a href='mailto:a@example.com'>mail</a>") out = render("README.md", "[bad](javascript:alert(1))") h.excludes("a javascript link renders no anchor", out, "<a ") @@ -132,8 +120,7 @@ out = render("README.md", "[bad](//evil.example/x)") h.excludes("a scheme relative link renders no anchor", out, "<a ") out = render("README.md", "[q](https://example.com/a'b)") -h.contains("a quote in a link target is escaped", out, - "href='https://example.com/a'b'") +h.contains("a quote in a link target is escaped", out, "href='https://example.com/a'b'") out = render("README.md", "") h.contains("an image renders with its alt text escaped", out, @@ -149,8 +136,7 @@ h.contains("a fenced block carries its language", out, h.contains("text after the fence renders on", out, "<p>after</p>") out = render("README.md", "~~~\n**not bold**\n~~~") -h.contains("no inline parsing happens inside a fence", out, - "<code>**not bold**\n</code>") +h.contains("no inline parsing happens inside a fence", out, "<code>**not bold**\n</code>") out = render("README.md", "---") h.contains("a rule of dashes renders a break", out, "<hr>") @@ -159,12 +145,10 @@ out = render("README.md", "- - -") h.contains("a spaced rule renders a break too", out, "<hr>") out = render("README.md", "> quoted words") -h.contains("a quote renders as a blockquote", out, - "<blockquote><p>quoted words</p></blockquote>") +h.contains("a quote renders as a blockquote", out, "<blockquote><p>quoted words</p></blockquote>") out = render("README.md", "> > deep") -h.contains("quotes nest", out, - "<blockquote><blockquote><p>deep</p></blockquote></blockquote>") +h.contains("quotes nest", out, "<blockquote><blockquote><p>deep</p></blockquote></blockquote>") -- A hostile readme of stacked markers has to hit the depth ceiling instead -- of the interpreter's stack. @@ -177,60 +161,49 @@ out = render("README.md", string.rep("*a", 200)) h.check("an emphasis bomb still renders something", #out > 0) out = render("README.md", "| a | b |\n| --- | --- |\n| 1 | 2 |") -h.contains("a pipe table renders its head", - out, "<thead><tr><th>a</th><th>b</th></tr></thead>") -h.contains("a pipe table renders its body", - out, "<tbody><tr><td>1</td><td>2</td></tr></tbody>") +h.contains("a pipe table renders its head", out, "<thead><tr><th>a</th><th>b</th></tr></thead>") +h.contains("a pipe table renders its body", out, "<tbody><tr><td>1</td><td>2</td></tr></tbody>") out = render("README.md", "a | b in prose") h.excludes("a pipe without a delimiter row stays prose", out, "<table") out = render("README.md", "- first\n- second") -h.contains("dashes render an unordered list", out, - "<ul><li>first</li><li>second</li></ul>") +h.contains("dashes render an unordered list", out, "<ul><li>first</li><li>second</li></ul>") out = render("README.md", "1. first\n2. second") -h.contains("numbers render an ordered list", out, - "<ol><li>first</li><li>second</li></ol>") +h.contains("numbers render an ordered list", out, "<ol><li>first</li><li>second</li></ol>") out = render("README.md", "- plain\n1. numbered") h.contains("a change of marker splits the list", out, "</ul><ol>") out = render("README.md", "- a **bold** item") -h.contains("list items parse their text", out, - "<li>a <strong>bold</strong> item</li>") +h.contains("list items parse their text", out, "<li>a <strong>bold</strong> item</li>") out = render("README.md", string.rep("a", 512 * 1024 + 1)) -h.contains("an oversized readme renders as plain text", out, - "<pre class='plaintext'>") +h.contains("an oversized readme renders as plain text", out, "<pre class='plaintext'>") -- Man pages. out = render("page.1", ".SH NAME") -h.contains("a section heading renders", out, - "<div class='markdown manpage'><h2>NAME</h2></div>") +h.contains("a section heading renders", out, "<div class='markdown manpage'><h2>NAME</h2></div>") out = render("page.man", '.SH "TWO WORDS"') -h.contains("a quoted heading argument is unquoted", out, - "<h2>TWO WORDS</h2>") +h.contains("a quoted heading argument is unquoted", out, "<h2>TWO WORDS</h2>") out = render("page.3", ".SS Details") h.contains("a subsection renders one level down", out, "<h3>Details</h3>") out = render("page.1", ".B bold words\nplain after") -h.contains("the bold macro renders strong", out, - "<p><strong>bold words</strong><br>plain after</p>") +h.contains("the bold macro renders strong", out, "<p><strong>bold words</strong><br>plain after</p>") out = render("page.1", "a \\fBbold\\fR c") -h.contains("font escapes carry across a run", out, - "<p>a <strong>bold</strong> c</p>") +h.contains("font escapes carry across a run", out, "<p>a <strong>bold</strong> c</p>") out = render("page.1", "x \\(em y \\- z") h.contains("character escapes are translated", out, "<p>x - y - z</p>") out = render("page.1", ".nf\ncode <x>\n.fi\nafter") -h.contains("a no fill block renders as code", out, - "<pre><code>code <x>\n</code></pre>") +h.contains("a no fill block renders as code", out, "<pre><code>code <x>\n</code></pre>") h.contains("filling resumes after it", out, "<p>after</p>") out = render("page.1", '.\\" a comment\nvisible') @@ -238,8 +211,7 @@ h.excludes("a roff comment is dropped", out, "comment") h.contains("the line after it renders", out, "visible") out = render("page.1", "first\n\nsecond") -h.contains("a blank line splits paragraphs", out, - "<p>first</p><p>second</p>") +h.contains("a blank line splits paragraphs", out, "<p>first</p><p>second</p>") out = render("page.1", ".TH title 1\nbody") h.excludes("the title macro renders nothing itself", out, "title 1") diff --git a/tests/extensions/test-auth.lua b/tests/extensions/test-auth.lua index 359f52e..e9fed78 100644 --- a/tests/extensions/test-auth.lua +++ b/tests/extensions/test-auth.lua @@ -79,16 +79,14 @@ local userset = repo_userset("secret-repo") h.check("a protected repository lists its users", userset ~= nil and userset.alice and userset.bob) h.equals("an unlisted repository is public", repo_userset("unlisted"), nil) -h.equals("the repository name matches case exactly", - repo_userset("Secret-Repo"), nil) +h.equals("the repository name matches case exactly", repo_userset("Secret-Repo"), nil) local empty = repo_userset("empty-repo") h.check("a protected repository with no members denies as an empty set", empty ~= nil and next(empty) == nil) if variant == "file" then h.redirect_file("/etc/cgit-auth/users", "auth-users-missing") - h.equals("a missing users file turns every login down", - account_hash("alice"), nil) + h.equals("a missing users file turns every login down", account_hash("alice"), nil) h.redirect_file("/etc/cgit-auth/users", "auth-users") end @@ -106,13 +104,10 @@ h.equals("a value is decoded", params.x, "A") h.equals("a cookie is found among others", get_cookie("foo=1; cgitauth=abc; bar=2", "cgitauth"), "abc") -h.equals("a lone cookie is found", get_cookie("cgitauth=abc", "cgitauth"), - "abc") +h.equals("a lone cookie is found", get_cookie("cgitauth=abc", "cgitauth"), "abc") h.equals("no header yields no cookie", get_cookie(nil, "cgitauth"), nil) -h.equals("a longer name does not match", - get_cookie("xcgitauth=z", "cgitauth"), nil) -h.equals("a magic character in the name is taken literally", - get_cookie("a-b=z", "a-b"), "z") +h.equals("a longer name does not match", get_cookie("xcgitauth=z", "cgitauth"), nil) +h.equals("a magic character in the name is taken literally", get_cookie("a-b=z", "a-b"), "z") h.check("equal strings compare equal", constant_equals("abc", "abc")) h.check("differing strings do not", not constant_equals("abc", "abd")) @@ -124,53 +119,42 @@ h.check("a scheme relative target is not", not is_safe_redirect("//evil")) h.check("a backslash variant is not", not is_safe_redirect("/\\evil")) h.check("a missing target is not", not is_safe_redirect(nil)) -h.equals("control characters are stripped from header values", - strip_controls("a\r\nb"), "ab") +h.equals("control characters are stripped from header values", strip_controls("a\r\nb"), "ab") -- Signing and verification. local now = os.time() local cookie = secure_value("username", "alice", now + 3600) -h.equals("a signed value verifies and comes back", - validate_value("username", cookie), "alice") +h.equals("a signed value verifies and comes back", validate_value("username", cookie), "alice") cookie = secure_value("username", "a|b", now + 3600) -h.equals("a value holding the separator survives the round trip", - validate_value("username", cookie), "a|b") +h.equals("a value holding the separator survives the round trip", validate_value("username", cookie), "a|b") cookie = secure_value("username", "a\nb", now + 3600) h.equals("a signed control character is still rejected on the way out", validate_value("username", cookie), nil) cookie = secure_value("redirect", "/repo/?a=b", 0) -h.equals("an expiration of zero never expires", - validate_value("redirect", cookie), "/repo/?a=b") +h.equals("an expiration of zero never expires", validate_value("redirect", cookie), "/repo/?a=b") cookie = secure_value("username", "alice", now - 10) -h.equals("an expired value is rejected", - validate_value("username", cookie), nil) +h.equals("an expired value is rejected", validate_value("username", cookie), nil) cookie = secure_value("username", "alice", now + 3600) -local flipped = cookie:sub(1, -2) .. - (cookie:sub(-1) == "0" and "1" or "0") -h.equals("a tampered signature is rejected", - validate_value("username", flipped), nil) +local flipped = cookie:sub(1, -2) .. (cookie:sub(-1) == "0" and "1" or "0") +h.equals("a tampered signature is rejected", validate_value("username", flipped), nil) -h.equals("a value signed for one field does not serve another", - validate_value("redirect", cookie), nil) +h.equals("a value signed for one field does not serve another", validate_value("redirect", cookie), nil) h.equals("no cookie does not verify", validate_value("username", nil), nil) -h.equals("a tiny cookie does not verify", validate_value("username", "ab"), - nil) -h.equals("a leading separator does not verify", - validate_value("username", "|x|1|s|sig"), nil) +h.equals("a tiny cookie does not verify", validate_value("username", "ab"), nil) +h.equals("a leading separator does not verify", validate_value("username", "|x|1|s|sig"), nil) h.equals("an unsigned cookie does not verify", validate_value("username", "username|alice|123|salt"), nil) h.equals("an exponent spelling of the expiry does not verify", validate_value("username", "username|alice|1e9|salt|beef"), nil) -h.equals("an empty value signs to nothing", secure_value("username", "", 1), - "") +h.equals("an empty value signs to nothing", secure_value("username", "", 1), "") -- The headers the filter writes itself. @@ -220,34 +204,27 @@ out, ret = run_action("authenticate-cookie", { repo = "secret-repo" }) h.equals("a protected repository turns a bare request away", ret, 0) local session = secure_value("username", "Alice", now + 3600) -out, ret = run_action("authenticate-cookie", - { repo = "secret-repo", cookie = "cgitauth=" .. session }) +out, ret = run_action("authenticate-cookie", { repo = "secret-repo", cookie = "cgitauth=" .. session }) h.equals("a signed session for a member is let through", ret, 1) -out, ret = run_action("authenticate-cookie", - { repo = "empty-repo", cookie = "cgitauth=" .. session }) +out, ret = run_action("authenticate-cookie", { repo = "empty-repo", cookie = "cgitauth=" .. session }) h.equals("a memberless repository denies even a valid session", ret, 0) local outsider = secure_value("username", "carol", now + 3600) -out, ret = run_action("authenticate-cookie", - { repo = "secret-repo", cookie = "cgitauth=" .. outsider }) +out, ret = run_action("authenticate-cookie", { repo = "secret-repo", cookie = "cgitauth=" .. outsider }) h.equals("a signed session for an outsider is turned away", ret, 0) -local forged = session:sub(1, -2) .. - (session:sub(-1) == "0" and "1" or "0") -out, ret = run_action("authenticate-cookie", - { repo = "secret-repo", cookie = "cgitauth=" .. forged }) +local forged = session:sub(1, -2) .. (session:sub(-1) == "0" and "1" or "0") +out, ret = run_action("authenticate-cookie", { repo = "secret-repo", cookie = "cgitauth=" .. forged }) h.equals("a forged session is turned away", ret, 0) out, ret = run_action("no-such-action", {}) h.equals("an unknown action denies rather than raising", ret, 0) out, ret = run_action("body", { url = "/repo/log/?q=x" }) -h.contains("the login form posts to the login url", out, - "<form method='post' action='/?p=login'>") +h.contains("the login form posts to the login url", out, "<form method='post' action='/?p=login'>") local token = out:match("name='redirect' value='([^']*)'") -h.equals("the form carries a signed way back", - token and validate_value("redirect", token), "/repo/log/?q=x") +h.equals("the form carries a signed way back", token and validate_value("redirect", token), "/repo/log/?q=x") out, ret = run_action("body", { url = "//evil.example/x" }) token = out:match("name='redirect' value='([^']*)'") @@ -258,45 +235,37 @@ local way_back = secure_value("redirect", "/repo/", 0) out, ret = run_action("authenticate-post", { method = "POST", - body = "username=Alice&password=" .. url_encode(password) .. - "&redirect=" .. url_encode(way_back), + body = "username=Alice&password=" .. url_encode(password) .. "&redirect=" .. url_encode(way_back), }) h.contains("a good login redirects back", out, "Status: 302") h.contains("to where the form said", out, "Location: /repo/\n") local granted = out:match("Set%-Cookie: cgitauth=([^;]*);") -h.equals("and grants a session that verifies", - granted and validate_value("username", granted), "Alice") +h.equals("and grants a session that verifies", granted and validate_value("username", granted), "Alice") out, ret = run_action("authenticate-post", { method = "POST", - body = "username=Alice&password=wrong&redirect=" .. - url_encode(way_back), + body = "username=Alice&password=wrong&redirect=" .. url_encode(way_back), }) h.contains("a bad password redirects the same way", out, "Status: 302") -h.contains("but clears the session cookie", out, - "Set-Cookie: cgitauth=; ") +h.contains("but clears the session cookie", out, "Set-Cookie: cgitauth=; ") out, ret = run_action("authenticate-post", { method = "POST", body = "username=nobody&password=x&redirect=" .. url_encode(way_back), }) -h.contains("an unknown user is told nothing different", out, - "Set-Cookie: cgitauth=; ") +h.contains("an unknown user is told nothing different", out, "Set-Cookie: cgitauth=; ") out, ret = run_action("authenticate-post", { method = "POST", body = "username=Alice&password=" .. url_encode(password), }) -h.contains("a post without the signed token is not served", out, - "Status: 404") +h.contains("a post without the signed token is not served", out, "Status: 404") local hijack = secure_value("redirect", "//evil.example/", 0) out, ret = run_action("authenticate-post", { method = "POST", - body = "username=Alice&password=" .. url_encode(password) .. - "&redirect=" .. url_encode(hijack), + body = "username=Alice&password=" .. url_encode(password) .. "&redirect=" .. url_encode(hijack), }) -h.contains("even a signed unsafe destination is not followed", out, - "Status: 404") +h.contains("even a signed unsafe destination is not followed", out, "Status: 404") h.finish() diff --git a/tests/extensions/test-email-avatar.lua b/tests/extensions/test-email-avatar.lua index d6bd957..94fec7e 100644 --- a/tests/extensions/test-email-avatar.lua +++ b/tests/extensions/test-email-avatar.lua @@ -70,8 +70,7 @@ h.contains("the name is buffered across writes", out, "> A U Thor") if mode == "real" then out = render("test@example.com", "x") - h.equals("a known address hashes to its published md5", - hash_of(out), "55502f40dc8b7c769880b10874abc9d0") + h.equals("a known address hashes to its published md5", hash_of(out), "55502f40dc8b7c769880b10874abc9d0") end h.finish() diff --git a/tests/extensions/test-link-commits.lua b/tests/extensions/test-link-commits.lua index 6c6d28d..07b2fdb 100644 --- a/tests/extensions/test-link-commits.lua +++ b/tests/extensions/test-link-commits.lua @@ -15,22 +15,19 @@ local function render(text) end local out, ret = render("see #123 for details") -h.contains("issue mark becomes a link", out, - "<a href='https://bugs.example.com/?bug=123'>#123</a>") +h.contains("issue mark becomes a link", out, "<a href='https://bugs.example.com/?bug=123'>#123</a>") h.contains("text around the link survives", out, "see ") h.contains("text after the link survives", out, " for details") h.equals("close answers zero", ret, 0) out = render("fixed in deadbee") -h.contains("seven hex characters link", out, - "<a href='./?id=deadbee'>deadbee</a>") +h.contains("seven hex characters link", out, "<a href='./?id=deadbee'>deadbee</a>") out = render("fixed in deadbe") h.excludes("six hex characters stay text", out, "<a") out = render("fixed in 1234567") -h.contains("an all digit run still links", out, - "<a href='./?id=1234567'>1234567</a>") +h.contains("an all digit run still links", out, "<a href='./?id=1234567'>1234567</a>") local sha1 = string.rep("0123456789abcdef", 2) .. "01234567" out = render("commit " .. sha1) @@ -58,14 +55,12 @@ h.excludes("the overlapped hash is dropped", out, "./?id=") out = render("#12 and cafebabe12") h.contains("both rules fire on one message", out, "?bug=12'>#12</a>") -h.contains("the object link also fires", out, - "<a href='./?id=cafebabe12'>cafebabe12</a>") +h.contains("the object link also fires", out, "<a href='./?id=cafebabe12'>cafebabe12</a>") -- One request is delivered as several writes, and a match split across two of -- them has to be seen whole. out = h.run({}, { "see #45", "6 and be done" }) -h.contains("a match split across writes still links", out, - "?bug=456'>#456</a>") +h.contains("a match split across writes still links", out, "?bug=456'>#456</a>") out, ret = render("") h.equals("an empty message stays empty", out, "") diff --git a/tests/extensions/test-syntax-highlight.lua b/tests/extensions/test-syntax-highlight.lua index 3b0eeb8..a9e8b36 100644 --- a/tests/extensions/test-syntax-highlight.lua +++ b/tests/extensions/test-syntax-highlight.lua @@ -31,51 +31,40 @@ if mode == "nolexers" then -- put the line numbers beside it out of step, so the whole escaped -- blob has to come back intact across several slices. out = render("big.fake", string.rep("x<y>", 30000)) - h.equals("slicing loses nothing at the boundaries", out, - string.rep("x<y>", 30000)) + h.equals("slicing loses nothing at the boundaries", out, string.rep("x<y>", 30000)) h.finish() end local out, ret = render("hello.fake", "if 42 'hi' & zz") -h.contains("keywords are wrapped in their class", out, - "<span class='hl-keyword'>if</span>") -h.contains("numbers are wrapped in their class", out, - "<span class='hl-number'>42</span>") -h.contains("a dotted tag maps by its first component", out, - "<span class='hl-string'>'hi'</span>") +h.contains("keywords are wrapped in their class", out, "<span class='hl-keyword'>if</span>") +h.contains("numbers are wrapped in their class", out, "<span class='hl-number'>42</span>") +h.contains("a dotted tag maps by its first component", out, "<span class='hl-string'>'hi'</span>") h.contains("bytes between tokens are escaped", out, " & ") -h.contains("later tokens still highlight", out, - "<span class='hl-keyword'>zz</span>") +h.contains("later tokens still highlight", out, "<span class='hl-keyword'>zz</span>") h.equals("close answers zero", ret, 0) out = h.run({ "split.fake" }, { "i", "f" }) -h.equals("writes are joined before lexing", out, - "<span class='hl-keyword'>if</span>") +h.equals("writes are joined before lexing", out, "<span class='hl-keyword'>if</span>") -- The short lexer tags four bytes and stops, and every byte after it still -- has to reach the page. out = render("cut.short", "abcd<ef>") -h.equals("a lexer stopping early leaves an escaped tail", out, - "<span class='hl-keyword'>abcd</span><ef>") +h.equals("a lexer stopping early leaves an escaped tail", out, "<span class='hl-keyword'>abcd</span><ef>") out = render("boom.badlex", "some <code>") -h.equals("a lexer that raises falls back to escaped text", out, - "some <code>") +h.equals("a lexer that raises falls back to escaped text", out, "some <code>") -- The viadetect lexer name only resolves through detect(), so highlighted -- output proves the detection path ran ahead of the extension path. out = render("script.viadetect", "if") -h.equals("filename detection picks the lexer", out, - "<span class='hl-keyword'>if</span>") +h.equals("filename detection picks the lexer", out, "<span class='hl-keyword'>if</span>") out = render("tool.py", "import <x>") -h.equals("an extension with no lexer serves escaped text", out, - "import <x>") +h.equals("an extension with no lexer serves escaped text", out, "import <x>") out = render("noextension", "words <here>") -h.equals("a file with no extension serves escaped text", out, - "words <here>") +h.equals("a file with no extension serves escaped text", out, "words <here>") out = render("big.fake", string.rep("a", 512 * 1024 + 1)) h.excludes("an oversized blob skips the lexing pass", out, "<span") diff --git a/tests/t0002-html-validity.sh b/tests/t0002-html-validity.sh index 0784092..8b04939 100755 --- a/tests/t0002-html-validity.sh +++ b/tests/t0002-html-validity.sh @@ -11,8 +11,7 @@ test_description='Validate html with tidy' test_url() { tidy_options="-eq" - test -z "$NO_TIDY_WARNINGS" || - tidy_options="$tidy_options --show-warnings no" + test -z "$NO_TIDY_WARNINGS" || tidy_options="$tidy_options --show-warnings no" # A second argument names a config of its own, for pages the shared # config keeps turned off. if test -n "$2" diff --git a/tests/t0003-cache.sh b/tests/t0003-cache.sh index 61bf45c..4693988 100755 --- a/tests/t0003-cache.sh +++ b/tests/t0003-cache.sh @@ -150,8 +150,7 @@ test_expect_success 'set up a repo missing a parent object' ' ' test_expect_success 'an error after output began replays none of it' ' - CGIT_CONFIG="$PWD/brokenrc" QUERY_STRING="url=broken/commit/&id=$tip" \ - cgit >broken.out && + CGIT_CONFIG="$PWD/brokenrc" QUERY_STRING="url=broken/commit/&id=$tip" cgit >broken.out && grep "Bad commit" broken.out && test $(grep -c "^Status:" broken.out) = 1 && ls cache4 >broken.slots && @@ -165,8 +164,7 @@ test_expect_success 'an error after output began replays none of it' ' test_expect_success 'an error page leaves no slot behind' ' rm -rf cache3 && mkdir cache3 && CGIT_CONFIG="$PWD/bigkeyrc" \ - QUERY_STRING="url=bigpage/commit/&id=0123456789abcdef0123456789abcdef01234567" \ - cgit >error.out && + QUERY_STRING="url=bigpage/commit/&id=0123456789abcdef0123456789abcdef01234567" cgit >error.out && grep "Bad commit reference" error.out && ls cache3 >error.slots && test_line_count = 0 error.slots diff --git a/tests/t0004-docs.sh b/tests/t0004-docs.sh index 85a4d8e..65c8275 100755 --- a/tests/t0004-docs.sh +++ b/tests/t0004-docs.sh @@ -12,16 +12,13 @@ test_description='Check the configuration documents' ROOT="$TEST_OUTPUT_DIRECTORY/.." test_expect_success 'extract the key lists' ' - sed -n "/^Global settings$/,/^Repository-specific cgitrc file$/p" \ - "$ROOT/MANUAL.txt" | + sed -n "/^Global settings$/,/^Repository-specific cgitrc file$/p" "$ROOT/MANUAL.txt" | sed -n "s/^\([a-z][a-zA-Z0-9.<>-]*\)::$/\1/p" | sort >manual-keys && - sed -n "s/^#\{0,1\}\([a-z][a-zA-Z0-9.<>-]*\)=.*/\1/p" \ - "$ROOT/custom/cgitrc" | + sed -n "s/^#\{0,1\}\([a-z][a-zA-Z0-9.<>-]*\)=.*/\1/p" "$ROOT/custom/cgitrc" | sed -e "s/^mimetype\..*/mimetype.<ext>/" | sort -u >example-keys && - sed -n "s/^#\{0,1\}\(repo\.module-link\)\..*=.*/\1.<path>/p" \ - "$ROOT/custom/cgitrc" >>example-keys && + sed -n "s/^#\{0,1\}\(repo\.module-link\)\..*=.*/\1.<path>/p" "$ROOT/custom/cgitrc" >>example-keys && sort -o example-keys example-keys && test -s manual-keys && test -s example-keys ' @@ -37,15 +34,13 @@ test_expect_success 'every key the reference config sets is documented' ' ' test_expect_success 'the manual lists its global settings in order' ' - sed -n "/^Global settings$/,/^Repository settings$/p" \ - "$ROOT/MANUAL.txt" | + sed -n "/^Global settings$/,/^Repository settings$/p" "$ROOT/MANUAL.txt" | sed -n "s/^\([a-z][a-zA-Z0-9.<>-]*\)::$/\1/p" >global-order && LC_ALL=C sort -c global-order ' test_expect_success 'the manual lists its repository settings in order' ' - sed -n "/^Repository settings$/,/^Repository-specific cgitrc file$/p" \ - "$ROOT/MANUAL.txt" | + sed -n "/^Repository settings$/,/^Repository-specific cgitrc file$/p" "$ROOT/MANUAL.txt" | sed -n "s/^\(repo\.[a-zA-Z0-9.<>-]*\)::$/\1/p" >repo-order && LC_ALL=C sort -c repo-order ' @@ -54,8 +49,7 @@ test_expect_success 'the manual lists its repository settings in order' ' # keeps the three copies from drifting apart. test_expect_success 'the server configs agree on one content security policy' ' for server in apache lighttpd nginx; do - grep "Content-Security-Policy" \ - "$ROOT/custom/servers/$server.conf" | + grep "Content-Security-Policy" "$ROOT/custom/servers/$server.conf" | grep "default-src" | sed "s/.*\"\(default-src[^\"]*\)\".*/\1/" || return 1 done >policies && diff --git a/tests/t0104-tree.sh b/tests/t0104-tree.sh index 66686c0..48c8406 100755 --- a/tests/t0104-tree.sh +++ b/tests/t0104-tree.sh @@ -52,8 +52,7 @@ test_expect_success 'set up a repo with a nested submodule' ' ' test_expect_success 'generate submodules/tree/vendor' ' - CGIT_CONFIG="$PWD/submodrc" QUERY_STRING="url=submodules/tree/vendor" \ - cgit >tmp + CGIT_CONFIG="$PWD/submodrc" QUERY_STRING="url=submodules/tree/vendor" cgit >tmp ' test_expect_success 'a submodule row shows the entry name alone' ' diff --git a/tests/t0109-patch.sh b/tests/t0109-patch.sh index 0982102..f4168f4 100755 --- a/tests/t0109-patch.sh +++ b/tests/t0109-patch.sh @@ -14,8 +14,7 @@ check_cgit_signature() { } # The version the built binary signs its patches with. -CGIT_VERSION=$(sed -n "s/CGIT_VERSION = //p" \ - "$TEST_OUTPUT_DIRECTORY/../build/VERSION") +CGIT_VERSION=$(sed -n "s/CGIT_VERSION = //p" "$TEST_OUTPUT_DIRECTORY/../build/VERSION") test_expect_success 'generate foo/patch' ' cgit_query "url=foo/patch" >tmp @@ -45,8 +44,7 @@ test_expect_success 'compare with output of git-format-patch(1)' ' ' test_expect_success 'find initial commit' ' - root=$(git --git-dir="$PWD/repos/foo/.git" \ - rev-list --max-parents=0 HEAD) + root=$(git --git-dir="$PWD/repos/foo/.git" rev-list --max-parents=0 HEAD) ' test_expect_success 'generate patch for initial commit' ' @@ -69,8 +67,7 @@ test_expect_success 'find `cgit` signature on the range' ' test_expect_success 'compare the range with git-format-patch(1)' ' git --git-dir="$PWD/repos/foo/.git" format-patch --subject-prefix="" \ - -N --signature="cgit $CGIT_VERSION" --stdout \ - HEAD~3..HEAD >tmp2 && + -N --signature="cgit $CGIT_VERSION" --stdout HEAD~3..HEAD >tmp2 && strip_headers <tmp >tmp_ && test_cmp tmp_ tmp2 ' @@ -83,10 +80,8 @@ test_expect_success 'max-patch-count bounds a patch range' ' echo "repo.path=$PWD/repos/foo/.git" } >patchcountrc && id=$(git --git-dir="$PWD/repos/foo/.git" rev-parse HEAD) && - root=$(git --git-dir="$PWD/repos/foo/.git" \ - rev-list --max-parents=0 HEAD) && - CGIT_CONFIG="$PWD/patchcountrc" \ - QUERY_STRING="url=foo/patch&id=$id&id2=$root" cgit >tmp && + root=$(git --git-dir="$PWD/repos/foo/.git" rev-list --max-parents=0 HEAD) && + CGIT_CONFIG="$PWD/patchcountrc" QUERY_STRING="url=foo/patch&id=$id&id2=$root" cgit >tmp && test $(grep -c "^From " tmp) -eq 2 ' diff --git a/tests/t0301-security.sh b/tests/t0301-security.sh index 2e5127c..6d6d493 100755 --- a/tests/t0301-security.sh +++ b/tests/t0301-security.sh @@ -257,8 +257,7 @@ test_expect_success 'set up a submodule fixture with a hostile module-link' ' ) && mkdir -p scan && cp -R repos/modlink scan/modlink && - printf "module-link=/m/%%s/%%s/%%s/%%s/%%s/%%s/%%s/%%s/%%s/%%s\n" \ - >scan/modlink/.git/cgitrc && + printf "module-link=/m/%%s/%%s/%%s/%%s/%%s/%%s/%%s/%%s/%%s/%%s\n" >scan/modlink/.git/cgitrc && { echo "virtual-root=/" && echo "cache-size=0" && diff --git a/tests/t0501-about-render.sh b/tests/t0501-about-render.sh index eff2a61..c2fdb71 100755 --- a/tests/t0501-about-render.sh +++ b/tests/t0501-about-render.sh @@ -20,13 +20,11 @@ test -z "$interpreters" && for lua in $interpreters do test_expect_success "unit checks under $lua" " - '$lua' '$EXT_TEST_DIRECTORY/test-about-render.lua' \ - '$EXTENSIONS_DIRECTORY/about-render.lua' + '$lua' '$EXT_TEST_DIRECTORY/test-about-render.lua' '$EXTENSIONS_DIRECTORY/about-render.lua' " test_expect_success "fallback checks without lpeg under $lua" " - '$lua' '$EXT_TEST_DIRECTORY/test-about-render.lua' \ - '$EXTENSIONS_DIRECTORY/about-render.lua' nolpeg + '$lua' '$EXT_TEST_DIRECTORY/test-about-render.lua' '$EXTENSIONS_DIRECTORY/about-render.lua' nolpeg " done diff --git a/tests/t0503-link-commits.sh b/tests/t0503-link-commits.sh index 11b1b54..1dfb28c 100755 --- a/tests/t0503-link-commits.sh +++ b/tests/t0503-link-commits.sh @@ -18,8 +18,7 @@ test -z "$interpreters" && for lua in $interpreters do test_expect_success "unit checks under $lua" " - '$lua' '$EXT_TEST_DIRECTORY/test-link-commits.lua' \ - '$EXTENSIONS_DIRECTORY/link-commits.lua' + '$lua' '$EXT_TEST_DIRECTORY/test-link-commits.lua' '$EXTENSIONS_DIRECTORY/link-commits.lua' " done diff --git a/tests/t0504-email-avatar.sh b/tests/t0504-email-avatar.sh index 0a4b74f..1af8988 100755 --- a/tests/t0504-email-avatar.sh +++ b/tests/t0504-email-avatar.sh @@ -23,15 +23,13 @@ do for script in email-gravatar email-libravatar do test_expect_success "$script checks under $lua" " - '$lua' '$EXT_TEST_DIRECTORY/test-email-avatar.lua' \ - '$EXTENSIONS_DIRECTORY/$script.lua' stub + '$lua' '$EXT_TEST_DIRECTORY/test-email-avatar.lua' '$EXTENSIONS_DIRECTORY/$script.lua' stub " if "$lua" -e "require([[openssl.digest]])" >/dev/null 2>&1 then test_expect_success "$script checks with real luaossl under $lua" " - '$lua' '$EXT_TEST_DIRECTORY/test-email-avatar.lua' \ - '$EXTENSIONS_DIRECTORY/$script.lua' real + '$lua' '$EXT_TEST_DIRECTORY/test-email-avatar.lua' '$EXTENSIONS_DIRECTORY/$script.lua' real " fi done diff --git a/tests/t0505-auth.sh b/tests/t0505-auth.sh index ca379de..2ebee10 100755 --- a/tests/t0505-auth.sh +++ b/tests/t0505-auth.sh @@ -22,8 +22,7 @@ do for variant in inline file do test_expect_success "auth-$variant checks under $lua" " - '$lua' '$EXT_TEST_DIRECTORY/test-auth.lua' \ - '$EXTENSIONS_DIRECTORY/auth-$variant.lua' $variant + '$lua' '$EXT_TEST_DIRECTORY/test-auth.lua' '$EXTENSIONS_DIRECTORY/auth-$variant.lua' $variant " done done @@ -39,8 +38,7 @@ test_expect_success 'create a repository with one commit' ' ' if test "$CGIT_HAS_LUA" -eq 1 && - cgit_lua_probe "$PWD/repos/authy/.git" \ - openssl.rand openssl.hmac posix.sys.stat posix.unistd + cgit_lua_probe "$PWD/repos/authy/.git" openssl.rand openssl.hmac posix.sys.stat posix.unistd then test_set_prereq CGIT_LUA_AUTH else diff --git a/tools/release-build.sh b/tools/release-build.sh index 0d9008f..babf008 100755 --- a/tools/release-build.sh +++ b/tools/release-build.sh @@ -38,10 +38,7 @@ supports() { probe=$(mktemp "${TMPDIR:-/tmp}/cgit-probe.XXXXXX") trap 'rm -f "$probe" "$probe.c" "$probe.out"' EXIT -CFLAGS="-O2 -g -Wall \ - -fstack-protector-strong \ - -fPIE \ - -fno-plt" +CFLAGS="-O2 -g -Wall -fstack-protector-strong -fPIE -fno-plt" # Level 3 adds the bounds checks level 2 could not prove, and needs GCC 12 or # Clang 15. Fall back rather than lose fortification altogether. @@ -57,9 +54,7 @@ if supports "-fstack-clash-protection"; then CFLAGS="$CFLAGS -fstack-clash-protection" fi -LDFLAGS="-pie \ - -Wl,-z,relro,-z,now \ - -Wl,-z,noexecstack" +LDFLAGS="-pie -Wl,-z,relro,-z,now -Wl,-z,noexecstack" # These reach only the cgit objects, so git's own sources are not held to them. # -Wformat-security is an error because a non-literal format with no arguments @@ -76,5 +71,4 @@ CGIT_EXTRA_CFLAGS="-Wformat -Wformat-security -Werror=format-security" # flags, and cleanall rather than clean because only cleanall descends into # vendor/git. make cleanall -exec make "$@" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" \ - CGIT_EXTRA_CFLAGS="$CGIT_EXTRA_CFLAGS" +exec make "$@" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" CGIT_EXTRA_CFLAGS="$CGIT_EXTRA_CFLAGS" diff --git a/tools/serve.py b/tools/serve.py index a39d03f..8924e53 100755 --- a/tools/serve.py +++ b/tools/serve.py @@ -72,8 +72,7 @@ def split_cgi_output(output: bytes) -> CgiResponse: than on a non-empty body keeps a legitimately empty body, such as the one a redirect leaves behind, from being read as headers. """ - ends = [(at, len(sep)) for sep in (b"\r\n\r\n", b"\n\n") - if (at := output.find(sep)) >= 0] + ends = [(at, len(sep)) for sep in (b"\r\n\r\n", b"\n\n") if (at := output.find(sep)) >= 0] if ends: at, seplen = min(ends) header_block, body = output[:at], output[at + seplen:] @@ -150,8 +149,7 @@ class CgitHandler(BaseHTTPRequestHandler): def send_asset(self, path: Path) -> None: data = path.read_bytes() - content_type = (mimetypes.guess_type(path.name)[0] - or "application/octet-stream") + content_type = (mimetypes.guess_type(path.name)[0] or "application/octet-stream") self.send_response(200) self.send_header("Content-Type", content_type) self.send_header("Content-Length", str(len(data))) @@ -228,8 +226,7 @@ class CgitHandler(BaseHTTPRequestHandler): self.send_response(response.status, response.reason) for name, value in response.headers: self.send_header(name, value) - if not any(name.lower() == "content-length" - for name, _ in response.headers): + if not any(name.lower() == "content-length" for name, _ in response.headers): self.send_header("Content-Length", str(len(response.body))) self.end_headers() if self.command != "HEAD": @@ -244,8 +241,7 @@ class CgitHandler(BaseHTTPRequestHandler): class CgitServer(ThreadingHTTPServer): """Holds the paths the handler needs, so none are attached later on.""" - def __init__(self, address: tuple[str, int], config: Path, cgit: Path, - data_dir: Path) -> None: + def __init__(self, address: tuple[str, int], config: Path, cgit: Path, data_dir: Path) -> None: self.config: Path = config self.cgit: Path = cgit self.data_dir: Path = data_dir @@ -268,14 +264,11 @@ class Options(argparse.Namespace): def parse_args(argv: list[str] | None = None) -> Options: parser = argparse.ArgumentParser(description="Preview cgit locally.") - _ = parser.add_argument("--config", default=Options.config, - help="path to cgitrc (default: ./cgitrc)") + _ = parser.add_argument("--config", default=Options.config, help="path to cgitrc (default: ./cgitrc)") _ = parser.add_argument("--port", type=int, default=Options.port) _ = parser.add_argument("--host", default=Options.host) - _ = parser.add_argument("--cgit", default=Options.cgit, - help="path to the cgit binary") - _ = parser.add_argument("--data", default=Options.data, - help="directory holding cgit.css, cgit.js, images") + _ = parser.add_argument("--cgit", default=Options.cgit, help="path to the cgit binary") + _ = parser.add_argument("--data", default=Options.data, help="directory holding cgit.css, cgit.js, images") return parser.parse_args(argv, namespace=Options()) |
