]> source.dussan.org Git - gitblit.git/commitdiff
Patch formatter. Ensure html escaping. css tweaks.
authorJames Moger <james.moger@gitblit.com>
Wed, 13 Apr 2011 13:43:56 +0000 (09:43 -0400)
committerJames Moger <james.moger@gitblit.com>
Wed, 13 Apr 2011 13:43:56 +0000 (09:43 -0400)
32 files changed:
src/com/gitblit/tests/JGitUtilsTest.java
src/com/gitblit/utils/HtmlDiffFormatter.java
src/com/gitblit/utils/JGitUtils.java
src/com/gitblit/utils/PatchFormatter.java [new file with mode: 0644]
src/com/gitblit/utils/TicGitTicket.java [deleted file]
src/com/gitblit/utils/Utils.java
src/com/gitblit/wicket/GitBlitWebApp.java
src/com/gitblit/wicket/GitBlitWebApp.properties
src/com/gitblit/wicket/WicketUtils.java
src/com/gitblit/wicket/models/TicGitTicket.java [new file with mode: 0644]
src/com/gitblit/wicket/pages/BlobDiffPage.html [new file with mode: 0644]
src/com/gitblit/wicket/pages/BlobDiffPage.java [new file with mode: 0644]
src/com/gitblit/wicket/pages/BlobPage.html
src/com/gitblit/wicket/pages/BlobPage.java
src/com/gitblit/wicket/pages/CommitDiffPage.html [new file with mode: 0644]
src/com/gitblit/wicket/pages/CommitDiffPage.java [new file with mode: 0644]
src/com/gitblit/wicket/pages/CommitPage.html
src/com/gitblit/wicket/pages/CommitPage.java
src/com/gitblit/wicket/pages/DiffPage.html [deleted file]
src/com/gitblit/wicket/pages/DiffPage.java [deleted file]
src/com/gitblit/wicket/pages/PatchPage.html [new file with mode: 0644]
src/com/gitblit/wicket/pages/PatchPage.java [new file with mode: 0644]
src/com/gitblit/wicket/pages/RawPage.html [new file with mode: 0644]
src/com/gitblit/wicket/pages/RawPage.java [new file with mode: 0644]
src/com/gitblit/wicket/pages/TagPage.html
src/com/gitblit/wicket/pages/TagPage.java
src/com/gitblit/wicket/pages/TicGitPage.java
src/com/gitblit/wicket/pages/TicGitTicketPage.java
src/com/gitblit/wicket/pages/TreePage.html
src/com/gitblit/wicket/pages/TreePage.java
src/com/gitblit/wicket/panels/LogPanel.java
src/com/gitblit/wicket/resources/gitblit.css

index 708f35af75f4af870658aa345e77524da864ea6f..abc733c9c3c1a5db1061d3c86556e73bfbbe4a49 100644 (file)
@@ -15,9 +15,9 @@ import org.eclipse.jgit.revwalk.RevTree;
 import org.eclipse.jgit.storage.file.FileRepository;\r
 \r
 import com.gitblit.utils.JGitUtils;\r
-import com.gitblit.utils.TicGitTicket;\r
 import com.gitblit.wicket.models.PathModel;\r
 import com.gitblit.wicket.models.RefModel;\r
+import com.gitblit.wicket.models.TicGitTicket;\r
 \r
 public class JGitUtilsTest extends TestCase {\r
 \r
index 7c37862cf563b7a9ebde76a2045dab50f0ab0ae8..08c0c21966a74243d8f4b03f1f2ab217c83e2e80 100644 (file)
@@ -2,6 +2,7 @@ package com.gitblit.utils;
 \r
 import static org.eclipse.jgit.lib.Constants.encodeASCII;\r
 \r
+import java.io.ByteArrayOutputStream;\r
 import java.io.IOException;\r
 import java.io.OutputStream;\r
 \r
@@ -9,6 +10,7 @@ import org.eclipse.jgit.diff.DiffFormatter;
 import org.eclipse.jgit.diff.RawText;\r
 \r
 public class HtmlDiffFormatter extends DiffFormatter {\r
+               \r
        private final OutputStream os;\r
 \r
        public HtmlDiffFormatter(OutputStream os) {\r
@@ -39,9 +41,6 @@ public class HtmlDiffFormatter extends DiffFormatter {
                os.write(' ');\r
                os.write('@');\r
                os.write('@');\r
-               // TODO not sure if JGit can determine hunk section\r
-               //os.write("<span class=\"diff hunk_section\">".getBytes());\r
-               //os.write("</span>".getBytes());\r
                os.write("</span></div>".getBytes());\r
        }\r
 \r
@@ -82,18 +81,22 @@ public class HtmlDiffFormatter extends DiffFormatter {
        protected void writeLine(final char prefix, final RawText text, final int cur) throws IOException {\r
                switch (prefix) {\r
                case '+':\r
-                       os.write("<div class=\"diff add\">".getBytes());\r
+                       os.write("<span class=\"diff add\">".getBytes());\r
                        break;\r
                case '-':\r
-                       os.write("<div class=\"diff remove\">".getBytes());\r
+                       os.write("<span class=\"diff remove\">".getBytes());\r
                        break;\r
                }\r
                os.write(prefix);\r
-               text.writeLine(os, cur);\r
+               ByteArrayOutputStream bos = new ByteArrayOutputStream();\r
+               text.writeLine(bos, cur);\r
+               String line = bos.toString();\r
+               line = Utils.escapeForHtml(line, false);\r
+               os.write(line.getBytes());\r
                switch (prefix) {\r
                case '+':\r
                case '-':\r
-                       os.write("</div>".getBytes());\r
+                       os.write("</span>\n".getBytes());\r
                        break;\r
                default:\r
                        os.write('\n');\r
@@ -115,14 +118,14 @@ public class HtmlDiffFormatter extends DiffFormatter {
                        if (line.startsWith("diff")) {\r
                                sb.append("<div class=\"diff header\">").append(line).append("</div>");\r
                        } else if (line.startsWith("---")) {\r
-                               sb.append("<div class=\"diff remove\">").append(line).append("</div>");\r
+                               sb.append("<span class=\"diff remove\">").append(line).append("</span><br/>");\r
                        } else if (line.startsWith("+++")) {\r
-                               sb.append("<div class=\"diff add\">").append(line).append("</div>");\r
+                               sb.append("<span class=\"diff add\">").append(line).append("</span><br/>");\r
                        } else {\r
                                sb.append(line).append('\n');\r
                        }\r
                }\r
-               sb.append("</div>");\r
+               sb.append("</div>\n");\r
                return sb.toString();\r
        }\r
 }\r
index abecac41a13bd755cabfbbed8eaff3c9c5e9dadf..69c46da4d16a7bb40685ea21ab8b73a5743b997d 100644 (file)
@@ -42,10 +42,11 @@ import org.eclipse.jgit.util.io.DisabledOutputStream;
 import org.slf4j.Logger;\r
 import org.slf4j.LoggerFactory;\r
 \r
-import com.gitblit.utils.TicGitTicket.Comment;\r
 import com.gitblit.wicket.models.Metric;\r
 import com.gitblit.wicket.models.PathModel;\r
 import com.gitblit.wicket.models.RefModel;\r
+import com.gitblit.wicket.models.TicGitTicket;\r
+import com.gitblit.wicket.models.TicGitTicket.Comment;\r
 \r
 public class JGitUtils {\r
 \r
@@ -98,12 +99,15 @@ public class JGitUtils {
                return getCommitDate(commit);\r
        }\r
 \r
-       public static RevCommit getCommit(Repository r, String commitId) {\r
+       public static RevCommit getCommit(Repository r, String objectId) {\r
                RevCommit commit = null;\r
                try {\r
-                       ObjectId objectId = r.resolve(commitId);\r
+                       if (objectId == null || objectId.trim().length() == 0) {\r
+                               objectId = Constants.HEAD;\r
+                       }\r
+                       ObjectId object = r.resolve(objectId);\r
                        RevWalk walk = new RevWalk(r);\r
-                       RevCommit rev = walk.parseCommit(objectId);\r
+                       RevCommit rev = walk.parseCommit(object);\r
                        commit = rev;\r
                        walk.dispose();\r
                } catch (Throwable t) {\r
@@ -205,8 +209,8 @@ public class JGitUtils {
                return new String(getRawContent(r, (RevBlob) obj));\r
        }\r
 \r
-       public static List<PathModel> getFilesInPath(Repository r, String basePath, String commitId) {\r
-               RevCommit commit = getCommit(r, commitId);\r
+       public static List<PathModel> getFilesInPath(Repository r, String basePath, String objectId) {\r
+               RevCommit commit = getCommit(r, objectId);\r
                return getFilesInPath(r, basePath, commit);\r
        }\r
 \r
@@ -298,11 +302,7 @@ public class JGitUtils {
                        walk.setRecursive(true);\r
                        walk.addTree(parentTree);\r
                        walk.addTree(commitTree);\r
-                       if (path != null && path.trim().length() > 0) {\r
-                               walk.setFilter(PathFilter.create(path));\r
-                       } else {\r
-                               walk.setFilter(TreeFilter.ANY_DIFF);\r
-                       }\r
+                       walk.setFilter(TreeFilter.ANY_DIFF);\r
 \r
                        final ByteArrayOutputStream os = new ByteArrayOutputStream();\r
                        RawTextComparator cmp = RawTextComparator.DEFAULT;\r
@@ -316,7 +316,16 @@ public class JGitUtils {
                        df.setDiffComparator(cmp);\r
                        df.setDetectRenames(true);\r
                        List<DiffEntry> diffs = df.scan(parentTree, commitTree);\r
-                       df.format(diffs);\r
+                       if (path != null && path.length() > 0) {\r
+                               for (DiffEntry diff : diffs) {\r
+                                       if (diff.getNewPath().equalsIgnoreCase(path)) {\r
+                                               df.format(diff);\r
+                                               break;\r
+                                       }\r
+                               }\r
+                       } else {\r
+                               df.format(diffs);\r
+                       }\r
                        String diff;\r
                        if (outputHtml) {\r
                                // workaround for complex private methods in DiffFormatter\r
@@ -331,6 +340,50 @@ public class JGitUtils {
                }\r
                return null;\r
        }\r
+       \r
+       public static String getCommitPatch(Repository r, RevCommit commit) {\r
+               return getCommitPatch(r, commit);\r
+       }\r
+       \r
+       public static String getCommitPatch(Repository r, RevCommit commit, String path) {\r
+               try {\r
+                       final RevWalk rw = new RevWalk(r);\r
+                       RevCommit parent = rw.parseCommit(commit.getParent(0).getId());\r
+                       RevTree parentTree = parent.getTree();\r
+                       RevTree commitTree = commit.getTree();\r
+\r
+                       final TreeWalk walk = new TreeWalk(r);\r
+                       walk.reset();\r
+                       walk.setRecursive(true);\r
+                       walk.addTree(parentTree);\r
+                       walk.addTree(commitTree);\r
+                       walk.setFilter(TreeFilter.ANY_DIFF);\r
+\r
+                       final ByteArrayOutputStream os = new ByteArrayOutputStream();\r
+                       RawTextComparator cmp = RawTextComparator.DEFAULT;\r
+                       PatchFormatter df = new PatchFormatter(os);\r
+                       df.setRepository(r);\r
+                       df.setDiffComparator(cmp);\r
+                       df.setDetectRenames(true);\r
+                       List<DiffEntry> diffs = df.scan(parentTree, commitTree);\r
+                       if (path != null && path.length() > 0) {\r
+                               for (DiffEntry diff : diffs) {\r
+                                       if (diff.getNewPath().equalsIgnoreCase(path)) {\r
+                                               df.format(diff);\r
+                                               break;\r
+                                       }\r
+                               }\r
+                       } else {\r
+                               df.format(diffs);\r
+                       }\r
+                       String diff = df.getPatch(commit);\r
+                       df.flush();\r
+                       return diff;\r
+               } catch (Throwable t) {\r
+                       LOGGER.error("failed to generate commit diff!", t);\r
+               }\r
+               return null;\r
+       }\r
 \r
        private static PathModel getPathModel(TreeWalk walk, String basePath, RevCommit commit) {\r
                String name;\r
@@ -523,6 +576,7 @@ public class JGitUtils {
        }\r
 \r
        public static List<Metric> getDateMetrics(Repository r) {\r
+               final List<RefModel> tags = getTags(r, -1);\r
                final Map<String, Metric> map = new HashMap<String, Metric>();\r
                try {\r
                        DateFormat df = new SimpleDateFormat("yyyy-MM");\r
diff --git a/src/com/gitblit/utils/PatchFormatter.java b/src/com/gitblit/utils/PatchFormatter.java
new file mode 100644 (file)
index 0000000..f019ce4
--- /dev/null
@@ -0,0 +1,111 @@
+package com.gitblit.utils;\r
+\r
+import java.io.IOException;\r
+import java.io.OutputStream;\r
+import java.text.MessageFormat;\r
+import java.text.SimpleDateFormat;\r
+import java.util.Date;\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
+import org.eclipse.jgit.diff.DiffEntry;\r
+import org.eclipse.jgit.diff.DiffFormatter;\r
+import org.eclipse.jgit.diff.RawText;\r
+import org.eclipse.jgit.revwalk.RevCommit;\r
+\r
+import com.gitblit.Constants;\r
+\r
+public class PatchFormatter extends DiffFormatter {\r
+\r
+       private final OutputStream os;\r
+\r
+       private PatchTouple currentTouple = null;\r
+\r
+       Map<String, PatchTouple> changes = new HashMap<String, PatchTouple>();\r
+\r
+       public PatchFormatter(OutputStream os) {\r
+               super(os);\r
+               this.os = os;\r
+       }\r
+\r
+       public void format(DiffEntry entry) throws IOException {\r
+               currentTouple = new PatchTouple();\r
+               changes.put(entry.getNewPath(), currentTouple);\r
+               super.format(entry);\r
+       }\r
+\r
+       @Override\r
+       protected void writeLine(final char prefix, final RawText text, final int cur) throws IOException {\r
+               switch (prefix) {\r
+               case '+':\r
+                       currentTouple.insertions++;\r
+                       break;\r
+               case '-':\r
+                       currentTouple.deletions++;\r
+                       break;\r
+               }\r
+               super.writeLine(prefix, text, cur);\r
+       }\r
+\r
+       public String getPatch(RevCommit commit) {\r
+               StringBuilder patch = new StringBuilder();\r
+               // hard-code the mon sep 17 2001 date string.\r
+               // I have no idea why that is there. it seems to be a constant.\r
+               patch.append("From " + commit.getName() + " Mon Sep 17 00:00:00 2001" + "\n");\r
+               patch.append("From: " + JGitUtils.getDisplayName(commit.getAuthorIdent()) + "\n");\r
+               patch.append("Date: " + (new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z").format(new Date(commit.getCommitTime() * 1000l))) + "\n");\r
+               patch.append("Subject: [PATCH] " + commit.getShortMessage() + "\n");\r
+               patch.append("\n");\r
+               patch.append("---");\r
+               int maxPathLen = 0;\r
+               int files = 0;\r
+               int insertions = 0;\r
+               int deletions = 0;\r
+               for (String path : changes.keySet()) {\r
+                       if (path.length() > maxPathLen) {\r
+                               maxPathLen = path.length();\r
+                       }\r
+                       PatchTouple touple = changes.get(path);\r
+                       files++;\r
+                       insertions += touple.insertions;\r
+                       deletions += touple.deletions;\r
+               }\r
+               int columns = 60;\r
+               int total = insertions + deletions;\r
+               int unit = total / columns + (total % columns > 0 ? 1 : 0);\r
+               if (unit == 0) {\r
+                       unit = 1;\r
+               }\r
+               for (String path : changes.keySet()) {\r
+                       PatchTouple touple = changes.get(path);\r
+                       patch.append("\n " + Utils.rightPad(path, maxPathLen, ' ') + " | " + Utils.leftPad("" + touple.total(), 4, ' ') + " " + touple.relativeScale(unit));\r
+               }\r
+               patch.append(MessageFormat.format("\n {0} files changed, {1} insertions(+), {2} deletions(-)\n\n", files, insertions, deletions));\r
+               patch.append(os.toString());\r
+               patch.append("\n--\n");\r
+               patch.append(Constants.getRunningVersion());\r
+               return patch.toString();\r
+       }\r
+\r
+       private class PatchTouple {\r
+               int insertions = 0;\r
+               int deletions = 0;\r
+\r
+               int total() {\r
+                       return insertions + deletions;\r
+               }\r
+\r
+               String relativeScale(int unit) {\r
+                       int plus = (insertions / unit);\r
+                       int minus = (deletions / unit);\r
+                       StringBuilder sb = new StringBuilder();\r
+                       for (int i = 0; i < plus; i++) {\r
+                               sb.append('+');\r
+                       }\r
+                       for (int i = 0; i < minus; i++) {\r
+                               sb.append('-');\r
+                       }\r
+                       return sb.toString();\r
+               }\r
+       }\r
+}\r
diff --git a/src/com/gitblit/utils/TicGitTicket.java b/src/com/gitblit/utils/TicGitTicket.java
deleted file mode 100644 (file)
index 48491a6..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-package com.gitblit.utils;\r
-\r
-import java.io.Serializable;\r
-import java.text.ParseException;\r
-import java.util.ArrayList;\r
-import java.util.Collections;\r
-import java.util.Date;\r
-import java.util.List;\r
-\r
-import com.gitblit.wicket.models.PathModel;\r
-\r
-public class TicGitTicket implements Serializable, Comparable<TicGitTicket> {\r
-\r
-       private static final long serialVersionUID = 1L;\r
-\r
-       public String id;\r
-       public String name;\r
-       public String title;\r
-       public String state;\r
-       public Date date;\r
-       public String handler;\r
-       public String milestone;\r
-       public String email;\r
-       public String author;\r
-       public List<Comment> comments;\r
-       public List<String> tags;\r
-\r
-       public TicGitTicket() {\r
-               state = "open";\r
-               comments = new ArrayList<Comment>();\r
-               tags = new ArrayList<String>();\r
-       }\r
-\r
-       public TicGitTicket(String ticketName) throws ParseException {\r
-               state = "";\r
-               name = ticketName;\r
-               comments = new ArrayList<Comment>();\r
-               tags = new ArrayList<String>();\r
-\r
-               String[] chunks = name.split("_");\r
-               if (chunks.length == 3) {\r
-                       date = new Date(Long.parseLong(chunks[0]) * 1000l);\r
-                       title = chunks[1].replace('-', ' ');\r
-               }               \r
-       }\r
-\r
-       public static class Comment implements Serializable, Comparable<Comment> {\r
-               \r
-               private static final long serialVersionUID = 1L;\r
-               \r
-               public String text;\r
-               public String author;\r
-               public Date date;\r
-\r
-               public Comment(String text, Date date) {\r
-                       this.text = text;\r
-                       this.date = date;\r
-               }\r
-\r
-               public Comment(String filename, String content) throws ParseException {\r
-                       String[] chunks = filename.split("_", -1);\r
-                       this.date = new Date(Long.parseLong(chunks[1]) * 1000l);\r
-                       this.author = chunks[2];\r
-                       this.text = content;\r
-               }\r
-\r
-               @Override\r
-               public int compareTo(Comment o) {\r
-                       return date.compareTo(o.date);\r
-               }\r
-       }\r
-\r
-       @Override\r
-       public int compareTo(TicGitTicket o) {\r
-               return date.compareTo(o.date);\r
-       }\r
-}\r
index bef41b29329897f30fc66204357d349cb928bcfa..c742fb624faa8f9bc692399e7d7426a4b74c2f34 100644 (file)
@@ -116,4 +116,51 @@ public class Utils {
                }\r
                return ago;\r
        }\r
+       \r
+       public static String leftPad(String input, int length, char pad) {\r
+               if (input.length() < length) {\r
+                       StringBuilder sb = new StringBuilder();\r
+                       for (int i = 0, len = length - input.length(); i < len; i++) {\r
+                               sb.append(pad);\r
+                       }\r
+                       sb.append(input);\r
+                       return sb.toString();\r
+               }\r
+               return input;\r
+       }\r
+       \r
+       public static String rightPad(String input, int length, char pad) {\r
+               if (input.length() < length) {\r
+                       StringBuilder sb = new StringBuilder();\r
+                       sb.append(input);\r
+                       for (int i = 0, len = length - input.length(); i < len; i++) {\r
+                               sb.append(pad);\r
+                       }                       \r
+                       return sb.toString();\r
+               }\r
+               return input;\r
+       }\r
+       \r
+       public static String escapeForHtml(String inStr, boolean changeSpace) {\r
+               StringBuffer retStr = new StringBuffer();\r
+               int i = 0;\r
+               while (i < inStr.length()) {\r
+                       if (inStr.charAt(i) == '&') {\r
+                               retStr.append("&amp;");\r
+                       } else if (inStr.charAt(i) == '<') {\r
+                               retStr.append("&lt;");\r
+                       } else if (inStr.charAt(i) == '>') {\r
+                               retStr.append("&gt;");\r
+                       } else if (inStr.charAt(i) == '\"') {\r
+                               retStr.append("&quot;");\r
+                       } else if (changeSpace && inStr.charAt(i) == ' ') {\r
+                               retStr.append("&nbsp;");\r
+                       } else if (changeSpace && inStr.charAt(i) == '\t') {\r
+                               retStr.append(" &nbsp; &nbsp;");\r
+                       } else\r
+                               retStr.append(inStr.charAt(i));\r
+                       i++;\r
+               }\r
+               return retStr.toString();\r
+       }\r
 }\r
index 90a03715b3bd1d71d548b6ea442bbf881f4815b8..b869a05fa04376397dc94e72fa7a13f66fca559f 100644 (file)
@@ -28,12 +28,15 @@ import com.gitblit.GitBlitServer;
 import com.gitblit.StoredSettings;\r
 import com.gitblit.utils.JGitUtils;\r
 import com.gitblit.wicket.models.RepositoryModel;\r
+import com.gitblit.wicket.pages.BlobDiffPage;\r
 import com.gitblit.wicket.pages.BlobPage;\r
 import com.gitblit.wicket.pages.BranchesPage;\r
 import com.gitblit.wicket.pages.CommitPage;\r
-import com.gitblit.wicket.pages.DiffPage;\r
-import com.gitblit.wicket.pages.RepositoriesPage;\r
+import com.gitblit.wicket.pages.CommitDiffPage;\r
 import com.gitblit.wicket.pages.LogPage;\r
+import com.gitblit.wicket.pages.PatchPage;\r
+import com.gitblit.wicket.pages.RawPage;\r
+import com.gitblit.wicket.pages.RepositoriesPage;\r
 import com.gitblit.wicket.pages.SummaryPage;\r
 import com.gitblit.wicket.pages.TagPage;\r
 import com.gitblit.wicket.pages.TagsPage;\r
@@ -70,7 +73,10 @@ public class GitBlitWebApp extends WebApplication {
                mount(new MixedParamUrlCodingStrategy("/tag", TagPage.class, new String[] { "r", "h" }));\r
                mount(new MixedParamUrlCodingStrategy("/tree", TreePage.class, new String[] { "r", "h", "f" }));\r
                mount(new MixedParamUrlCodingStrategy("/blob", BlobPage.class, new String[] { "r", "h", "f" }));\r
-               mount(new MixedParamUrlCodingStrategy("/diff", DiffPage.class, new String[] { "r", "h", "f" }));\r
+               mount(new MixedParamUrlCodingStrategy("/raw", RawPage.class, new String[] { "r", "h", "f" }));\r
+               mount(new MixedParamUrlCodingStrategy("/blobdiff", BlobDiffPage.class, new String[] { "r", "h", "f" }));\r
+               mount(new MixedParamUrlCodingStrategy("/commitdiff", CommitDiffPage.class, new String[] { "r", "h" }));\r
+               mount(new MixedParamUrlCodingStrategy("/patch", PatchPage.class, new String[] { "r", "h", "f" }));\r
                \r
                // setup extended urls\r
                mount(new MixedParamUrlCodingStrategy("/ticgit", TicGitPage.class, new String[] { "p" }));\r
index 1d7e7bab7ee32b63c1f14db4bf05f4fc9679d462..273ff5a7255dd3e070f339dd1a274c98c61cb454 100644 (file)
@@ -38,4 +38,6 @@ gb.ticgit = ticgit
 gb.pageFirst = first\r
 gb.pagePrevious prev\r
 gb.pageNext = next\r
-gb.parent = parent
\ No newline at end of file
+gb.parent = parent\r
+gb.head = HEAD\r
+gb.blame = blame
\ No newline at end of file
index 3a5ab9213f02063b93017f22bf4d691a2fc580b9..65270a2c3f7d090b02d3634c5185d15b493b754c 100644 (file)
@@ -10,6 +10,7 @@ import org.apache.wicket.Component;
 import org.apache.wicket.PageParameters;\r
 import org.apache.wicket.behavior.SimpleAttributeModifier;\r
 import org.apache.wicket.markup.html.basic.Label;\r
+import org.eclipse.jgit.lib.Constants;\r
 \r
 import com.gitblit.StoredSettings;\r
 import com.gitblit.utils.Utils;\r
@@ -108,7 +109,7 @@ public class WicketUtils {
        }\r
 \r
        public static String getObject(PageParameters params) {\r
-               return params.getString("h", "");\r
+               return params.getString("h", Constants.HEAD);\r
        }\r
 \r
        public static String getPath(PageParameters params) {\r
diff --git a/src/com/gitblit/wicket/models/TicGitTicket.java b/src/com/gitblit/wicket/models/TicGitTicket.java
new file mode 100644 (file)
index 0000000..50f1e08
--- /dev/null
@@ -0,0 +1,74 @@
+package com.gitblit.wicket.models;\r
+\r
+import java.io.Serializable;\r
+import java.text.ParseException;\r
+import java.util.ArrayList;\r
+import java.util.Date;\r
+import java.util.List;\r
+\r
+public class TicGitTicket implements Serializable, Comparable<TicGitTicket> {\r
+\r
+       private static final long serialVersionUID = 1L;\r
+\r
+       public String id;\r
+       public String name;\r
+       public String title;\r
+       public String state;\r
+       public Date date;\r
+       public String handler;\r
+       public String milestone;\r
+       public String email;\r
+       public String author;\r
+       public List<Comment> comments;\r
+       public List<String> tags;\r
+\r
+       public TicGitTicket() {\r
+               state = "open";\r
+               comments = new ArrayList<Comment>();\r
+               tags = new ArrayList<String>();\r
+       }\r
+\r
+       public TicGitTicket(String ticketName) throws ParseException {\r
+               state = "";\r
+               name = ticketName;\r
+               comments = new ArrayList<Comment>();\r
+               tags = new ArrayList<String>();\r
+\r
+               String[] chunks = name.split("_");\r
+               if (chunks.length == 3) {\r
+                       date = new Date(Long.parseLong(chunks[0]) * 1000l);\r
+                       title = chunks[1].replace('-', ' ');\r
+               }               \r
+       }\r
+\r
+       public static class Comment implements Serializable, Comparable<Comment> {\r
+               \r
+               private static final long serialVersionUID = 1L;\r
+               \r
+               public String text;\r
+               public String author;\r
+               public Date date;\r
+\r
+               public Comment(String text, Date date) {\r
+                       this.text = text;\r
+                       this.date = date;\r
+               }\r
+\r
+               public Comment(String filename, String content) throws ParseException {\r
+                       String[] chunks = filename.split("_", -1);\r
+                       this.date = new Date(Long.parseLong(chunks[1]) * 1000l);\r
+                       this.author = chunks[2];\r
+                       this.text = content;\r
+               }\r
+\r
+               @Override\r
+               public int compareTo(Comment o) {\r
+                       return date.compareTo(o.date);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public int compareTo(TicGitTicket o) {\r
+               return date.compareTo(o.date);\r
+       }\r
+}\r
diff --git a/src/com/gitblit/wicket/pages/BlobDiffPage.html b/src/com/gitblit/wicket/pages/BlobDiffPage.html
new file mode 100644 (file)
index 0000000..2267b37
--- /dev/null
@@ -0,0 +1,29 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r
+<html xmlns="http://www.w3.org/1999/xhtml"  \r
+      xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.3-strict.dtd"  \r
+      xml:lang="en"  \r
+      lang="en"> \r
+\r
+<body>\r
+<wicket:extend>\r
+\r
+       <!-- page nav links --> \r
+       <div wicket:id="pageLinks">[page links]</div>\r
+       \r
+       <!-- blob nav links --> \r
+       <div class="page_nav2">\r
+               <span wicket:id="blameLink">[blame link]</span> | <span wicket:id="historyLink">[history 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="commitDiffLink"><wicket:message key="gb.commitdiff"></wicket:message></a>\r
+       </div>  \r
+       \r
+       <!-- shortlog header -->\r
+       <div class="header" wicket:id="shortlog">[shortlog header]</div>\r
+\r
+       <!-- breadcrumbs -->\r
+       <div wicket:id="breadcrumbs">[breadcrumbs]</div>\r
+               \r
+       <!--  diff content -->\r
+       <pre wicket:id="diffText">[diff text]</pre>\r
+       \r
+</wicket:extend>\r
+</body>\r
+</html>
\ No newline at end of file
diff --git a/src/com/gitblit/wicket/pages/BlobDiffPage.java b/src/com/gitblit/wicket/pages/BlobDiffPage.java
new file mode 100644 (file)
index 0000000..17d7896
--- /dev/null
@@ -0,0 +1,44 @@
+package com.gitblit.wicket.pages;\r
+\r
+import org.apache.wicket.PageParameters;\r
+import org.apache.wicket.markup.html.basic.Label;\r
+import org.apache.wicket.markup.html.link.BookmarkablePageLink;\r
+import org.eclipse.jgit.lib.Repository;\r
+import org.eclipse.jgit.revwalk.RevCommit;\r
+\r
+import com.gitblit.utils.JGitUtils;\r
+import com.gitblit.wicket.LinkPanel;\r
+import com.gitblit.wicket.RepositoryPage;\r
+import com.gitblit.wicket.WicketUtils;\r
+import com.gitblit.wicket.panels.PathBreadcrumbsPanel;\r
+\r
+public class BlobDiffPage extends RepositoryPage {\r
+\r
+       public BlobDiffPage(PageParameters params) {\r
+               super(params);\r
+\r
+               final String blobPath = WicketUtils.getPath(params);\r
+\r
+               Repository r = getRepository();\r
+               RevCommit commit = JGitUtils.getCommit(r, objectId);\r
+               String diff = JGitUtils.getCommitDiff(r, commit, blobPath, true);\r
+               add(new BookmarkablePageLink<Void>("patchLink", PatchPage.class, WicketUtils.newPathParameter(repositoryName, objectId, blobPath)));\r
+               add(new BookmarkablePageLink<Void>("commitLink", CommitPage.class, WicketUtils.newObjectParameter(repositoryName, objectId)));\r
+               add(new BookmarkablePageLink<Void>("commitDiffLink", CommitDiffPage.class, WicketUtils.newObjectParameter(repositoryName, objectId)));\r
+\r
+               // diff page links\r
+               add(new Label("blameLink", getString("gb.blame")));\r
+               add(new Label("historyLink", getString("gb.history")));\r
+\r
+               add(new LinkPanel("shortlog", "title", commit.getShortMessage(), CommitPage.class, newCommitParameter()));\r
+\r
+               add(new PathBreadcrumbsPanel("breadcrumbs", repositoryName, blobPath, objectId));\r
+               \r
+               add(new Label("diffText", diff).setEscapeModelStrings(false));\r
+       }\r
+       \r
+       @Override\r
+       protected String getPageName() {\r
+               return getString("gb.diff");\r
+       }\r
+}\r
index 82ba32029f85741a84e79288fe0d6def65ef4c4e..393470a0f18f1777aa9cf77593aff8e906862de0 100644 (file)
@@ -21,7 +21,7 @@
        \r
                <!-- blob nav links --> \r
                <div class="page_nav2">\r
-                       <span wicket:id="historyLink">[history link]</span> | <span wicket:id="rawLink">[raw link]</span> | <span wicket:id="headLink">[head link]</span>\r
+                       <span wicket:id="blameLink">[blame link]</span> | <span wicket:id="historyLink">[history link]</span> | <a wicket:id="rawLink"><wicket:message key="gb.raw"></wicket:message></a> | <a wicket:id="headLink"><wicket:message key="gb.head"></wicket:message></a>\r
                </div>  \r
        \r
                <!-- shortlog header -->\r
index 7d7259a0e8a17685c21338fbf6a9e7addb20a804..0c112d08f665f19608b82b92b19073232e59e43b 100644 (file)
@@ -6,6 +6,8 @@ import java.util.Map;
 import org.apache.wicket.Component;\r
 import org.apache.wicket.PageParameters;\r
 import org.apache.wicket.markup.html.basic.Label;\r
+import org.apache.wicket.markup.html.link.BookmarkablePageLink;\r
+import org.eclipse.jgit.lib.Constants;\r
 import org.eclipse.jgit.lib.Repository;\r
 import org.eclipse.jgit.revwalk.RevCommit;\r
 \r
@@ -28,9 +30,10 @@ public class BlobPage extends RepositoryPage {
                RevCommit commit = JGitUtils.getCommit(r, objectId);\r
 \r
                // blob page links\r
+               add(new Label("blameLink", getString("gb.blame")));\r
                add(new Label("historyLink", getString("gb.history")));\r
-               add(new Label("rawLink", getString("gb.raw")));\r
-               add(new Label("headLink", "HEAD"));\r
+               add(new BookmarkablePageLink<Void>("rawLink", RawPage.class, WicketUtils.newPathParameter(repositoryName, objectId, blobPath)));\r
+               add(new BookmarkablePageLink<Void>("headLink", BlobPage.class, WicketUtils.newPathParameter(repositoryName, Constants.HEAD, blobPath)));\r
 \r
                add(new LinkPanel("shortlog", "title", commit.getShortMessage(), CommitPage.class, newCommitParameter()));\r
 \r
diff --git a/src/com/gitblit/wicket/pages/CommitDiffPage.html b/src/com/gitblit/wicket/pages/CommitDiffPage.html
new file mode 100644 (file)
index 0000000..2759de8
--- /dev/null
@@ -0,0 +1,38 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r
+<html xmlns="http://www.w3.org/1999/xhtml"  \r
+      xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.3-strict.dtd"  \r
+      xml:lang="en"  \r
+      lang="en"> \r
+\r
+<body>\r
+<wicket:extend>\r
+\r
+       <!-- page nav links --> \r
+       <div wicket:id="pageLinks">[page links]</div>\r
+       \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
+       </div>  \r
+       \r
+       <!-- shortlog header -->\r
+       <div class="header" wicket:id="shortlog">[shortlog header]</div>\r
+\r
+       <!-- changed paths -->\r
+       <table style="margin-top:10px;border-top:1px solid #bbb;" class="pretty">\r
+               <tr wicket:id="changedPath">\r
+                       <td class="path"><span wicket:id="pathName">[commit path]</span></td>                   \r
+                       <td>\r
+                               <div class="link">\r
+                                       <a wicket:id="patch"><wicket:message key="gb.patch"></wicket:message></a> | <a wicket:id="view"><wicket:message key="gb.view"></wicket:message></a> | <a wicket:id="blame"><wicket:message key="gb.blame"></wicket:message></a> | <a wicket:id="history"><wicket:message key="gb.history"></wicket:message></a>\r
+                               </div>\r
+                       </td>\r
+               </tr>\r
+       </table>\r
+       \r
+       <!--  diff content -->\r
+       <pre wicket:id="diffText">[diff text]</pre>\r
+       \r
+</wicket:extend>\r
+</body>\r
+</html>
\ No newline at end of file
diff --git a/src/com/gitblit/wicket/pages/CommitDiffPage.java b/src/com/gitblit/wicket/pages/CommitDiffPage.java
new file mode 100644 (file)
index 0000000..7f6d347
--- /dev/null
@@ -0,0 +1,80 @@
+package com.gitblit.wicket.pages;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.apache.wicket.PageParameters;\r
+import org.apache.wicket.markup.html.basic.Label;\r
+import org.apache.wicket.markup.html.link.BookmarkablePageLink;\r
+import org.apache.wicket.markup.repeater.Item;\r
+import org.apache.wicket.markup.repeater.data.DataView;\r
+import org.apache.wicket.markup.repeater.data.ListDataProvider;\r
+import org.eclipse.jgit.lib.Repository;\r
+import org.eclipse.jgit.revwalk.RevCommit;\r
+\r
+import com.gitblit.utils.JGitUtils;\r
+import com.gitblit.wicket.LinkPanel;\r
+import com.gitblit.wicket.RepositoryPage;\r
+import com.gitblit.wicket.WicketUtils;\r
+import com.gitblit.wicket.models.PathModel;\r
+\r
+public class CommitDiffPage extends RepositoryPage {\r
+\r
+       public CommitDiffPage(PageParameters params) {\r
+               super(params);\r
+\r
+               Repository r = getRepository();\r
+               RevCommit commit = JGitUtils.getCommit(r, objectId);\r
+               String diff = JGitUtils.getCommitDiff(r, commit, true);         \r
+               \r
+               List<String> parents = new ArrayList<String>();\r
+               if (commit.getParentCount() > 0) {\r
+                       for (RevCommit parent : commit.getParents()) {\r
+                               parents.add(parent.name());\r
+                       }\r
+               }\r
+               \r
+               // commit page links\r
+               if (parents.size() == 0) {\r
+                       add(new Label("parentLink", "none"));\r
+               } else {\r
+                       add(new LinkPanel("parentLink", null, parents.get(0).substring(0, 8), CommitDiffPage.class, newCommitParameter(parents.get(0))));\r
+               }\r
+               add(new BookmarkablePageLink<Void>("patchLink", PatchPage.class, WicketUtils.newObjectParameter(repositoryName, objectId)));\r
+               add(new BookmarkablePageLink<Void>("commitLink", CommitPage.class, WicketUtils.newObjectParameter(repositoryName, objectId)));\r
+\r
+               add(new LinkPanel("shortlog", "title", commit.getShortMessage(), CommitPage.class, newCommitParameter()));\r
+\r
+               // changed paths list\r
+               List<PathModel> paths  = JGitUtils.getFilesInCommit(r, commit);\r
+               ListDataProvider<PathModel> pathsDp = new ListDataProvider<PathModel>(paths);\r
+               DataView<PathModel> pathsView = new DataView<PathModel>("changedPath", pathsDp) {\r
+                       private static final long serialVersionUID = 1L;\r
+                       int counter = 0;\r
+\r
+                       public void populateItem(final Item<PathModel> item) {\r
+                               final PathModel entry = item.getModelObject();\r
+                               if (entry.isTree()) {\r
+                                       item.add(new LinkPanel("pathName", null, entry.path, TreePage.class, newPathParameter(entry.path)));\r
+                               } else {\r
+                                       item.add(new LinkPanel("pathName", "list", entry.path, BlobPage.class, newPathParameter(entry.path)));\r
+                               }\r
+                               \r
+                               item.add(new BookmarkablePageLink<Void>("patch", PatchPage.class, newPathParameter(entry.path)));\r
+                               item.add(new BookmarkablePageLink<Void>("view", BlobPage.class, newPathParameter(entry.path)));\r
+                               item.add(new BookmarkablePageLink<Void>("blame", BlobPage.class).setEnabled(false));\r
+                               item.add(new BookmarkablePageLink<Void>("history", BlobPage.class).setEnabled(false));\r
+\r
+                               WicketUtils.setAlternatingBackground(item, counter);\r
+                               counter++;\r
+                       }\r
+               };\r
+               add(pathsView);\r
+               add(new Label("diffText", diff).setEscapeModelStrings(false));\r
+       }\r
+       \r
+       @Override\r
+       protected String getPageName() {\r
+               return getString("gb.commitdiff");\r
+       }\r
+}\r
index 0614c0636b2965b6500ef3317f9a350750da234e..a65c5884fbd12f10cace251b817239c395589abd 100644 (file)
@@ -12,7 +12,7 @@
        \r
        <!-- commit nav links -->       \r
        <div class="page_nav2">\r
-               <wicket:message key="gb.parent"></wicket:message>: <span wicket:id="parentLink">[parent link]</span> | <span wicket:id="patchLink">[patch link]</span> | <span wicket:id="commitdiffLink">[commitdiff link]</span>\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> | <span wicket:id="commitdiffLink">[commitdiff link]</span>\r
        </div>  \r
        \r
        <!-- shortlog header -->\r
@@ -40,7 +40,7 @@
                        <td class="path"><span wicket:id="pathName">[commit path]</span></td>                   \r
                        <td>\r
                                <div class="link">\r
-                                       <a wicket:id="diff"><wicket:message key="gb.diff"></wicket:message></a> | <a wicket:id="view"><wicket:message key="gb.view"></wicket:message></a> | <a wicket:id="history"><wicket:message key="gb.history"></wicket:message></a>\r
+                                       <a wicket:id="diff"><wicket:message key="gb.diff"></wicket:message></a> | <a wicket:id="view"><wicket:message key="gb.view"></wicket:message></a> | <a wicket:id="blame"><wicket:message key="gb.blame"></wicket:message></a> | <a wicket:id="history"><wicket:message key="gb.history"></wicket:message></a>\r
                                </div>\r
                        </td>\r
                </tr>\r
index a53e322e163d31b1c92006629e1e6e16356ceaaf..d906f075158a856c3d24e671b5093c4bb736b30c 100644 (file)
@@ -41,11 +41,11 @@ public class CommitPage extends RepositoryPage {
                        add(new Label("commitdiffLink", getString("gb.commitdiff")));\r
                } else {\r
                        add(new LinkPanel("parentLink", null, parents.get(0).substring(0, 8), CommitPage.class, newCommitParameter(parents.get(0))));\r
-                       add(new LinkPanel("commitdiffLink", null, new StringResourceModel("gb.commitdiff", this, null), DiffPage.class, WicketUtils.newObjectParameter(repositoryName, objectId)));\r
+                       add(new LinkPanel("commitdiffLink", null, new StringResourceModel("gb.commitdiff", this, null), CommitDiffPage.class, WicketUtils.newObjectParameter(repositoryName, objectId)));\r
                }\r
-               add(new Label("patchLink", getString("gb.patch")));\r
+               add(new BookmarkablePageLink<Void>("patchLink", PatchPage.class, WicketUtils.newObjectParameter(repositoryName, objectId)));\r
                \r
-               add(new LinkPanel("shortlog", "title", c.getShortMessage(), LogPage.class, newRepositoryParameter()));\r
+               add(new LinkPanel("shortlog", "title", c.getShortMessage(), CommitDiffPage.class, WicketUtils.newObjectParameter(repositoryName, objectId)));\r
                \r
                addRefs(r, c);\r
 \r
@@ -88,8 +88,9 @@ public class CommitPage extends RepositoryPage {
                                        item.add(new LinkPanel("pathName", "list", entry.path, BlobPage.class, newPathParameter(entry.path)));\r
                                }\r
                                \r
-                               item.add(new BookmarkablePageLink<Void>("diff", DiffPage.class, newPathParameter(entry.path)));\r
+                               item.add(new BookmarkablePageLink<Void>("diff", BlobDiffPage.class, newPathParameter(entry.path)));\r
                                item.add(new BookmarkablePageLink<Void>("view", BlobPage.class, newPathParameter(entry.path)));\r
+                               item.add(new BookmarkablePageLink<Void>("blame", BlobPage.class).setEnabled(false));\r
                                item.add(new BookmarkablePageLink<Void>("history", BlobPage.class).setEnabled(false));\r
 \r
                                WicketUtils.setAlternatingBackground(item, counter);\r
diff --git a/src/com/gitblit/wicket/pages/DiffPage.html b/src/com/gitblit/wicket/pages/DiffPage.html
deleted file mode 100644 (file)
index 6a5d21b..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r
-<html xmlns="http://www.w3.org/1999/xhtml"  \r
-      xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.3-strict.dtd"  \r
-      xml:lang="en"  \r
-      lang="en"> \r
-\r
-<body>\r
-<wicket:extend>\r
-\r
-       <!-- page nav links --> \r
-       <div wicket:id="pageLinks">[page links]</div>\r
-       \r
-       <!-- blob nav links --> \r
-       <div class="page_nav2">\r
-               <span wicket:id="historyLink">[history link]</span> | <span wicket:id="rawLink">[raw link]</span> | <span wicket:id="headLink">[head link]</span>\r
-       </div>  \r
-       \r
-       <!-- shortlog header -->\r
-       <div class="header" wicket:id="shortlog">[shortlog header]</div>\r
-\r
-       <!-- breadcrumbs -->\r
-       <div wicket:id="breadcrumbs">[breadcrumbs]</div>\r
-               \r
-       <!--  diff content -->\r
-       <pre wicket:id="diffText">[diff text]</pre>\r
-       \r
-</wicket:extend>\r
-</body>\r
-</html>
\ No newline at end of file
diff --git a/src/com/gitblit/wicket/pages/DiffPage.java b/src/com/gitblit/wicket/pages/DiffPage.java
deleted file mode 100644 (file)
index 1912c42..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-package com.gitblit.wicket.pages;\r
-\r
-import org.apache.wicket.PageParameters;\r
-import org.apache.wicket.markup.html.basic.Label;\r
-import org.eclipse.jgit.lib.Repository;\r
-import org.eclipse.jgit.revwalk.RevCommit;\r
-\r
-import com.gitblit.utils.JGitUtils;\r
-import com.gitblit.wicket.LinkPanel;\r
-import com.gitblit.wicket.RepositoryPage;\r
-import com.gitblit.wicket.WicketUtils;\r
-import com.gitblit.wicket.panels.PathBreadcrumbsPanel;\r
-\r
-public class DiffPage extends RepositoryPage {\r
-\r
-       public DiffPage(PageParameters params) {\r
-               super(params);\r
-\r
-               final String blobPath = WicketUtils.getPath(params);\r
-\r
-               Repository r = getRepository();\r
-               RevCommit commit = JGitUtils.getCommit(r, objectId);\r
-               String diff;\r
-               if (blobPath != null && blobPath.length() > 0) {\r
-                       // blob diff\r
-                       diff = JGitUtils.getCommitDiff(r, commit, blobPath, true);\r
-               } else {\r
-                       // commit diff\r
-                       diff = JGitUtils.getCommitDiff(r, commit, true);\r
-               }\r
-\r
-               // diff page links\r
-               add(new Label("historyLink", getString("gb.history")));\r
-               add(new Label("rawLink", getString("gb.raw")));\r
-               add(new Label("headLink", "HEAD"));\r
-\r
-               add(new LinkPanel("shortlog", "title", commit.getShortMessage(), CommitPage.class, newCommitParameter()));\r
-\r
-               add(new PathBreadcrumbsPanel("breadcrumbs", repositoryName, blobPath, objectId));\r
-\r
-               add(new Label("diffText", diff).setEscapeModelStrings(false));\r
-       }\r
-       \r
-       @Override\r
-       protected String getPageName() {\r
-               return getString("gb.diff");\r
-       }\r
-}\r
diff --git a/src/com/gitblit/wicket/pages/PatchPage.html b/src/com/gitblit/wicket/pages/PatchPage.html
new file mode 100644 (file)
index 0000000..719a46d
--- /dev/null
@@ -0,0 +1,13 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r
+<html xmlns="http://www.w3.org/1999/xhtml"  \r
+      xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.3-strict.dtd"  \r
+      xml:lang="en"  \r
+      lang="en">\r
+      \r
+<body>\r
+\r
+               <!-- patch content -->\r
+               <pre style="border:0px;" wicket:id="patchText">[patch content]</pre>\r
+       \r
+</body>\r
+</html>
\ No newline at end of file
diff --git a/src/com/gitblit/wicket/pages/PatchPage.java b/src/com/gitblit/wicket/pages/PatchPage.java
new file mode 100644 (file)
index 0000000..52790d6
--- /dev/null
@@ -0,0 +1,46 @@
+package com.gitblit.wicket.pages;\r
+\r
+import javax.servlet.http.HttpServletRequest;\r
+\r
+import org.apache.wicket.PageParameters;\r
+import org.apache.wicket.markup.html.WebPage;\r
+import org.apache.wicket.markup.html.basic.Label;\r
+import org.apache.wicket.protocol.http.servlet.ServletWebRequest;\r
+import org.eclipse.jgit.lib.Repository;\r
+import org.eclipse.jgit.revwalk.RevCommit;\r
+\r
+import com.gitblit.utils.JGitUtils;\r
+import com.gitblit.wicket.GitBlitWebApp;\r
+import com.gitblit.wicket.WicketUtils;\r
+\r
+\r
+public class PatchPage extends WebPage {\r
+\r
+       public PatchPage(PageParameters params) {\r
+               super(params);\r
+\r
+               if (!params.containsKey("r")) {\r
+                       error("Repository not specified!");\r
+                       redirectToInterceptPage(new RepositoriesPage());\r
+               }\r
+               final String repositoryName = WicketUtils.getRepositoryName(params);\r
+               final String objectId = WicketUtils.getObject(params);          \r
+               final String blobPath = WicketUtils.getPath(params);\r
+\r
+               ServletWebRequest servletWebRequest = (ServletWebRequest) getRequest();\r
+               HttpServletRequest req = servletWebRequest.getHttpServletRequest();\r
+               req.getServerName();\r
+\r
+               Repository r = GitBlitWebApp.get().getRepository(req, repositoryName);\r
+               if (r == null) {\r
+                       error("Can not load repository " + repositoryName);\r
+                       redirectToInterceptPage(new RepositoriesPage());\r
+                       return;\r
+               }\r
+\r
+               RevCommit commit = JGitUtils.getCommit(r, objectId);\r
+               String patch = JGitUtils.getCommitPatch(r, commit, blobPath);\r
+               add(new Label("patchText", patch));\r
+               r.close();\r
+       }       \r
+}\r
diff --git a/src/com/gitblit/wicket/pages/RawPage.html b/src/com/gitblit/wicket/pages/RawPage.html
new file mode 100644 (file)
index 0000000..30dd316
--- /dev/null
@@ -0,0 +1,13 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r
+<html xmlns="http://www.w3.org/1999/xhtml"  \r
+      xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.3-strict.dtd"  \r
+      xml:lang="en"  \r
+      lang="en">\r
+      \r
+<body>\r
+\r
+               <!-- raw content -->\r
+               <pre style="border:0px;" wicket:id="rawText">[raw content]</pre>\r
+       \r
+</body>\r
+</html>
\ No newline at end of file
diff --git a/src/com/gitblit/wicket/pages/RawPage.java b/src/com/gitblit/wicket/pages/RawPage.java
new file mode 100644 (file)
index 0000000..18b91bc
--- /dev/null
@@ -0,0 +1,91 @@
+package com.gitblit.wicket.pages;\r
+\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
+import javax.servlet.http.HttpServletRequest;\r
+\r
+import org.apache.wicket.Component;\r
+import org.apache.wicket.PageParameters;\r
+import org.apache.wicket.markup.html.WebPage;\r
+import org.apache.wicket.markup.html.basic.Label;\r
+import org.apache.wicket.protocol.http.servlet.ServletWebRequest;\r
+import org.eclipse.jgit.lib.Repository;\r
+import org.eclipse.jgit.revwalk.RevCommit;\r
+\r
+import com.gitblit.StoredSettings;\r
+import com.gitblit.utils.JGitUtils;\r
+import com.gitblit.wicket.GitBlitWebApp;\r
+import com.gitblit.wicket.WicketUtils;\r
+\r
+\r
+public class RawPage extends WebPage {\r
+\r
+       public RawPage(PageParameters params) {\r
+               super(params);\r
+\r
+               if (!params.containsKey("r")) {\r
+                       error("Repository not specified!");\r
+                       redirectToInterceptPage(new RepositoriesPage());\r
+               }\r
+               final String repositoryName = WicketUtils.getRepositoryName(params);\r
+               final String objectId = WicketUtils.getObject(params);          \r
+               final String blobPath = WicketUtils.getPath(params);\r
+\r
+               ServletWebRequest servletWebRequest = (ServletWebRequest) getRequest();\r
+               HttpServletRequest req = servletWebRequest.getHttpServletRequest();\r
+               req.getServerName();\r
+\r
+               Repository r = GitBlitWebApp.get().getRepository(req, repositoryName);\r
+               if (r == null) {\r
+                       error("Can not load repository " + repositoryName);\r
+                       redirectToInterceptPage(new RepositoriesPage());\r
+                       return;\r
+               }\r
+\r
+               RevCommit commit = JGitUtils.getCommit(r, objectId);\r
+\r
+               String extension = null;\r
+               if (blobPath.lastIndexOf('.') > -1) {\r
+                       extension = blobPath.substring(blobPath.lastIndexOf('.') + 1);\r
+               }\r
+\r
+               // Map the extensions to types\r
+               Map<String, Integer> map = new HashMap<String, Integer>();\r
+               for (String ext : StoredSettings.getStrings("imageExtensions")) {\r
+                       map.put(ext.toLowerCase(), 2);\r
+               }\r
+               for (String ext : StoredSettings.getStrings("binaryExtensions")) {\r
+                       map.put(ext.toLowerCase(), 3);\r
+               }\r
+\r
+               if (extension != null) {\r
+                       int type = 0;\r
+                       if (map.containsKey(extension)) {\r
+                               type = map.get(extension);\r
+                       }\r
+                       Component c = null;\r
+                       switch (type) {\r
+                       case 2:\r
+                               // TODO image blobs\r
+                               c = new Label("rawText", "Image File");\r
+                               break;\r
+                       case 3:\r
+                               // TODO binary blobs\r
+                               c = new Label("rawText", "Binary File");\r
+                               break;\r
+                       default:\r
+                               // plain text\r
+                               c = new Label("rawText", JGitUtils.getRawContentAsString(r, commit, blobPath));\r
+                               WicketUtils.setCssClass(c, "plainprint");\r
+                       }\r
+                       add(c);\r
+               } else {\r
+                       // plain text\r
+                       Label blobLabel = new Label("rawText", JGitUtils.getRawContentAsString(r, commit, blobPath));\r
+                       WicketUtils.setCssClass(blobLabel, "plainprint");\r
+                       add(blobLabel);\r
+               }\r
+               r.close();\r
+       }       \r
+}\r
index 34c240cb85d71ecda91f28f1be22e0401aba3250..4eb3b4b4eae1b9b740beff13972cffd67203515f 100644 (file)
@@ -11,7 +11,7 @@
        <div wicket:id="pageLinks">[page links]</div>\r
 \r
        <!-- summary header -->\r
-       <div style="padding-top: 5px;" class="header" wicket:id="commit">[shortlog header]</div>\r
+       <div style="margin-top: 5px;" class="header" wicket:id="commit">[shortlog header]</div>\r
        \r
        <!-- commit info -->\r
        <table class="plain">\r
index 95be46ca3e13dceb4b68ccb36316a5d5749e49f5..622c2b15d53fa625d9ca25f194e0d063f4eede92 100644 (file)
@@ -1,5 +1,7 @@
 package com.gitblit.wicket.pages;\r
 \r
+import java.util.List;\r
+\r
 import org.apache.wicket.PageParameters;\r
 import org.apache.wicket.markup.html.basic.Label;\r
 import org.eclipse.jgit.lib.Repository;\r
@@ -9,6 +11,7 @@ import com.gitblit.utils.JGitUtils;
 import com.gitblit.wicket.LinkPanel;\r
 import com.gitblit.wicket.RepositoryPage;\r
 import com.gitblit.wicket.WicketUtils;\r
+import com.gitblit.wicket.models.RefModel;\r
 \r
 \r
 public class TagPage extends RepositoryPage {\r
@@ -16,10 +19,18 @@ public class TagPage extends RepositoryPage {
        public TagPage(PageParameters params) {\r
                super(params);\r
 \r
-               Repository r = getRepository();\r
+               Repository r = getRepository();         \r
+               List<RefModel> tags = JGitUtils.getTags(r, -1);\r
                RevCommit c = JGitUtils.getCommit(r, objectId);\r
-\r
-               add(new LinkPanel("commit", "title", c.getName(), CommitPage.class, newCommitParameter()));\r
+               \r
+               String name = c.getName();\r
+               for (RefModel tag:tags) {\r
+                       if (tag.getName().equals(objectId)) {\r
+                               name = tag.getDisplayName();\r
+                       }\r
+               }\r
+\r
+               add(new LinkPanel("commit", "title", name, CommitPage.class, newCommitParameter()));\r
 \r
                add(new LinkPanel("tagId", "list", c.getName(), CommitPage.class, newCommitParameter(c.getName())));\r
                add(new Label("tagAuthor", JGitUtils.getDisplayName(c.getAuthorIdent())));\r
index 2cfb772321e62c5da3a0920ad4f79eee775dfd4f..2a042a6da51f622f84ed1d74a9fe2e1688e50721 100644 (file)
@@ -9,11 +9,11 @@ import org.apache.wicket.markup.repeater.data.DataView;
 import org.apache.wicket.markup.repeater.data.ListDataProvider;\r
 \r
 import com.gitblit.utils.JGitUtils;\r
-import com.gitblit.utils.TicGitTicket;\r
 import com.gitblit.wicket.GitBlitWebSession;\r
 import com.gitblit.wicket.LinkPanel;\r
 import com.gitblit.wicket.RepositoryPage;\r
 import com.gitblit.wicket.WicketUtils;\r
+import com.gitblit.wicket.models.TicGitTicket;\r
 \r
 public class TicGitPage extends RepositoryPage {\r
 \r
index a27c8ddfb5004736c9fc5f4834b467e0b58e5ddf..fdd6ea0a92a18d4a07b9174bd8335c203b7b4e36 100644 (file)
@@ -8,11 +8,11 @@ import org.apache.wicket.markup.repeater.data.ListDataProvider;
 import org.eclipse.jgit.lib.Repository;\r
 \r
 import com.gitblit.utils.JGitUtils;\r
-import com.gitblit.utils.TicGitTicket;\r
-import com.gitblit.utils.TicGitTicket.Comment;\r
 import com.gitblit.wicket.GitBlitWebSession;\r
 import com.gitblit.wicket.RepositoryPage;\r
 import com.gitblit.wicket.WicketUtils;\r
+import com.gitblit.wicket.models.TicGitTicket;\r
+import com.gitblit.wicket.models.TicGitTicket.Comment;\r
 \r
 public class TicGitTicketPage extends RepositoryPage {\r
 \r
index 3eda96b70d8c4bed8741d7649a26e455118508d9..85fbdfc8819dce5d387e2bdca55f2fe10ec525f1 100644 (file)
@@ -12,7 +12,7 @@
        \r
        <!-- blob nav links --> \r
        <div class="page_nav2">\r
-               <span wicket:id="historyLink">[history link]</span> | <span wicket:id="headLink">[head link]</span>\r
+               <span wicket:id="historyLink">[history link]</span> | <a wicket:id="headLink"><wicket:message key="gb.head"></wicket:message></a>\r
        </div>  \r
        \r
        <!-- shortlog header -->\r
index 90e0a65d0c9506f2cd0ac061056d6ee3365deebc..2bea987d1dfb627bc72c560e2b2d53ab5d9b2dfa 100644 (file)
@@ -9,6 +9,7 @@ import org.apache.wicket.markup.html.panel.Fragment;
 import org.apache.wicket.markup.repeater.Item;\r
 import org.apache.wicket.markup.repeater.data.DataView;\r
 import org.apache.wicket.markup.repeater.data.ListDataProvider;\r
+import org.eclipse.jgit.lib.Constants;\r
 import org.eclipse.jgit.lib.Repository;\r
 import org.eclipse.jgit.revwalk.RevCommit;\r
 \r
@@ -34,7 +35,8 @@ public class TreePage extends RepositoryPage {
 \r
                // tree page links\r
                add(new Label("historyLink", getString("gb.history")));\r
-               add(new Label("headLink", "HEAD"));\r
+               add(new BookmarkablePageLink<Void>("headLink", TreePage.class, WicketUtils.newPathParameter(repositoryName, Constants.HEAD, basePath)));\r
+\r
 \r
                add(new LinkPanel("shortlog", "title", commit.getShortMessage(), CommitPage.class, newCommitParameter()));\r
 \r
@@ -79,7 +81,7 @@ public class TreePage extends RepositoryPage {
                                                // links\r
                                                Fragment links = new Fragment("pathLinks", "blobLinks", this);\r
                                                links.add(new BookmarkablePageLink<Void>("view", BlobPage.class, WicketUtils.newPathParameter(repositoryName, entry.commitId, entry.path)));\r
-                                               links.add(new BookmarkablePageLink<Void>("raw", BlobPage.class).setEnabled(false));\r
+                                               links.add(new BookmarkablePageLink<Void>("raw", RawPage.class, WicketUtils.newPathParameter(repositoryName, entry.commitId, entry.path)));\r
                                                links.add(new BookmarkablePageLink<Void>("history", BlobPage.class).setEnabled(false));\r
                                                item.add(links);\r
                                        }\r
index ccc46fd3d756723fb692fdabf2c3522d720c2063..8ef1e3e7e1d0061610f6394a6427c8227a974b7c 100644 (file)
@@ -19,7 +19,7 @@ import com.gitblit.utils.JGitUtils;
 import com.gitblit.wicket.LinkPanel;\r
 import com.gitblit.wicket.WicketUtils;\r
 import com.gitblit.wicket.pages.CommitPage;\r
-import com.gitblit.wicket.pages.DiffPage;\r
+import com.gitblit.wicket.pages.CommitDiffPage;\r
 import com.gitblit.wicket.pages.LogPage;\r
 import com.gitblit.wicket.pages.SummaryPage;\r
 import com.gitblit.wicket.pages.TreePage;\r
@@ -82,7 +82,7 @@ public class LogPanel extends BasePanel {
                                item.add(new RefsPanel("commitRefs", repositoryName, entry, allRefs));\r
 \r
                                item.add(new BookmarkablePageLink<Void>("view", CommitPage.class, WicketUtils.newObjectParameter(repositoryName, entry.getName())));\r
-                               item.add(new BookmarkablePageLink<Void>("diff", DiffPage.class, WicketUtils.newObjectParameter(repositoryName, entry.getName())));\r
+                               item.add(new BookmarkablePageLink<Void>("diff", CommitDiffPage.class, WicketUtils.newObjectParameter(repositoryName, entry.getName())));\r
                                item.add(new BookmarkablePageLink<Void>("tree", TreePage.class, WicketUtils.newObjectParameter(repositoryName, entry.getName())));\r
 \r
                                WicketUtils.setAlternatingBackground(item, counter);\r
index c089560742d655938dd18b65f024c3345d4527a0..da0c317ecbda526f21152e857e06842d612a32eb 100644 (file)
@@ -229,9 +229,9 @@ div.diff.header {
     background-color: #EDECE6;\r
     border-color: #D9D8D1;\r
     border-style: solid;\r
-    border-width: 1px 0;\r
+    border-width: 1px;\r
     font-weight: bold;\r
-    margin-top: 4px;\r
+    margin-top: 10px;\r
     padding: 4px 0 2px;\r
 }\r
 \r
@@ -241,17 +241,17 @@ div.diff.extended_header {
     font-family: inherit;\r
 }\r
 \r
-div.diff.add {\r
+span.diff.add {\r
        color: #008800;\r
        font-family: inherit;\r
 }\r
 \r
-div.diff.remove {\r
+span.diff.remove {\r
        color: #cc0000;\r
        font-family: inherit;\r
 }\r
 \r
-div.diff.unchanged {\r
+span.diff.unchanged {\r
        color: inherit;\r
        font-family: inherit;\r
 }\r
@@ -425,11 +425,12 @@ span .tagRef a span, span .headRef a span, span .remoteRef a span, span .otherRe
 \r
 span .tagRef a, span .headRef a, span .remoteRef a, span .otherRef a {\r
        text-decoration: none;\r
-       color: inherit;\r
+       color: black;\r
 }\r
 \r
 span .tagRef a:hover, span .headRef a:hover, span .remoteRef a:hover, span .otherRef a:hover {\r
-       color: inherit;\r
+       color: black;\r
+       text-decoration: underline;\r
 }\r
 \r
 span .otherRef {\r