org.eclipse.jgit.errors.MissingObjectException Java Examples

The following examples show how to use org.eclipse.jgit.errors.MissingObjectException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RevWalk.java    From onedev with MIT License 6 votes vote down vote up
/**
 * Locate a reference to a tree.
 * <p>
 * This method only returns successfully if the tree object exists, is
 * verified to be a tree.
 *
 * @param id
 *            name of the tree object, or a commit or annotated tag that may
 *            reference a tree.
 * @return reference to the tree object. Never null.
 * @throws org.eclipse.jgit.errors.MissingObjectException
 *             the supplied tree does not exist.
 * @throws org.eclipse.jgit.errors.IncorrectObjectTypeException
 *             the supplied id is not a tree, a commit or an annotated tag.
 * @throws java.io.IOException
 *             a pack file or loose object could not be read.
 */
@NonNull
public RevTree parseTree(AnyObjectId id)
		throws MissingObjectException, IncorrectObjectTypeException,
		IOException {
	RevObject c = peel(parseAny(id));

	final RevTree t;
	if (c instanceof RevCommit)
		t = ((RevCommit) c).getTree();
	else if (!(c instanceof RevTree))
		throw new IncorrectObjectTypeException(id.toObjectId(),
				Constants.TYPE_TREE);
	else
		t = (RevTree) c;
	parseHeaders(t);
	return t;
}
 
Example #2
Source File: ObjectWalk.java    From onedev with MIT License 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public RevCommit next() throws MissingObjectException,
		IncorrectObjectTypeException, IOException {
	for (;;) {
		final RevCommit r = super.next();
		if (r == null) {
			return null;
		}
		final RevTree t = r.getTree();
		if ((r.flags & UNINTERESTING) != 0) {
			if (objectFilter.include(this, t)) {
				markTreeUninteresting(t);
			}
			if (boundary) {
				return r;
			}
			continue;
		}
		if (objectFilter.include(this, t)) {
			pendingObjects.add(t);
		}
		return r;
	}
}
 
Example #3
Source File: ObjectWalk.java    From onedev with MIT License 6 votes vote down vote up
private RevObject pushTree(RevObject obj) throws LargeObjectException,
		MissingObjectException, IncorrectObjectTypeException, IOException {
	TreeVisit tv = freeVisit;
	if (tv != null) {
		freeVisit = tv.parent;
		tv.ptr = 0;
		tv.namePtr = 0;
		tv.nameEnd = 0;
		tv.pathLen = 0;
	} else {
		tv = new TreeVisit();
	}
	tv.obj = obj;
	tv.buf = reader.open(obj, OBJ_TREE).getCachedBytes();
	tv.parent = currVisit;
	currVisit = tv;
	if (tv.parent == null) {
		tv.depth = 1;
	} else {
		tv.depth = tv.parent.depth + 1;
	}

	return obj;
}
 
Example #4
Source File: TopoSortGenerator.java    From onedev with MIT License 6 votes vote down vote up
/**
 * Create a new sorter and completely spin the generator.
 * <p>
 * When the constructor completes the supplied generator will have no
 * commits remaining, as all of the commits will be held inside of this
 * generator's internal buffer.
 *
 * @param s
 *            generator to pull all commits out of, and into this buffer.
 * @throws MissingObjectException
 * @throws IncorrectObjectTypeException
 * @throws IOException
 */
TopoSortGenerator(Generator s) throws MissingObjectException,
		IncorrectObjectTypeException, IOException {
	super(s.firstParent);
	pending = new FIFORevQueue(firstParent);
	outputType = s.outputType() | SORT_TOPO;
	s.shareFreeList(pending);
	for (;;) {
		final RevCommit c = s.next();
		if (c == null) {
			break;
		}
		for (RevCommit p : c.parents) {
			p.inDegree++;
			if (firstParent) {
				break;
			}
		}
		pending.add(c);
	}
}
 
Example #5
Source File: RewriteGenerator.java    From onedev with MIT License 5 votes vote down vote up
@Override
RevCommit next() throws MissingObjectException,
		IncorrectObjectTypeException, IOException {
	final RevCommit c = source.next();
	if (c == null) {
		return null;
	}
	boolean rewrote = false;
	final RevCommit[] pList = c.parents;
	final int nParents = pList.length;
	for (int i = 0; i < nParents; i++) {
		final RevCommit oldp = pList[i];
		final RevCommit newp = rewrite(oldp);
		if (firstParent) {
			if (newp == null) {
				c.parents = RevCommit.NO_PARENTS;
			} else {
				c.parents = new RevCommit[] { newp };
			}
			return c;
		}
		if (oldp != newp) {
			pList[i] = newp;
			rewrote = true;
		}
	}
	if (rewrote) {
		c.parents = cleanup(pList);
	}
	return c;
}
 
Example #6
Source File: RevWalk.java    From onedev with MIT License 5 votes vote down vote up
byte[] getCachedBytes(RevObject obj, ObjectLoader ldr)
		throws LargeObjectException, MissingObjectException, IOException {
	try {
		return ldr.getCachedBytes(5 * MB);
	} catch (LargeObjectException tooBig) {
		tooBig.setObjectId(obj);
		throw tooBig;
	}
}
 
Example #7
Source File: CommitTimeRevFilter.java    From onedev with MIT License 5 votes vote down vote up
@Override
public boolean include(RevWalk walker, RevCommit cmit)
		throws StopWalkException, MissingObjectException,
		IncorrectObjectTypeException, IOException {
	// Since the walker sorts commits by commit time we can be
	// reasonably certain there is nothing remaining worth our
	// scanning if this commit is before the point in question.
	//
	if (cmit.getCommitTime() < when)
		throw StopWalkException.INSTANCE;
	return true;
}
 
Example #8
Source File: RevTree.java    From onedev with MIT License 5 votes vote down vote up
@Override
void parseHeaders(RevWalk walk) throws MissingObjectException,
		IncorrectObjectTypeException, IOException {
	if (walk.reader.has(this))
		flags |= PARSED;
	else
		throw new MissingObjectException(this, getType());
}
 
Example #9
Source File: MaxCountRevFilter.java    From onedev with MIT License 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public boolean include(RevWalk walker, RevCommit cmit)
		throws StopWalkException, MissingObjectException,
		IncorrectObjectTypeException, IOException {
	count++;
	if (count > maxCount)
		throw StopWalkException.INSTANCE;
	return true;
}
 
Example #10
Source File: TreeRevFilter.java    From onedev with MIT License 5 votes vote down vote up
private void updateFollowFilter(ObjectId[] trees, DiffConfig cfg)
		throws MissingObjectException, IncorrectObjectTypeException,
		CorruptObjectException, IOException {
	TreeWalk tw = pathFilter;
	FollowFilter oldFilter = (FollowFilter) tw.getFilter();
	tw.setFilter(TreeFilter.ANY_DIFF);
	tw.reset(trees);

	List<DiffEntry> files = DiffEntry.scan(tw);
	RenameDetector rd = new RenameDetector(tw.getObjectReader(), cfg);
	rd.addAll(files);
	files = rd.compute();

	TreeFilter newFilter = oldFilter;
	for (DiffEntry ent : files) {
		if (isRename(ent) && ent.getNewPath().equals(oldFilter.getPath())) {
			newFilter = FollowFilter.create(ent.getOldPath(), cfg);
			RenameCallback callback = oldFilter.getRenameCallback();
			if (callback != null) {
				callback.renamed(ent);
				// forward the callback to the new follow filter
				((FollowFilter) newFilter).setRenameCallback(callback);
			}
			break;
		}
	}
	tw.setFilter(newFilter);
}
 
Example #11
Source File: SkipRevFilter.java    From onedev with MIT License 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public boolean include(RevWalk walker, RevCommit cmit)
		throws StopWalkException, MissingObjectException,
		IncorrectObjectTypeException, IOException {
	if (skip > count++)
		return false;
	return true;
}
 
Example #12
Source File: DateRevQueue.java    From onedev with MIT License 5 votes vote down vote up
DateRevQueue(Generator s) throws MissingObjectException,
		IncorrectObjectTypeException, IOException {
	super(s.firstParent);
	for (;;) {
		final RevCommit c = s.next();
		if (c == null)
			break;
		add(c);
	}
}
 
Example #13
Source File: MergeBaseGenerator.java    From onedev with MIT License 5 votes vote down vote up
@Override
RevCommit next() throws MissingObjectException,
		IncorrectObjectTypeException, IOException {
	while (!ret.isEmpty()) {
		RevCommit commit = ret.remove();
		if ((commit.flags & mergeBaseAncestor) == 0) {
			return commit;
		}
	}
	return null;
}
 
Example #14
Source File: OrRevFilter.java    From onedev with MIT License 5 votes vote down vote up
@Override
public boolean include(RevWalk walker, RevCommit c)
		throws MissingObjectException, IncorrectObjectTypeException,
		IOException {
	for (RevFilter f : subfilters) {
		if (f.include(walker, c))
			return true;
	}
	return false;
}
 
Example #15
Source File: NotRevFilter.java    From onedev with MIT License 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public boolean include(RevWalk walker, RevCommit c)
		throws MissingObjectException, IncorrectObjectTypeException,
		IOException {
	return !a.include(walker, c);
}
 
Example #16
Source File: PatternMatchRevFilter.java    From onedev with MIT License 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public boolean include(RevWalk walker, RevCommit cmit)
		throws MissingObjectException, IncorrectObjectTypeException,
		IOException {
	return compiledPattern.reset(text(cmit)).matches();
}
 
Example #17
Source File: AndRevFilter.java    From onedev with MIT License 5 votes vote down vote up
@Override
public boolean include(RevWalk walker, RevCommit c)
		throws MissingObjectException, IncorrectObjectTypeException,
		IOException {
	for (RevFilter f : subfilters) {
		if (!f.include(walker, c))
			return false;
	}
	return true;
}
 
Example #18
Source File: RevWalk.java    From onedev with MIT License 5 votes vote down vote up
private RevObject parseNew(AnyObjectId id, ObjectLoader ldr)
		throws LargeObjectException, CorruptObjectException,
		MissingObjectException, IOException {
	RevObject r;
	int type = ldr.getType();
	switch (type) {
	case Constants.OBJ_COMMIT: {
		final RevCommit c = createCommit(id);
		c.parseCanonical(this, getCachedBytes(c, ldr));
		r = c;
		break;
	}
	case Constants.OBJ_TREE: {
		r = new RevTree(id);
		r.flags |= PARSED;
		break;
	}
	case Constants.OBJ_BLOB: {
		r = new RevBlob(id);
		r.flags |= PARSED;
		break;
	}
	case Constants.OBJ_TAG: {
		final RevTag t = new RevTag(id);
		t.parseCanonical(this, getCachedBytes(t, ldr));
		r = t;
		break;
	}
	default:
		throw new IllegalArgumentException(MessageFormat.format(
				JGitText.get().badObjectType, Integer.valueOf(type)));
	}
	objects.add(r);
	return r;
}
 
Example #19
Source File: DepthWalk.java    From onedev with MIT License 5 votes vote down vote up
/**
 * Mark a root commit (i.e., one whose depth should be considered 0.)
 *
 * @param o
 *            Commit to mark
 * @throws IOException
 * @throws IncorrectObjectTypeException
 * @throws MissingObjectException
 */
public void markRoot(RevObject o) throws MissingObjectException,
		IncorrectObjectTypeException, IOException {
	RevObject c = o;
	while (c instanceof RevTag) {
		c = ((RevTag) c).getObject();
		parseHeaders(c);
	}
	if (c instanceof Commit)
		((Commit) c).depth = 0;
	super.markStart(o);
}
 
Example #20
Source File: BoundaryGenerator.java    From onedev with MIT License 5 votes vote down vote up
@Override
RevCommit next() throws MissingObjectException,
		IncorrectObjectTypeException, IOException {
	RevCommit c = source.next();
	if (c != null) {
		for (int i = 0; i < c.parents.length; i++) {
			if (firstParent && i > 0) {
				break;
			}
			RevCommit p = c.parents[i];
			if ((p.flags & UNINTERESTING) != 0) {
				held.add(p);
			}
		}
		return c;
	}

	final FIFORevQueue boundary = new FIFORevQueue(firstParent);
	boundary.shareFreeList(held);
	for (;;) {
		c = held.next();
		if (c == null)
			break;
		if ((c.flags & DUPLICATE) != 0)
			continue;
		if ((c.flags & PARSED) == 0)
			c.parseHeaders(walk);
		c.flags |= DUPLICATE;
		boundary.add(c);
	}
	boundary.removeFlag(DUPLICATE);
	g = boundary;
	return boundary.next();
}
 
Example #21
Source File: BitmappedReachabilityChecker.java    From onedev with MIT License 5 votes vote down vote up
/**
 * Check all targets are reachable from the starters.
 * <p>
 * In this implementation, it is recommended to put the most popular
 * starters (e.g. refs/heads tips) at the beginning.
 */
@Override
public Optional<RevCommit> areAllReachable(Collection<RevCommit> targets,
		Stream<RevCommit> starters) throws MissingObjectException,
		IncorrectObjectTypeException, IOException {

	List<RevCommit> remainingTargets = new ArrayList<>(targets);

	walk.reset();
	walk.sort(RevSort.TOPO);

	// Filter emits only commits that are unreachable from previously
	// visited commits. Internally it keeps a bitmap of everything
	// reachable so far, which we use to discard reachable targets.
	BitmapIndex repoBitmaps = walk.getObjectReader().getBitmapIndex();
	ReachedFilter reachedFilter = new ReachedFilter(repoBitmaps);
	walk.setRevFilter(reachedFilter);

	Iterator<RevCommit> startersIter = starters.iterator();
	while (startersIter.hasNext()) {
		walk.markStart(startersIter.next());
		while (walk.next() != null) {
			remainingTargets.removeIf(reachedFilter::isReachable);

			if (remainingTargets.isEmpty()) {
				return Optional.empty();
			}
		}
		walk.reset();
	}

	return Optional.of(remainingTargets.get(0));
}
 
Example #22
Source File: BlockRevQueue.java    From onedev with MIT License 5 votes vote down vote up
BlockRevQueue(Generator s) throws MissingObjectException,
		IncorrectObjectTypeException, IOException {
	super(s.firstParent);
	free = new BlockFreeList();
	outputType = s.outputType();
	s.shareFreeList(this);
	for (;;) {
		final RevCommit c = s.next();
		if (c == null)
			break;
		add(c);
	}
}
 
Example #23
Source File: RevTag.java    From onedev with MIT License 5 votes vote down vote up
@Override
void parseBody(RevWalk walk) throws MissingObjectException,
		IncorrectObjectTypeException, IOException {
	if (buffer == null) {
		buffer = walk.getCachedBytes(this);
		if ((flags & PARSED) == 0)
			parseCanonical(walk, buffer);
	}
}
 
Example #24
Source File: RevBlob.java    From onedev with MIT License 5 votes vote down vote up
@Override
void parseHeaders(RevWalk walk) throws MissingObjectException,
		IncorrectObjectTypeException, IOException {
	if (walk.reader.has(this))
		flags |= PARSED;
	else
		throw new MissingObjectException(this, getType());
}
 
Example #25
Source File: TopoSortGenerator.java    From onedev with MIT License 5 votes vote down vote up
@Override
RevCommit next() throws MissingObjectException,
		IncorrectObjectTypeException, IOException {
	for (;;) {
		final RevCommit c = pending.next();
		if (c == null)
			return null;

		if (c.inDegree > 0) {
			// At least one of our children is missing. We delay
			// production until all of our children are output.
			//
			c.flags |= TOPO_DELAY;
			continue;
		}

		// All of our children have already produced,
		// so it is OK for us to produce now as well.
		//
		for (RevCommit p : c.parents) {
			if (--p.inDegree == 0 && (p.flags & TOPO_DELAY) != 0) {
				// This parent tried to come before us, but we are
				// his last child. unpop the parent so it goes right
				// behind this child.
				//
				p.flags &= ~TOPO_DELAY;
				pending.unpop(p);
			}
			if (firstParent) {
				break;
			}
		}
		return c;
	}
}
 
Example #26
Source File: SubStringRevFilter.java    From onedev with MIT License 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public boolean include(RevWalk walker, RevCommit cmit)
		throws MissingObjectException, IncorrectObjectTypeException,
		IOException {
	return pattern.match(text(cmit)) >= 0;
}
 
Example #27
Source File: FixUninterestingGenerator.java    From onedev with MIT License 5 votes vote down vote up
@Override
RevCommit next() throws MissingObjectException,
		IncorrectObjectTypeException, IOException {
	for (;;) {
		final RevCommit c = pending.next();
		if (c == null)
			return null;
		if ((c.flags & RevWalk.UNINTERESTING) == 0)
			return c;
	}
}
 
Example #28
Source File: FollowFilter.java    From onedev with MIT License 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public boolean include(TreeWalk walker)
		throws MissingObjectException, IncorrectObjectTypeException,
		IOException {
	return path.include(walker) && ANY_DIFF.include(walker);
}
 
Example #29
Source File: RevCommit.java    From onedev with MIT License 5 votes vote down vote up
@Override
void parseBody(RevWalk walk) throws MissingObjectException,
		IncorrectObjectTypeException, IOException {
	if (buffer == null) {
		buffer = walk.getCachedBytes(this);
		if ((flags & PARSED) == 0)
			parseCanonical(walk, buffer);
	}
}
 
Example #30
Source File: RevWalkUtils.java    From onedev with MIT License 5 votes vote down vote up
/**
 * Find the list of branches a given commit is reachable from when following
 * parents.
 * <p>
 * Note that this method calls
 * {@link org.eclipse.jgit.revwalk.RevWalk#reset()} at the beginning.
 * <p>
 * In order to improve performance this method assumes clock skew among
 * committers is never larger than 24 hours.
 *
 * @param commit
 *            the commit we are looking at
 * @param revWalk
 *            The RevWalk to be used.
 * @param refs
 *            the set of branches we want to see reachability from
 * @param monitor
 *            the callback for progress and cancellation
 * @return the list of branches a given commit is reachable from
 * @throws org.eclipse.jgit.errors.MissingObjectException
 * @throws org.eclipse.jgit.errors.IncorrectObjectTypeException
 * @throws java.io.IOException
 * @since 5.4
 */
public static List<Ref> findBranchesReachableFrom(RevCommit commit,
		RevWalk revWalk, Collection<Ref> refs, ProgressMonitor monitor)
		throws MissingObjectException, IncorrectObjectTypeException,
		IOException {

	// Make sure commit is from the same RevWalk
	commit = revWalk.parseCommit(commit.getId());
	revWalk.reset();
	List<Ref> result = new ArrayList<>();
	monitor.beginTask(JGitText.get().searchForReachableBranches,
			refs.size());
	final int SKEW = 24*3600; // one day clock skew

	for (Ref ref : refs) {
		if (monitor.isCancelled())
			return result;
		monitor.update(1);
		RevObject maybehead = revWalk.parseAny(ref.getObjectId());
		if (!(maybehead instanceof RevCommit))
			continue;
		RevCommit headCommit = (RevCommit) maybehead;

		// if commit is in the ref branch, then the tip of ref should be
		// newer than the commit we are looking for. Allow for a large
		// clock skew.
		if (headCommit.getCommitTime() + SKEW < commit.getCommitTime())
			continue;

		if (revWalk.isMergedInto(commit, headCommit))
			result.add(ref);
	}
	monitor.endTask();
	return result;
}