Fix hg parent diffs (again?).

If a standard hg diff is posted, along with a parent diff, and the diff
touches files that the parent diff didn't, application will fail. This
change now properly fills the source_revision field on these filediffs
so that we don't attempt to fetch the file for the revision the parent
diff created.

The revision handling for the hg case is messy and could really use some
more love to make things more sensical and robust. I'm going to hold off
on any big changes for now since I think it's important to just get this
use case working.

Reviewed at https://reviews.reviewboard.org/r/6253/
Merge branch 'release-2.0.x'
Fix an annoying unicode comparison warning.

If a given patch file isn't coercible to unicode, it would cause a
UnicodeWarning when comparing it to the empty string. I've replaced this test
with a truthy-test, which won't try to convert the arguments.

Testing done: Ran unit tests.

Reviewed at https://reviews.reviewboard.org/r/6254/
Cache rendered diff fragments with large_data=True

Diff fragments usually aren't too big for individual cache entries, but when
they are, they cause warnings. This change stores them using large_data=True,
which will split them into pieces before caching.

Testing done:
- Ran unit tests
- Created a diff where a fragment exceeded the cache entry size limit and
  didn't see a warning.

Reviewed at https://reviews.reviewboard.org/r/6255/
Merge branch 'release-2.0.x'
Fix usage of deprecated 'mimetype' parameter for HttpResponse.

Django renamed the 'mimetype' parameter to 'content_type'. This change updates
our usages of it.

Testing done: Ran unit tests.

Reviewed at https://reviews.reviewboard.org/r/6256/
Merge branch 'release-2.0.x'
Store new and migrated diffs as raw, compressed binary data.

Historically, due to the limitations of Django's support for database
field types, we had to store diff data as base64-encoded data. This used
to be stored on FileDiffs, and then we migrated de-duplicated
FileDiffData entries. Still, the size of the diffs added up
considerably.

This change modernizes the storage by making use of Django 1.6's
BinaryField, which allows for storing raw binary content. That means we
can store a diff as-is without dealing with base64. We then go a step
further to bzip2 compress the content. If the resulting compressed size
is smaller than the raw diff content, we store that instead. For larger
diffs, this saves a lot of space.

This new content is stored in a new RawFileDiffData table, which is
similar to FileDiffData, but with a few key differences. It uses
BinaryField, of course, but it also has a field for the compression type
(we can add additional entries down the road), and it uses numeric IDs
for the primary key. FileDiffData used hashes of the diff content, which
inflated the FileDiff table, requiring 40 bytes for the key value. That
also slowed down lookups, since a 40 byte string is more expensive than
a numeric ID. This hash still exists, but is in its own field now.

FileDiffData has been renamed to LegacyFileDiffData. Likewise, the
fields in FileDiff referencing that table have been renamed in the
model. To prevent expensive database upgrades, the table name and
the columns in FileDiff referencing it have not been renamed. The
renames are done purely on the Python side.

When accessing the diff content associated with a FileDiff, we
automatically perform the migration to RawFileDiffData. This happens
whether FileDiff is storing its own diff content, or whether it's using
a LegacyFileDiffData for storage.

This results in a typical savings of ~80% on production databases.

Reviewed at https://reviews.reviewboard.org/r/6226/
Support the new RawFileDiffData migration in condensediffs.

condensediffs has been updated to handle the migration of
LegacyFileDiffData entries to RawFileDiffData. A lot of work went into
optimizing this. These are converted in batches, with minimal SQL
queries on a modern database (read: not sqlite3).

A run of condensediffs on a copy of a real-world database containing
650,000 diffs (all stored in LegacyFileDiffData entries) took 15 minutes
to convert, with a space savings of 80% (3.6GB down to 714MB).

Reviewed at https://reviews.reviewboard.org/r/6227/