Skip to content

Commit 1359cc5

Browse files
committed
Merge pull request #1090 from libgit2/ntk/coverity
Let's (try to) make Coverity's job easier
2 parents e10e223 + 611e412 commit 1359cc5

File tree

6 files changed

+31
-39
lines changed

6 files changed

+31
-39
lines changed

LibGit2Sharp.Tests/FilterFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ private FileInfo CheckoutFileForSmudge(string repoPath, string branchName, strin
304304
private static FileInfo CommitFileOnBranch(Repository repo, string branchName, String content)
305305
{
306306
var branch = repo.CreateBranch(branchName);
307-
repo.Checkout(branch.Name);
307+
repo.Checkout(branch.FriendlyName);
308308

309309
FileInfo expectedPath = StageNewFile(repo, content);
310310
repo.Commit("Commit");

LibGit2Sharp.Tests/FilterSubstitutionCipherFixture.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void SmugdeIsNotCalledForFileWhichDoesNotMatchAnAttributeEntry()
3535
Assert.Equal(0, filter.SmudgeCalledCount);
3636

3737
var branch = repo.CreateBranch("delete-files");
38-
repo.Checkout(branch.Name);
38+
repo.Checkout(branch.FriendlyName);
3939

4040
DeleteFile(repo, fileName);
4141

@@ -75,7 +75,7 @@ public void CorrectlyEncodesAndDecodesInput()
7575
Assert.Equal(0, filter.SmudgeCalledCount);
7676

7777
var branch = repo.CreateBranch("delete-files");
78-
repo.Checkout(branch.Name);
78+
repo.Checkout(branch.FriendlyName);
7979

8080
DeleteFile(repo, fileName);
8181

@@ -181,7 +181,7 @@ public void SmudgeIsCalledIfAttributeEntryMatches(string filterAttribute, string
181181
CommitOnBranchAndReturnDatabaseBlob(repo, fileName, decodedInput);
182182

183183
var branch = repo.CreateBranch("delete-files");
184-
repo.Checkout(branch.Name);
184+
repo.Checkout(branch.FriendlyName);
185185

186186
DeleteFile(repo, fileName);
187187

LibGit2Sharp/Core/Ensure.cs

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -250,44 +250,21 @@ public static void ArgumentPositiveInt32(long argumentValue, string argumentName
250250
/// <param name="identifier">The <see cref="GitObject"/> identifier to examine.</param>
251251
public static void GitObjectIsNotNull(GitObject gitObject, string identifier)
252252
{
253-
Func<string, LibGit2SharpException> exceptionBuilder;
254-
255-
if (string.Equals("HEAD", identifier, StringComparison.Ordinal))
256-
{
257-
exceptionBuilder = m => new UnbornBranchException(m);
258-
}
259-
else
253+
if (gitObject != null)
260254
{
261-
exceptionBuilder = m => new NotFoundException(m);
255+
return;
262256
}
263257

264-
GitObjectIsNotNull(gitObject, identifier, exceptionBuilder);
265-
}
266-
258+
var message = string.Format(CultureInfo.InvariantCulture,
259+
"No valid git object identified by '{0}' exists in the repository.",
260+
identifier);
267261

268-
/// <summary>
269-
/// Check that the result of a C call that returns a non-null GitObject
270-
/// using the default exception builder.
271-
/// <para>
272-
/// The native function is expected to return a valid object value.
273-
/// </para>
274-
/// </summary>
275-
/// <param name="gitObject">The <see cref="GitObject"/> to examine.</param>
276-
/// <param name="identifier">The <see cref="GitObject"/> identifier to examine.</param>
277-
/// <param name="exceptionBuilder">The builder which constructs an <see cref="LibGit2SharpException"/> from a message.</param>
278-
public static void GitObjectIsNotNull(
279-
GitObject gitObject,
280-
string identifier,
281-
Func<string, LibGit2SharpException> exceptionBuilder)
282-
{
283-
if (gitObject != null)
262+
if (string.Equals("HEAD", identifier, StringComparison.Ordinal))
284263
{
285-
return;
264+
throw new UnbornBranchException(message);
286265
}
287266

288-
throw exceptionBuilder(string.Format(CultureInfo.InvariantCulture,
289-
"No valid git object identified by '{0}' exists in the repository.",
290-
identifier));
267+
throw new NotFoundException(message);
291268
}
292269
}
293270
}

LibGit2Sharp/Repository.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,14 +1006,17 @@ public void CheckoutPaths(string committishOrBranchSpec, IEnumerable<string> pat
10061006
Ensure.ArgumentNotNullOrEmptyString(committishOrBranchSpec, "committishOrBranchSpec");
10071007
Ensure.ArgumentNotNull(paths, "paths");
10081008

1009+
var listOfPaths = paths.ToList();
1010+
10091011
// If there are no paths, then there is nothing to do.
1010-
if (!paths.Any())
1012+
if (listOfPaths.Count == 0)
10111013
{
10121014
return;
10131015
}
10141016

10151017
Commit commit = LookupCommit(committishOrBranchSpec);
1016-
CheckoutTree(commit.Tree, paths.ToList(), checkoutOptions ?? new CheckoutOptions());
1018+
1019+
CheckoutTree(commit.Tree, listOfPaths, checkoutOptions ?? new CheckoutOptions());
10171020
}
10181021

10191022
/// <summary>

LibGit2Sharp/RepositoryExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private static Commit RetrieveHeadCommit(IRepository repository)
9898
{
9999
Commit commit = repository.Head.Tip;
100100

101-
Ensure.GitObjectIsNotNull(commit, "HEAD", m => new UnbornBranchException(m));
101+
Ensure.GitObjectIsNotNull(commit, "HEAD");
102102

103103
return commit;
104104
}

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,25 @@
2828
[twitter]: http://twitter.com/libgit2sharp
2929

3030
## Current project build status
31+
3132
The CI builds are generously hosted and run on the [Travis][travis] and [AppVeyor][appveyor] infrastructures.
3233

3334
| | Windows (x86/amd64) | Linux/Mac OS X |
3435
| :------ | :------: | :------: |
3536
| **master** | [![master win][master-win-badge]][master-win] | [![master nix][master-nix-badge]][master-nix] |
3637
| **vNext** | [![vNext win][vNext-win-badge]][vNext-win] | [![vNext nix][vNext-nix-badge]][vNext-nix] |
3738

39+
The security oriented static code analysis is kindly run through the [Coverity][coverity] service.
40+
41+
| | Analysis result |
42+
|-------|-----------------|
43+
| **vNext** | [![coverity][coverity-badge]][coverity-project] |
44+
3845

39-
[travis]: http://travis-ci.org/
46+
[travis]: https://travis-ci.org/
4047
[appveyor]: http://appveyor.com/
48+
[coverity]: https://scan.coverity.com/
49+
4150
[master-win-badge]: https://ci.appveyor.com/api/projects/status/8qxcoqdo9kp7x2w9/branch/master?svg=true
4251
[master-win]: https://ci.appveyor.com/project/libgit2/libgit2sharp/branch/master
4352
[master-nix-badge]: https://travis-ci.org/libgit2/libgit2sharp.svg?branch=master
@@ -47,6 +56,9 @@ The CI builds are generously hosted and run on the [Travis][travis] and [AppVeyo
4756
[vNext-nix-badge]: https://travis-ci.org/libgit2/libgit2sharp.svg?branch=vNext
4857
[vNext-nix]: https://travis-ci.org/libgit2/libgit2sharp/branches
4958

59+
[coverity-project]: https://scan.coverity.com/projects/2088
60+
[coverity-badge]: https://scan.coverity.com/projects/2088/badge.svg
61+
5062
## Quick contributing guide
5163

5264
- Fork and clone locally

0 commit comments

Comments
 (0)