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
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>
-rw-r--r--bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/PatchReader.java20
-rw-r--r--tests/org.eclipse.compare.tests/patchdata/2hunks_autofuzz-f0-f1/patch.txt4
-rw-r--r--tests/org.eclipse.compare.tests/patchdata/2hunks_autofuzz-f0-f2/patch.txt4
-rw-r--r--tests/org.eclipse.compare.tests/patchdata/2hunks_autofuzz-f1-f0/patch.txt4
-rw-r--r--tests/org.eclipse.compare.tests/patchdata/2hunks_shift_autofuzz-1/patch.txt4
-rw-r--r--tests/org.eclipse.compare.tests/patchdata/2hunks_switch/patch.txt4
-rw-r--r--tests/org.eclipse.compare.tests/patchdata/2hunks_switch_fail/patch.txt4
-rw-r--r--tests/org.eclipse.compare.tests/patchdata/autofuzz-f1/patch.txt2
-rw-r--r--tests/org.eclipse.compare.tests/patchdata/autofuzz-f2/patch.txt2
-rw-r--r--tests/org.eclipse.compare.tests/patchdata/fuzz1/patch_f1.txt2
-rw-r--r--tests/org.eclipse.compare.tests/patchdata/fuzz2/patch_f2.txt2
-rw-r--r--tests/org.eclipse.compare.tests/patchdata/shiftdown_f0/patch_f0.txt2
-rw-r--r--tests/org.eclipse.compare.tests/patchdata/shiftdown_f2/patch_f2.txt2
13 files changed, 32 insertions, 24 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;
}
diff --git a/tests/org.eclipse.compare.tests/patchdata/2hunks_autofuzz-f0-f1/patch.txt b/tests/org.eclipse.compare.tests/patchdata/2hunks_autofuzz-f0-f1/patch.txt
index 3ba685e04..9181b8a8d 100644
--- a/tests/org.eclipse.compare.tests/patchdata/2hunks_autofuzz-f0-f1/patch.txt
+++ b/tests/org.eclipse.compare.tests/patchdata/2hunks_autofuzz-f0-f1/patch.txt
@@ -2,7 +2,7 @@
diff -u -N context.txt context.txt
--- context.txt 2007-06-27 08:50:46.000000603 -0400
+++ context.txt 2007-07-11 17:24:45.000000000 -0400
-@@ -1,3 +1,3 @@
+@@ -1,9 +1,9 @@
[a]
[b]
[c]
@@ -15,7 +15,7 @@ diff -u -N context.txt context.txt
[g]
[h]
[i]
-@@ -14,3 +14,3 @@
+@@ -14,9 +14,9 @@
[Xn]
[o]
[p]
diff --git a/tests/org.eclipse.compare.tests/patchdata/2hunks_autofuzz-f0-f2/patch.txt b/tests/org.eclipse.compare.tests/patchdata/2hunks_autofuzz-f0-f2/patch.txt
index 34607db08..abff14f92 100644
--- a/tests/org.eclipse.compare.tests/patchdata/2hunks_autofuzz-f0-f2/patch.txt
+++ b/tests/org.eclipse.compare.tests/patchdata/2hunks_autofuzz-f0-f2/patch.txt
@@ -2,7 +2,7 @@
diff -u -N context.txt context.txt
--- context.txt 2007-06-27 08:50:46.000000603 -0400
+++ context.txt 2007-07-11 17:24:45.000000000 -0400
-@@ -1,3 +1,2 @@
+@@ -1,9 +1,8 @@
[a]
[b]
[c]
@@ -14,7 +14,7 @@ diff -u -N context.txt context.txt
[g]
[h]
[i]
-@@ -14,3 +14,3 @@
+@@ -14,9 +14,9 @@
[Xn]
[o]
[p]
diff --git a/tests/org.eclipse.compare.tests/patchdata/2hunks_autofuzz-f1-f0/patch.txt b/tests/org.eclipse.compare.tests/patchdata/2hunks_autofuzz-f1-f0/patch.txt
index 3d76d2f03..7abf57111 100644
--- a/tests/org.eclipse.compare.tests/patchdata/2hunks_autofuzz-f1-f0/patch.txt
+++ b/tests/org.eclipse.compare.tests/patchdata/2hunks_autofuzz-f1-f0/patch.txt
@@ -2,7 +2,7 @@
diff -u -N context.txt context.txt
--- context.txt 2007-06-27 08:50:46.000000603 -0400
+++ context.txt 2007-07-11 17:24:45.000000000 -0400
-@@ -1,3 +1,3 @@
+@@ -1,9 +1,9 @@
[Xa]
[b]
[c]
@@ -15,7 +15,7 @@ diff -u -N context.txt context.txt
[g]
[h]
[Xi]
-@@ -14,3 +14,3 @@
+@@ -14,9 +14,9 @@
[n]
[o]
[p]
diff --git a/tests/org.eclipse.compare.tests/patchdata/2hunks_shift_autofuzz-1/patch.txt b/tests/org.eclipse.compare.tests/patchdata/2hunks_shift_autofuzz-1/patch.txt
index 835f8a9d2..97b037925 100644
--- a/tests/org.eclipse.compare.tests/patchdata/2hunks_shift_autofuzz-1/patch.txt
+++ b/tests/org.eclipse.compare.tests/patchdata/2hunks_shift_autofuzz-1/patch.txt
@@ -2,7 +2,7 @@
diff -u -N context.txt context.txt
--- context.txt 2007-06-27 08:50:46.000000603 -0400
+++ context.txt 2007-07-11 17:24:45.000000000 -0400
-@@ -1,2 +1,4 @@
+@@ -1,8 +1,10 @@
[b]
[c]
[d]
@@ -15,7 +15,7 @@ diff -u -N context.txt context.txt
[g]
[h]
[Xi]
-@@ -10,3 +10,3 @@
+@@ -10,9 +10,9 @@
[n]
[o]
[p]
diff --git a/tests/org.eclipse.compare.tests/patchdata/2hunks_switch/patch.txt b/tests/org.eclipse.compare.tests/patchdata/2hunks_switch/patch.txt
index 61c9dd7ed..4651b483d 100644
--- a/tests/org.eclipse.compare.tests/patchdata/2hunks_switch/patch.txt
+++ b/tests/org.eclipse.compare.tests/patchdata/2hunks_switch/patch.txt
@@ -2,7 +2,7 @@
diff -u -N context.txt context.txt
--- context.txt 2007-06-27 08:50:46.000000603 -0400
+++ context.txt 2007-07-11 17:24:45.000000000 -0400
-@@ -2,3 +2,3 @@
+@@ -2,9 +2,9 @@
[n]
[o]
[p]
@@ -15,7 +15,7 @@ diff -u -N context.txt context.txt
[t]
[u]
[v]
-@@ -10,3 +10,3 @@
+@@ -10,9 +10,9 @@
[a]
[b]
[c]
diff --git a/tests/org.eclipse.compare.tests/patchdata/2hunks_switch_fail/patch.txt b/tests/org.eclipse.compare.tests/patchdata/2hunks_switch_fail/patch.txt
index c1cf70552..bf4d1ae8b 100644
--- a/tests/org.eclipse.compare.tests/patchdata/2hunks_switch_fail/patch.txt
+++ b/tests/org.eclipse.compare.tests/patchdata/2hunks_switch_fail/patch.txt
@@ -2,7 +2,7 @@
diff -u -N context.txt context.txt
--- context.txt 2007-06-27 08:50:46.000000603 -0400
+++ context.txt 2007-07-11 17:24:45.000000000 -0400
-@@ -1,3 +1,3 @@
+@@ -1,9 +1,9 @@
[r]
[s]
[t]
@@ -12,7 +12,7 @@ diff -u -N context.txt context.txt
+[U1]
+[V1]
+[W1]
-@@ -20,3 +20,3 @@
+@@ -20,9 +20,9 @@
[a]
[b]
[c]
diff --git a/tests/org.eclipse.compare.tests/patchdata/autofuzz-f1/patch.txt b/tests/org.eclipse.compare.tests/patchdata/autofuzz-f1/patch.txt
index 7cfd84546..1f4d56453 100644
--- a/tests/org.eclipse.compare.tests/patchdata/autofuzz-f1/patch.txt
+++ b/tests/org.eclipse.compare.tests/patchdata/autofuzz-f1/patch.txt
@@ -2,7 +2,7 @@
diff -u -N context.txt context.txt
--- context.txt 2007-06-27 08:50:46.000000603 -0400
+++ context.txt 2007-07-11 17:24:45.000000000 -0400
-@@ -1,3 +1,3 @@
+@@ -1,9 +1,9 @@
[X]
[b]
[c]
diff --git a/tests/org.eclipse.compare.tests/patchdata/autofuzz-f2/patch.txt b/tests/org.eclipse.compare.tests/patchdata/autofuzz-f2/patch.txt
index d88d1bbd7..f5f646760 100644
--- a/tests/org.eclipse.compare.tests/patchdata/autofuzz-f2/patch.txt
+++ b/tests/org.eclipse.compare.tests/patchdata/autofuzz-f2/patch.txt
@@ -2,7 +2,7 @@
diff -u -N context.txt context.txt
--- context.txt 2007-06-27 08:50:46.000000603 -0400
+++ context.txt 2007-07-11 17:24:45.000000000 -0400
-@@ -8,3 +8,3 @@
+@@ -8,9 +8,9 @@
[Xh]
[i]
[j]
diff --git a/tests/org.eclipse.compare.tests/patchdata/fuzz1/patch_f1.txt b/tests/org.eclipse.compare.tests/patchdata/fuzz1/patch_f1.txt
index 7cfd84546..1f4d56453 100644
--- a/tests/org.eclipse.compare.tests/patchdata/fuzz1/patch_f1.txt
+++ b/tests/org.eclipse.compare.tests/patchdata/fuzz1/patch_f1.txt
@@ -2,7 +2,7 @@
diff -u -N context.txt context.txt
--- context.txt 2007-06-27 08:50:46.000000603 -0400
+++ context.txt 2007-07-11 17:24:45.000000000 -0400
-@@ -1,3 +1,3 @@
+@@ -1,9 +1,9 @@
[X]
[b]
[c]
diff --git a/tests/org.eclipse.compare.tests/patchdata/fuzz2/patch_f2.txt b/tests/org.eclipse.compare.tests/patchdata/fuzz2/patch_f2.txt
index 42b3051c8..ddd93ca52 100644
--- a/tests/org.eclipse.compare.tests/patchdata/fuzz2/patch_f2.txt
+++ b/tests/org.eclipse.compare.tests/patchdata/fuzz2/patch_f2.txt
@@ -2,7 +2,7 @@
diff -u -N context.txt context.txt
--- context.txt 2007-06-27 08:50:46.000000603 -0400
+++ context.txt 2007-07-11 17:24:45.000000000 -0400
-@@ -1,3 +1,3 @@
+@@ -1,9 +1,9 @@
[Xa]
[Xb]
[c]
diff --git a/tests/org.eclipse.compare.tests/patchdata/shiftdown_f0/patch_f0.txt b/tests/org.eclipse.compare.tests/patchdata/shiftdown_f0/patch_f0.txt
index cc49c04ee..6233a5e18 100644
--- a/tests/org.eclipse.compare.tests/patchdata/shiftdown_f0/patch_f0.txt
+++ b/tests/org.eclipse.compare.tests/patchdata/shiftdown_f0/patch_f0.txt
@@ -2,7 +2,7 @@
diff -u -N context.txt context.txt
--- context.txt 2007-06-27 08:50:46.000000603 -0400
+++ context.txt 2007-07-11 17:24:45.000000000 -0400
-@@ -2,3 +2,3 @@
+@@ -2,9 +2,9 @@
[l]
[m]
[n]
diff --git a/tests/org.eclipse.compare.tests/patchdata/shiftdown_f2/patch_f2.txt b/tests/org.eclipse.compare.tests/patchdata/shiftdown_f2/patch_f2.txt
index 416d30b4b..ee61cc80a 100644
--- a/tests/org.eclipse.compare.tests/patchdata/shiftdown_f2/patch_f2.txt
+++ b/tests/org.eclipse.compare.tests/patchdata/shiftdown_f2/patch_f2.txt
@@ -2,7 +2,7 @@
diff -u -N context.txt context.txt
--- context.txt 2007-06-27 08:50:46.000000603 -0400
+++ context.txt 2007-07-11 17:24:45.000000000 -0400
-@@ -5,3 +5,3 @@
+@@ -5,9 +5,9 @@
[Xl]
[Xm]
[n]

Back to the top