Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2019-07-17 11:49:07 -0400
committerMatthias Sohn2019-07-22 18:21:39 -0400
commit667dc0c5175637e32b4b9f41c37006e7f827beeb (patch)
tree682271fe39b60240ec2c65365a5bb7287752e8c4 /org.eclipse.egit.ui
parent374c142de4634d0888425368b138957c38498482 (diff)
downloadegit-667dc0c5175637e32b4b9f41c37006e7f827beeb.tar.gz
egit-667dc0c5175637e32b4b9f41c37006e7f827beeb.tar.xz
egit-667dc0c5175637e32b4b9f41c37006e7f827beeb.zip
Log an error if the reflog cannot be read
EGit reads the reflog in three places: in the SwitchToMenu, when trying to get a short branch name, and in the reflog view. The latter uses JGit's ReflogCommand and has its own fatal error handling. In the other two places, a failure to read the reflog may cause severe UI functionality loss. Therefore catch RuntimeExceptions, too, and just log them. In SwitchToMenu, also just log IOExceptions when the ref log cannot be read. That way, there's a fair chance that the menu will still show some branches. Bug: 549235 Change-Id: I914536a65cec9d7e5c04199e989926d46e607427 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.egit.ui')
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/SwitchToMenu.java27
1 files changed, 14 insertions, 13 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/SwitchToMenu.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/SwitchToMenu.java
index 76e7226a2..20675976c 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/SwitchToMenu.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/SwitchToMenu.java
@@ -24,6 +24,7 @@ import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Stream;
+import org.eclipse.egit.core.RepositoryUtil;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.internal.CommonUtils;
import org.eclipse.egit.ui.internal.UIIcons;
@@ -41,7 +42,6 @@ import org.eclipse.jgit.lib.ConfigConstants;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.ReflogEntry;
-import org.eclipse.jgit.lib.ReflogReader;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
@@ -180,10 +180,17 @@ public class SwitchToMenu extends ContributionItem implements
try {
List<Map<String, Ref>> activeBranches = new ArrayList<>();
- for (Repository repository : repositories) {
- Map<String, Ref> branchRefMapping = getMostActiveBranches(
- repository, MAX_NUM_MENU_ENTRIES);
- activeBranches.add(branchRefMapping);
+ try {
+ for (Repository repository : repositories) {
+ Map<String, Ref> branchRefMapping = getMostActiveBranches(
+ repository, MAX_NUM_MENU_ENTRIES);
+ activeBranches.add(branchRefMapping);
+ }
+ } catch (IOException e) {
+ Activator.logError(e.getLocalizedMessage(), e);
+ // The intersection should be empty if we cannot read the reflog
+ // of one repository.
+ activeBranches.clear();
}
Set<String> activeBranchIntersection = getBranchNameIntersection(
@@ -309,14 +316,8 @@ public class SwitchToMenu extends ContributionItem implements
.getRefs(Constants.R_HEADS);
Map<String, Ref> activeRefs = new HashMap<>();
- ReflogReader reflogReader = repository.getReflogReader(Constants.HEAD);
- List<ReflogEntry> reflogEntries;
- if (reflogReader == null) {
- return Collections.emptyMap();
- }
-
- reflogEntries = reflogReader.getReverseEntries();
-
+ List<ReflogEntry> reflogEntries = RepositoryUtil
+ .safeReadReflog(repository, Constants.HEAD);
for (ReflogEntry entry : reflogEntries) {
CheckoutEntry checkout = entry.parseCheckout();
if (checkout != null) {

Back to the top