]> source.dussan.org Git - gitblit.git/commitdiff
Remove "show readme" flag in favor of automatic detection
authorJames Moger <james.moger@gitblit.com>
Thu, 24 Oct 2013 19:44:44 +0000 (15:44 -0400)
committerJames Moger <james.moger@gitblit.com>
Fri, 25 Oct 2013 11:55:56 +0000 (07:55 -0400)
Automatic detection also will now also display a plain text "readme"
or "readme.txt" file.

Change-Id: Id6be729bdc469e7a5cfd1f4144df340a6b93475e

releases.moxie
src/main/java/com/gitblit/GitBlit.java
src/main/java/com/gitblit/client/EditRepositoryDialog.java
src/main/java/com/gitblit/models/RepositoryModel.java
src/main/java/com/gitblit/utils/MarkdownUtils.java
src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.html
src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java
src/main/java/com/gitblit/wicket/pages/RepositoryPage.java
src/main/java/com/gitblit/wicket/pages/SummaryPage.html
src/main/java/com/gitblit/wicket/pages/SummaryPage.java

index 6dfb7446c43198c780ac6cbc977491341e6f16ac..df1ecce402768f52692444bfab4bdd4b9a73d90f 100644 (file)
@@ -23,6 +23,8 @@ r20: {
        - Updated default binary and Lucene ignore extensions
        - Change the WAR baseFolder context parameter to a JNDI env-entry to improve enterprise deployments
        - Removed internal Gitblit ref exclusions in the upload pack
+       - Removed "show readme" setting in favor of automatic detection
+       - Support plain text "readme" files
     additions:
        - Added branch graph image servlet based on EGit's branch graph renderer (issue-194)
        - Added option to render Markdown commit messages (issue-203)
index a23dd8c275e2676dbbfdb2bae70bb890b17e2a87..f313b6e3ccb3bafb6219d761d1c2662ccf655caf 100644 (file)
@@ -2015,7 +2015,6 @@ public class GitBlit implements ServletContextListener {
                        model.verifyCommitter = getConfig(config, "verifyCommitter", false);
                        model.showRemoteBranches = getConfig(config, "showRemoteBranches", hasOrigin);
                        model.isFrozen = getConfig(config, "isFrozen", false);
-                       model.showReadme = getConfig(config, "showReadme", false);
                        model.skipSizeCalculation = getConfig(config, "skipSizeCalculation", false);
                        model.skipSummaryMetrics = getConfig(config, "skipSummaryMetrics", false);
                        model.commitMessageRenderer = CommitMessageRenderer.fromName(getConfig(config, "commitMessageRenderer",
@@ -2578,7 +2577,6 @@ public class GitBlit implements ServletContextListener {
                config.setBoolean(Constants.CONFIG_GITBLIT, null, "verifyCommitter", repository.verifyCommitter);
                config.setBoolean(Constants.CONFIG_GITBLIT, null, "showRemoteBranches", repository.showRemoteBranches);
                config.setBoolean(Constants.CONFIG_GITBLIT, null, "isFrozen", repository.isFrozen);
-               config.setBoolean(Constants.CONFIG_GITBLIT, null, "showReadme", repository.showReadme);
                config.setBoolean(Constants.CONFIG_GITBLIT, null, "skipSizeCalculation", repository.skipSizeCalculation);
                config.setBoolean(Constants.CONFIG_GITBLIT, null, "skipSummaryMetrics", repository.skipSummaryMetrics);
                config.setString(Constants.CONFIG_GITBLIT, null, "federationStrategy",
index f4d945050963c0c18d3c3a12dd37b64a87882d0e..1c499ee12010ae05951ff489c321a4ead5ec4d52 100644 (file)
@@ -94,8 +94,6 @@ public class EditRepositoryDialog extends JDialog {
 \r
        private JCheckBox showRemoteBranches;\r
 \r
-       private JCheckBox showReadme;\r
-\r
        private JCheckBox skipSizeCalculation;\r
 \r
        private JCheckBox skipSummaryMetrics;\r
@@ -216,8 +214,6 @@ public class EditRepositoryDialog extends JDialog {
                showRemoteBranches = new JCheckBox(\r
                                Translation.get("gb.showRemoteBranchesDescription"),\r
                                anRepository.showRemoteBranches);\r
-               showReadme = new JCheckBox(Translation.get("gb.showReadmeDescription"),\r
-                               anRepository.showReadme);\r
                skipSizeCalculation = new JCheckBox(\r
                                Translation.get("gb.skipSizeCalculationDescription"),\r
                                anRepository.skipSizeCalculation);\r
@@ -312,8 +308,6 @@ public class EditRepositoryDialog extends JDialog {
                .add(newFieldPanel(Translation.get("gb.enableIncrementalPushTags"), useIncrementalPushTags));\r
                fieldsPanel.add(newFieldPanel(Translation.get("gb.showRemoteBranches"),\r
                                showRemoteBranches));\r
-               fieldsPanel.add(newFieldPanel(Translation.get("gb.showReadme"),\r
-                               showReadme));\r
                fieldsPanel\r
                                .add(newFieldPanel(Translation.get("gb.skipSizeCalculation"),\r
                                                skipSizeCalculation));\r
@@ -567,7 +561,6 @@ public class EditRepositoryDialog extends JDialog {
                repository.useDocs = useDocs.isSelected();\r
                repository.useIncrementalPushTags = useIncrementalPushTags.isSelected();\r
                repository.showRemoteBranches = showRemoteBranches.isSelected();\r
-               repository.showReadme = showReadme.isSelected();\r
                repository.skipSizeCalculation = skipSizeCalculation.isSelected();\r
                repository.skipSummaryMetrics = skipSummaryMetrics.isSelected();\r
                repository.maxActivityCommits = (Integer) maxActivityCommits.getSelectedItem();\r
index 2476834a9cae7079d9a50e362a53bac9dbe7cea0..888546523d3c1ef68bf794fa194ddbf62a0ec0e6 100644 (file)
@@ -58,7 +58,6 @@ public class RepositoryModel implements Serializable, Comparable<RepositoryModel
        public AuthorizationControl authorizationControl;\r
        public boolean allowAuthenticated;\r
        public boolean isFrozen;\r
-       public boolean showReadme;\r
        public FederationStrategy federationStrategy;\r
        public List<String> federationSets;\r
        public boolean isFederated;\r
@@ -208,7 +207,6 @@ public class RepositoryModel implements Serializable, Comparable<RepositoryModel
                clone.accessRestriction = AccessRestrictionType.PUSH;\r
                clone.authorizationControl = AuthorizationControl.NAMED;\r
                clone.federationStrategy = federationStrategy;\r
-               clone.showReadme = showReadme;\r
                clone.showRemoteBranches = false;\r
                clone.allowForks = false;\r
                clone.useDocs = useDocs;\r
index 33d7a6ae1877f7d519da7814b7c620481e2c36fa..f9c07fbc50ed523e590ee8f8b4a9c773f70872eb 100644 (file)
@@ -32,6 +32,21 @@ import org.pegdown.PegDownProcessor;
  */\r
 public class MarkdownUtils {\r
 \r
+       /**\r
+        * Returns the html version of the plain source text.\r
+        *\r
+        * @param text\r
+        * @return html version of plain text\r
+        * @throws java.text.ParseException\r
+        */\r
+       public static String transformPlainText(String text) {\r
+               // url auto-linking\r
+               text = text.replaceAll("((http|https)://[0-9A-Za-z-_=\\?\\.\\$#&/]*)", "<a href=\"$1\">$1</a>");\r
+               String html = "<pre>" + text + "</pre>";\r
+               return html;\r
+       }\r
+\r
+\r
        /**\r
         * Returns the html version of the markdown source text.\r
         *\r
index 6e41a7de9afe691de14e0eacf7a1921275d35afa..d8939e7529cfbaa0edc32644817f37274bf88657 100644 (file)
                                <tr><th><wicket:message key="gb.enableDocs"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="useDocs" tabindex="8" /> &nbsp;<span class="help-inline"><wicket:message key="gb.useDocsDescription"></wicket:message></span></label></td></tr>\r
                                <tr><th><wicket:message key="gb.enableIncrementalPushTags"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="useIncrementalPushTags" tabindex="8" /> &nbsp;<span class="help-inline"><wicket:message key="gb.useIncrementalPushTagsDescription"></wicket:message></span></label></td></tr>\r
                                <tr><th><wicket:message key="gb.showRemoteBranches"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="showRemoteBranches" tabindex="9" /> &nbsp;<span class="help-inline"><wicket:message key="gb.showRemoteBranchesDescription"></wicket:message></span></label></td></tr>\r
-                               <tr><th><wicket:message key="gb.showReadme"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="showReadme" tabindex="10" /> &nbsp;<span class="help-inline"><wicket:message key="gb.showReadmeDescription"></wicket:message></span></label></td></tr>\r
-                               <tr><th><wicket:message key="gb.skipSizeCalculation"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="skipSizeCalculation" tabindex="11" /> &nbsp;<span class="help-inline"><wicket:message key="gb.skipSizeCalculationDescription"></wicket:message></span></label></td></tr>\r
-                               <tr><th><wicket:message key="gb.skipSummaryMetrics"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="skipSummaryMetrics" tabindex="12" /> &nbsp;<span class="help-inline"><wicket:message key="gb.skipSummaryMetricsDescription"></wicket:message></span></label></td></tr>\r
-                               <tr><th><wicket:message key="gb.maxActivityCommits"></wicket:message></th><td class="edit"><select class="span2" wicket:id="maxActivityCommits" tabindex="13" /> &nbsp;<span class="help-inline"><wicket:message key="gb.maxActivityCommitsDescription"></wicket:message></span></td></tr>\r
-                               <tr><th><wicket:message key="gb.metricAuthorExclusions"></wicket:message></th><td class="edit"><input class="span8" type="text" wicket:id="metricAuthorExclusions" size="40" tabindex="14" /></td></tr>\r
-                               <tr><th><wicket:message key="gb.commitMessageRenderer"></wicket:message></th><td class="edit"><select class="span2" wicket:id="commitMessageRenderer" tabindex="15" /></td></tr>\r
+                               <tr><th><wicket:message key="gb.skipSizeCalculation"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="skipSizeCalculation" tabindex="10" /> &nbsp;<span class="help-inline"><wicket:message key="gb.skipSizeCalculationDescription"></wicket:message></span></label></td></tr>\r
+                               <tr><th><wicket:message key="gb.skipSummaryMetrics"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="skipSummaryMetrics" tabindex="11" /> &nbsp;<span class="help-inline"><wicket:message key="gb.skipSummaryMetricsDescription"></wicket:message></span></label></td></tr>\r
+                               <tr><th><wicket:message key="gb.maxActivityCommits"></wicket:message></th><td class="edit"><select class="span2" wicket:id="maxActivityCommits" tabindex="12" /> &nbsp;<span class="help-inline"><wicket:message key="gb.maxActivityCommitsDescription"></wicket:message></span></td></tr>\r
+                               <tr><th><wicket:message key="gb.metricAuthorExclusions"></wicket:message></th><td class="edit"><input class="span8" type="text" wicket:id="metricAuthorExclusions" size="40" tabindex="13" /></td></tr>\r
+                               <tr><th><wicket:message key="gb.commitMessageRenderer"></wicket:message></th><td class="edit"><select class="span2" wicket:id="commitMessageRenderer" tabindex="14" /></td></tr>\r
                                <tr><th colspan="2"><hr/></th></tr>\r
-                               <tr><th><wicket:message key="gb.mailingLists"></wicket:message></th><td class="edit"><input class="span8" type="text" wicket:id="mailingLists" size="40" tabindex="16" /></td></tr>\r
+                               <tr><th><wicket:message key="gb.mailingLists"></wicket:message></th><td class="edit"><input class="span8" type="text" wicket:id="mailingLists" size="40" tabindex="15" /></td></tr>\r
                        </tbody>\r
                </table>\r
                </div>\r
                <div class="tab-pane" id="permissions">\r
                        <table class="plain">\r
                                <tbody class="settings">\r
-                                       <tr><th><wicket:message key="gb.owners"></wicket:message></th><td class="edit"><span wicket:id="owners" tabindex="17" /> </td></tr>\r
+                                       <tr><th><wicket:message key="gb.owners"></wicket:message></th><td class="edit"><span wicket:id="owners" tabindex="16" /> </td></tr>\r
                                        <tr><th colspan="2"><hr/></th></tr>\r
-                                       <tr><th><wicket:message key="gb.accessRestriction"></wicket:message></th><td class="edit"><select class="span4" wicket:id="accessRestriction" tabindex="18" /></td></tr>\r
+                                       <tr><th><wicket:message key="gb.accessRestriction"></wicket:message></th><td class="edit"><select class="span4" wicket:id="accessRestriction" tabindex="17" /></td></tr>\r
                                        <tr><th colspan="2"><hr/></th></tr>\r
                                        <tr><th><wicket:message key="gb.authorizationControl"></wicket:message></th><td style="padding:2px;"><span class="authorizationControl" wicket:id="authorizationControl"></span></td></tr>\r
                                        <tr><th colspan="2"><hr/></th></tr>\r
-                                       <tr><th><wicket:message key="gb.isFrozen"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="isFrozen" tabindex="19" /> &nbsp;<span class="help-inline"><wicket:message key="gb.isFrozenDescription"></wicket:message></span></label></td></tr>\r
-                                       <tr><th><wicket:message key="gb.allowForks"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="allowForks" tabindex="20" /> &nbsp;<span class="help-inline"><wicket:message key="gb.allowForksDescription"></wicket:message></span></label></td></tr>\r
-                                       <tr><th><wicket:message key="gb.verifyCommitter"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="verifyCommitter" tabindex="21" /> &nbsp;<span class="help-inline"><wicket:message key="gb.verifyCommitterDescription"></wicket:message></span><br/><span class="help-inline" style="padding-left:10px;"><wicket:message key="gb.verifyCommitterNote"></wicket:message></span></label></td></tr>\r
+                                       <tr><th><wicket:message key="gb.isFrozen"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="isFrozen" tabindex="18" /> &nbsp;<span class="help-inline"><wicket:message key="gb.isFrozenDescription"></wicket:message></span></label></td></tr>\r
+                                       <tr><th><wicket:message key="gb.allowForks"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="allowForks" tabindex="19" /> &nbsp;<span class="help-inline"><wicket:message key="gb.allowForksDescription"></wicket:message></span></label></td></tr>\r
+                                       <tr><th><wicket:message key="gb.verifyCommitter"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="verifyCommitter" tabindex="20" /> &nbsp;<span class="help-inline"><wicket:message key="gb.verifyCommitterDescription"></wicket:message></span><br/><span class="help-inline" style="padding-left:10px;"><wicket:message key="gb.verifyCommitterNote"></wicket:message></span></label></td></tr>\r
                                        <tr><th colspan="2"><hr/></th></tr>\r
                                        <tr><th><wicket:message key="gb.userPermissions"></wicket:message></th><td style="padding:2px;"><span wicket:id="users"></span></td></tr>\r
                                        <tr><th colspan="2"><hr/></th></tr>\r
@@ -73,7 +72,7 @@
                <div class="tab-pane" id="federation">\r
                        <table class="plain">\r
                                <tbody class="settings">\r
-                                       <tr><th><wicket:message key="gb.federationStrategy"></wicket:message></th><td class="edit"><select class="span4" wicket:id="federationStrategy" tabindex="22" /></td></tr>\r
+                                       <tr><th><wicket:message key="gb.federationStrategy"></wicket:message></th><td class="edit"><select class="span4" wicket:id="federationStrategy" tabindex="21" /></td></tr>\r
                                        <tr><th><wicket:message key="gb.federationSets"></wicket:message></th><td style="padding:2px;"><span wicket:id="federationSets"></span></td></tr>\r
                                </tbody>\r
                        </table>\r
index cde60314dbf2c74d00f4ec46ff6fd662c39d6535..f0afb57c3b4d0e2491c1f50945f4edd18a0d713b 100644 (file)
@@ -448,7 +448,6 @@ public class EditRepositoryPage extends RootSubPage {
                form.add(new CheckBox("useDocs"));\r
                form.add(new CheckBox("useIncrementalPushTags"));\r
                form.add(new CheckBox("showRemoteBranches"));\r
-               form.add(new CheckBox("showReadme"));\r
                form.add(new CheckBox("skipSizeCalculation"));\r
                form.add(new CheckBox("skipSummaryMetrics"));\r
                List<Integer> maxActivityCommits  = Arrays.asList(-1, 0, 25, 50, 75, 100, 150, 200, 250, 500 );\r
index dabaed037f3eeb8b6826c57aa1d1f2afb77d38a3..b31bc3b51997fd9a927df4b7caeba7a447bd5bb1 100644 (file)
@@ -204,7 +204,7 @@ public abstract class RepositoryPage extends RootPage {
 \r
                // conditional links\r
                // per-repository extra page links\r
-               if (model.showReadme || model.useDocs) {\r
+               if (model.useDocs) {\r
                        pages.put("docs", new PageRegistration("gb.docs", DocsPage.class, params, true));\r
                }\r
                if (JGitUtils.getPagesBranch(r) != null) {\r
index 3dd1eb4bd04022b7bed9cff215b4be8e886b6513..69cd390392d0662d998cdea2b55f727e31075468 100644 (file)
                        <div wicket:id="readmeContent" class="markdown"></div>\r
                </div>\r
        </wicket:fragment>\r
-       \r
+\r
+       <wicket:fragment wicket:id="plaintextPanel">\r
+               <div class="header" style="margin-top:0px;" >\r
+                       <i style="vertical-align: middle;" class="icon-book"></i>\r
+                       <span style="font-weight:bold;vertical-align:middle;" wicket:id="readmeFile"></span>\r
+               </div>\r
+               <div style="border:1px solid #ddd;border-radius: 0 0 3px 3px;padding: 20px;">\r
+                       <div wicket:id="readmeContent"></div>\r
+               </div>\r
+       </wicket:fragment>      \r
        <wicket:fragment wicket:id="ownersFragment">\r
                \r
        </wicket:fragment>\r
index cc9697c6f6460705838912132480e645f300ad26..0a13837171185b7297212c0b093f8a758203630b 100644 (file)
@@ -137,47 +137,56 @@ public class SummaryPage extends RepositoryPage {
                add(new TagsPanel("tagsPanel", repositoryName, r, numberRefs).hideIfEmpty());\r
                add(new BranchesPanel("branchesPanel", getRepositoryModel(), r, numberRefs, false).hideIfEmpty());\r
 \r
-               if (getRepositoryModel().showReadme) {\r
-                       String htmlText = null;\r
-                       String markdownText = null;\r
-                       String readme = null;\r
-                       try {\r
-                               RevCommit head = JGitUtils.getCommit(r, null);\r
-                               List<String> markdownExtensions = GitBlit.getStrings(Keys.web.markdownExtensions);\r
-                               List<PathModel> paths = JGitUtils.getFilesInPath(r, null, head);\r
-                               for (PathModel path : paths) {\r
-                                       if (!path.isTree()) {\r
-                                               String name = path.name.toLowerCase();\r
-\r
-                                               if (name.startsWith("readme")) {\r
-                                                       if (name.indexOf('.') > -1) {\r
-                                                               String ext = name.substring(name.lastIndexOf('.') + 1);\r
-                                                               if (markdownExtensions.contains(ext)) {\r
-                                                                       readme = path.name;\r
-                                                                       break;\r
-                                                               }\r
+               String htmlText = null;\r
+               String markdownText = null;\r
+               String readme = null;\r
+               boolean isMarkdown = false;\r
+               try {\r
+                       RevCommit head = JGitUtils.getCommit(r, null);\r
+                       List<String> markdownExtensions = GitBlit.getStrings(Keys.web.markdownExtensions);\r
+                       List<PathModel> paths = JGitUtils.getFilesInPath(r, null, head);\r
+                       for (PathModel path : paths) {\r
+                               if (!path.isTree()) {\r
+                                       String name = path.name.toLowerCase();\r
+                                       if (name.equals("readme") || name.equals("readme.txt")) {\r
+                                               readme = path.name;\r
+                                               isMarkdown = false;\r
+                                       } else if (name.startsWith("readme")) {\r
+                                               if (name.indexOf('.') > -1) {\r
+                                                       String ext = name.substring(name.lastIndexOf('.') + 1);\r
+                                                       if (markdownExtensions.contains(ext)) {\r
+                                                               readme = path.name;\r
+                                                               isMarkdown = true;\r
+                                                               break;\r
                                                        }\r
                                                }\r
                                        }\r
                                }\r
-                               if (!StringUtils.isEmpty(readme)) {\r
-                                       String [] encodings = GitBlit.getEncodings();\r
-                                       markdownText = JGitUtils.getStringContent(r, head.getTree(), readme, encodings);\r
+                       }\r
+                       if (!StringUtils.isEmpty(readme)) {\r
+                               String [] encodings = GitBlit.getEncodings();\r
+                               markdownText = JGitUtils.getStringContent(r, head.getTree(), readme, encodings);\r
+                               if (isMarkdown) {\r
                                        htmlText = MarkdownUtils.transformMarkdown(markdownText);\r
+                               } else {\r
+                                       htmlText = MarkdownUtils.transformPlainText(markdownText);\r
                                }\r
-                       } catch (Exception e) {\r
-                               logger.error("failed to transform markdown", e);\r
-                               markdownText = MessageFormat.format("<div class=\"alert alert-error\"><strong>{0}:</strong> {1}</div>{2}", getString("gb.error"), getString("gb.markdownFailure"), markdownText);\r
-                               htmlText = StringUtils.breakLinesForHtml(markdownText);\r
                        }\r
-                       Fragment fragment = new Fragment("readme", "markdownPanel");\r
+               } catch (Exception e) {\r
+                       logger.error("failed to transform markdown", e);\r
+                       markdownText = MessageFormat.format("<div class=\"alert alert-error\"><strong>{0}:</strong> {1}</div>{2}", getString("gb.error"), getString("gb.markdownFailure"), markdownText);\r
+                       htmlText = MarkdownUtils.transformPlainText(markdownText);\r
+               }\r
+\r
+               if (StringUtils.isEmpty(htmlText)) {\r
+                       add(new Label("readme").setVisible(false));\r
+               } else {\r
+                       Fragment fragment = new Fragment("readme", isMarkdown ? "markdownPanel" : "plaintextPanel");\r
                        fragment.add(new Label("readmeFile", readme));\r
                        // Add the html to the page\r
                        Component content = new Label("readmeContent", htmlText).setEscapeModelStrings(false);\r
                        fragment.add(content.setVisible(!StringUtils.isEmpty(htmlText)));\r
                        add(fragment);\r
-               } else {\r
-                       add(new Label("readme").setVisible(false));\r
                }\r
 \r
                // Display an activity line graph\r