[staging] Avoid unnecessary work when commit message text changes
The CommitMessageComponent updates the "sign-off" and "add change-id"
buttons on every text change, depending on whether the text contains
a signed-off-by or change-id line. Updating the change-id button state
also updated the commit buttons in order to show the correct icon and
text for the "Commit & Push" button. Updating the commit buttons is a
fairly expensive operation involving multiple file accesses to read the
git config or to resolve HEAD, which definitely should not be done on
every text change.
First, track the "add change-id" button's state explicitly so that we
can update the button only if the toggle state really changes. We can't
rely on the button's isChecked() because that toggles when the button
is selected and is already changed when the listener is invoked.
Second, factor out updating the image and text of the "Commit & Push"
button into a separate method. This is all that this listener really
needs to update.
Third, cache the push mode for the current repository. Invalidate the
cache whenever the git config changes.
Fourth, keep the git config cached during updateCommitButtons() with
a UnitOfWork.
Further work to avoid duplicate work in updateCommitButtons() can be
done in the scope of bug 578768. (Computing the RepositoryState only
once, maybe caching whether there is a HEAD at all.)
Bug: 579284
Change-Id: I93293ee077d4e2f4818252eef6be7c6849d2a7f0
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>