You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 11, 2020. It is now read-only.
I wanted to reproduce the behavior of git rev-list HEAD my_file with the help of go-git.
As this feature was not here out of the box, I tried my best to do a clean implementation for it with the library and it looks like this :
cIter, err:=g.Log(&git.LogOptions{
From: fromHash,
})
history:=make(map[string]CommitSlice)
// Where CommitSlice is just an improved version of HashSlice which can sort by Commit dateerr=cIter.ForEach(func(c*object.Commit) error {
sts, err:=c.Stats()
iferr!=nil {
iferr!=plumbing.ErrObjectNotFound {
returnerr
}
files, err:=c.Files()
CheckIfErr(err)
files.ForEach(func(f*object.File) error {
history[f.Name] =append(history[f.Name], c.Hash)
returnnil
})
}
for_, f:=rangests {
ifc.NumParents() <2 { // To get the actual commit and not the merge commithistory[f.Name] =append(history[f.Name], c.Hash)
}
}
returnnil
})
// CommitSlice implementation of the sort.Interface striped from this example.
I'd like to share this with the community and potentially have it in the go-git library so I'm wondering what would be the best place for this to live in.