}\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
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
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
\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
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
}\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