commit | author | age
|
608ece
|
1 |
package com.gitblit.wicket.pages;
|
JM |
2 |
|
|
3 |
import java.util.ArrayList;
|
|
4 |
import java.util.List;
|
|
5 |
|
|
6 |
import org.apache.wicket.PageParameters;
|
|
7 |
import org.apache.wicket.markup.html.basic.Label;
|
|
8 |
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
|
|
9 |
import org.apache.wicket.markup.repeater.Item;
|
|
10 |
import org.apache.wicket.markup.repeater.data.DataView;
|
|
11 |
import org.apache.wicket.markup.repeater.data.ListDataProvider;
|
|
12 |
import org.eclipse.jgit.lib.Repository;
|
|
13 |
import org.eclipse.jgit.revwalk.RevCommit;
|
|
14 |
|
3df349
|
15 |
import com.gitblit.GitBlit;
|
JM |
16 |
import com.gitblit.Keys;
|
608ece
|
17 |
import com.gitblit.utils.JGitUtils;
|
3df349
|
18 |
import com.gitblit.utils.JGitUtils.DiffOutputType;
|
608ece
|
19 |
import com.gitblit.wicket.LinkPanel;
|
JM |
20 |
import com.gitblit.wicket.RepositoryPage;
|
|
21 |
import com.gitblit.wicket.WicketUtils;
|
9bc17d
|
22 |
import com.gitblit.wicket.models.PathModel.PathChangeModel;
|
c1c3c6
|
23 |
import com.gitblit.wicket.panels.CommitHeaderPanel;
|
a645ba
|
24 |
import com.gitblit.wicket.panels.CommitLegendPanel;
|
608ece
|
25 |
|
JM |
26 |
public class CommitDiffPage extends RepositoryPage {
|
|
27 |
|
|
28 |
public CommitDiffPage(PageParameters params) {
|
|
29 |
super(params);
|
|
30 |
|
|
31 |
Repository r = getRepository();
|
bc9d4a
|
32 |
RevCommit commit = getCommit();
|
3df349
|
33 |
DiffOutputType diffType = DiffOutputType.forName(GitBlit.self().settings().getString(Keys.web.diffStyle, DiffOutputType.GITBLIT.name()));
|
JM |
34 |
String diff = JGitUtils.getCommitDiff(r, commit, diffType);
|
155bf7
|
35 |
|
608ece
|
36 |
List<String> parents = new ArrayList<String>();
|
JM |
37 |
if (commit.getParentCount() > 0) {
|
|
38 |
for (RevCommit parent : commit.getParents()) {
|
|
39 |
parents.add(parent.name());
|
|
40 |
}
|
|
41 |
}
|
155bf7
|
42 |
|
608ece
|
43 |
// commit page links
|
JM |
44 |
if (parents.size() == 0) {
|
|
45 |
add(new Label("parentLink", "none"));
|
|
46 |
} else {
|
|
47 |
add(new LinkPanel("parentLink", null, parents.get(0).substring(0, 8), CommitDiffPage.class, newCommitParameter(parents.get(0))));
|
|
48 |
}
|
|
49 |
add(new BookmarkablePageLink<Void>("patchLink", PatchPage.class, WicketUtils.newObjectParameter(repositoryName, objectId)));
|
|
50 |
add(new BookmarkablePageLink<Void>("commitLink", CommitPage.class, WicketUtils.newObjectParameter(repositoryName, objectId)));
|
|
51 |
|
c1c3c6
|
52 |
add(new CommitHeaderPanel("commitHeader", repositoryName, commit));
|
608ece
|
53 |
|
JM |
54 |
// changed paths list
|
9bc17d
|
55 |
List<PathChangeModel> paths = JGitUtils.getFilesInCommit(r, commit);
|
a645ba
|
56 |
add(new CommitLegendPanel("commitLegend", paths));
|
9bc17d
|
57 |
ListDataProvider<PathChangeModel> pathsDp = new ListDataProvider<PathChangeModel>(paths);
|
JM |
58 |
DataView<PathChangeModel> pathsView = new DataView<PathChangeModel>("changedPath", pathsDp) {
|
608ece
|
59 |
private static final long serialVersionUID = 1L;
|
JM |
60 |
int counter = 0;
|
|
61 |
|
9bc17d
|
62 |
public void populateItem(final Item<PathChangeModel> item) {
|
JM |
63 |
final PathChangeModel entry = item.getModelObject();
|
|
64 |
Label changeType = new Label("changeType", "");
|
|
65 |
WicketUtils.setChangeTypeCssClass(changeType, entry.changeType);
|
|
66 |
setChangeTypeTooltip(changeType, entry.changeType);
|
|
67 |
item.add(changeType);
|
|
68 |
|
608ece
|
69 |
if (entry.isTree()) {
|
JM |
70 |
item.add(new LinkPanel("pathName", null, entry.path, TreePage.class, newPathParameter(entry.path)));
|
|
71 |
} else {
|
|
72 |
item.add(new LinkPanel("pathName", "list", entry.path, BlobPage.class, newPathParameter(entry.path)));
|
|
73 |
}
|
155bf7
|
74 |
|
608ece
|
75 |
item.add(new BookmarkablePageLink<Void>("patch", PatchPage.class, newPathParameter(entry.path)));
|
JM |
76 |
item.add(new BookmarkablePageLink<Void>("view", BlobPage.class, newPathParameter(entry.path)));
|
|
77 |
item.add(new BookmarkablePageLink<Void>("blame", BlobPage.class).setEnabled(false));
|
f602a2
|
78 |
item.add(new BookmarkablePageLink<Void>("history", HistoryPage.class, newPathParameter(entry.path)));
|
608ece
|
79 |
|
JM |
80 |
WicketUtils.setAlternatingBackground(item, counter);
|
|
81 |
counter++;
|
|
82 |
}
|
|
83 |
};
|
|
84 |
add(pathsView);
|
|
85 |
add(new Label("diffText", diff).setEscapeModelStrings(false));
|
|
86 |
}
|
155bf7
|
87 |
|
608ece
|
88 |
@Override
|
JM |
89 |
protected String getPageName() {
|
|
90 |
return getString("gb.commitdiff");
|
|
91 |
}
|
|
92 |
}
|