]> source.dussan.org Git - gitblit.git/commitdiff
patch-to-current feature.
authorJames Moger <james.moger@gitblit.com>
Sun, 17 Apr 2011 20:10:38 +0000 (16:10 -0400)
committerJames Moger <james.moger@gitblit.com>
Sun, 17 Apr 2011 20:10:38 +0000 (16:10 -0400)
src/com/gitblit/utils/JGitUtils.java
src/com/gitblit/wicket/pages/BlobDiffPage.java
src/com/gitblit/wicket/pages/PatchPage.java

index 9b2e37cfb63e1728b2d8ec7a1e891e7ef2615cc6..5590ffed3012147fc13070cedb6d6e7c57723dfb 100644 (file)
@@ -362,16 +362,25 @@ public class JGitUtils {
        }\r
 \r
        public static String getCommitPatch(Repository r, RevCommit commit, String path) {\r
+               return getCommitPatch(r, null, commit, path);\r
+       }\r
+       \r
+       public static String getCommitPatch(Repository r, RevCommit baseCommit, 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 baseTree;\r
+                       if (baseCommit == null) {\r
+                               final RevWalk rw = new RevWalk(r);\r
+                               RevCommit parent = rw.parseCommit(commit.getParent(0).getId());\r
+                               baseTree = parent.getTree();\r
+                       } else {\r
+                               baseTree = baseCommit.getTree();\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
@@ -381,7 +390,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 bff46b38526cfc250494628369aa4b9eeb43557d..bb471712a763a388dafc3b10d6e1b80e6011e705 100644 (file)
@@ -28,13 +28,14 @@ public class BlobDiffPage extends RepositoryPage {
                if (StringUtils.isEmpty(baseObjectId)) {\r
                        // use first parent\r
                        diff = JGitUtils.getCommitDiff(r, commit, blobPath, true);\r
+                       add(new BookmarkablePageLink<Void>("patchLink", PatchPage.class, WicketUtils.newPathParameter(repositoryName, objectId, blobPath)));\r
                } else {\r
                        // base commit specified\r
                        RevCommit baseCommit = JGitUtils.getCommit(r, baseObjectId);\r
                        diff = JGitUtils.getCommitDiff(r, baseCommit, commit, blobPath, true);\r
+                       add(new BookmarkablePageLink<Void>("patchLink", PatchPage.class, WicketUtils.newBlobDiffParameter(repositoryName, baseObjectId, objectId, blobPath)));\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
 \r
index 12e89a6c89dfca620a80449bf291deccdb832d0b..45c1bf55d46bb2d71c248cbcef2e59ad9ef4337e 100644 (file)
@@ -11,6 +11,7 @@ import org.eclipse.jgit.revwalk.RevCommit;
 \r
 import com.gitblit.GitBlit;\r
 import com.gitblit.utils.JGitUtils;\r
+import com.gitblit.utils.StringUtils;\r
 import com.gitblit.wicket.WicketUtils;\r
 \r
 public class PatchPage extends WebPage {\r
@@ -23,6 +24,7 @@ public class PatchPage extends WebPage {
                        redirectToInterceptPage(new RepositoriesPage());\r
                }\r
                final String repositoryName = WicketUtils.getRepositoryName(params);\r
+               final String baseObjectId = WicketUtils.getBaseObjectId(params);\r
                final String objectId = WicketUtils.getObject(params);\r
                final String blobPath = WicketUtils.getPath(params);\r
 \r
@@ -38,7 +40,13 @@ public class PatchPage extends WebPage {
                }\r
 \r
                RevCommit commit = JGitUtils.getCommit(r, objectId);\r
-               String patch = JGitUtils.getCommitPatch(r, commit, blobPath);\r
+               String patch;\r
+               if (StringUtils.isEmpty(baseObjectId)) {\r
+                       patch = JGitUtils.getCommitPatch(r, commit, blobPath);\r
+               } else {\r
+                       RevCommit baseCommit = JGitUtils.getCommit(r, baseObjectId);\r
+                       patch = JGitUtils.getCommitPatch(r, baseCommit, commit, blobPath);                      \r
+               }\r
                add(new Label("patchText", patch));\r
                r.close();\r
        }\r