commit | author | age
|
32dc8c
|
1 |
/* |
A |
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 |
*/ |
|
16 |
package com.gitblit.wicket.pages; |
|
17 |
|
|
18 |
import java.util.ArrayList; |
67b82a
|
19 |
import java.util.Arrays; |
32dc8c
|
20 |
import java.util.List; |
A |
21 |
|
|
22 |
import org.apache.wicket.PageParameters; |
|
23 |
import org.apache.wicket.markup.html.basic.Label; |
|
24 |
import org.apache.wicket.markup.html.link.BookmarkablePageLink; |
9cc56a
|
25 |
import org.apache.wicket.markup.html.link.ExternalLink; |
32dc8c
|
26 |
import org.apache.wicket.markup.repeater.Item; |
A |
27 |
import org.apache.wicket.markup.repeater.data.DataView; |
|
28 |
import org.apache.wicket.markup.repeater.data.ListDataProvider; |
|
29 |
import org.eclipse.jgit.diff.DiffEntry.ChangeType; |
|
30 |
import org.eclipse.jgit.lib.Repository; |
|
31 |
import org.eclipse.jgit.revwalk.RevCommit; |
|
32 |
|
67b82a
|
33 |
import com.gitblit.Constants; |
7dd99f
|
34 |
import com.gitblit.Keys; |
67b82a
|
35 |
import com.gitblit.models.GitNote; |
319342
|
36 |
import com.gitblit.models.PathModel.PathChangeModel; |
32dc8c
|
37 |
import com.gitblit.models.SubmoduleModel; |
ff17f7
|
38 |
import com.gitblit.servlet.RawServlet; |
32dc8c
|
39 |
import com.gitblit.utils.DiffUtils; |
cff352
|
40 |
import com.gitblit.utils.DiffUtils.DiffComparator; |
319342
|
41 |
import com.gitblit.utils.DiffUtils.DiffOutput; |
32dc8c
|
42 |
import com.gitblit.utils.DiffUtils.DiffOutputType; |
A |
43 |
import com.gitblit.utils.JGitUtils; |
a7db57
|
44 |
import com.gitblit.wicket.CacheControl; |
JM |
45 |
import com.gitblit.wicket.CacheControl.LastModified; |
32dc8c
|
46 |
import com.gitblit.wicket.WicketUtils; |
A |
47 |
import com.gitblit.wicket.panels.CommitHeaderPanel; |
|
48 |
import com.gitblit.wicket.panels.CommitLegendPanel; |
319342
|
49 |
import com.gitblit.wicket.panels.DiffStatPanel; |
b57b9e
|
50 |
import com.gitblit.wicket.panels.AvatarImage; |
32dc8c
|
51 |
import com.gitblit.wicket.panels.LinkPanel; |
67b82a
|
52 |
import com.gitblit.wicket.panels.RefsPanel; |
32dc8c
|
53 |
|
a7db57
|
54 |
@CacheControl(LastModified.BOOT) |
32dc8c
|
55 |
public class CommitDiffPage extends RepositoryPage { |
A |
56 |
|
|
57 |
public CommitDiffPage(PageParameters params) { |
|
58 |
super(params); |
|
59 |
|
5d59b9
|
60 |
final Repository r = getRepository(); |
JM |
61 |
final RevCommit commit = getCommit(); |
|
62 |
final DiffComparator diffComparator = WicketUtils.getDiffComparator(params); |
32dc8c
|
63 |
|
A |
64 |
List<String> parents = new ArrayList<String>(); |
|
65 |
if (commit.getParentCount() > 0) { |
|
66 |
for (RevCommit parent : commit.getParents()) { |
|
67 |
parents.add(parent.name()); |
|
68 |
} |
|
69 |
} |
|
70 |
|
|
71 |
// commit page links |
|
72 |
if (parents.size() == 0) { |
|
73 |
add(new Label("parentLink", getString("gb.none"))); |
|
74 |
} else { |
|
75 |
add(new LinkPanel("parentLink", null, parents.get(0).substring(0, 8), |
|
76 |
CommitDiffPage.class, newCommitParameter(parents.get(0)))); |
|
77 |
} |
|
78 |
add(new BookmarkablePageLink<Void>("patchLink", PatchPage.class, |
|
79 |
WicketUtils.newObjectParameter(repositoryName, objectId))); |
|
80 |
add(new BookmarkablePageLink<Void>("commitLink", CommitPage.class, |
|
81 |
WicketUtils.newObjectParameter(repositoryName, objectId))); |
5d59b9
|
82 |
add(new LinkPanel("whitespaceLink", null, getString(diffComparator.getOpposite().getTranslationKey()), |
JM |
83 |
CommitDiffPage.class, WicketUtils.newDiffParameter(repositoryName, objectId, diffComparator.getOpposite()))); |
32dc8c
|
84 |
|
A |
85 |
add(new CommitHeaderPanel("commitHeader", repositoryName, commit)); |
319342
|
86 |
|
7dd99f
|
87 |
final List<String> imageExtensions = app().settings().getStrings(Keys.web.imageExtensions); |
b6f475
|
88 |
final ImageDiffHandler handler = new ImageDiffHandler(this, repositoryName, |
7dd99f
|
89 |
parents.isEmpty() ? null : parents.get(0), commit.getName(), imageExtensions); |
310a80
|
90 |
final int tabLength = app().settings().getInteger(Keys.web.tabLength, 4); |
JM |
91 |
final DiffOutput diff = DiffUtils.getCommitDiff(r, commit, diffComparator, DiffOutputType.HTML, handler, tabLength); |
3e1336
|
92 |
if (handler.getImgDiffCount() > 0) { |
T |
93 |
addBottomScript("scripts/imgdiff.js"); // Tiny support script for image diffs |
|
94 |
} |
7dd99f
|
95 |
|
319342
|
96 |
// add commit diffstat |
JM |
97 |
int insertions = 0; |
|
98 |
int deletions = 0; |
|
99 |
for (PathChangeModel pcm : diff.stat.paths) { |
|
100 |
insertions += pcm.insertions; |
|
101 |
deletions += pcm.deletions; |
|
102 |
} |
|
103 |
add(new DiffStatPanel("diffStat", insertions, deletions)); |
32dc8c
|
104 |
|
cd9461
|
105 |
addFullText("fullMessage", commit.getFullMessage()); |
684cfd
|
106 |
|
67b82a
|
107 |
// git notes |
JM |
108 |
List<GitNote> notes = JGitUtils.getNotesOnCommit(r, commit); |
|
109 |
ListDataProvider<GitNote> notesDp = new ListDataProvider<GitNote>(notes); |
|
110 |
DataView<GitNote> notesView = new DataView<GitNote>("notes", notesDp) { |
|
111 |
private static final long serialVersionUID = 1L; |
|
112 |
|
699e71
|
113 |
@Override |
67b82a
|
114 |
public void populateItem(final Item<GitNote> item) { |
JM |
115 |
GitNote entry = item.getModelObject(); |
|
116 |
item.add(new RefsPanel("refName", repositoryName, Arrays.asList(entry.notesRef))); |
|
117 |
item.add(createPersonPanel("authorName", entry.notesRef.getAuthorIdent(), |
|
118 |
Constants.SearchType.AUTHOR)); |
b57b9e
|
119 |
item.add(new AvatarImage("noteAuthorAvatar", entry.notesRef.getAuthorIdent())); |
67b82a
|
120 |
item.add(WicketUtils.createTimestampLabel("authorDate", entry.notesRef |
JM |
121 |
.getAuthorIdent().getWhen(), getTimeZone(), getTimeUtils())); |
fef234
|
122 |
item.add(new Label("noteContent", bugtraqProcessor().processPlainCommitMessage(getRepository(), repositoryName, |
67b82a
|
123 |
entry.content)).setEscapeModelStrings(false)); |
JM |
124 |
} |
|
125 |
}; |
|
126 |
add(notesView.setVisible(notes.size() > 0)); |
699e71
|
127 |
|
32dc8c
|
128 |
// changed paths list |
319342
|
129 |
add(new CommitLegendPanel("commitLegend", diff.stat.paths)); |
JM |
130 |
ListDataProvider<PathChangeModel> pathsDp = new ListDataProvider<PathChangeModel>(diff.stat.paths); |
32dc8c
|
131 |
DataView<PathChangeModel> pathsView = new DataView<PathChangeModel>("changedPath", pathsDp) { |
A |
132 |
private static final long serialVersionUID = 1L; |
|
133 |
int counter; |
|
134 |
|
699e71
|
135 |
@Override |
32dc8c
|
136 |
public void populateItem(final Item<PathChangeModel> item) { |
A |
137 |
final PathChangeModel entry = item.getModelObject(); |
|
138 |
Label changeType = new Label("changeType", ""); |
|
139 |
WicketUtils.setChangeTypeCssClass(changeType, entry.changeType); |
|
140 |
setChangeTypeTooltip(changeType, entry.changeType); |
|
141 |
item.add(changeType); |
319342
|
142 |
item.add(new DiffStatPanel("diffStat", entry.insertions, entry.deletions, true)); |
32dc8c
|
143 |
|
A |
144 |
boolean hasSubmodule = false; |
|
145 |
String submodulePath = null; |
|
146 |
if (entry.isTree()) { |
|
147 |
// tree |
|
148 |
item.add(new LinkPanel("pathName", null, entry.path, TreePage.class, |
|
149 |
WicketUtils |
|
150 |
.newPathParameter(repositoryName, entry.commitId, entry.path))); |
|
151 |
} else if (entry.isSubmodule()) { |
|
152 |
// submodule |
|
153 |
String submoduleId = entry.objectId; |
|
154 |
SubmoduleModel submodule = getSubmodule(entry.path); |
|
155 |
submodulePath = submodule.gitblitPath; |
|
156 |
hasSubmodule = submodule.hasSubmodule; |
|
157 |
|
5c0605
|
158 |
// add relative link |
f0ebfe
|
159 |
item.add(new LinkPanel("pathName", "list", entry.path + " @ " + getShortObjectId(submoduleId), "#n" + entry.objectId)); |
32dc8c
|
160 |
} else { |
5c0605
|
161 |
// add relative link |
f0ebfe
|
162 |
item.add(new LinkPanel("pathName", "list", entry.path, "#n" + entry.objectId)); |
32dc8c
|
163 |
} |
A |
164 |
|
|
165 |
// quick links |
|
166 |
if (entry.isSubmodule()) { |
4cec4b
|
167 |
item.add(new ExternalLink("raw", "").setEnabled(false)); |
32dc8c
|
168 |
// submodule |
9cc56a
|
169 |
item.add(new ExternalLink("patch", "").setEnabled(false)); |
32dc8c
|
170 |
item.add(new BookmarkablePageLink<Void>("view", CommitPage.class, WicketUtils |
A |
171 |
.newObjectParameter(submodulePath, entry.objectId)).setEnabled(hasSubmodule)); |
9cc56a
|
172 |
item.add(new ExternalLink("blame", "").setEnabled(false)); |
32dc8c
|
173 |
item.add(new BookmarkablePageLink<Void>("history", HistoryPage.class, WicketUtils |
6b8976
|
174 |
.newPathParameter(repositoryName, entry.commitId, entry.path)) |
JM |
175 |
.setEnabled(!entry.changeType.equals(ChangeType.ADD))); |
32dc8c
|
176 |
} else { |
A |
177 |
// tree or blob |
|
178 |
item.add(new BookmarkablePageLink<Void>("patch", PatchPage.class, WicketUtils |
6b8976
|
179 |
.newPathParameter(repositoryName, entry.commitId, entry.path)) |
JM |
180 |
.setEnabled(!entry.changeType.equals(ChangeType.ADD) |
|
181 |
&& !entry.changeType.equals(ChangeType.DELETE))); |
32dc8c
|
182 |
item.add(new BookmarkablePageLink<Void>("view", BlobPage.class, WicketUtils |
6b8976
|
183 |
.newPathParameter(repositoryName, entry.commitId, entry.path)) |
JM |
184 |
.setEnabled(!entry.changeType.equals(ChangeType.DELETE))); |
ff17f7
|
185 |
String rawUrl = RawServlet.asLink(getContextUrl(), repositoryName, entry.commitId, entry.path); |
JM |
186 |
item.add(new ExternalLink("raw", rawUrl) |
c95e30
|
187 |
.setEnabled(!entry.changeType.equals(ChangeType.DELETE))); |
32dc8c
|
188 |
item.add(new BookmarkablePageLink<Void>("blame", BlamePage.class, WicketUtils |
6b8976
|
189 |
.newPathParameter(repositoryName, entry.commitId, entry.path)) |
JM |
190 |
.setEnabled(!entry.changeType.equals(ChangeType.ADD) |
|
191 |
&& !entry.changeType.equals(ChangeType.DELETE))); |
32dc8c
|
192 |
item.add(new BookmarkablePageLink<Void>("history", HistoryPage.class, WicketUtils |
A |
193 |
.newPathParameter(repositoryName, entry.commitId, entry.path)) |
|
194 |
.setEnabled(!entry.changeType.equals(ChangeType.ADD))); |
|
195 |
} |
699e71
|
196 |
|
32dc8c
|
197 |
WicketUtils.setAlternatingBackground(item, counter); |
A |
198 |
counter++; |
|
199 |
} |
|
200 |
}; |
|
201 |
add(pathsView); |
319342
|
202 |
add(new Label("diffText", diff.content).setEscapeModelStrings(false)); |
32dc8c
|
203 |
} |
A |
204 |
|
|
205 |
@Override |
|
206 |
protected String getPageName() { |
|
207 |
return getString("gb.commitdiff"); |
|
208 |
} |
699e71
|
209 |
|
6ef8d7
|
210 |
@Override |
5d5e55
|
211 |
protected boolean isCommitPage() { |
JM |
212 |
return true; |
|
213 |
} |
|
214 |
|
|
215 |
@Override |
6ef8d7
|
216 |
protected Class<? extends BasePage> getRepoNavPageClass() { |
JM |
217 |
return LogPage.class; |
32dc8c
|
218 |
} |
A |
219 |
} |