import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.errors.ObjectWritingException;
import org.eclipse.jgit.lib.AnyObjectId;
-import org.eclipse.jgit.lib.Commit;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.RefWriter;
import org.eclipse.jgit.lib.Repository;
-import org.eclipse.jgit.lib.Tag;
+import org.eclipse.jgit.lib.TagBuilder;
import org.eclipse.jgit.revwalk.ObjectWalk;
import org.eclipse.jgit.revwalk.RevBlob;
import org.eclipse.jgit.revwalk.RevCommit;
final RevCommit... parents) throws Exception {
tick(secDelta);
- final Commit c = new Commit();
+ final org.eclipse.jgit.lib.CommitBuilder c;
+
+ c = new org.eclipse.jgit.lib.CommitBuilder();
c.setTreeId(tree);
c.setParentIds(parents);
c.setAuthor(new PersonIdent(author, new Date(now)));
* @throws Exception
*/
public RevTag tag(final String name, final RevObject dst) throws Exception {
- final Tag t = new Tag();
+ final TagBuilder t = new TagBuilder();
t.setObjectId(dst);
t.setTag(name);
t.setTagger(new PersonIdent(committer, new Date(now)));
if (self == null) {
TestRepository.this.tick(tick);
- final Commit c = new Commit();
+ final org.eclipse.jgit.lib.CommitBuilder c;
+
+ c = new org.eclipse.jgit.lib.CommitBuilder();
c.setParentIds(parents);
c.setAuthor(new PersonIdent(author, new Date(now)));
c.setCommitter(new PersonIdent(committer, new Date(now)));
final ObjectInserter inserter = db.newObjectInserter();
final ObjectId id;
try {
- org.eclipse.jgit.lib.Tag tag = new org.eclipse.jgit.lib.Tag();
+ final org.eclipse.jgit.lib.TagBuilder tag;
+
+ tag = new org.eclipse.jgit.lib.TagBuilder();
tag.setObjectId(object, ldr.getType());
tag.setTagger(new PersonIdent(db));
tag.setMessage(message.replaceAll("\r", ""));
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.errors.ObjectWritingException;
-import org.eclipse.jgit.lib.Commit;
+import org.eclipse.jgit.lib.CommitBuilder;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectIdRef;
}
}
- final Commit newc = new Commit();
+ final CommitBuilder newc = new CommitBuilder();
newc.setTreeId(emptyTree);
newc.setAuthor(new PersonIdent(me, new Date(t.commitTime)));
newc.setCommitter(newc.getAuthor());
private void commit(final Tree t, String commitMsg, PersonIdent author,
PersonIdent committer) throws IOException {
- final Commit commit = new Commit();
+ final CommitBuilder commit = new CommitBuilder();
commit.setAuthor(author);
commit.setCommitter(committer);
commit.setMessage(commitMsg);
import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheBuilder;
import org.eclipse.jgit.dircache.DirCacheEntry;
-import org.eclipse.jgit.lib.Commit;
+import org.eclipse.jgit.lib.CommitBuilder;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectId;
private ObjectId commit(final ObjectInserter odi, final DirCache treeB,
final ObjectId[] parentIds) throws Exception {
- final Commit c = new Commit();
+ final CommitBuilder c = new CommitBuilder();
c.setTreeId(treeB.writeTree(odi));
c.setAuthor(new PersonIdent("A U Thor", "a.u.thor", 1L, 0));
c.setCommitter(c.getAuthor());
import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheBuilder;
import org.eclipse.jgit.dircache.DirCacheEntry;
-import org.eclipse.jgit.lib.Commit;
+import org.eclipse.jgit.lib.CommitBuilder;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectId;
private ObjectId commit(final ObjectInserter odi, final DirCache treeB,
final ObjectId[] parentIds) throws Exception {
- final Commit c = new Commit();
+ final CommitBuilder c = new CommitBuilder();
c.setTreeId(treeB.writeTree(odi));
c.setAuthor(new PersonIdent("A U Thor", "a.u.thor", 1L, 0));
c.setCommitter(c.getAuthor());
import java.io.ByteArrayOutputStream;
import java.io.UnsupportedEncodingException;
-import org.eclipse.jgit.lib.Commit;
+import org.eclipse.jgit.lib.CommitBuilder;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectInserter;
public void testParse_PublicParseMethod()
throws UnsupportedEncodingException {
ObjectInserter.Formatter fmt = new ObjectInserter.Formatter();
- Commit src = new Commit();
+ CommitBuilder src = new CommitBuilder();
src.setTreeId(fmt.idFor(Constants.OBJ_TREE, new byte[] {}));
src.setAuthor(author);
src.setCommitter(committer);
import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.RepositoryTestCase;
-import org.eclipse.jgit.lib.Tag;
+import org.eclipse.jgit.lib.TagBuilder;
public class RevTagParseTest extends RepositoryTestCase {
public void testTagBlob() throws Exception {
public void testParse_PublicParseMethod() throws CorruptObjectException {
ObjectInserter.Formatter fmt = new ObjectInserter.Formatter();
- Tag src = new Tag();
+ TagBuilder src = new TagBuilder();
src.setObjectId(fmt.idFor(Constants.OBJ_TREE, new byte[] {}),
Constants.OBJ_TREE);
src.setTagger(committer);
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.lib.AnyObjectId;
-import org.eclipse.jgit.lib.Commit;
+import org.eclipse.jgit.lib.CommitBuilder;
import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileTreeEntry;
import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.SampleDataRepositoryTestCase;
-import org.eclipse.jgit.lib.Tag;
+import org.eclipse.jgit.lib.TagBuilder;
import org.eclipse.jgit.lib.Tree;
import org.eclipse.jgit.lib.TreeEntry;
import org.eclipse.jgit.lib.WriteTree;
assertEquals(ObjectId.fromString("00b1f73724f493096d1ffa0b0f1f1482dbb8c936"),
t.getTreeId());
- final Commit c = new Commit();
+ final CommitBuilder c = new CommitBuilder();
c.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60));
c.setCommitter(new PersonIdent(committer, 1154236443000L, -4 * 60));
c.setMessage("A Commit\n");
public void test020_createBlobTag() throws IOException {
final ObjectId emptyId = new ObjectWriter(db).writeBlob(new byte[0]);
- final Tag t = new Tag();
+ final TagBuilder t = new TagBuilder();
t.setObjectId(emptyId, Constants.OBJ_BLOB);
t.setTag("test020");
t.setTagger(new PersonIdent(author, 1154236443000L, -4 * 60));
final Tree almostEmptyTree = new Tree(db);
almostEmptyTree.addEntry(new FileTreeEntry(almostEmptyTree, emptyId, "empty".getBytes(), false));
final ObjectId almostEmptyTreeId = new ObjectWriter(db).writeTree(almostEmptyTree);
- final Tag t = new Tag();
+ final TagBuilder t = new TagBuilder();
t.setObjectId(almostEmptyTreeId, Constants.OBJ_TREE);
t.setTag("test021");
t.setTagger(new PersonIdent(author, 1154236443000L, -4 * 60));
final Tree almostEmptyTree = new Tree(db);
almostEmptyTree.addEntry(new FileTreeEntry(almostEmptyTree, emptyId, "empty".getBytes(), false));
final ObjectId almostEmptyTreeId = new ObjectWriter(db).writeTree(almostEmptyTree);
- final Commit almostEmptyCommit = new Commit();
+ final CommitBuilder almostEmptyCommit = new CommitBuilder();
almostEmptyCommit.setAuthor(new PersonIdent(author, 1154236443000L, -2 * 60)); // not exactly the same
almostEmptyCommit.setCommitter(new PersonIdent(author, 1154236443000L, -2 * 60));
almostEmptyCommit.setMessage("test022\n");
almostEmptyCommit.setTreeId(almostEmptyTreeId);
ObjectId almostEmptyCommitId = insertCommit(almostEmptyCommit);
- final Tag t = new Tag();
+ final TagBuilder t = new TagBuilder();
t.setObjectId(almostEmptyCommitId,Constants.OBJ_COMMIT);
t.setTag("test022");
t.setTagger(new PersonIdent(author, 1154236443000L, -4 * 60));
final Tree almostEmptyTree = new Tree(db);
almostEmptyTree.addEntry(new FileTreeEntry(almostEmptyTree, emptyId, "empty".getBytes(), false));
final ObjectId almostEmptyTreeId = new ObjectWriter(db).writeTree(almostEmptyTree);
- Commit commit = new Commit();
+ CommitBuilder commit = new CommitBuilder();
commit.setTreeId(almostEmptyTreeId);
commit.setAuthor(new PersonIdent("Joe H\u00e4cker","joe@example.com",4294967295000L,60));
commit.setCommitter(new PersonIdent("Joe Hacker","joe2@example.com",4294967295000L,60));
final Tree almostEmptyTree = new Tree(db);
almostEmptyTree.addEntry(new FileTreeEntry(almostEmptyTree, emptyId, "empty".getBytes(), false));
final ObjectId almostEmptyTreeId = new ObjectWriter(db).writeTree(almostEmptyTree);
- Commit commit = new Commit();
+ CommitBuilder commit = new CommitBuilder();
commit.setTreeId(almostEmptyTreeId);
commit.setAuthor(new PersonIdent("Joe H\u00e4cker","joe@example.com",4294967295000L,60));
commit.setCommitter(new PersonIdent("Joe Hacker","joe2@example.com",4294967295000L,60));
assertEquals(ObjectId.fromString("00b1f73724f493096d1ffa0b0f1f1482dbb8c936"),
t.getTreeId());
- final Commit c1 = new Commit();
+ final CommitBuilder c1 = new CommitBuilder();
c1.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60));
c1.setCommitter(new PersonIdent(committer, 1154236443000L, -4 * 60));
c1.setMessage("A Commit\n");
"803aec4aba175e8ab1d666873c984c0308179099");
assertEquals(cmtid1, c1.getCommitId());
- final Commit c2 = new Commit();
+ final CommitBuilder c2 = new CommitBuilder();
c2.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60));
c2.setCommitter(new PersonIdent(committer, 1154236443000L, -4 * 60));
c2.setMessage("A Commit 2\n");
assertEquals(1, rm2.getParentCount());
assertEquals(c1.getCommitId(), rm2.getParent(0));
- final Commit c3 = new Commit();
+ final CommitBuilder c3 = new CommitBuilder();
c3.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60));
c3.setCommitter(new PersonIdent(committer, 1154236443000L, -4 * 60));
c3.setMessage("A Commit 3\n");
assertEquals(c1.getCommitId(), rm3.getParent(0));
assertEquals(c2.getCommitId(), rm3.getParent(1));
- final Commit c4 = new Commit();
+ final CommitBuilder c4 = new CommitBuilder();
c4.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60));
c4.setCommitter(new PersonIdent(committer, 1154236443000L, -4 * 60));
c4.setMessage("A Commit 4\n");
}
- private ObjectId insertCommit(final Commit commit) throws IOException,
+ private ObjectId insertCommit(final CommitBuilder commit) throws IOException,
UnsupportedEncodingException {
ObjectInserter oi = db.newObjectInserter();
try {
}
}
- private ObjectId insertTag(final Tag tag) throws IOException,
+ private ObjectId insertTag(final TagBuilder tag) throws IOException,
UnsupportedEncodingException {
ObjectInserter oi = db.newObjectInserter();
try {
import org.eclipse.jgit.JGitText;
import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.errors.UnmergedPathException;
-import org.eclipse.jgit.lib.Commit;
+import org.eclipse.jgit.lib.CommitBuilder;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectInserter;
* class should only be used for one invocation of the command (means: one
* call to {@link #call()})
*
- * @return a {@link Commit} object representing the successful commit
+ * @return a {@link RevCommit} object representing the successful commit.
* @throws NoHeadException
* when called on a git repo without a HEAD reference
* @throws NoMessageException
ObjectId indexTreeId = index.writeTree(odi);
// Create a Commit object, populate it and write it
- Commit commit = new Commit();
+ CommitBuilder commit = new CommitBuilder();
commit.setCommitter(committer);
commit.setAuthor(author);
commit.setMessage(message);
+++ /dev/null
-/*
- * Copyright (C) 2007, Dave Watson <dwatson@mimvista.com>
- * Copyright (C) 2006-2007, Robin Rosenberg <robin.rosenberg@dewire.com>
- * Copyright (C) 2006-2007, Shawn O. Pearce <spearce@spearce.org>
- * and other copyright owners as documented in the project's IP log.
- *
- * This program and the accompanying materials are made available
- * under the terms of the Eclipse Distribution License v1.0 which
- * accompanies this distribution, is reproduced below, and is
- * available at http://www.eclipse.org/org/documents/edl-v10.php
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or
- * without modification, are permitted provided that the following
- * conditions are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- *
- * - Neither the name of the Eclipse Foundation, Inc. nor the
- * names of its contributors may be used to endorse or promote
- * products derived from this software without specific prior
- * written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-package org.eclipse.jgit.lib;
-
-import java.nio.charset.Charset;
-import java.util.List;
-
-/**
- * Mutable builder to construct a commit recording the state of a project.
- *
- * Applications should use this object when they need to manually construct a
- * commit and want precise control over its fields. For a higher level interface
- * see {@link org.eclipse.jgit.api.CommitCommand}.
- *
- * To read a commit object, construct a {@link org.eclipse.jgit.revwalk.RevWalk}
- * and obtain a {@link org.eclipse.jgit.revwalk.RevCommit} instance by calling
- * {@link org.eclipse.jgit.revwalk.RevWalk#parseCommit(AnyObjectId)}.
- */
-public class Commit {
- private static final ObjectId[] EMPTY_OBJECTID_LIST = new ObjectId[0];
-
- private ObjectId commitId;
-
- private ObjectId treeId;
-
- private ObjectId[] parentIds;
-
- private PersonIdent author;
-
- private PersonIdent committer;
-
- private String message;
-
- private Charset encoding;
-
- /** Initialize an empty commit. */
- public Commit() {
- parentIds = EMPTY_OBJECTID_LIST;
- encoding = Constants.CHARSET;
- }
-
- /** @return this commit's object id. */
- public ObjectId getCommitId() {
- return commitId;
- }
-
- /**
- * Set the id of this commit object.
- *
- * @param id
- * the id that we calculated for this object.
- */
- public void setCommitId(final ObjectId id) {
- commitId = id;
- }
-
- /** @return id of the root tree listing this commit's snapshot. */
- public ObjectId getTreeId() {
- return treeId;
- }
-
- /**
- * Set the tree id for this commit object
- *
- * @param id
- * the tree identity.
- */
- public void setTreeId(AnyObjectId id) {
- treeId = id.copy();
- commitId = null;
- }
-
- /** @return the author of this commit (who wrote it). */
- public PersonIdent getAuthor() {
- return author;
- }
-
- /**
- * Set the author (name, email address, and date) of who wrote the commit.
- *
- * @param newAuthor
- * the new author. Should not be null.
- */
- public void setAuthor(PersonIdent newAuthor) {
- author = newAuthor;
- commitId = null;
- }
-
- /** @return the committer and commit time for this object. */
- public PersonIdent getCommitter() {
- return committer;
- }
-
- /**
- * Set the committer and commit time for this object
- *
- * @param newCommitter
- * the committer information. Should not be null.
- */
- public void setCommitter(PersonIdent newCommitter) {
- committer = newCommitter;
- commitId = null;
- }
-
- /** @return the ancestors of this commit. Never null. */
- public ObjectId[] getParentIds() {
- return parentIds;
- }
-
- /**
- * Set the parent of this commit.
- *
- * @param newParent
- * the single parent for the commit.
- */
- public void setParentId(AnyObjectId newParent) {
- parentIds = new ObjectId[] { newParent.copy() };
- commitId = null;
- }
-
- /**
- * Set the parents of this commit.
- *
- * @param parent1
- * the first parent of this commit. Typically this is the current
- * value of the {@code HEAD} reference and is thus the current
- * branch's position in history.
- * @param parent2
- * the second parent of this merge commit. Usually this is the
- * branch being merged into the current branch.
- */
- public void setParentIds(AnyObjectId parent1, AnyObjectId parent2) {
- parentIds = new ObjectId[] { parent1.copy(), parent2.copy() };
- commitId = null;
- }
-
- /**
- * Set the parents of this commit.
- *
- * @param newParents
- * the entire list of parents for this commit.
- */
- public void setParentIds(ObjectId... newParents) {
- parentIds = new ObjectId[newParents.length];
- for (int i = 0; i < newParents.length; i++)
- parentIds[i] = newParents[i].copy();
- commitId = null;
- }
-
- /**
- * Set the parents of this commit.
- *
- * @param newParents
- * the entire list of parents for this commit.
- */
- public void setParentIds(List<? extends AnyObjectId> newParents) {
- parentIds = new ObjectId[newParents.size()];
- for (int i = 0; i < newParents.size(); i++)
- parentIds[i] = newParents.get(i).copy();
- commitId = null;
- }
-
- /**
- * Add a parent onto the end of the parent list.
- *
- * @param additionalParent
- * new parent to add onto the end of the current parent list.
- */
- public void addParentId(AnyObjectId additionalParent) {
- if (parentIds.length == 0) {
- setParentId(additionalParent);
- } else {
- ObjectId[] newParents = new ObjectId[parentIds.length + 1];
- for (int i = 0; i < parentIds.length; i++)
- newParents[i] = parentIds[i];
- newParents[parentIds.length] = additionalParent.copy();
- parentIds = newParents;
- commitId = null;
- }
- }
-
- /** @return the complete commit message. */
- public String getMessage() {
- return message;
- }
-
- /**
- * Set the commit message.
- *
- * @param newMessage
- * the commit message. Should not be null.
- */
- public void setMessage(final String newMessage) {
- message = newMessage;
- }
-
- /**
- * Set the encoding for the commit information
- *
- * @param encodingName
- * the encoding name. See {@link Charset#forName(String)}.
- */
- public void setEncoding(String encodingName) {
- encoding = Charset.forName(encodingName);
- }
-
- /**
- * Set the encoding for the commit information
- *
- * @param enc
- * the encoding to use.
- */
- public void setEncoding(Charset enc) {
- encoding = enc;
- }
-
- /** @return the encoding that should be used for the commit message text. */
- public Charset getEncoding() {
- return encoding;
- }
-
- @Override
- public String toString() {
- StringBuilder r = new StringBuilder();
- r.append("Commit");
- if (commitId != null)
- r.append("[" + commitId.name() + "]");
- r.append("={\n");
-
- r.append("tree ");
- r.append(treeId != null ? treeId.name() : "NOT_SET");
- r.append("\n");
-
- for (ObjectId p : parentIds) {
- r.append("parent ");
- r.append(p.name());
- r.append("\n");
- }
-
- r.append("author ");
- r.append(author != null ? author.toString() : "NOT_SET");
- r.append("\n");
-
- r.append("committer ");
- r.append(committer != null ? committer.toString() : "NOT_SET");
- r.append("\n");
-
- if (encoding != null && encoding != Constants.CHARSET) {
- r.append("encoding ");
- r.append(encoding.name());
- r.append("\n");
- }
-
- r.append("\n");
- r.append(message != null ? message : "");
- r.append("}");
- return r.toString();
- }
-}
--- /dev/null
+/*
+ * Copyright (C) 2007, Dave Watson <dwatson@mimvista.com>
+ * Copyright (C) 2006-2007, Robin Rosenberg <robin.rosenberg@dewire.com>
+ * Copyright (C) 2006-2007, Shawn O. Pearce <spearce@spearce.org>
+ * and other copyright owners as documented in the project's IP log.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.eclipse.jgit.lib;
+
+import java.nio.charset.Charset;
+import java.util.List;
+
+/**
+ * Mutable builder to construct a commit recording the state of a project.
+ *
+ * Applications should use this object when they need to manually construct a
+ * commit and want precise control over its fields. For a higher level interface
+ * see {@link org.eclipse.jgit.api.CommitCommand}.
+ *
+ * To read a commit object, construct a {@link org.eclipse.jgit.revwalk.RevWalk}
+ * and obtain a {@link org.eclipse.jgit.revwalk.RevCommit} instance by calling
+ * {@link org.eclipse.jgit.revwalk.RevWalk#parseCommit(AnyObjectId)}.
+ */
+public class CommitBuilder {
+ private static final ObjectId[] EMPTY_OBJECTID_LIST = new ObjectId[0];
+
+ private ObjectId commitId;
+
+ private ObjectId treeId;
+
+ private ObjectId[] parentIds;
+
+ private PersonIdent author;
+
+ private PersonIdent committer;
+
+ private String message;
+
+ private Charset encoding;
+
+ /** Initialize an empty commit. */
+ public CommitBuilder() {
+ parentIds = EMPTY_OBJECTID_LIST;
+ encoding = Constants.CHARSET;
+ }
+
+ /** @return this commit's object id. */
+ public ObjectId getCommitId() {
+ return commitId;
+ }
+
+ /**
+ * Set the id of this commit object.
+ *
+ * @param id
+ * the id that we calculated for this object.
+ */
+ public void setCommitId(final ObjectId id) {
+ commitId = id;
+ }
+
+ /** @return id of the root tree listing this commit's snapshot. */
+ public ObjectId getTreeId() {
+ return treeId;
+ }
+
+ /**
+ * Set the tree id for this commit object
+ *
+ * @param id
+ * the tree identity.
+ */
+ public void setTreeId(AnyObjectId id) {
+ treeId = id.copy();
+ commitId = null;
+ }
+
+ /** @return the author of this commit (who wrote it). */
+ public PersonIdent getAuthor() {
+ return author;
+ }
+
+ /**
+ * Set the author (name, email address, and date) of who wrote the commit.
+ *
+ * @param newAuthor
+ * the new author. Should not be null.
+ */
+ public void setAuthor(PersonIdent newAuthor) {
+ author = newAuthor;
+ commitId = null;
+ }
+
+ /** @return the committer and commit time for this object. */
+ public PersonIdent getCommitter() {
+ return committer;
+ }
+
+ /**
+ * Set the committer and commit time for this object
+ *
+ * @param newCommitter
+ * the committer information. Should not be null.
+ */
+ public void setCommitter(PersonIdent newCommitter) {
+ committer = newCommitter;
+ commitId = null;
+ }
+
+ /** @return the ancestors of this commit. Never null. */
+ public ObjectId[] getParentIds() {
+ return parentIds;
+ }
+
+ /**
+ * Set the parent of this commit.
+ *
+ * @param newParent
+ * the single parent for the commit.
+ */
+ public void setParentId(AnyObjectId newParent) {
+ parentIds = new ObjectId[] { newParent.copy() };
+ commitId = null;
+ }
+
+ /**
+ * Set the parents of this commit.
+ *
+ * @param parent1
+ * the first parent of this commit. Typically this is the current
+ * value of the {@code HEAD} reference and is thus the current
+ * branch's position in history.
+ * @param parent2
+ * the second parent of this merge commit. Usually this is the
+ * branch being merged into the current branch.
+ */
+ public void setParentIds(AnyObjectId parent1, AnyObjectId parent2) {
+ parentIds = new ObjectId[] { parent1.copy(), parent2.copy() };
+ commitId = null;
+ }
+
+ /**
+ * Set the parents of this commit.
+ *
+ * @param newParents
+ * the entire list of parents for this commit.
+ */
+ public void setParentIds(ObjectId... newParents) {
+ parentIds = new ObjectId[newParents.length];
+ for (int i = 0; i < newParents.length; i++)
+ parentIds[i] = newParents[i].copy();
+ commitId = null;
+ }
+
+ /**
+ * Set the parents of this commit.
+ *
+ * @param newParents
+ * the entire list of parents for this commit.
+ */
+ public void setParentIds(List<? extends AnyObjectId> newParents) {
+ parentIds = new ObjectId[newParents.size()];
+ for (int i = 0; i < newParents.size(); i++)
+ parentIds[i] = newParents.get(i).copy();
+ commitId = null;
+ }
+
+ /**
+ * Add a parent onto the end of the parent list.
+ *
+ * @param additionalParent
+ * new parent to add onto the end of the current parent list.
+ */
+ public void addParentId(AnyObjectId additionalParent) {
+ if (parentIds.length == 0) {
+ setParentId(additionalParent);
+ } else {
+ ObjectId[] newParents = new ObjectId[parentIds.length + 1];
+ for (int i = 0; i < parentIds.length; i++)
+ newParents[i] = parentIds[i];
+ newParents[parentIds.length] = additionalParent.copy();
+ parentIds = newParents;
+ commitId = null;
+ }
+ }
+
+ /** @return the complete commit message. */
+ public String getMessage() {
+ return message;
+ }
+
+ /**
+ * Set the commit message.
+ *
+ * @param newMessage
+ * the commit message. Should not be null.
+ */
+ public void setMessage(final String newMessage) {
+ message = newMessage;
+ }
+
+ /**
+ * Set the encoding for the commit information
+ *
+ * @param encodingName
+ * the encoding name. See {@link Charset#forName(String)}.
+ */
+ public void setEncoding(String encodingName) {
+ encoding = Charset.forName(encodingName);
+ }
+
+ /**
+ * Set the encoding for the commit information
+ *
+ * @param enc
+ * the encoding to use.
+ */
+ public void setEncoding(Charset enc) {
+ encoding = enc;
+ }
+
+ /** @return the encoding that should be used for the commit message text. */
+ public Charset getEncoding() {
+ return encoding;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder r = new StringBuilder();
+ r.append("Commit");
+ if (commitId != null)
+ r.append("[" + commitId.name() + "]");
+ r.append("={\n");
+
+ r.append("tree ");
+ r.append(treeId != null ? treeId.name() : "NOT_SET");
+ r.append("\n");
+
+ for (ObjectId p : parentIds) {
+ r.append("parent ");
+ r.append(p.name());
+ r.append("\n");
+ }
+
+ r.append("author ");
+ r.append(author != null ? author.toString() : "NOT_SET");
+ r.append("\n");
+
+ r.append("committer ");
+ r.append(committer != null ? committer.toString() : "NOT_SET");
+ r.append("\n");
+
+ if (encoding != null && encoding != Constants.CHARSET) {
+ r.append("encoding ");
+ r.append(encoding.name());
+ r.append("\n");
+ }
+
+ r.append("\n");
+ r.append(message != null ? message : "");
+ r.append("}");
+ return r.toString();
+ }
+}
* @throws UnsupportedEncodingException
* the commit's chosen encoding isn't supported on this JVM.
*/
- public final byte[] format(Commit commit)
+ public final byte[] format(CommitBuilder commit)
throws UnsupportedEncodingException {
Charset encoding = commit.getEncoding();
ByteArrayOutputStream os = new ByteArrayOutputStream();
* the tag object to format
* @return canonical encoding of the tag object.
*/
- public final byte[] format(Tag tag) {
+ public final byte[] format(TagBuilder tag) {
ByteArrayOutputStream os = new ByteArrayOutputStream();
OutputStreamWriter w = new OutputStreamWriter(os, Constants.CHARSET);
try {
* @return SHA-1 of the commit
* @throws IOException
*/
- public ObjectId writeCommit(Commit commit) throws IOException {
+ public ObjectId writeCommit(CommitBuilder commit) throws IOException {
try {
ObjectId id = inserter.insert(OBJ_COMMIT, inserter.format(commit));
inserter.flush();
* @return SHA-1 of the tag
* @throws IOException
*/
- public ObjectId writeTag(Tag tag) throws IOException {
+ public ObjectId writeTag(TagBuilder tag) throws IOException {
try {
ObjectId id = inserter.insert(OBJ_TAG, inserter.format(tag));
inserter.flush();
* file operations triggering a merge will store the IDs of all heads which
* should be merged together with HEAD.
*
- * @return a list of {@link Commit}s which IDs are listed in the MERGE_HEAD
+ * @return a list of commits which IDs are listed in the MERGE_HEAD
* file or {@code null} if this file doesn't exist. Also if the file
* exists but is empty {@code null} will be returned
* @throws IOException
* the file will be deleted
*
* @param heads
- * a list of {@link Commit}s which IDs should be written to
+ * a list of commits which IDs should be written to
* $GIT_DIR/MERGE_HEAD or <code>null</code> to delete the file
* @throws IOException
*/
+++ /dev/null
-/*
- * Copyright (C) 2006-2008, Robin Rosenberg <robin.rosenberg@dewire.com>
- * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
- * Copyright (C) 2010, Chris Aniszczyk <caniszczyk@gmail.com>
- * and other copyright owners as documented in the project's IP log.
- *
- * This program and the accompanying materials are made available
- * under the terms of the Eclipse Distribution License v1.0 which
- * accompanies this distribution, is reproduced below, and is
- * available at http://www.eclipse.org/org/documents/edl-v10.php
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or
- * without modification, are permitted provided that the following
- * conditions are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- *
- * - Neither the name of the Eclipse Foundation, Inc. nor the
- * names of its contributors may be used to endorse or promote
- * products derived from this software without specific prior
- * written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-package org.eclipse.jgit.lib;
-
-import org.eclipse.jgit.revwalk.RevObject;
-
-/**
- * Mutable builder to construct an annotated tag recording a project state.
- *
- * Applications should use this object when they need to manually construct a
- * tag and want precise control over its fields.
- *
- * To read a tag object, construct a {@link org.eclipse.jgit.revwalk.RevWalk}
- * and obtain a {@link org.eclipse.jgit.revwalk.RevTag} instance by calling
- * {@link org.eclipse.jgit.revwalk.RevWalk#parseTag(AnyObjectId)}.
- */
-public class Tag {
- private ObjectId tagId;
-
- private ObjectId object;
-
- private int type = Constants.OBJ_BAD;
-
- private String tag;
-
- private PersonIdent tagger;
-
- private String message;
-
- /** @return this tag's object id. */
- public ObjectId getTagId() {
- return tagId;
- }
-
- /**
- * Set the id of this tag object.
- *
- * @param id
- * the id that we calculated for this object.
- */
- public void setTagId(ObjectId id) {
- tagId = id;
- }
-
- /** @return the type of object this tag refers to. */
- public int getObjectType() {
- return type;
- }
-
- /** @return the object this tag refers to. */
- public ObjectId getObjectId() {
- return object;
- }
-
- /**
- * Set the object this tag refers to, and its type.
- *
- * @param obj
- * the object.
- * @param objType
- * the type of {@code obj}. Must be a valid type code.
- */
- public void setObjectId(AnyObjectId obj, int objType) {
- object = obj.copy();
- type = objType;
- tagId = null;
- }
-
- /**
- * Set the object this tag refers to, and infer its type.
- *
- * @param obj
- * the object the tag will refer to.
- */
- public void setObjectId(RevObject obj) {
- setObjectId(obj, obj.getType());
- }
-
- /** @return short name of the tag (no {@code refs/tags/} prefix). */
- public String getTag() {
- return tag;
- }
-
- /**
- * Set the name of this tag.
- *
- * @param shortName
- * new short name of the tag. This short name should not start
- * with {@code refs/} as typically a tag is stored under the
- * reference derived from {@code "refs/tags/" + getTag()}.
- */
- public void setTag(String shortName) {
- this.tag = shortName;
- tagId = null;
- }
-
- /** @return creator of this tag. May be null. */
- public PersonIdent getTagger() {
- return tagger;
- }
-
- /**
- * Set the creator of this tag.
- *
- * @param taggerIdent
- * the creator. May be null.
- */
- public void setTagger(PersonIdent taggerIdent) {
- tagger = taggerIdent;
- tagId = null;
- }
-
- /** @return the complete commit message. */
- public String getMessage() {
- return message;
- }
-
- /**
- * Set the tag's message.
- *
- * @param newMessage
- * the tag's message.
- */
- public void setMessage(final String newMessage) {
- message = newMessage;
- tagId = null;
- }
-
- @Override
- public String toString() {
- StringBuilder r = new StringBuilder();
- r.append("Tag");
- if (tagId != null)
- r.append("[" + tagId.name() + "]");
- r.append("={\n");
-
- r.append("object ");
- r.append(object != null ? object.name() : "NOT_SET");
- r.append("\n");
-
- r.append("type ");
- r.append(object != null ? Constants.typeString(type) : "NOT_SET");
- r.append("\n");
-
- r.append("tag ");
- r.append(tag != null ? tag : "NOT_SET");
- r.append("\n");
-
- if (tagger != null) {
- r.append("tagger ");
- r.append(tagger);
- r.append("\n");
- }
-
- r.append("\n");
- r.append(message != null ? message : "");
- r.append("}");
- return r.toString();
- }
-}
--- /dev/null
+/*
+ * Copyright (C) 2006-2008, Robin Rosenberg <robin.rosenberg@dewire.com>
+ * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
+ * Copyright (C) 2010, Chris Aniszczyk <caniszczyk@gmail.com>
+ * and other copyright owners as documented in the project's IP log.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.eclipse.jgit.lib;
+
+import org.eclipse.jgit.revwalk.RevObject;
+
+/**
+ * Mutable builder to construct an annotated tag recording a project state.
+ *
+ * Applications should use this object when they need to manually construct a
+ * tag and want precise control over its fields.
+ *
+ * To read a tag object, construct a {@link org.eclipse.jgit.revwalk.RevWalk}
+ * and obtain a {@link org.eclipse.jgit.revwalk.RevTag} instance by calling
+ * {@link org.eclipse.jgit.revwalk.RevWalk#parseTag(AnyObjectId)}.
+ */
+public class TagBuilder {
+ private ObjectId tagId;
+
+ private ObjectId object;
+
+ private int type = Constants.OBJ_BAD;
+
+ private String tag;
+
+ private PersonIdent tagger;
+
+ private String message;
+
+ /** @return this tag's object id. */
+ public ObjectId getTagId() {
+ return tagId;
+ }
+
+ /**
+ * Set the id of this tag object.
+ *
+ * @param id
+ * the id that we calculated for this object.
+ */
+ public void setTagId(ObjectId id) {
+ tagId = id;
+ }
+
+ /** @return the type of object this tag refers to. */
+ public int getObjectType() {
+ return type;
+ }
+
+ /** @return the object this tag refers to. */
+ public ObjectId getObjectId() {
+ return object;
+ }
+
+ /**
+ * Set the object this tag refers to, and its type.
+ *
+ * @param obj
+ * the object.
+ * @param objType
+ * the type of {@code obj}. Must be a valid type code.
+ */
+ public void setObjectId(AnyObjectId obj, int objType) {
+ object = obj.copy();
+ type = objType;
+ tagId = null;
+ }
+
+ /**
+ * Set the object this tag refers to, and infer its type.
+ *
+ * @param obj
+ * the object the tag will refer to.
+ */
+ public void setObjectId(RevObject obj) {
+ setObjectId(obj, obj.getType());
+ }
+
+ /** @return short name of the tag (no {@code refs/tags/} prefix). */
+ public String getTag() {
+ return tag;
+ }
+
+ /**
+ * Set the name of this tag.
+ *
+ * @param shortName
+ * new short name of the tag. This short name should not start
+ * with {@code refs/} as typically a tag is stored under the
+ * reference derived from {@code "refs/tags/" + getTag()}.
+ */
+ public void setTag(String shortName) {
+ this.tag = shortName;
+ tagId = null;
+ }
+
+ /** @return creator of this tag. May be null. */
+ public PersonIdent getTagger() {
+ return tagger;
+ }
+
+ /**
+ * Set the creator of this tag.
+ *
+ * @param taggerIdent
+ * the creator. May be null.
+ */
+ public void setTagger(PersonIdent taggerIdent) {
+ tagger = taggerIdent;
+ tagId = null;
+ }
+
+ /** @return the complete commit message. */
+ public String getMessage() {
+ return message;
+ }
+
+ /**
+ * Set the tag's message.
+ *
+ * @param newMessage
+ * the tag's message.
+ */
+ public void setMessage(final String newMessage) {
+ message = newMessage;
+ tagId = null;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder r = new StringBuilder();
+ r.append("Tag");
+ if (tagId != null)
+ r.append("[" + tagId.name() + "]");
+ r.append("={\n");
+
+ r.append("object ");
+ r.append(object != null ? object.name() : "NOT_SET");
+ r.append("\n");
+
+ r.append("type ");
+ r.append(object != null ? Constants.typeString(type) : "NOT_SET");
+ r.append("\n");
+
+ r.append("tag ");
+ r.append(tag != null ? tag : "NOT_SET");
+ r.append("\n");
+
+ if (tagger != null) {
+ r.append("tagger ");
+ r.append(tagger);
+ r.append("\n");
+ }
+
+ r.append("\n");
+ r.append(message != null ? message : "");
+ r.append("}");
+ return r.toString();
+ }
+}