8000 Add PathCase and related Repository members · gitextensions/libgit2sharp@a187d2e · GitHub
[go: up one dir, main page]

Skip to content

Commit a187d2e

Browse files
dahlbyknulltoken
authored andcommitted
Add PathCase and related Repository members
1 parent 15e20b1 commit a187d2e

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

LibGit2Sharp/Core/PathCase.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
3+
namespace LibGit2Sharp.Core
4+
{
5+
internal class PathCase
6+
{
7+
private readonly StringComparer comparer;
8+
private readonly StringComparison comparison;
9+
10+
public PathCase(IRepository repo)
11+
{
12+
var value = repo.Config.Get<bool>("core.ignorecase");
13+
switch (value != null && value.Value)
14+
{
15+
case true:
16+
comparer = StringComparer.OrdinalIgnoreCase;
17+
comparison = StringComparison.OrdinalIgnoreCase;
18+
break;
19+
default:
20+
comparer = StringComparer.Ordinal;
21+
comparison = StringComparison.Ordinal;
22+
break;
23+
}
24+
}
25+
26+
public StringComparer Comparer
27+
{
28+
get { return comparer; }
29+
}
30+
31+
public bool StartsWith(string path, string value)
32+
{
33+
return path != null && path.StartsWith(value, comparison);
34+
}
35+
}
36+
}

LibGit2Sharp/LibGit2Sharp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
<Compile Include="Conflict.cs" />
7070
<Compile Include="ConflictCollection.cs" />
7171
<Compile Include="Core\Handles\GitFetchSpecHandle.cs" />
72+
<Compile Include="Core\PathCase.cs" />
7273
<Compile Include="Network.cs" />
7374
<Compile Include="Core\GitRemoteHead.cs" />
7475
<Compile Include="Stash.cs" />

LibGit2Sharp/Repository.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class Repository : IRepository
3737
private readonly Stack<IDisposable> toCleanup = new Stack<IDisposable>();
3838
private readonly Ignore ignore;
3939
private static readonly Lazy<string> versionRetriever = new Lazy<string>(RetrieveVersion);
40+
private readonly Lazy<PathCase> pathCase;
4041

4142
/// <summary>
4243
/// Initializes a new instance of the <see cref = "Repository" /> class, providing ooptional behavioral overrides through <paramref name="options"/> parameter.
@@ -116,6 +117,7 @@ public Repository(string path, RepositoryOptions options = null)
116117
notes = new NoteCollection(this);
117118
ignore = new Ignore(this);
118119
network = new Lazy<Network>(() => new Network(this));
120+
pathCase = new Lazy<PathCase>(() => new PathCase(this));
119121

120122
EagerlyLoadTheConfigIfAnyPathHaveBeenPassed(options);
121123
}
@@ -794,6 +796,16 @@ public virtual IEnumerable<MergeHead> MergeHeads
794796
}
795797
}
796798

799+
internal StringComparer PathComparer
800+
{
801+
get { return pathCase.Value.Comparer; }
802+
}
803+
804+
internal bool PathStartsWith(string path, string value)
805+
{
806+
return pathCase.Value.StartsWith(path, value);
807+
}
808+
797809
private string DebuggerDisplay
798810
{
799811
get

0 commit comments

Comments
 (0)
0