org.eclipse.jgit.errors.CorruptObjectException Java Examples

The following examples show how to use org.eclipse.jgit.errors.CorruptObjectException. 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: RevTag.java    From onedev with MIT License 6 votes vote down vote up
void parseCanonical(RevWalk walk, byte[] rawTag)
		throws CorruptObjectException {
	final MutableInteger pos = new MutableInteger();
	final int oType;

	pos.value = 53; // "object $sha1\ntype "
	oType = Constants.decodeTypeString(this, rawTag, (byte) '\n', pos);
	walk.idBuffer.fromString(rawTag, 7);
	object = walk.lookupAny(walk.idBuffer, oType);

	int p = pos.value += 4; // "tag "
	final int nameEnd = RawParseUtils.nextLF(rawTag, p) - 1;
	tagName = RawParseUtils.decode(UTF_8, rawTag, p, nameEnd);

	if (walk.isRetainBody())
		buffer = rawTag;
	flags |= PARSED;
}
 
Example #2
Source File: ResolveMerger.java    From onedev with MIT License 6 votes vote down vote up
/**
 * Reverts the worktree after an unsuccessful merge. We know that for all
 * modified files the old content was in the old index and the index
 * contained only stage 0. In case if inCore operation just clear the
 * history of modified files.
 *
 * @throws java.io.IOException
 * @throws org.eclipse.jgit.errors.CorruptObjectException
 * @throws org.eclipse.jgit.errors.NoWorkTreeException
 * @since 3.4
 */
protected void cleanUp() throws NoWorkTreeException,
		CorruptObjectException,
		IOException {
	if (inCore) {
		modifiedFiles.clear();
		return;
	}

	DirCache dc = nonNullRepo().readDirCache();
	Iterator<String> mpathsIt=modifiedFiles.iterator();
	while(mpathsIt.hasNext()) {
		String mpath = mpathsIt.next();
		DirCacheEntry entry = dc.getEntry(mpath);
		if (entry != null) {
			DirCacheCheckout.checkoutEntry(db, entry, reader, false,
					checkoutMetadata.get(mpath));
		}
		mpathsIt.remove();
	}
}
 
Example #3
Source File: RepositoryPGit.java    From coming with MIT License 6 votes vote down vote up
protected void detectRenames(RevTree revTree)
		throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException {
	TreeWalk tw = new TreeWalk(repository);
	tw.setRecursive(true);
	tw.addTree(revTree);
	tw.addTree(new FileTreeIterator(repository));
	RenameDetector rd = new RenameDetector(repository);
	rd.addAll(DiffEntry.scan(tw));

	List<DiffEntry> lde = rd.compute(/* tw.getObjectReader(), null */);
	for (DiffEntry de : lde) {
		if (de.getScore() >= rd.getRenameScore()) {
			System.out.println("file: " + de.getOldPath() + " copied/moved to: " + de.getNewPath() + " ");
		}
	}
}
 
Example #4
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 #5
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 #6
Source File: GitNoteWriter.java    From git-appraise-eclipse with Eclipse Public License 1.0 5 votes vote down vote up
private void updateRef() throws IOException, InterruptedException, RuntimeException,
                                MissingObjectException, IncorrectObjectTypeException,
                                CorruptObjectException {
  if (baseCommit != null && oursCommit.getTree().equals(baseCommit.getTree())) {
    // If the trees are identical, there is no change in the notes.
    // Avoid saving this commit as it has no new information.
    return;
  }

  int remainingLockFailureCalls = JgitUtils.MAX_LOCK_FAILURE_CALLS;
  RefUpdate refUpdate = JgitUtils.updateRef(repo, oursCommit, baseCommit, ref);

  for (;;) {
    Result result = refUpdate.update();

    if (result == Result.LOCK_FAILURE) {
      if (--remainingLockFailureCalls > 0) {
        Thread.sleep(JgitUtils.SLEEP_ON_LOCK_FAILURE_MS);
      } else {
        throw new RuntimeException("Failed to lock the ref: " + ref);
      }

    } else if (result == Result.REJECTED) {
      RevCommit theirsCommit = revWalk.parseCommit(refUpdate.getOldObjectId());
      NoteMap theirs = NoteMap.read(revWalk.getObjectReader(), theirsCommit);
      NoteMapMerger merger = new NoteMapMerger(repo);
      NoteMap merged = merger.merge(base, ours, theirs);
      RevCommit mergeCommit =
          createCommit(merged, author, "Merged note records\n", theirsCommit, oursCommit);
      refUpdate = JgitUtils.updateRef(repo, mergeCommit, theirsCommit, ref);
      remainingLockFailureCalls = JgitUtils.MAX_LOCK_FAILURE_CALLS;

    } else if (result == Result.IO_FAILURE) {
      throw new RuntimeException("Couldn't create notes because of IO_FAILURE");
    } else {
      break;
    }
  }
}
 
Example #7
Source File: ObjectWalk.java    From onedev with MIT License 4 votes vote down vote up
private void markTreeUninteresting(RevTree tree)
		throws MissingObjectException, IncorrectObjectTypeException,
		IOException {
	if ((tree.flags & UNINTERESTING) != 0)
		return;
	tree.flags |= UNINTERESTING;

	byte[] raw = reader.open(tree, OBJ_TREE).getCachedBytes();
	for (int ptr = 0; ptr < raw.length;) {
		byte c = raw[ptr];
		int mode = c - '0';
		for (;;) {
			c = raw[++ptr];
			if (' ' == c)
				break;
			mode <<= 3;
			mode += c - '0';
		}
		while (raw[++ptr] != 0) {
			// Skip entry name.
		}
		ptr++; // Skip NUL after entry name.

		switch (mode >>> TYPE_SHIFT) {
		case TYPE_FILE:
		case TYPE_SYMLINK:
			idBuffer.fromRaw(raw, ptr);
			lookupBlob(idBuffer).flags |= UNINTERESTING;
			break;

		case TYPE_TREE:
			idBuffer.fromRaw(raw, ptr);
			markTreeUninteresting(lookupTree(idBuffer));
			break;

		case TYPE_GITLINK:
			break;

		default:
			idBuffer.fromRaw(raw, ptr);
			throw new CorruptObjectException(MessageFormat.format(
					JGitText.get().corruptObjectInvalidMode3,
					String.format("%o", Integer.valueOf(mode)), //$NON-NLS-1$
					idBuffer.name(), "", tree)); //$NON-NLS-1$
		}
		ptr += ID_SZ;
	}
}
 
Example #8
Source File: RevTag.java    From onedev with MIT License 3 votes vote down vote up
/**
 * Parse an annotated tag from its canonical format.
 * <p>
 * This method inserts the tag directly into the caller supplied revision
 * pool, making it appear as though the tag exists in the repository, even
 * if it doesn't. The repository under the pool is not affected.
 * <p>
 * The body of the tag (message, tagger, signature) is always retained in
 * the returned {@code RevTag}, even if the supplied {@code RevWalk} has
 * been configured with {@code setRetainBody(false)}.
 *
 * @param rw
 *            the revision pool to allocate the tag within. The tag's object
 *            pointer will be obtained from this pool.
 * @param raw
 *            the canonical formatted tag to be parsed. This buffer will be
 *            retained by the returned {@code RevTag} and must not be
 *            modified by the caller.
 * @return the parsed tag, in an isolated revision pool that is not
 *         available to the caller.
 * @throws org.eclipse.jgit.errors.CorruptObjectException
 *             the tag contains a malformed header that cannot be handled.
 */
public static RevTag parse(RevWalk rw, byte[] raw)
		throws CorruptObjectException {
	try (ObjectInserter.Formatter fmt = new ObjectInserter.Formatter()) {
		RevTag r = rw.lookupTag(fmt.idFor(Constants.OBJ_TAG, raw));
		r.parseCanonical(rw, raw);
		r.buffer = raw;
		return r;
	}
}
 
Example #9
Source File: RevTag.java    From onedev with MIT License 2 votes vote down vote up
/**
 * Parse an annotated tag from its canonical format.
 *
 * This method constructs a temporary revision pool, parses the tag as
 * supplied, and returns it to the caller. Since the tag was built inside of
 * a private revision pool its object pointer will be initialized, but will
 * not have its headers loaded.
 *
 * Applications are discouraged from using this API. Callers usually need
 * more than one object. Use
 * {@link org.eclipse.jgit.revwalk.RevWalk#parseTag(AnyObjectId)} to obtain
 * a RevTag from an existing repository.
 *
 * @param raw
 *            the canonical formatted tag to be parsed.
 * @return the parsed tag, in an isolated revision pool that is not
 *         available to the caller.
 * @throws org.eclipse.jgit.errors.CorruptObjectException
 *             the tag contains a malformed header that cannot be handled.
 */
public static RevTag parse(byte[] raw) throws CorruptObjectException {
	return parse(new RevWalk((ObjectReader) null), raw);
}