use of org.eclipse.jgit.errors.MissingObjectException in project jwt by emweb.
the class Git method treeSize.
public int treeSize(ObjectId treeId) {
if (treeId.id == null)
return 0;
try {
RevWalk walk = new RevWalk(repository, 0);
RevTree tree = walk.parseTree(treeId.id);
TreeWalk treeWalk = new TreeWalk(repository);
treeWalk.addTree(tree);
treeWalk.setRecursive(false);
int count = 0;
while (treeWalk.next()) ++count;
return count;
} catch (MissingObjectException e) {
throw new RuntimeException(e);
} catch (IncorrectObjectTypeException e) {
throw new RuntimeException(e);
} catch (CorruptObjectException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.eclipse.jgit.errors.MissingObjectException in project repairnator by Spirals-Team.
the class GitHelper method getLastKnowParent.
private String getLastKnowParent(GitHub gh, GHRepository ghRepo, Git git, String oldCommitSha, AbstractStep step) throws IOException {
showGitHubRateInformation(gh, step);
// get the deleted
GHCommit commit = ghRepo.getCommit(oldCommitSha);
// commit from GH
List<String> commitParents = commit.getParentSHA1s();
if (commitParents.isEmpty()) {
step.addStepError("The following commit does not have any parent in GitHub: " + oldCommitSha + ". It cannot be resolved.");
return null;
}
if (commitParents.size() > 1) {
this.getLogger().debug("Step " + step.getName() + " - The commit has more than one parent : " + commit.getHtmlUrl());
}
String parent = commitParents.get(0);
try {
ObjectId commitObject = git.getRepository().resolve(parent);
git.getRepository().open(commitObject);
return parent;
} catch (MissingObjectException e) {
return getLastKnowParent(gh, ghRepo, git, parent, step);
}
}
use of org.eclipse.jgit.errors.MissingObjectException in project gitiles by GerritCodeReview.
the class DiffServlet method doGetHtml.
@Override
protected void doGetHtml(HttpServletRequest req, HttpServletResponse res) throws IOException {
GitilesView view = ViewFilter.getView(req);
Repository repo = ServletUtils.getRepository(req);
try (RevWalk walk = new RevWalk(repo);
TreeWalk tw = newTreeWalk(walk, view)) {
boolean showCommit;
boolean isFile;
AbstractTreeIterator oldTree;
AbstractTreeIterator newTree;
try {
if (tw == null && !view.getPathPart().isEmpty()) {
res.setStatus(SC_NOT_FOUND);
return;
}
isFile = tw != null && isFile(tw);
// If we are viewing the diff between a commit and one of its parents,
// include the commit detail in the rendered page.
showCommit = isParentOf(walk, view.getOldRevision(), view.getRevision());
oldTree = getTreeIterator(walk, view.getOldRevision().getId());
newTree = getTreeIterator(walk, view.getRevision().getId());
} catch (MissingObjectException | IncorrectObjectTypeException e) {
res.setStatus(SC_NOT_FOUND);
return;
}
Map<String, Object> data = getData(req);
data.put("title", "Diff - " + view.getRevisionRange());
if (showCommit) {
Set<Field> fs = CommitSoyData.DEFAULT_FIELDS;
if (isFile) {
fs = Field.setOf(fs, Field.PARENT_BLAME_URL);
}
GitilesAccess access = getAccess(req);
DateFormatter df = new DateFormatter(access, Format.DEFAULT);
data.put("commit", new CommitSoyData().setLinkifier(linkifier).setArchiveFormat(getArchiveFormat(access)).toSoyData(req, walk.parseCommit(view.getRevision().getId()), fs, df));
}
if (!data.containsKey("repositoryName") && (view.getRepositoryName() != null)) {
data.put("repositoryName", view.getRepositoryName());
}
if (!data.containsKey("breadcrumbs")) {
data.put("breadcrumbs", view.getBreadcrumbs());
}
setCacheHeaders(req, res);
try (OutputStream out = startRenderStreamingHtml(req, res, "gitiles.diffDetail", data);
DiffFormatter diff = new HtmlDiffFormatter(renderer, view, out)) {
formatDiff(repo, oldTree, newTree, view.getPathPart(), diff);
}
}
}
use of org.eclipse.jgit.errors.MissingObjectException in project egit by eclipse.
the class GitBlobStorage method open.
private InputStream open() throws IOException, CoreException, IncorrectObjectTypeException {
if (blobId == null)
return new ByteArrayInputStream(new byte[0]);
try {
WorkingTreeOptions workingTreeOptions = db.getConfig().get(WorkingTreeOptions.KEY);
final InputStream objectInputStream = db.open(blobId, Constants.OBJ_BLOB).openStream();
switch(workingTreeOptions.getAutoCRLF()) {
case INPUT:
// itself should ignore line endings.
case FALSE:
return objectInputStream;
case TRUE:
default:
return new AutoCRLFInputStream(objectInputStream, true);
}
} catch (MissingObjectException notFound) {
throw new CoreException(Activator.error(NLS.bind(CoreText.BlobStorage_blobNotFound, blobId.name(), path), notFound));
}
}
use of org.eclipse.jgit.errors.MissingObjectException in project gerrit by GerritCodeReview.
the class IncludedIn method apply.
public IncludedInInfo apply(Project.NameKey project, String revisionId) throws RestApiException, IOException, PermissionBackendException {
try (Repository r = repoManager.openRepository(project);
RevWalk rw = new RevWalk(r)) {
rw.setRetainBody(false);
RevCommit rev;
try {
rev = rw.parseCommit(ObjectId.fromString(revisionId));
} catch (IncorrectObjectTypeException err) {
throw new BadRequestException(err.getMessage());
} catch (MissingObjectException err) {
throw new ResourceConflictException(err.getMessage());
}
RefDatabase refDb = r.getRefDatabase();
Collection<Ref> tags = refDb.getRefsByPrefix(Constants.R_TAGS);
Collection<Ref> branches = refDb.getRefsByPrefix(Constants.R_HEADS);
List<Ref> allTagsAndBranches = Lists.newArrayListWithCapacity(tags.size() + branches.size());
allTagsAndBranches.addAll(tags);
allTagsAndBranches.addAll(branches);
Set<String> allMatchingTagsAndBranches = rw.getMergedInto(rev, IncludedInUtil.getSortedRefs(allTagsAndBranches, rw)).stream().map(Ref::getName).collect(Collectors.toSet());
// Filter branches and tags according to their visbility by the user
ImmutableSortedSet<String> filteredBranches = sortedShortNames(filterReadableRefs(project, getMatchingRefNames(allMatchingTagsAndBranches, branches)));
ImmutableSortedSet<String> filteredTags = sortedShortNames(filterReadableRefs(project, getMatchingRefNames(allMatchingTagsAndBranches, tags)));
ListMultimap<String, String> external = MultimapBuilder.hashKeys().arrayListValues().build();
externalIncludedIn.runEach(ext -> {
ListMultimap<String, String> extIncludedIns = ext.getIncludedIn(project.get(), rev.name(), filteredBranches, filteredTags);
if (extIncludedIns != null) {
external.putAll(extIncludedIns);
}
});
return new IncludedInInfo(filteredBranches, filteredTags, (!external.isEmpty() ? external.asMap() : null));
}
}
Aggregations