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 |
*/
|
5fe7df
|
16 |
package com.gitblit.wicket.pages;
|
JM |
17 |
|
|
18 |
import java.util.List;
|
|
19 |
|
|
20 |
import org.apache.wicket.PageParameters;
|
|
21 |
import org.apache.wicket.markup.html.basic.Label;
|
1a3fc5
|
22 |
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
|
ff17f7
|
23 |
import org.apache.wicket.markup.html.link.ExternalLink;
|
1a3fc5
|
24 |
import org.apache.wicket.markup.html.panel.Fragment;
|
5fe7df
|
25 |
import org.apache.wicket.markup.repeater.Item;
|
JM |
26 |
import org.apache.wicket.markup.repeater.data.DataView;
|
|
27 |
import org.apache.wicket.markup.repeater.data.ListDataProvider;
|
f08c1c
|
28 |
import org.eclipse.jgit.lib.FileMode;
|
5fe7df
|
29 |
import org.eclipse.jgit.lib.Repository;
|
JM |
30 |
import org.eclipse.jgit.revwalk.RevCommit;
|
|
31 |
|
1f9dae
|
32 |
import com.gitblit.models.PathModel;
|
eb870f
|
33 |
import com.gitblit.models.SubmoduleModel;
|
ff17f7
|
34 |
import com.gitblit.servlet.RawServlet;
|
5fe7df
|
35 |
import com.gitblit.utils.ByteFormat;
|
JM |
36 |
import com.gitblit.utils.JGitUtils;
|
a7db57
|
37 |
import com.gitblit.wicket.CacheControl;
|
JM |
38 |
import com.gitblit.wicket.CacheControl.LastModified;
|
5fe7df
|
39 |
import com.gitblit.wicket.WicketUtils;
|
c1c3c6
|
40 |
import com.gitblit.wicket.panels.CommitHeaderPanel;
|
59b817
|
41 |
import com.gitblit.wicket.panels.CompressedDownloadsPanel;
|
1f9dae
|
42 |
import com.gitblit.wicket.panels.LinkPanel;
|
5fe7df
|
43 |
import com.gitblit.wicket.panels.PathBreadcrumbsPanel;
|
JM |
44 |
|
a7db57
|
45 |
@CacheControl(LastModified.BOOT)
|
5fe7df
|
46 |
public class TreePage extends RepositoryPage {
|
JM |
47 |
|
|
48 |
public TreePage(PageParameters params) {
|
cebf45
|
49 |
super(params);
|
5fe7df
|
50 |
|
f602a2
|
51 |
final String path = WicketUtils.getPath(params);
|
5fe7df
|
52 |
|
JM |
53 |
Repository r = getRepository();
|
bc9d4a
|
54 |
RevCommit commit = getCommit();
|
a9a2ff
|
55 |
List<PathModel> paths = JGitUtils.getFilesInPath2(r, path, commit);
|
5fe7df
|
56 |
|
JM |
57 |
// tree page links
|
2a7306
|
58 |
add(new BookmarkablePageLink<Void>("historyLink", HistoryPage.class,
|
JM |
59 |
WicketUtils.newPathParameter(repositoryName, objectId, path)));
|
59b817
|
60 |
add(new CompressedDownloadsPanel("compressedLinks", getRequest()
|
JM |
61 |
.getRelativePathPrefixToContextRoot(), repositoryName, objectId, path));
|
608ece
|
62 |
|
c1c3c6
|
63 |
add(new CommitHeaderPanel("commitHeader", repositoryName, commit));
|
5fe7df
|
64 |
|
JM |
65 |
// breadcrumbs
|
f602a2
|
66 |
add(new PathBreadcrumbsPanel("breadcrumbs", repositoryName, path, objectId));
|
JM |
67 |
if (path != null && path.trim().length() > 0) {
|
28d6b2
|
68 |
// add .. parent path entry
|
JM |
69 |
String parentPath = null;
|
|
70 |
if (path.lastIndexOf('/') > -1) {
|
|
71 |
parentPath = path.substring(0, path.lastIndexOf('/'));
|
|
72 |
}
|
46f33f
|
73 |
PathModel model = new PathModel("..", parentPath, null, 0, FileMode.TREE.getBits(), null, objectId);
|
28d6b2
|
74 |
model.isParentPath = true;
|
JM |
75 |
paths.add(0, model);
|
5fe7df
|
76 |
}
|
JM |
77 |
|
ab1e11
|
78 |
final String id = getBestCommitId(commit);
|
46f33f
|
79 |
|
5fe7df
|
80 |
final ByteFormat byteFormat = new ByteFormat();
|
2179fb
|
81 |
final String baseUrl = WicketUtils.getGitblitURL(getRequest());
|
JM |
82 |
|
155bf7
|
83 |
// changed paths list
|
5fe7df
|
84 |
ListDataProvider<PathModel> pathsDp = new ListDataProvider<PathModel>(paths);
|
JM |
85 |
DataView<PathModel> pathsView = new DataView<PathModel>("changedPath", pathsDp) {
|
|
86 |
private static final long serialVersionUID = 1L;
|
2a7306
|
87 |
int counter;
|
5fe7df
|
88 |
|
699e71
|
89 |
@Override
|
5fe7df
|
90 |
public void populateItem(final Item<PathModel> item) {
|
JM |
91 |
PathModel entry = item.getModelObject();
|
46f33f
|
92 |
|
5fe7df
|
93 |
item.add(new Label("pathPermissions", JGitUtils.getPermissionsFromMode(entry.mode)));
|
46f33f
|
94 |
|
5fe7df
|
95 |
if (entry.isParentPath) {
|
JM |
96 |
// parent .. path
|
1e8390
|
97 |
item.add(WicketUtils.newBlankImage("pathIcon"));
|
fc8426
|
98 |
item.add(new Label("pathSize", ""));
|
2a7306
|
99 |
item.add(new LinkPanel("pathName", null, entry.name, TreePage.class,
|
a2709d
|
100 |
WicketUtils
|
ab1e11
|
101 |
.newPathParameter(repositoryName, id, entry.path)));
|
46f33f
|
102 |
item.add(new Label("filestore", getString("gb.filestore")).setVisible(false));
|
1a3fc5
|
103 |
item.add(new Label("pathLinks", ""));
|
5fe7df
|
104 |
} else {
|
JM |
105 |
if (entry.isTree()) {
|
|
106 |
// folder/tree link
|
1e8390
|
107 |
item.add(WicketUtils.newImage("pathIcon", "folder_16x16.png"));
|
fc8426
|
108 |
item.add(new Label("pathSize", ""));
|
2a7306
|
109 |
item.add(new LinkPanel("pathName", "list", entry.name, TreePage.class,
|
ab1e11
|
110 |
WicketUtils.newPathParameter(repositoryName, id,
|
a2709d
|
111 |
entry.path)));
|
46f33f
|
112 |
|
PM |
113 |
item.add(new Label("filestore", getString("gb.filestore")).setVisible(false));
|
155bf7
|
114 |
|
1a3fc5
|
115 |
// links
|
JM |
116 |
Fragment links = new Fragment("pathLinks", "treeLinks", this);
|
2a7306
|
117 |
links.add(new BookmarkablePageLink<Void>("tree", TreePage.class,
|
ab1e11
|
118 |
WicketUtils.newPathParameter(repositoryName, id,
|
2a7306
|
119 |
entry.path)));
|
JM |
120 |
links.add(new BookmarkablePageLink<Void>("history", HistoryPage.class,
|
ab1e11
|
121 |
WicketUtils.newPathParameter(repositoryName, id,
|
699e71
|
122 |
entry.path)));
|
59b817
|
123 |
links.add(new CompressedDownloadsPanel("compressedLinks", baseUrl,
|
JM |
124 |
repositoryName, objectId, entry.path));
|
|
125 |
|
1a3fc5
|
126 |
item.add(links);
|
eb870f
|
127 |
} else if (entry.isSubmodule()) {
|
JM |
128 |
// submodule
|
699e71
|
129 |
String submoduleId = entry.objectId;
|
eb870f
|
130 |
String submodulePath;
|
JM |
131 |
boolean hasSubmodule = false;
|
|
132 |
SubmoduleModel submodule = getSubmodule(entry.path);
|
|
133 |
submodulePath = submodule.gitblitPath;
|
|
134 |
hasSubmodule = submodule.hasSubmodule;
|
699e71
|
135 |
|
eb870f
|
136 |
item.add(WicketUtils.newImage("pathIcon", "git-orange-16x16.png"));
|
JM |
137 |
item.add(new Label("pathSize", ""));
|
699e71
|
138 |
item.add(new LinkPanel("pathName", "list", entry.name + " @ " +
|
eb870f
|
139 |
getShortObjectId(submoduleId), TreePage.class,
|
JM |
140 |
WicketUtils.newPathParameter(submodulePath, submoduleId, "")).setEnabled(hasSubmodule));
|
699e71
|
141 |
|
46f33f
|
142 |
item.add(new Label("filestore", getString("gb.filestore")).setVisible(false));
|
PM |
143 |
|
eb870f
|
144 |
Fragment links = new Fragment("pathLinks", "submoduleLinks", this);
|
JM |
145 |
links.add(new BookmarkablePageLink<Void>("view", SummaryPage.class,
|
|
146 |
WicketUtils.newRepositoryParameter(submodulePath)).setEnabled(hasSubmodule));
|
|
147 |
links.add(new BookmarkablePageLink<Void>("tree", TreePage.class,
|
|
148 |
WicketUtils.newPathParameter(submodulePath, submoduleId,
|
|
149 |
"")).setEnabled(hasSubmodule));
|
|
150 |
links.add(new BookmarkablePageLink<Void>("history", HistoryPage.class,
|
ab1e11
|
151 |
WicketUtils.newPathParameter(repositoryName, id,
|
9cc56a
|
152 |
entry.path)));
|
59b817
|
153 |
links.add(new CompressedDownloadsPanel("compressedLinks", baseUrl,
|
JM |
154 |
submodulePath, submoduleId, "").setEnabled(hasSubmodule));
|
699e71
|
155 |
item.add(links);
|
5fe7df
|
156 |
} else {
|
JM |
157 |
// blob link
|
7670a0
|
158 |
String displayPath = entry.name;
|
e5662e
|
159 |
String path = entry.path;
|
JM |
160 |
if (entry.isSymlink()) {
|
|
161 |
path = JGitUtils.getStringContent(getRepository(), getCommit().getTree(), path);
|
7670a0
|
162 |
displayPath = entry.name + " -> " + path;
|
e5662e
|
163 |
}
|
c1c3c6
|
164 |
item.add(WicketUtils.getFileImage("pathIcon", entry.name));
|
5fe7df
|
165 |
item.add(new Label("pathSize", byteFormat.format(entry.size)));
|
46f33f
|
166 |
|
1a3fc5
|
167 |
// links
|
JM |
168 |
Fragment links = new Fragment("pathLinks", "blobLinks", this);
|
46f33f
|
169 |
|
PM |
170 |
if (entry.isFilestoreItem()) {
|
|
171 |
item.add(new Label("filestore", getString("gb.filestore")).setVisible(true));
|
|
172 |
|
|
173 |
final String filestoreItemUrl = JGitUtils.getLfsRepositoryUrl(getContextUrl(), repositoryName, entry.getFilestoreOid());
|
|
174 |
|
|
175 |
item.add(new LinkPanel("pathName", "list", displayPath, filestoreItemUrl));
|
|
176 |
links.add(new ExternalLink("view", filestoreItemUrl));
|
|
177 |
links.add(new ExternalLink("raw", filestoreItemUrl));
|
|
178 |
|
|
179 |
} else {
|
|
180 |
item.add(new Label("filestore", getString("gb.filestore")).setVisible(false));
|
|
181 |
|
|
182 |
item.add(new LinkPanel("pathName", "list", displayPath, BlobPage.class,
|
|
183 |
WicketUtils.newPathParameter(repositoryName, id,
|
|
184 |
path)));
|
|
185 |
|
|
186 |
links.add(new BookmarkablePageLink<Void>("view", BlobPage.class,
|
|
187 |
WicketUtils.newPathParameter(repositoryName, id,
|
|
188 |
path)));
|
|
189 |
String rawUrl = RawServlet.asLink(getContextUrl(), repositoryName, id, path);
|
|
190 |
links.add(new ExternalLink("raw", rawUrl));
|
|
191 |
}
|
|
192 |
|
716745
|
193 |
links.add(new BookmarkablePageLink<Void>("blame", BlamePage.class,
|
ab1e11
|
194 |
WicketUtils.newPathParameter(repositoryName, id,
|
e5662e
|
195 |
path)));
|
2a7306
|
196 |
links.add(new BookmarkablePageLink<Void>("history", HistoryPage.class,
|
ab1e11
|
197 |
WicketUtils.newPathParameter(repositoryName, id,
|
e5662e
|
198 |
path)));
|
1a3fc5
|
199 |
item.add(links);
|
5fe7df
|
200 |
}
|
JM |
201 |
}
|
1a3fc5
|
202 |
WicketUtils.setAlternatingBackground(item, counter);
|
5fe7df
|
203 |
counter++;
|
JM |
204 |
}
|
|
205 |
};
|
|
206 |
add(pathsView);
|
|
207 |
}
|
155bf7
|
208 |
|
cebf45
|
209 |
@Override
|
JM |
210 |
protected String getPageName() {
|
1e47ab
|
211 |
return getString("gb.tree");
|
cebf45
|
212 |
}
|
5d5e55
|
213 |
|
JM |
214 |
@Override
|
|
215 |
protected boolean isCommitPage() {
|
|
216 |
return true;
|
|
217 |
}
|
|
218 |
|
5fe7df
|
219 |
}
|