diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2022-08-29 19:01:36 +0200 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2022-12-21 14:44:08 +0100 |
commit | 2c994adbd2d5778bb881bd792a57294f86e143b1 (patch) | |
tree | 653250cbd6c5c38667ac69de406be4735ba4f541 /src/buildtool/file_system/git_utils.cpp | |
parent | ecff253633ada6ca88db8ab207c593ebde033044 (diff) | |
download | justbuild-2c994adbd2d5778bb881bd792a57294f86e143b1.tar.gz |
Git: Wrap libgit2 raw pointers
Diffstat (limited to 'src/buildtool/file_system/git_utils.cpp')
-rw-r--r-- | src/buildtool/file_system/git_utils.cpp | 99 |
1 files changed, 99 insertions, 0 deletions
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 <git2.h> +} + +void repo_closer(gsl::owner<git_repository*> repo) { +#ifndef BOOTSTRAP_BUILD_TOOL + git_repository_free(repo); +#endif +} + +void odb_closer(gsl::owner<git_odb*> odb) { +#ifndef BOOTSTRAP_BUILD_TOOL + git_odb_free(odb); +#endif +} + +void tree_closer(gsl::owner<git_tree*> tree) { +#ifndef BOOTSTRAP_BUILD_TOOL + git_tree_free(tree); +#endif +} + +void treebuilder_closer(gsl::owner<git_treebuilder*> builder) { +#ifndef BOOTSTRAP_BUILD_TOOL + git_treebuilder_free(builder); +#endif +} + +void index_closer(gsl::owner<git_index*> index) { +#ifndef BOOTSTRAP_BUILD_TOOL + git_index_free(index); +#endif +} + +void strarray_closer(gsl::owner<git_strarray*> strarray) { +#ifndef BOOTSTRAP_BUILD_TOOL + git_strarray_dispose(strarray); +#endif +} + +void strarray_deleter(gsl::owner<git_strarray*> 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<git_signature*> signature) { +#ifndef BOOTSTRAP_BUILD_TOOL + git_signature_free(signature); +#endif +} + +void object_closer(gsl::owner<git_object*> object) { +#ifndef BOOTSTRAP_BUILD_TOOL + git_object_free(object); +#endif +} + +void remote_closer(gsl::owner<git_remote*> remote) { +#ifndef BOOTSTRAP_BUILD_TOOL + git_remote_free(remote); +#endif +} + +void commit_closer(gsl::owner<git_commit*> commit) { +#ifndef BOOTSTRAP_BUILD_TOOL + git_commit_free(commit); +#endif +} + +void tree_entry_closer(gsl::owner<git_tree_entry*> tree_entry) { +#ifndef BOOTSTRAP_BUILD_TOOL + git_tree_entry_free(tree_entry); +#endif +} |