From 9633031298d9f03b1bfef4e8697f62246578fdda Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Mon, 11 Jul 2016 18:57:50 +0100 Subject: [PATCH] Remove unnecessary GitHelper.Free() function --- src/backend/helpers/git_helper.cpp | 52 +++++++-------------- src/backend/helpers/git_helper.h | 1 - src/tests/backend/helpers/git_helper_test.h | 12 ----- 3 files changed, 17 insertions(+), 48 deletions(-) diff --git a/src/backend/helpers/git_helper.cpp b/src/backend/helpers/git_helper.cpp index 5e6ae358..fe1daeb9 100644 --- a/src/backend/helpers/git_helper.cpp +++ b/src/backend/helpers/git_helper.cpp @@ -60,7 +60,23 @@ namespace loot { if (repo != nullptr) path = git_repository_path(repo); - Free(); + git_commit_free(commit); + git_object_free(obj); + git_config_free(cfg); + git_remote_free(remote); + git_repository_free(repo); + git_reference_free(ref); + git_reference_free(ref2); + git_blob_free(blob); + git_annotated_commit_free(annotated_commit); + git_tree_free(tree); + git_diff_free(diff); + git_buf_free(&buf); + + // Also free any path strings in the checkout options. + for (size_t i = 0; i < checkout_options.paths.count; ++i) { + delete[] checkout_options.paths.strings[i]; + } if (!path.empty()) { try { @@ -95,40 +111,6 @@ namespace loot { errorMessage = message; } - void GitHelper::Free() { - git_commit_free(commit); - git_object_free(obj); - git_config_free(cfg); - git_remote_free(remote); - git_repository_free(repo); - git_reference_free(ref); - git_reference_free(ref2); - git_blob_free(blob); - git_annotated_commit_free(annotated_commit); - git_tree_free(tree); - git_diff_free(diff); - git_buf_free(&buf); - - commit = nullptr; - obj = nullptr; - cfg = nullptr; - remote = nullptr; - repo = nullptr; - ref = nullptr; - ref2 = nullptr; - blob = nullptr; - annotated_commit = nullptr; - tree = nullptr; - diff = nullptr; - buf = {0}; - - // Also free any path strings in the checkout options. - for (size_t i = 0; i < checkout_options.paths.count; ++i) { - delete[] checkout_options.paths.strings[i]; - checkout_options.paths.strings[i] = nullptr; - } - } - bool GitHelper::IsRepository(const boost::filesystem::path& path) { return git_repository_open_ext(NULL, path.string().c_str(), GIT_REPOSITORY_OPEN_NO_SEARCH, NULL) == 0; } diff --git a/src/backend/helpers/git_helper.h b/src/backend/helpers/git_helper.h index 0e115f77..0333b084 100644 --- a/src/backend/helpers/git_helper.h +++ b/src/backend/helpers/git_helper.h @@ -39,7 +39,6 @@ namespace loot { void Call(int error_code); void SetErrorMessage(const std::string& message); - void Free(); static bool IsRepository(const boost::filesystem::path& path); diff --git a/src/tests/backend/helpers/git_helper_test.h b/src/tests/backend/helpers/git_helper_test.h index 0c5a5143..aced1b84 100644 --- a/src/tests/backend/helpers/git_helper_test.h +++ b/src/tests/backend/helpers/git_helper_test.h @@ -110,18 +110,6 @@ namespace loot { } } - TEST_F(GitHelperTest, freeShouldFreeMemoryAllocatedToMembers) { - // Initialise buffer member, it's simplest to test with. - GitHelper git; - git_buf_set(&git.buf, "foo", 4); - ASSERT_NE(nullptr, git.buf.ptr); - ASSERT_EQ(4, git.buf.size); - - git.Free(); - EXPECT_EQ(nullptr, git.buf.ptr); - EXPECT_EQ(0, git.buf.size); - } - TEST_F(GitHelperTest, isRepositoryShouldReturnTrueForARepositoryRoot) { EXPECT_TRUE(GitHelper::IsRepository(parentRepoRoot)); }