@@ -76,8 +76,8 @@ func (c *Commit) Tree() (*Tree, error) {
7676 return GetTree (c .s , c .TreeHash )
7777}
7878
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.
8181func (c * Commit ) PatchContext (ctx context.Context , to * Commit ) (* Patch , error ) {
8282 fromTree , err := c .Tree ()
8383 if err != nil {
@@ -291,25 +291,33 @@ func (b *Commit) encode(o plumbing.EncodedObject, includeSig bool) (err error) {
291291 return err
292292}
293293
294- // Stats shows the status of commit.
294+ // Stats returns the stats of a commit.
295295func (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 ()
299303 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 {
308316 return nil , err
309317 }
310318 }
311319
312- patch , err := parentCommit . Patch ( c )
320+ patch , err := toTree . PatchContext ( ctx , fromTree )
313321 if err != nil {
314322 return nil , err
315323 }
0 commit comments