Pergunta

I want to display just the first 100 commits of a repository. I used the linux-repo to test this:

        const int maxSize = 100;

        Stopwatch sw = new Stopwatch();
        Console.WriteLine( "Getting Commits in own Thread" );
        sw.Start();

        using( Repository repo = new Repository( path_to_linux_repo ) )
        {
            ICommitLog commits = repo.Commits.QueryBy( new CommitFilter { Since = "HEAD" } );

            int index = 0;
            foreach( Commit commit in commits )
            {
                if( index++ > maxSize ) break;                    
            }
        }

        sw.Stop();
        Console.WriteLine( "Took {0}ms for {1} entries", sw.ElapsedMilliseconds, maxSize ); 

This simple loop takes over 9000ms on my machine. Its FAR faster when using a repo with less commits, but why is it so slow in repos with a lot of commits? Another question: is it possible to just retrieve a given number of commits e.g. to page through all commits?

Foi útil?

Solução

I can reproduce here. It's definitely far too long to take. It looks as though libgit2 is enqueueing the full graph before returning, which would be a bug with the given settings. Would you mind opening an issue?

As for retrieving a number of commits, the iteration is pull-based, so you will only grab as many out of the repository as you ask for. the commit log implements IEnumerable so you can use whatever LINQ methods you like (or do it manually as in this example).


UPDATE:

The bug was quite embarrassing, but there's a PR to fix it in libgit2 which will make its way into libgit2sharp releases in due course. With the fix, this test now takes ~80ms. Thanks for bringing it up.

UPDATE 2:

The fix is now available in the vNext branch of LibGit2Sharp.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top