Remove unnecessary GitHelper.Free() function

This commit is contained in:
Oliver Hamlet
2016-07-13 20:48:18 +01:00
parent f8fe231fc2
commit 9633031298
3 changed files with 17 additions and 48 deletions
+17 -35
View File
@@ -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;
}
-1
View File
@@ -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);
@@ -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));
}