From d8a045c91469b1d121b8fd14dffaa367b194831d Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sun, 6 Sep 2026 21:46:52 -1000 Subject: Clean up the whole tree --- Makefile | 12 +- assets/cgit.js | 9 +- custom/cgitrc | 7 +- custom/extensions/about-render.lua | 27 +-- custom/extensions/auth-file.lua | 33 +-- custom/extensions/auth-inline.lua | 33 +-- custom/extensions/link-commits.lua | 15 +- custom/extensions/syntax-highlight.lua | 6 +- custom/hooks/post-receive.cgit-age | 3 +- custom/hooks/post-receive.cgit-cache | 3 +- source/cache.c | 63 +++--- source/cache.h | 3 +- source/cgit.c | 103 +++++----- source/cgit.h | 3 +- source/cgit.mk | 9 +- source/cmd.c | 17 +- source/cmd.h | 4 +- source/filter.c | 48 ++--- source/html.c | 15 +- source/html.h | 10 +- source/parsing.c | 15 +- source/scan-tree.c | 30 +-- source/shared.c | 47 ++--- source/shared.h | 21 +- source/ui-atom.c | 3 +- source/ui-blame.c | 70 +++---- source/ui-blob.c | 31 +-- source/ui-blob.h | 9 +- source/ui-clone.c | 9 +- source/ui-commit.c | 42 ++-- source/ui-diff.c | 126 +++++------- source/ui-diff.h | 4 +- source/ui-log.c | 125 +++++------- source/ui-log.h | 5 +- source/ui-patch.c | 34 ++- source/ui-patch.h | 3 +- source/ui-plain.c | 19 +- source/ui-refs.c | 24 +-- source/ui-repolist.c | 18 +- source/ui-shared.c | 318 +++++++++++------------------ source/ui-shared.h | 81 +++----- source/ui-snapshot.c | 51 ++--- source/ui-snapshot.h | 3 +- source/ui-ssdiff.c | 52 ++--- source/ui-stats.c | 38 ++-- source/ui-stats.h | 3 +- source/ui-summary.c | 15 +- source/ui-tag.c | 25 +-- source/ui-tree.c | 86 +++----- tests/extensions/harness.lua | 18 +- tests/extensions/lib.sh | 3 +- tests/extensions/test-about-render.lua | 84 +++----- tests/extensions/test-auth.lua | 93 +++------ tests/extensions/test-email-avatar.lua | 3 +- tests/extensions/test-link-commits.lua | 15 +- tests/extensions/test-syntax-highlight.lua | 33 +-- tests/t0002-html-validity.sh | 3 +- tests/t0003-cache.sh | 6 +- tests/t0004-docs.sh | 18 +- tests/t0104-tree.sh | 3 +- tests/t0109-patch.sh | 15 +- tests/t0301-security.sh | 3 +- tests/t0501-about-render.sh | 6 +- tests/t0503-link-commits.sh | 3 +- tests/t0504-email-avatar.sh | 6 +- tests/t0505-auth.sh | 6 +- tools/release-build.sh | 12 +- tools/serve.py | 21 +- 68 files changed, 763 insertions(+), 1318 deletions(-) diff --git a/Makefile b/Makefile index b22beb9..332f5a0 100644 --- a/Makefile +++ b/Makefile @@ -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 = "" - .. part .. "" + part = "" .. part .. "" 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("\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 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 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); // 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(""); - 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(""); - 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("%s", 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("\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(""); cgit_print_error("Error reading parent commit"); html("\n"); continue; } - html("parent" - ""); + html("parent"); 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(")\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("\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("\n"); @@ -135,12 +126,10 @@ void cgit_print_commit(char *hex, const char *prefix) html("\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("["); cgit_print_filemode(info->old_mode); html("]"); } htmlf("\n", - info->old_size, info->new_size); + htmlf("bin\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("
--- 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("
+++ 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("
"); 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(""); @@ -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("
"); - 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("
\n"); html("
commit"); 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(")
tree"); 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("
", 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(""); if (info->binary) { - htmlf("bin%lu -> %lu bytes
%lu -> %lu bytes
\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("
\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("\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("
"); - 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("
"); @@ -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("\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(""); @@ -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(""); 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(""); strbuf_setlen(&graphbuf, 0); - } - else { + } else { html(""); - 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(""); } @@ -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(""); 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(""); - 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("%d", file_count); if (ctx.repo->enable_log_linecount) htmlf("-%d/" - "+%d", - removed_lines, added_lines); + "+%d", removed_lines, added_lines); html("\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(""); 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(""); // Either way one cell is already on the row, so the message // spans the remaining columns. - htmlf("\n", columns - 1, - ctx.qry.showmsg ? " class='logmsg'" : ""); + htmlf("\n", columns - 1, ctx.qry.showmsg ? " class='logmsg'" : ""); html_txt(msgbuf.buf); html("\n"); } @@ -370,20 +354,18 @@ static void print_pager(struct rev_info *revs, int ofs, int cnt) html(""); @@ -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(""); } -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("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("Author"); @@ -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("", 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("\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("
  • "); - 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("
  • \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("\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(""); - 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(""); 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("[prev] "); 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(" [next]"); @@ -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("", - columns); + htmlf("", columns); html_txt(section); html("\n"); } @@ -224,8 +222,7 @@ static void print_repo_row(const char *currenturl, int sublevel) { char *repourl; - htmlf("", - sublevel ? "sublevel-repo" : "toplevel-repo"); + htmlf("", sublevel ? "sublevel-repo" : "toplevel-repo"); cgit_summary_link(ctx.repo->name, NULL, NULL, NULL); html(""); 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(""); 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(""); } @@ -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("
  • "); - 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("
  • "); } html("\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(""); } -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("