long running test succeeds using HistogramDiff from jgit

This commit is contained in:
wumpz
2017-04-18 21:27:59 +02:00
parent 295f37ee8c
commit 8c575b63a2
3 changed files with 208 additions and 165 deletions

348
pom.xml
View File

@@ -1,174 +1,200 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.java-diff-utils</groupId>
<artifactId>diffutils</artifactId>
<packaging>jar</packaging>
<version>1.4.0-SNAPSHOT</version>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.java-diff-utils</groupId>
<artifactId>diffutils</artifactId>
<packaging>jar</packaging>
<version>1.4.0-SNAPSHOT</version>
<name>java-diff-utils</name>
<description>The DiffUtils library for computing diffs, applying patches, generationg side-by-side view in Java.</description>
<url>https://github.com/wumpz/java-diff-utils</url>
<inceptionYear>2009</inceptionYear>
<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>9</version>
</parent>
<scm>
<connection>scm:git:https://github.com/wumpz/java-diff-utils.git</connection>
<developerConnection>scm:git:ssh://git@github.com:wumpz/java-diff-utils.git</developerConnection>
<url>https://github.com/wumpz/java-diff-utils.git</url>
</scm>
<name>java-diff-utils</name>
<description>The DiffUtils library for computing diffs, applying patches, generationg side-by-side view in Java.</description>
<url>https://github.com/wumpz/java-diff-utils</url>
<inceptionYear>2009</inceptionYear>
<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>9</version>
</parent>
<scm>
<connection>scm:git:https://github.com/wumpz/java-diff-utils.git</connection>
<developerConnection>scm:git:ssh://git@github.com:wumpz/java-diff-utils.git</developerConnection>
<url>https://github.com/wumpz/java-diff-utils.git</url>
</scm>
<issueManagement>
<system>GitHub Issues</system>
<url>https://github.com/wumpz/java-diff-utils/issues</url>
</issueManagement>
<issueManagement>
<system>GitHub Issues</system>
<url>https://github.com/wumpz/java-diff-utils/issues</url>
</issueManagement>
<organization>
<name>java-diff-utils</name>
</organization>
<organization>
<name>java-diff-utils</name>
</organization>
<developers>
<developer>
<name>Tobias Warneke</name>
<email>t.warneke@gmx.net</email>
</developer>
<developer>
<name>Dmitry Naumenko</name>
<email>dm.naumenko@gmail.com</email>
</developer>
<developer>
<name>Juanco Anez</name>
<email>juanco@suigeneris.org</email>
</developer>
</developers>
<developers>
<developer>
<name>Tobias Warneke</name>
<email>t.warneke@gmx.net</email>
</developer>
<developer>
<name>Dmitry Naumenko</name>
<email>dm.naumenko@gmail.com</email>
</developer>
<developer>
<name>Juanco Anez</name>
<email>juanco@suigeneris.org</email>
</developer>
</developers>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
<comments>A business-friendly OSS license</comments>
</license>
</licenses>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
<comments>A business-friendly OSS license</comments>
</license>
</licenses>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<type>jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
<version>4.4.1.201607150455-r</version>
</dependency>
</dependencies>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<type>jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
<version>4.4.1.201607150455-r</version>
<exclusions>
<exclusion>
<groupId>com.googlecode.javaewah</groupId>
<artifactId>JavaEWAH</artifactId>
</exclusion>
<exclusion>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</exclusion>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</exclusion>
<exclusion>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- Make this JAR OSGi ready -->
<!-- We want to keep packaging type as jar. Therefore we need to customize the MANIFEST.MF.
See http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html
-->
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.4</version>
<configuration>
<additionalparam>${javadoc.opts}</additionalparam>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!--
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>1.12</version>
<configuration>
<verbose>false</verbose>
<addJavaLicenseAfterPackage>false</addJavaLicenseAfterPackage>
<canUpdateDescription>false</canUpdateDescription>
</configuration>
<executions>
<execution>
<id>first</id>
<goals>
<goal>update-file-header</goal>
</goals>
<phase>process-sources</phase>
<configuration>
<licenseName>apache_v2</licenseName>
<roots>
<root>src/main/java</root>
</roots>
</configuration>
</execution>
</executions>
</plugin>
-->
</plugins>
</build>
<profiles>
<profile>
<id>doclint-java8-disable</id>
<activation>
<jdk>[1.8,)</jdk>
</activation>
<properties>
<javadoc.opts>-Xdoclint:none</javadoc.opts>
</properties>
</profile>
</profiles>
<!-- Make this JAR OSGi ready -->
<!-- We want to keep packaging type as jar. Therefore we need to customize the MANIFEST.MF.
See http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html
-->
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.4</version>
<configuration>
<additionalparam>${javadoc.opts}</additionalparam>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!--
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>1.12</version>
<configuration>
<verbose>false</verbose>
<addJavaLicenseAfterPackage>false</addJavaLicenseAfterPackage>
<canUpdateDescription>false</canUpdateDescription>
</configuration>
<executions>
<execution>
<id>first</id>
<goals>
<goal>update-file-header</goal>
</goals>
<phase>process-sources</phase>
<configuration>
<licenseName>apache_v2</licenseName>
<roots>
<root>src/main/java</root>
</roots>
</configuration>
</execution>
</executions>
</plugin>
-->
</plugins>
</build>
<profiles>
<profile>
<id>doclint-java8-disable</id>
<activation>
<jdk>[1.8,)</jdk>
</activation>
<properties>
<javadoc.opts>-Xdoclint:none</javadoc.opts>
</properties>
</profile>
</profiles>
</project>

View File

@@ -30,7 +30,9 @@ import org.eclipse.jgit.diff.Sequence;
import org.eclipse.jgit.diff.SequenceComparator;
/**
*
* HistorgramDiff using JGit - Library. This one is much more performant than the
* orginal Myers implementation.
*
* @author toben
*/
public class JGitDiff<T> implements DiffAlgorithm<T> {
@@ -41,8 +43,6 @@ public class JGitDiff<T> implements DiffAlgorithm<T> {
diffList.addAll(new HistogramDiff().diff(new DataListComparator<>(), new DataList<>(original), new DataList<>(revised)));
Patch<T> patch = new Patch<>();
for (Edit edit : diffList) {
System.out.println(edit);
Chunk<T> orgChunk = new Chunk<>(edit.getBeginA(), original.subList(edit.getBeginA(), edit.getEndA()));
Chunk<T> revChunk = new Chunk<>(edit.getBeginA(), revised.subList(edit.getBeginB(), edit.getEndB()));
switch (edit.getType()) {

View File

@@ -15,12 +15,15 @@
*/
package difflib.algorithm.jgit;
import difflib.DiffUtils;
import static difflib.DiffUtilsTest.readStringListFromInputStream;
import difflib.TestConstants;
import difflib.algorithm.DiffException;
import difflib.patch.Patch;
import difflib.patch.PatchFailedException;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.zip.ZipFile;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
@@ -70,4 +73,18 @@ public class JGitDiffTest {
assertEquals(revList, patched);
}
@Test
public void testPossibleDiffHangOnLargeDatasetDnaumenkoIssue26() throws IOException, DiffException, PatchFailedException {
ZipFile zip = new ZipFile(TestConstants.MOCK_FOLDER + "/large_dataset1.zip");
List<String> original = readStringListFromInputStream(zip.getInputStream(zip.getEntry("ta")));
List<String> revised = readStringListFromInputStream(zip.getInputStream(zip.getEntry("tb")));
Patch<String> patch = new JGitDiff().diff(original, revised);
assertEquals(34, patch.getDeltas().size());
List<String> created = patch.applyTo(original);
assertArrayEquals(revised.toArray(), created.toArray());
}
}