use of org.eclipse.jgit.errors.IncorrectObjectTypeException in project gerrit by GerritCodeReview.
the class DashboardsCollection method parse.
@Override
public DashboardResource parse(ProjectResource parent, IdString id) throws ResourceNotFoundException, IOException, ConfigInvalidException {
ProjectControl myCtl = parent.getControl();
if (id.toString().equals("default")) {
return DashboardResource.projectDefault(myCtl);
}
List<String> parts = Lists.newArrayList(Splitter.on(':').limit(2).split(id.get()));
if (parts.size() != 2) {
throw new ResourceNotFoundException(id);
}
CurrentUser user = myCtl.getUser();
String ref = parts.get(0);
String path = parts.get(1);
for (ProjectState ps : myCtl.getProjectState().tree()) {
try {
return parse(ps.controlFor(user), ref, path, myCtl);
} catch (AmbiguousObjectException | ConfigInvalidException | IncorrectObjectTypeException e) {
throw new ResourceNotFoundException(id);
} catch (ResourceNotFoundException e) {
continue;
}
}
throw new ResourceNotFoundException(id);
}
use of org.eclipse.jgit.errors.IncorrectObjectTypeException in project gerrit by GerritCodeReview.
the class CreateBranch method apply.
@Override
public BranchInfo apply(ProjectResource rsrc, BranchInput input) throws BadRequestException, AuthException, ResourceConflictException, IOException {
if (input == null) {
input = new BranchInput();
}
if (input.ref != null && !ref.equals(input.ref)) {
throw new BadRequestException("ref must match URL");
}
if (input.revision == null) {
input.revision = Constants.HEAD;
}
while (ref.startsWith("/")) {
ref = ref.substring(1);
}
ref = RefNames.fullName(ref);
if (!Repository.isValidRefName(ref)) {
throw new BadRequestException("invalid branch name \"" + ref + "\"");
}
if (MagicBranch.isMagicBranch(ref)) {
throw new BadRequestException("not allowed to create branches under \"" + MagicBranch.getMagicRefNamePrefix(ref) + "\"");
}
final Branch.NameKey name = new Branch.NameKey(rsrc.getNameKey(), ref);
final RefControl refControl = rsrc.getControl().controlForRef(name);
try (Repository repo = repoManager.openRepository(rsrc.getNameKey())) {
ObjectId revid = RefUtil.parseBaseRevision(repo, rsrc.getNameKey(), input.revision);
RevWalk rw = RefUtil.verifyConnected(repo, revid);
RevObject object = rw.parseAny(revid);
if (ref.startsWith(Constants.R_HEADS)) {
//
try {
object = rw.parseCommit(object);
} catch (IncorrectObjectTypeException notCommit) {
throw new BadRequestException("\"" + input.revision + "\" not a commit");
}
}
if (!refControl.canCreate(db.get(), repo, object)) {
throw new AuthException("Cannot create \"" + ref + "\"");
}
try {
final RefUpdate u = repo.updateRef(ref);
u.setExpectedOldObjectId(ObjectId.zeroId());
u.setNewObjectId(object.copy());
u.setRefLogIdent(identifiedUser.get().newRefLogIdent());
u.setRefLogMessage("created via REST from " + input.revision, false);
refCreationValidator.validateRefOperation(rsrc.getName(), identifiedUser.get(), u);
final RefUpdate.Result result = u.update(rw);
switch(result) {
case FAST_FORWARD:
case NEW:
case NO_CHANGE:
referenceUpdated.fire(name.getParentKey(), u, ReceiveCommand.Type.CREATE, identifiedUser.get().getAccount());
break;
case LOCK_FAILURE:
if (repo.getRefDatabase().exactRef(ref) != null) {
throw new ResourceConflictException("branch \"" + ref + "\" already exists");
}
String refPrefix = RefUtil.getRefPrefix(ref);
while (!Constants.R_HEADS.equals(refPrefix)) {
if (repo.getRefDatabase().exactRef(refPrefix) != null) {
throw new ResourceConflictException("Cannot create branch \"" + ref + "\" since it conflicts with branch \"" + refPrefix + "\".");
}
refPrefix = RefUtil.getRefPrefix(refPrefix);
}
//$FALL-THROUGH$
case FORCED:
case IO_FAILURE:
case NOT_ATTEMPTED:
case REJECTED:
case REJECTED_CURRENT_BRANCH:
case RENAMED:
default:
{
throw new IOException(result.name());
}
}
BranchInfo info = new BranchInfo();
info.ref = ref;
info.revision = revid.getName();
info.canDelete = permissionBackend.user(identifiedUser).ref(name).testOrFalse(RefPermission.DELETE) ? true : null;
return info;
} catch (IOException err) {
log.error("Cannot create branch \"" + name + "\"", err);
throw err;
}
} catch (RefUtil.InvalidRevisionException e) {
throw new BadRequestException("invalid revision \"" + input.revision + "\"");
}
}
use of org.eclipse.jgit.errors.IncorrectObjectTypeException in project gerrit by GerritCodeReview.
the class WalkSorter method byCommit.
private ListMultimap<RevCommit, PatchSetData> byCommit(RevWalk rw, Collection<ChangeData> in) throws OrmException, IOException {
ListMultimap<RevCommit, PatchSetData> byCommit = MultimapBuilder.hashKeys(in.size()).arrayListValues(1).build();
for (ChangeData cd : in) {
PatchSet maxPs = null;
for (PatchSet ps : cd.patchSets()) {
if (shouldInclude(ps) && (maxPs == null || ps.getId().get() > maxPs.getId().get())) {
maxPs = ps;
}
}
if (maxPs == null) {
// No patch sets matched.
continue;
}
ObjectId id = ObjectId.fromString(maxPs.getRevision().get());
try {
RevCommit c = rw.parseCommit(id);
byCommit.put(c, PatchSetData.create(cd, maxPs, c));
} catch (MissingObjectException | IncorrectObjectTypeException e) {
log.warn("missing commit " + id.name() + " for patch set " + maxPs.getId(), e);
}
}
return byCommit;
}
use of org.eclipse.jgit.errors.IncorrectObjectTypeException in project gitiles by GerritCodeReview.
the class DiffServlet method doGetText.
@Override
protected void doGetText(HttpServletRequest req, HttpServletResponse res) throws IOException {
GitilesView view = ViewFilter.getView(req);
Repository repo = ServletUtils.getRepository(req);
try (RevWalk walk = new RevWalk(repo)) {
AbstractTreeIterator oldTree;
AbstractTreeIterator newTree;
try {
oldTree = getTreeIterator(walk, view.getOldRevision().getId());
newTree = getTreeIterator(walk, view.getRevision().getId());
} catch (MissingObjectException | IncorrectObjectTypeException e) {
res.setStatus(SC_NOT_FOUND);
return;
}
try (Writer writer = startRenderText(req, res);
OutputStream out = BaseEncoding.base64().encodingStream(writer);
DiffFormatter diff = new DiffFormatter(out)) {
formatDiff(repo, oldTree, newTree, view.getPathPart(), diff);
}
}
}
use of org.eclipse.jgit.errors.IncorrectObjectTypeException in project gitiles by GerritCodeReview.
the class LogServlet method newWalk.
private static RevWalk newWalk(Repository repo, GitilesView view, GitilesAccess access) throws MissingObjectException, IOException {
RevWalk walk = new RevWalk(repo);
try {
walk.markStart(walk.parseCommit(view.getRevision().getId()));
if (view.getOldRevision() != Revision.NULL) {
walk.markUninteresting(walk.parseCommit(view.getOldRevision().getId()));
}
} catch (IncorrectObjectTypeException iote) {
return null;
}
setTreeFilter(walk, view, access);
setRevFilter(walk, view);
if (isTrue(view, "topo-order")) {
walk.sort(RevSort.TOPO, true);
}
if (isTrue(view, "reverse")) {
walk.sort(RevSort.REVERSE, true);
}
return walk;
}
Aggregations