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