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.2KB

11 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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.Keys;
  34. import com.gitblit.models.RefModel;
  35. import com.gitblit.servlet.BranchGraphServlet;
  36. import com.gitblit.utils.JGitUtils;
  37. import com.gitblit.utils.StringUtils;
  38. import com.gitblit.wicket.ExternalImage;
  39. import com.gitblit.wicket.WicketUtils;
  40. import com.gitblit.wicket.pages.CommitDiffPage;
  41. import com.gitblit.wicket.pages.CommitPage;
  42. import com.gitblit.wicket.pages.GitSearchPage;
  43. import com.gitblit.wicket.pages.LogPage;
  44. import com.gitblit.wicket.pages.TreePage;
  45. public class LogPanel extends BasePanel {
  46. private static final long serialVersionUID = 1L;
  47. private boolean hasMore;
  48. public LogPanel(String wicketId, final String repositoryName, final String objectId,
  49. Repository r, int limit, int pageOffset, boolean showRemoteRefs) {
  50. super(wicketId);
  51. boolean pageResults = limit <= 0;
  52. int itemsPerPage = app().settings().getInteger(Keys.web.itemsPerPage, 50);
  53. if (itemsPerPage <= 1) {
  54. itemsPerPage = 50;
  55. }
  56. final Map<ObjectId, List<RefModel>> allRefs = JGitUtils.getAllRefs(r, showRemoteRefs);
  57. List<RevCommit> commits;
  58. if (pageResults) {
  59. // Paging result set
  60. commits = JGitUtils.getRevLog(r, objectId, pageOffset * itemsPerPage, itemsPerPage);
  61. } else {
  62. // Fixed size result set
  63. commits = JGitUtils.getRevLog(r, objectId, 0, limit);
  64. }
  65. // inaccurate way to determine if there are more commits.
  66. // works unless commits.size() represents the exact end.
  67. hasMore = commits.size() >= itemsPerPage;
  68. final String baseUrl = WicketUtils.getGitblitURL(getRequest());
  69. final boolean showGraph = app().settings().getBoolean(Keys.web.showBranchGraph, true);
  70. MarkupContainer graph = new WebMarkupContainer("graph");
  71. add(graph);
  72. if (!showGraph || commits.isEmpty()) {
  73. // not showing or nothing to show
  74. graph.setVisible(false);
  75. } else {
  76. // set the rowspan on the graph row and +1 for the graph row itself
  77. graph.add(new SimpleAttributeModifier("rowspan", "" + (commits.size() + 1)));
  78. graph.add(new ExternalImage("image", BranchGraphServlet.asLink(baseUrl, repositoryName, commits.get(0).name(), commits.size())));
  79. }
  80. // header
  81. if (pageResults) {
  82. // shortlog page
  83. add(new Label("header", objectId));
  84. } else {
  85. // summary page
  86. // show shortlog page link
  87. add(new LinkPanel("header", "title", objectId, LogPage.class,
  88. WicketUtils.newRepositoryParameter(repositoryName)));
  89. }
  90. final int hashLen = app().settings().getInteger(Keys.web.shortCommitIdLength, 6);
  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;
  95. @Override
  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. null, 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. String clazz = counter % 2 == 0 ? "light commit" : "dark commit";
  142. WicketUtils.setCssClass(item, clazz);
  143. counter++;
  144. }
  145. };
  146. add(logView);
  147. // determine to show pager, more, or neither
  148. if (limit <= 0) {
  149. // no display limit
  150. add(new Label("moreLogs", "").setVisible(false));
  151. } else {
  152. if (pageResults) {
  153. // paging
  154. add(new Label("moreLogs", "").setVisible(false));
  155. } else {
  156. // more
  157. if (commits.size() == limit) {
  158. // show more
  159. add(new LinkPanel("moreLogs", "link", new StringResourceModel("gb.moreLogs",
  160. this, null), LogPage.class,
  161. WicketUtils.newRepositoryParameter(repositoryName)));
  162. } else {
  163. // no more
  164. add(new Label("moreLogs", "").setVisible(false));
  165. }
  166. }
  167. }
  168. }
  169. public boolean hasMore() {
  170. return hasMore;
  171. }
  172. }