Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Keller2014-12-02 13:37:39 +0000
committerDani Megert2014-12-02 13:37:39 +0000
commitc739996f0722742a5c46b6b3995af89301633819 (patch)
treec952bf824c3938b9a29d6d4b80b013f9c8249cb9 /bundles
parentcc9d6f826e11f654302e380e3a2dbc96c5c8b0ba (diff)
downloadeclipse.platform.team-c739996f0722742a5c46b6b3995af89301633819.tar.gz
eclipse.platform.team-c739996f0722742a5c46b6b3995af89301633819.tar.xz
eclipse.platform.team-c739996f0722742a5c46b6b3995af89301633819.zip
Fixed bug 441993: Eclipse can't apply patch produced by "git format-patch" due to the --<git version> lines at the end
Signed-off-by: Markus Keller <markus_keller@ch.ibm.com>
Diffstat (limited to 'bundles')
-rw-r--r--bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/PatchReader.java20
1 files changed, 14 insertions, 6 deletions
diff --git a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/PatchReader.java b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/PatchReader.java
index 0e22b4166..c103e1b8a 100644
--- a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/PatchReader.java
+++ b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/PatchReader.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2013 IBM Corporation and others.
+ * Copyright (c) 2006, 2014 IBM Corporation 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
@@ -67,9 +67,6 @@ public class PatchReader {
private static final Pattern GIT_PATCH_PATTERN= Pattern.compile("^diff --git a/.+ b/.+[\r\n]+$"); //$NON-NLS-1$
- private static final Pattern GIT_VERSION_PATTERN= Pattern.compile("^\\d+\\.\\d*.*$"); //$NON-NLS-1$
-
-
/**
* Create a patch reader for the default date formats.
*/
@@ -258,6 +255,8 @@ public class PatchReader {
int[] oldRange= new int[2];
int[] newRange= new int[2];
+ int remainingOld= -1; // remaining old lines for current hunk
+ int remainingNew= -1; // remaining new lines for current hunk
List lines= new ArrayList();
boolean encounteredPlus = false;
@@ -279,6 +278,10 @@ public class PatchReader {
}
char c= line.charAt(0);
+ if (remainingOld == 0 && remainingNew == 0 && c != '@' && c != '\\') {
+ return line;
+ }
+
switch (c) {
case '@':
if (line.startsWith("@@ ")) { //$NON-NLS-1$
@@ -291,19 +294,25 @@ public class PatchReader {
// format: @@ -oldStart,oldLength +newStart,newLength @@
extractPair(line, '-', oldRange);
extractPair(line, '+', newRange);
+ remainingOld= oldRange[1];
+ remainingNew= newRange[1];
continue;
}
break;
case ' ':
encounteredSpace= true;
+ remainingOld--;
+ remainingNew--;
lines.add(line);
continue;
case '+':
encounteredPlus= true;
+ remainingNew--;
lines.add(line);
continue;
case '-':
encounteredMinus= true;
+ remainingOld--;
lines.add(line);
continue;
case '\\':
@@ -341,8 +350,7 @@ public class PatchReader {
break;
//$FALL-THROUGH$
default:
- if (!isGitPatch() || !GIT_VERSION_PATTERN.matcher(line.trim()).matches())
- throw new IOException("Invalid patch"); //$NON-NLS-1$
+ break;
}
return line;
}

Back to the top