From 2c994adbd2d5778bb881bd792a57294f86e143b1 Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Mon, 29 Aug 2022 19:01:36 +0200 Subject: Git: Wrap libgit2 raw pointers --- src/buildtool/file_system/git_utils.cpp | 99 +++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 src/buildtool/file_system/git_utils.cpp (limited to 'src/buildtool/file_system/git_utils.cpp') diff --git a/src/buildtool/file_system/git_utils.cpp b/src/buildtool/file_system/git_utils.cpp new file mode 100644 index 00000000..ec3b5f6d --- /dev/null +++ b/src/buildtool/file_system/git_utils.cpp @@ -0,0 +1,99 @@ +// Copyright 2022 Huawei Cloud Computing Technology Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "src/buildtool/file_system/git_utils.hpp" + +extern "C" { +#include +} + +void repo_closer(gsl::owner repo) { +#ifndef BOOTSTRAP_BUILD_TOOL + git_repository_free(repo); +#endif +} + +void odb_closer(gsl::owner odb) { +#ifndef BOOTSTRAP_BUILD_TOOL + git_odb_free(odb); +#endif +} + +void tree_closer(gsl::owner tree) { +#ifndef BOOTSTRAP_BUILD_TOOL + git_tree_free(tree); +#endif +} + +void treebuilder_closer(gsl::owner builder) { +#ifndef BOOTSTRAP_BUILD_TOOL + git_treebuilder_free(builder); +#endif +} + +void index_closer(gsl::owner index) { +#ifndef BOOTSTRAP_BUILD_TOOL + git_index_free(index); +#endif +} + +void strarray_closer(gsl::owner strarray) { +#ifndef BOOTSTRAP_BUILD_TOOL + git_strarray_dispose(strarray); +#endif +} + +void strarray_deleter(gsl::owner strarray) { +#ifndef BOOTSTRAP_BUILD_TOOL + if (strarray->strings != nullptr) { + for (size_t i = 0; i < strarray->count; ++i) { + // NOLINTNEXTLINE(cppcoreguidelines-owning-memory,cppcoreguidelines-pro-bounds-pointer-arithmetic) + delete[] strarray->strings[i]; + } + delete[] strarray->strings; + strarray->strings = nullptr; + strarray->count = 0; + } +#endif +} + +void signature_closer(gsl::owner signature) { +#ifndef BOOTSTRAP_BUILD_TOOL + git_signature_free(signature); +#endif +} + +void object_closer(gsl::owner object) { +#ifndef BOOTSTRAP_BUILD_TOOL + git_object_free(object); +#endif +} + +void remote_closer(gsl::owner remote) { +#ifndef BOOTSTRAP_BUILD_TOOL + git_remote_free(remote); +#endif +} + +void commit_closer(gsl::owner commit) { +#ifndef BOOTSTRAP_BUILD_TOOL + git_commit_free(commit); +#endif +} + +void tree_entry_closer(gsl::owner tree_entry) { +#ifndef BOOTSTRAP_BUILD_TOOL + git_tree_entry_free(tree_entry); +#endif +} -- cgit v1.2.3