[staging] Avoid unnecessary work when commit message text changes
commitdaa12362b5e06a229e1a5496f3ffb577b158fe54
authorThomas Wolf <thomas.wolf@paranor.ch>
Wed, 16 Mar 2022 22:06:35 +0000 (16 23:06 +0100)
committerThomas Wolf <thomas.wolf@paranor.ch>
Thu, 17 Mar 2022 12:02:03 +0000 (17 08:02 -0400)
tree84df5951f3e2d98f424cc5f56c46173895e2f57e
parentdf7499bcc4b1c9aa406316094434b3ed7513309e
[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>
org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java