Example usage for org.eclipse.jgit.api StashListCommand call

List of usage examples for org.eclipse.jgit.api StashListCommand call

Introduction

In this page you can find the example usage for org.eclipse.jgit.api StashListCommand call.

Prototype

@Override
public Collection<RevCommit> call() throws GitAPIException, InvalidRefNameException 

Source Link

Usage

From source file:org.eclipse.orion.server.git.servlets.GitStashHandlerV1.java

License:Open Source License

/**
 * Helper method extracting the StashRef for the stash commit rev
 * /*from w w w .  jav a2  s . c  o m*/
 * @param git
 *            Git handler object
 * @param stashRev
 *            Git commit name
 * @return StashRef wrapper object or <code>null</code> if the given commit is not present in the stash
 * @throws InvalidRefNameException
 * @throws GitAPIException
 */
protected StashRef getStashRef(Git git, String stashRev) throws InvalidRefNameException, GitAPIException {

    if (stashRev == null)
        return null;

    StashListCommand stashList = git.stashList();
    Collection<RevCommit> stashedRefsCollection = stashList.call();

    int k = 0;
    for (RevCommit rev : stashedRefsCollection)
        if (stashRev.equals(rev.getName()))
            return new StashRef(k);
        else
            ++k;

    return null;
}

From source file:org.eclipse.orion.server.git.servlets.GitStashHandlerV1.java

License:Open Source License

/**
 * Helper method returning whether the stash is empty or not
 * /*www .  j  ava 2 s .c  o m*/
 * @param git
 *            Git handler object
 * @return <code>true</code> iff the git stash is empty
 * @throws InvalidRefNameException
 * @throws GitAPIException
 */
protected boolean isStashEmpty(Git git) throws InvalidRefNameException, GitAPIException {
    StashListCommand stashList = git.stashList();
    Collection<RevCommit> stashedRefsCollection = stashList.call();
    return stashedRefsCollection.isEmpty();
}

From source file:org.eclipse.orion.server.git.servlets.GitStashHandlerV1.java

License:Open Source License

@Override
protected boolean handleGet(RequestInfo requestInfo) throws ServletException {

    HttpServletRequest request = requestInfo.request;
    HttpServletResponse response = requestInfo.response;
    Repository db = requestInfo.db;//from  w ww .  ja v a 2 s. co  m

    int page = request.getParameter("page") != null ? new Integer(request.getParameter("page")).intValue() : 1; //$NON-NLS-1$ //$NON-NLS-2$
    int pageSize = request.getParameter("pageSize") != null //$NON-NLS-1$
            ? new Integer(request.getParameter("pageSize")).intValue() //$NON-NLS-1$
            : PAGE_SIZE;
    String messageFilter = request.getParameter("filter"); //$NON-NLS-1$
    try {

        URI baseLocation = getURI(request);
        URI cloneLocation = BaseToCloneConverter.getCloneLocation(baseLocation, BaseToCloneConverter.COMMIT);

        Git git = new Git(db);
        StashListCommand stashList = git.stashList();
        Collection<RevCommit> stashedRefsCollection = stashList.call();

        StashPage stashPage = new StashPage(cloneLocation, db, stashedRefsCollection, page, pageSize,
                messageFilter);
        OrionServlet.writeJSONResponse(request, response, stashPage.toJSON());
        return true;

    } catch (Exception ex) {
        String msg = "An error occured for stash command.";
        return statusHandler.handleRequest(request, response,
                new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, ex));
    }
}