You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LogPanel.java 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  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.panels;
  17. import java.util.Date;
  18. import java.util.List;
  19. import java.util.Map;
  20. import org.apache.wicket.MarkupContainer;
  21. import org.apache.wicket.behavior.SimpleAttributeModifier;
  22. import org.apache.wicket.markup.html.WebMarkupContainer;
  23. import org.apache.wicket.markup.html.basic.Label;
  24. import org.apache.wicket.markup.html.link.BookmarkablePageLink;
  25. import org.apache.wicket.markup.repeater.Item;
  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. import com.gitblit.Constants;
  33. import com.gitblit.GitBlit;
  34. import com.gitblit.Keys;
  35. import com.gitblit.BranchGraphServlet;
  36. import com.gitblit.models.RefModel;
  37. import com.gitblit.utils.JGitUtils;
  38. import com.gitblit.utils.StringUtils;
  39. import com.gitblit.wicket.ExternalImage;
  40. import com.gitblit.wicket.WicketUtils;
  41. import com.gitblit.wicket.pages.CommitDiffPage;
  42. import com.gitblit.wicket.pages.CommitPage;
  43. import com.gitblit.wicket.pages.GitSearchPage;
  44. import com.gitblit.wicket.pages.LogPage;
  45. import com.gitblit.wicket.pages.TreePage;
  46. public class LogPanel extends BasePanel {
  47. private static final long serialVersionUID = 1L;
  48. private boolean hasMore;
  49. public LogPanel(String wicketId, final String repositoryName, final String objectId,
  50. Repository r, int limit, int pageOffset, boolean showRemoteRefs) {
  51. super(wicketId);
  52. boolean pageResults = limit <= 0;
  53. int itemsPerPage = GitBlit.getInteger(Keys.web.itemsPerPage, 50);
  54. if (itemsPerPage <= 1) {
  55. itemsPerPage = 50;
  56. }
  57. final Map<ObjectId, List<RefModel>> allRefs = JGitUtils.getAllRefs(r, showRemoteRefs);
  58. List<RevCommit> commits;
  59. if (pageResults) {
  60. // Paging result set
  61. commits = JGitUtils.getRevLog(r, objectId, pageOffset * itemsPerPage, itemsPerPage);
  62. } else {
  63. // Fixed size result set
  64. commits = JGitUtils.getRevLog(r, objectId, 0, limit);
  65. }
  66. // inaccurate way to determine if there are more commits.
  67. // works unless commits.size() represents the exact end.
  68. hasMore = commits.size() >= itemsPerPage;
  69. final String baseUrl = WicketUtils.getGitblitURL(getRequest());
  70. final boolean showGraph = GitBlit.getBoolean(Keys.web.showBranchGraph, true);
  71. MarkupContainer graph = new WebMarkupContainer("graph");
  72. add(graph);
  73. if (!showGraph || commits.isEmpty()) {
  74. // not showing or nothing to show
  75. graph.setVisible(false);
  76. } else {
  77. // set the rowspan on the graph row and +1 for the graph row itself
  78. graph.add(new SimpleAttributeModifier("rowspan", "" + (commits.size() + 1)));
  79. graph.add(new ExternalImage("image", BranchGraphServlet.asLink(baseUrl, repositoryName, commits.get(0).name(), commits.size())));
  80. }
  81. // header
  82. if (pageResults) {
  83. // shortlog page
  84. add(new Label("header", objectId));
  85. } else {
  86. // summary page
  87. // show shortlog page link
  88. add(new LinkPanel("header", "title", objectId, LogPage.class,
  89. WicketUtils.newRepositoryParameter(repositoryName)));
  90. }
  91. final int hashLen = GitBlit.getInteger(Keys.web.shortCommitIdLength, 6);
  92. ListDataProvider<RevCommit> dp = new ListDataProvider<RevCommit>(commits);
  93. DataView<RevCommit> logView = new DataView<RevCommit>("commit", dp) {
  94. private static final long serialVersionUID = 1L;
  95. int counter;
  96. public void populateItem(final Item<RevCommit> item) {
  97. final RevCommit entry = item.getModelObject();
  98. final Date date = JGitUtils.getCommitDate(entry);
  99. item.add(WicketUtils.createDateLabel("commitDate", date, getTimeZone(), getTimeUtils()));
  100. // author search link
  101. String author = entry.getAuthorIdent().getName();
  102. LinkPanel authorLink = new LinkPanel("commitAuthor", "list", author,
  103. GitSearchPage.class, WicketUtils.newSearchParameter(repositoryName,
  104. objectId, author, Constants.SearchType.AUTHOR));
  105. setPersonSearchTooltip(authorLink, author, Constants.SearchType.AUTHOR);
  106. item.add(authorLink);
  107. // merge icon
  108. if (entry.getParentCount() > 1) {
  109. item.add(WicketUtils.newImage("commitIcon", "commit_merge_16x16.png"));
  110. } else {
  111. item.add(WicketUtils.newBlankImage("commitIcon"));
  112. }
  113. // short message
  114. String shortMessage = entry.getShortMessage();
  115. String trimmedMessage = shortMessage;
  116. if (allRefs.containsKey(entry.getId())) {
  117. trimmedMessage = StringUtils.trimString(shortMessage, Constants.LEN_SHORTLOG_REFS);
  118. } else {
  119. trimmedMessage = StringUtils.trimString(shortMessage, Constants.LEN_SHORTLOG);
  120. }
  121. LinkPanel shortlog = new LinkPanel("commitShortMessage", "list subject",
  122. trimmedMessage, CommitPage.class, WicketUtils.newObjectParameter(
  123. repositoryName, entry.getName()));
  124. if (!shortMessage.equals(trimmedMessage)) {
  125. WicketUtils.setHtmlTooltip(shortlog, shortMessage);
  126. }
  127. item.add(shortlog);
  128. item.add(new RefsPanel("commitRefs", repositoryName, entry, allRefs));
  129. // commit hash link
  130. LinkPanel commitHash = new LinkPanel("hashLink", null, entry.getName().substring(0, hashLen),
  131. CommitPage.class, WicketUtils.newObjectParameter(
  132. repositoryName, entry.getName()));
  133. WicketUtils.setCssClass(commitHash, "shortsha1");
  134. WicketUtils.setHtmlTooltip(commitHash, entry.getName());
  135. item.add(commitHash);
  136. item.add(new BookmarkablePageLink<Void>("diff", CommitDiffPage.class, WicketUtils
  137. .newObjectParameter(repositoryName, entry.getName())).setEnabled(entry
  138. .getParentCount() > 0));
  139. item.add(new BookmarkablePageLink<Void>("tree", TreePage.class, WicketUtils
  140. .newObjectParameter(repositoryName, entry.getName())));
  141. WicketUtils.setAlternatingBackground(item, counter);
  142. counter++;
  143. }
  144. };
  145. add(logView);
  146. // determine to show pager, more, or neither
  147. if (limit <= 0) {
  148. // no display limit
  149. add(new Label("moreLogs", "").setVisible(false));
  150. } else {
  151. if (pageResults) {
  152. // paging
  153. add(new Label("moreLogs", "").setVisible(false));
  154. } else {
  155. // more
  156. if (commits.size() == limit) {
  157. // show more
  158. add(new LinkPanel("moreLogs", "link", new StringResourceModel("gb.moreLogs",
  159. this, null), LogPage.class,
  160. WicketUtils.newRepositoryParameter(repositoryName)));
  161. } else {
  162. // no more
  163. add(new Label("moreLogs", "").setVisible(false));
  164. }
  165. }
  166. }
  167. }
  168. public boolean hasMore() {
  169. return hasMore;
  170. }
  171. }