aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/object/commit.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2019-04-18 12:42:43 +0200
committerGitHub <noreply@github.com>2019-04-18 12:42:43 +0200
commitaa6f288c256ff8baf8a7745546a9752323dc0d89 (patch)
tree2a109735d6c9ff5f5cd2c61250008c479ecf30a6 /plumbing/object/commit.go
parentcc5579e8f1d44e7a61b11221ba1b0f6d8afe4e6a (diff)
downloadgo-git-aa6f288c256ff8baf8a7745546a9752323dc0d89.tar.gz
plumbing: commit.StatsContext and fix for orphan commit (#1115)v4.11.0
plumbing: commit.StatsContext and fix for root commit
Diffstat (limited to 'plumbing/object/commit.go')
-rw-r--r--plumbing/object/commit.go38
1 files changed, 23 insertions, 15 deletions
diff --git a/plumbing/object/commit.go b/plumbing/object/commit.go
index e254342..b569d3c 100644
--- a/plumbing/object/commit.go
+++ b/plumbing/object/commit.go
@@ -76,8 +76,8 @@ func (c *Commit) Tree() (*Tree, error) {
return GetTree(c.s, c.TreeHash)
}
-// Patch returns the Patch between the actual commit and the provided one.
-// Error will be return if context expires. Provided context must be non-nil
+// PatchContext returns the Patch between the actual commit and the provided one.
+// Error will be return if context expires. Provided context must be non-nil.
func (c *Commit) PatchContext(ctx context.Context, to *Commit) (*Patch, error) {
fromTree, err := c.Tree()
if err != nil {
@@ -291,25 +291,33 @@ func (b *Commit) encode(o plumbing.EncodedObject, includeSig bool) (err error) {
return err
}
-// Stats shows the status of commit.
+// Stats returns the stats of a commit.
func (c *Commit) Stats() (FileStats, error) {
- // Get the previous commit.
- ci := c.Parents()
- parentCommit, err := ci.Next()
+ return c.StatsContext(context.Background())
+}
+
+// StatsContext returns the stats of a commit. Error will be return if context
+// expires. Provided context must be non-nil.
+func (c *Commit) StatsContext(ctx context.Context) (FileStats, error) {
+ fromTree, err := c.Tree()
if err != nil {
- if err == io.EOF {
- emptyNoder := treeNoder{}
- parentCommit = &Commit{
- Hash: emptyNoder.hash,
- // TreeHash: emptyNoder.parent.Hash,
- s: c.s,
- }
- } else {
+ return nil, err
+ }
+
+ toTree := &Tree{}
+ if c.NumParents() != 0 {
+ firstParent, err := c.Parents().Next()
+ if err != nil {
+ return nil, err
+ }
+
+ toTree, err = firstParent.Tree()
+ if err != nil {
return nil, err
}
}
- patch, err := parentCommit.Patch(c)
+ patch, err := toTree.PatchContext(ctx, fromTree)
if err != nil {
return nil, err
}