]> source.dussan.org Git - gitblit.git/commitdiff
Working on error handling.
authorJames Moger <james.moger@gitblit.com>
Sat, 30 Apr 2011 00:46:44 +0000 (20:46 -0400)
committerJames Moger <james.moger@gitblit.com>
Sat, 30 Apr 2011 00:46:44 +0000 (20:46 -0400)
25 files changed:
src/com/gitblit/Constants.java
src/com/gitblit/GitBlit.java
src/com/gitblit/utils/JGitUtils.java
src/com/gitblit/wicket/BasePage.html
src/com/gitblit/wicket/BasePage.java
src/com/gitblit/wicket/GitBlitWebApp.java
src/com/gitblit/wicket/GitBlitWebApp.properties
src/com/gitblit/wicket/GitBlitWebSession.java
src/com/gitblit/wicket/LoginPage.html
src/com/gitblit/wicket/RepositoryPage.html
src/com/gitblit/wicket/RepositoryPage.java
src/com/gitblit/wicket/models/RepositoryModel.java
src/com/gitblit/wicket/pages/BlobDiffPage.java
src/com/gitblit/wicket/pages/BlobPage.java
src/com/gitblit/wicket/pages/CommitDiffPage.java
src/com/gitblit/wicket/pages/CommitPage.java
src/com/gitblit/wicket/pages/EditRepositoryPage.html
src/com/gitblit/wicket/pages/PatchPage.java
src/com/gitblit/wicket/pages/RepositoriesPage.html
src/com/gitblit/wicket/pages/RepositoriesPage.java
src/com/gitblit/wicket/pages/TagPage.java
src/com/gitblit/wicket/pages/TreePage.java
src/com/gitblit/wicket/panels/CommitHeaderPanel.java
src/com/gitblit/wicket/panels/SearchPanel.java
src/com/gitblit/wicket/resources/gitblit.css

index d5fc1a41f2d3e671e46d980ca34efd8d2f188836..4ad46636c25c1d0a4aab5a4d18e0403ac2bf426c 100644 (file)
@@ -19,7 +19,7 @@ public class Constants {
        }\r
 \r
        public static String getJGitVersion() {\r
-               return "JGit 0.11.3";\r
+               return "JGit 0.12-stable";\r
        }\r
 \r
        public static String getRunningVersion() {\r
index e557c934876cf976b62d944614df4dca0b19434b..32ee73c48a8c38a8bf5a8805a9a164d96ea16114 100644 (file)
@@ -105,8 +105,7 @@ public class GitBlit implements ServletContextListener {
                        r = repositoryResolver.open(null, repositoryName);\r
                } catch (RepositoryNotFoundException e) {\r
                        r = null;\r
-                       logger.error("Failed to find repository " + repositoryName);\r
-                       e.printStackTrace();\r
+                       logger.error("GitBlit.getRepository(String) failed to find repository " + repositoryName);\r
                } catch (ServiceNotEnabledException e) {\r
                        r = null;\r
                        e.printStackTrace();\r
@@ -128,6 +127,7 @@ public class GitBlit implements ServletContextListener {
                Repository r = getRepository(repositoryName);\r
                RepositoryModel model = new RepositoryModel();\r
                model.name = repositoryName;\r
+               model.hasCommits = JGitUtils.hasCommits(r);\r
                model.lastChange = JGitUtils.getLastChange(r);\r
                StoredConfig config = JGitUtils.readConfig(r);\r
                if (config != null) {\r
index 70a938ff124ce6757c74603aaa641a7a330c9900..71fa20e19ce161c64a7c5153737bbdc60f7ec443 100644 (file)
@@ -70,7 +70,7 @@ public class JGitUtils {
        public static final String R_NOTES_COMMITS = R_NOTES + "commits";\r
 \r
        private final static Logger LOGGER = LoggerFactory.getLogger(JGitUtils.class);\r
-       \r
+\r
        public static Repository createRepository(File repositoriesFolder, String name, boolean bare) {\r
                Git git = Git.init().setDirectory(new File(repositoriesFolder, name)).setBare(bare).call();\r
                return git.getRepository();\r
@@ -93,11 +93,11 @@ public class JGitUtils {
                                // first look for standard folder/.git structure\r
                                File gitFolder = new File(file, Constants.DOT_GIT);\r
                                boolean isGitRepository = gitFolder.exists() && gitFolder.isDirectory();\r
-                               \r
-                               // then look for folder.git/HEAD or folder/HEAD and folder/config\r
+\r
+                               // then look for folder.git/HEAD or folder/HEAD and\r
+                               // folder/config\r
                                if (!isGitRepository) {\r
-                                       if ((file.getName().endsWith(Constants.DOT_GIT_EXT) && new File(file, Constants.HEAD).exists())\r
-                                                       || (new File(file, "config").exists() && new File(file, Constants.HEAD).exists())) {\r
+                                       if ((file.getName().endsWith(Constants.DOT_GIT_EXT) && new File(file, Constants.HEAD).exists()) || (new File(file, "config").exists() && new File(file, Constants.HEAD).exists())) {\r
                                                gitFolder = file;\r
                                                isGitRepository = true;\r
                                        }\r
@@ -124,6 +124,9 @@ public class JGitUtils {
        }\r
 \r
        public static RevCommit getFirstCommit(Repository r, String branch) {\r
+               if (!hasCommits(r)) {\r
+                       return null;\r
+               }\r
                if (StringUtils.isEmpty(branch)) {\r
                        branch = Constants.HEAD;\r
                }\r
@@ -146,7 +149,7 @@ public class JGitUtils {
                        RevCommit commit = getFirstCommit(r, branch);\r
                        if (commit == null) {\r
                                // fresh repository\r
-                               return new Date(r.getDirectory().lastModified());                       \r
+                               return new Date(r.getDirectory().lastModified());\r
                        }\r
                        return getCommitDate(commit);\r
                } catch (Throwable t) {\r
@@ -155,17 +158,24 @@ public class JGitUtils {
                return null;\r
        }\r
 \r
-       public static Date getLastChange(Repository r) {                \r
-               RevCommit commit = getCommit(r, Constants.HEAD);\r
-               if (commit == null) {\r
+       public static boolean hasCommits(Repository r) {\r
+               return new File(r.getDirectory(), Constants.R_HEADS).list().length > 0;\r
+       }\r
+\r
+       public static Date getLastChange(Repository r) {\r
+               if (!hasCommits(r)) {\r
                        // fresh repository\r
-                       return new Date(r.getDirectory().lastModified());                       \r
+                       return new Date(r.getDirectory().lastModified());\r
                }\r
+               RevCommit commit = getCommit(r, Constants.HEAD);\r
                return getCommitDate(commit);\r
        }\r
 \r
        public static RevCommit getCommit(Repository r, String objectId) {\r
                RevCommit commit = null;\r
+               if (!hasCommits(r)) {\r
+                       return null;\r
+               }\r
                try {\r
                        if (objectId == null || objectId.trim().length() == 0) {\r
                                objectId = Constants.HEAD;\r
@@ -176,7 +186,7 @@ public class JGitUtils {
                        commit = rev;\r
                        walk.dispose();\r
                } catch (Throwable t) {\r
-                       LOGGER.error("Failed to determine last change", t);\r
+                       LOGGER.error("Failed to get commit " + objectId, t);\r
                }\r
                return commit;\r
        }\r
@@ -266,13 +276,13 @@ public class JGitUtils {
        }\r
 \r
        public static String getRawContentAsString(Repository r, RevBlob blob) {\r
-               byte [] content = getRawContent(r, blob);\r
+               byte[] content = getRawContent(r, blob);\r
                return new String(content, Charset.forName(Constants.CHARACTER_ENCODING));\r
        }\r
 \r
        public static String getRawContentAsString(Repository r, RevCommit commit, String blobPath) {\r
                RevObject obj = getRevObject(r, commit.getTree(), blobPath);\r
-               byte [] content = getRawContent(r, (RevBlob) obj);\r
+               byte[] content = getRawContent(r, (RevBlob) obj);\r
                return new String(content, Charset.forName(Constants.CHARACTER_ENCODING));\r
        }\r
 \r
@@ -328,6 +338,10 @@ public class JGitUtils {
 \r
        public static List<PathChangeModel> getFilesInCommit(Repository r, RevCommit commit) {\r
                List<PathChangeModel> list = new ArrayList<PathChangeModel>();\r
+               if (commit == null) {\r
+                       LOGGER.warn("getFilesInCommit for NULL commit");\r
+                       return list;\r
+               }\r
                try {\r
                        final RevWalk rw = new RevWalk(r);\r
                        RevCommit parent = rw.parseCommit(commit.getParent(0).getId());\r
@@ -359,16 +373,16 @@ public class JGitUtils {
                }\r
                return list;\r
        }\r
-       \r
+\r
        public static List<PathModel> getDocuments(Repository r, List<String> extensions) {\r
                List<PathModel> list = new ArrayList<PathModel>();\r
-               RevCommit commit = getCommit(r, Constants.HEAD);                \r
+               RevCommit commit = getCommit(r, Constants.HEAD);\r
                final TreeWalk walk = new TreeWalk(r);\r
                try {\r
                        walk.addTree(commit.getTree());\r
                        if (extensions != null && extensions.size() > 0) {\r
                                Collection<TreeFilter> suffixFilters = new ArrayList<TreeFilter>();\r
-                               for (String extension:extensions) {\r
+                               for (String extension : extensions) {\r
                                        if (extension.charAt(0) == '.') {\r
                                                suffixFilters.add(PathSuffixFilter.create(extension));\r
                                        } else {\r
@@ -606,6 +620,9 @@ public class JGitUtils {
 \r
        public static List<RevCommit> getRevLog(Repository r, String objectId, String path, int offset, int maxCount) {\r
                List<RevCommit> list = new ArrayList<RevCommit>();\r
+               if (!hasCommits(r)) {\r
+                       return list;\r
+               }\r
                try {\r
                        if (objectId == null || objectId.trim().length() == 0) {\r
                                objectId = Constants.HEAD;\r
@@ -664,6 +681,9 @@ public class JGitUtils {
        public static List<RevCommit> searchRevlogs(Repository r, String objectId, String value, final SearchType type, int offset, int maxCount) {\r
                final String lcValue = value.toLowerCase();\r
                List<RevCommit> list = new ArrayList<RevCommit>();\r
+               if (!hasCommits(r)) {\r
+                       return list;\r
+               }\r
                try {\r
                        if (objectId == null || objectId.trim().length() == 0) {\r
                                objectId = Constants.HEAD;\r
@@ -792,50 +812,53 @@ public class JGitUtils {
        }\r
 \r
        public static List<Metric> getDateMetrics(Repository r) {\r
-               final List<RefModel> tags = getTags(r, -1);\r
-               final Map<ObjectId, RefModel> tagMap = new HashMap<ObjectId, RefModel>();\r
-               for (RefModel tag : tags) {\r
-                       tagMap.put(tag.getCommitId(), tag);\r
-               }\r
                Metric total = new Metric("TOTAL");\r
                final Map<String, Metric> metricMap = new HashMap<String, Metric>();\r
-               try {\r
-                       RevWalk walk = new RevWalk(r);\r
-                       ObjectId object = r.resolve(Constants.HEAD);\r
-\r
-                       RevCommit firstCommit = getFirstCommit(r, Constants.HEAD);\r
-                       RevCommit lastCommit = walk.parseCommit(object);\r
-                       int diffDays = (lastCommit.getCommitTime() - firstCommit.getCommitTime()) / (60 * 60 * 24);\r
-                       total.duration = diffDays;\r
-                       DateFormat df;\r
-                       if (diffDays <= 90) {\r
-                               // Days\r
-                               df = new SimpleDateFormat("yyyy-MM-dd");\r
-                       } else if (diffDays > 90 && diffDays < 365) {\r
-                               // Weeks\r
-                               df = new SimpleDateFormat("yyyy-MM (w)");\r
-                       } else {\r
-                               // Months\r
-                               df = new SimpleDateFormat("yyyy-MM");\r
+               \r
+               if (hasCommits(r)) {\r
+                       final List<RefModel> tags = getTags(r, -1);\r
+                       final Map<ObjectId, RefModel> tagMap = new HashMap<ObjectId, RefModel>();\r
+                       for (RefModel tag : tags) {\r
+                               tagMap.put(tag.getCommitId(), tag);\r
                        }\r
-                       walk.markStart(lastCommit);\r
+                       try {\r
+                               RevWalk walk = new RevWalk(r);\r
+                               ObjectId object = r.resolve(Constants.HEAD);\r
+\r
+                               RevCommit firstCommit = getFirstCommit(r, Constants.HEAD);\r
+                               RevCommit lastCommit = walk.parseCommit(object);\r
+                               int diffDays = (lastCommit.getCommitTime() - firstCommit.getCommitTime()) / (60 * 60 * 24);\r
+                               total.duration = diffDays;\r
+                               DateFormat df;\r
+                               if (diffDays <= 90) {\r
+                                       // Days\r
+                                       df = new SimpleDateFormat("yyyy-MM-dd");\r
+                               } else if (diffDays > 90 && diffDays < 365) {\r
+                                       // Weeks\r
+                                       df = new SimpleDateFormat("yyyy-MM (w)");\r
+                               } else {\r
+                                       // Months\r
+                                       df = new SimpleDateFormat("yyyy-MM");\r
+                               }\r
+                               walk.markStart(lastCommit);\r
 \r
-                       Iterable<RevCommit> revlog = walk;\r
-                       for (RevCommit rev : revlog) {\r
-                               Date d = getCommitDate(rev);\r
-                               String p = df.format(d);\r
-                               if (!metricMap.containsKey(p))\r
-                                       metricMap.put(p, new Metric(p));\r
-                               Metric m = metricMap.get(p);\r
-                               m.count++;\r
-                               total.count++;\r
-                               if (tagMap.containsKey(rev.getId())) {\r
-                                       m.tag++;\r
-                                       total.tag++;\r
+                               Iterable<RevCommit> revlog = walk;\r
+                               for (RevCommit rev : revlog) {\r
+                                       Date d = getCommitDate(rev);\r
+                                       String p = df.format(d);\r
+                                       if (!metricMap.containsKey(p))\r
+                                               metricMap.put(p, new Metric(p));\r
+                                       Metric m = metricMap.get(p);\r
+                                       m.count++;\r
+                                       total.count++;\r
+                                       if (tagMap.containsKey(rev.getId())) {\r
+                                               m.tag++;\r
+                                               total.tag++;\r
+                                       }\r
                                }\r
+                       } catch (Throwable t) {\r
+                               LOGGER.error("Failed to mine log history for metrics", t);\r
                        }\r
-               } catch (Throwable t) {\r
-                       LOGGER.error("Failed to mine log history for metrics", t);\r
                }\r
                List<String> keys = new ArrayList<String>(metricMap.keySet());\r
                Collections.sort(keys);\r
@@ -846,7 +869,7 @@ public class JGitUtils {
                metrics.add(0, total);\r
                return metrics;\r
        }\r
-       \r
+\r
        public static RefModel getTicketsBranch(Repository r) {\r
                RefModel ticgitBranch = null;\r
                try {\r
index 69183b686462f5d95e80d41efdffcb23ba3a291b..0ec9e181988afb69e8c1f1287398ea9b3f1643f1 100644 (file)
@@ -24,7 +24,6 @@
                        <span>\r
                                <a href="/"><span wicket:id="siteName">[site name]</span></a> / <span wicket:id="repositoryName">[repository name]</span> <span wicket:id="pageName">[page name]</span>\r
                        </span> \r
-                       <span wicket:id="feedback">[Feedback Panel]</span>\r
                </div>\r
 \r
                <!-- page content -->\r
index 8daab447c4a84c56c62b99a619e06f62ba0a796c..6125f2a0620d3fe90250d2df966a5499524b3609 100644 (file)
@@ -5,6 +5,7 @@ import java.util.TimeZone;
 import javax.servlet.http.HttpServletRequest;\r
 \r
 import org.apache.wicket.PageParameters;\r
+import org.apache.wicket.RestartResponseAtInterceptPageException;\r
 import org.apache.wicket.markup.html.WebPage;\r
 import org.apache.wicket.markup.html.basic.Label;\r
 import org.apache.wicket.markup.html.panel.FeedbackPanel;\r
@@ -50,14 +51,13 @@ public abstract class BasePage extends WebPage {
                add(new FeedbackPanel("feedback"));\r
 \r
                // footer\r
-               if (GitBlit.self().settings().getBoolean(Keys.web.authenticateViewPages, true)\r
-                               || GitBlit.self().settings().getBoolean(Keys.web.authenticateAdminPages, true)) {\r
+               if (GitBlit.self().settings().getBoolean(Keys.web.authenticateViewPages, true) || GitBlit.self().settings().getBoolean(Keys.web.authenticateAdminPages, true)) {\r
                        if (GitBlitWebSession.get().isLoggedIn()) {\r
                                // logout\r
                                add(new LinkPanel("userPanel", null, getString("gb.logout") + " " + GitBlitWebSession.get().getUser().toString(), LogoutPage.class));\r
                        } else {\r
                                // login\r
-                               add(new LinkPanel("userPanel", null, getString("gb.login"), LoginPage.class));                          \r
+                               add(new LinkPanel("userPanel", null, getString("gb.login"), LoginPage.class));\r
                        }\r
                } else {\r
                        add(new Label("userPanel", ""));\r
@@ -78,8 +78,23 @@ public abstract class BasePage extends WebPage {
                return req.getServerName();\r
        }\r
 \r
-       public void error(String message, Throwable t) {\r
-               super.error(message);\r
+       public void error(String message, boolean redirect) {\r
+               logger.error(message);\r
+               if (redirect) {\r
+                       GitBlitWebSession.get().cacheErrorMessage(message);\r
+                       throw new RestartResponseAtInterceptPageException(getApplication().getHomePage());\r
+               } else {\r
+                       super.error(message);\r
+               }\r
+       }\r
+\r
+       public void error(String message, Throwable t, boolean redirect) {\r
                logger.error(message, t);\r
+               if (redirect) {\r
+                       GitBlitWebSession.get().cacheErrorMessage(message);\r
+                       throw new RestartResponseAtInterceptPageException(getApplication().getHomePage());\r
+               } else {\r
+                       super.error(message);\r
+               }\r
        }\r
 }\r
index 7410dfa5754cb870619b214e5d73343a2adbbd33..87c97a58c1eadda32fba0771affc6773d3a2a620 100644 (file)
@@ -63,7 +63,7 @@ public class GitBlitWebApp extends WebApplication {
                mount(new MixedParamUrlCodingStrategy("/commitdiff", CommitDiffPage.class, new String[] { "r", "h" }));\r
                mount(new MixedParamUrlCodingStrategy("/patch", PatchPage.class, new String[] { "r", "h", "f" }));\r
                mount(new MixedParamUrlCodingStrategy("/history", HistoryPage.class, new String[] { "r", "h", "f" }));\r
-               mount(new MixedParamUrlCodingStrategy("/search", SearchPage.class, new String[] { "r", "h", "a", "c" }));\r
+               mount(new MixedParamUrlCodingStrategy("/search", SearchPage.class, new String[] { }));\r
 \r
                // setup ticket urls\r
                mount(new MixedParamUrlCodingStrategy("/tickets", TicketsPage.class, new String[] { "r" }));\r
index 367ae3df246e2120369af67f7282e138a5ad2019..17bbdecb52ee0f2e39bf1eea0a83342fc95ba7ce 100644 (file)
@@ -75,4 +75,5 @@ gb.name = name
 gb.group = group\r
 gb.description = description\r
 gb.enableTickets = enable tickets\r
-gb.enableDocs = enable docs
\ No newline at end of file
+gb.enableDocs = enable docs\r
+gb.save = save
\ No newline at end of file
index 92eaff666b996fcb624469a31459dd51f03d8f13..58ba495076e26c3f374db75ddc798723b256a1a6 100644 (file)
@@ -14,6 +14,8 @@ public final class GitBlitWebSession extends WebSession {
        protected TimeZone timezone = null;\r
 \r
        private User user = null;\r
+       \r
+       private String errorMessage = null;\r
 \r
        public GitBlitWebSession(Request request) {\r
                super(request);\r
@@ -53,6 +55,16 @@ public final class GitBlitWebSession extends WebSession {
                }\r
                return timezone;\r
        }\r
+       \r
+       public void cacheErrorMessage(String message) {\r
+               this.errorMessage = message;\r
+       }\r
+       \r
+       public String clearErrorMessage() {\r
+               String msg = errorMessage;\r
+               errorMessage = null;\r
+               return msg;\r
+       }\r
 \r
        public static GitBlitWebSession get() {\r
                return (GitBlitWebSession) Session.get();\r
index f38e01ddff56ec5e9a47b0927ce24c22b53e1392..71421ab4c0f20d86df0bd36af636e0c64ab9abf0 100644 (file)
@@ -32,9 +32,9 @@
                                        <input type="password"  wicket:id="password" value=""/>\r
                                        <p/>\r
                                        <input type="submit" value="Login" wicket:message="value:gb.login" />\r
-                                       <div style="background-color:#c7c7c7" wicket:id="feedback"></div>\r
+                                       <div style="padding-top:10px;" wicket:id="feedback"></div>\r
                                </div>\r
-                       </form>\r
+                       </form>                                 \r
                </div>\r
        </body>\r
 </html>
\ No newline at end of file
index 4b3f2e78c65de6d478f26ad615c3b0ba0955ead2..0e0ce476e9ff494b0deec0acb6b9773f051e5b89 100644 (file)
@@ -21,6 +21,8 @@
                                <a wicket:id="summary"><wicket:message key="gb.summary"></wicket:message></a> | <a wicket:id="log"><wicket:message key="gb.log"></wicket:message></a> | <a wicket:id="branches"><wicket:message key="gb.branches"></wicket:message></a> | <a wicket:id="tags"><wicket:message key="gb.tags"></wicket:message></a> | <a wicket:id="tree"><wicket:message key="gb.tree"></wicket:message></a> <span wicket:id="extra"><span wicket:id="extraSeparator"></span><span wicket:id="extraLink"></span></span>\r
                        </div>\r
                </div>\r
+               \r
+               <div style="text-align:center;" wicket:id="feedback">[Feedback Panel]</div>\r
        \r
                <!-- page content -->\r
                <wicket:child />\r
index ba3ca6926d7d15ba42fba0dfa5fbe18e22e4772a..1f88075ee0e9df78fe8fa452a82ffffab8a75b52 100644 (file)
@@ -1,5 +1,6 @@
 package com.gitblit.wicket;\r
 \r
+import java.text.MessageFormat;\r
 import java.util.ArrayList;\r
 import java.util.Arrays;\r
 import java.util.HashMap;\r
@@ -46,10 +47,10 @@ import com.gitblit.wicket.panels.RefsPanel;
 public abstract class RepositoryPage extends BasePage {\r
 \r
        protected final String repositoryName;\r
-       protected final String objectId;        \r
+       protected final String objectId;\r
 \r
        private transient Repository r = null;\r
-       \r
+\r
        private RepositoryModel m = null;\r
 \r
        private final Logger logger = LoggerFactory.getLogger(RepositoryPage.class);\r
@@ -70,14 +71,17 @@ public abstract class RepositoryPage extends BasePage {
 \r
        public RepositoryPage(PageParameters params) {\r
                super(params);\r
-               if (!params.containsKey("r")) {\r
-                       error("Repository not specified!");\r
-                       redirectToInterceptPage(new RepositoriesPage());\r
-               }\r
                repositoryName = WicketUtils.getRepositoryName(params);\r
                objectId = WicketUtils.getObject(params);\r
 \r
+               if (StringUtils.isEmpty(repositoryName)) {\r
+                       error(MessageFormat.format("Repository not specified for {0}!", getPageName()), true);\r
+               }\r
+\r
                Repository r = getRepository();\r
+               if (r == null) {\r
+                       error(MessageFormat.format("Failed to open repository {0} for {1}!", repositoryName, getPageName()), true);\r
+               }\r
 \r
                // standard page links\r
                add(new BookmarkablePageLink<Void>("summary", SummaryPage.class, WicketUtils.newRepositoryParameter(repositoryName)));\r
@@ -86,7 +90,7 @@ public abstract class RepositoryPage extends BasePage {
                add(new BookmarkablePageLink<Void>("tags", TagsPage.class, WicketUtils.newRepositoryParameter(repositoryName)));\r
                add(new BookmarkablePageLink<Void>("tree", TreePage.class, WicketUtils.newRepositoryParameter(repositoryName)));\r
 \r
-               // per-repository extra page links \r
+               // per-repository extra page links\r
                List<String> extraPageLinks = new ArrayList<String>();\r
 \r
                // Conditionally add tickets page\r
@@ -115,7 +119,7 @@ public abstract class RepositoryPage extends BasePage {
                        }\r
                };\r
                add(extrasView);\r
-               \r
+\r
                // disable current page\r
                disablePageLink(getPageName());\r
 \r
@@ -123,7 +127,7 @@ public abstract class RepositoryPage extends BasePage {
                SearchForm searchForm = new SearchForm("searchForm", repositoryName);\r
                add(searchForm);\r
                searchForm.setTranslatedAttributes();\r
-               \r
+\r
                // set stateless page preference\r
                setStatelessHint(true);\r
        }\r
@@ -154,13 +158,21 @@ public abstract class RepositoryPage extends BasePage {
                }\r
                return r;\r
        }\r
-       \r
+\r
        protected RepositoryModel getRepositoryModel() {\r
                if (m == null) {\r
                        m = GitBlit.self().getRepositoryModel(repositoryName);\r
                }\r
                return m;\r
        }\r
+       \r
+       protected RevCommit getCommit() {\r
+               RevCommit commit = JGitUtils.getCommit(r, objectId);\r
+               if (commit == null) {\r
+                       error(MessageFormat.format("Failed to find commit \"{0}\" in {1} for {2} page!", objectId, repositoryName, getPageName()), true);\r
+               }\r
+               return commit;\r
+       }\r
 \r
        protected void addRefs(Repository r, RevCommit c) {\r
                add(new RefsPanel("refsPanel", repositoryName, c, JGitUtils.getAllRefs(r)));\r
@@ -303,11 +315,11 @@ public abstract class RepositoryPage extends BasePage {
                        TextField<String> searchBox = new TextField<String>("searchBox", searchBoxModel);\r
                        add(searchBox);\r
                }\r
-               \r
-               void setTranslatedAttributes() {                        \r
+\r
+               void setTranslatedAttributes() {\r
                        WicketUtils.setHtmlTooltip(get("searchType"), getString("gb.searchTypeTooltip"));\r
                        WicketUtils.setHtmlTooltip(get("searchBox"), getString("gb.searchTooltip"));\r
-                       WicketUtils.setInputPlaceholder(get("searchBox"), getString("gb.search"));                      \r
+                       WicketUtils.setInputPlaceholder(get("searchBox"), getString("gb.search"));\r
                }\r
 \r
                @Override\r
index 8840f070a51f6bc93c302c6bd90bb4c4c2dd2aee..8efa58dc1cfced50ea52cfd6a981225910f558d3 100644 (file)
@@ -11,6 +11,7 @@ public class RepositoryModel implements Serializable {
        public String owner;\r
        public String group;\r
        public Date lastChange;\r
+       public boolean hasCommits;\r
        public boolean useTickets;\r
        public boolean useDocs;\r
        public boolean useRestrictedAccess;\r
index 983b3c48ef3c19f323205ca23fadb5d70da7f49a..4be48ecc9987c7b225198a5ddc26324ef9e81f0f 100644 (file)
@@ -25,8 +25,8 @@ public class BlobDiffPage extends RepositoryPage {
                final String baseObjectId = WicketUtils.getBaseObjectId(params);\r
 \r
                Repository r = getRepository();\r
-               RevCommit commit = JGitUtils.getCommit(r, objectId);\r
-               \r
+               RevCommit commit = getCommit();\r
+                               \r
                DiffOutputType diffType = DiffOutputType.forName(GitBlit.self().settings().getString(Keys.web.diffStyle, DiffOutputType.GITBLIT.name()));\r
 \r
                String diff;\r
index ca2afe9e6f5b16bd5023a50da78fc2dd00711384..938eaabe4a005d9ba39c7e0b4ded0cb0f1553ab9 100644 (file)
@@ -41,7 +41,7 @@ public class BlobPage extends RepositoryPage {
                \r
                // standard blob view\r
                Repository r = getRepository();\r
-               RevCommit commit = JGitUtils.getCommit(r, objectId);\r
+               RevCommit commit = getCommit();\r
 \r
                // blob page links\r
                add(new Label("blameLink", getString("gb.blame")));\r
index eb30e0888dd5bb35cf0067c2be500a999dd6535d..f293c12bd3ae9ba25535116f90bc1633f88b40cc 100644 (file)
@@ -29,7 +29,7 @@ public class CommitDiffPage extends RepositoryPage {
                super(params);\r
 \r
                Repository r = getRepository();\r
-               RevCommit commit = JGitUtils.getCommit(r, objectId);\r
+               RevCommit commit = getCommit();\r
                DiffOutputType diffType = DiffOutputType.forName(GitBlit.self().settings().getString(Keys.web.diffStyle, DiffOutputType.GITBLIT.name()));\r
                String diff = JGitUtils.getCommitDiff(r, commit, diffType);\r
 \r
index e724ca1222fa561e5133a80db8bc131e778b13b7..5396e821cdeb85330d3b257537c38f4d8c1b515a 100644 (file)
@@ -28,7 +28,7 @@ public class CommitPage extends RepositoryPage {
                super(params);\r
 \r
                Repository r = getRepository();\r
-               RevCommit c = JGitUtils.getCommit(r, objectId);\r
+               RevCommit c = getCommit();\r
 \r
                List<String> parents = new ArrayList<String>();\r
                if (c.getParentCount() > 0) {\r
index 4aebef3d42f7180f84940d53758fd5006d3a780c..6c622455baecb91d7248438a252b7387f18fb1b5 100644 (file)
@@ -8,7 +8,9 @@
 <wicket:extend>\r
        <!-- Push content down to preserve header image -->\r
        <div style="padding-top:20px"></div>\r
-       \r
+\r
+       <div style="text-align:center;" wicket:id="feedback">[Feedback Panel]</div>     \r
+\r
        <!-- Repository Table -->\r
        <form wicket:id="editForm">\r
                <table class="plain">\r
                                <tr><th><wicket:message key="gb.group"></wicket:message></th><td class="edit"><input type="text" wicket:id="group" size="30" tabindex="4" /></td></tr>\r
                                <tr><th><wicket:message key="gb.enableTickets"></wicket:message></th><td class="edit"><input type="checkbox" wicket:id="useTickets" tabindex="5" /> &nbsp;<i>distributed Ticgit issues</i></td></tr>\r
                                <tr><th><wicket:message key="gb.enableDocs"></wicket:message></th><td class="edit"><input type="checkbox" wicket:id="useDocs" tabindex="6" /> &nbsp;<i>enumerates repository Markdown documentation</i></td></tr>\r
-                               <tr><td class="edit" colspan="2"><input type="submit" value="Submit" tabindex="7" /></td></tr>\r
+                               <tr><td class="edit" colspan="2"><input type="submit" value="Save" wicket:message="value:gb.save" tabindex="7" /></td></tr>\r
                        </tbody>\r
                </table>\r
        </form> \r
+\r
 </wicket:extend>\r
 </body>\r
 </html>
\ No newline at end of file
index b7dd1a3cb28199e8bf135a6ac57693ff97cafe06..62431d209198f17be7006c04b32ace5c5cca7e14 100644 (file)
@@ -9,6 +9,7 @@ import org.eclipse.jgit.revwalk.RevCommit;
 import com.gitblit.GitBlit;\r
 import com.gitblit.utils.JGitUtils;\r
 import com.gitblit.utils.StringUtils;\r
+import com.gitblit.wicket.GitBlitWebSession;\r
 import com.gitblit.wicket.WicketUtils;\r
 \r
 public class PatchPage extends WebPage {\r
@@ -17,9 +18,11 @@ public class PatchPage extends WebPage {
                super(params);\r
 \r
                if (!params.containsKey("r")) {\r
-                       error("Repository not specified!");\r
+                       GitBlitWebSession.get().cacheErrorMessage("Repository not specified!");\r
                        redirectToInterceptPage(new RepositoriesPage());\r
+                       return;\r
                }\r
+               \r
                final String repositoryName = WicketUtils.getRepositoryName(params);\r
                final String baseObjectId = WicketUtils.getBaseObjectId(params);\r
                final String objectId = WicketUtils.getObject(params);\r
@@ -27,12 +30,18 @@ public class PatchPage extends WebPage {
 \r
                Repository r = GitBlit.self().getRepository(repositoryName);\r
                if (r == null) {\r
-                       error("Can not load repository " + repositoryName);\r
+                       GitBlitWebSession.get().cacheErrorMessage("Can not load repository " + repositoryName);\r
                        redirectToInterceptPage(new RepositoriesPage());\r
                        return;\r
                }\r
 \r
                RevCommit commit = JGitUtils.getCommit(r, objectId);\r
+               if (commit == null) {\r
+                       GitBlitWebSession.get().cacheErrorMessage("Commit is null");\r
+                       redirectToInterceptPage(new RepositoriesPage());\r
+                       return;\r
+               }\r
+               \r
                String patch;\r
                if (StringUtils.isEmpty(baseObjectId)) {\r
                        patch = JGitUtils.getCommitPatch(r, commit, blobPath);\r
index bb132922e9dc708216a0a62eae43389fcbb8eb68..09de115c68a5a98587b118976ef3a477f89abe01 100644 (file)
@@ -13,6 +13,8 @@
 <wicket:extend>\r
        <div wicket:id="adminPanel">[admin links]</div>\r
        \r
+       <div style="text-align:center;padding-top:20px;" wicket:id="feedback">[Feedback Panel]</div>\r
+       \r
        <div class="markdown" wicket:id="repositoriesMessage">[repositories message]</div>\r
                \r
        <table class="repositories">\r
@@ -46,6 +48,7 @@
        <wicket:fragment wicket:id="repositoryAdminLinks">\r
                <span class="link"><a wicket:id="editRepository"><wicket:message key="gb.edit">[edit]</wicket:message></a> | <a wicket:id="renameRepository"><wicket:message key="gb.rename">[rename]</wicket:message></a> | <a wicket:id="deleteRepository"><wicket:message key="gb.delete">[delete]</wicket:message></a></span>\r
        </wicket:fragment>\r
+       \r
 </wicket:extend>\r
 </body>\r
 </html>
\ No newline at end of file
index 768cea148cf3d21fd9ddc4e74e27ae3e29300b0d..2edb3e8c9f8146d8382c8e62afa1303fd182fccb 100644 (file)
@@ -52,6 +52,13 @@ public class RepositoriesPage extends BasePage {
                adminLinks.add(new BookmarkablePageLink<Void>("newUser", RepositoriesPage.class));\r
                add(adminLinks.setVisible(showAdmin));\r
 \r
+               // display an error message cached from a redirect\r
+               String cachedMessage = GitBlitWebSession.get().clearErrorMessage();\r
+               if (!StringUtils.isEmpty(cachedMessage)) {\r
+                       error(cachedMessage);\r
+                       System.out.println("displayed message");\r
+               }\r
+               \r
                // Load the markdown welcome message\r
                String messageSource = GitBlit.self().settings().getString(Keys.web.repositoriesMessage, "gitblit");\r
                String message = "";\r
@@ -64,7 +71,7 @@ public class RepositoriesPage extends BasePage {
                                message = StringUtils.transformMarkdown(reader);\r
                        } catch (Throwable t) {\r
                                message = "Failed to read default welcome message!";\r
-                               error(message, t);\r
+                               error(message, t, false);\r
                        }\r
                } else {\r
                        // Read user-supplied welcome message\r
@@ -76,7 +83,7 @@ public class RepositoriesPage extends BasePage {
                                                message = StringUtils.transformMarkdown(reader);\r
                                        } catch (Throwable t) {\r
                                                message = "Failed to read " + file;\r
-                                               error(message, t);\r
+                                               error(message, t, false);\r
                                        }\r
                                } else {\r
                                        message = messageSource + " is not a valid file.";\r
@@ -97,10 +104,17 @@ public class RepositoriesPage extends BasePage {
 \r
                        public void populateItem(final Item<RepositoryModel> item) {\r
                                final RepositoryModel entry = item.getModelObject();\r
-                               PageParameters pp = WicketUtils.newRepositoryParameter(entry.name);\r
-                               item.add(new LinkPanel("repositoryName", "list", entry.name, SummaryPage.class, pp));\r
-                               item.add(new LinkPanel("repositoryDescription", "list", entry.description, SummaryPage.class, pp));\r
-\r
+                               if (entry.hasCommits) {\r
+                                       // Existing repository\r
+                                       PageParameters pp = WicketUtils.newRepositoryParameter(entry.name);\r
+                                       item.add(new LinkPanel("repositoryName", "list", entry.name, SummaryPage.class, pp));\r
+                                       item.add(new LinkPanel("repositoryDescription", "list", entry.description, SummaryPage.class, pp));\r
+                               } else {\r
+                                       // New repository\r
+                                       item.add(new Label("repositoryName", entry.name + "<span class='empty'>(empty)</span>").setEscapeModelStrings(false));\r
+                                       item.add(new Label("repositoryDescription", entry.description));                                        \r
+                               }\r
+                               \r
                                if (entry.useTickets) {\r
                                        item.add(WicketUtils.newImage("ticketsIcon", "bug_16x16.png", getString("gb.tickets")));\r
                                } else {\r
index 7448ae5d190fff306d574bba748cd86add93e81a..a95b967d118453cd326f863336b7f31b53c07703 100644 (file)
@@ -19,8 +19,8 @@ public class TagPage extends RepositoryPage {
                super(params);\r
 \r
                Repository r = getRepository();\r
+               RevCommit c = getCommit();\r
                List<RefModel> tags = JGitUtils.getTags(r, -1);\r
-               RevCommit c = JGitUtils.getCommit(r, objectId);\r
 \r
                RefModel tagRef = null;\r
                // determine tag\r
index 56f96d65fdd26e8a93f104de2ccd6132c23237af..ea5bd5304aef5df968b9a1fe5a7e25feb6975559 100644 (file)
@@ -30,7 +30,7 @@ public class TreePage extends RepositoryPage {
                final String path = WicketUtils.getPath(params);\r
 \r
                Repository r = getRepository();\r
-               RevCommit commit = JGitUtils.getCommit(r, objectId);\r
+               RevCommit commit = getCommit();\r
                List<PathModel> paths = JGitUtils.getFilesInPath(r, path, commit);\r
 \r
                // tree page links\r
index da72a7cf6e94d5006d19c27b62671f03e4379f07..bf653ec4beda820e0ae5ced2066adc863b545063 100644 (file)
@@ -1,7 +1,5 @@
 package com.gitblit.wicket.panels;\r
 \r
-import java.util.Date;\r
-\r
 import org.apache.wicket.markup.html.basic.Label;\r
 import org.eclipse.jgit.revwalk.RevCommit;\r
 \r
@@ -15,9 +13,9 @@ public class CommitHeaderPanel extends BasePanel {
 \r
        public CommitHeaderPanel(String id, String repositoryName, RevCommit c) {\r
                super(id);\r
-               add(new LinkPanel("shortmessage", "title", c == null ? "" : c.getShortMessage(), CommitPage.class, WicketUtils.newObjectParameter(repositoryName, c == null ? "" : c.getName())));\r
+               add(new LinkPanel("shortmessage", "title", c.getShortMessage(), CommitPage.class, WicketUtils.newObjectParameter(repositoryName, c.getName())));\r
                add(new Label("commitid", "(" + c.getName().substring(0, 8) + ")"));            \r
-               add(new Label("author", c == null ? "" : c.getAuthorIdent().getName()));\r
-               add(WicketUtils.createDateLabel("date", c == null ? new Date(0) : c.getAuthorIdent().getWhen(), getTimeZone()));\r
+               add(new Label("author", c.getAuthorIdent().getName()));\r
+               add(WicketUtils.createDateLabel("date", c.getAuthorIdent().getWhen(), getTimeZone()));\r
        }\r
 }
\ No newline at end of file
index 7a877324766ef46edafed3d313afc000e8cdee1c..38a54d9f2295a61422b958d49a4ee62b53288b3e 100644 (file)
@@ -55,7 +55,7 @@ public class SearchPanel extends BasePanel {
                hasMore = commits.size() >= itemsPerPage;\r
 \r
                // header\r
-               add(new LinkPanel("header", "title", commit.getShortMessage(), CommitPage.class, WicketUtils.newObjectParameter(repositoryName, commit.getName())));\r
+               add(new LinkPanel("header", "title", commit == null ? "":commit.getShortMessage(), CommitPage.class, WicketUtils.newObjectParameter(repositoryName, commit == null ? "":commit.getName())));\r
 \r
                ListDataProvider<RevCommit> dp = new ListDataProvider<RevCommit>(commits);\r
                DataView<RevCommit> searchView = new DataView<RevCommit>("commit", dp) {\r
index 8317e363a5d9265a380ba9e1326422056670238d..3d0a1cd51af28d8069e7b8e8ab95510018321ab2 100644 (file)
@@ -100,6 +100,13 @@ div.pager {
        padding: 0px 0px 15px 5px;\r
 }\r
 \r
+span.empty {\r
+       font-size: 0.9em;\r
+       font-style: italic;\r
+       padding-left:10px;\r
+       color: #008000;\r
+}\r
+\r
 span.link, span.link a {\r
        font-family: sans-serif;\r
        font-size: 11px;\r
@@ -633,8 +640,7 @@ span .headRef {
 .feedbackPanelERROR {  \r
        color: red;\r
        list-style-image: url(bullet_error.png);\r
-       font-weight: bold;\r
-       text-align:left;\r
+       font-weight: bold;      \r
        vertical-align: top;\r
        padding:0;      \r
        margin:0;       \r
@@ -643,8 +649,7 @@ span .headRef {
 .feedbackPanelINFO {\r
        color: green;\r
        list-style: none;\r
-       font-weight: bold;\r
-       text-align:center;\r
+       font-weight: bold;      \r
        padding:0;\r
        margin:0;\r
 }
\ No newline at end of file