| | |
| | | import java.text.MessageFormat;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Arrays;
|
| | | import java.util.Date;
|
| | | import java.util.HashMap;
|
| | | import java.util.LinkedHashMap;
|
| | | import java.util.LinkedHashSet;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
| | |
|
| | | import org.apache.wicket.Component;
|
| | | import org.apache.wicket.PageParameters;
|
| | | import org.apache.wicket.RestartResponseException;
|
| | | import org.apache.wicket.behavior.SimpleAttributeModifier;
|
| | | import org.apache.wicket.markup.html.basic.Label;
|
| | | import org.apache.wicket.markup.html.form.DropDownChoice;
|
| | | import org.apache.wicket.markup.html.form.TextField;
|
| | |
| | | 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 org.eclipse.jgit.revwalk.RevCommit;
|
| | | import org.slf4j.Logger;
|
| | | import org.slf4j.LoggerFactory;
|
| | |
|
| | | import com.gitblit.Constants;
|
| | | import com.gitblit.GitBlit;
|
| | | import com.gitblit.GitBlitException;
|
| | | import com.gitblit.Keys;
|
| | | import com.gitblit.PagesServlet;
|
| | | import com.gitblit.SyndicationServlet;
|
| | | import com.gitblit.extensions.RepositoryNavLinkExtension;
|
| | | import com.gitblit.models.NavLink;
|
| | | import com.gitblit.models.NavLink.ExternalNavLink;
|
| | | import com.gitblit.models.NavLink.PageNavLink;
|
| | | import com.gitblit.models.ProjectModel;
|
| | | import com.gitblit.models.RefModel;
|
| | | import com.gitblit.models.RepositoryModel;
|
| | | import com.gitblit.models.SubmoduleModel;
|
| | | import com.gitblit.models.UserModel;
|
| | | import com.gitblit.models.UserRepositoryPreferences;
|
| | | import com.gitblit.servlet.PagesServlet;
|
| | | import com.gitblit.servlet.SyndicationServlet;
|
| | | import com.gitblit.utils.ArrayUtils;
|
| | | import com.gitblit.utils.BugtraqProcessor;
|
| | | import com.gitblit.utils.DeepCopier;
|
| | | import com.gitblit.utils.JGitUtils;
|
| | | import com.gitblit.utils.PushLogUtils;
|
| | | import com.gitblit.utils.ModelUtils;
|
| | | import com.gitblit.utils.RefLogUtils;
|
| | | import com.gitblit.utils.StringUtils;
|
| | | import com.gitblit.utils.TicgitUtils;
|
| | | import com.gitblit.wicket.CacheControl;
|
| | | import com.gitblit.wicket.GitBlitWebSession;
|
| | | import com.gitblit.wicket.PageRegistration;
|
| | | import com.gitblit.wicket.PageRegistration.OtherPageLink;
|
| | | import com.gitblit.wicket.SessionlessForm;
|
| | | import com.gitblit.wicket.WicketUtils;
|
| | | import com.gitblit.wicket.panels.LinkPanel;
|
| | | import com.gitblit.wicket.panels.NavigationPanel;
|
| | | import com.gitblit.wicket.panels.RefsPanel;
|
| | | import com.google.common.base.Optional;
|
| | |
|
| | | public abstract class RepositoryPage extends RootPage {
|
| | |
|
| | | protected final Logger logger = LoggerFactory.getLogger(getClass());
|
| | |
|
| | | private final String PARAM_STAR = "star";
|
| | |
|
| | | 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;
|
| | |
|
| | | private boolean showAdmin;
|
| | | private boolean isOwner;
|
| | | |
| | |
|
| | | public RepositoryPage(PageParameters params) {
|
| | | super(params);
|
| | | repositoryName = WicketUtils.getRepositoryName(params);
|
| | | String root =StringUtils.getFirstPathElement(repositoryName);
|
| | | String root = StringUtils.getFirstPathElement(repositoryName);
|
| | | if (StringUtils.isEmpty(root)) {
|
| | | projectName = GitBlit.getString(Keys.web.repositoryRootGroupName, "main");
|
| | | projectName = app().settings().getString(Keys.web.repositoryRootGroupName, "main");
|
| | | } else {
|
| | | projectName = root;
|
| | | }
|
| | | objectId = WicketUtils.getObject(params);
|
| | | |
| | |
|
| | | if (StringUtils.isEmpty(repositoryName)) {
|
| | | error(MessageFormat.format(getString("gb.repositoryNotSpecifiedFor"), getPageName()), true);
|
| | | }
|
| | |
|
| | | if (!getRepositoryModel().hasCommits) {
|
| | | setResponsePage(EmptyRepositoryPage.class, params);
|
| | | if (!getRepositoryModel().hasCommits && getClass() != EmptyRepositoryPage.class) {
|
| | | throw new RestartResponseException(EmptyRepositoryPage.class, params);
|
| | | }
|
| | | |
| | |
|
| | | if (getRepositoryModel().isCollectingGarbage) {
|
| | | error(MessageFormat.format(getString("gb.busyCollectingGarbage"), getRepositoryModel().name), true);
|
| | | }
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | // register the available page links for this page and user
|
| | | registeredPages = registerPages();
|
| | | if (params.containsKey(PARAM_STAR)) {
|
| | | // set starred state
|
| | | boolean star = params.getBoolean(PARAM_STAR);
|
| | | UserModel user = GitBlitWebSession.get().getUser();
|
| | | if (user != null && user.isAuthenticated) {
|
| | | UserRepositoryPreferences prefs = user.getPreferences().getRepositoryPreferences(getRepositoryModel().name);
|
| | | prefs.starred = star;
|
| | | try {
|
| | | app().gitblit().reviseUser(user.username, user);
|
| | | } catch (GitBlitException e) {
|
| | | logger.error("Failed to update user " + user.username, e);
|
| | | error(getString("gb.failedToUpdateUser"), false);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | // standard page links
|
| | | List<PageRegistration> pages = new ArrayList<PageRegistration>(registeredPages.values());
|
| | | NavigationPanel navigationPanel = new NavigationPanel("repositoryNavPanel", getRepoNavPageClass(), pages);
|
| | | showAdmin = false;
|
| | | if (app().settings().getBoolean(Keys.web.authenticateAdminPages, true)) {
|
| | | boolean allowAdmin = app().settings().getBoolean(Keys.web.allowAdministration, false);
|
| | | showAdmin = allowAdmin && GitBlitWebSession.get().canAdmin();
|
| | | } else {
|
| | | showAdmin = app().settings().getBoolean(Keys.web.allowAdministration, false);
|
| | | }
|
| | | isOwner = GitBlitWebSession.get().isLoggedIn()
|
| | | && (getRepositoryModel().isOwner(GitBlitWebSession.get().getUsername()));
|
| | |
|
| | | // register the available navigation links for this page and user
|
| | | List<NavLink> navLinks = registerNavLinks();
|
| | |
|
| | | // standard navigation links
|
| | | NavigationPanel navigationPanel = new NavigationPanel("repositoryNavPanel", getRepoNavPageClass(), navLinks);
|
| | | add(navigationPanel);
|
| | |
|
| | | add(new ExternalLink("syndication", SyndicationServlet.asLink(getRequest()
|
| | | .getRelativePathPrefixToContextRoot(), repositoryName, null, 0)));
|
| | | .getRelativePathPrefixToContextRoot(), getRepositoryName(), null, 0)));
|
| | |
|
| | | // add floating search form
|
| | | SearchForm searchForm = new SearchForm("searchForm", repositoryName);
|
| | | SearchForm searchForm = new SearchForm("searchForm", getRepositoryName());
|
| | | add(searchForm);
|
| | | searchForm.setTranslatedAttributes();
|
| | |
|
| | | // set stateless page preference
|
| | | setStatelessHint(true);
|
| | | }
|
| | | |
| | |
|
| | | @Override
|
| | | protected Class<? extends BasePage> getRootNavPageClass() {
|
| | | return RepositoriesPage.class;
|
| | |
| | | protected Class<? extends BasePage> getRepoNavPageClass() {
|
| | | return getClass();
|
| | | }
|
| | | |
| | | private Map<String, PageRegistration> registerPages() {
|
| | | PageParameters params = null;
|
| | | if (!StringUtils.isEmpty(repositoryName)) {
|
| | | params = WicketUtils.newRepositoryParameter(repositoryName);
|
| | | }
|
| | | Map<String, PageRegistration> pages = new LinkedHashMap<String, PageRegistration>();
|
| | |
|
| | | protected BugtraqProcessor bugtraqProcessor() {
|
| | | return new BugtraqProcessor(app().settings());
|
| | | }
|
| | |
|
| | | private List<NavLink> registerNavLinks() {
|
| | | Repository r = getRepository();
|
| | | RepositoryModel model = getRepositoryModel();
|
| | |
|
| | | PageParameters params = null;
|
| | | PageParameters objectParams = null;
|
| | | if (!StringUtils.isEmpty(repositoryName)) {
|
| | | params = WicketUtils.newRepositoryParameter(getRepositoryName());
|
| | | objectParams = params;
|
| | |
|
| | | // preserve the objectid iff the objectid directly (or indirectly) refers to a ref
|
| | | if (isCommitPage() && !StringUtils.isEmpty(objectId)) {
|
| | | RevCommit commit = JGitUtils.getCommit(r, objectId);
|
| | | if (commit != null) {
|
| | | String bestId = getBestCommitId(commit);
|
| | | if (!commit.getName().equals(bestId)) {
|
| | | objectParams = WicketUtils.newObjectParameter(getRepositoryName(), bestId);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | List<NavLink> navLinks = new ArrayList<NavLink>();
|
| | |
|
| | |
|
| | | // standard links
|
| | | if (PushLogUtils.getPushLogBranch(r) == null) {
|
| | | pages.put("summary", new PageRegistration("gb.summary", SummaryPage.class, params));
|
| | | if (RefLogUtils.getRefLogBranch(r) == null) {
|
| | | navLinks.add(new PageNavLink("gb.summary", SummaryPage.class, params));
|
| | | } else {
|
| | | pages.put("summary", new PageRegistration("gb.summary", SummaryPage.class, params));
|
| | | // pages.put("overview", new PageRegistration("gb.overview", OverviewPage.class, params));
|
| | | navLinks.add(new PageNavLink("gb.summary", SummaryPage.class, params));
|
| | | // pages.put("overview", new PageRegistration("gb.overview", OverviewPage.class, params));
|
| | | navLinks.add(new PageNavLink("gb.reflog", ReflogPage.class, params));
|
| | | }
|
| | | pages.put("commits", new PageRegistration("gb.commits", LogPage.class, params));
|
| | | pages.put("tree", new PageRegistration("gb.tree", TreePage.class, params));
|
| | | pages.put("compare", new PageRegistration("gb.compare", ComparePage.class, params));
|
| | | if (GitBlit.getBoolean(Keys.web.allowForking, true)) {
|
| | | pages.put("forks", new PageRegistration("gb.forks", ForksPage.class, params));
|
| | |
|
| | | if (!model.hasCommits) {
|
| | | return navLinks;
|
| | | }
|
| | |
|
| | | navLinks.add(new PageNavLink("gb.commits", LogPage.class, objectParams));
|
| | | navLinks.add(new PageNavLink("gb.tree", TreePage.class, objectParams));
|
| | | if (app().tickets().isReady() && (app().tickets().isAcceptingNewTickets(model) || app().tickets().hasTickets(model))) {
|
| | | PageParameters tParams = WicketUtils.newOpenTicketsParameter(getRepositoryName());
|
| | | navLinks.add(new PageNavLink("gb.tickets", TicketsPage.class, tParams)); |
| | | } |
| | | navLinks.add(new PageNavLink("gb.docs", DocsPage.class, objectParams, true));
|
| | | if (app().settings().getBoolean(Keys.web.allowForking, true)) {
|
| | | navLinks.add(new PageNavLink("gb.forks", ForksPage.class, params, true));
|
| | | }
|
| | | navLinks.add(new PageNavLink("gb.compare", ComparePage.class, params, true)); |
| | |
|
| | | // conditional links
|
| | | // per-repository extra page links
|
| | | if (model.useTickets && TicgitUtils.getTicketsBranch(r) != null) {
|
| | | pages.put("tickets", new PageRegistration("gb.tickets", TicketsPage.class, params));
|
| | | }
|
| | | if (model.showReadme || model.useDocs) {
|
| | | pages.put("docs", new PageRegistration("gb.docs", DocsPage.class, params));
|
| | | }
|
| | | // per-repository extra navlinks
|
| | | if (JGitUtils.getPagesBranch(r) != null) {
|
| | | OtherPageLink pagesLink = new OtherPageLink("gb.pages", PagesServlet.asLink(
|
| | | getRequest().getRelativePathPrefixToContextRoot(), repositoryName, null));
|
| | | pages.put("pages", pagesLink);
|
| | | ExternalNavLink pagesLink = new ExternalNavLink("gb.pages", PagesServlet.asLink(
|
| | | getRequest().getRelativePathPrefixToContextRoot(), getRepositoryName(), null), true);
|
| | | navLinks.add(pagesLink);
|
| | | }
|
| | |
|
| | | // Conditionally add edit link
|
| | | showAdmin = false;
|
| | | if (GitBlit.getBoolean(Keys.web.authenticateAdminPages, true)) {
|
| | | boolean allowAdmin = GitBlit.getBoolean(Keys.web.allowAdministration, false);
|
| | | showAdmin = allowAdmin && GitBlitWebSession.get().canAdmin();
|
| | | } else {
|
| | | showAdmin = GitBlit.getBoolean(Keys.web.allowAdministration, false);
|
| | | UserModel user = UserModel.ANONYMOUS;
|
| | | if (GitBlitWebSession.get().isLoggedIn()) {
|
| | | user = GitBlitWebSession.get().getUser();
|
| | | }
|
| | | isOwner = GitBlitWebSession.get().isLoggedIn()
|
| | | && (model.isOwner(GitBlitWebSession.get()
|
| | | .getUsername()));
|
| | | if (showAdmin || isOwner) {
|
| | | pages.put("edit", new PageRegistration("gb.edit", EditRepositoryPage.class, params));
|
| | |
|
| | | // add repository nav link extensions
|
| | | List<RepositoryNavLinkExtension> extensions = app().plugins().getExtensions(RepositoryNavLinkExtension.class);
|
| | | for (RepositoryNavLinkExtension ext : extensions) {
|
| | | navLinks.addAll(ext.getNavLinks(user, model));
|
| | | }
|
| | | return pages;
|
| | |
|
| | | return navLinks;
|
| | | }
|
| | | |
| | |
|
| | | protected boolean allowForkControls() {
|
| | | return GitBlit.getBoolean(Keys.web.allowForking, true);
|
| | | return app().settings().getBoolean(Keys.web.allowForking, true);
|
| | | }
|
| | |
|
| | | @Override
|
| | | protected void setupPage(String repositoryName, String pageName) {
|
| | | |
| | | //This method should only be called once in the page lifecycle.
|
| | | //However, it must be called after the constructor has run, hence not in onInitialize
|
| | | //It may be attempted to be called again if an info or error message is displayed.
|
| | | if (get("projectTitle") != null) { return; }
|
| | | |
| | | String projectName = StringUtils.getFirstPathElement(repositoryName);
|
| | | ProjectModel project = GitBlit.self().getProjectModel(projectName);
|
| | | ProjectModel project = app().projects().getProjectModel(projectName);
|
| | |
|
| | | if (project.isUserProject()) {
|
| | | // user-as-project
|
| | | add(new LinkPanel("projectTitle", null, project.getDisplayName(),
|
| | |
| | | add(new LinkPanel("projectTitle", null, project.name,
|
| | | ProjectPage.class, WicketUtils.newProjectParameter(project.name)));
|
| | | }
|
| | | |
| | |
|
| | | String name = StringUtils.stripDotGit(repositoryName);
|
| | | if (!StringUtils.isEmpty(projectName) && name.startsWith(projectName)) {
|
| | | name = name.substring(projectName.length() + 1);
|
| | | }
|
| | | add(new LinkPanel("repositoryName", null, name, SummaryPage.class,
|
| | | WicketUtils.newRepositoryParameter(repositoryName)));
|
| | | add(new Label("pageName", pageName).setRenderBodyOnly(true));
|
| | | |
| | |
|
| | | UserModel user = GitBlitWebSession.get().getUser();
|
| | | if (user == null) {
|
| | | user = UserModel.ANONYMOUS;
|
| | |
| | | // indicate origin repository
|
| | | RepositoryModel model = getRepositoryModel();
|
| | | if (StringUtils.isEmpty(model.originRepository)) {
|
| | | add(new Label("originRepository").setVisible(false));
|
| | | if (model.isMirror) {
|
| | | add(new Fragment("repoIcon", "mirrorIconFragment", this));
|
| | | Fragment mirrorFrag = new Fragment("originRepository", "mirrorFragment", this);
|
| | | Label lbl = new Label("originRepository", MessageFormat.format(getString("gb.mirrorOf"), "<b>" + model.origin + "</b>"));
|
| | | mirrorFrag.add(lbl.setEscapeModelStrings(false));
|
| | | add(mirrorFrag);
|
| | | } else {
|
| | | if (model.isBare) {
|
| | | add(new Fragment("repoIcon", "repoIconFragment", this));
|
| | | } else {
|
| | | add(new Fragment("repoIcon", "cloneIconFragment", this));
|
| | | }
|
| | | add(new Label("originRepository", Optional.of(model.description).or("")));
|
| | | }
|
| | | } else {
|
| | | RepositoryModel origin = GitBlit.self().getRepositoryModel(model.originRepository);
|
| | | RepositoryModel origin = app().repositories().getRepositoryModel(model.originRepository);
|
| | | if (origin == null) {
|
| | | // no origin repository
|
| | | add(new Label("originRepository").setVisible(false));
|
| | | // no origin repository, show description if available
|
| | | if (model.isBare) {
|
| | | add(new Fragment("repoIcon", "repoIconFragment", this));
|
| | | } else {
|
| | | add(new Fragment("repoIcon", "cloneIconFragment", this));
|
| | | }
|
| | | add(new Label("originRepository", Optional.of(model.description).or("")));
|
| | | } else if (!user.canView(origin)) {
|
| | | // show origin repository without link
|
| | | add(new Fragment("repoIcon", "forkIconFragment", this));
|
| | | Fragment forkFrag = new Fragment("originRepository", "originFragment", this);
|
| | | forkFrag.add(new Label("originRepository", StringUtils.stripDotGit(model.originRepository)));
|
| | | add(forkFrag);
|
| | | } else {
|
| | | // link to origin repository
|
| | | add(new Fragment("repoIcon", "forkIconFragment", this));
|
| | | Fragment forkFrag = new Fragment("originRepository", "originFragment", this);
|
| | | forkFrag.add(new LinkPanel("originRepository", null, StringUtils.stripDotGit(model.originRepository), |
| | | forkFrag.add(new LinkPanel("originRepository", null, StringUtils.stripDotGit(model.originRepository),
|
| | | SummaryPage.class, WicketUtils.newRepositoryParameter(model.originRepository)));
|
| | | add(forkFrag);
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | // new ticket button
|
| | | if (user.isAuthenticated && app().tickets().isAcceptingNewTickets(getRepositoryModel())) {
|
| | | String newTicketUrl = getRequestCycle().urlFor(NewTicketPage.class, WicketUtils.newRepositoryParameter(repositoryName)).toString();
|
| | | addToolbarButton("newTicketLink", "fa fa-ticket", getString("gb.new"), newTicketUrl);
|
| | | } else {
|
| | | add(new Label("newTicketLink").setVisible(false));
|
| | | }
|
| | |
|
| | | // (un)star link allows a user to star a repository
|
| | | if (user.isAuthenticated && model.hasCommits) {
|
| | | PageParameters starParams = DeepCopier.copy(getPageParameters());
|
| | | starParams.put(PARAM_STAR, !user.getPreferences().isStarredRepository(model.name));
|
| | | String toggleStarUrl = getRequestCycle().urlFor(getClass(), starParams).toString();
|
| | | if (user.getPreferences().isStarredRepository(model.name)) {
|
| | | // show unstar button
|
| | | add(new Label("starLink").setVisible(false));
|
| | | addToolbarButton("unstarLink", "icon-star-empty", getString("gb.unstar"), toggleStarUrl);
|
| | | } else {
|
| | | // show star button
|
| | | addToolbarButton("starLink", "icon-star", getString("gb.star"), toggleStarUrl);
|
| | | add(new Label("unstarLink").setVisible(false));
|
| | | }
|
| | | } else {
|
| | | // anonymous user
|
| | | add(new Label("starLink").setVisible(false));
|
| | | add(new Label("unstarLink").setVisible(false));
|
| | | }
|
| | |
|
| | | // fork controls
|
| | | if (!allowForkControls() || user == null || !user.isAuthenticated) {
|
| | | if (!allowForkControls() || !user.isAuthenticated) {
|
| | | // must be logged-in to fork, hide all fork controls
|
| | | add(new ExternalLink("forkLink", "").setVisible(false));
|
| | | add(new ExternalLink("myForkLink", "").setVisible(false));
|
| | | } else {
|
| | | String fork = GitBlit.self().getFork(user.username, model.name);
|
| | | String fork = app().repositories().getFork(user.username, model.name);
|
| | | String userRepo = ModelUtils.getPersonalPath(user.username) + "/" + StringUtils.stripDotGit(StringUtils.getLastPathElement(model.name));
|
| | | boolean hasUserRepo = app().repositories().hasRepository(userRepo);
|
| | | boolean hasFork = fork != null;
|
| | | boolean canFork = user.canFork(model);
|
| | | boolean canFork = user.canFork(model) && model.hasCommits && !hasUserRepo;
|
| | |
|
| | | if (hasFork || !canFork) {
|
| | | // user not allowed to fork or fork already exists or repo forbids forking
|
| | | add(new ExternalLink("forkLink", "").setVisible(false));
|
| | | |
| | |
|
| | | if (hasFork && !fork.equals(model.name)) {
|
| | | // user has fork, view my fork link
|
| | | String url = getRequestCycle().urlFor(SummaryPage.class, WicketUtils.newRepositoryParameter(fork)).toString();
|
| | |
| | | add(new ExternalLink("forkLink", url));
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | if (showAdmin || isOwner) {
|
| | | String url = getRequestCycle().urlFor(EditRepositoryPage.class, WicketUtils.newRepositoryParameter(model.name)).toString();
|
| | | add(new ExternalLink("editLink", url));
|
| | | } else {
|
| | | add(new Label("editLink").setVisible(false));
|
| | | }
|
| | |
|
| | | super.setupPage(repositoryName, pageName);
|
| | | }
|
| | |
|
| | | protected void addToolbarButton(String wicketId, String iconClass, String label, String url) {
|
| | | Fragment button = new Fragment(wicketId, "toolbarLinkFragment", this);
|
| | | Label icon = new Label("icon");
|
| | | WicketUtils.setCssClass(icon, iconClass);
|
| | | button.add(icon);
|
| | | button.add(new Label("label", label));
|
| | | button.add(new SimpleAttributeModifier("href", url));
|
| | | add(button);
|
| | | }
|
| | |
|
| | | protected void addSyndicationDiscoveryLink() {
|
| | |
| | |
|
| | | protected Repository getRepository() {
|
| | | if (r == null) {
|
| | | Repository r = GitBlit.self().getRepository(repositoryName);
|
| | | Repository r = app().repositories().getRepository(repositoryName);
|
| | | if (r == null) {
|
| | | error(getString("gb.canNotLoadRepository") + " " + repositoryName, true);
|
| | | return null;
|
| | |
| | |
|
| | | protected RepositoryModel getRepositoryModel() {
|
| | | if (m == null) {
|
| | | RepositoryModel model = GitBlit.self().getRepositoryModel(
|
| | | RepositoryModel model = app().repositories().getRepositoryModel(
|
| | | GitBlitWebSession.get().getUser(), repositoryName);
|
| | | if (model == null) {
|
| | | if (GitBlit.self().hasRepository(repositoryName, true)) {
|
| | | if (app().repositories().hasRepository(repositoryName, true)) {
|
| | | // has repository, but unauthorized
|
| | | authenticationError(getString("gb.unauthorizedAccessForRepository") + " " + repositoryName);
|
| | | } else {
|
| | |
| | | return m;
|
| | | }
|
| | |
|
| | | protected String getRepositoryName() {
|
| | | return getRepositoryModel().name;
|
| | | }
|
| | |
|
| | | protected RevCommit getCommit() {
|
| | | RevCommit commit = JGitUtils.getCommit(r, objectId);
|
| | | if (commit == null) {
|
| | | error(MessageFormat.format(getString("gb.failedToFindCommit"),
|
| | | objectId, repositoryName, getPageName()), true);
|
| | | objectId, repositoryName, getPageName()), null, LogPage.class,
|
| | | WicketUtils.newRepositoryParameter(repositoryName));
|
| | | }
|
| | | getSubmodules(commit);
|
| | | return commit;
|
| | | }
|
| | | |
| | | private Map<String, SubmoduleModel> getSubmodules(RevCommit commit) { |
| | |
|
| | | protected String getBestCommitId(RevCommit commit) {
|
| | | String head = null;
|
| | | try {
|
| | | head = r.resolve(getRepositoryModel().HEAD).getName();
|
| | | } catch (Exception e) {
|
| | | }
|
| | |
|
| | | String id = commit.getName();
|
| | | if (!StringUtils.isEmpty(head) && head.equals(id)) {
|
| | | // match default branch
|
| | | return Repository.shortenRefName(getRepositoryModel().HEAD);
|
| | | }
|
| | |
|
| | | // find first branch match
|
| | | for (RefModel ref : JGitUtils.getLocalBranches(r, false, -1)) {
|
| | | if (ref.getObjectId().getName().equals(id)) {
|
| | | return Repository.shortenRefName(ref.getName());
|
| | | }
|
| | | }
|
| | |
|
| | | // return sha
|
| | | return id;
|
| | | }
|
| | |
|
| | | protected Map<String, SubmoduleModel> getSubmodules(RevCommit commit) {
|
| | | if (submodules == null) {
|
| | | submodules = new HashMap<String, SubmoduleModel>();
|
| | | for (SubmoduleModel model : JGitUtils.getSubmodules(r, commit.getTree())) {
|
| | |
| | | }
|
| | | return submodules;
|
| | | }
|
| | | |
| | |
|
| | | protected SubmoduleModel getSubmodule(String path) {
|
| | | SubmoduleModel model = submodules.get(path);
|
| | | SubmoduleModel model = null;
|
| | | if (submodules != null) {
|
| | | model = submodules.get(path);
|
| | | }
|
| | | if (model == null) {
|
| | | // undefined submodule?!
|
| | | model = new SubmoduleModel(path.substring(path.lastIndexOf('/') + 1), path, path);
|
| | |
| | | return model;
|
| | | } else {
|
| | | // extract the repository name from the clone url
|
| | | List<String> patterns = GitBlit.getStrings(Keys.git.submoduleUrlPatterns);
|
| | | List<String> patterns = app().settings().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 (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");
|
| | | candidates.add(candidates.get(candidates.size() - 1) + ".git");
|
| | | }
|
| | |
|
| | | // absolute
|
| | |
| | | // create a unique, ordered set of candidate paths
|
| | | Set<String> paths = new LinkedHashSet<String>(candidates);
|
| | | for (String candidate : paths) {
|
| | | if (GitBlit.self().hasRepository(candidate)) {
|
| | | if (app().repositories().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) {
|
| | | return objectId.substring(0, GitBlit.getInteger(Keys.web.shortCommitIdLength, 6));
|
| | | return objectId.substring(0, app().settings().getInteger(Keys.web.shortCommitIdLength, 6));
|
| | | }
|
| | |
|
| | | protected void addRefs(Repository r, RevCommit c) {
|
| | | add(new RefsPanel("refsPanel", repositoryName, c, JGitUtils.getAllRefs(r, getRepositoryModel().showRemoteBranches)));
|
| | | }
|
| | |
|
| | | protected void addFullText(String wicketId, String text, boolean substituteRegex) {
|
| | | String html = StringUtils.escapeForHtml(text, false);
|
| | | if (substituteRegex) {
|
| | | html = GitBlit.self().processCommitMessage(repositoryName, html);
|
| | | } else {
|
| | | html = StringUtils.breakLinesForHtml(html);
|
| | | protected void addFullText(String wicketId, String text) {
|
| | | RepositoryModel model = getRepositoryModel();
|
| | | String content = bugtraqProcessor().processCommitMessage(r, model, text);
|
| | | String html;
|
| | | switch (model.commitMessageRenderer) {
|
| | | case MARKDOWN:
|
| | | String safeContent = app().xssFilter().relaxed(content);
|
| | | html = MessageFormat.format("<div class='commit_message'>{0}</div>", safeContent);
|
| | | break;
|
| | | default:
|
| | | html = MessageFormat.format("<pre class='commit_message'>{0}</pre>", content);
|
| | | break;
|
| | | }
|
| | | add(new Label(wicketId, html).setEscapeModelStrings(false));
|
| | | }
|
| | |
|
| | | protected abstract String getPageName();
|
| | |
|
| | | protected boolean isCommitPage() {
|
| | | return false;
|
| | | }
|
| | |
|
| | | protected Component createPersonPanel(String wicketId, PersonIdent identity,
|
| | | Constants.SearchType searchType) {
|
| | |
| | | String address = identity == null ? "" : identity.getEmailAddress();
|
| | | name = StringUtils.removeNewlines(name);
|
| | | address = StringUtils.removeNewlines(address);
|
| | | boolean showEmail = GitBlit.getBoolean(Keys.web.showEmailAddresses, false);
|
| | | boolean showEmail = app().settings().getBoolean(Keys.web.showEmailAddresses, false);
|
| | | if (!showEmail || StringUtils.isEmpty(name) || StringUtils.isEmpty(address)) {
|
| | | String value = name;
|
| | | if (StringUtils.isEmpty(value)) {
|
| | |
| | | }
|
| | | }
|
| | |
|
| | |
|
| | | @Override
|
| | | protected void onBeforeRender() {
|
| | | // dispose of repository object
|
| | |
| | | r.close();
|
| | | r = null;
|
| | | }
|
| | | |
| | | // setup page header and footer
|
| | | setupPage(repositoryName, "/ " + getPageName());
|
| | | setupPage(getRepositoryName(), "/ " + getPageName());
|
| | |
|
| | | super.onBeforeRender();
|
| | | }
|
| | |
|
| | | @Override
|
| | | protected void setLastModified() {
|
| | | if (getClass().isAnnotationPresent(CacheControl.class)) {
|
| | | CacheControl cacheControl = getClass().getAnnotation(CacheControl.class);
|
| | | switch (cacheControl.value()) {
|
| | | case REPOSITORY:
|
| | | RepositoryModel repository = getRepositoryModel();
|
| | | if (repository != null) {
|
| | | setLastModified(repository.lastChange);
|
| | | }
|
| | | break;
|
| | | case COMMIT:
|
| | | RevCommit commit = getCommit();
|
| | | if (commit != null) {
|
| | | Date commitDate = JGitUtils.getCommitDate(commit);
|
| | | setLastModified(commitDate);
|
| | | }
|
| | | break;
|
| | | default:
|
| | | super.setLastModified();
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | protected PageParameters newRepositoryParameter() {
|
| | |
| | | public boolean isShowAdmin() {
|
| | | return showAdmin;
|
| | | }
|
| | | |
| | |
|
| | | public boolean isOwner() {
|
| | | return isOwner;
|
| | | }
|
| | | |
| | |
|
| | | private class SearchForm extends SessionlessForm<Void> implements Serializable {
|
| | | private static final long serialVersionUID = 1L;
|
| | |
|
| | |
| | | DropDownChoice<Constants.SearchType> searchType = new DropDownChoice<Constants.SearchType>(
|
| | | "searchType", Arrays.asList(Constants.SearchType.values()));
|
| | | searchType.setModel(searchTypeModel);
|
| | | add(searchType.setVisible(GitBlit.getBoolean(Keys.web.showSearchTypeSelection, false)));
|
| | | add(searchType.setVisible(app().settings().getBoolean(Keys.web.showSearchTypeSelection, false)));
|
| | | TextField<String> searchBox = new TextField<String>("searchBox", searchBoxModel);
|
| | | add(searchBox);
|
| | | }
|
| | |
| | | Constants.SearchType searchType = searchTypeModel.getObject();
|
| | | String searchString = searchBoxModel.getObject();
|
| | | if (StringUtils.isEmpty(searchString)) {
|
| | | // redirect to self to avoid wicket page update bug |
| | | PageParameters params = RepositoryPage.this.getPageParameters();
|
| | | String relativeUrl = urlFor(RepositoryPage.this.getClass(), params).toString();
|
| | | String absoluteUrl = RequestUtils.toAbsolutePath(relativeUrl);
|
| | | // redirect to self to avoid wicket page update bug
|
| | | String absoluteUrl = getCanonicalUrl();
|
| | | getRequestCycle().setRequestTarget(new RedirectRequestTarget(absoluteUrl));
|
| | | return;
|
| | | }
|
| | |
| | | }
|
| | | }
|
| | | Class<? extends BasePage> searchPageClass = GitSearchPage.class;
|
| | | RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);
|
| | | if (GitBlit.getBoolean(Keys.web.allowLuceneIndexing, true)
|
| | | RepositoryModel model = app().repositories().getRepositoryModel(repositoryName);
|
| | | if (app().settings().getBoolean(Keys.web.allowLuceneIndexing, true)
|
| | | && !ArrayUtils.isEmpty(model.indexedBranches)) {
|
| | | // this repository is Lucene-indexed
|
| | | searchPageClass = LuceneSearchPage.class;
|
| | |
| | | // 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);
|
| | | String absoluteUrl = getCanonicalUrl(searchPageClass, params);
|
| | | getRequestCycle().setRequestTarget(new RedirectRequestTarget(absoluteUrl));
|
| | | }
|
| | | }
|