Process expanded/collapsed state on saving state

Instead of saving expanded/collapsed state for the files when
toggling state, process them when saving navigation state.

Fixes bug with commit.expandAllFiles set to true when javascript
and html states were not in sync on load because expandedFiles
dictonary wasn't getting updated. On navigating away and going
back, all files would be collapsed.

I think this approach is much less error prone and does not require
sprinkling state updating code all over. It shouldn't have any
noticable performance impact.
When restoring history state, collapse file after showing it

Instead of first collapsing and then showing which would end up with
expanded file with expandedFiles[id] being 'false', which seems wrong.
Include all files from the diff view, when saving history state

Files that were hidden before navigating away from the page, were
made visible on navigating back due to initial state held by JS
was not in sync with view created by server (with expandAllFiles
option enabled).

Store state for both hidden, collapsed and expanded files to fix it.
Trigger history state save after load

It would otherwise only be saved on scroll event. Or when collapsing/
expanding file but then we would not have proper previous state, when
navigating back.
Avoid creating spurious history navigation entries

Don't save transient history states that are not visible to the user.
Also don't save when state didn't change in in practive (multiple clicks
on the file name, for example).