@@ -76,8 +76,8 @@ func (c *Commit) Tree() (*Tree, error) {
76
76
return GetTree (c .s , c .TreeHash )
77
77
}
78
78
79
- // Patch returns the Patch between the actual commit and the provided one.
80
- // Error will be return if context expires. Provided context must be non-nil
79
+ // PatchContext returns the Patch between the actual commit and the provided one.
80
+ // Error will be return if context expires. Provided context must be non-nil.
81
81
func (c * Commit ) PatchContext (ctx context.Context , to * Commit ) (* Patch , error ) {
82
82
fromTree , err := c .Tree ()
83
83
if err != nil {
@@ -291,25 +291,33 @@ func (b *Commit) encode(o plumbing.EncodedObject, includeSig bool) (err error) {
291
291
return err
292
292
}
293
293
294
- // Stats shows the status of commit.
294
+ // Stats returns the stats of a commit.
295
295
func (c * Commit ) Stats () (FileStats , error ) {
296
- // Get the previous commit.
297
- ci := c .Parents ()
298
- parentCommit , err := ci .Next ()
296
+ return c .StatsContext (context .Background ())
297
+ }
298
+
299
+ // StatsContext returns the stats of a commit. Error will be return if context
300
+ // expires. Provided context must be non-nil.
301
+ func (c * Commit ) StatsContext (ctx context.Context ) (FileStats , error ) {
302
+ fromTree , err := c .Tree ()
299
303
if err != nil {
300
- if err == io .EOF {
301
- emptyNoder := treeNoder {}
302
- parentCommit = & Commit {
303
- Hash : emptyNoder .hash ,
304
- // TreeHash: emptyNoder.parent.Hash,
305
- s : c .s ,
306
- }
307
- } else {
304
+ return nil , err
305
+ }
306
+
307
+ toTree := & Tree {}
308
+ if c .NumParents () != 0 {
309
+ firstParent , err := c .Parents ().Next ()
310
+ if err != nil {
311
+ return nil , err
312
+ }
313
+
314
+ toTree , err = firstParent .Tree ()
315
+ if err != nil {
308
316
return nil , err
309
317
}
310
318
}
311
319
312
- patch , err := parentCommit . Patch ( c )
320
+ patch , err := toTree . PatchContext ( ctx , fromTree )
313
321
if err != nil {
314
322
return nil , err
315
323
}
0 commit comments