Search in sources :

Example 1 with NameRevCommand

use of org.eclipse.jgit.api.NameRevCommand in project gitiles by GerritCodeReview.

the class DescribeServlet method nameRevCommand.

private NameRevCommand nameRevCommand(Git git, ObjectId id, HttpServletRequest req, HttpServletResponse res) throws IOException {
    GitilesView view = ViewFilter.getView(req);
    NameRevCommand cmd = git.nameRev();
    boolean all = getBooleanParam(view, ALL_PARAM);
    boolean tags = getBooleanParam(view, TAGS_PARAM);
    if (all && tags) {
        renderTextError(req, res, SC_BAD_REQUEST, "Cannot specify both \"all\" and \"tags\"");
        return null;
    }
    if (all) {
        cmd.addPrefix(Constants.R_REFS);
    } else if (tags) {
        cmd.addPrefix(Constants.R_TAGS);
    } else {
        cmd.addAnnotatedTags();
    }
    cmd.add(id);
    return cmd;
}
Also used : NameRevCommand(org.eclipse.jgit.api.NameRevCommand)

Example 2 with NameRevCommand

use of org.eclipse.jgit.api.NameRevCommand in project gitiles by GerritCodeReview.

the class DescribeServlet method describe.

private String describe(Repository repo, GitilesView view, HttpServletRequest req, HttpServletResponse res) throws IOException {
    if (!getBooleanParam(view, CONTAINS_PARAM)) {
        res.setStatus(SC_BAD_REQUEST);
        return null;
    }
    ObjectId id = resolve(repo, view, req, res);
    if (id == null) {
        return null;
    }
    String name;
    try (Git git = new Git(repo)) {
        NameRevCommand cmd = nameRevCommand(git, id, req, res);
        if (cmd == null) {
            return null;
        }
        name = cmd.call().get(id);
    } catch (GitAPIException e) {
        throw new IOException(e);
    }
    if (name == null) {
        res.setStatus(SC_NOT_FOUND);
        return null;
    }
    return name;
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) Git(org.eclipse.jgit.api.Git) ObjectId(org.eclipse.jgit.lib.ObjectId) NameRevCommand(org.eclipse.jgit.api.NameRevCommand) IOException(java.io.IOException)

Aggregations

NameRevCommand (org.eclipse.jgit.api.NameRevCommand)2 IOException (java.io.IOException)1 Git (org.eclipse.jgit.api.Git)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1 ObjectId (org.eclipse.jgit.lib.ObjectId)1