cgit_print_error_page() has the advantage that it sets a suitable HTTP
status code for the response. Note that setting "mimetype" is redundant
here since it cannot have changed since being initialized in
cgit.c::prepare_context(), so we do not need to worry that
cgit_print_error_page() does not set it.
John Keeping [Fri, 14 Aug 2015 11:47:08 +0000 (12:47 +0100)]
snapshot: use cgit_print_error_page() for HTTP status codes
This is a bugfix as well as an improvement to the HTTP status code
handling since previously we would not print HTTP headers on any of
these code paths.
John Keeping [Fri, 14 Aug 2015 11:47:06 +0000 (12:47 +0100)]
blob: use cgit_print_error_page() to add HTTP headers
This is a bugfix as well as an improvement to the HTTP status code
handling since previously we would not print HTTP headers on any of
these code paths.
John Keeping [Fri, 14 Aug 2015 11:47:02 +0000 (12:47 +0100)]
cgit: use cgit_print_error_page() where appropriate
These are more-or-less one-to-one translations but in the final hunk we
gain an HTTP error code where we used to send "200 OK", which is an
improvement.
Christian Hesse [Thu, 13 Aug 2015 22:02:50 +0000 (00:02 +0200)]
ui-patch: make sure to send http headers
Requesting a text/plain patch with bad commit id made cgit send text
without proper http headers. This results in "500 Internal Server Error"
with "Premature end of script headers" in server logs.
So print http headers before error message and return.
Signed-off-by: Christian Hesse <mail@eworm.de> Reviewed-by: John Keeping <john@keeping.me.uk>
John Keeping [Thu, 13 Aug 2015 11:24:34 +0000 (12:24 +0100)]
ui-shared: show full date in tooltip if longer ago than max_relative
Commit caed6cb (ui-shared: show absolute time in tooltip for relative
dates, 2014-12-20) added a toolip when we show a relative time.
However, in some cases we show a short date (that is, the date but not
the time) if an event was sufficiently far in the past and that commit
did not update that case to add the same tooltip.
John Keeping [Thu, 13 Aug 2015 11:14:19 +0000 (12:14 +0100)]
ui-tree: use "sane" isgraph()
Git's git-compat-util.h defines a "sane ctype" that does not use locale
information and works with signed chars, but it does not include
isgraph() so we have included ctype.h ourselves.
However, this means we have to include a system header before
git-compat-util.h which may lead to the system defining some macros
(e.g. _FILE_OFFSET_BITS on Solaris) before git-compat-util.h redefines
them with a different value. We cannot include ctype.h after
git-compat-util.h because we have defined many of its functions as
macros which causes a stream of compilation errors.
Defining our own "sane" isgraph() using Git's sane isprint() and
isspace() avoids all of these problems.
John Keeping [Thu, 13 Aug 2015 11:14:17 +0000 (12:14 +0100)]
cache.c: fix header order
git-compat-util.h may define values that affect how system headers are
interpreted, so move sys/sendfile.h after cgit.h (which includes
git-compat-util.h).
John Keeping [Thu, 13 Aug 2015 11:14:16 +0000 (12:14 +0100)]
configfile.c: don't include system headers directly
git-compat-util.h may define various values that affect the
interpretation of system headers. In most places we include cgit.h
first, which pulls in git-compat-util.h, but this file does not depend
on anything else in CGit, so use git-compat-util.h directly.
John Keeping [Thu, 13 Aug 2015 11:14:13 +0000 (12:14 +0100)]
tests: allow shell to be overridden
On some systems (e.g. Solaris), /bin/sh is not a POSIX shell. Git
already provides suitable overrides in its config.mak.uname file and we
provide cgit.conf to allow the user to further change this.
The code for this is taken from Git's t/Makefile, meaning that we now
invoke the tests in the same way that Git does.
John Keeping [Wed, 12 Aug 2015 14:55:28 +0000 (15:55 +0100)]
log: allow users to follow a file
Teach the "log" UI to behave in the same way as "git log --follow", when
given a suitable instruction by the user. The default behaviour remains
to show the log without following renames, but the follow behaviour can
be activated by following a link in the page header.
Follow is not the default because outputting merges in follow mode is
tricky ("git log --follow" will not show merges). We also disable the
graph in follow mode because the commit graph is not simplified so we
end up with frequent gaps in the graph and many lines that do not
connect with any commits we're actually showing.
We also teach the "diff" and "commit" UIs to respect the follow flag on
URLs, causing the single-file version of these UIs to detect renames.
This feature is needed only for commits that rename the path we're
interested in.
For commits before the file has been renamed (i.e. that appear later in
the log list) we change the file path in the links from the log to point
to the old name; this means that links to commits always limit by the
path known to that commit. If we didn't do this we would need to walk
down the log diff'ing every commit whenever we want to show a commit.
The drawback is that the "Log" link in the top bar of such a page links
to the log limited by the old name, so it will only show pre-rename
commits. I consider this a reasonable trade-off since the "Back" button
still works and the log matches the path displayed in the top bar.
Since following renames requires running diff on every commit we
consider, I've added a knob to the configuration file to globally
enable/disable this feature. Note that we may consider a large number
of commits the revision walking machinery no longer performs any path
limitation so we have to examine every commit until we find a page full
of commits that affect the target path or something related to it.
John Keeping [Tue, 23 Dec 2014 14:40:44 +0000 (14:40 +0000)]
contrib/hooks: add sample post-receive hook using agefile
One of the most frequent questions on the mailing list relates to the
idle time in the repository list. The answer to this is to use the
"agefile" feature to calculate the time of the last change whenever the
repository receives changes.
Add a sample post-receive hook in a new "contrib" directory so that we
can just point people at the repository in the future.
John Keeping [Sun, 8 Mar 2015 16:32:27 +0000 (16:32 +0000)]
html: avoid using a plain integer as a NULL pointer
Sparse complains about this table because we use the integer zero as the
NULL pointer. Use this as an opportunity to reformat the table so that
it always contains 8 elements per row, making it easier to see which
values are being set and which are not.
John Keeping [Sun, 8 Mar 2015 16:32:24 +0000 (16:32 +0000)]
ui-shared: avoid initializing static variable to zero
Sparse complains that we are using a plain integer as a NULL pointer
here, but in fact we do not have to specify a value for this variable at
all since it has static storage duration and thus will be initialized to
NULL by the compiler.
Lukas Fleischer [Thu, 5 Mar 2015 11:58:12 +0000 (12:58 +0100)]
Drop return value from parse_user()
In commit 936295c (Simplify commit and tag parsing, 2015-03-03), the
commit and tag parsing code was refactored. This broke tag messages in
ui-tag since the line after the tagger header was erroneously skipped.
Rework parse_user() and skip the line manually outside parse_user().
John Keeping [Tue, 3 Mar 2015 19:22:31 +0000 (19:22 +0000)]
cache: use F_SETLK to avoid stale lock files
If CGit is killed while it holds a lock on a cache slot (for example
because it is taking too long to generate a page), the lock file will be
left in place. This prevents any future attempt to use the same slot
since it will fail to exclusively create the lock file.
Since CGit is the only program that should be manipulating lock files,
we can use advisory locking to detect whether another process is
actually using the lock file or if it is now stale.
I have confirmed that this works on Linux by setting a short TTL in a
custom cgitrc and running the following with CGit patched to print a
message to stderr if the fcntl(2) fails:
Lukas Fleischer [Tue, 3 Mar 2015 12:00:07 +0000 (13:00 +0100)]
Simplify commit and tag parsing
* Use skip_prefix to avoid magic numbers in the code.
* Use xcalloc() instead of xmalloc(), followed by manual initialization.
* Split out line splitting.
Christian Hesse [Wed, 11 Feb 2015 08:12:44 +0000 (09:12 +0100)]
shrink cgit.png file size
Ran optipng against cgit.png, which shrank file size by more than eight
percent. The image (including protocol overhead) should fit into a
single network packet now.
Optipng optimizes filters and compression. The actual pixel results are
not altered.
Lukas Fleischer [Mon, 9 Feb 2015 06:25:00 +0000 (07:25 +0100)]
ui-clone.c: Fix path check
The starts_with() check was broken in two ways: For one thing, the
parameters were passed in the wrong order, for another thing,
starts_with() returns 1 if the string starts with the prefix (not 0).
Note that this bug existed since commit 02a545e (Add support for cloning
over http, 2008-08-06) but only pops in in corner cases.
Christian Hesse [Sat, 7 Feb 2015 13:18:28 +0000 (14:18 +0100)]
git: update for v2.3.0
* sort_string_list(): rename to string_list_sort() (upstream commit 3383e199)
* update read_tree_recursive callback to pass strbuf as base (upstream
commit 6a0b0b6d)
Lukas Fleischer [Thu, 29 Jan 2015 11:52:49 +0000 (12:52 +0100)]
Add repo.hide and repo.ignore
These options can be used to hide a repository from the index or
completely ignore a repository, respectively. They are particularly
useful when used in combination with scan-path.
John Keeping [Thu, 15 Jan 2015 22:18:14 +0000 (22:18 +0000)]
tag: reference with "h" instead of "id"
When clicking on "log" from a tag we end up showing the log of whatever
branch we used to reach the tag. If the tag doesn't point onto a branch
then the tagged commit won't appear in this output.
By linking to tags with the head parameter instead of the "id" parameter
the log link will show the log of the tag. This is clearly desirable
when the tag has been reached from the refs UI and changing the
behaviour for tag decorations makes them match branch decorations where
log -> decoration -> log shows the log of the decoration.
Reported-by: Ferry Huberts <mailings@hupie.com> Signed-off-by: John Keeping <john@keeping.me.uk>
Lukas Fleischer [Thu, 15 Jan 2015 18:47:42 +0000 (19:47 +0100)]
Return proper HTTP response when accessing info/
Currently, when a user directly accesses the info command of a
repository, we exit cgit without printing anything to stdout, bringing
up error messages like "502 Bad Gateway" or "An error occurred while
reading CGI reply (no response received)". Instead of bailing out, at
least print the HTTP headers, including a reasonable error message.
John Keeping [Mon, 29 Dec 2014 22:27:55 +0000 (22:27 +0000)]
ui-diff: don't link to single file diff stat
Seeing the diff stat for a single file is pretty useless, so reset the
diff type before generating the links to individual files in the diff
stat so that the links will show a useful diff.
Reported-by: Konstantin Ryabitsev <mricon@kernel.org> Signed-off-by: John Keeping <john@keeping.me.uk>
John Keeping [Sun, 28 Dec 2014 13:10:33 +0000 (13:10 +0000)]
ui-patch: match git-format-patch(1) output
Using (DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_PATCH) causes Git to emit a
"---" line between the commit message and the body of the patch, which
fixes a regression introduced in commit 455b598 (ui-patch.c: Use
log_tree_commit() to generate diffs, 2013-08-20), prior to which we
inserted the "---" line ourselves.
DIFF_FORMAT_SUMMARY is added so that we match the output of
git-format-patch(1) without the "-p" option.
Lukas Fleischer [Wed, 24 Dec 2014 07:50:11 +0000 (08:50 +0100)]
Use split_ident_line() in parse_user()
Use Git's built-in ident line splitting algorithm instead of
reimplementing it. This does not only simplify the code but also makes
sure that cgit is consistent with Git when it comes to author parsing.