Closed dmigwi closed 5 years ago
I have made progress in implementing git log -p
. The pending bit is now how to fetch changes in the first commit made i.e. without a parent commit.
This implementation has been quite helpful.
func (c *Commit) Stats() (FileStats, error) {
// Get the previous commit.
ci := c.Parents()
parentCommit, err := ci.Next()
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
}
}
patch, err := parentCommit.Patch(c)
if err != nil {
return nil, err
}
return getFileStatsFromFilePatches(patch.FilePatches()), nil
}
Sadly stats for the first commit (without a parent) returns Object not found
error.
Also creating a dummy parent commit outside the package is quite difficult because storer.EncodedObjectStorer
Commit field is unexported.
So how can I fetch stats/changes in a commit without a parent?
It's interesting that (*Commit).Stats
does not work for the initial commit. I can't work out how to get the patch for the initial commit either.
@mcuadros Sorry for the direct mention, but it seems like there must be a simple way to get the initial commit patch diff that I'm just not seeing. How would you suggest handling this?
This was solved here: https://github.com/src-d/go-git/pull/1115
How can I be able to implement
git log -p --reverse
using this tool?