Skip to content

Instantly share code, notes, and snippets.

@exavolt
Last active August 21, 2019 04:26
Show Gist options
  • Save exavolt/9422ed9ae07c766149c4a9ed831a29f8 to your computer and use it in GitHub Desktop.
Save exavolt/9422ed9ae07c766149c4a9ed831a29f8 to your computer and use it in GitHub Desktop.
Nothing
package main
import (
"fmt"
"path/filepath"
"strings"
"gopkg.in/src-d/go-billy.v4/osfs"
"gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/plumbing/cache"
"gopkg.in/src-d/go-git.v4/plumbing/object"
"gopkg.in/src-d/go-git.v4/storage/filesystem"
)
func main() {
targetCount := 20
workingDirectory := "."
gitDotFS := osfs.New(filepath.Join(workingDirectory, ".git"))
gitWorkingDirFS := osfs.New(workingDirectory)
objectCache := cache.NewObjectLRUDefault()
gitStorage := filesystem.NewStorage(gitDotFS, objectCache)
gitRepo, err := git.Open(gitStorage, gitWorkingDirFS)
if err != nil {
panic(err)
}
commitIter, err := gitRepo.Log(&git.LogOptions{
Order: git.LogOrderBSF,
})
if err != nil {
panic(err)
}
var commits []object.Commit
for i := 0; i < targetCount; {
commit, err := commitIter.Next()
if err != nil {
panic(err)
}
if commit == nil {
break
}
if len(commit.ParentHashes) > 1 {
continue
}
commits = append(commits, *commit)
i++
}
for i := 0; i < targetCount; i++ {
commit := commits[i]
msg := strings.SplitN(commit.Message, "\n", 2)[0]
fmt.Printf("- %v\n", msg)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment