Have RepositoryForm take a local_site_name argument for hard-coding a site.

RepositoryForm now accepts a local_site_name keyword argument that
forces the form to operate with a specific LocalSite. Previously, it
only worked with initial data or form data.
Remove the RepositoryForm's local_site_name arg from kwargs.

RepositoryForm's local_site_name was being passed down to the parent
form class, which didn't understand the parameter. So, pop it from
kwargs before calling the parent constructor.
Make it possible to add custom middleware in settings_local.

There's now a RB_EXTRA_MIDDLEWARE_CLASSES that allows a
settings_local.py file to include extra middleware. These will be
appended to the main list of middleware classes.
Move common comment code into BaseComment.

BaseComment is a nice base class, but wasn't doing enough. In order to
simplify maintenance, the reply_to, timestamp, text, and objects
variables and the public_replies, get_review_url, and __unicode__
functions have been moved into BaseComment.

This also introduces a get_review_request function, which is used
instead of calling self.review.get().review_request. If the
_review_request variable is assigned on the comment, it will be returned
instead, which skips a couple of otherwise necessary queries.
Merge branch 'release-1.6.x'
Make it possible to add custom middleware in settings_local.

There's now a RB_EXTRA_MIDDLEWARE_CLASSES that allows a
settings_local.py file to include extra middleware. These will be
appended to the main list of middleware classes.
Remove many SQL queries from the review request page.

It turns out the review request page had a terribly large number of SQL
queries being performed. This is the first step in removing those and
simplifying the code.
Pass the list of diffsets and public reviews to ReviewRequest.get_last_activity.

ReviewRequest.get_last_activity can now take a list of diffsets and
review to operate on. This works as an optimization when you don't need
that function to perform its own queries. We use this in review_detail
now in order to reduce the number of queries we need to make.
Optimize comment loading.

Instead of loading lists of comments, we now load the through tables
inbetween the comment and review. This allows us to do a select_related
that will fetch the comment and the review at the same time, making it
cheaper to map into the entry with the review ID.
Store the last reply timestamps without doing a query per review.

We had a query per review to get the timestamp of the latest reply. This
wasn't very efficient. Now, we just do the calculations when iterating
over all the reviews.
Set the review request on some objects to prevent further lookups.

Several objects (Comment, ScreenShot, FileAttachment, etc.) performed
queries to get the associated review request, in order to generate URLs.
Where we're using them, though, we already know the review
request. So, short-circuit by setting a special _review_request attribute.
Provide accessor methods for screenshots and file attachments.
Reduce queries for reviews, replies, and comments.

Each reply to a review was generating queries for each comment, each
replied review, and each user. These ballooned up in size quite a bit.

We now cache these along with everything else we're caching to reduce
lookups. The lists of replies are all computed at one place when we're
computing everything else, and new accessors on Review and BaseComment
make it easy to grab the results without assuming a query.
Use user IDs instead of users in the templates for several checks.

There were lots of template tags that were being passed users instead of
just user IDs, which were causing extra queries. We can get away with
just using the user IDs, so pass those instead.
Select the submitter and repository along with a review request.
Reduce queries for screenshot and file attachment snippets on comments.

Comments for screenshots and file attachments caused extra queries per
comment, particularly on images during the process of providing the
snippet of the screenshot.

Since we already fetch the screenshots and file attachments, just build
another ID map and re-associate the screenshots and file attachments
before handing them off to the template.
Optimize the diff viewer page.

The diff viewer page was performing excessive queries for comments and
reviews. Now we pre-compute those, and diffsets, before rendering the
page.
Fix for newer versions of mercurial that use version numbers like 2.2.2+20120602

This will replace the "+" in the version number with "."

Reviewed at http://reviews.reviewboard.org/r/3154/
Add a framework for handling file attachments by mimetype.

This introduces a new framework for mimetype handlers. These handlers
can render file attachments for display in the review request. Right
now, we have handlers for generic file attachments (which don't render
anything), for text files (which renders the first couple lines of the
file), and for images (which render the image sort of like a
screenshot).

There are some things that still need to be done. For example, an
initially uploaded file attachment won't have any sort of thumbnail
rendered until the page is loaded. This will need to happen before
1.7.0.

Reviewed at http://reviews.reviewboard.org/r/2967/
Upload files with the proper mimetypes.

The file uploading code was always setting the mimetype to
application/octet-stream, despite being able to get the mimetype from
the File object. We now use the File's mimetype instead. This fixes
mimetypes for any newly uploaded file attachments.