Skip to content

Git log extremely slow when applied to a file #811

@romain-gaillard

Description

@romain-gaillard

I am trying to get a list of commits in which a given file has been modified.

Therefore, I'm doing a Log and I set FileName to my file in the LogOptions.
But this process is very slow. In the following example, it takes about a minute to return, whereas using git in command line returns immediately.

package main

import (
	"fmt"

	"github.com/go-git/go-billy/v5/memfs"
	git "github.com/go-git/go-git/v5"
	"github.com/go-git/go-git/v5/plumbing/object"
	"github.com/go-git/go-git/v5/storage/memory"
)

func main() {
	fs := memfs.New()

	fmt.Println("Cloning repository")

	rep, _ := git.Clone(memory.NewStorage(), fs, &git.CloneOptions{
		URL: "https://www.github.com/sigmahq/sigma",
	})

	f := "README.md"

	fmt.Println("git log")
	cIter, _ := rep.Log(&git.LogOptions{FileName: &f})

	_ = cIter.ForEach(func(c *object.Commit) error {

		return nil
	})

	fmt.Println("Finished")
}

Also, the same example just browsing all the commits, not filtering on a given file returns immediately.

package main

import (
	"fmt"

	"github.com/go-git/go-billy/v5/memfs"
	git "github.com/go-git/go-git/v5"
	"github.com/go-git/go-git/v5/plumbing/object"
	"github.com/go-git/go-git/v5/storage/memory"
)

func main() {
	fs := memfs.New()

	fmt.Println("Cloning repository")

	rep, _ := git.Clone(memory.NewStorage(), fs, &git.CloneOptions{
		URL: "https://www.github.com/sigmahq/sigma",
	})

	//f := "README.md"

	fmt.Println("git log")
	cIter, _ := rep.Log(&git.LogOptions{})

	_ = cIter.ForEach(func(c *object.Commit) error {

		return nil
	})

	fmt.Println("Finished")
}

Can this be improved? If not, what workaround can I use to get the list of commits that modified a given file with better performance?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions