From: Shawn O. Pearce Date: Mon, 23 Aug 2010 16:46:14 +0000 (-0700) Subject: Rename Commit, Tag to CommitBuilder, TagBuilder X-Git-Tag: v0.9.1~88 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fchanges%2F83%2F1383%2F1;p=jgit.git 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 --- diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java index 9df4072b0c..6e1f1db397 100644 --- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java +++ b/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 { 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 { * @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 { 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))); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Tag.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Tag.java index df986a88bc..0ab19b6bb9 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Tag.java +++ b/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", "")); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java index e0a7433564..ab44128713 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java +++ b/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()); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java index 5001b8fc73..ebe2db111d 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java +++ b/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); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CherryPickTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CherryPickTest.java index 977c9216e5..876b98636c 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CherryPickTest.java +++ b/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()); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SimpleMergeTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SimpleMergeTest.java index 88959c7924..5e7bcee1e7 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SimpleMergeTest.java +++ b/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()); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java index 9354373379..36730c153f 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java +++ b/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); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java index af70eb5a0d..727c48e8ef 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java +++ b/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); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0003_Basic.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0003_Basic.java index 1c7d3b681e..cd802d41ec 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0003_Basic.java +++ b/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 { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java index da6ac0a434..a88899cc58 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java +++ b/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 { * 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 { 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); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Commit.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Commit.java deleted file mode 100644 index 8fc46c915c..0000000000 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Commit.java +++ /dev/null @@ -1,302 +0,0 @@ -/* - * Copyright (C) 2007, Dave Watson - * Copyright (C) 2006-2007, Robin Rosenberg - * Copyright (C) 2006-2007, Shawn O. Pearce - * 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 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(); - } -} diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/CommitBuilder.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/CommitBuilder.java new file mode 100644 index 0000000000..8457d45496 --- /dev/null +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/CommitBuilder.java @@ -0,0 +1,302 @@ +/* + * Copyright (C) 2007, Dave Watson + * Copyright (C) 2006-2007, Robin Rosenberg + * Copyright (C) 2006-2007, Shawn O. Pearce + * 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 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(); + } +} diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectInserter.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectInserter.java index 369dd6e4c2..94d792858f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectInserter.java +++ b/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 { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectWriter.java index ce91efb8e4..5cb4b21689 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectWriter.java +++ b/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(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java index 2742cd4e50..c910889f68 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java +++ b/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 null to delete the file * @throws IOException */ diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Tag.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Tag.java deleted file mode 100644 index fda6b1cb1b..0000000000 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Tag.java +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright (C) 2006-2008, Robin Rosenberg - * Copyright (C) 2008, Shawn O. Pearce - * Copyright (C) 2010, Chris Aniszczyk - * 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(); - } -} diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/TagBuilder.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/TagBuilder.java new file mode 100644 index 0000000000..6cd0e9e882 --- /dev/null +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/TagBuilder.java @@ -0,0 +1,203 @@ +/* + * Copyright (C) 2006-2008, Robin Rosenberg + * Copyright (C) 2008, Shawn O. Pearce + * Copyright (C) 2010, Chris Aniszczyk + * 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(); + } +}