Rename Commit, Tag to CommitBuilder, TagBuilder

Since these types no longer support reading, calling them a Builder
is a better description of what they do.  They help the caller to
build a commit or a tag object.

Change-Id: I53cae5a800a66ea1721b0fe5e702599df31da05d
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
This commit is contained in:
Shawn O. Pearce 2010-08-23 09:46:14 -07:00
parent 6a51d97948
commit 22b285695a
15 changed files with 49 additions and 44 deletions

View File

@ -70,7 +70,6 @@
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;
@ -82,7 +81,7 @@
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;
@ -359,7 +358,9 @@ public RevCommit commit(final int secDelta, final RevTree tree,
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)));
@ -397,7 +398,7 @@ public CommitBuilder commit() {
* @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)));
@ -810,7 +811,9 @@ public RevCommit create() throws Exception {
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)));

View File

@ -93,7 +93,9 @@ protected void run() throws Exception {
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", ""));

View File

@ -58,7 +58,7 @@
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;
@ -191,7 +191,7 @@ private void recreateCommitGraph() throws IOException {
}
}
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());

View File

@ -104,7 +104,7 @@ private void addFileToTree(final Tree t, String filename, String content)
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);

View File

@ -50,7 +50,7 @@
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;
@ -131,7 +131,7 @@ private void assertCorrectId(final DirCache treeT, final TreeWalk tw) {
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());

View File

@ -52,7 +52,7 @@
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;
@ -367,7 +367,7 @@ private void assertCorrectId(final DirCache treeT, final TreeWalk tw) {
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());

View File

@ -46,7 +46,7 @@
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;
@ -321,7 +321,7 @@ public void testParse_GitStyleMessage() throws Exception {
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);

View File

@ -51,7 +51,7 @@
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 {
@ -400,7 +400,7 @@ public void testParse_GitStyleMessage() 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);

View File

@ -60,7 +60,7 @@
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;
@ -72,7 +72,7 @@
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;
@ -383,7 +383,7 @@ public void test009_CreateCommitOldFormat() throws IOException {
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");
@ -440,7 +440,7 @@ public void test012_SubtreeExternalSorting() throws IOException {
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));
@ -460,7 +460,7 @@ public void test021_createTreeTag() throws IOException {
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));
@ -480,13 +480,13 @@ public void test022_createCommitTag() throws IOException {
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));
@ -506,7 +506,7 @@ public void test023_createCommitNonAnullii() throws IOException {
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));
@ -524,7 +524,7 @@ public void test024_createCommitNonAscii() throws IOException {
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));
@ -551,7 +551,7 @@ public void test026_CreateCommitMultipleparents() throws IOException {
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");
@ -562,7 +562,7 @@ public void test026_CreateCommitMultipleparents() throws IOException {
"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");
@ -583,7 +583,7 @@ public void test026_CreateCommitMultipleparents() throws IOException {
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");
@ -605,7 +605,7 @@ public void test026_CreateCommitMultipleparents() throws IOException {
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");
@ -693,7 +693,7 @@ public void test30_stripWorkDir() {
}
private ObjectId insertCommit(final Commit commit) throws IOException,
private ObjectId insertCommit(final CommitBuilder commit) throws IOException,
UnsupportedEncodingException {
ObjectInserter oi = db.newObjectInserter();
try {
@ -717,7 +717,7 @@ private RevCommit parseCommit(AnyObjectId id)
}
}
private ObjectId insertTag(final Tag tag) throws IOException,
private ObjectId insertTag(final TagBuilder tag) throws IOException,
UnsupportedEncodingException {
ObjectInserter oi = db.newObjectInserter();
try {

View File

@ -50,7 +50,7 @@
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;
@ -100,7 +100,7 @@ protected CommitCommand(Repository repo) {
* 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
@ -162,7 +162,7 @@ public RevCommit call() throws NoHeadException, 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);

View File

@ -59,7 +59,7 @@
* and obtain a {@link org.eclipse.jgit.revwalk.RevCommit} instance by calling
* {@link org.eclipse.jgit.revwalk.RevWalk#parseCommit(AnyObjectId)}.
*/
public class Commit {
public class CommitBuilder {
private static final ObjectId[] EMPTY_OBJECTID_LIST = new ObjectId[0];
private ObjectId commitId;
@ -77,7 +77,7 @@ public class Commit {
private Charset encoding;
/** Initialize an empty commit. */
public Commit() {
public CommitBuilder() {
parentIds = EMPTY_OBJECTID_LIST;
encoding = Constants.CHARSET;
}

View File

@ -303,7 +303,7 @@ public final byte[] format(Tree tree) throws IOException {
* @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();
@ -362,7 +362,7 @@ public final byte[] format(Commit commit)
* 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 {

View File

@ -172,7 +172,7 @@ public ObjectId writeCanonicalTree(byte[] treeData) throws IOException {
* @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();
@ -190,7 +190,7 @@ public ObjectId writeCommit(Commit commit) throws IOException {
* @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();

View File

@ -1091,7 +1091,7 @@ public void writeMergeCommitMsg(String msg) throws IOException {
* 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
@ -1130,7 +1130,7 @@ public List<ObjectId> readMergeHeads() throws IOException, NoWorkTreeException {
* 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
*/

View File

@ -57,7 +57,7 @@
* and obtain a {@link org.eclipse.jgit.revwalk.RevTag} instance by calling
* {@link org.eclipse.jgit.revwalk.RevWalk#parseTag(AnyObjectId)}.
*/
public class Tag {
public class TagBuilder {
private ObjectId tagId;
private ObjectId object;