From 3101a2e1705a8f60e2c8cdb92ccd887e7865699e Mon Sep 17 00:00:00 2001 From: Thomas Wolf Date: Tue, 20 Jun 2017 12:35:04 +0200 Subject: [PATCH] FetchGerritChangePage: improve content assist Make content assist for the Change field work also if it already contains a change ref ("refs/changes/dd/ccccc/ps"). Bug: 518495 Change-Id: I1cd9e0f8fda97af32e82a0286c31d1b06f6a8fcf Signed-off-by: Thomas Wolf --- .../ui/internal/fetch/FetchGerritChangePage.java | 23 ++++++++++++++++------ 1 file changed, 17 insertions(+), 6 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 33fa5de68..0371ccd7d 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 @@ -111,6 +111,15 @@ import org.eclipse.ui.progress.WorkbenchJob; */ public class FetchGerritChangePage extends WizardPage { + private static final Pattern GERRIT_FETCH_PATTERN = Pattern.compile( + "git fetch (\\w+:\\S+) (refs/changes/\\d+/\\d+/\\d+) && git (\\w+) FETCH_HEAD"); //$NON-NLS-1$ + + private static final Pattern GERRIT_URL_PATTERN = Pattern.compile( + "(?:https?://\\S+?/|/)?([1-9][0-9]*)(?:/([1-9][0-9]*)(?:/([1-9][0-9]*)(?:\\.\\.\\d+)?)?)?(?:/\\S*)?"); //$NON-NLS-1$ + + private static final Pattern GERRIT_CHANGE_REF_PATTERN = Pattern + .compile("refs/changes/\\d+/(\\d+)(?:/\\d*)"); //$NON-NLS-1$ + private enum CheckoutMode { CREATE_BRANCH, CREATE_TAG, CHECKOUT_FETCH_HEAD, NOCHECKOUT } @@ -208,8 +217,7 @@ public class FetchGerritChangePage extends WizardPage { String defaultChange = null; String candidateChange = null; if (clipText != null) { - String pattern = "git fetch (\\w+:\\S+) (refs/changes/\\d+/\\d+/\\d+) && git (\\w+) FETCH_HEAD"; //$NON-NLS-1$ - Matcher matcher = Pattern.compile(pattern).matcher(clipText); + Matcher matcher = GERRIT_FETCH_PATTERN.matcher(clipText); if (matcher.matches()) { defaultUri = matcher.group(1); defaultChange = matcher.group(2); @@ -526,9 +534,7 @@ public class FetchGerritChangePage extends WizardPage { if (input == null) { return null; } - Pattern pattern = Pattern.compile( - "(?:https?://\\S+?/|/)?([1-9][0-9]*)(?:/([1-9][0-9]*)(?:/([1-9][0-9]*)(?:\\.\\.\\d+)?)?)?(?:/\\S*)?"); //$NON-NLS-1$ - Matcher matcher = pattern.matcher(input); + Matcher matcher = GERRIT_URL_PATTERN.matcher(input); if (matcher.matches()) { String first = matcher.group(1); String second = matcher.group(2); @@ -946,7 +952,12 @@ public class FetchGerritChangePage extends WizardPage { return null; } List resultList = new ArrayList<>(); - Pattern pattern = UIUtils.createProposalPattern(contents); + String input = contents; + Matcher matcher = GERRIT_CHANGE_REF_PATTERN.matcher(contents); + if (matcher.find()) { + input = matcher.group(1); + } + Pattern pattern = UIUtils.createProposalPattern(input); for (final Change ref : proposals) { if (pattern != null && !pattern .matcher(ref.getChangeNumber().toString()) -- 2.11.4.GIT