}\r
}\r
\r
+ /**\r
+ * Enumeration for the diff comparator types.\r
+ */\r
+ public static enum DiffComparator {\r
+ DEFAULT(RawTextComparator.DEFAULT),\r
+ WS_IGNORE_ALL(RawTextComparator.WS_IGNORE_ALL),\r
+ WS_IGNORE_LEADING(RawTextComparator.WS_IGNORE_LEADING),\r
+ WS_IGNORE_TRAILING(RawTextComparator.WS_IGNORE_TRAILING),\r
+ WS_IGNORE_CHANGE(RawTextComparator.WS_IGNORE_CHANGE);\r
+\r
+ public final RawTextComparator textComparator;\r
+\r
+ DiffComparator(RawTextComparator textComparator) {\r
+ this.textComparator = textComparator;\r
+ }\r
+\r
+ public static DiffComparator forName(String name) {\r
+ for (DiffComparator type : values()) {\r
+ if (type.name().equalsIgnoreCase(name)) {\r
+ return type;\r
+ }\r
+ }\r
+ return null;\r
+ }\r
+ }\r
+\r
/**\r
* Encapsulates the output of a diff.\r
*/\r
*\r
* @param repository\r
* @param commit\r
+ * @param comparator\r
* @param outputType\r
* @return the diff\r
*/\r
public static DiffOutput getCommitDiff(Repository repository, RevCommit commit,\r
- DiffOutputType outputType) {\r
- return getDiff(repository, null, commit, null, outputType);\r
+ DiffComparator comparator, DiffOutputType outputType) {\r
+ return getDiff(repository, null, commit, null, comparator, outputType);\r
}\r
\r
/**\r
*\r
* @param repository\r
* @param commit\r
+ * @param comparator\r
* @param outputType\r
* @param handler\r
* to use for rendering binary diffs if {@code outputType} is {@link DiffOutputType#HTML HTML}.\r
* @return the diff\r
*/\r
public static DiffOutput getCommitDiff(Repository repository, RevCommit commit,\r
- DiffOutputType outputType, BinaryDiffHandler handler) {\r
- return getDiff(repository, null, commit, null, outputType, handler);\r
+ DiffComparator comparator, DiffOutputType outputType, BinaryDiffHandler handler) {\r
+ return getDiff(repository, null, commit, null, comparator, outputType, handler);\r
}\r
\r
\r
* @param repository\r
* @param commit\r
* @param path\r
+ * @param comparator\r
* @param outputType\r
* @return the diff\r
*/\r
public static DiffOutput getDiff(Repository repository, RevCommit commit, String path,\r
- DiffOutputType outputType) {\r
- return getDiff(repository, null, commit, path, outputType);\r
+ DiffComparator comparator, DiffOutputType outputType) {\r
+ return getDiff(repository, null, commit, path, comparator, outputType);\r
}\r
\r
/**\r
* @param repository\r
* @param commit\r
* @param path\r
+ * @param comparator\r
* @param outputType\r
* @param handler\r
* to use for rendering binary diffs if {@code outputType} is {@link DiffOutputType#HTML HTML}.\r
* @return the diff\r
*/\r
public static DiffOutput getDiff(Repository repository, RevCommit commit, String path,\r
- DiffOutputType outputType, BinaryDiffHandler handler) {\r
- return getDiff(repository, null, commit, path, outputType, handler);\r
+ DiffComparator comparator, DiffOutputType outputType, BinaryDiffHandler handler) {\r
+ return getDiff(repository, null, commit, path, comparator, outputType, handler);\r
}\r
\r
/**\r
* @param repository\r
* @param baseCommit\r
* @param commit\r
+ * @param comparator\r
* @param outputType\r
* @return the diff\r
*/\r
public static DiffOutput getDiff(Repository repository, RevCommit baseCommit, RevCommit commit,\r
- DiffOutputType outputType) {\r
- return getDiff(repository, baseCommit, commit, null, outputType);\r
+ DiffComparator comparator, DiffOutputType outputType) {\r
+ return getDiff(repository, baseCommit, commit, null, comparator, outputType);\r
}\r
\r
/**\r
* @param repository\r
* @param baseCommit\r
* @param commit\r
+ * @param comparator\r
* @param outputType\r
* @param handler\r
* to use for rendering binary diffs if {@code outputType} is {@link DiffOutputType#HTML HTML}.\r
* @return the diff\r
*/\r
public static DiffOutput getDiff(Repository repository, RevCommit baseCommit, RevCommit commit,\r
- DiffOutputType outputType, BinaryDiffHandler handler) {\r
- return getDiff(repository, baseCommit, commit, null, outputType, handler);\r
+ DiffComparator comparator, DiffOutputType outputType, BinaryDiffHandler handler) {\r
+ return getDiff(repository, baseCommit, commit, null, comparator, outputType, handler);\r
}\r
\r
/**\r
* if the path is specified, the diff is restricted to that file\r
* or folder. if unspecified, the diff is for the entire commit.\r
* @param outputType\r
+ * @param diffComparator\r
* @return the diff\r
*/\r
public static DiffOutput getDiff(Repository repository, RevCommit baseCommit, RevCommit commit,\r
- String path, DiffOutputType outputType) {\r
- return getDiff(repository, baseCommit, commit, path, outputType, null);\r
+ String path, DiffComparator diffComparator, DiffOutputType outputType) {\r
+ return getDiff(repository, baseCommit, commit, path, diffComparator, outputType, null);\r
}\r
\r
/**\r
* @param path\r
* if the path is specified, the diff is restricted to that file\r
* or folder. if unspecified, the diff is for the entire commit.\r
+ * @param comparator\r
* @param outputType\r
* @param handler\r
* to use for rendering binary diffs if {@code outputType} is {@link DiffOutputType#HTML HTML}.\r
* May be {@code null}, resulting in the default behavior.\r
* @return the diff\r
*/\r
- public static DiffOutput getDiff(Repository repository, RevCommit baseCommit, RevCommit commit, String path, DiffOutputType outputType,\r
- final BinaryDiffHandler handler) {\r
+ public static DiffOutput getDiff(Repository repository, RevCommit baseCommit, RevCommit commit, String path,\r
+ DiffComparator comparator, DiffOutputType outputType, final BinaryDiffHandler handler) {\r
DiffStat stat = null;\r
String diff = null;\r
try {\r
ByteArrayOutputStream os = null;\r
- RawTextComparator cmp = RawTextComparator.DEFAULT;\r
+\r
DiffFormatter df;\r
switch (outputType) {\r
case HTML:\r
break;\r
}\r
df.setRepository(repository);\r
- df.setDiffComparator(cmp);\r
+ df.setDiffComparator((comparator == null ? DiffComparator.DEFAULT : comparator).textComparator);\r
df.setDetectRenames(true);\r
\r
RevTree commitTree = commit.getTree();\r
\r
import com.gitblit.Keys;\r
import com.gitblit.utils.DiffUtils;\r
+import com.gitblit.utils.DiffUtils.DiffComparator;\r
import com.gitblit.utils.DiffUtils.DiffOutputType;\r
import com.gitblit.utils.JGitUtils;\r
import com.gitblit.utils.StringUtils;\r
\r
final String blobPath = WicketUtils.getPath(params);\r
final String baseObjectId = WicketUtils.getBaseObjectId(params);\r
+ final DiffComparator diffComparator = DiffComparator.WS_IGNORE_ALL;\r
\r
Repository r = getRepository();\r
RevCommit commit = getCommit();\r
RevCommit parent = commit.getParentCount() == 0 ? null : commit.getParent(0);\r
ImageDiffHandler handler = new ImageDiffHandler(this, repositoryName,\r
parent.getName(), commit.getName(), imageExtensions);\r
- diff = DiffUtils.getDiff(r, commit, blobPath, DiffOutputType.HTML, handler).content;\r
+ diff = DiffUtils.getDiff(r, commit, blobPath, diffComparator, DiffOutputType.HTML, handler).content;\r
if (handler.getImgDiffCount() > 0) {\r
addBottomScript("scripts/imgdiff.js"); // Tiny support script for image diffs\r
}\r
RevCommit baseCommit = JGitUtils.getCommit(r, baseObjectId);\r
ImageDiffHandler handler = new ImageDiffHandler(this, repositoryName,\r
baseCommit.getName(), commit.getName(), imageExtensions);\r
- diff = DiffUtils.getDiff(r, baseCommit, commit, blobPath, DiffOutputType.HTML, handler).content;\r
+ diff = DiffUtils.getDiff(r, baseCommit, commit, blobPath, DiffComparator.WS_IGNORE_ALL, DiffOutputType.HTML, handler).content;\r
if (handler.getImgDiffCount() > 0) {\r
addBottomScript("scripts/imgdiff.js"); // Tiny support script for image diffs\r
}\r
\r
import com.gitblit.models.AnnotatedLine;\r
import com.gitblit.utils.DiffUtils;\r
+import com.gitblit.utils.DiffUtils.DiffComparator;\r
import com.gitblit.utils.DiffUtils.DiffOutputType;\r
import com.gitblit.utils.JGitUtils;\r
\r
Repository repository = GitBlitSuite.getHelloworldRepository();\r
RevCommit commit = JGitUtils.getCommit(repository,\r
"1d0c2933a4ae69c362f76797d42d6bd182d05176");\r
- String diff = DiffUtils.getCommitDiff(repository, commit, DiffOutputType.PLAIN).content;\r
+ String diff = DiffUtils.getCommitDiff(repository, commit, DiffComparator.DEFAULT, DiffOutputType.PLAIN).content;\r
repository.close();\r
assertTrue(diff != null && diff.length() > 0);\r
String expected = "- system.out.println(\"Hello World\");\n+ System.out.println(\"Hello World\"";\r
"8baf6a833b5579384d9b9ceb8a16b5d0ea2ec4ca");\r
RevCommit commit = JGitUtils.getCommit(repository,\r
"1d0c2933a4ae69c362f76797d42d6bd182d05176");\r
- String diff = DiffUtils.getDiff(repository, baseCommit, commit, DiffOutputType.PLAIN).content;\r
+ String diff = DiffUtils.getDiff(repository, baseCommit, commit, DiffComparator.DEFAULT, DiffOutputType.PLAIN).content;\r
repository.close();\r
assertTrue(diff != null && diff.length() > 0);\r
String expected = "- system.out.println(\"Hello World\");\n+ System.out.println(\"Hello World\"";\r
Repository repository = GitBlitSuite.getHelloworldRepository();\r
RevCommit commit = JGitUtils.getCommit(repository,\r
"1d0c2933a4ae69c362f76797d42d6bd182d05176");\r
- String diff = DiffUtils.getDiff(repository, commit, "java.java", DiffOutputType.PLAIN).content;\r
+ String diff = DiffUtils.getDiff(repository, commit, "java.java", DiffComparator.DEFAULT, DiffOutputType.PLAIN).content;\r
repository.close();\r
assertTrue(diff != null && diff.length() > 0);\r
String expected = "- system.out.println(\"Hello World\");\n+ System.out.println(\"Hello World\"";\r