import java.io.ByteArrayOutputStream;
+import org.eclipse.jgit.errors.CorruptObjectException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.RepositoryTestCase;
+import org.eclipse.jgit.lib.Tag;
public class RevTagParseTest extends RepositoryTestCase {
public void testTagBlob() throws Exception {
assertEquals(shortMsg, c.getShortMessage());
}
+ public void testParse_PublicParseMethod() throws CorruptObjectException {
+ ObjectInserter.Formatter fmt = new ObjectInserter.Formatter();
+ Tag src = new Tag();
+ src.setObjectId(fmt.idFor(Constants.OBJ_TREE, new byte[] {}),
+ Constants.OBJ_TREE);
+ src.setTagger(committer);
+ src.setTag("a.test");
+ src.setMessage("Test tag\n\nThis is a test.\n");
+
+ RevTag p = RevTag.parse(fmt.format(src));
+ assertEquals(src.getObjectId(), p.getObject());
+ assertEquals(committer, p.getTaggerIdent());
+ assertEquals("a.test", p.getTagName());
+ assertEquals("Test tag", p.getShortMessage());
+ assertEquals(src.getMessage(), p.getFullMessage());
+ }
+
private static ObjectId id(final String str) {
return ObjectId.fromString(str);
}
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.ObjectInserter;
+import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.util.MutableInteger;
import org.eclipse.jgit.util.RawParseUtils;
/** An annotated tag. */
public class RevTag extends RevObject {
+ /**
+ * 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 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 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);
+ }
+
+ /**
+ * Parse an annotated tag from its canonical format.
+ *
+ * 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.
+ *
+ * @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.
+ * @return the parsed tag, in an isolated revision pool that is not
+ * available to the caller.
+ * @throws CorruptObjectException
+ * the tag contains a malformed header that cannot be handled.
+ */
+ public static RevTag parse(RevWalk rw, byte[] raw)
+ throws CorruptObjectException {
+ ObjectInserter.Formatter fmt = new ObjectInserter.Formatter();
+ boolean retain = rw.isRetainBody();
+ rw.setRetainBody(true);
+ RevTag r = rw.lookupTag(fmt.idFor(Constants.OBJ_TAG, raw));
+ r.parseCanonical(rw, raw);
+ rw.setRetainBody(retain);
+ return r;
+ }
+
private RevObject object;
private byte[] buffer;