libgit2 / libgit2/libgit2sharp

RewriteHistory extremely slow

Aperta
#1,684 6 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
C#
Stelle
3.5k
Fork
925
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

Reproduction steps

Find a repo with 3000+ commits
Run the below code against that repo to rewrite the repo history:

private static void RewriteHistory(string repoPath, ICollection<string> subFolders)
{
    using (var repo = new Repository(repoPath))
    {
        var refs = repo.Refs.Where(r => r.CanonicalName.EndsWith("develop")).OrderBy(r => r.CanonicalName).ToList();
        var commits = repo.Commits.QueryBy(new CommitFilter { IncludeReachableFrom = refs }).ToArray();
        var count = 0;
        var stopwatch = Stopwatch.StartNew();

        Logger.InfoFormat("Found {0} commits", commits.Length);
        Logger.InfoFormat("Rewrite history started");

        repo.Refs.RewriteHistory(new RewriteHistoryOptions
        {
            OnError = OnError,
            OnSucceeding = OnSucceeding,
            PruneEmptyCommits = true,
            CommitTreeRewriter = commit =>
            {
                Logger.InfoFormat("Commit {0}/{1}", ++count, commits.Length);

                var tree = TreeDefinition.From(commit);
                foreach (var treeEntry in commit.Tree)
                {
                    var match = subFolders.FirstOrDefault(s => treeEntry.Path.StartsWithIgnoreCase(s));

                    if (match == null)
                        tree.Remove(treeEntry.Path);
                }

                return tree;
            }
        }, commits);
        Logger.InfoFormat("Rewrite history ended. Took {0}", stopwatch.Elapsed);

        repo.Reset(ResetMode.Hard, repo.Head.Commits.First());
    }
}
Expected behavior

This should take a reasonable time. I expect it to take a few minutes for sure but not hours. For example when running something similar in git from the command like it takes minutes. I'm sorry I don't have specific times but I can try to provide more data to compare performance if necessary.

Actual behavior

This takes 1h 43 minutes of which 1h 40 to just start the rewrite and about a couple of minutes to go through all the commits.
INFO : Found 3486 commits
INFO : Rewrite history started
[between these two log messages there is a 1h 40m gap]
INFO : Commit 1/3486
INFO : Commit 2/3486
...
INFO : Rewrite history ended. Took 01:43:51.5536779

Version of LibGit2Sharp (release number or SHA1)

0.26.0 + 2.0.267 (native)

Operating system(s) tested; .NET runtime tested

.net 4.6.1 - Win 2012R2

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia riproducendo il problema riportato con un repository contenente più di 3.000 commit e misura il ritardo tra “Rewrite history started” e il primo callback di CommitTreeRewriter. Ispeziona la chiamata a RewriteHistory e la configurazione di CommitTreeRewriter mostrati nell’issue. Il lavoro è completato quando la stessa riscrittura della cronologia termina in pochi minuti anziché in ore, mantenendo il comportamento di pruning riportato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
csharp, git
Ambito
devtools, performance
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.