diff options
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse')
7 files changed, 245 insertions, 365 deletions
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 ae4b33477b..859e92fdb7 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java @@ -162,12 +162,12 @@ public class CommitCommand extends GitCommand<RevCommit> { ObjectId indexTreeId = index.writeTree(odi); // Create a Commit object, populate it and write it - Commit commit = new Commit(repo); + Commit commit = new Commit(); commit.setCommitter(committer); commit.setAuthor(author); commit.setMessage(message); - commit.setParentIds(parents.toArray(new ObjectId[] {})); + commit.setParentIds(parents); commit.setTreeId(indexTreeId); ObjectId commitId = odi.insert(Constants.OBJ_COMMIT, odi .format(commit)); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java index 4d37c28e0a..a6e648d360 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java @@ -57,11 +57,11 @@ import org.eclipse.jgit.lib.GitIndex; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectIdRef; import org.eclipse.jgit.lib.Ref; -import org.eclipse.jgit.lib.Ref.Storage; import org.eclipse.jgit.lib.RefUpdate; -import org.eclipse.jgit.lib.RefUpdate.Result; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.WorkDirCheckout; +import org.eclipse.jgit.lib.Ref.Storage; +import org.eclipse.jgit.lib.RefUpdate.Result; import org.eclipse.jgit.merge.MergeStrategy; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevWalk; @@ -176,8 +176,8 @@ public class MergeCommand extends GitCommand<MergeResult> { File workDir = repo.getWorkTree(); if (workDir != null) { WorkDirCheckout workDirCheckout = new WorkDirCheckout(repo, - workDir, headCommit.asCommit(revWalk).getTree(), index, - newHeadCommit.asCommit(revWalk).getTree()); + workDir, repo.mapTree(headCommit.getTree()), index, + repo.mapTree(newHeadCommit.getTree())); workDirCheckout.setFailOnConflict(true); try { workDirCheckout.checkout(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BlobBasedConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BlobBasedConfig.java index b56966ff42..f25b0781e6 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BlobBasedConfig.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BlobBasedConfig.java @@ -51,15 +51,24 @@ import java.text.MessageFormat; import org.eclipse.jgit.JGitText; import org.eclipse.jgit.errors.ConfigInvalidException; +import org.eclipse.jgit.errors.IncorrectObjectTypeException; +import org.eclipse.jgit.errors.MissingObjectException; +import org.eclipse.jgit.revwalk.RevCommit; +import org.eclipse.jgit.revwalk.RevTree; +import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.treewalk.TreeWalk; +import org.eclipse.jgit.util.IO; import org.eclipse.jgit.util.RawParseUtils; /** - * The configuration file based on the blobs stored in the repository + * Configuration file based on the blobs stored in the repository. + * + * This implementation currently only provides reading support, and is primarily + * useful for supporting the {@code .gitmodules} file. */ public class BlobBasedConfig extends Config { /** - * The constructor from a byte array + * Parse a configuration from a byte array. * * @param base * the base configuration file @@ -75,11 +84,11 @@ public class BlobBasedConfig extends Config { } /** - * The constructor from object identifier + * Load a configuration file from a blob. * * @param base * the base configuration file - * @param r + * @param db * the repository * @param objectId * the object identifier @@ -88,22 +97,50 @@ public class BlobBasedConfig extends Config { * @throws ConfigInvalidException * the blob is not a valid configuration format. */ - public BlobBasedConfig(Config base, final Repository r, - final ObjectId objectId) throws IOException, ConfigInvalidException { - super(base); - ObjectLoader loader = r.open(objectId, Constants.OBJ_BLOB); - fromText(RawParseUtils.decode(loader.getCachedBytes())); + public BlobBasedConfig(Config base, Repository db, AnyObjectId objectId) + throws IOException, ConfigInvalidException { + this(base, read(db, objectId)); + } + + private static byte[] read(Repository db, AnyObjectId blobId) + throws MissingObjectException, IncorrectObjectTypeException, + IOException { + ObjectReader or = db.newObjectReader(); + try { + return read(or, blobId); + } finally { + or.release(); + } + } + + private static byte[] read(ObjectReader or, AnyObjectId blobId) + throws MissingObjectException, IncorrectObjectTypeException, + IOException { + ObjectLoader loader = or.open(blobId, Constants.OBJ_BLOB); + if (loader.isLarge()) { + ObjectStream in = loader.openStream(); + try { + byte[] buf = new byte[(int) in.getSize()]; + IO.readFully(in, buf, 0, buf.length); + return buf; + } finally { + in.close(); + } + } + return loader.getCachedBytes(); } /** - * The constructor from commit and path + * Load a configuration file from a blob stored in a specific commit. * * @param base * the base configuration file - * @param commit - * the commit that contains the object + * @param db + * the repository containing the objects. + * @param treeish + * the tree (or commit) that contains the object * @param path - * the path within the tree of the commit + * the path within the tree * @throws FileNotFoundException * the path does not exist in the commit's tree. * @throws IOException @@ -111,16 +148,37 @@ public class BlobBasedConfig extends Config { * @throws ConfigInvalidException * the blob is not a valid configuration format. */ - public BlobBasedConfig(Config base, final Commit commit, final String path) - throws FileNotFoundException, IOException, ConfigInvalidException { - super(base); - final ObjectId treeId = commit.getTreeId(); - final Repository r = commit.getRepository(); - final TreeWalk tree = TreeWalk.forPath(r, path, treeId); - if (tree == null) - throw new FileNotFoundException(MessageFormat.format(JGitText.get().entryNotFoundByPath, path)); - final ObjectId blobId = tree.getObjectId(0); - ObjectLoader loader = r.open(blobId,Constants.OBJ_BLOB); - fromText(RawParseUtils.decode(loader.getCachedBytes())); + public BlobBasedConfig(Config base, Repository db, AnyObjectId treeish, + String path) throws FileNotFoundException, IOException, + ConfigInvalidException { + this(base, read(db, treeish, path)); + } + + private static byte[] read(Repository db, AnyObjectId treeish, String path) + throws MissingObjectException, IncorrectObjectTypeException, + IOException { + ObjectReader or = db.newObjectReader(); + try { + TreeWalk tree = TreeWalk.forPath(or, path, asTree(or, treeish)); + if (tree == null) + throw new FileNotFoundException(MessageFormat.format(JGitText + .get().entryNotFoundByPath, path)); + return read(or, tree.getObjectId(0)); + } finally { + or.release(); + } + } + + private static AnyObjectId asTree(ObjectReader or, AnyObjectId treeish) + throws MissingObjectException, IncorrectObjectTypeException, + IOException { + if (treeish instanceof RevTree) + return treeish; + + if (treeish instanceof RevCommit + && ((RevCommit) treeish).getTree() != null) + return ((RevCommit) treeish).getTree(); + + return new RevWalk(or).parseTree(treeish).getId(); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Commit.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Commit.java index eeffb08e95..ebf75f92b9 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Commit.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Commit.java @@ -45,25 +45,19 @@ package org.eclipse.jgit.lib; -import java.io.ByteArrayInputStream; -import java.io.DataInputStream; -import java.io.IOException; import java.nio.charset.Charset; -import java.text.MessageFormat; - -import org.eclipse.jgit.JGitText; -import org.eclipse.jgit.errors.CorruptObjectException; -import org.eclipse.jgit.errors.MissingObjectException; +import java.util.List; /** - * Instances of this class represent a Commit object. It represents a snapshot - * in a Git repository, who created it and when. + * 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}. */ -public class Commit implements Treeish { +public class Commit { private static final ObjectId[] EMPTY_OBJECTID_LIST = new ObjectId[0]; - private final Repository objdb; - private ObjectId commitId; private ObjectId treeId; @@ -76,102 +70,21 @@ public class Commit implements Treeish { private String message; - private Tree treeObj; - - private byte[] raw; - private Charset encoding; - /** - * Create an empty commit object. More information must be fed to this - * object to make it useful. - * - * @param db - * The repository with which to associate it. - */ - public Commit(final Repository db) { - objdb = db; + /** Initialize an empty commit. */ + public Commit() { parentIds = EMPTY_OBJECTID_LIST; + encoding = Constants.CHARSET; } - /** - * Create a commit associated with these parents and associate it with a - * repository. - * - * @param db - * The repository to which this commit object belongs - * @param parentIds - * Id's of the parent(s) - */ - public Commit(final Repository db, final ObjectId[] parentIds) { - objdb = db; - this.parentIds = parentIds; - } - - /** - * Create a commit object with the specified id and data from and existing - * commit object in a repository. - * - * @param db - * The repository to which this commit object belongs - * @param id - * Commit id - * @param raw - * Raw commit object data - */ - public Commit(final Repository db, final ObjectId id, final byte[] raw) { - objdb = db; - commitId = id; - treeId = ObjectId.fromString(raw, 5); - parentIds = new ObjectId[1]; - int np=0; - int rawPtr = 46; - for (;;) { - if (raw[rawPtr] != 'p') - break; - if (np == 0) { - parentIds[np++] = ObjectId.fromString(raw, rawPtr + 7); - } else if (np == 1) { - parentIds = new ObjectId[] { parentIds[0], ObjectId.fromString(raw, rawPtr + 7) }; - np++; - } else { - if (parentIds.length <= np) { - ObjectId[] old = parentIds; - parentIds = new ObjectId[parentIds.length+32]; - for (int i=0; i<np; ++i) - parentIds[i] = old[i]; - } - parentIds[np++] = ObjectId.fromString(raw, rawPtr + 7); - } - rawPtr += 48; - } - if (np != parentIds.length) { - ObjectId[] old = parentIds; - parentIds = new ObjectId[np]; - for (int i=0; i<np; ++i) - parentIds[i] = old[i]; - } else - if (np == 0) - parentIds = EMPTY_OBJECTID_LIST; - this.raw = raw; - } - - /** - * @return get repository for the commit - */ - public Repository getRepository() { - return objdb; - } - - /** - * @return The commit object id - */ + /** @return this commit's object id. */ public ObjectId getCommitId() { return commitId; } /** - * Set the id of this object. + * Set the id of this commit object. * * @param id * the id that we calculated for this object. @@ -180,6 +93,7 @@ public class Commit implements Treeish { commitId = id; } + /** @return id of the root tree listing this commit's snapshot. */ public ObjectId getTreeId() { return treeId; } @@ -188,198 +102,197 @@ public class Commit implements Treeish { * Set the tree id for this commit object * * @param id + * the tree identity. */ - public void setTreeId(final ObjectId id) { - if (treeId==null || !treeId.equals(id)) { - treeObj = null; - } - treeId = id; - } - - public Tree getTree() throws IOException { - if (treeObj == null) { - treeObj = objdb.mapTree(getTreeId()); - if (treeObj == null) { - throw new MissingObjectException(getTreeId(), - Constants.TYPE_TREE); - } - } - return treeObj; - } - - /** - * Set the tree object for this commit - * @see #setTreeId - * @param t the Tree object - */ - public void setTree(final Tree t) { - treeId = t.getTreeId(); - treeObj = t; + public void setTreeId(AnyObjectId id) { + treeId = id.copy(); + commitId = null; } - /** - * @return the author and authoring time for this commit - */ + /** @return the author of this commit (who wrote it). */ public PersonIdent getAuthor() { - decode(); return author; } /** - * Set the author and authoring time for this commit - * @param a + * 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(final PersonIdent a) { - author = a; + public void setAuthor(PersonIdent newAuthor) { + author = newAuthor; + commitId = null; } - /** - * @return the committer and commit time for this object - */ + /** @return the committer and commit time for this object. */ public PersonIdent getCommitter() { - decode(); return committer; } /** * Set the committer and commit time for this object - * @param c the committer information + * + * @param newCommitter + * the committer information. Should not be null. */ - public void setCommitter(final PersonIdent c) { - committer = c; + public void setCommitter(PersonIdent newCommitter) { + committer = newCommitter; + commitId = null; } - /** - * @return the object ids of this commit - */ + /** @return the ancestors of this commit. Never null. */ public ObjectId[] getParentIds() { return parentIds; } /** - * @return the commit message + * Set the parent of this commit. + * + * @param newParent + * the single parent for the commit. */ - public String getMessage() { - decode(); - return message; + public void setParentId(AnyObjectId newParent) { + parentIds = new ObjectId[] { newParent.copy() }; + commitId = null; } /** - * Set the parents of this commit - * @param parentIds + * 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(ObjectId[] parentIds) { - this.parentIds = new ObjectId[parentIds.length]; - for (int i=0; i<parentIds.length; ++i) - this.parentIds[i] = parentIds[i]; + public void setParentIds(AnyObjectId parent1, AnyObjectId parent2) { + parentIds = new ObjectId[] { parent1.copy(), parent2.copy() }; + commitId = null; } - private void decode() { - // FIXME: handle I/O errors - if (raw != null) { - try { - DataInputStream br = new DataInputStream(new ByteArrayInputStream(raw)); - String n = br.readLine(); - if (n == null || !n.startsWith("tree ")) { - throw new CorruptObjectException(commitId, JGitText.get().corruptObjectNotree); - } - while ((n = br.readLine()) != null && n.startsWith("parent ")) { - // empty body - } - if (n == null || !n.startsWith("author ")) { - throw new CorruptObjectException(commitId, JGitText.get().corruptObjectNoAuthor); - } - String rawAuthor = n.substring("author ".length()); - n = br.readLine(); - if (n == null || !n.startsWith("committer ")) { - throw new CorruptObjectException(commitId, JGitText.get().corruptObjectNoCommitter); - } - String rawCommitter = n.substring("committer ".length()); - n = br.readLine(); - if (n != null && n.startsWith( "encoding")) - encoding = Charset.forName(n.substring("encoding ".length())); - else - if (n == null || !n.equals("")) { - throw new CorruptObjectException(commitId, MessageFormat.format( - JGitText.get().corruptObjectMalformedHeader, n)); - } - byte[] readBuf = new byte[br.available()]; // in-memory stream so this is all bytes left - br.read(readBuf); - int msgstart = readBuf.length != 0 ? ( readBuf[0] == '\n' ? 1 : 0 ) : 0; - - // If encoding is not specified, the default for commit is UTF-8 - if (encoding == null) encoding = Constants.CHARSET; - - // TODO: this isn't reliable so we need to guess the encoding from the actual content - author = new PersonIdent(new String(rawAuthor.getBytes(),encoding.name())); - committer = new PersonIdent(new String(rawCommitter.getBytes(),encoding.name())); - message = new String(readBuf,msgstart, readBuf.length-msgstart, encoding.name()); - } catch (IOException e) { - e.printStackTrace(); - } finally { - raw = 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 commit message + * Set the parents of this commit. * - * @param m the commit message + * @param newParents + * the entire list of parents for this commit. */ - public void setMessage(final String m) { - message = m; + 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; } /** - * Persist this commit object + * Add a parent onto the end of the parent list. * - * @throws IOException + * @param additionalParent + * new parent to add onto the end of the current parent list. */ - public void commit() throws IOException { - if (getCommitId() != null) - throw new IllegalStateException(MessageFormat.format(JGitText.get().commitAlreadyExists, getCommitId())); - ObjectInserter odi = objdb.newObjectInserter(); - try { - ObjectId id = odi.insert(Constants.OBJ_COMMIT, odi.format(this)); - odi.flush(); - setCommitId(id); - } finally { - odi.release(); + 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; } } - public String toString() { - return "Commit[" + ObjectId.toString(getCommitId()) + " " + getAuthor() + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + /** @return the complete commit message. */ + public String getMessage() { + return message; } /** - * State the encoding for the commit information + * Set the commit message. * - * @param e - * the encoding. See {@link Charset} + * @param newMessage + * the commit message. Should not be null. */ - public void setEncoding(String e) { - encoding = Charset.forName(e); + public void setMessage(final String newMessage) { + message = newMessage; } /** - * State the encoding for the commit information + * Set the encoding for the commit information * - * @param e - * the encoding. See {@link Charset} + * @param encodingName + * the encoding name. See {@link Charset#forName(String)}. */ - public void setEncoding(Charset e) { - encoding = e; + public void setEncoding(String encodingName) { + encoding = Charset.forName(encodingName); } /** - * @return the encoding used. See {@link Charset} + * Set the encoding for the commit information + * + * @param enc + * the encoding to use. */ - public String getEncoding() { - if (encoding != null) - return encoding.name(); - else - return null; + 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 a9522452b6..349b8197db 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectInserter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectInserter.java @@ -53,6 +53,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStreamWriter; import java.io.UnsupportedEncodingException; +import java.nio.charset.Charset; import java.security.MessageDigest; import java.text.MessageFormat; @@ -304,10 +305,7 @@ public abstract class ObjectInserter { */ public final byte[] format(Commit commit) throws UnsupportedEncodingException { - String encoding = commit.getEncoding(); - if (encoding == null) - encoding = Constants.CHARACTER_ENCODING; - + Charset encoding = commit.getEncoding(); ByteArrayOutputStream os = new ByteArrayOutputStream(); OutputStreamWriter w = new OutputStreamWriter(os, encoding); try { @@ -316,11 +314,10 @@ public abstract class ObjectInserter { commit.getTreeId().copyTo(os); os.write('\n'); - ObjectId[] ps = commit.getParentIds(); - for (int i = 0; i < ps.length; ++i) { + for (ObjectId p : commit.getParentIds()) { os.write(hparent); os.write(' '); - ps[i].copyTo(os); + p.copyTo(os); os.write('\n'); } @@ -336,16 +333,19 @@ public abstract class ObjectInserter { w.flush(); os.write('\n'); - if (!encoding.equals(Constants.CHARACTER_ENCODING)) { + if (encoding != Constants.CHARSET) { os.write(hencoding); os.write(' '); - os.write(Constants.encodeASCII(encoding)); + os.write(Constants.encodeASCII(encoding.name())); os.write('\n'); } os.write('\n'); - w.write(commit.getMessage()); - w.flush(); + + if (commit.getMessage() != null) { + w.write(commit.getMessage()); + w.flush(); + } } catch (IOException err) { // This should never occur, the only way to get it above is // for the ByteArrayOutputStream to throw, but it doesn't. 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 27fdf68417..6059efde91 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java @@ -271,84 +271,6 @@ public abstract class Repository { } /** - * Access a Commit object using a symbolic reference. This reference may - * be a SHA-1 or ref in combination with a number of symbols translating - * from one ref or SHA1-1 to another, such as HEAD^ etc. - * - * @param revstr a reference to a git commit object - * @return a Commit named by the specified string - * @throws IOException for I/O error or unexpected object type. - * - * @see #resolve(String) - * @deprecated Use {@link #resolve(String)} and pass its return value to - * {@link org.eclipse.jgit.revwalk.RevWalk#parseCommit(AnyObjectId)}. - */ - @Deprecated - public Commit mapCommit(final String revstr) throws IOException { - final ObjectId id = resolve(revstr); - return id != null ? mapCommit(id) : null; - } - - /** - * Access any type of Git object by id and - * - * @param id - * SHA-1 of object to read - * @param refName optional, only relevant for simple tags - * @return The Git object if found or null - * @throws IOException - * @deprecated Use {@link org.eclipse.jgit.revwalk.RevWalk#parseCommit(AnyObjectId)}, - * or {@link org.eclipse.jgit.revwalk.RevWalk#parseTag(AnyObjectId)}. - * To read a tree, use {@link org.eclipse.jgit.treewalk.TreeWalk#addTree(AnyObjectId)}. - * To read a blob, open it with {@link #open(AnyObjectId)}. - */ - @Deprecated - public Object mapObject(final ObjectId id, final String refName) throws IOException { - final ObjectLoader or; - try { - or = open(id); - } catch (MissingObjectException notFound) { - return null; - } - final byte[] raw = or.getCachedBytes(); - switch (or.getType()) { - case Constants.OBJ_TREE: - return new Tree(this, id, raw); - - case Constants.OBJ_COMMIT: - return new Commit(this, id, raw); - - case Constants.OBJ_TAG: - return new Tag(this, id, refName, raw); - - case Constants.OBJ_BLOB: - return raw; - - default: - throw new IncorrectObjectTypeException(id, - JGitText.get().incorrectObjectType_COMMITnorTREEnorBLOBnorTAG); - } - } - - /** - * Access a Commit by SHA'1 id. - * @param id - * @return Commit or null - * @throws IOException for I/O error or unexpected object type. - * @deprecated Use {@link org.eclipse.jgit.revwalk.RevWalk#parseCommit(AnyObjectId)}. - */ - @Deprecated - public Commit mapCommit(final ObjectId id) throws IOException { - final ObjectLoader or; - try { - or = open(id, Constants.OBJ_COMMIT); - } catch (MissingObjectException notFound) { - return null; - } - return new Commit(this, id, or.getCachedBytes()); - } - - /** * Access a Tree object using a symbolic reference. This reference may * be a SHA-1 or ref in combination with a number of symbols translating * from one ref or SHA1-1 to another, such as HEAD^{tree} etc. diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java index 84cc704c34..74a51c8a4a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java @@ -53,7 +53,6 @@ import java.util.List; 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.Constants; import org.eclipse.jgit.lib.MutableObjectId; import org.eclipse.jgit.lib.PersonIdent; @@ -207,18 +206,6 @@ public class RevCommit extends RevObject { } /** - * Parse this commit buffer for display. - * - * @param walk - * revision walker owning this reference. - * @return parsed commit. - */ - public final Commit asCommit(final RevWalk walk) { - // TODO(spearce) Remove repository when this method dies. - return new Commit(walk.repository, this, buffer); - } - - /** * Get a reference to this commit's tree. * * @return tree of this commit. |