org.eclipse.jgit.errors.IncorrectObjectTypeException Java Examples

The following examples show how to use org.eclipse.jgit.errors.IncorrectObjectTypeException. 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: 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 #2
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 #3
Source File: PedestrianReachabilityChecker.java    From onedev with MIT License 6 votes vote down vote up
@Override
public Optional<RevCommit> areAllReachable(Collection<RevCommit> targets,
		Stream<RevCommit> starters)
				throws MissingObjectException, IncorrectObjectTypeException,
				IOException {
	walk.reset();
	if (topoSort) {
		walk.sort(RevSort.TOPO);
	}

	for (RevCommit target: targets) {
		walk.markStart(target);
	}

	Iterator<RevCommit> iterator = starters.iterator();
	while (iterator.hasNext()) {
		walk.markUninteresting(iterator.next());
	}

	return Optional.ofNullable(walk.next());
}
 
Example #4
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 #5
Source File: Merger.java    From onedev with MIT License 6 votes vote down vote up
/**
 * Return the merge base of two commits.
 *
 * @param a
 *            the first commit in {@link #sourceObjects}.
 * @param b
 *            the second commit in {@link #sourceObjects}.
 * @return the merge base of two commits
 * @throws org.eclipse.jgit.errors.IncorrectObjectTypeException
 *             one of the input objects is not a commit.
 * @throws java.io.IOException
 *             objects are missing or multiple merge bases were found.
 * @since 3.0
 */
protected RevCommit getBaseCommit(RevCommit a, RevCommit b)
		throws IncorrectObjectTypeException, IOException {
	walk.reset();
	walk.setRevFilter(RevFilter.MERGE_BASE);
	walk.markStart(a);
	walk.markStart(b);
	final RevCommit base = walk.next();
	if (base == null)
		return null;
	final RevCommit base2 = walk.next();
	if (base2 != null) {
		throw new NoMergeBaseException(
				MergeBaseFailureReason.MULTIPLE_MERGE_BASES_NOT_SUPPORTED,
				MessageFormat.format(
				JGitText.get().multipleMergeBasesFor, a.name(), b.name(),
				base.name(), base2.name()));
	}
	return base;
}
 
Example #6
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 #7
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 #8
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 #9
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 #10
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 #11
Source File: Merger.java    From onedev with MIT License 5 votes vote down vote up
/**
 * Merge together two or more tree-ish objects.
 * <p>
 * Any tree-ish may be supplied as inputs. Commits and/or tags pointing at
 * trees or commits may be passed as input objects.
 *
 * @since 3.5
 * @param flush
 *            whether to flush and close the underlying object inserter when
 *            finished to store any content-merged blobs and virtual merged
 *            bases; if false, callers are responsible for flushing.
 * @param tips
 *            source trees to be combined together. The merge base is not
 *            included in this set.
 * @return true if the merge was completed without conflicts; false if the
 *         merge strategy cannot handle this merge or there were conflicts
 *         preventing it from automatically resolving all paths.
 * @throws IncorrectObjectTypeException
 *             one of the input objects is not a commit, but the strategy
 *             requires it to be a commit.
 * @throws java.io.IOException
 *             one or more sources could not be read, or outputs could not
 *             be written to the Repository.
 */
public boolean merge(boolean flush, AnyObjectId... tips)
		throws IOException {
	sourceObjects = new RevObject[tips.length];
	for (int i = 0; i < tips.length; i++)
		sourceObjects[i] = walk.parseAny(tips[i]);

	sourceCommits = new RevCommit[sourceObjects.length];
	for (int i = 0; i < sourceObjects.length; i++) {
		try {
			sourceCommits[i] = walk.parseCommit(sourceObjects[i]);
		} catch (IncorrectObjectTypeException err) {
			sourceCommits[i] = null;
		}
	}

	sourceTrees = new RevTree[sourceObjects.length];
	for (int i = 0; i < sourceObjects.length; i++)
		sourceTrees[i] = walk.parseTree(sourceObjects[i]);

	try {
		boolean ok = mergeImpl();
		if (ok && flush)
			inserter.flush();
		return ok;
	} finally {
		if (flush)
			inserter.close();
		reader.close();
	}
}
 
Example #12
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 #13
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 #14
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 #15
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 #16
Source File: GitMergeUtil.java    From MergeProcessor with Apache License 2.0 5 votes vote down vote up
/**
 * Evaluate the commit message for the merge unit.
 */
private void evaluteCommitMessage() {
	final String localBranch = getLocalSourceBranch();
	if (localBranch == null) {
		return;
	}
	try {
		final List<Ref> branchListResult = repo.branchList().call();
		final boolean localBranchExists = branchListResult.stream()
				.anyMatch(ref -> ref.getName().endsWith(localBranch));
		CheckoutCommand branchCmd = repo.checkout().setName(localBranch);
		if (!localBranchExists) {
			branchCmd = branchCmd.setCreateBranch(true).setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM)
					.setStartPoint(mergeUnit.getBranchSource());
		}
		branchCmd.call();

		final ObjectId id = ObjectId.fromString(mergeUnit.getRevisionInfo());
		commitMessage = repo.log().add(id).call().iterator().next().getFullMessage();
		/*
		 * Remove merge processor commit information, if the commmit is done by merge
		 * processor e.g. MP [29c64cf540d8f3ea116c3683eade862c3d996dfb] V1.1 -> master:
		 * (2018-03-06 12:17:22)
		 */
		commitMessage = commitMessage.replaceAll("MP \\[[A-Za-z0-9]*\\] .* -> .*: \\(.*\\) ", ""); //$NON-NLS-1$ //$NON-NLS-2$
	} catch (GitAPIException | MissingObjectException | IncorrectObjectTypeException e) {
		exception = new MergeUnitException(String.format("Could not checkout branch '%s'", localBranch), e); //$NON-NLS-1$
	}
}
 
Example #17
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 #18
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 #19
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 #20
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 #21
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 #22
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 #23
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 #24
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 #25
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 #26
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 #27
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 #28
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 #29
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;
}
 
Example #30
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;
	}
}