Bret K. Ikehara
2013-08-04 cd9461c0c05958444d1313b794be57df39d98956
src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java
@@ -15,7 +15,6 @@
 */
package com.gitblit.wicket.pages;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
@@ -37,11 +36,14 @@
import com.gitblit.utils.DiffUtils;
import com.gitblit.utils.DiffUtils.DiffOutputType;
import com.gitblit.utils.JGitUtils;
import com.gitblit.wicket.CacheControl;
import com.gitblit.wicket.CacheControl.LastModified;
import com.gitblit.wicket.WicketUtils;
import com.gitblit.wicket.panels.CommitHeaderPanel;
import com.gitblit.wicket.panels.CommitLegendPanel;
import com.gitblit.wicket.panels.LinkPanel;
@CacheControl(LastModified.BOOT)
public class CommitDiffPage extends RepositoryPage {
   public CommitDiffPage(PageParameters params) {
@@ -52,29 +54,9 @@
      DiffOutputType diffType = DiffOutputType.forName(GitBlit.getString(Keys.web.diffStyle,
            DiffOutputType.GITBLIT.name()));
      RevCommit commit = null, otherCommit = null;
      RevCommit commit = getCommit();
      if( objectId.contains("..") )
      {
         String[] parts = objectId.split("\\.\\.");
         commit = getCommit(r, parts[0]);
         otherCommit = getCommit(r, parts[1]);
      }
      else
      {
         commit = getCommit();
      }
      String diff;
      if(otherCommit == null)
      {
         diff = DiffUtils.getCommitDiff(r, commit, diffType);
      }
      else
      {
         diff = DiffUtils.getDiff(r, commit, otherCommit, diffType);
      }
      String diff = DiffUtils.getCommitDiff(r, commit, diffType);
      List<String> parents = new ArrayList<String>();
      if (commit.getParentCount() > 0) {
@@ -97,17 +79,10 @@
      add(new CommitHeaderPanel("commitHeader", repositoryName, commit));
      // changed paths list
      List<PathChangeModel> paths;
      addFullText("fullMessage", commit.getFullMessage());
      if( otherCommit == null )
      {
         paths = JGitUtils.getFilesInCommit(r, commit);
      }
      else
      {
         paths = JGitUtils.getFilesInCommit(r, otherCommit);
      }
      // changed paths list
      List<PathChangeModel> paths = JGitUtils.getFilesInCommit(r, commit);
      add(new CommitLegendPanel("commitLegend", paths));
      ListDataProvider<PathChangeModel> pathsDp = new ListDataProvider<PathChangeModel>(paths);
@@ -151,19 +126,26 @@
                     .newObjectParameter(submodulePath, entry.objectId)).setEnabled(hasSubmodule));
               item.add(new ExternalLink("blame", "").setEnabled(false));
               item.add(new BookmarkablePageLink<Void>("history", HistoryPage.class, WicketUtils
                     .newPathParameter(repositoryName, entry.commitId, entry.path)));
                     .newPathParameter(repositoryName, entry.commitId, entry.path))
                     .setEnabled(!entry.changeType.equals(ChangeType.ADD)));
            } else {
               // tree or blob
               item.add(new BookmarkablePageLink<Void>("patch", PatchPage.class, WicketUtils
                     .newPathParameter(repositoryName, entry.commitId, entry.path)));
                     .newPathParameter(repositoryName, entry.commitId, entry.path))
                     .setEnabled(!entry.changeType.equals(ChangeType.ADD)
                           && !entry.changeType.equals(ChangeType.DELETE)));
               item.add(new BookmarkablePageLink<Void>("view", BlobPage.class, WicketUtils
                     .newPathParameter(repositoryName, entry.commitId, entry.path)));
                     .newPathParameter(repositoryName, entry.commitId, entry.path))
                     .setEnabled(!entry.changeType.equals(ChangeType.DELETE)));
               item.add(new BookmarkablePageLink<Void>("blame", BlamePage.class, WicketUtils
                     .newPathParameter(repositoryName, entry.commitId, entry.path)));
                     .newPathParameter(repositoryName, entry.commitId, entry.path))
                     .setEnabled(!entry.changeType.equals(ChangeType.ADD)
                           && !entry.changeType.equals(ChangeType.DELETE)));
               item.add(new BookmarkablePageLink<Void>("history", HistoryPage.class, WicketUtils
                     .newPathParameter(repositoryName, entry.commitId, entry.path))
                     .setEnabled(!entry.changeType.equals(ChangeType.ADD)));
            }
            WicketUtils.setAlternatingBackground(item, counter);
            counter++;
         }
@@ -180,14 +162,5 @@
   @Override
   protected Class<? extends BasePage> getRepoNavPageClass() {
      return LogPage.class;
   }
   private RevCommit getCommit(Repository r, String rev)
   {
      RevCommit otherCommit = JGitUtils.getCommit(r, rev);
      if (otherCommit == null) {
         error(MessageFormat.format(getString("gb.failedToFindCommit"), rev, repositoryName, getPageName()), true);
      }
      return otherCommit;
   }
}