Skip to content

Instantly share code, notes, and snippets.

@exavolt
Last active August 21, 2019 04:26
Show Gist options
  • Select an option

  • Save exavolt/9422ed9ae07c766149c4a9ed831a29f8 to your computer and use it in GitHub Desktop.

Select an option

Save exavolt/9422ed9ae07c766149c4a9ed831a29f8 to your computer and use it in GitHub Desktop.

Revisions

  1. exavolt revised this gist Aug 21, 2019. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions go-git-log.go
    Original file line number Diff line number Diff line change
    @@ -37,6 +37,7 @@ func main() {
    }
    if commit == nil {
    break
    }
    if len(commit.ParentHashes) > 1 {
    continue
    }
  2. exavolt revised this gist Aug 21, 2019. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions go-git-log.go
    Original file line number Diff line number Diff line change
    @@ -35,6 +35,8 @@ func main() {
    if err != nil {
    panic(err)
    }
    if commit == nil {
    break
    if len(commit.ParentHashes) > 1 {
    continue
    }
  3. exavolt created this gist Aug 21, 2019.
    49 changes: 49 additions & 0 deletions go-git-log.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    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 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)
    }
    }