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.

HistoryPanel.java 7.0KB

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