Fixed #22867 -- Memoized django.utils.version.get_git_changeset().

This follows commits 80f4487 and 01399fa; original patch had to be
reverted because it wasn't Python 2.6 compatible and we need it to
be in order to build docs on the djangoproject.com server.

This fix should be replaced by @lru_cache as soon as we drop
Python 2.6 compatibility.

Thanks Florian Apolloner for the review and Alexander Schepanovski
for the original patch.
Fixed #22875: Optimizer did not take through= into account.
Include swapped apps in autodetector state
Clean up syncdb parts of migrate output if no synced apps