use of org.eclipse.jgit.errors.MissingObjectException 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.MissingObjectException in project egit by eclipse.
the class GitHistoryPage method markStartRef.
private void markStartRef(RevWalk walk, Ref ref) throws IOException, IncorrectObjectTypeException {
try {
RevObject refTarget = walk.parseAny(ref.getLeaf().getObjectId());
RevObject peeled = walk.peel(refTarget);
if (peeled instanceof RevCommit)
walk.markStart((RevCommit) peeled);
} catch (MissingObjectException e) {
// If there is a ref which points to Nirvana then we should simply
// ignore this ref. We should not let a corrupt ref cause that the
// history view is not filled at all
}
}
use of org.eclipse.jgit.errors.MissingObjectException in project egit by eclipse.
the class RefContentProposal method getDescription.
@Override
public String getDescription() {
if (objectId == null) {
return null;
} else if (upstream && objectId.equals(ObjectId.zeroId())) {
return refName + '\n' + UIText.RefContentProposal_newRemoteObject;
}
try (ObjectReader reader = db.newObjectReader()) {
ObjectLoader loader = null;
try {
loader = reader.open(objectId);
} catch (MissingObjectException e) {
if (upstream) {
return refName + '\n' + objectId.abbreviate(7).name() + // $NON-NLS-1$
" - " + UIText.RefContentProposal_unknownRemoteObject;
}
throw e;
}
final StringBuilder sb = new StringBuilder();
sb.append(refName);
sb.append('\n');
sb.append(reader.abbreviate(objectId).name());
// $NON-NLS-1$
sb.append(" - ");
switch(loader.getType()) {
case Constants.OBJ_COMMIT:
try (RevWalk rw = new RevWalk(db)) {
RevCommit c = rw.parseCommit(objectId);
appendObjectSummary(sb, UIText.RefContentProposal_commit, c.getAuthorIdent(), c.getFullMessage());
}
break;
case Constants.OBJ_TAG:
try (RevWalk rw = new RevWalk(db)) {
RevTag t = rw.parseTag(objectId);
appendObjectSummary(sb, UIText.RefContentProposal_tag, t.getTaggerIdent(), t.getFullMessage());
}
break;
case Constants.OBJ_TREE:
sb.append(UIText.RefContentProposal_tree);
break;
case Constants.OBJ_BLOB:
sb.append(UIText.RefContentProposal_blob);
break;
default:
sb.append(UIText.RefContentProposal_unknownObject);
}
return sb.toString();
} catch (IOException e) {
Activator.logError(NLS.bind(UIText.RefContentProposal_errorReadingObject, objectId, refName), e);
return null;
}
}
use of org.eclipse.jgit.errors.MissingObjectException in project repairnator by Spirals-Team.
the class GitHelper method testCommitExistence.
/**
* Test if a commit exists in the given git repository
*
* @param git
* @param oldCommitSha
* @return oldCommitSha if the commit exists in the repo, a new commit SHA
* if the commit has been retrieved from GitHub and applied back, or
* null if the retrieve failed.
*/
public String testCommitExistence(Git git, String oldCommitSha, AbstractStep step, Build build) {
try {
ObjectId commitObject = git.getRepository().resolve(oldCommitSha);
git.getRepository().open(commitObject);
return oldCommitSha;
} catch (MissingObjectException e) {
return retrieveAndApplyCommitFromGithub(git, oldCommitSha, step, build);
} catch (IOException e) {
step.addStepError("Error while testing commit: " + e);
}
return null;
}
use of org.eclipse.jgit.errors.MissingObjectException in project gerrit by GerritCodeReview.
the class WalkSorter method byCommit.
private ListMultimap<RevCommit, PatchSetData> byCommit(RevWalk rw, Collection<ChangeData> in) throws 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.id().get() > maxPs.id().get())) {
maxPs = ps;
}
}
if (maxPs == null) {
// No patch sets matched.
continue;
}
try {
RevCommit c = rw.parseCommit(maxPs.commitId());
byCommit.put(c, PatchSetData.create(cd, maxPs, c));
} catch (MissingObjectException | IncorrectObjectTypeException e) {
logger.atWarning().withCause(e).log("missing commit %s for patch set %s", maxPs.commitId().name(), maxPs.id());
}
}
return byCommit;
}
Aggregations