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 |
|
|
18 |
import org.apache.wicket.PageParameters;
|
|
19 |
import org.apache.wicket.markup.html.WebPage;
|
|
20 |
import org.apache.wicket.markup.html.basic.Label;
|
|
21 |
import org.eclipse.jgit.lib.Repository;
|
|
22 |
import org.eclipse.jgit.revwalk.RevCommit;
|
|
23 |
|
fc948c
|
24 |
import com.gitblit.GitBlit;
|
1f9dae
|
25 |
import com.gitblit.utils.DiffUtils;
|
608ece
|
26 |
import com.gitblit.utils.JGitUtils;
|
ce119a
|
27 |
import com.gitblit.utils.StringUtils;
|
bc9d4a
|
28 |
import com.gitblit.wicket.GitBlitWebSession;
|
608ece
|
29 |
import com.gitblit.wicket.WicketUtils;
|
JM |
30 |
|
|
31 |
public class PatchPage extends WebPage {
|
|
32 |
|
|
33 |
public PatchPage(PageParameters params) {
|
|
34 |
super(params);
|
|
35 |
|
|
36 |
if (!params.containsKey("r")) {
|
6caa93
|
37 |
GitBlitWebSession.get().cacheErrorMessage(getString("gb.repositoryNotSpecified"));
|
608ece
|
38 |
redirectToInterceptPage(new RepositoriesPage());
|
bc9d4a
|
39 |
return;
|
608ece
|
40 |
}
|
2a7306
|
41 |
|
608ece
|
42 |
final String repositoryName = WicketUtils.getRepositoryName(params);
|
ce119a
|
43 |
final String baseObjectId = WicketUtils.getBaseObjectId(params);
|
155bf7
|
44 |
final String objectId = WicketUtils.getObject(params);
|
608ece
|
45 |
final String blobPath = WicketUtils.getPath(params);
|
JM |
46 |
|
f5d0ad
|
47 |
Repository r = GitBlit.self().getRepository(repositoryName);
|
608ece
|
48 |
if (r == null) {
|
6caa93
|
49 |
GitBlitWebSession.get().cacheErrorMessage(getString("gb.canNotLoadRepository") + " " + repositoryName);
|
608ece
|
50 |
redirectToInterceptPage(new RepositoriesPage());
|
JM |
51 |
return;
|
|
52 |
}
|
|
53 |
|
|
54 |
RevCommit commit = JGitUtils.getCommit(r, objectId);
|
bc9d4a
|
55 |
if (commit == null) {
|
6caa93
|
56 |
GitBlitWebSession.get().cacheErrorMessage(getString("gb.commitIsNull"));
|
bc9d4a
|
57 |
redirectToInterceptPage(new RepositoriesPage());
|
JM |
58 |
return;
|
|
59 |
}
|
2a7306
|
60 |
|
JM |
61 |
RevCommit baseCommit = null;
|
|
62 |
if (!StringUtils.isEmpty(baseObjectId)) {
|
|
63 |
baseCommit = JGitUtils.getCommit(r, baseObjectId);
|
ce119a
|
64 |
}
|
1f9dae
|
65 |
String patch = DiffUtils.getCommitPatch(r, baseCommit, commit, blobPath);
|
608ece
|
66 |
add(new Label("patchText", patch));
|
JM |
67 |
r.close();
|
155bf7
|
68 |
}
|
608ece
|
69 |
}
|