Skip to content

Commit e304d9e

Browse files
David van Luijk | IAIDavid van Luijk | IAI
authored andcommitted
RetrieveStatus-take-so-long-time-about-5s - Add UpdateIndex to StatusOptions to improve performance for subsequent calls available on libgit2sharp API
1 parent cb58177 commit e304d9e

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

LibGit2Sharp.Tests/StatusFixture.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,5 +660,19 @@ public void UnalteredFilesDontMarkIndexAsDirty()
660660
Assert.Equal(9, status.Count());
661661
}
662662
}
663+
664+
[Fact]
665+
public void TestUpdateIndexDoesNotFail()
666+
{
667+
var path = SandboxStandardTestRepo();
668+
669+
using (var repo = new Repository(path))
670+
{
671+
// This option improves the performance of subsequent calls,
672+
// but there isn't really an observable difference to assert
673+
// Therefor enable the option and to ensure it doesn't trigger and exception is the only thing possible
674+
repo.RetrieveStatus(new StatusOptions() { UpdateIndex = true });
675+
}
676+
}
663677
}
664678
}

LibGit2Sharp/RepositoryStatus.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ private static GitStatusOptions CreateStatusOptions(StatusOptions options)
139139
GitStatusOptionFlags.IncludeUnmodified;
140140
}
141141

142+
if (options.UpdateIndex)
143+
{
144+
coreOptions.Flags |=
145+
GitStatusOptionFlags.UpdateIndex;
146+
}
147+
142148
return coreOptions;
143149
}
144150

LibGit2Sharp/StatusOptions.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,13 @@ public StatusOptions()
105105
/// Include untracked files when scanning for status
106106
/// </summary>
107107
public bool IncludeUntracked { get; set; }
108+
109+
/// <summary>
110+
/// Refresh out of date index and save it in index
111+
/// </summary>
112+
/// <remarks>
113+
/// Will result in less work being done in subsequent calls
114+
/// </remarks>
115+
public bool UpdateIndex { get; set; }
108116
}
109117
}

0 commit comments

Comments
 (0)