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;
}
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;
}
Aggregations