Fix crash in /checkmergestatus operation

This fixes a regression introduced by

  1a9e4bf5 "Remove dbutils.Branch.{head,tail,commits} attributes"

which forgot to change this one use of Branch.head to use getHead().
On /manageextensions, list only extensions by current users

IOW, skip looking for potential extensions belonging to retired users,
and thus also avoid showing them, and prevent users from installing them.

It makes sense that extensions by retired users are not available.  If
they should be available, another user should adopt the extension, or the
system administrator should make the extension a system extension.
Use urlparse.parse_qs() to parse query string

This should be more reliable than the old version Request.getParameter().
In particular, the old version didn't work correctly for parameter names
with non-alphanumeric characters in them.
Execute __init__.py files under testing/tests/ before running tests

Specifically, before running a test A/B/C.py, execute first A/__init__.py
and then A/B/__init__.py in the same scope as A/B/C.py will eventually be
executed.  Missing __init__.py files are ignored.

This allows code sharing within groups of related tests without needing
to extend the basic testing framework.
Add |reviewers| and |watchers| attributes on api.review.Review
Add api.branch.fetchAll() function

Can be used to fetch Branch objects for all branches, or all branches in
a given repository.
Add api.user.fetchAll() function and api.user.User.status attribute

The fetchAll() function can be used to fetch User objects for all users
in the system, or all users with a given status.
Rename api.commit.Commit.UserAndTimestamp.fullname attribute 'name'

There's no other name in this context, and just 'name' matches the Git
naming better, since this name comes from the Git configuration setting
user.name, and the 'email' attribute comes from the Git configuration
setting user.email.
Fix accessing api.repository.Repository.url attribute as anonymous user

Or rather, if there is no critic.effective_user, use the anonymous user
internally to look up the URL format setting, instead of crashing.
Add license header to files under src/api/
Fix infinite loop in api.commitset.CommitSet.date_ordered

If the sorting function encountered the sequence of commits A-B-X where
A is the parent of B is the parent of X, and X's commit timestamp is
earlier than both A and B, it would get stuck forever alternating between
trying to emit A and B (only) failing A since B hasn't been emitted and
failing B since X hasn't been emitted.

Also extend the unit test slightly to trigger this situation.
Add api.review.fetchAll() function

Can be used to fetch Review objects for all reviews, or all reviews in
a given repository and/or in a given state.

Also add |state| and |repository| attributes on Review objects.
Clean up api.user error handling somewhat

- When calling api.user.fetch() with invalid arguments, raise singular
  exceptions instead of the plural exceptions that api.user.fetchMany()
  raises.  The new singular exceptions are sub-classes of the plural
  exceptions, mostly with a slightly more accurate message.

- Assert that the |status| argument to api.user.fetchAll() is valid
  instead of raising a proper exception when it's not.

  The policy here (and in the rest of the API) is that asserts are used
  to validate input when the calling code is broken if the value isn't
  valid, whereas proper exceptions are raised when the calling code can't
  be expected to know if the value is valid or not without trying.
Add (partial) JSON API

The API is rooted at /api/v1 and is currently quite limited in
scope, handling only these (top-level) resources:

  /api/v1/users
  /api/v1/repositories
  /api/v1/branches
  /api/v1/commits
  /api/v1/reviews

The /api/v1/reviews end-point in particular currently provides access
only to a very limited set of information about each review.

The API is somewhat self-documenting.  This documentation is available
at <URL:http://hostname/api/v1> on any Critic system upgraded to this
commit.
Fix typo: oups -> oops
Restructure the 'index' module

This is very old code (relatively speaking) and it was rather extra poorly
designed.  It had module global state (a |db| variable) and passed around
repository and user names instead of repository and user objects.

It also needed to represent that the acting user was "the system" and did
so by letting the |user| variable that normally referenced a dbutils.User
object reference a plain string instead (whose value was the name of the
system user.)  To improve the situation, add support for representing the
system user as a proper dbutils.User object similar to how we represent
an anonymous user already.

This is meaningful clean-up in itself, but the immediate motivation for
these changes is to make the 'index' module directly usable from other
code, thus avoiding the need to use 'git push' to make changes to the
repository.  Avoiding that can make code elsewhere more straight-forward,
and also faster.
Fetch remote branches without a relay repository

Modify gitutils.Repository.fetchTemporaryFromRemote() to run directly in
the target repository, by fetching to a temporary ref (whose name includes
a timestamp and a some randomness) and processing the fetched commit by
calling index.processCommits().

Creating a relay copy is usually very cheap, but does become expensive if
the main repository has very many loose objects.  A single fetch directly
in the target repository should also be quite a bit faster than a clone,
a fetch in the clone, and then a push back to the target repository, even
in the best of cases.
Add --upgrade-after argument and drop 002-late-upgrade test group

Late upgrading is sometimes absolutely necessary testing, but the model
implemented by the 002-late-upgrade group is inherently inflexible and
impractical.  What tests need to run before the upgrade, and what to test
after the upgrade, depends entirely on the upgrade and the particular
migration scripts it will run, and isn't practical to "hard-code" with a
test group like 002-late-upgrade.  Also, an extra group adds significant
cost to testing, often to little or no use.

The new --upgrade-after means any set of tests can run, and the upgrade
can be "inserted" anywhere in that set of tests.  For now, this will only
be useful for manual testing, but it would be possible to add some
mechanism by which a commit (via some checked in control file) can declare
useful test runs, that the automatic testing system could use to run
additional custom tests when testing that particular commit.
Clean up handling of equivalent merges and replayed rebases

When performing a move rebase, we will either create an "equivalent merge"
(for a fast-forward rebase) or a "replayed rebase" (otherwise.)  In the
former case, we'd update the review rebase's "old head" to point to the
equivalent merge, as if it had been pushed to the review before the rebase.
A replayed rebase wasn't directly recorded in the database at all, instead
its existence was deduced from there being a changeset added to the review
of type "conflicts" whose child commit was the new head of the rebase.

This was generally messy, and error-prone to work with.

Instead of all this, add two explicit columns to the reviewrebases table,
equivalent_merge and replayed_rebase, and set the appropriate one to point
to the generated commit when performing a rebase.  Adjust code elsewhere
to use the values of these columns.
In extension library, use cli.py to do comment propagation

Comment propagation is quite complicated, so use the same (Python) code
from the extension library as is used via the web front-end.

This fixes at least one bug: the old propagation code in the extension
library crashed if the file had had (only) its file mode / access bits
changed in some commit in the "propagation path."