commit | author | age
|
f13c4c
|
1 |
/*
|
JM |
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 |
*/
|
608ece
|
16 |
package com.gitblit.wicket.pages;
|
JM |
17 |
|
7dd99f
|
18 |
import java.util.List;
|
T |
19 |
|
608ece
|
20 |
import org.apache.wicket.PageParameters;
|
JM |
21 |
import org.apache.wicket.markup.html.basic.Label;
|
|
22 |
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
|
|
23 |
import org.eclipse.jgit.lib.Repository;
|
|
24 |
import org.eclipse.jgit.revwalk.RevCommit;
|
|
25 |
|
7dd99f
|
26 |
import com.gitblit.Keys;
|
1f9dae
|
27 |
import com.gitblit.utils.DiffUtils;
|
cff352
|
28 |
import com.gitblit.utils.DiffUtils.DiffComparator;
|
a125cf
|
29 |
import com.gitblit.utils.DiffUtils.DiffOutputType;
|
608ece
|
30 |
import com.gitblit.utils.JGitUtils;
|
f5d0ad
|
31 |
import com.gitblit.utils.StringUtils;
|
a7db57
|
32 |
import com.gitblit.wicket.CacheControl;
|
JM |
33 |
import com.gitblit.wicket.CacheControl.LastModified;
|
608ece
|
34 |
import com.gitblit.wicket.WicketUtils;
|
c1c3c6
|
35 |
import com.gitblit.wicket.panels.CommitHeaderPanel;
|
5d59b9
|
36 |
import com.gitblit.wicket.panels.LinkPanel;
|
608ece
|
37 |
import com.gitblit.wicket.panels.PathBreadcrumbsPanel;
|
JM |
38 |
|
a7db57
|
39 |
@CacheControl(LastModified.BOOT)
|
608ece
|
40 |
public class BlobDiffPage extends RepositoryPage {
|
JM |
41 |
|
|
42 |
public BlobDiffPage(PageParameters params) {
|
|
43 |
super(params);
|
|
44 |
|
|
45 |
final String blobPath = WicketUtils.getPath(params);
|
f1dfc2
|
46 |
final String baseObjectId = WicketUtils.getBaseObjectId(params);
|
dd661a
|
47 |
final DiffComparator diffComparator = WicketUtils.getDiffComparator(params);
|
608ece
|
48 |
|
JM |
49 |
Repository r = getRepository();
|
bc9d4a
|
50 |
RevCommit commit = getCommit();
|
2a7306
|
51 |
|
7dd99f
|
52 |
final List<String> imageExtensions = app().settings().getStrings(Keys.web.imageExtensions);
|
T |
53 |
|
f1dfc2
|
54 |
String diff;
|
JM |
55 |
if (StringUtils.isEmpty(baseObjectId)) {
|
|
56 |
// use first parent
|
7dd99f
|
57 |
RevCommit parent = commit.getParentCount() == 0 ? null : commit.getParent(0);
|
b6f475
|
58 |
ImageDiffHandler handler = new ImageDiffHandler(this, repositoryName,
|
7dd99f
|
59 |
parent.getName(), commit.getName(), imageExtensions);
|
310a80
|
60 |
diff = DiffUtils.getDiff(r, commit, blobPath, diffComparator, DiffOutputType.HTML, handler, 3).content;
|
3e1336
|
61 |
if (handler.getImgDiffCount() > 0) {
|
T |
62 |
addBottomScript("scripts/imgdiff.js"); // Tiny support script for image diffs
|
|
63 |
}
|
2a7306
|
64 |
add(new BookmarkablePageLink<Void>("patchLink", PatchPage.class,
|
JM |
65 |
WicketUtils.newPathParameter(repositoryName, objectId, blobPath)));
|
f1dfc2
|
66 |
} else {
|
JM |
67 |
// base commit specified
|
|
68 |
RevCommit baseCommit = JGitUtils.getCommit(r, baseObjectId);
|
b6f475
|
69 |
ImageDiffHandler handler = new ImageDiffHandler(this, repositoryName,
|
7dd99f
|
70 |
baseCommit.getName(), commit.getName(), imageExtensions);
|
310a80
|
71 |
diff = DiffUtils.getDiff(r, baseCommit, commit, blobPath, diffComparator, DiffOutputType.HTML, handler, 3).content;
|
3e1336
|
72 |
if (handler.getImgDiffCount() > 0) {
|
T |
73 |
addBottomScript("scripts/imgdiff.js"); // Tiny support script for image diffs
|
|
74 |
}
|
2a7306
|
75 |
add(new BookmarkablePageLink<Void>("patchLink", PatchPage.class,
|
JM |
76 |
WicketUtils.newBlobDiffParameter(repositoryName, baseObjectId, objectId,
|
|
77 |
blobPath)));
|
f1dfc2
|
78 |
}
|
2a7306
|
79 |
|
JM |
80 |
add(new BookmarkablePageLink<Void>("commitLink", CommitPage.class,
|
|
81 |
WicketUtils.newObjectParameter(repositoryName, objectId)));
|
|
82 |
add(new BookmarkablePageLink<Void>("commitDiffLink", CommitDiffPage.class,
|
|
83 |
WicketUtils.newObjectParameter(repositoryName, objectId)));
|
5d59b9
|
84 |
add(new LinkPanel("whitespaceLink", null, getString(diffComparator.getOpposite().getTranslationKey()),
|
JM |
85 |
BlobDiffPage.class, WicketUtils.newDiffParameter(repositoryName, objectId, diffComparator.getOpposite(), blobPath)));
|
608ece
|
86 |
|
JM |
87 |
// diff page links
|
716745
|
88 |
add(new BookmarkablePageLink<Void>("blameLink", BlamePage.class,
|
JM |
89 |
WicketUtils.newPathParameter(repositoryName, objectId, blobPath)));
|
2a7306
|
90 |
add(new BookmarkablePageLink<Void>("historyLink", HistoryPage.class,
|
JM |
91 |
WicketUtils.newPathParameter(repositoryName, objectId, blobPath)));
|
608ece
|
92 |
|
c1c3c6
|
93 |
add(new CommitHeaderPanel("commitHeader", repositoryName, commit));
|
608ece
|
94 |
|
JM |
95 |
add(new PathBreadcrumbsPanel("breadcrumbs", repositoryName, blobPath, objectId));
|
155bf7
|
96 |
|
608ece
|
97 |
add(new Label("diffText", diff).setEscapeModelStrings(false));
|
JM |
98 |
}
|
155bf7
|
99 |
|
608ece
|
100 |
@Override
|
JM |
101 |
protected String getPageName() {
|
|
102 |
return getString("gb.diff");
|
|
103 |
}
|
699e71
|
104 |
|
6ef8d7
|
105 |
@Override
|
5d5e55
|
106 |
protected boolean isCommitPage() {
|
JM |
107 |
return true;
|
|
108 |
}
|
|
109 |
|
|
110 |
@Override
|
6ef8d7
|
111 |
protected Class<? extends BasePage> getRepoNavPageClass() {
|
JM |
112 |
return TreePage.class;
|
|
113 |
}
|
608ece
|
114 |
}
|