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