James Moger
2012-09-18 2d58e62108b6c749607fae10419cc510c55f6088
Merge pull request #37 from ajermakovics/master

View a diff between two branches
1 files modified
50 ■■■■■ changed files
src/com/gitblit/wicket/pages/CommitDiffPage.java 50 ●●●●● patch | view | raw | blame | history
src/com/gitblit/wicket/pages/CommitDiffPage.java
@@ -18,6 +18,8 @@
import java.util.ArrayList;
import java.util.List;
import java.text.MessageFormat;
import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
@@ -46,10 +48,33 @@
        super(params);
        Repository r = getRepository();
        RevCommit commit = getCommit();
        DiffOutputType diffType = DiffOutputType.forName(GitBlit.getString(Keys.web.diffStyle,
                DiffOutputType.GITBLIT.name()));
        String diff = DiffUtils.getCommitDiff(r, commit, diffType);
        RevCommit commit = null, otherCommit = null;
        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);
        }
        List<String> parents = new ArrayList<String>();
        if (commit.getParentCount() > 0) {
@@ -73,7 +98,17 @@
        add(new CommitHeaderPanel("commitHeader", repositoryName, commit));
        // changed paths list
        List<PathChangeModel> paths = JGitUtils.getFilesInCommit(r, commit);
        List<PathChangeModel> paths;
        if( otherCommit == null )
        {
            paths = JGitUtils.getFilesInCommit(r, commit);
        }
        else
        {
            paths = JGitUtils.getFilesInCommit(r, otherCommit);
        }
        add(new CommitLegendPanel("commitLegend", paths));
        ListDataProvider<PathChangeModel> pathsDp = new ListDataProvider<PathChangeModel>(paths);
        DataView<PathChangeModel> pathsView = new DataView<PathChangeModel>("changedPath", pathsDp) {
@@ -148,4 +183,13 @@
    protected String getPageName() {
        return getString("gb.commitdiff");
    }
    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;
    }
}