Skip to content

Commit c6184f0

Browse files
committed
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 parent 6e1efcd commit c6184f0

31 files changed

+79
-6
lines changed

src/blame.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,9 @@ int git_blame_options_init(git_blame_options *opts, unsigned int version)
538538
return 0;
539539
}
540540

541+
#ifndef GIT_DEPRECATE_HARD
541542
int git_blame_init_options(git_blame_options *opts, unsigned int version)
542543
{
543544
return git_blame_options_init(opts, version);
544545
}
546+
#endif

src/blob.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ int git_blob_filter(
445445

446446
/* Deprecated functions */
447447

448+
#ifndef GIT_DEPRECATE_HARD
448449
int git_blob_create_frombuffer(
449450
git_oid *id, git_repository *repo, const void *buffer, size_t len)
450451
{
@@ -491,3 +492,4 @@ int git_blob_filtered_content(
491492

492493
return git_blob_filter(out, blob, path, &opts);
493494
}
495+
#endif

src/buffer.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,12 @@ void git_buf_dispose(git_buf *buf)
133133
git_buf_init(buf, 0);
134134
}
135135

136+
#ifndef GIT_DEPRECATE_HARD
136137
void git_buf_free(git_buf *buf)
137138
{
138139
git_buf_dispose(buf);
139140
}
141+
#endif
140142

141143
void git_buf_sanitize(git_buf *buf)
142144
{

src/checkout.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2820,7 +2820,9 @@ int git_checkout_options_init(git_checkout_options *opts, unsigned int version)
28202820
return 0;
28212821
}
28222822

2823+
#ifndef GIT_DEPRECATE_HARD
28232824
int git_checkout_init_options(git_checkout_options *opts, unsigned int version)
28242825
{
28252826
return git_checkout_options_init(opts, version);
28262827
}
2828+
#endif

src/cherrypick.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,10 @@ int git_cherrypick_options_init(
229229
return 0;
230230
}
231231

232+
#ifndef GIT_DEPRECATE_HARD
232233
int git_cherrypick_init_options(
233234
git_cherrypick_options *opts, unsigned int version)
234235
{
235236
return git_cherrypick_options_init(opts, version);
236237
}
238+
#endif

src/clone.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,10 +479,12 @@ int git_clone_options_init(git_clone_options *opts, unsigned int version)
479479
return 0;
480480
}
481481

482+
#ifndef GIT_DEPRECATE_HARD
482483
int git_clone_init_options(git_clone_options *opts, unsigned int version)
483484
{
484485
return git_clone_options_init(opts, version);
485486
}
487+
#endif
486488

487489
static bool can_link(const char *src, const char *dst, int link)
488490
{

src/describe.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,10 +876,12 @@ int git_describe_options_init(git_describe_options *opts, unsigned int version)
876876
return 0;
877877
}
878878

879+
#ifndef GIT_DEPRECATE_HARD
879880
int git_describe_init_options(git_describe_options *opts, unsigned int version)
880881
{
881882
return git_describe_options_init(opts, version);
882883
}
884+
#endif
883885

884886
int git_describe_format_options_init(git_describe_format_options *opts, unsigned int version)
885887
{
@@ -888,7 +890,9 @@ int git_describe_format_options_init(git_describe_format_options *opts, unsigned
888890
return 0;
889891
}
890892

893+
#ifndef GIT_DEPRECATE_HARD
891894
int git_describe_init_format_options(git_describe_format_options *opts, unsigned int version)
892895
{
893896
return git_describe_format_options_init(opts, version);
894897
}
898+
#endif

src/diff.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,10 +352,12 @@ int git_diff_options_init(git_diff_options *opts, unsigned int version)
352352
return 0;
353353
}
354354

355+
#ifndef GIT_DEPRECATE_HARD
355356
int git_diff_init_options(git_diff_options *opts, unsigned int version)
356357
{
357358
return git_diff_options_init(opts, version);
358359
}
360+
#endif
359361

360362
int git_diff_find_options_init(
361363
git_diff_find_options *opts, unsigned int version)
@@ -365,11 +367,13 @@ int git_diff_find_options_init(
365367
return 0;
366368
}
367369

370+
#ifndef GIT_DEPRECATE_HARD
368371
int git_diff_find_init_options(
369372
git_diff_find_options *opts, unsigned int version)
370373
{
371374
return git_diff_find_options_init(opts, version);
372375
}
376+
#endif
373377

374378
int git_diff_format_email_options_init(
375379
git_diff_format_email_options *opts, unsigned int version)
@@ -380,11 +384,13 @@ int git_diff_format_email_options_init(
380384
return 0;
381385
}
382386

387+
#ifndef GIT_DEPRECATE_HARD
383388
int git_diff_format_email_init_options(
384389
git_diff_format_email_options *opts, unsigned int version)
385390
{
386391
return git_diff_format_email_options_init(opts, version);
387392
}
393+
#endif
388394

389395
static int flush_hunk(git_oid *result, git_hash_ctx *ctx)
390396
{

src/errors.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ void git_error_system_set(int code)
210210

211211
/* Deprecated error values and functions */
212212

213+
#ifndef GIT_DEPRECATE_HARD
213214
const git_error *giterr_last(void)
214215
{
215216
return git_error_last();
@@ -229,3 +230,4 @@ void giterr_set_oom(void)
229230
{
230231
git_error_set_oom();
231232
}
233+
#endif

src/fetch.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ int git_fetch_options_init(git_fetch_options *opts, unsigned int version)
155155
return 0;
156156
}
157157

158+
#ifndef GIT_DEPRECATE_HARD
158159
int git_fetch_init_options(git_fetch_options *opts, unsigned int version)
159160
{
160161
return git_fetch_options_init(opts, version);
161162
}
163+
#endif

0 commit comments

Comments
 (0)