Search in sources :

Example 86 with RepositoryModel

use of com.gitblit.models.RepositoryModel in project gitblit by gitblit.

the class FederationManager method createFederationProposal.

/**
	 * Creates a proposal from the token.
	 *
	 * @param gitblitUrl
	 *            the url of this Gitblit instance
	 * @param token
	 * @return a potential proposal
	 */
@Override
public FederationProposal createFederationProposal(String gitblitUrl, String token) {
    FederationToken tokenType = FederationToken.REPOSITORIES;
    for (FederationToken type : FederationToken.values()) {
        if (token.equals(getFederationToken(type))) {
            tokenType = type;
            break;
        }
    }
    Map<String, RepositoryModel> repositories = getRepositories(gitblitUrl, token);
    FederationProposal proposal = new FederationProposal(gitblitUrl, tokenType, token, repositories);
    return proposal;
}
Also used : FederationProposal(com.gitblit.models.FederationProposal) RepositoryModel(com.gitblit.models.RepositoryModel) FederationToken(com.gitblit.Constants.FederationToken)

Example 87 with RepositoryModel

use of com.gitblit.models.RepositoryModel in project gitblit by gitblit.

the class RepositoryManager method getForkNetwork.

/**
	 * Returns the fork network for a repository by traversing up the fork graph
	 * to discover the root and then down through all children of the root node.
	 *
	 * @param repository
	 * @return a ForkModel
	 */
@Override
public ForkModel getForkNetwork(String repository) {
    if (settings.getBoolean(Keys.git.cacheRepositoryList, true)) {
        // find the root, cached
        String key = getRepositoryKey(repository);
        RepositoryModel model = repositoryListCache.get(key);
        if (model == null) {
            return null;
        }
        while (model.originRepository != null) {
            String originKey = getRepositoryKey(model.originRepository);
            model = repositoryListCache.get(originKey);
            if (model == null) {
                return null;
            }
        }
        ForkModel root = getForkModelFromCache(model.name);
        return root;
    } else {
        // find the root, non-cached
        RepositoryModel model = getRepositoryModel(repository.toLowerCase());
        while (model.originRepository != null) {
            model = getRepositoryModel(model.originRepository);
        }
        ForkModel root = getForkModel(model.name);
        return root;
    }
}
Also used : ForkModel(com.gitblit.models.ForkModel) RepositoryModel(com.gitblit.models.RepositoryModel)

Example 88 with RepositoryModel

use of com.gitblit.models.RepositoryModel in project gitblit by gitblit.

the class RepositoryManager method getRepositoryModels.

/**
	 * Returns the list of all repository models.
	 *
	 * @return list of all repository models
	 */
@Override
public List<RepositoryModel> getRepositoryModels() {
    long methodStart = System.currentTimeMillis();
    List<String> list = getRepositoryList();
    List<RepositoryModel> repositories = new ArrayList<RepositoryModel>();
    for (String repo : list) {
        RepositoryModel model = getRepositoryModel(repo);
        if (model != null) {
            repositories.add(model);
        }
    }
    long duration = System.currentTimeMillis() - methodStart;
    logger.info(MessageFormat.format("{0} repository models loaded in {1} msecs", duration));
    return repositories;
}
Also used : ArrayList(java.util.ArrayList) RepositoryModel(com.gitblit.models.RepositoryModel)

Example 89 with RepositoryModel

use of com.gitblit.models.RepositoryModel in project gitblit by gitblit.

the class RepositoryManager method addToCachedRepositoryList.

/**
	 * Adds the repository to the list of cached repositories if Gitblit is
	 * configured to cache the repository list.
	 *
	 * @param model
	 */
@Override
public void addToCachedRepositoryList(RepositoryModel model) {
    if (settings.getBoolean(Keys.git.cacheRepositoryList, true)) {
        String key = getRepositoryKey(model.name);
        repositoryListCache.put(key, model);
        // update the fork origin repository with this repository clone
        if (!StringUtils.isEmpty(model.originRepository)) {
            String originKey = getRepositoryKey(model.originRepository);
            if (repositoryListCache.containsKey(originKey)) {
                RepositoryModel origin = repositoryListCache.get(originKey);
                origin.addFork(model.name);
            }
        }
    }
}
Also used : RepositoryModel(com.gitblit.models.RepositoryModel)

Example 90 with RepositoryModel

use of com.gitblit.models.RepositoryModel in project gitblit by gitblit.

the class UserPage method setup.

private void setup(PageParameters params) {
    setupPage("", "");
    // check to see if we should display a login message
    boolean authenticateView = app().settings().getBoolean(Keys.web.authenticateViewPages, true);
    if (authenticateView && !GitBlitWebSession.get().isLoggedIn()) {
        authenticationError("Please login");
        return;
    }
    String userName = WicketUtils.getUsername(params);
    if (StringUtils.isEmpty(userName)) {
        throw new GitblitRedirectException(GitBlitWebApp.get().getHomePage());
    }
    UserModel user = app().users().getUserModel(userName);
    if (user == null) {
        // construct a temporary user model
        user = new UserModel(userName);
    }
    add(new UserTitlePanel("userTitlePanel", user, user.username));
    UserModel sessionUser = GitBlitWebSession.get().getUser();
    boolean isMyProfile = sessionUser != null && sessionUser.equals(user);
    if (isMyProfile) {
        addPreferences(user);
        if (app().services().isServingSSH()) {
            // show the SSH key management tab
            addSshKeys(user);
        } else {
            // SSH daemon is disabled, hide keys tab
            add(new Label("sshKeysLink").setVisible(false));
            add(new Label("sshKeysTab").setVisible(false));
        }
    } else {
        // visiting user
        add(new Label("preferencesLink").setVisible(false));
        add(new Label("preferencesTab").setVisible(false));
        add(new Label("sshKeysLink").setVisible(false));
        add(new Label("sshKeysTab").setVisible(false));
    }
    List<RepositoryModel> repositories = getRepositories(params);
    Collections.sort(repositories, new Comparator<RepositoryModel>() {

        @Override
        public int compare(RepositoryModel o1, RepositoryModel o2) {
            // reverse-chronological sort
            return o2.lastChange.compareTo(o1.lastChange);
        }
    });
    final ListDataProvider<RepositoryModel> dp = new ListDataProvider<RepositoryModel>(repositories);
    DataView<RepositoryModel> dataView = new DataView<RepositoryModel>("repositoryList", dp) {

        private static final long serialVersionUID = 1L;

        @Override
        public void populateItem(final Item<RepositoryModel> item) {
            final RepositoryModel entry = item.getModelObject();
            ProjectRepositoryPanel row = new ProjectRepositoryPanel("repository", getLocalizer(), this, showAdmin, entry, getAccessRestrictions());
            item.add(row);
        }
    };
    add(dataView);
}
Also used : ListDataProvider(org.apache.wicket.markup.repeater.data.ListDataProvider) UserTitlePanel(com.gitblit.wicket.panels.UserTitlePanel) Label(org.apache.wicket.markup.html.basic.Label) RepositoryModel(com.gitblit.models.RepositoryModel) GitblitRedirectException(com.gitblit.wicket.GitblitRedirectException) UserModel(com.gitblit.models.UserModel) DataView(org.apache.wicket.markup.repeater.data.DataView) ParameterMenuItem(com.gitblit.models.Menu.ParameterMenuItem) Item(org.apache.wicket.markup.repeater.Item) ProjectRepositoryPanel(com.gitblit.wicket.panels.ProjectRepositoryPanel)

Aggregations

RepositoryModel (com.gitblit.models.RepositoryModel)234 Test (org.junit.Test)145 Date (java.util.Date)135 UserModel (com.gitblit.models.UserModel)116 TeamModel (com.gitblit.models.TeamModel)68 ArrayList (java.util.ArrayList)39 File (java.io.File)20 Repository (org.eclipse.jgit.lib.Repository)20 CloneCommand (org.eclipse.jgit.api.CloneCommand)16 Git (org.eclipse.jgit.api.Git)13 ReceiveCommand (org.eclipse.jgit.transport.ReceiveCommand)13 GitBlitException (com.gitblit.GitBlitException)11 Label (org.apache.wicket.markup.html.basic.Label)11 UsernamePasswordCredentialsProvider (org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider)11 PushResult (org.eclipse.jgit.transport.PushResult)10 RemoteRefUpdate (org.eclipse.jgit.transport.RemoteRefUpdate)10 RegistrantAccessPermission (com.gitblit.models.RegistrantAccessPermission)9 BufferedWriter (java.io.BufferedWriter)9 FileOutputStream (java.io.FileOutputStream)9 RevCommit (org.eclipse.jgit.revwalk.RevCommit)9