From 6747421e975b84f52d588ddb2c0383e3ef462355 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Thu, 11 Jun 2015 11:34:41 +0200 Subject: [PATCH 1/5] Prevent multiple enumerations --- LibGit2Sharp/Repository.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs index 030a79829..77e928f38 100644 --- a/LibGit2Sharp/Repository.cs +++ b/LibGit2Sharp/Repository.cs @@ -1006,14 +1006,17 @@ public void CheckoutPaths(string committishOrBranchSpec, IEnumerable pat Ensure.ArgumentNotNullOrEmptyString(committishOrBranchSpec, "committishOrBranchSpec"); Ensure.ArgumentNotNull(paths, "paths"); + var listOfPaths = paths.ToList(); + // If there are no paths, then there is nothing to do. - if (!paths.Any()) + if (listOfPaths.Count == 0) { return; } Commit commit = LookupCommit(committishOrBranchSpec); - CheckoutTree(commit.Tree, paths.ToList(), checkoutOptions ?? new CheckoutOptions()); + + CheckoutTree(commit.Tree, listOfPaths, checkoutOptions ?? new CheckoutOptions()); } /// From e4bb41243958b0b670ebe9ea182369d359ef804f Mon Sep 17 00:00:00 2001 From: nulltoken Date: Thu, 11 Jun 2015 11:54:20 +0200 Subject: [PATCH 2/5] Fix build warnings by not relying on obsolete properties --- LibGit2Sharp.Tests/FilterFixture.cs | 2 +- LibGit2Sharp.Tests/FilterSubstitutionCipherFixture.cs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/LibGit2Sharp.Tests/FilterFixture.cs b/LibGit2Sharp.Tests/FilterFixture.cs index 1de81595d..b0480256a 100644 --- a/LibGit2Sharp.Tests/FilterFixture.cs +++ b/LibGit2Sharp.Tests/FilterFixture.cs @@ -304,7 +304,7 @@ private FileInfo CheckoutFileForSmudge(string repoPath, string branchName, strin private static FileInfo CommitFileOnBranch(Repository repo, string branchName, String content) { var branch = repo.CreateBranch(branchName); - repo.Checkout(branch.Name); + repo.Checkout(branch.FriendlyName); FileInfo expectedPath = StageNewFile(repo, content); repo.Commit("Commit"); diff --git a/LibGit2Sharp.Tests/FilterSubstitutionCipherFixture.cs b/LibGit2Sharp.Tests/FilterSubstitutionCipherFixture.cs index b2610a574..1ef2f47a1 100644 --- a/LibGit2Sharp.Tests/FilterSubstitutionCipherFixture.cs +++ b/LibGit2Sharp.Tests/FilterSubstitutionCipherFixture.cs @@ -35,7 +35,7 @@ public void SmugdeIsNotCalledForFileWhichDoesNotMatchAnAttributeEntry() Assert.Equal(0, filter.SmudgeCalledCount); var branch = repo.CreateBranch("delete-files"); - repo.Checkout(branch.Name); + repo.Checkout(branch.FriendlyName); DeleteFile(repo, fileName); @@ -75,7 +75,7 @@ public void CorrectlyEncodesAndDecodesInput() Assert.Equal(0, filter.SmudgeCalledCount); var branch = repo.CreateBranch("delete-files"); - repo.Checkout(branch.Name); + repo.Checkout(branch.FriendlyName); DeleteFile(repo, fileName); @@ -181,7 +181,7 @@ public void SmudgeIsCalledIfAttributeEntryMatches(string filterAttribute, string CommitOnBranchAndReturnDatabaseBlob(repo, fileName, decodedInput); var branch = repo.CreateBranch("delete-files"); - repo.Checkout(branch.Name); + repo.Checkout(branch.FriendlyName); DeleteFile(repo, fileName); From 8212155b2477d153811c37c50e12467b7ab98715 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Thu, 11 Jun 2015 12:12:55 +0200 Subject: [PATCH 3/5] Remove duplicated code --- LibGit2Sharp/RepositoryExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LibGit2Sharp/RepositoryExtensions.cs b/LibGit2Sharp/RepositoryExtensions.cs index 922ff82cd..57f7b8601 100644 --- a/LibGit2Sharp/RepositoryExtensions.cs +++ b/LibGit2Sharp/RepositoryExtensions.cs @@ -98,7 +98,7 @@ private static Commit RetrieveHeadCommit(IRepository repository) { Commit commit = repository.Head.Tip; - Ensure.GitObjectIsNotNull(commit, "HEAD", m => new UnbornBranchException(m)); + Ensure.GitObjectIsNotNull(commit, "HEAD"); return commit; } From 02264deffbcc08bc4371e4ac598d854d00603959 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Thu, 11 Jun 2015 12:13:48 +0200 Subject: [PATCH 4/5] Simplify GitObjectIsNotNull implementation --- LibGit2Sharp/Core/Ensure.cs | 39 ++++++++----------------------------- 1 file changed, 8 insertions(+), 31 deletions(-) diff --git a/LibGit2Sharp/Core/Ensure.cs b/LibGit2Sharp/Core/Ensure.cs index b051c8505..04303ca3d 100644 --- a/LibGit2Sharp/Core/Ensure.cs +++ b/LibGit2Sharp/Core/Ensure.cs @@ -250,44 +250,21 @@ public static void ArgumentPositiveInt32(long argumentValue, string argumentName /// The identifier to examine. public static void GitObjectIsNotNull(GitObject gitObject, string identifier) { - Func exceptionBuilder; - - if (string.Equals("HEAD", identifier, StringComparison.Ordinal)) - { - exceptionBuilder = m => new UnbornBranchException(m); - } - else + if (gitObject != null) { - exceptionBuilder = m => new NotFoundException(m); + return; } - GitObjectIsNotNull(gitObject, identifier, exceptionBuilder); - } - + var message = string.Format(CultureInfo.InvariantCulture, + "No valid git object identified by '{0}' exists in the repository.", + identifier); - /// - /// Check that the result of a C call that returns a non-null GitObject - /// using the default exception builder. - /// - /// The native function is expected to return a valid object value. - /// - /// - /// The to examine. - /// The identifier to examine. - /// The builder which constructs an from a message. - public static void GitObjectIsNotNull( - GitObject gitObject, - string identifier, - Func exceptionBuilder) - { - if (gitObject != null) + if (string.Equals("HEAD", identifier, StringComparison.Ordinal)) { - return; + throw new UnbornBranchException(message); } - throw exceptionBuilder(string.Format(CultureInfo.InvariantCulture, - "No valid git object identified by '{0}' exists in the repository.", - identifier)); + throw new NotFoundException(message); } } } From 611e4123fa078d72111e89c57f49a3fc3fe61205 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Thu, 11 Jun 2015 13:04:34 +0200 Subject: [PATCH 5/5] Link to Coverity from the README --- README.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b3dd52d5f..0c0b0fe10 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ [twitter]: http://twitter.com/libgit2sharp ## Current project build status + The CI builds are generously hosted and run on the [Travis][travis] and [AppVeyor][appveyor] infrastructures. | | Windows (x86/amd64) | Linux/Mac OS X | @@ -35,9 +36,17 @@ The CI builds are generously hosted and run on the [Travis][travis] and [AppVeyo | **master** | [![master win][master-win-badge]][master-win] | [![master nix][master-nix-badge]][master-nix] | | **vNext** | [![vNext win][vNext-win-badge]][vNext-win] | [![vNext nix][vNext-nix-badge]][vNext-nix] | +The security oriented static code analysis is kindly run through the [Coverity][coverity] service. + +| | Analysis result | +|-------|-----------------| +| **vNext** | [![coverity][coverity-badge]][coverity-project] | + - [travis]: http://travis-ci.org/ + [travis]: https://travis-ci.org/ [appveyor]: http://appveyor.com/ + [coverity]: https://scan.coverity.com/ + [master-win-badge]: https://ci.appveyor.com/api/projects/status/8qxcoqdo9kp7x2w9/branch/master?svg=true [master-win]: https://ci.appveyor.com/project/libgit2/libgit2sharp/branch/master [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 [vNext-nix-badge]: https://travis-ci.org/libgit2/libgit2sharp.svg?branch=vNext [vNext-nix]: https://travis-ci.org/libgit2/libgit2sharp/branches + [coverity-project]: https://scan.coverity.com/projects/2088 + [coverity-badge]: https://scan.coverity.com/projects/2088/badge.svg + ## Quick contributing guide - Fork and clone locally