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