1 package org
.spearce
.jgit
.lib
;
3 import java
.io
.BufferedReader
;
4 import java
.io
.IOException
;
5 import java
.util
.ArrayList
;
6 import java
.util
.Collections
;
9 public class Commit
implements Treeish
{
10 private final ObjectDatabase objdb
;
12 private final ObjectId commitId
;
14 private final ObjectId treeId
;
16 private final List parentIds
;
18 private final String author
;
20 private final String committer
;
22 private final String message
;
26 public Commit(final ObjectDatabase db
, final ObjectId id
,
27 final BufferedReader br
) throws IOException
{
31 final ArrayList tempParents
;
32 final StringBuffer tempMessage
;
38 if (line
== null || !line
.startsWith("tree ")) {
39 throw new CorruptObjectException("No tree found in commit " + id
);
41 treeId
= new ObjectId(line
.substring("tree ".length()));
43 tempParents
= new ArrayList(2);
47 throw new CorruptObjectException("Commit header corrupt " + id
);
49 if (line
.startsWith("parent ")) {
51 .add(new ObjectId(line
.substring("parent ".length())));
56 parentIds
= Collections
.unmodifiableList(tempParents
);
58 if (line
== null || !line
.startsWith("author ")) {
59 throw new CorruptObjectException("No author found in commit " + id
);
61 author
= line
.substring("author ".length());
64 if (line
== null || !line
.startsWith("committer ")) {
65 throw new CorruptObjectException("No committer found in commit "
68 committer
= line
.substring("committer ".length());
71 if (line
== null || !line
.equals("")) {
72 throw new CorruptObjectException(
73 "No blank line after header in commit " + id
);
76 tempMessage
= new StringBuffer();
77 readBuf
= new char[128];
78 while ((readLen
= br
.read(readBuf
)) > 0) {
79 tempMessage
.append(readBuf
, 0, readLen
);
81 message
= tempMessage
.toString();
84 public ObjectId
getCommitId() {
88 public ObjectId
getTreeId() {
92 public List
getTreeEntries() throws IOException
{
93 if (treeObj
== null) {
94 treeObj
= objdb
.openTree(getTreeId());
96 return treeObj
.getTreeEntries();
99 public String
getAuthor() {
103 public String
getCommitter() {
107 public List
getParentIds() {
111 public String
getMessage() {