ui-refs.c: Remove global header variable

print_tag_header() is only called from cgit_print_tags() -- the
conditional invocation in print_tag() is never executed since
print_tag() is only called by cgit_print_tags() which already executes
print_tag_header() before (resulting in the global variable being always
set in when the condition is evaluated).

Remove the global variable and the conditional invocation.

Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de>
ui-refs.c: Refactor print_tag()

The code snippets for OBJ_TAG and other object types are almost
equivalent. Merge them and use a couple of inline if conditions to
select proper fields.

Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de>
Fix out-of-bounds memory accesses with virtual_root=""

The CGit configuration variable virtual_root is normalized so that it
does not have a trailing '/' character, but it is allowed to be empty
(the empty string and NULL have different meanings here) and there is
code that is insufficiently cautious when checking if it ends in a '/':

	if (virtual_root[strlen(virtual_root) - 1] != '/')

Clearly this check is redundant, but rather than simply removing it we
get a slight efficiency improvement by switching the normalization so
that the virtual_root variable always ends in '/'.  Do this with a new
"ensure_end" helper.

Signed-off-by: John Keeping <john@keeping.me.uk>
Mark char* fields in struct cgit_page as const

Signed-off-by: John Keeping <john@keeping.me.uk>
Remove redundant calls to fmt("%s", ...)

After this change there is one remaining call 'fmt("%s", delim)' in
ui-shared.c but is needed as delim is stack allocated and so cannot be
returned from the function.

Signed-off-by: John Keeping <john@keeping.me.uk>
---
Changes since v1:
- Fix a thinko: 'fmt("%s", path)' is equivalent to path not "%s".
html.c: add fmtalloc helper

Signed-off-by: John Keeping <john@keeping.me.uk>
shared.c: add strbuf_ensure_end

This is a small helper so that we can easily ensure that a strbuf ends
with the specified character.

Signed-off-by: John Keeping <john@keeping.me.uk>
cache.c: don't use statically sized buffers for filenames

Instead use "struct strbuf" from Git to remove the limit on file path
length.

Signed-off-by: John Keeping <john@keeping.me.uk>

---
Changes since v1:
- Reset the buffer length before appending each filename to the base
  path.
html: introduce html_txtf and html_vtxtf functions

These takes a printf style format string like htmlf but escapes the
resulting string.  The html_vtxtf variant takes a va_list whereas
html_txtf is variadic.

Signed-off-by: John Keeping <john@keeping.me.uk>
Convert cgit_print_error to a variadic function

This removes many uses of "fmt" which uses a fixed size static pool of
fixed size buffers.  Instead of relying on these, we now pass around
argument lists for as long as possible before using a strbuf to render
content of an arbitrary size.

Signed-off-by: John Keeping <john@keeping.me.uk>
---
Changes since v2:
- Don't access ctx->repo after setting it to NULL in prepare_repo_cmd
scan-tree: use struct strbuf instead of static buffers

This is slightly involved since I decided to pass the strbuf into
add_repo() and modify if whenever a new file name is required, which
should avoid any extra allocations within that function.  The pattern
there is to append the filename, use it and then reset the buffer to its
original length (retaining a trailing '/').

Signed-off-by: John Keeping <john@keeping.me.uk>

---
Changes since v1:
- Free the strbuf in is_git_dir.
- Free the strbuf in scan_projects.
ui-log.c: use a strbuf for refs

This avoids using a fixed-size buffer in fmt() for a user-supplied ref
string.

Signed-off-by: John Keeping <john@keeping.me.uk>
ui-log.c: use a strbuf for grep arguments

Signed-off-by: John Keeping <john@keeping.me.uk>
ui-plain.c: use struct strbuf instead of fmt()

Signed-off-by: John Keeping <john@keeping.me.uk>

---
Changes since v1:
- Use fmtalloc where appropriate
ui-refs.c: use struct strbuf instead of fixed-size buffers

Signed-off-by: John Keeping <john@keeping.me.uk>

---
Changes since v1:
- Reset filename buffer in the print_tag_downloads loop.
- Use fmtalloc where appropriate
ui-repolist.c: use struct strbuf for repository paths

Signed-off-by: John Keeping <john@keeping.me.uk>
ui-snapshot.c: tidy up memory management in write_archive_type

- Use a strbuf instead of a fixed-size buffer
- Free the argv_array when we're done with it

Note that since write_archive modifies the argv array passed to it we
copy the argv_array values into a new array of char* and then free the
original argv_array structure and the new array without worrying about
what the values now look like.

Signed-off-by: John Keeping <john@keeping.me.uk>

---
Changes since v1:
- Fix freeing the argv array to avoid double frees.
ui-snapshot: use a struct strbuf instead of fixed-size buffers

Signed-off-by: John Keeping <john@keeping.me.uk>

---
Changes since v1:
- Fix completely bogus reset-then-use code.
ui-summary.c: use struct strbuf instead of fixed-size buffers

Signed-off-by: John Keeping <john@keeping.me.uk>

---
Changes since v1:
- Use fmtalloc where appropriate
ui-tag.c: use struct strbuf for user-supplied data

Signed-off-by: John Keeping <john@keeping.me.uk>