From 049827d7080201fe24f2728b26d681434327f72a Mon Sep 17 00:00:00 2001 From: Christian Halstrick Date: Fri, 26 Nov 2010 00:30:08 +0100 Subject: Make diff algorithm configurable The diff algorithm which is used by Merge, Cherry-Pick, Rebase should be configurable. A new configuration parameter "diff.algorithm" is introduced which currently accepts the values "myers" or "histogram". Based on this parameter for example the ResolveMerger will choose a diff algorithm. The reason for this is bug 331078. This bug shows that JGit is more compatible with C Git when histogram diff is in place. But since histogram diff is quite new we need an easy way to fall back to Myers diff. Bug: 331078 Change-Id: I2549c992e478d991c61c9508ad826d1a9e539ae3 Signed-off-by: Christian Halstrick Signed-off-by: Philipp Thun --- .../src/org/eclipse/jgit/diff/DiffAlgorithm.java | 32 ++++++++++++++++++++++ .../src/org/eclipse/jgit/diff/DiffFormatter.java | 10 ++++++- 2 files changed, 41 insertions(+), 1 deletion(-) (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/diff') diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffAlgorithm.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffAlgorithm.java index f6859a29c3..b20e3258b6 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffAlgorithm.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffAlgorithm.java @@ -53,6 +53,38 @@ package org.eclipse.jgit.diff; * a unique instance per thread. */ public abstract class DiffAlgorithm { + /** + * Supported diff algorithm + */ + public enum SupportedAlgorithm { + /** + * Myers diff algorithm + */ + MYERS, + + /** + * Histogram diff algorithm + */ + HISTOGRAM + } + + /** + * @param alg + * the diff algorithm for which an implementation should be + * returned + * @return an implementation of the specified diff algorithm + */ + public static DiffAlgorithm getAlgorithm(SupportedAlgorithm alg) { + switch (alg) { + case MYERS: + return MyersDiff.INSTANCE; + case HISTOGRAM: + return new HistogramDiff(); + default: + throw new IllegalArgumentException(); + } + } + /** * Compare two sequences and identify a list of edits between them. * diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java index be9a86eda9..fa0cb9c473 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java @@ -63,6 +63,7 @@ import java.util.Collections; import java.util.List; import org.eclipse.jgit.JGitText; +import org.eclipse.jgit.diff.DiffAlgorithm.SupportedAlgorithm; import org.eclipse.jgit.diff.DiffEntry.ChangeType; import org.eclipse.jgit.errors.AmbiguousObjectException; import org.eclipse.jgit.errors.CorruptObjectException; @@ -70,6 +71,7 @@ import org.eclipse.jgit.errors.LargeObjectException; import org.eclipse.jgit.errors.MissingObjectException; import org.eclipse.jgit.lib.AbbreviatedObjectId; import org.eclipse.jgit.lib.AnyObjectId; +import org.eclipse.jgit.lib.ConfigConstants; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.ObjectId; @@ -118,7 +120,7 @@ public class DiffFormatter { private int abbreviationLength = 7; - private DiffAlgorithm diffAlgorithm = new HistogramDiff(); + private DiffAlgorithm diffAlgorithm; private RawTextComparator comparator = RawTextComparator.DEFAULT; @@ -178,6 +180,12 @@ public class DiffFormatter { setNewPrefix(""); } setDetectRenames(dc.isRenameDetectionEnabled()); + + diffAlgorithm = DiffAlgorithm.getAlgorithm(db.getConfig().getEnum( + ConfigConstants.CONFIG_DIFF_SECTION, null, + ConfigConstants.CONFIG_KEY_ALGORITHM, + SupportedAlgorithm.HISTOGRAM)); + } /** -- cgit v1.2.3