@@ -362,16 +362,25 @@ public class JGitUtils { | |||
} | |||
public static String getCommitPatch(Repository r, RevCommit commit, String path) { | |||
return getCommitPatch(r, null, commit, path); | |||
} | |||
public static String getCommitPatch(Repository r, RevCommit baseCommit, RevCommit commit, String path) { | |||
try { | |||
final RevWalk rw = new RevWalk(r); | |||
RevCommit parent = rw.parseCommit(commit.getParent(0).getId()); | |||
RevTree parentTree = parent.getTree(); | |||
RevTree baseTree; | |||
if (baseCommit == null) { | |||
final RevWalk rw = new RevWalk(r); | |||
RevCommit parent = rw.parseCommit(commit.getParent(0).getId()); | |||
baseTree = parent.getTree(); | |||
} else { | |||
baseTree = baseCommit.getTree(); | |||
} | |||
RevTree commitTree = commit.getTree(); | |||
final TreeWalk walk = new TreeWalk(r); | |||
walk.reset(); | |||
walk.setRecursive(true); | |||
walk.addTree(parentTree); | |||
walk.addTree(baseTree); | |||
walk.addTree(commitTree); | |||
walk.setFilter(TreeFilter.ANY_DIFF); | |||
@@ -381,7 +390,7 @@ public class JGitUtils { | |||
df.setRepository(r); | |||
df.setDiffComparator(cmp); | |||
df.setDetectRenames(true); | |||
List<DiffEntry> diffs = df.scan(parentTree, commitTree); | |||
List<DiffEntry> diffs = df.scan(baseTree, commitTree); | |||
if (path != null && path.length() > 0) { | |||
for (DiffEntry diff : diffs) { | |||
if (diff.getNewPath().equalsIgnoreCase(path)) { |
@@ -28,13 +28,14 @@ public class BlobDiffPage extends RepositoryPage { | |||
if (StringUtils.isEmpty(baseObjectId)) { | |||
// use first parent | |||
diff = JGitUtils.getCommitDiff(r, commit, blobPath, true); | |||
add(new BookmarkablePageLink<Void>("patchLink", PatchPage.class, WicketUtils.newPathParameter(repositoryName, objectId, blobPath))); | |||
} else { | |||
// base commit specified | |||
RevCommit baseCommit = JGitUtils.getCommit(r, baseObjectId); | |||
diff = JGitUtils.getCommitDiff(r, baseCommit, commit, blobPath, true); | |||
add(new BookmarkablePageLink<Void>("patchLink", PatchPage.class, WicketUtils.newBlobDiffParameter(repositoryName, baseObjectId, objectId, blobPath))); | |||
} | |||
add(new BookmarkablePageLink<Void>("patchLink", PatchPage.class, WicketUtils.newPathParameter(repositoryName, objectId, blobPath))); | |||
add(new BookmarkablePageLink<Void>("commitLink", CommitPage.class, WicketUtils.newObjectParameter(repositoryName, objectId))); | |||
add(new BookmarkablePageLink<Void>("commitDiffLink", CommitDiffPage.class, WicketUtils.newObjectParameter(repositoryName, objectId))); | |||
@@ -11,6 +11,7 @@ import org.eclipse.jgit.revwalk.RevCommit; | |||
import com.gitblit.GitBlit; | |||
import com.gitblit.utils.JGitUtils; | |||
import com.gitblit.utils.StringUtils; | |||
import com.gitblit.wicket.WicketUtils; | |||
public class PatchPage extends WebPage { | |||
@@ -23,6 +24,7 @@ public class PatchPage extends WebPage { | |||
redirectToInterceptPage(new RepositoriesPage()); | |||
} | |||
final String repositoryName = WicketUtils.getRepositoryName(params); | |||
final String baseObjectId = WicketUtils.getBaseObjectId(params); | |||
final String objectId = WicketUtils.getObject(params); | |||
final String blobPath = WicketUtils.getPath(params); | |||
@@ -38,7 +40,13 @@ public class PatchPage extends WebPage { | |||
} | |||
RevCommit commit = JGitUtils.getCommit(r, objectId); | |||
String patch = JGitUtils.getCommitPatch(r, commit, blobPath); | |||
String patch; | |||
if (StringUtils.isEmpty(baseObjectId)) { | |||
patch = JGitUtils.getCommitPatch(r, commit, blobPath); | |||
} else { | |||
RevCommit baseCommit = JGitUtils.getCommit(r, baseObjectId); | |||
patch = JGitUtils.getCommitPatch(r, baseCommit, commit, blobPath); | |||
} | |||
add(new Label("patchText", patch)); | |||
r.close(); | |||
} |