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 Project: onedev   Author: theonedev   File: RevWalk.java    License: 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 Project: onedev   Author: theonedev   File: ObjectWalk.java    License: 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 Project: onedev   Author: theonedev   File: ObjectWalk.java    License: 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 Project: onedev   Author: theonedev   File: TopoSortGenerator.java    License: 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 Project: onedev   Author: theonedev   File: PedestrianReachabilityChecker.java    License: 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 #6
Source Project: onedev   Author: theonedev   File: Merger.java    License: 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 #7
Source Project: MergeProcessor   Author: aposin   File: GitMergeUtil.java    License: 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 #8
Source Project: onedev   Author: theonedev   File: MergeBaseGenerator.java    License: 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 #9
Source Project: onedev   Author: theonedev   File: DateRevQueue.java    License: 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 #10
Source Project: onedev   Author: theonedev   File: TreeRevFilter.java    License: 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 Project: onedev   Author: theonedev   File: RevTree.java    License: 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 #12
Source Project: onedev   Author: theonedev   File: RevTag.java    License: 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 #13
Source Project: onedev   Author: theonedev   File: RevBlob.java    License: 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 #14
Source Project: onedev   Author: theonedev   File: FixUninterestingGenerator.java    License: 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 #15
Source Project: onedev   Author: theonedev   File: FollowFilter.java    License: 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 #16
Source Project: onedev   Author: theonedev   File: RevCommit.java    License: 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 #17
Source Project: onedev   Author: theonedev   File: RevWalkUtils.java    License: 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 #18
Source Project: onedev   Author: theonedev   File: TopoSortGenerator.java    License: 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 #19
Source Project: onedev   Author: theonedev   File: BlockRevQueue.java    License: 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 #20
Source Project: onedev   Author: theonedev   File: BitmappedReachabilityChecker.java    License: 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 #21
Source Project: onedev   Author: theonedev   File: BoundaryGenerator.java    License: 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 #22
Source Project: onedev   Author: theonedev   File: DepthWalk.java    License: 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 Project: onedev   Author: theonedev   File: RewriteGenerator.java    License: 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 #24
Source Project: onedev   Author: theonedev   File: OrRevFilter.java    License: 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 #25
Source Project: onedev   Author: theonedev   File: AndRevFilter.java    License: 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 #26
Source Project: onedev   Author: theonedev   File: CommitTimeRevFilter.java    License: 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 #27
Source Project: onedev   Author: theonedev   File: MaxCountRevFilter.java    License: 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 #28
Source Project: onedev   Author: theonedev   File: PatternMatchRevFilter.java    License: 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 #29
Source Project: onedev   Author: theonedev   File: NotRevFilter.java    License: 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 #30
Source Project: onedev   Author: theonedev   File: SkipRevFilter.java    License: 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;
}