diff options
author | onee-only <kimww0306@gmail.com> | 2024-03-10 15:50:17 +0900 |
---|---|---|
committer | onee-only <kimww0306@gmail.com> | 2024-03-10 15:50:17 +0900 |
commit | c1002494eb389b703731c5267561a2703a8cd3b1 (patch) | |
tree | f01cd50c5d99eb5fe5b515752046dbc8a68b9dea /plumbing/object | |
parent | d9497bae668afcc540fa6f2177575777b3ff91de (diff) | |
download | go-git-c1002494eb389b703731c5267561a2703a8cd3b1.tar.gz |
plumbing: object, Optimize getNextFileCommit to reuse parent tree.
Diffstat (limited to 'plumbing/object')
-rw-r--r-- | plumbing/object/commit_walker_path.go | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/plumbing/object/commit_walker_path.go b/plumbing/object/commit_walker_path.go index e054966..c1ec8ba 100644 --- a/plumbing/object/commit_walker_path.go +++ b/plumbing/object/commit_walker_path.go @@ -57,6 +57,8 @@ func (c *commitPathIter) Next() (*Commit, error) { } func (c *commitPathIter) getNextFileCommit() (*Commit, error) { + var parentTree, currentTree *Tree + for { // Parent-commit can be nil if the current-commit is the initial commit parentCommit, parentCommitErr := c.sourceIter.Next() @@ -68,13 +70,17 @@ func (c *commitPathIter) getNextFileCommit() (*Commit, error) { parentCommit = nil } - // Fetch the trees of the current and parent commits - currentTree, currTreeErr := c.currentCommit.Tree() - if currTreeErr != nil { - return nil, currTreeErr + if parentTree == nil { + var currTreeErr error + currentTree, currTreeErr = c.currentCommit.Tree() + if currTreeErr != nil { + return nil, currTreeErr + } + } else { + currentTree = parentTree + parentTree = nil } - var parentTree *Tree if parentCommit != nil { var parentTreeErr error parentTree, parentTreeErr = parentCommit.Tree() |