]> source.dussan.org Git - gitblit.git/commitdiff
Add links to commit diff and blob diff pages to toggle whitespace setting
authorJames Moger <james.moger@gitblit.com>
Sat, 7 Mar 2015 16:52:14 +0000 (11:52 -0500)
committerJames Moger <james.moger@gitblit.com>
Sat, 7 Mar 2015 16:52:14 +0000 (11:52 -0500)
src/main/java/com/gitblit/utils/DiffUtils.java
src/main/java/com/gitblit/wicket/GitBlitWebApp.properties
src/main/java/com/gitblit/wicket/WicketUtils.java
src/main/java/com/gitblit/wicket/pages/BlobDiffPage.html
src/main/java/com/gitblit/wicket/pages/BlobDiffPage.java
src/main/java/com/gitblit/wicket/pages/CommitDiffPage.html
src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java
src/test/java/com/gitblit/tests/DiffUtilsTest.java

index 458a465146808be616e56d1a3b0cb31bd38e31b4..09b8f8012e7358272fb804186ff928bfcd5dcd00 100644 (file)
@@ -92,11 +92,11 @@ public class DiffUtils {
         * 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
+               SHOW_WHITESPACE(RawTextComparator.DEFAULT),\r
+               IGNORE_WHITESPACE(RawTextComparator.WS_IGNORE_ALL),\r
+               IGNORE_LEADING(RawTextComparator.WS_IGNORE_LEADING),\r
+               IGNORE_TRAILING(RawTextComparator.WS_IGNORE_TRAILING),\r
+               IGNORE_CHANGES(RawTextComparator.WS_IGNORE_CHANGE);\r
 \r
                public final RawTextComparator textComparator;\r
 \r
@@ -104,6 +104,14 @@ public class DiffUtils {
                        this.textComparator = textComparator;\r
                }\r
 \r
+               public DiffComparator getOpposite() {\r
+                       return this == SHOW_WHITESPACE ? IGNORE_WHITESPACE : SHOW_WHITESPACE;\r
+               }\r
+\r
+               public String getTranslationKey() {\r
+                       return "gb." + name().toLowerCase();\r
+               }\r
+\r
                public static DiffComparator forName(String name) {\r
                        for (DiffComparator type : values()) {\r
                                if (type.name().equalsIgnoreCase(name)) {\r
@@ -371,7 +379,7 @@ public class DiffUtils {
                                break;\r
                        }\r
                        df.setRepository(repository);\r
-                       df.setDiffComparator((comparator == null ? DiffComparator.DEFAULT : comparator).textComparator);\r
+                       df.setDiffComparator((comparator == null ? DiffComparator.SHOW_WHITESPACE : comparator).textComparator);\r
                        df.setDetectRenames(true);\r
 \r
                        RevTree commitTree = commit.getTree();\r
index 10b318dc08fac8eaadcc2be489ac0fc2a1295bf3..d037420061b683615981589ae89683128e528228 100644 (file)
@@ -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
index 0684be3024fe0f70ac80dea7476c08edb7615a1f..0d48e2beb412f2d4f1061f3347a819cfc6c25f79 100644 (file)
@@ -331,6 +331,31 @@ public class WicketUtils {
                return new PageParameters(parameterMap);\r
        }\r
 \r
+       public static PageParameters newDiffParameter(String repositoryName,\r
+                       String objectId, DiffComparator diffComparator) {\r
+               Map<String, String> parameterMap = new HashMap<String, String>();\r
+               if (StringUtils.isEmpty(objectId)) {\r
+                       return newRepositoryParameter(repositoryName);\r
+               }\r
+               parameterMap.put("r", repositoryName);\r
+               parameterMap.put("h", objectId);\r
+               parameterMap.put("w", "" + diffComparator.ordinal());\r
+               return new PageParameters(parameterMap);\r
+       }\r
+\r
+       public static PageParameters newDiffParameter(String repositoryName,\r
+                       String objectId, DiffComparator diffComparator, String blobPath) {\r
+               Map<String, String> parameterMap = new HashMap<String, String>();\r
+               if (StringUtils.isEmpty(objectId)) {\r
+                       return newRepositoryParameter(repositoryName);\r
+               }\r
+               parameterMap.put("r", repositoryName);\r
+               parameterMap.put("h", objectId);\r
+               parameterMap.put("w", "" + diffComparator.ordinal());\r
+               parameterMap.put("f", blobPath);\r
+               return new PageParameters(parameterMap);\r
+       }\r
+\r
        public static PageParameters newRangeParameter(String repositoryName,\r
                        String startRange, String endRange) {\r
                Map<String, String> parameterMap = new HashMap<String, String>();\r
index c63364290abc29f755afc578b8fcb3220af88961..d218436ef1ab8e0333a2c77a31cd77b18f0a88ac 100644 (file)
@@ -9,7 +9,7 @@
        \r
        <!-- blob nav links --> \r
        <div class="page_nav2">\r
-               <a wicket:id="blameLink"><wicket:message key="gb.blame"></wicket:message></a> | <a wicket:id="historyLink"><wicket:message key="gb.history"></wicket:message></a> | <a wicket:id="patchLink"><wicket:message key="gb.patch"></wicket:message></a> | <a wicket:id="commitLink"><wicket:message key="gb.commit"></wicket:message></a> | <a wicket:id="commitDiffLink"><wicket:message key="gb.commitdiff"></wicket:message></a>\r
+               <a wicket:id="blameLink"><wicket:message key="gb.blame"></wicket:message></a> | <a wicket:id="historyLink"><wicket:message key="gb.history"></wicket:message></a> | <a wicket:id="patchLink"><wicket:message key="gb.patch"></wicket:message></a> | <a wicket:id="commitLink"><wicket:message key="gb.commit"></wicket:message></a> | <a wicket:id="commitDiffLink"><wicket:message key="gb.commitdiff"></wicket:message></a> | <a wicket:id="whitespaceLink"></a>\r
        </div>  \r
        \r
        <!-- commit header -->\r
index bf84fad939a3cec18971996a0f414d424756d1ff..187e4600d4e49310f9eb3d82a0420d6d9551c800 100644 (file)
@@ -33,6 +33,7 @@ import com.gitblit.wicket.CacheControl;
 import com.gitblit.wicket.CacheControl.LastModified;\r
 import com.gitblit.wicket.WicketUtils;\r
 import com.gitblit.wicket.panels.CommitHeaderPanel;\r
+import com.gitblit.wicket.panels.LinkPanel;\r
 import com.gitblit.wicket.panels.PathBreadcrumbsPanel;\r
 \r
 @CacheControl(LastModified.BOOT)\r
@@ -80,6 +81,8 @@ public class BlobDiffPage extends RepositoryPage {
                                WicketUtils.newObjectParameter(repositoryName, objectId)));\r
                add(new BookmarkablePageLink<Void>("commitDiffLink", CommitDiffPage.class,\r
                                WicketUtils.newObjectParameter(repositoryName, objectId)));\r
+               add(new LinkPanel("whitespaceLink", null, getString(diffComparator.getOpposite().getTranslationKey()),\r
+                               BlobDiffPage.class, WicketUtils.newDiffParameter(repositoryName, objectId, diffComparator.getOpposite(), blobPath)));\r
 \r
                // diff page links\r
                add(new BookmarkablePageLink<Void>("blameLink", BlamePage.class,\r
index 2c35a28c97aae818c912cdb2f625665f4e1c1dfe..2e0d57ce9f40dc63473901f388056156a70fdd12 100644 (file)
@@ -9,7 +9,7 @@
 \r
        <!-- commitdiff nav links -->   \r
        <div class="page_nav2">\r
-               <wicket:message key="gb.parent"></wicket:message>: <span wicket:id="parentLink">[parent link]</span> | <a wicket:id="patchLink"><wicket:message key="gb.patch"></wicket:message></a> | <a wicket:id="commitLink"><wicket:message key="gb.commit"></wicket:message></a>\r
+               <wicket:message key="gb.parent"></wicket:message>: <span wicket:id="parentLink">[parent link]</span> | <a wicket:id="patchLink"><wicket:message key="gb.patch"></wicket:message></a> | <a wicket:id="commitLink"><wicket:message key="gb.commit"></wicket:message></a> | <a wicket:id="whitespaceLink"></a>\r
        </div>  \r
        \r
        <!-- commit header -->\r
index 2ec829eee30b0b297f724ef875ce56de8220dae3..95580ed154aa23693661acae3b2cdeb6a218c510 100644 (file)
@@ -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<String> parents = new ArrayList<String>();
                if (commit.getParentCount() > 0) {
@@ -79,6 +79,8 @@ public class CommitDiffPage extends RepositoryPage {
                                WicketUtils.newObjectParameter(repositoryName, objectId)));
                add(new BookmarkablePageLink<Void>("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
index 34366ffa3c0c743d7de0a23a0894798e7d8cbbc1..c73e4783dc6953f5facf323512be0aec5dd2924c 100644 (file)
@@ -41,7 +41,7 @@ public class DiffUtilsTest extends GitblitUnitTest {
                Repository repository = GitBlitSuite.getHelloworldRepository();\r
                RevCommit commit = JGitUtils.getCommit(repository,\r
                                "1d0c2933a4ae69c362f76797d42d6bd182d05176");\r
-               String diff = DiffUtils.getCommitDiff(repository, commit, DiffComparator.DEFAULT, DiffOutputType.PLAIN).content;\r
+               String diff = DiffUtils.getCommitDiff(repository, commit, DiffComparator.SHOW_WHITESPACE, 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
@@ -55,7 +55,7 @@ public class DiffUtilsTest extends GitblitUnitTest {
                                "8baf6a833b5579384d9b9ceb8a16b5d0ea2ec4ca");\r
                RevCommit commit = JGitUtils.getCommit(repository,\r
                                "1d0c2933a4ae69c362f76797d42d6bd182d05176");\r
-               String diff = DiffUtils.getDiff(repository, baseCommit, commit, DiffComparator.DEFAULT, DiffOutputType.PLAIN).content;\r
+               String diff = DiffUtils.getDiff(repository, baseCommit, commit, DiffComparator.SHOW_WHITESPACE, 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
@@ -67,7 +67,7 @@ public class DiffUtilsTest extends GitblitUnitTest {
                Repository repository = GitBlitSuite.getHelloworldRepository();\r
                RevCommit commit = JGitUtils.getCommit(repository,\r
                                "1d0c2933a4ae69c362f76797d42d6bd182d05176");\r
-               String diff = DiffUtils.getDiff(repository, commit, "java.java", DiffComparator.DEFAULT, DiffOutputType.PLAIN).content;\r
+               String diff = DiffUtils.getDiff(repository, commit, "java.java", DiffComparator.SHOW_WHITESPACE, 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