Skip to content

Commit

Permalink
Fix dupfinder warning cause
Browse files Browse the repository at this point in the history
  • Loading branch information
vCipher committed Jan 27, 2018
1 parent 64d3afc commit 3ea7b1b
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/HgVersion/VCS/HgRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ public HgRepository(Repository repository)
/// <inheritdoc />
public IEnumerable<ICommit> Log(ILogQuery query)
{
if (query == null)
throw new ArgumentNullException(nameof(query));

if (!(query is HgLogQuery hgQuery))
throw new InvalidOperationException($"{query.GetType()} is not supported.");
var hgQuery = CastTo<HgLogQuery>(query);

return _repository
.Log(new LogCommand()
Expand All @@ -56,12 +52,7 @@ public IEnumerable<ICommit> Log(Func<ILogQueryBuilder, ILogQuery> select)
/// <inheritdoc />
public int Count(ILogQuery query)
{
if (query == null)
throw new ArgumentNullException(nameof(query));

if (!(query is HgLogQuery hgQuery))
throw new InvalidOperationException($"{query.GetType()} is not supported.");

var hgQuery = CastTo<HgLogQuery>(query);
var command = new CountCommand()
.WithRevision(hgQuery.Revision);

Expand Down Expand Up @@ -146,9 +137,7 @@ public string Commit(string message)
/// <inheritdoc />
public IEnumerable<ICommit> Parents(ICommit commit)
{
if (!(commit is HgCommit hgCommit))
throw new InvalidOperationException($"{commit.GetType()} is not supported.");

var hgCommit = CastTo<HgCommit>(commit);
var command = new ParentsCommand()
.WithRevision(hgCommit);

Expand Down Expand Up @@ -202,5 +191,16 @@ public void Update(RevSpec rev)
/// <returns></returns>
public static implicit operator HgRepository(Repository repository) =>
new HgRepository(repository);

private static T CastTo<T>(object from)
{
if (from == null)
throw new ArgumentNullException(nameof(from));

if (!(from is T to))
throw new InvalidCastException($"{from.GetType()} is not supported.");

return to;
}
}
}

0 comments on commit 3ea7b1b

Please sign in to comment.