Commit c6184f0c by Patrick Steinhardt

tree-wide: do not compile deprecated functions with hard deprecation

When compiling libgit2 with -DDEPRECATE_HARD, we add a preprocessor
definition `GIT_DEPRECATE_HARD` which causes the "git2/deprecated.h"
header to be empty. As a result, no function declarations are made
available to callers, but the implementations are still available to
link against. This has the problem that function declarations also
aren't visible to the implementations, meaning that the symbol's
visibility will not be set up correctly. As a result, the resulting
library may not expose those deprecated symbols at all on some platforms
and thus cause linking errors.

Fix the issue by conditionally compiling deprecated functions, only.
While it becomes impossible to link against such a library in case one
uses deprecated functions, distributors of libgit2 aren't expected to
pass -DDEPRECATE_HARD anyway. Instead, users of libgit2 should manually
define GIT_DEPRECATE_HARD to hide deprecated functions. Using "real"
hard deprecation still makes sense in the context of CI to test we don't
use deprecated symbols ourselves and in case a dependant uses libgit2 in
a vendored way and knows it won't ever use any of the deprecated symbols
anyway.
parent 6e1efcd6
......@@ -538,7 +538,9 @@ int git_blame_options_init(git_blame_options *opts, unsigned int version)
return 0;
}
#ifndef GIT_DEPRECATE_HARD
int git_blame_init_options(git_blame_options *opts, unsigned int version)
{
return git_blame_options_init(opts, version);
}
#endif
......@@ -445,6 +445,7 @@ int git_blob_filter(
/* Deprecated functions */
#ifndef GIT_DEPRECATE_HARD
int git_blob_create_frombuffer(
git_oid *id, git_repository *repo, const void *buffer, size_t len)
{
......@@ -491,3 +492,4 @@ int git_blob_filtered_content(
return git_blob_filter(out, blob, path, &opts);
}
#endif
......@@ -133,10 +133,12 @@ void git_buf_dispose(git_buf *buf)
git_buf_init(buf, 0);
}
#ifndef GIT_DEPRECATE_HARD
void git_buf_free(git_buf *buf)
{
git_buf_dispose(buf);
}
#endif
void git_buf_sanitize(git_buf *buf)
{
......
......@@ -2820,7 +2820,9 @@ int git_checkout_options_init(git_checkout_options *opts, unsigned int version)
return 0;
}
#ifndef GIT_DEPRECATE_HARD
int git_checkout_init_options(git_checkout_options *opts, unsigned int version)
{
return git_checkout_options_init(opts, version);
}
#endif
......@@ -229,8 +229,10 @@ int git_cherrypick_options_init(
return 0;
}
#ifndef GIT_DEPRECATE_HARD
int git_cherrypick_init_options(
git_cherrypick_options *opts, unsigned int version)
{
return git_cherrypick_options_init(opts, version);
}
#endif
......@@ -479,10 +479,12 @@ int git_clone_options_init(git_clone_options *opts, unsigned int version)
return 0;
}
#ifndef GIT_DEPRECATE_HARD
int git_clone_init_options(git_clone_options *opts, unsigned int version)
{
return git_clone_options_init(opts, version);
}
#endif
static bool can_link(const char *src, const char *dst, int link)
{
......
......@@ -876,10 +876,12 @@ int git_describe_options_init(git_describe_options *opts, unsigned int version)
return 0;
}
#ifndef GIT_DEPRECATE_HARD
int git_describe_init_options(git_describe_options *opts, unsigned int version)
{
return git_describe_options_init(opts, version);
}
#endif
int git_describe_format_options_init(git_describe_format_options *opts, unsigned int version)
{
......@@ -888,7 +890,9 @@ int git_describe_format_options_init(git_describe_format_options *opts, unsigned
return 0;
}
#ifndef GIT_DEPRECATE_HARD
int git_describe_init_format_options(git_describe_format_options *opts, unsigned int version)
{
return git_describe_format_options_init(opts, version);
}
#endif
......@@ -352,10 +352,12 @@ int git_diff_options_init(git_diff_options *opts, unsigned int version)
return 0;
}
#ifndef GIT_DEPRECATE_HARD
int git_diff_init_options(git_diff_options *opts, unsigned int version)
{
return git_diff_options_init(opts, version);
}
#endif
int git_diff_find_options_init(
git_diff_find_options *opts, unsigned int version)
......@@ -365,11 +367,13 @@ int git_diff_find_options_init(
return 0;
}
#ifndef GIT_DEPRECATE_HARD
int git_diff_find_init_options(
git_diff_find_options *opts, unsigned int version)
{
return git_diff_find_options_init(opts, version);
}
#endif
int git_diff_format_email_options_init(
git_diff_format_email_options *opts, unsigned int version)
......@@ -380,11 +384,13 @@ int git_diff_format_email_options_init(
return 0;
}
#ifndef GIT_DEPRECATE_HARD
int git_diff_format_email_init_options(
git_diff_format_email_options *opts, unsigned int version)
{
return git_diff_format_email_options_init(opts, version);
}
#endif
static int flush_hunk(git_oid *result, git_hash_ctx *ctx)
{
......
......@@ -210,6 +210,7 @@ void git_error_system_set(int code)
/* Deprecated error values and functions */
#ifndef GIT_DEPRECATE_HARD
const git_error *giterr_last(void)
{
return git_error_last();
......@@ -229,3 +230,4 @@ void giterr_set_oom(void)
{
git_error_set_oom();
}
#endif
......@@ -155,7 +155,9 @@ int git_fetch_options_init(git_fetch_options *opts, unsigned int version)
return 0;
}
#ifndef GIT_DEPRECATE_HARD
int git_fetch_init_options(git_fetch_options *opts, unsigned int version)
{
return git_fetch_options_init(opts, version);
}
#endif
......@@ -3717,9 +3717,11 @@ void git_indexwriter_cleanup(git_indexwriter *writer)
/* Deprecated functions */
#ifndef GIT_DEPRECATE_HARD
int git_index_add_frombuffer(
git_index *index, const git_index_entry *source_entry,
const void *buffer, size_t len)
{
return git_index_add_from_buffer(index, source_entry, buffer, len);
}
#endif
......@@ -123,10 +123,12 @@ int git_indexer_options_init(git_indexer_options *opts, unsigned int version)
return 0;
}
#ifndef GIT_DEPRECATE_HARD
int git_indexer_init_options(git_indexer_options *opts, unsigned int version)
{
return git_indexer_options_init(opts, version);
}
#endif
int git_indexer_new(
git_indexer **out,
......
......@@ -3351,10 +3351,12 @@ int git_merge_options_init(git_merge_options *opts, unsigned int version)
return 0;
}
#ifndef GIT_DEPRECATE_HARD
int git_merge_init_options(git_merge_options *opts, unsigned int version)
{
return git_merge_options_init(opts, version);
}
#endif
int git_merge_file_input_init(git_merge_file_input *input, unsigned int version)
{
......@@ -3363,10 +3365,12 @@ int git_merge_file_input_init(git_merge_file_input *input, unsigned int version)
return 0;
}
#ifndef GIT_DEPRECATE_HARD
int git_merge_file_init_input(git_merge_file_input *input, unsigned int version)
{
return git_merge_file_input_init(input, version);
}
#endif
int git_merge_file_options_init(
git_merge_file_options *opts, unsigned int version)
......@@ -3376,8 +3380,10 @@ int git_merge_file_options_init(
return 0;
}
#ifndef GIT_DEPRECATE_HARD
int git_merge_file_init_options(
git_merge_file_options *opts, unsigned int version)
{
return git_merge_file_options_init(opts, version);
}
#endif
......@@ -1510,10 +1510,12 @@ void *git_odb_backend_data_alloc(git_odb_backend *backend, size_t len)
return git__malloc(len);
}
#ifndef GIT_DEPRECATE_HARD
void *git_odb_backend_malloc(git_odb_backend *backend, size_t len)
{
return git_odb_backend_data_alloc(backend, len);
}
#endif
void git_odb_backend_data_free(git_odb_backend *backend, void *data)
{
......
......@@ -253,10 +253,12 @@ int git_oid_is_zero(const git_oid *oid_a)
return 1;
}
#ifndef GIT_DEPRECATE_HARD
int git_oid_iszero(const git_oid *oid_a)
{
return git_oid_is_zero(oid_a);
}
#endif
typedef short node_index;
......
......@@ -16,10 +16,12 @@ int git_proxy_options_init(git_proxy_options *opts, unsigned int version)
return 0;
}
#ifndef GIT_DEPRECATE_HARD
int git_proxy_init_options(git_proxy_options *opts, unsigned int version)
{
return git_proxy_options_init(opts, version);
}
#endif
int git_proxy_options_dup(git_proxy_options *tgt, const git_proxy_options *src)
{
......
......@@ -555,7 +555,9 @@ int git_push_options_init(git_push_options *opts, unsigned int version)
return 0;
}
#ifndef GIT_DEPRECATE_HARD
int git_push_init_options(git_push_options *opts, unsigned int version)
{
return git_push_options_init(opts, version);
}
#endif
......@@ -501,10 +501,12 @@ int git_rebase_options_init(git_rebase_options *opts, unsigned int version)
return 0;
}
#ifndef GIT_DEPRECATE_HARD
int git_rebase_init_options(git_rebase_options *opts, unsigned int version)
{
return git_rebase_options_init(opts, version);
}
#endif
static int rebase_ensure_not_in_progress(git_repository *repo)
{
......
......@@ -195,10 +195,12 @@ int git_remote_create_options_init(git_remote_create_options *opts, unsigned int
return 0;
}
#ifndef GIT_DEPRECATE_HARD
int git_remote_create_init_options(git_remote_create_options *opts, unsigned int version)
{
return git_remote_create_options_init(opts, version);
}
#endif
int git_remote_create_with_opts(git_remote **out, const char *url, const git_remote_create_options *opts)
{
......
......@@ -2928,11 +2928,13 @@ int git_repository_init_options_init(
return 0;
}
#ifndef GIT_DEPRECATE_HARD
int git_repository_init_init_options(
git_repository_init_options *opts, unsigned int version)
{
return git_repository_init_options_init(opts, version);
}
#endif
int git_repository_ident(const char **name, const char **email, const git_repository *repo)
{
......
......@@ -231,7 +231,9 @@ int git_revert_options_init(git_revert_options *opts, unsigned int version)
return 0;
}
#ifndef GIT_DEPRECATE_HARD
int git_revert_init_options(git_revert_options *opts, unsigned int version)
{
return git_revert_options_init(opts, version);
}
#endif
......@@ -776,10 +776,12 @@ int git_stash_apply_options_init(git_stash_apply_options *opts, unsigned int ver
return 0;
}
#ifndef GIT_DEPRECATE_HARD
int git_stash_apply_init_options(git_stash_apply_options *opts, unsigned int version)
{
return git_stash_apply_options_init(opts, version);
}
#endif
#define NOTIFY_PROGRESS(opts, progress_type) \
do { \
......
......@@ -548,10 +548,12 @@ int git_status_options_init(git_status_options *opts, unsigned int version)
return 0;
}
#ifndef GIT_DEPRECATE_HARD
int git_status_init_options(git_status_options *opts, unsigned int version)
{
return git_status_options_init(opts, version);
}
#endif
int git_status_list_get_perfdata(
git_diff_perfdata *out, const git_status_list *status)
......
......@@ -55,7 +55,9 @@ void git_strarray_dispose(git_strarray *array)
memset(array, 0, sizeof(*array));
}
#ifndef GIT_DEPRECATE_HARD
void git_strarray_free(git_strarray *array)
{
git_strarray_dispose(array);
}
#endif
......@@ -101,7 +101,7 @@ int git_stream_register(git_stream_t type, git_stream_registration *registration
return 0;
}
#ifndef GIT_DEPRECATE_HARD
int git_stream_register_tls(
int GIT_CALLBACK(ctor)(git_stream **out, const char *host, const char *port))
{
......@@ -117,3 +117,4 @@ int git_stream_register_tls(
return git_stream_register(GIT_STREAM_TLS, NULL);
}
}
#endif
......@@ -1240,10 +1240,12 @@ int git_submodule_update_options_init(git_submodule_update_options *opts, unsign
return 0;
}
#ifndef GIT_DEPRECATE_HARD
int git_submodule_update_init_options(git_submodule_update_options *opts, unsigned int version)
{
return git_submodule_update_options_init(opts, version);
}
#endif
int git_submodule_update(git_submodule *sm, int init, git_submodule_update_options *_update_options)
{
......
......@@ -524,7 +524,9 @@ int git_tag_peel(git_object **tag_target, const git_tag *tag)
/* Deprecated Functions */
#ifndef GIT_DEPRECATE_HARD
int git_tag_create_frombuffer(git_oid *oid, git_repository *repo, const char *buffer, int allow_ref_overwrite)
{
return git_tag_create_from_buffer(oid, repo, buffer, allow_ref_overwrite);
}
#endif
......@@ -391,6 +391,7 @@ void git_credential_free(git_credential *cred)
/* Deprecated credential functions */
#ifndef GIT_DEPRECATE_HARD
int git_cred_has_username(git_credential *cred)
{
return git_credential_has_username(cred);
......@@ -474,3 +475,4 @@ void git_cred_free(git_credential *cred)
{
git_credential_free(cred);
}
#endif
......@@ -54,6 +54,7 @@ int git_credential_userpass(
/* Deprecated credential functions */
#ifndef GIT_DEPRECATE_HARD
int git_cred_userpass(
git_credential **out,
const char *url,
......@@ -64,3 +65,4 @@ int git_cred_userpass(
return git_credential_userpass(out, url, user_from_url,
allowed_types, payload);
}
#endif
......@@ -271,11 +271,13 @@ int git_worktree_add_options_init(git_worktree_add_options *opts,
return 0;
}
#ifndef GIT_DEPRECATE_HARD
int git_worktree_add_init_options(git_worktree_add_options *opts,
unsigned int version)
{
return git_worktree_add_options_init(opts, version);
}
#endif
int git_worktree_add(git_worktree **out, git_repository *repo,
const char *name, const char *worktree,
......@@ -506,11 +508,13 @@ int git_worktree_prune_options_init(
return 0;
}
#ifndef GIT_DEPRECATE_HARD
int git_worktree_prune_init_options(git_worktree_prune_options *opts,
unsigned int version)
{
return git_worktree_prune_options_init(opts, version);
}
#endif
int git_worktree_is_prunable(git_worktree *wt,
git_worktree_prune_options *opts)
......
#undef GIT_DEPRECATE_HARD
#include "clar_libgit2.h"
#include "git2/sys/stream.h"
#include "streams/tls.h"
#include "streams/socket.h"
#include "stream.h"
static git_stream test_stream;
static int ctor_called;
void test_stream_deprecated__cleanup(void)
{
cl_git_pass(git_stream_register(GIT_STREAM_TLS | GIT_STREAM_STANDARD, NULL));
}
#ifndef GIT_DEPRECATE_HARD
static git_stream test_stream;
static int ctor_called;
static int test_stream_init(git_stream **out, const char *host, const char *port)
{
GIT_UNUSED(host);
......@@ -24,9 +23,11 @@ static int test_stream_init(git_stream **out, const char *host, const char *port
return 0;
}
#endif
void test_stream_deprecated__register_tls(void)
{
#ifndef GIT_DEPRECATE_HARD
git_stream *stream;
int error;
......@@ -55,4 +56,5 @@ void test_stream_deprecated__register_tls(void)
cl_assert(&test_stream != stream);
git_stream_free(stream);
#endif
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment