Browse Source

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>
stable-0.9
Shawn O. Pearce 14 years ago
parent
commit
22b285695a
  1. 13
      org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
  2. 4
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Tag.java
  3. 4
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java
  4. 2
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java
  5. 4
      org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CherryPickTest.java
  6. 4
      org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SimpleMergeTest.java
  7. 4
      org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java
  8. 4
      org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java
  9. 30
      org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0003_Basic.java
  10. 6
      org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java
  11. 4
      org.eclipse.jgit/src/org/eclipse/jgit/lib/CommitBuilder.java
  12. 4
      org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectInserter.java
  13. 4
      org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectWriter.java
  14. 4
      org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
  15. 2
      org.eclipse.jgit/src/org/eclipse/jgit/lib/TagBuilder.java

13
org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java

@ -70,7 +70,6 @@ import org.eclipse.jgit.errors.IncorrectObjectTypeException;
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.Ref;
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 class TestRepository<R extends Repository> {
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 class TestRepository<R extends Repository> {
* @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 class TestRepository<R extends Repository> {
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)));

4
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Tag.java

@ -93,7 +93,9 @@ class Tag extends TextBuiltin {
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", ""));

4
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java

@ -58,7 +58,7 @@ import java.util.Map;
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 @@ class RebuildCommitGraph extends TextBuiltin {
}
}
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());

2
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java

@ -104,7 +104,7 @@ public class ReflogConfigTest extends RepositoryTestCase {
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);

4
org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CherryPickTest.java

@ -50,7 +50,7 @@ import static org.eclipse.jgit.lib.Constants.OBJ_COMMIT;
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 @@ public class CherryPickTest extends RepositoryTestCase {
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());

4
org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SimpleMergeTest.java

@ -52,7 +52,7 @@ import java.io.IOException;
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 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
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());

4
org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java

@ -46,7 +46,7 @@ package org.eclipse.jgit.revwalk;
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 class RevCommitParseTest extends RepositoryTestCase {
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);

4
org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java

@ -51,7 +51,7 @@ 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;
import org.eclipse.jgit.lib.TagBuilder;
public class RevTagParseTest extends RepositoryTestCase {
public void testTagBlob() throws Exception {
@ -400,7 +400,7 @@ public class RevTagParseTest extends RepositoryTestCase {
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);

30
org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0003_Basic.java

@ -60,7 +60,7 @@ import org.eclipse.jgit.errors.ConfigInvalidException;
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.PersonIdent;
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 class T0003_Basic extends SampleDataRepositoryTestCase {
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 class T0003_Basic extends SampleDataRepositoryTestCase {
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 class T0003_Basic extends SampleDataRepositoryTestCase {
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 class T0003_Basic extends SampleDataRepositoryTestCase {
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 class T0003_Basic extends SampleDataRepositoryTestCase {
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 class T0003_Basic extends SampleDataRepositoryTestCase {
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 class T0003_Basic extends SampleDataRepositoryTestCase {
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 class T0003_Basic extends SampleDataRepositoryTestCase {
"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 class T0003_Basic extends SampleDataRepositoryTestCase {
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 class T0003_Basic extends SampleDataRepositoryTestCase {
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 class T0003_Basic extends SampleDataRepositoryTestCase {
}
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 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
}
}
private ObjectId insertTag(final Tag tag) throws IOException,
private ObjectId insertTag(final TagBuilder tag) throws IOException,
UnsupportedEncodingException {
ObjectInserter oi = db.newObjectInserter();
try {

6
org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java

@ -50,7 +50,7 @@ import java.util.List;
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 @@ public class CommitCommand extends GitCommand<RevCommit> {
* 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 class CommitCommand extends GitCommand<RevCommit> {
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);

4
org.eclipse.jgit/src/org/eclipse/jgit/lib/Commit.java → org.eclipse.jgit/src/org/eclipse/jgit/lib/CommitBuilder.java

@ -59,7 +59,7 @@ import java.util.List;
* 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;
}

4
org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectInserter.java

@ -303,7 +303,7 @@ public abstract class ObjectInserter {
* @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 abstract class ObjectInserter {
* 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 {

4
org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectWriter.java

@ -172,7 +172,7 @@ public class ObjectWriter {
* @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 class ObjectWriter {
* @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();

4
org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java

@ -1091,7 +1091,7 @@ public abstract class Repository {
* 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 abstract class Repository {
* 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
*/

2
org.eclipse.jgit/src/org/eclipse/jgit/lib/Tag.java → org.eclipse.jgit/src/org/eclipse/jgit/lib/TagBuilder.java

@ -57,7 +57,7 @@ import org.eclipse.jgit.revwalk.RevObject;
* 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;
Loading…
Cancel
Save