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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611
diff --git a/src/blame.c b/src/blame.c
index 23c2102..1046dab 100644
--- a/src/blame.c
+++ b/src/blame.c
@@ -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
diff --git a/src/blob.c b/src/blob.c
index 5e734e2..da4e6ff 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -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
diff --git a/src/buffer.c b/src/buffer.c
index 328fdfe..3ee2775 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -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)
{
diff --git a/src/checkout.c b/src/checkout.c
index 44a8671..b18e8d9 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -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
diff --git a/src/cherrypick.c b/src/cherrypick.c
index 640d11a..103897a 100644
--- a/src/cherrypick.c
+++ b/src/cherrypick.c
@@ -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
diff --git a/src/clone.c b/src/clone.c
index 3d749c3..8ca6cea 100644
--- a/src/clone.c
+++ b/src/clone.c
@@ -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)
{
diff --git a/src/describe.c b/src/describe.c
index 42e5848..c8a1752 100644
--- a/src/describe.c
+++ b/src/describe.c
@@ -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
diff --git a/src/diff.c b/src/diff.c
index 9fd3613..3e52e3f 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -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)
{
diff --git a/src/errors.c b/src/errors.c
index b34aa3a..8570226 100644
--- a/src/errors.c
+++ b/src/errors.c
@@ -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
diff --git a/src/fetch.c b/src/fetch.c
index f2f3131..f4a4c9f 100644
--- a/src/fetch.c
+++ b/src/fetch.c
@@ -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
diff --git a/src/index.c b/src/index.c
index 774321d..361288b 100644
--- a/src/index.c
+++ b/src/index.c
@@ -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
diff --git a/src/indexer.c b/src/indexer.c
index 8dc6c7a..412dfc9 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -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,
diff --git a/src/merge.c b/src/merge.c
index 652b7ea..2f6bf6f 100644
--- a/src/merge.c
+++ b/src/merge.c
@@ -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
diff --git a/src/odb.c b/src/odb.c
index 68d9a9a..90565b7 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -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)
{
diff --git a/src/oid.c b/src/oid.c
index 6419566..7831aca 100644
--- a/src/oid.c
+++ b/src/oid.c
@@ -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;
diff --git a/src/proxy.c b/src/proxy.c
index 367c4b1..78a4c55 100644
--- a/src/proxy.c
+++ b/src/proxy.c
@@ -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)
{
diff --git a/src/push.c b/src/push.c
index 34867c2..b724188 100644
--- a/src/push.c
+++ b/src/push.c
@@ -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
diff --git a/src/rebase.c b/src/rebase.c
index 0a38807..7c65611 100644
--- a/src/rebase.c
+++ b/src/rebase.c
@@ -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)
{
diff --git a/src/remote.c b/src/remote.c
index 78e056a..23054c8 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -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)
{
diff --git a/src/repository.c b/src/repository.c
index 5806155..5e818fb 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -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)
{
diff --git a/src/revert.c b/src/revert.c
index b41a2a1..b84bc7d 100644
--- a/src/revert.c
+++ b/src/revert.c
@@ -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
diff --git a/src/stash.c b/src/stash.c
index 790f56f..0d5dc43 100644
--- a/src/stash.c
+++ b/src/stash.c
@@ -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 { \
diff --git a/src/status.c b/src/status.c
index 6a12844..eca1f49 100644
--- a/src/status.c
+++ b/src/status.c
@@ -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)
diff --git a/src/strarray.c b/src/strarray.c
index 7ad4134..54fe9fb 100644
--- a/src/strarray.c
+++ b/src/strarray.c
@@ -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
diff --git a/src/streams/registry.c b/src/streams/registry.c
index a5fa849..2844312 100644
--- a/src/streams/registry.c
+++ b/src/streams/registry.c
@@ -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
diff --git a/src/submodule.c b/src/submodule.c
index 7ae78c1..c32b977 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -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)
{
diff --git a/src/tag.c b/src/tag.c
index a7a005c..037dc66 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -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
diff --git a/src/transports/credential.c b/src/transports/credential.c
index 0cf50a0..7b28364 100644
--- a/src/transports/credential.c
+++ b/src/transports/credential.c
@@ -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
diff --git a/src/transports/credential_helpers.c b/src/transports/credential_helpers.c
index 6b975e1..6d34a4e 100644
--- a/src/transports/credential_helpers.c
+++ b/src/transports/credential_helpers.c
@@ -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
diff --git a/src/worktree.c b/src/worktree.c
index 74b32f9..fda9b0b 100644
--- a/src/worktree.c
+++ b/src/worktree.c
@@ -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)
diff --git a/tests/stream/deprecated.c b/tests/stream/deprecated.c
index 2c2bbfd..fecd1be 100644
--- a/tests/stream/deprecated.c
+++ b/tests/stream/deprecated.c
@@ -1,19 +1,18 @@
-#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
}