From: James Moger Date: Sat, 7 Mar 2015 16:52:14 +0000 (-0500) Subject: Add links to commit diff and blob diff pages to toggle whitespace setting X-Git-Tag: v1.7.0~1^2~78^2~1 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5d59b9ba3206894198a24807690fba00844c98f7;p=gitblit.git Add links to commit diff and blob diff pages to toggle whitespace setting --- diff --git a/src/main/java/com/gitblit/utils/DiffUtils.java b/src/main/java/com/gitblit/utils/DiffUtils.java index 458a4651..09b8f801 100644 --- a/src/main/java/com/gitblit/utils/DiffUtils.java +++ b/src/main/java/com/gitblit/utils/DiffUtils.java @@ -92,11 +92,11 @@ public class DiffUtils { * 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); + SHOW_WHITESPACE(RawTextComparator.DEFAULT), + IGNORE_WHITESPACE(RawTextComparator.WS_IGNORE_ALL), + IGNORE_LEADING(RawTextComparator.WS_IGNORE_LEADING), + IGNORE_TRAILING(RawTextComparator.WS_IGNORE_TRAILING), + IGNORE_CHANGES(RawTextComparator.WS_IGNORE_CHANGE); public final RawTextComparator textComparator; @@ -104,6 +104,14 @@ public class DiffUtils { this.textComparator = textComparator; } + public DiffComparator getOpposite() { + return this == SHOW_WHITESPACE ? IGNORE_WHITESPACE : SHOW_WHITESPACE; + } + + public String getTranslationKey() { + return "gb." + name().toLowerCase(); + } + public static DiffComparator forName(String name) { for (DiffComparator type : values()) { if (type.name().equalsIgnoreCase(name)) { @@ -371,7 +379,7 @@ public class DiffUtils { break; } df.setRepository(repository); - df.setDiffComparator((comparator == null ? DiffComparator.DEFAULT : comparator).textComparator); + df.setDiffComparator((comparator == null ? DiffComparator.SHOW_WHITESPACE : comparator).textComparator); df.setDetectRenames(true); RevTree commitTree = commit.getTree(); diff --git a/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties b/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties index 10b318dc..d0374200 100644 --- a/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties +++ b/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties @@ -761,4 +761,6 @@ gb.opacityAdjust = Adjust opacity gb.blinkComparator = Blink comparator gb.imgdiffSubtract = Subtract (black = identical) gb.deleteRepositoryHeader = Delete Repository -gb.deleteRepositoryDescription = Deleted repositories will be unrecoverable. \ No newline at end of file +gb.deleteRepositoryDescription = Deleted repositories will be unrecoverable. +gb.show_whitespace = show whitespace +gb.ignore_whitespace = ignore whitespace \ No newline at end of file diff --git a/src/main/java/com/gitblit/wicket/WicketUtils.java b/src/main/java/com/gitblit/wicket/WicketUtils.java index 0684be30..0d48e2be 100644 --- a/src/main/java/com/gitblit/wicket/WicketUtils.java +++ b/src/main/java/com/gitblit/wicket/WicketUtils.java @@ -331,6 +331,31 @@ public class WicketUtils { return new PageParameters(parameterMap); } + public static PageParameters newDiffParameter(String repositoryName, + String objectId, DiffComparator diffComparator) { + Map parameterMap = new HashMap(); + if (StringUtils.isEmpty(objectId)) { + return newRepositoryParameter(repositoryName); + } + parameterMap.put("r", repositoryName); + parameterMap.put("h", objectId); + parameterMap.put("w", "" + diffComparator.ordinal()); + return new PageParameters(parameterMap); + } + + public static PageParameters newDiffParameter(String repositoryName, + String objectId, DiffComparator diffComparator, String blobPath) { + Map parameterMap = new HashMap(); + if (StringUtils.isEmpty(objectId)) { + return newRepositoryParameter(repositoryName); + } + parameterMap.put("r", repositoryName); + parameterMap.put("h", objectId); + parameterMap.put("w", "" + diffComparator.ordinal()); + parameterMap.put("f", blobPath); + return new PageParameters(parameterMap); + } + public static PageParameters newRangeParameter(String repositoryName, String startRange, String endRange) { Map parameterMap = new HashMap(); diff --git a/src/main/java/com/gitblit/wicket/pages/BlobDiffPage.html b/src/main/java/com/gitblit/wicket/pages/BlobDiffPage.html index c6336429..d218436e 100644 --- a/src/main/java/com/gitblit/wicket/pages/BlobDiffPage.html +++ b/src/main/java/com/gitblit/wicket/pages/BlobDiffPage.html @@ -9,7 +9,7 @@ diff --git a/src/main/java/com/gitblit/wicket/pages/BlobDiffPage.java b/src/main/java/com/gitblit/wicket/pages/BlobDiffPage.java index bf84fad9..187e4600 100644 --- a/src/main/java/com/gitblit/wicket/pages/BlobDiffPage.java +++ b/src/main/java/com/gitblit/wicket/pages/BlobDiffPage.java @@ -33,6 +33,7 @@ import com.gitblit.wicket.CacheControl; import com.gitblit.wicket.CacheControl.LastModified; import com.gitblit.wicket.WicketUtils; import com.gitblit.wicket.panels.CommitHeaderPanel; +import com.gitblit.wicket.panels.LinkPanel; import com.gitblit.wicket.panels.PathBreadcrumbsPanel; @CacheControl(LastModified.BOOT) @@ -80,6 +81,8 @@ public class BlobDiffPage extends RepositoryPage { WicketUtils.newObjectParameter(repositoryName, objectId))); add(new BookmarkablePageLink("commitDiffLink", CommitDiffPage.class, WicketUtils.newObjectParameter(repositoryName, objectId))); + add(new LinkPanel("whitespaceLink", null, getString(diffComparator.getOpposite().getTranslationKey()), + BlobDiffPage.class, WicketUtils.newDiffParameter(repositoryName, objectId, diffComparator.getOpposite(), blobPath))); // diff page links add(new BookmarkablePageLink("blameLink", BlamePage.class, diff --git a/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.html b/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.html index 2c35a28c..2e0d57ce 100644 --- a/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.html +++ b/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.html @@ -9,7 +9,7 @@ diff --git a/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java b/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java index 2ec829ee..95580ed1 100644 --- a/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java +++ b/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java @@ -57,9 +57,9 @@ public class CommitDiffPage extends RepositoryPage { public CommitDiffPage(PageParameters params) { super(params); - Repository r = getRepository(); - - RevCommit commit = getCommit(); + final Repository r = getRepository(); + final RevCommit commit = getCommit(); + final DiffComparator diffComparator = WicketUtils.getDiffComparator(params); List parents = new ArrayList(); if (commit.getParentCount() > 0) { @@ -79,6 +79,8 @@ public class CommitDiffPage extends RepositoryPage { WicketUtils.newObjectParameter(repositoryName, objectId))); add(new BookmarkablePageLink("commitLink", CommitPage.class, WicketUtils.newObjectParameter(repositoryName, objectId))); + add(new LinkPanel("whitespaceLink", null, getString(diffComparator.getOpposite().getTranslationKey()), + CommitDiffPage.class, WicketUtils.newDiffParameter(repositoryName, objectId, diffComparator.getOpposite()))); add(new CommitHeaderPanel("commitHeader", repositoryName, commit)); @@ -86,7 +88,6 @@ public class CommitDiffPage extends RepositoryPage { final ImageDiffHandler handler = new ImageDiffHandler(this, repositoryName, parents.isEmpty() ? null : parents.get(0), commit.getName(), imageExtensions); - final DiffComparator diffComparator = WicketUtils.getDiffComparator(params); 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 diff --git a/src/test/java/com/gitblit/tests/DiffUtilsTest.java b/src/test/java/com/gitblit/tests/DiffUtilsTest.java index 34366ffa..c73e4783 100644 --- a/src/test/java/com/gitblit/tests/DiffUtilsTest.java +++ b/src/test/java/com/gitblit/tests/DiffUtilsTest.java @@ -41,7 +41,7 @@ public class DiffUtilsTest extends GitblitUnitTest { Repository repository = GitBlitSuite.getHelloworldRepository(); RevCommit commit = JGitUtils.getCommit(repository, "1d0c2933a4ae69c362f76797d42d6bd182d05176"); - String diff = DiffUtils.getCommitDiff(repository, commit, DiffComparator.DEFAULT, DiffOutputType.PLAIN).content; + String diff = DiffUtils.getCommitDiff(repository, commit, DiffComparator.SHOW_WHITESPACE, DiffOutputType.PLAIN).content; repository.close(); assertTrue(diff != null && diff.length() > 0); String expected = "- system.out.println(\"Hello World\");\n+ System.out.println(\"Hello World\""; @@ -55,7 +55,7 @@ public class DiffUtilsTest extends GitblitUnitTest { "8baf6a833b5579384d9b9ceb8a16b5d0ea2ec4ca"); RevCommit commit = JGitUtils.getCommit(repository, "1d0c2933a4ae69c362f76797d42d6bd182d05176"); - String diff = DiffUtils.getDiff(repository, baseCommit, commit, DiffComparator.DEFAULT, DiffOutputType.PLAIN).content; + String diff = DiffUtils.getDiff(repository, baseCommit, commit, DiffComparator.SHOW_WHITESPACE, DiffOutputType.PLAIN).content; repository.close(); assertTrue(diff != null && diff.length() > 0); String expected = "- system.out.println(\"Hello World\");\n+ System.out.println(\"Hello World\""; @@ -67,7 +67,7 @@ public class DiffUtilsTest extends GitblitUnitTest { Repository repository = GitBlitSuite.getHelloworldRepository(); RevCommit commit = JGitUtils.getCommit(repository, "1d0c2933a4ae69c362f76797d42d6bd182d05176"); - String diff = DiffUtils.getDiff(repository, commit, "java.java", DiffComparator.DEFAULT, DiffOutputType.PLAIN).content; + String diff = DiffUtils.getDiff(repository, commit, "java.java", DiffComparator.SHOW_WHITESPACE, DiffOutputType.PLAIN).content; repository.close(); assertTrue(diff != null && diff.length() > 0); String expected = "- system.out.println(\"Hello World\");\n+ System.out.println(\"Hello World\"";