commit | author | age
|
f13c4c
|
1 |
/*
|
JM |
2 |
* Copyright 2011 gitblit.com.
|
|
3 |
*
|
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5 |
* you may not use this file except in compliance with the License.
|
|
6 |
* You may obtain a copy of the License at
|
|
7 |
*
|
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9 |
*
|
|
10 |
* Unless required by applicable law or agreed to in writing, software
|
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13 |
* See the License for the specific language governing permissions and
|
|
14 |
* limitations under the License.
|
|
15 |
*/
|
608ece
|
16 |
package com.gitblit.wicket.pages;
|
JM |
17 |
|
|
18 |
import java.util.ArrayList;
|
|
19 |
import java.util.List;
|
|
20 |
|
|
21 |
import org.apache.wicket.PageParameters;
|
|
22 |
import org.apache.wicket.markup.html.basic.Label;
|
|
23 |
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
|
|
24 |
import org.apache.wicket.markup.repeater.Item;
|
|
25 |
import org.apache.wicket.markup.repeater.data.DataView;
|
|
26 |
import org.apache.wicket.markup.repeater.data.ListDataProvider;
|
f1720c
|
27 |
import org.eclipse.jgit.diff.DiffEntry.ChangeType;
|
608ece
|
28 |
import org.eclipse.jgit.lib.Repository;
|
JM |
29 |
import org.eclipse.jgit.revwalk.RevCommit;
|
|
30 |
|
3df349
|
31 |
import com.gitblit.GitBlit;
|
JM |
32 |
import com.gitblit.Keys;
|
1f9dae
|
33 |
import com.gitblit.models.PathModel.PathChangeModel;
|
JM |
34 |
import com.gitblit.utils.DiffUtils;
|
a125cf
|
35 |
import com.gitblit.utils.DiffUtils.DiffOutputType;
|
608ece
|
36 |
import com.gitblit.utils.JGitUtils;
|
JM |
37 |
import com.gitblit.wicket.WicketUtils;
|
c1c3c6
|
38 |
import com.gitblit.wicket.panels.CommitHeaderPanel;
|
a645ba
|
39 |
import com.gitblit.wicket.panels.CommitLegendPanel;
|
1f9dae
|
40 |
import com.gitblit.wicket.panels.LinkPanel;
|
608ece
|
41 |
|
JM |
42 |
public class CommitDiffPage extends RepositoryPage {
|
|
43 |
|
|
44 |
public CommitDiffPage(PageParameters params) {
|
|
45 |
super(params);
|
|
46 |
|
|
47 |
Repository r = getRepository();
|
bc9d4a
|
48 |
RevCommit commit = getCommit();
|
2a7306
|
49 |
DiffOutputType diffType = DiffOutputType.forName(GitBlit.getString(Keys.web.diffStyle,
|
JM |
50 |
DiffOutputType.GITBLIT.name()));
|
1f9dae
|
51 |
String diff = DiffUtils.getCommitDiff(r, commit, diffType);
|
155bf7
|
52 |
|
608ece
|
53 |
List<String> parents = new ArrayList<String>();
|
JM |
54 |
if (commit.getParentCount() > 0) {
|
|
55 |
for (RevCommit parent : commit.getParents()) {
|
|
56 |
parents.add(parent.name());
|
|
57 |
}
|
|
58 |
}
|
155bf7
|
59 |
|
608ece
|
60 |
// commit page links
|
JM |
61 |
if (parents.size() == 0) {
|
|
62 |
add(new Label("parentLink", "none"));
|
|
63 |
} else {
|
2a7306
|
64 |
add(new LinkPanel("parentLink", null, parents.get(0).substring(0, 8),
|
JM |
65 |
CommitDiffPage.class, newCommitParameter(parents.get(0))));
|
608ece
|
66 |
}
|
2a7306
|
67 |
add(new BookmarkablePageLink<Void>("patchLink", PatchPage.class,
|
JM |
68 |
WicketUtils.newObjectParameter(repositoryName, objectId)));
|
|
69 |
add(new BookmarkablePageLink<Void>("commitLink", CommitPage.class,
|
|
70 |
WicketUtils.newObjectParameter(repositoryName, objectId)));
|
608ece
|
71 |
|
c1c3c6
|
72 |
add(new CommitHeaderPanel("commitHeader", repositoryName, commit));
|
608ece
|
73 |
|
JM |
74 |
// changed paths list
|
9bc17d
|
75 |
List<PathChangeModel> paths = JGitUtils.getFilesInCommit(r, commit);
|
a645ba
|
76 |
add(new CommitLegendPanel("commitLegend", paths));
|
9bc17d
|
77 |
ListDataProvider<PathChangeModel> pathsDp = new ListDataProvider<PathChangeModel>(paths);
|
JM |
78 |
DataView<PathChangeModel> pathsView = new DataView<PathChangeModel>("changedPath", pathsDp) {
|
608ece
|
79 |
private static final long serialVersionUID = 1L;
|
2a7306
|
80 |
int counter;
|
608ece
|
81 |
|
9bc17d
|
82 |
public void populateItem(final Item<PathChangeModel> item) {
|
JM |
83 |
final PathChangeModel entry = item.getModelObject();
|
|
84 |
Label changeType = new Label("changeType", "");
|
|
85 |
WicketUtils.setChangeTypeCssClass(changeType, entry.changeType);
|
|
86 |
setChangeTypeTooltip(changeType, entry.changeType);
|
|
87 |
item.add(changeType);
|
|
88 |
|
608ece
|
89 |
if (entry.isTree()) {
|
2a7306
|
90 |
item.add(new LinkPanel("pathName", null, entry.path, TreePage.class,
|
a2709d
|
91 |
WicketUtils
|
JM |
92 |
.newPathParameter(repositoryName, entry.commitId, entry.path)));
|
608ece
|
93 |
} else {
|
2a7306
|
94 |
item.add(new LinkPanel("pathName", "list", entry.path, BlobPage.class,
|
a2709d
|
95 |
WicketUtils
|
JM |
96 |
.newPathParameter(repositoryName, entry.commitId, entry.path)));
|
608ece
|
97 |
}
|
155bf7
|
98 |
|
a2709d
|
99 |
item.add(new BookmarkablePageLink<Void>("patch", PatchPage.class, WicketUtils
|
JM |
100 |
.newPathParameter(repositoryName, entry.commitId, entry.path)));
|
|
101 |
item.add(new BookmarkablePageLink<Void>("view", BlobPage.class, WicketUtils
|
|
102 |
.newPathParameter(repositoryName, entry.commitId, entry.path)));
|
|
103 |
item.add(new BookmarkablePageLink<Void>("blame", BlamePage.class, WicketUtils
|
|
104 |
.newPathParameter(repositoryName, entry.commitId, entry.path)));
|
|
105 |
item.add(new BookmarkablePageLink<Void>("history", HistoryPage.class, WicketUtils
|
|
106 |
.newPathParameter(repositoryName, entry.commitId, entry.path))
|
|
107 |
.setEnabled(!entry.changeType.equals(ChangeType.ADD)));
|
608ece
|
108 |
|
JM |
109 |
WicketUtils.setAlternatingBackground(item, counter);
|
|
110 |
counter++;
|
|
111 |
}
|
|
112 |
};
|
|
113 |
add(pathsView);
|
|
114 |
add(new Label("diffText", diff).setEscapeModelStrings(false));
|
|
115 |
}
|
155bf7
|
116 |
|
608ece
|
117 |
@Override
|
JM |
118 |
protected String getPageName() {
|
|
119 |
return getString("gb.commitdiff");
|
|
120 |
}
|
|
121 |
}
|