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 |
*/
|
f602a2
|
16 |
package com.gitblit.wicket.panels;
|
JM |
17 |
|
|
18 |
import java.util.Date;
|
|
19 |
import java.util.List;
|
|
20 |
import java.util.Map;
|
|
21 |
|
|
22 |
import org.apache.wicket.markup.html.basic.Label;
|
|
23 |
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
|
e299e1
|
24 |
import org.apache.wicket.markup.html.panel.Fragment;
|
f602a2
|
25 |
import org.apache.wicket.markup.repeater.Item;
|
JM |
26 |
import org.apache.wicket.markup.repeater.data.DataView;
|
|
27 |
import org.apache.wicket.markup.repeater.data.ListDataProvider;
|
|
28 |
import org.apache.wicket.model.StringResourceModel;
|
|
29 |
import org.eclipse.jgit.lib.ObjectId;
|
|
30 |
import org.eclipse.jgit.lib.Repository;
|
|
31 |
import org.eclipse.jgit.revwalk.RevCommit;
|
|
32 |
|
|
33 |
import com.gitblit.GitBlit;
|
|
34 |
import com.gitblit.Keys;
|
1f9dae
|
35 |
import com.gitblit.models.PathModel;
|
JM |
36 |
import com.gitblit.models.PathModel.PathChangeModel;
|
4ab184
|
37 |
import com.gitblit.models.RefModel;
|
f602a2
|
38 |
import com.gitblit.utils.JGitUtils;
|
98ce17
|
39 |
import com.gitblit.utils.JGitUtils.SearchType;
|
9bc17d
|
40 |
import com.gitblit.utils.StringUtils;
|
f602a2
|
41 |
import com.gitblit.wicket.WicketUtils;
|
JM |
42 |
import com.gitblit.wicket.pages.BlobDiffPage;
|
e299e1
|
43 |
import com.gitblit.wicket.pages.BlobPage;
|
f602a2
|
44 |
import com.gitblit.wicket.pages.CommitDiffPage;
|
JM |
45 |
import com.gitblit.wicket.pages.CommitPage;
|
|
46 |
import com.gitblit.wicket.pages.HistoryPage;
|
98ce17
|
47 |
import com.gitblit.wicket.pages.SearchPage;
|
e299e1
|
48 |
import com.gitblit.wicket.pages.TreePage;
|
f602a2
|
49 |
|
JM |
50 |
public class HistoryPanel extends BasePanel {
|
|
51 |
|
|
52 |
private static final long serialVersionUID = 1L;
|
e299e1
|
53 |
|
2a7306
|
54 |
private boolean hasMore;
|
f602a2
|
55 |
|
2a7306
|
56 |
public HistoryPanel(String wicketId, final String repositoryName, final String objectId,
|
JM |
57 |
final String path, Repository r, int limit, int pageOffset) {
|
f602a2
|
58 |
super(wicketId);
|
JM |
59 |
boolean pageResults = limit <= 0;
|
2a7306
|
60 |
int itemsPerPage = GitBlit.getInteger(Keys.web.itemsPerPage, 50);
|
f602a2
|
61 |
if (itemsPerPage <= 1) {
|
JM |
62 |
itemsPerPage = 50;
|
|
63 |
}
|
e299e1
|
64 |
|
JM |
65 |
RevCommit commit = JGitUtils.getCommit(r, objectId);
|
9bc17d
|
66 |
List<PathChangeModel> paths = JGitUtils.getFilesInCommit(r, commit);
|
e299e1
|
67 |
|
JM |
68 |
PathModel matchingPath = null;
|
|
69 |
for (PathModel p : paths) {
|
|
70 |
if (p.path.equals(path)) {
|
|
71 |
matchingPath = p;
|
|
72 |
break;
|
|
73 |
}
|
|
74 |
}
|
|
75 |
final boolean isTree = matchingPath == null ? true : matchingPath.isTree();
|
|
76 |
|
4ab184
|
77 |
final Map<ObjectId, List<RefModel>> allRefs = JGitUtils.getAllRefs(r);
|
f602a2
|
78 |
List<RevCommit> commits;
|
JM |
79 |
if (pageResults) {
|
|
80 |
// Paging result set
|
2a7306
|
81 |
commits = JGitUtils.getRevLog(r, objectId, path, pageOffset * itemsPerPage,
|
JM |
82 |
itemsPerPage);
|
f602a2
|
83 |
} else {
|
JM |
84 |
// Fixed size result set
|
|
85 |
commits = JGitUtils.getRevLog(r, objectId, path, 0, limit);
|
|
86 |
}
|
e299e1
|
87 |
|
f602a2
|
88 |
// inaccurate way to determine if there are more commits.
|
e299e1
|
89 |
// works unless commits.size() represents the exact end.
|
f602a2
|
90 |
hasMore = commits.size() >= itemsPerPage;
|
JM |
91 |
|
c1c3c6
|
92 |
add(new CommitHeaderPanel("commitHeader", repositoryName, commit));
|
f602a2
|
93 |
|
JM |
94 |
// breadcrumbs
|
|
95 |
add(new PathBreadcrumbsPanel("breadcrumbs", repositoryName, path, objectId));
|
|
96 |
|
|
97 |
ListDataProvider<RevCommit> dp = new ListDataProvider<RevCommit>(commits);
|
|
98 |
DataView<RevCommit> logView = new DataView<RevCommit>("commit", dp) {
|
|
99 |
private static final long serialVersionUID = 1L;
|
2a7306
|
100 |
int counter;
|
f602a2
|
101 |
|
JM |
102 |
public void populateItem(final Item<RevCommit> item) {
|
|
103 |
final RevCommit entry = item.getModelObject();
|
|
104 |
final Date date = JGitUtils.getCommitDate(entry);
|
|
105 |
|
|
106 |
item.add(WicketUtils.createDateLabel("commitDate", date, getTimeZone()));
|
|
107 |
|
98ce17
|
108 |
// author search link
|
f602a2
|
109 |
String author = entry.getAuthorIdent().getName();
|
2a7306
|
110 |
LinkPanel authorLink = new LinkPanel("commitAuthor", "list", author,
|
JM |
111 |
SearchPage.class, WicketUtils.newSearchParameter(repositoryName, objectId,
|
|
112 |
author, SearchType.AUTHOR));
|
98ce17
|
113 |
setPersonSearchTooltip(authorLink, author, SearchType.AUTHOR);
|
JM |
114 |
item.add(authorLink);
|
f5d0ad
|
115 |
|
a645ba
|
116 |
// merge icon
|
JM |
117 |
if (entry.getParentCount() > 1) {
|
1e8390
|
118 |
item.add(WicketUtils.newImage("commitIcon", "commit_merge_16x16.png"));
|
a645ba
|
119 |
} else {
|
1e8390
|
120 |
item.add(WicketUtils.newBlankImage("commitIcon"));
|
a645ba
|
121 |
}
|
JM |
122 |
|
f602a2
|
123 |
String shortMessage = entry.getShortMessage();
|
JM |
124 |
String trimmedMessage = StringUtils.trimShortLog(shortMessage);
|
2a7306
|
125 |
LinkPanel shortlog = new LinkPanel("commitShortMessage", "list subject",
|
JM |
126 |
trimmedMessage, CommitPage.class, WicketUtils.newObjectParameter(
|
|
127 |
repositoryName, entry.getName()));
|
f602a2
|
128 |
if (!shortMessage.equals(trimmedMessage)) {
|
1e8390
|
129 |
WicketUtils.setHtmlTooltip(shortlog, shortMessage);
|
f602a2
|
130 |
}
|
JM |
131 |
item.add(shortlog);
|
|
132 |
|
|
133 |
item.add(new RefsPanel("commitRefs", repositoryName, entry, allRefs));
|
|
134 |
|
e299e1
|
135 |
if (isTree) {
|
JM |
136 |
Fragment links = new Fragment("historyLinks", "treeLinks", this);
|
2a7306
|
137 |
links.add(new BookmarkablePageLink<Void>("tree", TreePage.class, WicketUtils
|
JM |
138 |
.newObjectParameter(repositoryName, entry.getName())));
|
|
139 |
links.add(new BookmarkablePageLink<Void>("commitdiff", CommitDiffPage.class,
|
|
140 |
WicketUtils.newObjectParameter(repositoryName, entry.getName())));
|
e299e1
|
141 |
item.add(links);
|
JM |
142 |
} else {
|
|
143 |
Fragment links = new Fragment("historyLinks", "blobLinks", this);
|
2a7306
|
144 |
links.add(new BookmarkablePageLink<Void>("view", BlobPage.class, WicketUtils
|
JM |
145 |
.newPathParameter(repositoryName, entry.getName(), path)));
|
|
146 |
links.add(new BookmarkablePageLink<Void>("commitdiff", CommitDiffPage.class,
|
|
147 |
WicketUtils.newObjectParameter(repositoryName, entry.getName())));
|
|
148 |
links.add(new BookmarkablePageLink<Void>("difftocurrent", BlobDiffPage.class,
|
|
149 |
WicketUtils.newBlobDiffParameter(repositoryName, entry.getName(),
|
|
150 |
objectId, path)).setEnabled(counter > 0));
|
e299e1
|
151 |
item.add(links);
|
JM |
152 |
}
|
f602a2
|
153 |
|
JM |
154 |
WicketUtils.setAlternatingBackground(item, counter);
|
|
155 |
counter++;
|
|
156 |
}
|
|
157 |
};
|
|
158 |
add(logView);
|
|
159 |
|
|
160 |
// determine to show pager, more, or neither
|
|
161 |
if (limit <= 0) {
|
|
162 |
// no display limit
|
|
163 |
add(new Label("moreHistory", "").setVisible(false));
|
|
164 |
} else {
|
|
165 |
if (pageResults) {
|
|
166 |
// paging
|
|
167 |
add(new Label("moreHistory", "").setVisible(false));
|
|
168 |
} else {
|
|
169 |
// more
|
|
170 |
if (commits.size() == limit) {
|
|
171 |
// show more
|
2a7306
|
172 |
add(new LinkPanel("moreHistory", "link", new StringResourceModel(
|
JM |
173 |
"gb.moreHistory", this, null), HistoryPage.class,
|
|
174 |
WicketUtils.newPathParameter(repositoryName, objectId, path)));
|
f602a2
|
175 |
} else {
|
JM |
176 |
// no more
|
|
177 |
add(new Label("moreHistory", "").setVisible(false));
|
|
178 |
}
|
|
179 |
}
|
|
180 |
}
|
|
181 |
}
|
e299e1
|
182 |
|
f602a2
|
183 |
public boolean hasMore() {
|
JM |
184 |
return hasMore;
|
|
185 |
}
|
|
186 |
}
|