This is for history where we specify two revs to diff, not just a commit against its parent.tags/v0.5.0
@@ -288,20 +288,35 @@ public class JGitUtils { | |||
} | |||
public static String getCommitDiff(Repository r, RevCommit commit, boolean outputHtml) { | |||
return getCommitDiff(r, commit, null, outputHtml); | |||
return getCommitDiff(r, null, commit, null, outputHtml); | |||
} | |||
public static String getCommitDiff(Repository r, RevCommit commit, String path, boolean outputHtml) { | |||
return getCommitDiff(r, null, commit, path, outputHtml); | |||
} | |||
public static String getCommitDiff(Repository r, RevCommit baseCommit, RevCommit commit, boolean outputHtml) { | |||
return getCommitDiff(r, baseCommit, commit, null, outputHtml); | |||
} | |||
public static String getCommitDiff(Repository r, RevCommit baseCommit, RevCommit commit, String path, boolean outputHtml) { | |||
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()); | |||
rw.dispose(); | |||
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); | |||
@@ -316,7 +331,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)) { |
@@ -13,6 +13,7 @@ import org.eclipse.jgit.lib.Constants; | |||
import com.gitblit.GitBlit; | |||
import com.gitblit.Keys; | |||
import com.gitblit.utils.StringUtils; | |||
import com.gitblit.utils.TimeUtils; | |||
public class WicketUtils { | |||
@@ -61,14 +62,14 @@ public class WicketUtils { | |||
} | |||
public static PageParameters newObjectParameter(String repositoryName, String objectId) { | |||
if (objectId == null || objectId.trim().length() == 0) { | |||
if (StringUtils.isEmpty(objectId)) { | |||
return newRepositoryParameter(repositoryName); | |||
} | |||
return new PageParameters("r=" + repositoryName + ",h=" + objectId); | |||
} | |||
public static PageParameters newPathParameter(String repositoryName, String objectId, String path) { | |||
if (path == null || path.trim().length() == 0) { | |||
if (StringUtils.isEmpty(path)) { | |||
return newObjectParameter(repositoryName, objectId); | |||
} | |||
return new PageParameters("r=" + repositoryName + ",h=" + objectId + ",f=" + path); | |||
@@ -88,6 +89,11 @@ public class WicketUtils { | |||
return new PageParameters("r=" + repositoryName + ",h=" + objectId + ",f=" + path + ",page=" + pageNumber); | |||
} | |||
public static PageParameters newBlobDiffParameter(String repositoryName, String baseCommitId, String commitId, String path) { | |||
return new PageParameters("r=" + repositoryName + ",h=" + commitId + ",f=" + path + ",hb=" + baseCommitId); | |||
} | |||
public static String getRepositoryName(PageParameters params) { | |||
return params.getString("r", ""); | |||
} | |||
@@ -99,6 +105,10 @@ public class WicketUtils { | |||
public static String getPath(PageParameters params) { | |||
return params.getString("f", null); | |||
} | |||
public static String getBaseObjectId(PageParameters params) { | |||
return params.getString("hb", null); | |||
} | |||
public static int getPage(PageParameters params) { | |||
return params.getInt("page", 1); // index from 1 |
@@ -7,6 +7,7 @@ import org.eclipse.jgit.lib.Repository; | |||
import org.eclipse.jgit.revwalk.RevCommit; | |||
import com.gitblit.utils.JGitUtils; | |||
import com.gitblit.utils.StringUtils; | |||
import com.gitblit.wicket.LinkPanel; | |||
import com.gitblit.wicket.RepositoryPage; | |||
import com.gitblit.wicket.WicketUtils; | |||
@@ -18,10 +19,21 @@ public class BlobDiffPage extends RepositoryPage { | |||
super(params); | |||
final String blobPath = WicketUtils.getPath(params); | |||
final String baseObjectId = WicketUtils.getBaseObjectId(params); | |||
Repository r = getRepository(); | |||
RevCommit commit = JGitUtils.getCommit(r, objectId); | |||
String diff = JGitUtils.getCommitDiff(r, commit, blobPath, true); | |||
String diff; | |||
if (StringUtils.isEmpty(baseObjectId)) { | |||
// use first parent | |||
diff = JGitUtils.getCommitDiff(r, commit, blobPath, true); | |||
} 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.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))); |
@@ -32,7 +32,7 @@ public class HistoryPanel extends BasePanel { | |||
private boolean hasMore = false; | |||
public HistoryPanel(String wicketId, final String repositoryName, String objectId, final String path, Repository r, int limit, int pageOffset) { | |||
public HistoryPanel(String wicketId, final String repositoryName, final String objectId, final String path, Repository r, int limit, int pageOffset) { | |||
super(wicketId); | |||
boolean pageResults = limit <= 0; | |||
int itemsPerPage = GitBlit.self().settings().getInteger(Keys.web.logPageCommitCount, 50); | |||
@@ -96,7 +96,7 @@ public class HistoryPanel extends BasePanel { | |||
// TODO links for folder | |||
item.add(new BookmarkablePageLink<Void>("view", CommitPage.class, WicketUtils.newObjectParameter(repositoryName, entry.getName()))); | |||
item.add(new BookmarkablePageLink<Void>("commitdiff", CommitDiffPage.class, WicketUtils.newObjectParameter(repositoryName, entry.getName()))); | |||
item.add(new BookmarkablePageLink<Void>("difftocurrent", BlobDiffPage.class, WicketUtils.newPathParameter(repositoryName, entry.getName(), path)).setEnabled(counter > 0)); | |||
item.add(new BookmarkablePageLink<Void>("difftocurrent", BlobDiffPage.class, WicketUtils.newBlobDiffParameter(repositoryName, entry.getName(), objectId, path)).setEnabled(counter > 0)); | |||
WicketUtils.setAlternatingBackground(item, counter); | |||
counter++; |