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.

CommitPage.java 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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.pages;
  17. import java.util.ArrayList;
  18. import java.util.Arrays;
  19. import java.util.List;
  20. import org.apache.wicket.PageParameters;
  21. import org.apache.wicket.markup.html.basic.Label;
  22. import org.apache.wicket.markup.html.link.BookmarkablePageLink;
  23. import org.apache.wicket.markup.html.link.ExternalLink;
  24. import org.apache.wicket.markup.repeater.Item;
  25. import org.apache.wicket.markup.repeater.data.DataView;
  26. import org.apache.wicket.markup.repeater.data.ListDataProvider;
  27. import org.apache.wicket.model.StringResourceModel;
  28. import org.eclipse.jgit.diff.DiffEntry.ChangeType;
  29. import org.eclipse.jgit.lib.Repository;
  30. import org.eclipse.jgit.revwalk.RevCommit;
  31. import com.gitblit.Constants;
  32. import com.gitblit.GitBlit;
  33. import com.gitblit.models.GitNote;
  34. import com.gitblit.models.PathModel.PathChangeModel;
  35. import com.gitblit.models.SubmoduleModel;
  36. import com.gitblit.utils.JGitUtils;
  37. import com.gitblit.wicket.CacheControl;
  38. import com.gitblit.wicket.CacheControl.LastModified;
  39. import com.gitblit.wicket.WicketUtils;
  40. import com.gitblit.wicket.panels.CommitHeaderPanel;
  41. import com.gitblit.wicket.panels.CommitLegendPanel;
  42. import com.gitblit.wicket.panels.CompressedDownloadsPanel;
  43. import com.gitblit.wicket.panels.DiffStatPanel;
  44. import com.gitblit.wicket.panels.GravatarImage;
  45. import com.gitblit.wicket.panels.LinkPanel;
  46. import com.gitblit.wicket.panels.RefsPanel;
  47. @CacheControl(LastModified.BOOT)
  48. public class CommitPage extends RepositoryPage {
  49. public CommitPage(PageParameters params) {
  50. super(params);
  51. Repository r = getRepository();
  52. RevCommit c = getCommit();
  53. List<String> parents = new ArrayList<String>();
  54. if (c.getParentCount() > 0) {
  55. for (RevCommit parent : c.getParents()) {
  56. parents.add(parent.name());
  57. }
  58. }
  59. // commit page links
  60. if (parents.size() == 0) {
  61. add(new Label("parentLink", "none"));
  62. add(new Label("commitdiffLink", getString("gb.commitdiff")));
  63. } else {
  64. add(new LinkPanel("parentLink", null, getShortObjectId(parents.get(0)),
  65. CommitPage.class, newCommitParameter(parents.get(0))));
  66. add(new LinkPanel("commitdiffLink", null, new StringResourceModel("gb.commitdiff",
  67. this, null), CommitDiffPage.class, WicketUtils.newObjectParameter(
  68. repositoryName, objectId)));
  69. }
  70. add(new BookmarkablePageLink<Void>("patchLink", PatchPage.class,
  71. WicketUtils.newObjectParameter(repositoryName, objectId)));
  72. add(new CommitHeaderPanel("commitHeader", repositoryName, c));
  73. addRefs(r, c);
  74. // author
  75. add(createPersonPanel("commitAuthor", c.getAuthorIdent(), Constants.SearchType.AUTHOR));
  76. add(WicketUtils.createTimestampLabel("commitAuthorDate", c.getAuthorIdent().getWhen(),
  77. getTimeZone(), getTimeUtils()));
  78. // committer
  79. add(createPersonPanel("commitCommitter", c.getCommitterIdent(), Constants.SearchType.COMMITTER));
  80. add(WicketUtils.createTimestampLabel("commitCommitterDate",
  81. c.getCommitterIdent().getWhen(), getTimeZone(), getTimeUtils()));
  82. add(new Label("commitId", c.getName()));
  83. add(new LinkPanel("commitTree", "list", c.getTree().getName(), TreePage.class,
  84. newCommitParameter()));
  85. add(new BookmarkablePageLink<Void>("treeLink", TreePage.class, newCommitParameter()));
  86. final String baseUrl = WicketUtils.getGitblitURL(getRequest());
  87. add(new CompressedDownloadsPanel("compressedLinks", baseUrl, repositoryName, objectId, null));
  88. // Parent Commits
  89. ListDataProvider<String> parentsDp = new ListDataProvider<String>(parents);
  90. DataView<String> parentsView = new DataView<String>("commitParents", parentsDp) {
  91. private static final long serialVersionUID = 1L;
  92. public void populateItem(final Item<String> item) {
  93. String entry = item.getModelObject();
  94. item.add(new LinkPanel("commitParent", "list", entry, CommitPage.class,
  95. newCommitParameter(entry)));
  96. item.add(new BookmarkablePageLink<Void>("view", CommitPage.class,
  97. newCommitParameter(entry)));
  98. item.add(new BookmarkablePageLink<Void>("diff", CommitDiffPage.class,
  99. newCommitParameter(entry)));
  100. }
  101. };
  102. add(parentsView);
  103. addFullText("fullMessage", c.getFullMessage());
  104. // git notes
  105. List<GitNote> notes = JGitUtils.getNotesOnCommit(r, c);
  106. ListDataProvider<GitNote> notesDp = new ListDataProvider<GitNote>(notes);
  107. DataView<GitNote> notesView = new DataView<GitNote>("notes", notesDp) {
  108. private static final long serialVersionUID = 1L;
  109. public void populateItem(final Item<GitNote> item) {
  110. GitNote entry = item.getModelObject();
  111. item.add(new RefsPanel("refName", repositoryName, Arrays.asList(entry.notesRef)));
  112. item.add(createPersonPanel("authorName", entry.notesRef.getAuthorIdent(),
  113. Constants.SearchType.AUTHOR));
  114. item.add(new GravatarImage("noteAuthorAvatar", entry.notesRef.getAuthorIdent()));
  115. item.add(WicketUtils.createTimestampLabel("authorDate", entry.notesRef
  116. .getAuthorIdent().getWhen(), getTimeZone(), getTimeUtils()));
  117. item.add(new Label("noteContent", GitBlit.self().processPlainCommitMessage(repositoryName,
  118. entry.content)).setEscapeModelStrings(false));
  119. }
  120. };
  121. add(notesView.setVisible(notes.size() > 0));
  122. // changed paths list
  123. List<PathChangeModel> paths = JGitUtils.getFilesInCommit(r, c);
  124. // add commit diffstat
  125. int insertions = 0;
  126. int deletions = 0;
  127. for (PathChangeModel pcm : paths) {
  128. insertions += pcm.insertions;
  129. deletions += pcm.deletions;
  130. }
  131. add(new DiffStatPanel("diffStat", insertions, deletions));
  132. add(new CommitLegendPanel("commitLegend", paths));
  133. ListDataProvider<PathChangeModel> pathsDp = new ListDataProvider<PathChangeModel>(paths);
  134. DataView<PathChangeModel> pathsView = new DataView<PathChangeModel>("changedPath", pathsDp) {
  135. private static final long serialVersionUID = 1L;
  136. int counter;
  137. public void populateItem(final Item<PathChangeModel> item) {
  138. final PathChangeModel entry = item.getModelObject();
  139. Label changeType = new Label("changeType", "");
  140. WicketUtils.setChangeTypeCssClass(changeType, entry.changeType);
  141. setChangeTypeTooltip(changeType, entry.changeType);
  142. item.add(changeType);
  143. item.add(new DiffStatPanel("diffStat", entry.insertions, entry.deletions, true));
  144. boolean hasSubmodule = false;
  145. String submodulePath = null;
  146. if (entry.isTree()) {
  147. // tree
  148. item.add(new LinkPanel("pathName", null, entry.path, TreePage.class,
  149. WicketUtils
  150. .newPathParameter(repositoryName, entry.commitId, entry.path)));
  151. } else if (entry.isSubmodule()) {
  152. // submodule
  153. String submoduleId = entry.objectId;
  154. SubmoduleModel submodule = getSubmodule(entry.path);
  155. submodulePath = submodule.gitblitPath;
  156. hasSubmodule = submodule.hasSubmodule;
  157. item.add(new LinkPanel("pathName", "list", entry.path + " @ " +
  158. getShortObjectId(submoduleId), TreePage.class,
  159. WicketUtils.newPathParameter(submodulePath, submoduleId, "")).setEnabled(hasSubmodule));
  160. } else {
  161. // blob
  162. String displayPath = entry.path;
  163. String path = entry.path;
  164. if (entry.isSymlink()) {
  165. path = JGitUtils.getStringContent(getRepository(), getCommit().getTree(), path);
  166. displayPath = entry.path + " -> " + path;
  167. }
  168. item.add(new LinkPanel("pathName", "list", displayPath, BlobPage.class,
  169. WicketUtils
  170. .newPathParameter(repositoryName, entry.commitId, path)));
  171. }
  172. // quick links
  173. if (entry.isSubmodule()) {
  174. // submodule
  175. item.add(new BookmarkablePageLink<Void>("diff", BlobDiffPage.class, WicketUtils
  176. .newPathParameter(repositoryName, entry.commitId, entry.path))
  177. .setEnabled(!entry.changeType.equals(ChangeType.ADD)));
  178. item.add(new BookmarkablePageLink<Void>("view", CommitPage.class, WicketUtils
  179. .newObjectParameter(submodulePath, entry.objectId)).setEnabled(hasSubmodule));
  180. item.add(new ExternalLink("blame", "").setEnabled(false));
  181. item.add(new BookmarkablePageLink<Void>("history", HistoryPage.class, WicketUtils
  182. .newPathParameter(repositoryName, entry.commitId, entry.path))
  183. .setEnabled(!entry.changeType.equals(ChangeType.ADD)));
  184. } else {
  185. // tree or blob
  186. item.add(new BookmarkablePageLink<Void>("diff", BlobDiffPage.class, WicketUtils
  187. .newPathParameter(repositoryName, entry.commitId, entry.path))
  188. .setEnabled(!entry.changeType.equals(ChangeType.ADD)
  189. && !entry.changeType.equals(ChangeType.DELETE)));
  190. item.add(new BookmarkablePageLink<Void>("view", BlobPage.class, WicketUtils
  191. .newPathParameter(repositoryName, entry.commitId, entry.path))
  192. .setEnabled(!entry.changeType.equals(ChangeType.DELETE)));
  193. item.add(new BookmarkablePageLink<Void>("blame", BlamePage.class, WicketUtils
  194. .newPathParameter(repositoryName, entry.commitId, entry.path))
  195. .setEnabled(!entry.changeType.equals(ChangeType.ADD)
  196. && !entry.changeType.equals(ChangeType.DELETE)));
  197. item.add(new BookmarkablePageLink<Void>("history", HistoryPage.class, WicketUtils
  198. .newPathParameter(repositoryName, entry.commitId, entry.path))
  199. .setEnabled(!entry.changeType.equals(ChangeType.ADD)));
  200. }
  201. WicketUtils.setAlternatingBackground(item, counter);
  202. counter++;
  203. }
  204. };
  205. add(pathsView);
  206. }
  207. @Override
  208. protected String getPageName() {
  209. return getString("gb.commit");
  210. }
  211. @Override
  212. protected Class<? extends BasePage> getRepoNavPageClass() {
  213. return LogPage.class;
  214. }
  215. }