| | |
| | | import java.text.MessageFormat;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Arrays;
|
| | | import java.util.HashMap;
|
| | | import java.util.LinkedHashMap;
|
| | | import java.util.LinkedHashSet;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.Set;
|
| | |
|
| | | import org.apache.wicket.Component;
|
| | | import org.apache.wicket.PageParameters;
|
| | |
| | | import org.apache.wicket.markup.html.panel.Fragment;
|
| | | import org.apache.wicket.model.IModel;
|
| | | import org.apache.wicket.model.Model;
|
| | | import org.apache.wicket.protocol.http.RequestUtils;
|
| | | import org.apache.wicket.request.target.basic.RedirectRequestTarget;
|
| | | import org.eclipse.jgit.diff.DiffEntry.ChangeType;
|
| | | import org.eclipse.jgit.lib.PersonIdent;
|
| | | import org.eclipse.jgit.lib.Repository;
|
| | |
| | | import com.gitblit.PagesServlet;
|
| | | import com.gitblit.SyndicationServlet;
|
| | | import com.gitblit.models.RepositoryModel;
|
| | | import com.gitblit.models.SubmoduleModel;
|
| | | import com.gitblit.utils.ArrayUtils;
|
| | | import com.gitblit.utils.JGitUtils;
|
| | | import com.gitblit.utils.StringUtils;
|
| | |
| | |
|
| | | public abstract class RepositoryPage extends BasePage {
|
| | |
|
| | | protected final String projectName;
|
| | | protected final String repositoryName;
|
| | | protected final String objectId;
|
| | |
|
| | | |
| | | private transient Repository r;
|
| | |
|
| | | private RepositoryModel m;
|
| | |
|
| | | private Map<String, SubmoduleModel> submodules;
|
| | | |
| | | private final Map<String, PageRegistration> registeredPages;
|
| | |
|
| | | public RepositoryPage(PageParameters params) {
|
| | | super(params);
|
| | | repositoryName = WicketUtils.getRepositoryName(params);
|
| | | if (repositoryName.indexOf('/') > -1) {
|
| | | projectName = repositoryName.substring(0, repositoryName.indexOf('/'));
|
| | | } else {
|
| | | projectName = GitBlit.getString(Keys.web.repositoryRootGroupName, "main");
|
| | | }
|
| | | objectId = WicketUtils.getObject(params);
|
| | |
|
| | | |
| | | if (StringUtils.isEmpty(repositoryName)) {
|
| | | error(MessageFormat.format("Repository not specified for {0}!", getPageName()), true);
|
| | | error(MessageFormat.format(getString("gb.repositoryNotSpecifiedFor"), getPageName()), true);
|
| | | }
|
| | |
|
| | | if (!getRepositoryModel().hasCommits) {
|
| | |
| | |
|
| | | // standard links
|
| | | pages.put("repositories", new PageRegistration("gb.repositories", RepositoriesPage.class));
|
| | | pages.put("project", new PageRegistration("gb.project", ProjectPage.class, WicketUtils.newProjectParameter(projectName)));
|
| | | pages.put("summary", new PageRegistration("gb.summary", SummaryPage.class, params));
|
| | | pages.put("log", new PageRegistration("gb.log", LogPage.class, params));
|
| | | pages.put("branches", new PageRegistration("gb.branches", BranchesPage.class, params));
|
| | |
| | | if (showAdmin
|
| | | || GitBlitWebSession.get().isLoggedIn()
|
| | | && (model.owner != null && model.owner.equalsIgnoreCase(GitBlitWebSession.get()
|
| | | .getUser().username))) {
|
| | | .getUsername()))) {
|
| | | pages.put("edit", new PageRegistration("gb.edit", EditRepositoryPage.class, params));
|
| | | }
|
| | | return pages;
|
| | |
| | | protected void setupPage(String repositoryName, String pageName) {
|
| | | add(new LinkPanel("repositoryName", null, StringUtils.stripDotGit(repositoryName),
|
| | | SummaryPage.class, WicketUtils.newRepositoryParameter(repositoryName)));
|
| | | add(new Label("pageName", pageName));
|
| | | add(new Label("pageName", pageName).setRenderBodyOnly(true));
|
| | | if (getRepositoryModel().isBare) {
|
| | | add(new Label("workingCopy").setVisible(false));
|
| | | } else {
|
| | |
| | | if (r == null) {
|
| | | Repository r = GitBlit.self().getRepository(repositoryName);
|
| | | if (r == null) {
|
| | | error("Can not load repository " + repositoryName, true);
|
| | | error(getString("gb.canNotLoadRepository") + " " + repositoryName, true);
|
| | | return null;
|
| | | }
|
| | | this.r = r;
|
| | |
| | | RepositoryModel model = GitBlit.self().getRepositoryModel(
|
| | | GitBlitWebSession.get().getUser(), repositoryName);
|
| | | if (model == null) {
|
| | | authenticationError("Unauthorized access for repository " + repositoryName);
|
| | | if (GitBlit.self().hasRepository(repositoryName)) {
|
| | | // has repository, but unauthorized
|
| | | authenticationError(getString("gb.unauthorizedAccessForRepository") + " " + repositoryName);
|
| | | } else {
|
| | | // does not have repository
|
| | | error(getString("gb.canNotLoadRepository") + " " + repositoryName, true);
|
| | | }
|
| | | return null;
|
| | | }
|
| | | m = model;
|
| | |
| | | protected RevCommit getCommit() {
|
| | | RevCommit commit = JGitUtils.getCommit(r, objectId);
|
| | | if (commit == null) {
|
| | | error(MessageFormat.format("Failed to find commit \"{0}\" in {1} for {2} page!",
|
| | | error(MessageFormat.format(getString("gb.failedToFindCommit"),
|
| | | objectId, repositoryName, getPageName()), true);
|
| | | }
|
| | | getSubmodules(commit);
|
| | | return commit;
|
| | | }
|
| | | |
| | | private Map<String, SubmoduleModel> getSubmodules(RevCommit commit) { |
| | | if (submodules == null) {
|
| | | submodules = new HashMap<String, SubmoduleModel>();
|
| | | for (SubmoduleModel model : JGitUtils.getSubmodules(r, commit.getTree())) {
|
| | | submodules.put(model.path, model);
|
| | | }
|
| | | }
|
| | | return submodules;
|
| | | }
|
| | | |
| | | protected Map<String, SubmoduleModel> getSubmodules() {
|
| | | return submodules;
|
| | | }
|
| | | |
| | | protected SubmoduleModel getSubmodule(String path) {
|
| | | SubmoduleModel model = submodules.get(path);
|
| | | if (model == null) {
|
| | | // undefined submodule?!
|
| | | model = new SubmoduleModel(path.substring(path.lastIndexOf('/') + 1), path, path);
|
| | | model.hasSubmodule = false;
|
| | | model.gitblitPath = model.name;
|
| | | return model;
|
| | | } else {
|
| | | // extract the repository name from the clone url
|
| | | List<String> patterns = GitBlit.getStrings(Keys.git.submoduleUrlPatterns);
|
| | | String submoduleName = StringUtils.extractRepositoryPath(model.url, patterns.toArray(new String[0]));
|
| | | |
| | | // determine the current path for constructing paths relative
|
| | | // to the current repository
|
| | | String currentPath = "";
|
| | | if (repositoryName.indexOf('/') > -1) {
|
| | | currentPath = repositoryName.substring(0, repositoryName.lastIndexOf('/') + 1);
|
| | | }
|
| | |
|
| | | // try to locate the submodule repository
|
| | | // prefer bare to non-bare names
|
| | | List<String> candidates = new ArrayList<String>();
|
| | |
|
| | | // relative
|
| | | candidates.add(currentPath + StringUtils.stripDotGit(submoduleName));
|
| | | candidates.add(candidates.get(candidates.size() - 1) + ".git");
|
| | |
|
| | | // relative, no subfolder
|
| | | if (submoduleName.lastIndexOf('/') > -1) {
|
| | | String name = submoduleName.substring(submoduleName.lastIndexOf('/') + 1);
|
| | | candidates.add(currentPath + StringUtils.stripDotGit(name));
|
| | | candidates.add(currentPath + candidates.get(candidates.size() - 1) + ".git");
|
| | | }
|
| | |
|
| | | // absolute
|
| | | candidates.add(StringUtils.stripDotGit(submoduleName));
|
| | | candidates.add(candidates.get(candidates.size() - 1) + ".git");
|
| | |
|
| | | // absolute, no subfolder
|
| | | if (submoduleName.lastIndexOf('/') > -1) {
|
| | | String name = submoduleName.substring(submoduleName.lastIndexOf('/') + 1);
|
| | | candidates.add(StringUtils.stripDotGit(name));
|
| | | candidates.add(candidates.get(candidates.size() - 1) + ".git");
|
| | | }
|
| | |
|
| | | // create a unique, ordered set of candidate paths
|
| | | Set<String> paths = new LinkedHashSet<String>(candidates);
|
| | | for (String candidate : paths) {
|
| | | if (GitBlit.self().hasRepository(candidate)) {
|
| | | model.hasSubmodule = true;
|
| | | model.gitblitPath = candidate;
|
| | | return model;
|
| | | }
|
| | | }
|
| | | |
| | | // we do not have a copy of the submodule, but we need a path
|
| | | model.gitblitPath = candidates.get(0);
|
| | | return model;
|
| | | } |
| | | }
|
| | |
|
| | | protected String getShortObjectId(String objectId) {
|
| | |
| | | }
|
| | |
|
| | | protected void addFullText(String wicketId, String text, boolean substituteRegex) {
|
| | | String html;
|
| | | String html = StringUtils.escapeForHtml(text, true);
|
| | | if (substituteRegex) {
|
| | | html = GitBlit.self().processCommitMessage(repositoryName, text);
|
| | | } else {
|
| | | html = StringUtils.breakLinesForHtml(text);
|
| | | html = StringUtils.breakLinesForHtml(html);
|
| | | }
|
| | | add(new Label(wicketId, html).setEscapeModelStrings(false));
|
| | | }
|
| | |
| | | setPersonSearchTooltip(nameLink, name, searchType);
|
| | | fullPerson.add(nameLink);
|
| | |
|
| | | LinkPanel addressLink = new LinkPanel("personAddress", "list", "<" + address + ">",
|
| | | LinkPanel addressLink = new LinkPanel("personAddress", "hidden-phone list", "<" + address + ">",
|
| | | GitSearchPage.class, WicketUtils.newSearchParameter(repositoryName, objectId,
|
| | | address, searchType));
|
| | | setPersonSearchTooltip(addressLink, address, searchType);
|
| | |
| | | Constants.SearchType searchType = searchTypeModel.getObject();
|
| | | String searchString = searchBoxModel.getObject();
|
| | | if (searchString == null) {
|
| | | // FIXME IE intermittently has no searchString. Wicket bug?
|
| | | return;
|
| | | }
|
| | | for (Constants.SearchType type : Constants.SearchType.values()) {
|
| | |
| | | }
|
| | | Class<? extends BasePage> searchPageClass = GitSearchPage.class;
|
| | | RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);
|
| | | if (!ArrayUtils.isEmpty(model.indexedBranches)) {
|
| | | if (GitBlit.getBoolean(Keys.web.allowLuceneIndexing, true)
|
| | | && !ArrayUtils.isEmpty(model.indexedBranches)) {
|
| | | // this repository is Lucene-indexed
|
| | | searchPageClass = LuceneSearchPage.class;
|
| | | }
|
| | | setResponsePage(searchPageClass,
|
| | | WicketUtils.newSearchParameter(repositoryName, null, searchString, searchType));
|
| | | // use an absolute url to workaround Wicket-Tomcat problems with
|
| | | // mounted url parameters (issue-111)
|
| | | PageParameters params = WicketUtils.newSearchParameter(repositoryName, null, searchString, searchType);
|
| | | String relativeUrl = urlFor(searchPageClass, params).toString();
|
| | | String absoluteUrl = RequestUtils.toAbsolutePath(relativeUrl);
|
| | | getRequestCycle().setRequestTarget(new RedirectRequestTarget(absoluteUrl));
|
| | | }
|
| | | }
|
| | | }
|