Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2016-05-22 13:50:18 +0000
committerMatthias Sohn2016-06-01 08:08:00 +0000
commitd968d6b5578da62e69e23069f7c2b8850545c567 (patch)
tree10065efe5b07b74084eec339b993187ef1b8986c
parentbe99e570b9bb98a823563595058b9023bde2ffb9 (diff)
downloadegit-d968d6b5578da62e69e23069f7c2b8850545c567.tar.gz
egit-d968d6b5578da62e69e23069f7c2b8850545c567.tar.xz
egit-d968d6b5578da62e69e23069f7c2b8850545c567.zip
Initialize dialog settings when a remote is configured
When a user cloned a repository via git:// and then configured the remote for Gerrit through "Gerrit Configuration..." (specifying a ssh:// push URI), the "Push to Gerrit..." wizard would still open with the git:// URI pre-selected because the dialog hadn't remembered any "last used" URI yet and "git://" is lexicographically smaller than "ssh://". This was counter-intuitive. Therefore: if a remote is configured for Gerrit, or a push or fetch refspec is configured (and it's a Gerrit refspec), and the "Push to Gerrit" or "Fetch Change from Gerrit" dialogs have no last used URI set, initialize it to the URI just configured. This gives a reasonable initial value when those dialogs are subsequently opened the first time for that repository. Bug: 493935 Change-Id: I9815358a5d2e0a31ce355513d5ad76139e6e123d Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchGerritChangePage.java17
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/SimpleConfigureFetchDialog.java7
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/gerrit/ConfigureGerritWizard.java12
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/gerrit/GerritDialogSettings.java119
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/PushToGerritPage.java16
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/SimpleConfigurePushDialog.java7
6 files changed, 151 insertions, 27 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchGerritChangePage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchGerritChangePage.java
index 488207186f..b16306d249 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchGerritChangePage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchGerritChangePage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2014 SAP AG and others.
+ * Copyright (c) 2010, 2016 SAP AG and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,6 +8,7 @@
* Contributors:
* Mathias Kinzler (SAP AG) - initial implementation
* Marc Khouzam (Ericsson) - Add an option not to checkout the new branch
+ * Thomas Wolf <thomas.wolf@paranor.ch> - Bug 493935
*******************************************************************************/
package org.eclipse.egit.ui.internal.fetch;
@@ -43,6 +44,7 @@ import org.eclipse.egit.ui.internal.branch.BranchOperationUI;
import org.eclipse.egit.ui.internal.dialogs.AbstractBranchSelectionDialog;
import org.eclipse.egit.ui.internal.dialogs.BranchEditDialog;
import org.eclipse.egit.ui.internal.dialogs.CheckoutConflictDialog;
+import org.eclipse.egit.ui.internal.gerrit.GerritDialogSettings;
import org.eclipse.jface.bindings.keys.KeyStroke;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogSettings;
@@ -104,9 +106,6 @@ import org.eclipse.ui.PlatformUI;
* Fetch a change from Gerrit
*/
public class FetchGerritChangePage extends WizardPage {
- private static final String FETCH_GERRIT_CHANGE_PAGE_SECTION = "FetchGerritChangePage"; //$NON-NLS-1$
-
- private static final String LAST_URI_POSTFIX = ".lastUri"; //$NON-NLS-1$
private static final String RUN_IN_BACKGROUND = "runInBackground"; //$NON-NLS-1$
@@ -167,7 +166,7 @@ public class FetchGerritChangePage extends WizardPage {
.getRepositoryName(repository)));
setMessage(UIText.FetchGerritChangePage_PageMessage);
settings = getDialogSettings();
- lastUriKey = repository + LAST_URI_POSTFIX;
+ lastUriKey = repository + GerritDialogSettings.LAST_URI_SUFFIX;
branchValidator = ValidationUtils.getRefNameInputValidator(repository,
Constants.R_HEADS, true);
@@ -177,12 +176,8 @@ public class FetchGerritChangePage extends WizardPage {
@Override
protected IDialogSettings getDialogSettings() {
- IDialogSettings s = Activator.getDefault().getDialogSettings();
- IDialogSettings section = s
- .getSection(FETCH_GERRIT_CHANGE_PAGE_SECTION);
- if (section == null)
- section = s.addNewSection(FETCH_GERRIT_CHANGE_PAGE_SECTION);
- return section;
+ return GerritDialogSettings
+ .getSection(GerritDialogSettings.FETCH_FROM_GERRIT_SECTION);
}
@Override
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/SimpleConfigureFetchDialog.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/SimpleConfigureFetchDialog.java
index eb24469250..a7d23e19d3 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/SimpleConfigureFetchDialog.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/SimpleConfigureFetchDialog.java
@@ -1,10 +1,13 @@
/*******************************************************************************
- * Copyright (C) 2011, Mathias Kinzler <mathias.kinzler@sap.com>
+ * Copyright (C) 2011, 2016 Mathias Kinzler <mathias.kinzler@sap.com> and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Thomas Wolf <thomas.wolf@paranor.ch> - Bug 493935
*******************************************************************************/
package org.eclipse.egit.ui.internal.fetch;
@@ -20,6 +23,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.UIPreferences;
import org.eclipse.egit.ui.internal.UIText;
+import org.eclipse.egit.ui.internal.gerrit.GerritDialogSettings;
import org.eclipse.egit.ui.internal.push.RefSpecDialog;
import org.eclipse.egit.ui.internal.push.RefSpecWizard;
import org.eclipse.egit.ui.internal.repository.SelectUriWizard;
@@ -551,6 +555,7 @@ public class SimpleConfigureFetchDialog extends TitleAreaDialog {
} catch (IOException e) {
Activator.handleError(e.getMessage(), e, true);
}
+ GerritDialogSettings.updateRemoteConfig(repository, config);
if (buttonId == OK)
try {
new ProgressMonitorDialog(getShell()).run(true, true,
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/gerrit/ConfigureGerritWizard.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/gerrit/ConfigureGerritWizard.java
index 3bda1a8115..44115305e1 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/gerrit/ConfigureGerritWizard.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/gerrit/ConfigureGerritWizard.java
@@ -1,10 +1,13 @@
/*******************************************************************************
- * Copyright (C) 2012, Stefan Lay <stefan.lay@sap.com>
+ * Copyright (C) 2012, 2016 Stefan Lay <stefan.lay@sap.com> and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Thomas Wolf <thomas.wolf@paranor.ch> - Bug 493935
*******************************************************************************/
package org.eclipse.egit.ui.internal.gerrit;
@@ -36,6 +39,8 @@ public class ConfigureGerritWizard extends Wizard {
private final String remoteName;
private RemoteConfig remoteConfig;
+ private Repository repository;
+
/**
* @param repository the repository
* @param remoteName the name of the remote in the configuration
@@ -57,7 +62,7 @@ public class ConfigureGerritWizard extends Wizard {
};
this.config = repository.getConfig();
this.remoteName = remoteName;
-
+ this.repository = repository;
}
@Override
@@ -115,10 +120,11 @@ public class ConfigureGerritWizard extends Wizard {
gerritConfiguration.setErrorMessage(e.getMessage());
return false;
}
+ GerritDialogSettings.updateRemoteConfig(repository, remoteConfig);
return true;
}
- private void configureRemoteSection() throws URISyntaxException {
+ private void configureRemoteSection() {
GerritUtil.configurePushURI(remoteConfig, gerritConfiguration.getURI());
GerritUtil.configurePushRefSpec(remoteConfig,
gerritConfiguration.getBranch());
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/gerrit/GerritDialogSettings.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/gerrit/GerritDialogSettings.java
new file mode 100644
index 0000000000..e4e641562c
--- /dev/null
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/gerrit/GerritDialogSettings.java
@@ -0,0 +1,119 @@
+/*******************************************************************************
+ * Copyright (C) 2016, Thomas Wolf <thomas.wolf@paranor.ch>
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.egit.ui.internal.gerrit;
+
+import java.util.List;
+
+import org.eclipse.egit.core.internal.gerrit.GerritUtil;
+import org.eclipse.egit.ui.Activator;
+import org.eclipse.egit.ui.internal.fetch.FetchGerritChangePage;
+import org.eclipse.egit.ui.internal.push.PushToGerritPage;
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jgit.annotations.NonNull;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.transport.RemoteConfig;
+import org.eclipse.jgit.transport.URIish;
+
+/**
+ * Helper class for managing the dialog setting of the
+ * {@link FetchGerritChangePage} and {@link PushToGerritPage}.
+ */
+public final class GerritDialogSettings {
+
+ /**
+ * Name of the {@link IDialogSettings} section for the
+ * {@link FetchGerritChangePage}.
+ */
+ public static final String FETCH_FROM_GERRIT_SECTION = FetchGerritChangePage.class
+ .getSimpleName();
+
+ /**
+ * Name of the {@link IDialogSettings} section for the
+ * {@link PushToGerritPage}.
+ */
+ public static final String PUSH_TO_GERRIT_SECTION = PushToGerritPage.class
+ .getSimpleName();
+
+ /**
+ * Repository suffix for storing the last used URI in a section.
+ */
+ public static final String LAST_URI_SUFFIX = ".lastUri"; //$NON-NLS-1$
+
+ private GerritDialogSettings() {
+ // Utility class shall not be instantiated.
+ }
+
+ /**
+ * Updates dialog settings as appropriate. Called within the UI thread.
+ *
+ * @param repository
+ * the {@code config} belongs to
+ * @param config
+ * that was updated
+ */
+ public static void updateRemoteConfig(Repository repository,
+ RemoteConfig config) {
+ if (repository == null || config == null) {
+ return;
+ }
+ if (GerritUtil.isGerritFetch(config)) {
+ updateGerritFetch(repository, config);
+ }
+ if (GerritUtil.isGerritPush(config)) {
+ updateGerritPush(repository, config);
+ }
+ }
+
+ /**
+ * Gets the specified section from the activator's {@link IDialogSettings}.
+ * Creates the section if it doesn't exist.
+ *
+ * @param id
+ * of the section to get
+ * @return the section
+ */
+ public static @NonNull IDialogSettings getSection(String id) {
+ IDialogSettings settings = Activator.getDefault().getDialogSettings();
+ IDialogSettings section = settings.getSection(id);
+ if (section == null) {
+ section = settings.addNewSection(id);
+ if (section == null) {
+ throw new NullPointerException(
+ "IDialogSettings section could not be created"); //$NON-NLS-1$
+ }
+ }
+ return section;
+ }
+
+ private static void updateGerritFetch(@NonNull Repository repository,
+ @NonNull RemoteConfig config) {
+ IDialogSettings section = getSection(FETCH_FROM_GERRIT_SECTION);
+ String configured = section.get(repository + LAST_URI_SUFFIX);
+ if (configured == null || configured.isEmpty()) {
+ List<URIish> fetchUris = config.getURIs();
+ if (!fetchUris.isEmpty()) {
+ section.put(repository + LAST_URI_SUFFIX,
+ fetchUris.get(0).toPrivateString());
+ }
+ }
+ }
+
+ private static void updateGerritPush(@NonNull Repository repository,
+ @NonNull RemoteConfig config) {
+ IDialogSettings section = getSection(PUSH_TO_GERRIT_SECTION);
+ String configured = section.get(repository + LAST_URI_SUFFIX);
+ if (configured == null || configured.isEmpty()) {
+ List<URIish> pushUris = config.getPushURIs();
+ if (!pushUris.isEmpty()) {
+ section.put(repository + LAST_URI_SUFFIX,
+ pushUris.get(0).toPrivateString());
+ }
+ }
+ }
+}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/PushToGerritPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/PushToGerritPage.java
index 9366c2ba32..1976451c3d 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/PushToGerritPage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/PushToGerritPage.java
@@ -36,6 +36,7 @@ import org.eclipse.egit.ui.UIUtils;
import org.eclipse.egit.ui.internal.CommonUtils;
import org.eclipse.egit.ui.internal.UIText;
import org.eclipse.egit.ui.internal.credentials.EGitCredentialsProvider;
+import org.eclipse.egit.ui.internal.gerrit.GerritDialogSettings;
import org.eclipse.jface.bindings.keys.KeyStroke;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogSettings;
@@ -76,11 +77,7 @@ import org.eclipse.ui.IWorkbenchCommandConstants;
/**
* Push the current HEAD to Gerrit
*/
-class PushToGerritPage extends WizardPage {
- private static final String PUSH_TO_GERRIT_PAGE_SECTION = "PushToGerritPage"; //$NON-NLS-1$
-
- private static final String LAST_URI_POSTFIX = ".lastUri"; //$NON-NLS-1$
-
+public class PushToGerritPage extends WizardPage {
private static final String LAST_BRANCH_POSTFIX = ".lastBranch"; //$NON-NLS-1$
private static final String LAST_TOPICS_POSTFIX = ".lastTopics"; //$NON-NLS-1$
@@ -139,17 +136,14 @@ class PushToGerritPage extends WizardPage {
.getRepositoryUtil().getRepositoryName(repository)));
setMessage(UIText.PushToGerritPage_Message);
settings = getDialogSettings();
- lastUriKey = repository + LAST_URI_POSTFIX;
+ lastUriKey = repository + GerritDialogSettings.LAST_URI_SUFFIX;
lastBranchKey = repository + LAST_BRANCH_POSTFIX;
}
@Override
protected IDialogSettings getDialogSettings() {
- IDialogSettings s = Activator.getDefault().getDialogSettings();
- IDialogSettings section = s.getSection(PUSH_TO_GERRIT_PAGE_SECTION);
- if (section == null)
- section = s.addNewSection(PUSH_TO_GERRIT_PAGE_SECTION);
- return section;
+ return GerritDialogSettings
+ .getSection(GerritDialogSettings.PUSH_TO_GERRIT_SECTION);
}
@Override
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/SimpleConfigurePushDialog.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/SimpleConfigurePushDialog.java
index 0481231f82..43796cfb60 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/SimpleConfigurePushDialog.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/SimpleConfigurePushDialog.java
@@ -1,10 +1,13 @@
/*******************************************************************************
- * Copyright (C) 2011, 2014 Mathias Kinzler <mathias.kinzler@sap.com> and others.
+ * Copyright (C) 2011, 2016 Mathias Kinzler <mathias.kinzler@sap.com> and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Thomas Wolf <thomas.wolf@paranor.ch> - Bug 493935
*******************************************************************************/
package org.eclipse.egit.ui.internal.push;
@@ -20,6 +23,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.egit.core.op.PushOperationResult;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.internal.UIText;
+import org.eclipse.egit.ui.internal.gerrit.GerritDialogSettings;
import org.eclipse.egit.ui.internal.repository.SelectUriWizard;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
@@ -632,6 +636,7 @@ public class SimpleConfigurePushDialog extends TitleAreaDialog {
} catch (IOException e) {
Activator.handleError(e.getMessage(), e, true);
}
+ GerritDialogSettings.updateRemoteConfig(repository, config);
if (buttonId == OK)
try {
new ProgressMonitorDialog(getShell()).run(true, true,

Back to the top