Return const char * in cgit_{httpscheme, hosturl, rooturl}()

The return values of these functions are essentially constant and should
never be modified.

Note that this will introduce a compiler warning when we try to free the
return value of any of these functions. However, given that all of these
currently return statically allocated strings in some cases, they need
to be refactored before this can be done anyway.

Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de>
Maŕk cgit_environment members const

These reflect the values of environment variables and should never be
changed. Add another xstrdup() when we assign environment variables to
strings that are potentially non-constant.

Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de>
Do not unnecessarily strdup() environment variables

This reverts the memory duplication introduced in commit 60a2627, while
keeping everything else that has been cleaned up. The environment
variables are never modified, so we do not need to call xstrdupn() here.

Also, remove xstrdupn() which is no longer needed.

Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de>
Makefile: re-include cgit.conf in cgit.mk

This avoids needed to export every variable that might be used in
cgit.mk from the top-level Makefile.

Signed-off-by: John Keeping <john@keeping.me.uk>
cgit.mk: fix dependency handling

Git calculates the dependency files to be included using a simply
expanded Makefile variable, so it does not include the CGit objects that
are added after that Makefile has been processed.

We therefore need to include the dependency files ourselves in order to
get the dependency calculations right.  Do this.

Signed-off-by: John Keeping <john@keeping.me.uk>
tests: use Git's test framework

This allows tests to run in parallel as well as letting us use "prove"
or another TAP harness to run the tests.

Git's test framework requires Git to be fully built before letting any
tests run, so add a new target to the top-level Makefile which builds
all of Git instead of just libgit.a and make the "test" target depend on
that.

Signed-off-by: John Keeping <john@keeping.me.uk>
tests: use git's skip_all for missing tidy

Ideally we'd be able to use test_have_prereq and test_set_prereq to test
and set features, but for now, calling `which` directly is sufficient.

Adding skip_all lets git's test harness know why we're bailing early.
Always #include corresponding .h in .c files

While doing this, remove declarations from header files where the
corresponding definition is declared "static" in order to avoid build
errors.

Also re-order existing headers in ui-*.c so that the file-specific
header always comes immediately after "cgit.h", helping with future
consistency.

Signed-off-by: John Keeping <john@keeping.me.uk>
html.c: Replace strdup() with xstrdup()

Use the xstrdup() wrapper which already bails out if strdup() returns a
NULL pointer.

Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de>
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>
Update git to v1.8.2.1

This requires a small change to how we handle notes, but otherwise just
works.

Note that we can't use anything from v1.8.0 until v1.8.2.1 because some
of the symbols that we need for graph drawing were made private in
v1.8.0 and this was not reverted until v1.8.2.1.

Signed-off-by: John Keeping <john@keeping.me.uk>
Merge branch 'jk/compat-timegm' into pu

* branch jk/compat-timegm:
  compat/timegm: new compat function for systems lacking timegm()
  Makefile: re-include cgit.conf in cgit.mk

Submitted to cgit@hjemli.net.
Merge branch 'jk/update-git' into pu

* branch jk/update-git:
  Update git to v1.8.2.1

Waiting for the next maint release of Git.
Merge branch 'jk/use-git-test-framework' into pu

* branch jk/use-git-test-framework: (23 commits)
  tests: use test_create_repo instead of "git init"
  tests: use test_line_count where appropriate
  t0001: use test_cmp instead of 'diff -u'
  tests: add Valgrind support
  .gitignore: tighten cgit ignore expression
  tests: put cgit onto $PATH
  tests: remove "trash" directory
  tests/.gitignore: update for using Git's test infrastructure
  t0001: don't setup test repositories
  tests: remove prepare_tests
  tests: don't let Git's test-lib create a repository
  tests: use Git test functions directly
  ui-refs.c: Refactor print_tag()
  ui-refs.c: Remove global header variable
  html.c: Replace strdup() with xstrdup()
  Always #include corresponding .h in .c files
  tests: use git's skip_all for missing tidy
  tests: use Git's test framework
  cgit.mk: fix dependency handling
  Makefile: re-include cgit.conf in cgit.mk
  ...

Submitted to cgit@hjemli.net.

Could use Sharness instead of Git's test framework.

Can have several tidy-ups built on top if there is agreement that this
is the right way to go.

Conflicts:
	tests/setup.sh
	tests/t0001-validate-git-versions.sh
	tests/t0010-validate-html.sh
	tests/t0020-validate-cache.sh
	tests/t0101-index.sh
	tests/t0102-summary.sh
	tests/t0103-log.sh
	tests/t0104-tree.sh
	tests/t0105-commit.sh
	tests/t0106-diff.sh
	tests/t0107-snapshot.sh
	tests/t0108-patch.sh
Merge branch 'jk/portable-tests' into pu

* branch jk/portable-tests:
  t0107: use "-z" when asking tar to gunzip
  tests: sed -i is not portable

Currently dogfooding locally.

Conflicts:
	tests/t0010-validate-html.sh
	tests/t0020-validate-cache.sh
	tests/t0107-snapshot.sh
Merge branch 'jk/no-static-char-buf' into pu

* branch jk/no-static-char-buf: (22 commits)
  ui-shared.c: use struct strbuf instead of fmt()
  html: add html_attrf to output an attribute value from a format string
  cgit.c: use struct strbuf instead of fmt()
  ui-tree.c: use struct strbuf instead of fmt()
  ui-tag.c: use struct strbuf for user-supplied data
  ui-summary.c: use struct strbuf instead of fixed-size buffers
  ui-snapshot: use a struct strbuf instead of fixed-size buffers
  ui-snapshot.c: tidy up memory management in write_archive_type
  ui-repolist.c: use struct strbuf for repository paths
  ui-refs.c: use struct strbuf instead of fixed-size buffers
  ui-plain.c: use struct strbuf instead of fmt()
  ui-log.c: use a strbuf for grep arguments
  ui-log.c: use a strbuf for refs
  scan-tree: use struct strbuf instead of static buffers
  Convert cgit_print_error to a variadic function
  html: introduce html_txtf and html_vtxtf functions
  cache.c: don't use statically sized buffers for filenames
  shared.c: add strbuf_ensure_end
  html.c: add fmtalloc helper
  Remove redundant calls to fmt("%s", ...)
  ...

War on fixed size buffers.