]> source.dussan.org Git - gitblit.git/commitdiff
Implemented diff-to-current.
authorJames Moger <james.moger@gitblit.com>
Sun, 17 Apr 2011 20:00:02 +0000 (16:00 -0400)
committerJames Moger <james.moger@gitblit.com>
Sun, 17 Apr 2011 20:00:02 +0000 (16:00 -0400)
This is for history where we specify two revs to diff, not just a
commit against its parent.

src/com/gitblit/utils/JGitUtils.java
src/com/gitblit/wicket/WicketUtils.java
src/com/gitblit/wicket/pages/BlobDiffPage.java
src/com/gitblit/wicket/panels/HistoryPanel.java

index 075ad81b7ca4956dcc2b8f4a85f7f915bd9393b6..9b2e37cfb63e1728b2d8ec7a1e891e7ef2615cc6 100644 (file)
@@ -288,20 +288,35 @@ public class JGitUtils {
        }\r
 \r
        public static String getCommitDiff(Repository r, RevCommit commit, boolean outputHtml) {\r
-               return getCommitDiff(r, commit, null, outputHtml);\r
+               return getCommitDiff(r, null, commit, null, outputHtml);\r
        }\r
 \r
        public static String getCommitDiff(Repository r, RevCommit commit, String path, boolean outputHtml) {\r
+               return getCommitDiff(r, null, commit, path, outputHtml);\r
+       }\r
+\r
+       public static String getCommitDiff(Repository r, RevCommit baseCommit, RevCommit commit, boolean outputHtml) {\r
+               return getCommitDiff(r, baseCommit, commit, null, outputHtml);\r
+       }\r
+\r
+       public static String getCommitDiff(Repository r, RevCommit baseCommit, RevCommit commit, String path, boolean outputHtml) {\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 baseTree;\r
+                       if (baseCommit == null) {\r
+                               final RevWalk rw = new RevWalk(r);\r
+                               RevCommit parent = rw.parseCommit(commit.getParent(0).getId());\r
+                               rw.dispose();\r
+                               baseTree = parent.getTree();    \r
+                       } else {\r
+                               baseTree = baseCommit.getTree();\r
+                       }\r
+\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(baseTree);\r
                        walk.addTree(commitTree);\r
                        walk.setFilter(TreeFilter.ANY_DIFF);\r
 \r
@@ -316,7 +331,7 @@ public class JGitUtils {
                        df.setRepository(r);\r
                        df.setDiffComparator(cmp);\r
                        df.setDetectRenames(true);\r
-                       List<DiffEntry> diffs = df.scan(parentTree, commitTree);\r
+                       List<DiffEntry> diffs = df.scan(baseTree, commitTree);\r
                        if (path != null && path.length() > 0) {\r
                                for (DiffEntry diff : diffs) {\r
                                        if (diff.getNewPath().equalsIgnoreCase(path)) {\r
index 3bc55f1b33ace4f8edd497d13f5ce2b78d72e492..0a1c3a03f9afd80b44913c51f282e87486dca6ca 100644 (file)
@@ -13,6 +13,7 @@ import org.eclipse.jgit.lib.Constants;
 \r
 import com.gitblit.GitBlit;\r
 import com.gitblit.Keys;\r
+import com.gitblit.utils.StringUtils;\r
 import com.gitblit.utils.TimeUtils;\r
 \r
 public class WicketUtils {\r
@@ -61,14 +62,14 @@ public class WicketUtils {
        }\r
 \r
        public static PageParameters newObjectParameter(String repositoryName, String objectId) {\r
-               if (objectId == null || objectId.trim().length() == 0) {\r
+               if (StringUtils.isEmpty(objectId)) {\r
                        return newRepositoryParameter(repositoryName);\r
                }\r
                return new PageParameters("r=" + repositoryName + ",h=" + objectId);\r
        }\r
 \r
        public static PageParameters newPathParameter(String repositoryName, String objectId, String path) {\r
-               if (path == null || path.trim().length() == 0) {\r
+               if (StringUtils.isEmpty(path)) {\r
                        return newObjectParameter(repositoryName, objectId);\r
                }\r
                return new PageParameters("r=" + repositoryName + ",h=" + objectId + ",f=" + path);\r
@@ -88,6 +89,11 @@ public class WicketUtils {
                return new PageParameters("r=" + repositoryName + ",h=" + objectId + ",f=" + path + ",page=" + pageNumber);\r
        }\r
 \r
+       public static PageParameters newBlobDiffParameter(String repositoryName, String baseCommitId, String commitId, String path) {\r
+               return new PageParameters("r=" + repositoryName + ",h=" + commitId + ",f=" + path + ",hb=" + baseCommitId);\r
+       }\r
+\r
+       \r
        public static String getRepositoryName(PageParameters params) {\r
                return params.getString("r", "");\r
        }\r
@@ -99,6 +105,10 @@ public class WicketUtils {
        public static String getPath(PageParameters params) {\r
                return params.getString("f", null);\r
        }\r
+       \r
+       public static String getBaseObjectId(PageParameters params) {\r
+               return params.getString("hb", null);\r
+       }\r
 \r
        public static int getPage(PageParameters params) {\r
                return params.getInt("page", 1); // index from 1\r
index de49b3cf88f154ea17b1ab76eb99dfd1df14fc4c..bff46b38526cfc250494628369aa4b9eeb43557d 100644 (file)
@@ -7,6 +7,7 @@ import org.eclipse.jgit.lib.Repository;
 import org.eclipse.jgit.revwalk.RevCommit;\r
 \r
 import com.gitblit.utils.JGitUtils;\r
+import com.gitblit.utils.StringUtils;\r
 import com.gitblit.wicket.LinkPanel;\r
 import com.gitblit.wicket.RepositoryPage;\r
 import com.gitblit.wicket.WicketUtils;\r
@@ -18,10 +19,21 @@ public class BlobDiffPage extends RepositoryPage {
                super(params);\r
 \r
                final String blobPath = WicketUtils.getPath(params);\r
+               final String baseObjectId = WicketUtils.getBaseObjectId(params);\r
 \r
                Repository r = getRepository();\r
                RevCommit commit = JGitUtils.getCommit(r, objectId);\r
-               String diff = JGitUtils.getCommitDiff(r, commit, blobPath, true);\r
+               \r
+               String diff;\r
+               if (StringUtils.isEmpty(baseObjectId)) {\r
+                       // use first parent\r
+                       diff = JGitUtils.getCommitDiff(r, commit, blobPath, true);\r
+               } else {\r
+                       // base commit specified\r
+                       RevCommit baseCommit = JGitUtils.getCommit(r, baseObjectId);\r
+                       diff = JGitUtils.getCommitDiff(r, baseCommit, commit, blobPath, true);\r
+               }\r
+               \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
index e78788384be9288092372820f24a8b9c0b55ab59..855128b0d264764c087f60707314f2a369e65c16 100644 (file)
@@ -32,7 +32,7 @@ public class HistoryPanel extends BasePanel {
        \r
        private boolean hasMore = false;\r
 \r
-       public HistoryPanel(String wicketId, final String repositoryName, String objectId, final String path, Repository r, int limit, int pageOffset) {\r
+       public HistoryPanel(String wicketId, final String repositoryName, final String objectId, final String path, Repository r, int limit, int pageOffset) {\r
                super(wicketId);\r
                boolean pageResults = limit <= 0;\r
                int itemsPerPage = GitBlit.self().settings().getInteger(Keys.web.logPageCommitCount, 50);\r
@@ -96,7 +96,7 @@ public class HistoryPanel extends BasePanel {
                                // TODO links for folder\r
                                item.add(new BookmarkablePageLink<Void>("view", CommitPage.class, WicketUtils.newObjectParameter(repositoryName, entry.getName())));\r
                                item.add(new BookmarkablePageLink<Void>("commitdiff", CommitDiffPage.class, WicketUtils.newObjectParameter(repositoryName, entry.getName())));\r
-                               item.add(new BookmarkablePageLink<Void>("difftocurrent", BlobDiffPage.class, WicketUtils.newPathParameter(repositoryName, entry.getName(), path)).setEnabled(counter > 0));\r
+                               item.add(new BookmarkablePageLink<Void>("difftocurrent", BlobDiffPage.class, WicketUtils.newBlobDiffParameter(repositoryName, entry.getName(), objectId, path)).setEnabled(counter > 0));\r
 \r
                                WicketUtils.setAlternatingBackground(item, counter);\r
                                counter++;\r