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 |
*/
|
5fe7df
|
16 |
package com.gitblit.wicket.pages;
|
JM |
17 |
|
|
18 |
import java.util.ArrayList;
|
4ab184
|
19 |
import java.util.Arrays;
|
5fe7df
|
20 |
import java.util.List;
|
JM |
21 |
|
|
22 |
import org.apache.wicket.PageParameters;
|
|
23 |
import org.apache.wicket.markup.html.basic.Label;
|
698678
|
24 |
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
|
9197d3
|
25 |
import org.apache.wicket.markup.html.link.ExternalLink;
|
5fe7df
|
26 |
import org.apache.wicket.markup.repeater.Item;
|
JM |
27 |
import org.apache.wicket.markup.repeater.data.DataView;
|
|
28 |
import org.apache.wicket.markup.repeater.data.ListDataProvider;
|
1a3fc5
|
29 |
import org.apache.wicket.model.StringResourceModel;
|
f1720c
|
30 |
import org.eclipse.jgit.diff.DiffEntry.ChangeType;
|
5fe7df
|
31 |
import org.eclipse.jgit.lib.Repository;
|
JM |
32 |
import org.eclipse.jgit.revwalk.RevCommit;
|
|
33 |
|
33d8d8
|
34 |
import com.gitblit.Constants;
|
9197d3
|
35 |
import com.gitblit.DownloadZipServlet;
|
JM |
36 |
import com.gitblit.GitBlit;
|
|
37 |
import com.gitblit.Keys;
|
a125cf
|
38 |
import com.gitblit.models.GitNote;
|
eb870f
|
39 |
import com.gitblit.models.SubmoduleModel;
|
1f9dae
|
40 |
import com.gitblit.models.PathModel.PathChangeModel;
|
5fe7df
|
41 |
import com.gitblit.utils.JGitUtils;
|
JM |
42 |
import com.gitblit.wicket.WicketUtils;
|
c1c3c6
|
43 |
import com.gitblit.wicket.panels.CommitHeaderPanel;
|
a645ba
|
44 |
import com.gitblit.wicket.panels.CommitLegendPanel;
|
797322
|
45 |
import com.gitblit.wicket.panels.GravatarImage;
|
1f9dae
|
46 |
import com.gitblit.wicket.panels.LinkPanel;
|
4ab184
|
47 |
import com.gitblit.wicket.panels.RefsPanel;
|
5fe7df
|
48 |
|
JM |
49 |
public class CommitPage extends RepositoryPage {
|
|
50 |
|
|
51 |
public CommitPage(PageParameters params) {
|
cebf45
|
52 |
super(params);
|
5fe7df
|
53 |
|
JM |
54 |
Repository r = getRepository();
|
bc9d4a
|
55 |
RevCommit c = getCommit();
|
eb870f
|
56 |
|
5fe7df
|
57 |
List<String> parents = new ArrayList<String>();
|
JM |
58 |
if (c.getParentCount() > 0) {
|
|
59 |
for (RevCommit parent : c.getParents()) {
|
|
60 |
parents.add(parent.name());
|
|
61 |
}
|
|
62 |
}
|
155bf7
|
63 |
|
5fe7df
|
64 |
// commit page links
|
JM |
65 |
if (parents.size() == 0) {
|
|
66 |
add(new Label("parentLink", "none"));
|
1a3fc5
|
67 |
add(new Label("commitdiffLink", getString("gb.commitdiff")));
|
5fe7df
|
68 |
} else {
|
008322
|
69 |
add(new LinkPanel("parentLink", null, getShortObjectId(parents.get(0)),
|
JM |
70 |
CommitPage.class, newCommitParameter(parents.get(0))));
|
2a7306
|
71 |
add(new LinkPanel("commitdiffLink", null, new StringResourceModel("gb.commitdiff",
|
JM |
72 |
this, null), CommitDiffPage.class, WicketUtils.newObjectParameter(
|
|
73 |
repositoryName, objectId)));
|
5fe7df
|
74 |
}
|
2a7306
|
75 |
add(new BookmarkablePageLink<Void>("patchLink", PatchPage.class,
|
JM |
76 |
WicketUtils.newObjectParameter(repositoryName, objectId)));
|
155bf7
|
77 |
|
c1c3c6
|
78 |
add(new CommitHeaderPanel("commitHeader", repositoryName, c));
|
155bf7
|
79 |
|
5fe7df
|
80 |
addRefs(r, c);
|
JM |
81 |
|
98ce17
|
82 |
// author
|
33d8d8
|
83 |
add(createPersonPanel("commitAuthor", c.getAuthorIdent(), Constants.SearchType.AUTHOR));
|
2a7306
|
84 |
add(WicketUtils.createTimestampLabel("commitAuthorDate", c.getAuthorIdent().getWhen(),
|
9adf62
|
85 |
getTimeZone(), getTimeUtils()));
|
9dcd53
|
86 |
|
98ce17
|
87 |
// committer
|
33d8d8
|
88 |
add(createPersonPanel("commitCommitter", c.getCommitterIdent(), Constants.SearchType.COMMITTER));
|
2a7306
|
89 |
add(WicketUtils.createTimestampLabel("commitCommitterDate",
|
9adf62
|
90 |
c.getCommitterIdent().getWhen(), getTimeZone(), getTimeUtils()));
|
5fe7df
|
91 |
|
JM |
92 |
add(new Label("commitId", c.getName()));
|
|
93 |
|
2a7306
|
94 |
add(new LinkPanel("commitTree", "list", c.getTree().getName(), TreePage.class,
|
JM |
95 |
newCommitParameter()));
|
9197d3
|
96 |
add(new BookmarkablePageLink<Void>("treeLink", TreePage.class, newCommitParameter()));
|
2179fb
|
97 |
final String baseUrl = WicketUtils.getGitblitURL(getRequest());
|
JM |
98 |
add(new ExternalLink("zipLink", DownloadZipServlet.asLink(baseUrl, repositoryName,
|
|
99 |
objectId, null)).setVisible(GitBlit.getBoolean(Keys.web.allowZipDownloads, true)));
|
5fe7df
|
100 |
|
JM |
101 |
// Parent Commits
|
|
102 |
ListDataProvider<String> parentsDp = new ListDataProvider<String>(parents);
|
|
103 |
DataView<String> parentsView = new DataView<String>("commitParents", parentsDp) {
|
|
104 |
private static final long serialVersionUID = 1L;
|
|
105 |
|
|
106 |
public void populateItem(final Item<String> item) {
|
|
107 |
String entry = item.getModelObject();
|
2a7306
|
108 |
item.add(new LinkPanel("commitParent", "list", entry, CommitPage.class,
|
JM |
109 |
newCommitParameter(entry)));
|
|
110 |
item.add(new BookmarkablePageLink<Void>("view", CommitPage.class,
|
|
111 |
newCommitParameter(entry)));
|
|
112 |
item.add(new BookmarkablePageLink<Void>("diff", CommitDiffPage.class,
|
|
113 |
newCommitParameter(entry)));
|
5fe7df
|
114 |
}
|
JM |
115 |
};
|
|
116 |
add(parentsView);
|
|
117 |
|
|
118 |
addFullText("fullMessage", c.getFullMessage(), true);
|
|
119 |
|
a125cf
|
120 |
// git notes
|
JM |
121 |
List<GitNote> notes = JGitUtils.getNotesOnCommit(r, c);
|
|
122 |
ListDataProvider<GitNote> notesDp = new ListDataProvider<GitNote>(notes);
|
|
123 |
DataView<GitNote> notesView = new DataView<GitNote>("notes", notesDp) {
|
|
124 |
private static final long serialVersionUID = 1L;
|
|
125 |
|
|
126 |
public void populateItem(final Item<GitNote> item) {
|
|
127 |
GitNote entry = item.getModelObject();
|
4ab184
|
128 |
item.add(new RefsPanel("refName", repositoryName, Arrays.asList(entry.notesRef)));
|
716745
|
129 |
item.add(createPersonPanel("authorName", entry.notesRef.getAuthorIdent(),
|
33d8d8
|
130 |
Constants.SearchType.AUTHOR));
|
9dcd53
|
131 |
item.add(new GravatarImage("noteAuthorAvatar", entry.notesRef.getAuthorIdent()));
|
716745
|
132 |
item.add(WicketUtils.createTimestampLabel("authorDate", entry.notesRef
|
9adf62
|
133 |
.getAuthorIdent().getWhen(), getTimeZone(), getTimeUtils()));
|
85c2e6
|
134 |
item.add(new Label("noteContent", GitBlit.self().processCommitMessage(
|
JM |
135 |
repositoryName, entry.content)).setEscapeModelStrings(false));
|
a125cf
|
136 |
}
|
JM |
137 |
};
|
|
138 |
add(notesView.setVisible(notes.size() > 0));
|
716745
|
139 |
|
5fe7df
|
140 |
// changed paths list
|
2a7306
|
141 |
List<PathChangeModel> paths = JGitUtils.getFilesInCommit(r, c);
|
a645ba
|
142 |
add(new CommitLegendPanel("commitLegend", paths));
|
9bc17d
|
143 |
ListDataProvider<PathChangeModel> pathsDp = new ListDataProvider<PathChangeModel>(paths);
|
JM |
144 |
DataView<PathChangeModel> pathsView = new DataView<PathChangeModel>("changedPath", pathsDp) {
|
5fe7df
|
145 |
private static final long serialVersionUID = 1L;
|
2a7306
|
146 |
int counter;
|
5fe7df
|
147 |
|
9bc17d
|
148 |
public void populateItem(final Item<PathChangeModel> item) {
|
JM |
149 |
final PathChangeModel entry = item.getModelObject();
|
|
150 |
Label changeType = new Label("changeType", "");
|
|
151 |
WicketUtils.setChangeTypeCssClass(changeType, entry.changeType);
|
|
152 |
setChangeTypeTooltip(changeType, entry.changeType);
|
|
153 |
item.add(changeType);
|
eb870f
|
154 |
|
JM |
155 |
boolean hasSubmodule = false;
|
|
156 |
String submodulePath = null;
|
5fe7df
|
157 |
if (entry.isTree()) {
|
eb870f
|
158 |
// tree
|
2a7306
|
159 |
item.add(new LinkPanel("pathName", null, entry.path, TreePage.class,
|
a2709d
|
160 |
WicketUtils
|
JM |
161 |
.newPathParameter(repositoryName, entry.commitId, entry.path)));
|
eb870f
|
162 |
} else if (entry.isSubmodule()) {
|
JM |
163 |
// submodule
|
|
164 |
String submoduleId = entry.objectId;
|
|
165 |
SubmoduleModel submodule = getSubmodule(entry.path);
|
|
166 |
submodulePath = submodule.gitblitPath;
|
|
167 |
hasSubmodule = submodule.hasSubmodule;
|
|
168 |
|
|
169 |
item.add(new LinkPanel("pathName", "list", entry.path + " @ " +
|
|
170 |
getShortObjectId(submoduleId), TreePage.class,
|
|
171 |
WicketUtils.newPathParameter(submodulePath, submoduleId, "")).setEnabled(hasSubmodule));
|
5fe7df
|
172 |
} else {
|
eb870f
|
173 |
// blob
|
2a7306
|
174 |
item.add(new LinkPanel("pathName", "list", entry.path, BlobPage.class,
|
a2709d
|
175 |
WicketUtils
|
JM |
176 |
.newPathParameter(repositoryName, entry.commitId, entry.path)));
|
5fe7df
|
177 |
}
|
eb870f
|
178 |
|
JM |
179 |
// quick links
|
|
180 |
if (entry.isSubmodule()) {
|
|
181 |
// submodule
|
|
182 |
item.add(new BookmarkablePageLink<Void>("diff", BlobDiffPage.class, WicketUtils
|
|
183 |
.newPathParameter(submodulePath, entry.objectId, entry.path))
|
|
184 |
.setEnabled(false));
|
|
185 |
item.add(new BookmarkablePageLink<Void>("view", CommitPage.class, WicketUtils
|
|
186 |
.newObjectParameter(submodulePath, entry.objectId)).setEnabled(hasSubmodule));
|
|
187 |
item.add(new BookmarkablePageLink<Void>("blame", BlamePage.class, WicketUtils
|
|
188 |
.newPathParameter(submodulePath, entry.objectId, entry.path))
|
|
189 |
.setEnabled(false));
|
|
190 |
item.add(new BookmarkablePageLink<Void>("history", HistoryPage.class, WicketUtils
|
|
191 |
.newPathParameter(submodulePath, entry.objectId, entry.path))
|
|
192 |
.setEnabled(hasSubmodule));
|
|
193 |
} else {
|
|
194 |
// tree or blob
|
|
195 |
item.add(new BookmarkablePageLink<Void>("diff", BlobDiffPage.class, WicketUtils
|
|
196 |
.newPathParameter(repositoryName, entry.commitId, entry.path))
|
|
197 |
.setEnabled(!entry.changeType.equals(ChangeType.ADD)
|
|
198 |
&& !entry.changeType.equals(ChangeType.DELETE)));
|
|
199 |
item.add(new BookmarkablePageLink<Void>("view", BlobPage.class, WicketUtils
|
|
200 |
.newPathParameter(repositoryName, entry.commitId, entry.path)));
|
|
201 |
item.add(new BookmarkablePageLink<Void>("blame", BlamePage.class, WicketUtils
|
|
202 |
.newPathParameter(repositoryName, entry.commitId, entry.path))
|
|
203 |
.setEnabled(!entry.changeType.equals(ChangeType.ADD)));
|
|
204 |
item.add(new BookmarkablePageLink<Void>("history", HistoryPage.class, WicketUtils
|
|
205 |
.newPathParameter(repositoryName, entry.commitId, entry.path))
|
|
206 |
.setEnabled(!entry.changeType.equals(ChangeType.ADD)));
|
|
207 |
}
|
698678
|
208 |
|
JM |
209 |
WicketUtils.setAlternatingBackground(item, counter);
|
5fe7df
|
210 |
counter++;
|
JM |
211 |
}
|
|
212 |
};
|
|
213 |
add(pathsView);
|
|
214 |
}
|
a645ba
|
215 |
|
cebf45
|
216 |
@Override
|
JM |
217 |
protected String getPageName() {
|
1e47ab
|
218 |
return getString("gb.commit");
|
cebf45
|
219 |
}
|
5fe7df
|
220 |
}
|