From 136f18266e4f3e3129841a385c9ba4e82e321c86 Mon Sep 17 00:00:00 2001 From: Nadya Zabrodina Date: Thu, 26 Oct 2017 15:03:00 +0300 Subject: [PATCH] patch: extend user name matching pattern, add tests --- .../patchHeaderWithDoubleSurname/test.patch | 27 +++++++++++++++++++ .../patchHeaderWithLongName/test.patch | 27 +++++++++++++++++++ .../diff/impl/patch/PatchReaderTest.kt | 12 +++++++++ .../impl/patch/PatchFileHeaderParser.java | 2 +- 4 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 platform/platform-tests/testData/diff/patchReader/patchHeaderWithDoubleSurname/test.patch create mode 100644 platform/platform-tests/testData/diff/patchReader/patchHeaderWithLongName/test.patch diff --git a/platform/platform-tests/testData/diff/patchReader/patchHeaderWithDoubleSurname/test.patch b/platform/platform-tests/testData/diff/patchReader/patchHeaderWithDoubleSurname/test.patch new file mode 100644 index 000000000000..877566dd70ea --- /dev/null +++ b/platform/platform-tests/testData/diff/patchReader/patchHeaderWithDoubleSurname/test.patch @@ -0,0 +1,27 @@ +From d48bebc211cc216aaa78bdf25d7f0b0143d6333b Mon Sep 17 00:00:00 2001 +From: D D-D +Date: Wed, 12 Oct 2016 19:03:51 -0700 +Subject: [PATCH 1/5] Subject line + +--- + +mode change 100755 => 100644 l.php + +diff --git a/l.php b/l.php + old mode 100755 + new mode 100644 +diff --git a/community/FileDropHandler.java b/community/FileDropHandler.java +--- a/community/FileDropHandler.java ++++ b/community/FileDropHandler.java +@@ -1,9 +1,11 @@ + package com.intellij.openapi.fileEditor.impl.text; + + import com.intellij.ide.dnd.FileCopyPasteUtil; ++import com.intellij.openapi.editor.CustomFileDropHandler; + import com.intellij.openapi.editor.Document; + import com.intellij.openapi.editor.Editor; + import com.intellij.openapi.editor.EditorDropHandler; ++import com.intellij.openapi.extensions.Extensions; + import com.intellij.openapi.fileEditor.*; + import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx; + import com.intellij.openapi.fileEditor.impl.EditorWindow; diff --git a/platform/platform-tests/testData/diff/patchReader/patchHeaderWithLongName/test.patch b/platform/platform-tests/testData/diff/patchReader/patchHeaderWithLongName/test.patch new file mode 100644 index 000000000000..b617fd3d32ad --- /dev/null +++ b/platform/platform-tests/testData/diff/patchReader/patchHeaderWithLongName/test.patch @@ -0,0 +1,27 @@ +From d48bebc211cc216aaa78bdf25d7f0b0143d6333b Mon Sep 17 00:00:00 2001 +From: very long author-surname +Date: Wed, 12 Oct 2016 19:03:51 -0700 +Subject: [PATCH 1/5] Subject line + +--- + +mode change 100755 => 100644 l.php + +diff --git a/l.php b/l.php + old mode 100755 + new mode 100644 +diff --git a/community/FileDropHandler.java b/community/FileDropHandler.java +--- a/community/FileDropHandler.java ++++ b/community/FileDropHandler.java +@@ -1,9 +1,11 @@ + package com.intellij.openapi.fileEditor.impl.text; + + import com.intellij.ide.dnd.FileCopyPasteUtil; ++import com.intellij.openapi.editor.CustomFileDropHandler; + import com.intellij.openapi.editor.Document; + import com.intellij.openapi.editor.Editor; + import com.intellij.openapi.editor.EditorDropHandler; ++import com.intellij.openapi.extensions.Extensions; + import com.intellij.openapi.fileEditor.*; + import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx; + import com.intellij.openapi.fileEditor.impl.EditorWindow; diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/diff/impl/patch/PatchReaderTest.kt b/platform/platform-tests/testSrc/com/intellij/openapi/diff/impl/patch/PatchReaderTest.kt index d554215f32f2..20775fef4af6 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/diff/impl/patch/PatchReaderTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/openapi/diff/impl/patch/PatchReaderTest.kt @@ -27,6 +27,8 @@ import java.io.File class PatchReaderTest : PlatformTestCase() { private val author = VcsUserImpl("D D", "aaaa@gmail.com") + private val doubleSurname = VcsUserImpl("D D-D", "aaaa@gmail.com") + private val longName = VcsUserImpl("very long author-surname", "aaaa@gmail.com") private val baseRevision = "d48bebc211cc216aaa78bdf25d7f0b0143d6333b" private val subjectLine = "Subject line" @@ -85,6 +87,16 @@ class PatchReaderTest : PlatformTestCase() { TestCase.assertEquals(PatchFileHeaderInfo(subjectLine, author, baseRevision), read().patchFileInfo) } + @Throws(Exception::class) + fun testPatchHeaderWithDoubleSurname() { + TestCase.assertEquals(PatchFileHeaderInfo(subjectLine, doubleSurname, baseRevision), read().patchFileInfo) + } + + @Throws(Exception::class) + fun testPatchHeaderWithLongName() { + TestCase.assertEquals(PatchFileHeaderInfo(subjectLine, longName, baseRevision), read().patchFileInfo) + } + private fun read(): PatchReader { val testDataPath = PlatformTestUtil.getPlatformTestDataPath() + "diff/patchReader/" + getTestName(true) PsiTestUtil.createTestProjectStructure(myProject, myModule, testDataPath, PlatformTestCase.myFilesToDelete) diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/PatchFileHeaderParser.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/PatchFileHeaderParser.java index b59d4754a4c5..ef74fa2ec3b1 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/PatchFileHeaderParser.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/PatchFileHeaderParser.java @@ -29,7 +29,7 @@ import static com.intellij.openapi.diff.impl.patch.PatchReader.HASH_PATTERN; public class PatchFileHeaderParser { @NonNls private static final Pattern ourBaseRevisionPattern = Pattern.compile("From\\s+(" + HASH_PATTERN + ")\\s+.*"); - @NonNls private static final Pattern ourAuthorPattern = Pattern.compile("From:\\s+(\\w+[\\W_]\\w+)\\s*(?:<(.*)>\\s*)?"); + @NonNls private static final Pattern ourAuthorPattern = Pattern.compile("From:\\s+(.*?)\\s*(?:<(.*)>\\s*)?"); @NonNls private static final Pattern ourSubjectPattern = Pattern.compile("Subject:(?:\\s+\\[PATCH.*])?\\s*(.+)"); @NonNls private static final Pattern ourHeaderEndMarker = Pattern.compile("---\\s*");