Skip to content

Commit 28016db

Browse files
committed
fixup! [WIP] Introduce CommitFilter.Parse()
1 parent a289bbf commit 28016db

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

LibGit2Sharp.Tests/CommitFilterFixture.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class CommitFilterFixture : BaseFixture
1111
[InlineData("HEAD^", "HEAD^", null)]
1212
[InlineData("HEAD^..HEAD", "HEAD", "HEAD^")]
1313
[InlineData("HEAD^..", null, "HEAD^")]
14+
[InlineData("..HEAD^", "HEAD^", null)]
1415
public void tada(string expression, object includeReachableFrom, object excludeReachableFrom)
1516
{
1617
CommitFilter cf = CommitFilter.Parse(expression);
@@ -19,6 +20,14 @@ public void tada(string expression, object includeReachableFrom, object excludeR
1920
Assert.Equal(excludeReachableFrom, cf.ExcludeReachableFrom);
2021
}
2122

23+
[Theory]
24+
[InlineData("..")]
25+
[InlineData("...")]
26+
public void tada2(string expression)
27+
{
28+
Assert.Throws<InvalidOperationException>(() => CommitFilter.Parse(expression));
29+
}
30+
2231
[Fact]
2332
public void throws()
2433
{

LibGit2Sharp/CommitFilter.cs

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,49 @@ public static CommitFilter Parse(string expression)
148148

149149
private static CommitFilter MergeRangeParse(string expression)
150150
{
151+
var parts = Strings(expression, "...");
152+
151153
throw new NotImplementedException();
152154
}
153155

154156
private static CommitFilter RangeParse(string expression)
155157
{
156-
var parts = expression.Split(new[] { ".." }, StringSplitOptions.None);
158+
var parts = Strings(expression, "..");
159+
160+
return new CommitFilter { IncludeReachableFrom = parts[1], ExcludeReachableFrom = parts[0] };
161+
}
162+
163+
static readonly Func<string, string> Nullify = s => s == string.Empty ? null : s;
164+
165+
private static string[] Strings(string expression, string rangeSeparator)
166+
{
167+
var parts = expression.Split(new[] { rangeSeparator }, StringSplitOptions.None);
168+
169+
if (parts.Length != 2)
170+
{
171+
throw new InvalidOperationException();
172+
}
157173

158-
Debug.Assert(parts.Length == 2);
174+
int nullsCount = 0;
175+
176+
for (int i = 0; i < parts.Length; i++)
177+
{
178+
string part = Nullify(parts[i]);
159179

160-
Func<string, string> nullify = (s) => s == string.Empty ? null : s;
180+
if (part == default(string))
181+
{
182+
nullsCount++;
183+
}
184+
185+
if (nullsCount > 1)
186+
{
187+
throw new InvalidOperationException();
188+
}
189+
190+
parts[i] = part;
191+
}
161192

162-
return new CommitFilter { IncludeReachableFrom = nullify(parts[1]), ExcludeReachableFrom = nullify(parts[0]) };
193+
return parts;
163194
}
164195
}
165196
}

0 commit comments

Comments
 (0)