@@ -30,10 +30,12 @@ type Commit struct {
30
30
Committer Signature
31
31
// Message is the commit message, contains arbitrary text.
32
32
Message string
33
+ // TreeHash is the hash of the root tree of the commit.
34
+ TreeHash plumbing.Hash
35
+ // ParentHashes are the hashes of the parent commits of the commit.
36
+ ParentHashes []plumbing.Hash
33
37
34
- tree plumbing.Hash
35
- parents []plumbing.Hash
36
- s storer.EncodedObjectStorer
38
+ s storer.EncodedObjectStorer
37
39
}
38
40
39
41
// GetCommit gets a commit from an object storer and decodes it.
@@ -59,19 +61,19 @@ func DecodeCommit(s storer.EncodedObjectStorer, o plumbing.EncodedObject) (*Comm
59
61
60
62
// Tree returns the Tree from the commit.
61
63
func (c * Commit ) Tree () (* Tree , error ) {
62
- return GetTree (c .s , c .tree )
64
+ return GetTree (c .s , c .TreeHash )
63
65
}
64
66
65
67
// Parents return a CommitIter to the parent Commits.
66
68
func (c * Commit ) Parents () CommitIter {
67
69
return NewCommitIter (c .s ,
68
- storer .NewEncodedObjectLookupIter (c .s , plumbing .CommitObject , c .parents ),
70
+ storer .NewEncodedObjectLookupIter (c .s , plumbing .CommitObject , c .ParentHashes ),
69
71
)
70
72
}
71
73
72
74
// NumParents returns the number of parents in a commit.
73
75
func (c * Commit ) NumParents () int {
74
- return len (c .parents )
76
+ return len (c .ParentHashes )
75
77
}
76
78
77
79
// File returns the file with the specified "path" in the commit and a
@@ -144,9 +146,9 @@ func (c *Commit) Decode(o plumbing.EncodedObject) (err error) {
144
146
split := bytes .SplitN (line , []byte {' ' }, 2 )
145
147
switch string (split [0 ]) {
146
148
case "tree" :
147
- c .tree = plumbing .NewHash (string (split [1 ]))
149
+ c .TreeHash = plumbing .NewHash (string (split [1 ]))
148
150
case "parent" :
149
- c .parents = append (c .parents , plumbing .NewHash (string (split [1 ])))
151
+ c .ParentHashes = append (c .ParentHashes , plumbing .NewHash (string (split [1 ])))
150
152
case "author" :
151
153
c .Author .Decode (split [1 ])
152
154
case "committer" :
@@ -169,30 +171,39 @@ func (b *Commit) Encode(o plumbing.EncodedObject) error {
169
171
if err != nil {
170
172
return err
171
173
}
174
+
172
175
defer ioutil .CheckClose (w , & err )
173
- if _ , err = fmt .Fprintf (w , "tree %s\n " , b .tree .String ()); err != nil {
176
+
177
+ if _ , err = fmt .Fprintf (w , "tree %s\n " , b .TreeHash .String ()); err != nil {
174
178
return err
175
179
}
176
- for _ , parent := range b .parents {
180
+
181
+ for _ , parent := range b .ParentHashes {
177
182
if _ , err = fmt .Fprintf (w , "parent %s\n " , parent .String ()); err != nil {
178
183
return err
179
184
}
180
185
}
186
+
181
187
if _ , err = fmt .Fprint (w , "author " ); err != nil {
182
188
return err
183
189
}
190
+
184
191
if err = b .Author .Encode (w ); err != nil {
185
192
return err
186
193
}
194
+
187
195
if _ , err = fmt .Fprint (w , "\n committer " ); err != nil {
188
196
return err
189
197
}
198
+
190
199
if err = b .Committer .Encode (w ); err != nil {
191
200
return err
192
201
}
202
+
193
203
if _ , err = fmt .Fprintf (w , "\n \n %s" , b .Message ); err != nil {
194
204
return err
195
205
}
206
+
196
207
return err
197
208
}
198
209
0 commit comments