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.

BlobDiffPage.java 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 org.apache.wicket.PageParameters;
  18. import org.apache.wicket.markup.html.basic.Label;
  19. import org.apache.wicket.markup.html.link.BookmarkablePageLink;
  20. import org.eclipse.jgit.lib.Repository;
  21. import org.eclipse.jgit.revwalk.RevCommit;
  22. import com.gitblit.GitBlit;
  23. import com.gitblit.Keys;
  24. import com.gitblit.utils.JGitUtils;
  25. import com.gitblit.utils.JGitUtils.DiffOutputType;
  26. import com.gitblit.utils.StringUtils;
  27. import com.gitblit.wicket.RepositoryPage;
  28. import com.gitblit.wicket.WicketUtils;
  29. import com.gitblit.wicket.panels.CommitHeaderPanel;
  30. import com.gitblit.wicket.panels.PathBreadcrumbsPanel;
  31. public class BlobDiffPage extends RepositoryPage {
  32. public BlobDiffPage(PageParameters params) {
  33. super(params);
  34. final String blobPath = WicketUtils.getPath(params);
  35. final String baseObjectId = WicketUtils.getBaseObjectId(params);
  36. Repository r = getRepository();
  37. RevCommit commit = getCommit();
  38. DiffOutputType diffType = DiffOutputType.forName(GitBlit.self().settings().getString(Keys.web.diffStyle, DiffOutputType.GITBLIT.name()));
  39. String diff;
  40. if (StringUtils.isEmpty(baseObjectId)) {
  41. // use first parent
  42. diff = JGitUtils.getCommitDiff(r, commit, blobPath, diffType);
  43. add(new BookmarkablePageLink<Void>("patchLink", PatchPage.class, WicketUtils.newPathParameter(repositoryName, objectId, blobPath)));
  44. } else {
  45. // base commit specified
  46. RevCommit baseCommit = JGitUtils.getCommit(r, baseObjectId);
  47. diff = JGitUtils.getCommitDiff(r, baseCommit, commit, blobPath, diffType);
  48. add(new BookmarkablePageLink<Void>("patchLink", PatchPage.class, WicketUtils.newBlobDiffParameter(repositoryName, baseObjectId, objectId, blobPath)));
  49. }
  50. add(new BookmarkablePageLink<Void>("commitLink", CommitPage.class, WicketUtils.newObjectParameter(repositoryName, objectId)));
  51. add(new BookmarkablePageLink<Void>("commitDiffLink", CommitDiffPage.class, WicketUtils.newObjectParameter(repositoryName, objectId)));
  52. // diff page links
  53. add(new Label("blameLink", getString("gb.blame")));
  54. add(new BookmarkablePageLink<Void>("historyLink", HistoryPage.class, WicketUtils.newPathParameter(repositoryName, objectId, blobPath)));
  55. add(new CommitHeaderPanel("commitHeader", repositoryName, commit));
  56. add(new PathBreadcrumbsPanel("breadcrumbs", repositoryName, blobPath, objectId));
  57. add(new Label("diffText", diff).setEscapeModelStrings(false));
  58. }
  59. @Override
  60. protected String getPageName() {
  61. return getString("gb.diff");
  62. }
  63. }