Permalink
Browse files

Add PathCase and related Repository members

  • Loading branch information...
dahlbyk authored and nulltoken committed Feb 19, 2013
1 parent 15e20b1 commit a187d2e5fef360db21b4a4ede050600d4aed1e48
Showing with 49 additions and 0 deletions.
  1. +36 −0 LibGit2Sharp/Core/PathCase.cs
  2. +1 −0 LibGit2Sharp/LibGit2Sharp.csproj
  3. +12 −0 LibGit2Sharp/Repository.cs
@@ -0,0 +1,36 @@
+using System;
+
+namespace LibGit2Sharp.Core
+{
+ internal class PathCase
+ {
+ private readonly StringComparer comparer;
+ private readonly StringComparison comparison;
+
+ public PathCase(IRepository repo)
+ {
+ var value = repo.Config.Get<bool>("core.ignorecase");
+ switch (value != null && value.Value)
+ {
+ case true:
+ comparer = StringComparer.OrdinalIgnoreCase;
+ comparison = StringComparison.OrdinalIgnoreCase;
+ break;
+ default:
+ comparer = StringComparer.Ordinal;
+ comparison = StringComparison.Ordinal;
+ break;
+ }
+ }
+
+ public StringComparer Comparer
+ {
+ get { return comparer; }
+ }
+
+ public bool StartsWith(string path, string value)
+ {
+ return path != null && path.StartsWith(value, comparison);
+ }
+ }
+}
@@ -69,6 +69,7 @@
<Compile Include="Conflict.cs" />
<Compile Include="ConflictCollection.cs" />
<Compile Include="Core\Handles\GitFetchSpecHandle.cs" />
+ <Compile Include="Core\PathCase.cs" />
<Compile Include="Network.cs" />
<Compile Include="Core\GitRemoteHead.cs" />
<Compile Include="Stash.cs" />
View
@@ -37,6 +37,7 @@ public class Repository : IRepository
private readonly Stack<IDisposable> toCleanup = new Stack<IDisposable>();
private readonly Ignore ignore;
private static readonly Lazy<string> versionRetriever = new Lazy<string>(RetrieveVersion);
+ private readonly Lazy<PathCase> pathCase;
/// <summary>
/// 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)
notes = new NoteCollection(this);
ignore = new Ignore(this);
network = new Lazy<Network>(() => new Network(this));
+ pathCase = new Lazy<PathCase>(() => new PathCase(this));
EagerlyLoadTheConfigIfAnyPathHaveBeenPassed(options);
}
@@ -794,6 +796,16 @@ public virtual IEnumerable<MergeHead> MergeHeads
}
}
+ internal StringComparer PathComparer
+ {
+ get { return pathCase.Value.Comparer; }
+ }
+
+ internal bool PathStartsWith(string path, string value)
+ {
+ return pathCase.Value.StartsWith(path, value);
+ }
+
private string DebuggerDisplay
{
get

0 comments on commit a187d2e

Please sign in to comment.