Skip to content

Commit 859d922

Browse files
authored
Merge pull request libgit2#4952 from libgit2/ethomson/deprecation
Deprecate functions and constants more gently
2 parents 5524a46 + c951b82 commit 859d922

File tree

15 files changed

+354
-263
lines changed

15 files changed

+354
-263
lines changed

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ SET(LIBGIT2_VERSION_STRING "${LIBGIT2_VERSION_MAJOR}.${LIBGIT2_VERSION_MINOR}.${
105105
FILE(STRINGS "${libgit2_SOURCE_DIR}/include/git2/version.h" GIT2_HEADER_SOVERSION REGEX "^#define LIBGIT2_SOVERSION [0-9]+$")
106106
STRING(REGEX REPLACE "^.*LIBGIT2_SOVERSION ([0-9]+)$" "\\1" LIBGIT2_SOVERSION "${GIT2_HEADER_SOVERSION}")
107107

108+
# Ensure that we do not use deprecated functions internally
109+
ADD_DEFINITIONS(-DGIT_DEPRECATE_HARD)
110+
108111
# Platform specific compilation flags
109112
IF (MSVC)
110113
IF (STDCALL)
@@ -229,7 +232,6 @@ ELSE ()
229232
ENABLE_WARNINGS(int-conversion)
230233
DISABLE_WARNINGS(documentation-deprecated-sync)
231234

232-
233235
IF (PROFILE)
234236
SET(CMAKE_C_FLAGS "-pg ${CMAKE_C_FLAGS}")
235237
SET(CMAKE_EXE_LINKER_FLAGS "-pg ${CMAKE_EXE_LINKER_FLAGS}")

docs/changelog.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,22 +112,30 @@ v0.27 + 1
112112

113113
### API removals
114114

115-
### Breaking API changes
116-
117115
* The `git_buf_free` API is deprecated; it has been renamed to
118116
`git_buf_dispose` for consistency. The `git_buf_free` API will be
119-
removed in a future release.
117+
retained for backward compatibility for the foreseeable future.
120118

121119
* The `git_otype` enumeration and its members are deprecated and have
122120
been renamed for consistency. The `GIT_OBJ_` enumeration values are
123-
now prefixed with `GIT_OBJECT_`. The `git_otype` enumeration will
124-
be removed in a future release.
121+
now prefixed with `GIT_OBJECT_`. The old enumerations and macros
122+
will be retained for backward compatibility for the foreseeable future.
125123

126124
* Several index-related APIs have been renamed for consistency. The
127125
`GIT_IDXENTRY_` enumeration values and macros have been renamed to
128126
be prefixed with `GIT_INDEX_ENTRY_`. The `GIT_INDEXCAP` enumeration
129127
values are now prefixed with `GIT_INDEX_CAPABILITY_`. The old
130-
enumerations and macros will be removed in a future release.
128+
enumerations and macros will be retained for backward compatibility
129+
for the foreseeable future.
130+
131+
* The error functions and enumeration values have been renamed for
132+
consistency. The `giterr_` functions and values prefix have been
133+
renamed to be prefixed with `git_error_`; similarly, the `GITERR_`
134+
constants have been renamed to be prefixed with `GIT_ERROR_`.
135+
The old enumerations and macros will be retained for backward
136+
compatibility for the foreseeable future.
137+
138+
### Breaking API changes
131139

132140
* The default checkout strategy changed from `DRY_RUN` to `SAFE` (#4531).
133141

examples/general.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ static void object_database(git_repository *repo, git_oid *oid)
185185
int error;
186186
git_odb_object *obj;
187187
git_odb *odb;
188-
git_otype otype;
188+
git_object_t otype;
189189

190190
git_repository_odb(&odb, repo);
191191

@@ -416,7 +416,7 @@ static void commit_parsing(git_repository *repo)
416416
static void tag_parsing(git_repository *repo)
417417
{
418418
git_commit *commit;
419-
git_otype type;
419+
git_object_t type;
420420
git_tag *tag;
421421
git_oid oid;
422422
const char *name, *message;

fuzzers/objects_fuzzer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ int LLVMFuzzerInitialize(int *argc, char ***argv)
2525

2626
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
2727
{
28-
const git_otype types[] = {
28+
const git_object_t types[] = {
2929
GIT_OBJECT_BLOB, GIT_OBJECT_TREE, GIT_OBJECT_COMMIT, GIT_OBJECT_TAG
3030
};
3131
git_object *object = NULL;

include/git2.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "git2/commit.h"
2222
#include "git2/common.h"
2323
#include "git2/config.h"
24+
#include "git2/deprecated.h"
2425
#include "git2/describe.h"
2526
#include "git2/diff.h"
2627
#include "git2/errors.h"

include/git2/buffer.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,6 @@ typedef struct {
7171
*/
7272
GIT_EXTERN(void) git_buf_dispose(git_buf *buffer);
7373

74-
/**
75-
* Alias of `git_buf_dispose`.
76-
*
77-
* This function is directly calls `git_buf_dispose` now and is deprecated.
78-
* Going forward, we refer to functions freeing the internal state of a
79-
* structure a `dispose` function, while functions freeing the structure
80-
* themselves will be called a `free` function.
81-
*
82-
* This function is going to be removed in v0.30.0.
83-
*/
84-
GIT_DEPRECATED(GIT_EXTERN(void)) git_buf_free(git_buf *buffer);
85-
8674
/**
8775
* Resize the buffer allocation to make more space.
8876
*

include/git2/deprecated.h

Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
/*
2+
* Copyright (C) the libgit2 contributors. All rights reserved.
3+
*
4+
* This file is part of libgit2, distributed under the GNU GPL v2 with
5+
* a Linking Exception. For full terms see the included COPYING file.
6+
*/
7+
#ifndef INCLUDE_git_deprecated_h__
8+
#define INCLUDE_git_deprecated_h__
9+
10+
#include "common.h"
11+
#include "buffer.h"
12+
#include "errors.h"
13+
#include "index.h"
14+
#include "object.h"
15+
#include "refs.h"
16+
17+
/*
18+
* Users can avoid deprecated functions by defining `GIT_DEPRECATE_HARD`.
19+
*/
20+
#ifndef GIT_DEPRECATE_HARD
21+
22+
/**
23+
* @file git2/deprecated.h
24+
* @brief libgit2 deprecated functions and values
25+
* @ingroup Git
26+
* @{
27+
*/
28+
GIT_BEGIN_DECL
29+
30+
/** @name Deprecated Buffer Functions
31+
*
32+
* These functions and enumeration values are retained for backward
33+
* compatibility. The newer versions of these functions should be
34+
* preferred in all new code.
35+
*
36+
* There is no plan to remove these backward compatibility values at
37+
* this time.
38+
*/
39+
/**@{*/
40+
41+
/**
42+
* Free the memory referred to by the git_buf. This is an alias of
43+
* `git_buf_dispose` and is preserved for backward compatibility.
44+
*
45+
* This function is deprecated, but there is no plan to remove this
46+
* function at this time.
47+
*
48+
* @deprecated Use git_buf_dispose
49+
* @see git_buf_dispose
50+
*/
51+
GIT_EXTERN(void) git_buf_free(git_buf *buffer);
52+
53+
/**@}*/
54+
55+
/** @name Deprecated Error Functions and Constants
56+
*
57+
* These functions and enumeration values are retained for backward
58+
* compatibility. The newer versions of these functions and values
59+
* should be preferred in all new code.
60+
*
61+
* There is no plan to remove these backward compatibility values at
62+
* this time.
63+
*/
64+
/**@{*/
65+
66+
#define GITERR_NONE GIT_ERROR_NONE
67+
#define GITERR_NOMEMORY GIT_ERROR_NOMEMORY
68+
#define GITERR_OS GIT_ERROR_OS
69+
#define GITERR_INVALID GIT_ERROR_INVALID
70+
#define GITERR_REFERENCE GIT_ERROR_REFERENCE
71+
#define GITERR_ZLIB GIT_ERROR_ZLIB
72+
#define GITERR_REPOSITORY GIT_ERROR_REPOSITORY
73+
#define GITERR_CONFIG GIT_ERROR_CONFIG
74+
#define GITERR_REGEX GIT_ERROR_REGEX
75+
#define GITERR_ODB GIT_ERROR_ODB
76+
#define GITERR_INDEX GIT_ERROR_INDEX
77+
#define GITERR_OBJECT GIT_ERROR_OBJECT
78+
#define GITERR_NET GIT_ERROR_NET
79+
#define GITERR_TAG GIT_ERROR_TAG
80+
#define GITERR_TREE GIT_ERROR_TREE
81+
#define GITERR_INDEXER GIT_ERROR_INDEXER
82+
#define GITERR_SSL GIT_ERROR_SSL
83+
#define GITERR_SUBMODULE GIT_ERROR_SUBMODULE
84+
#define GITERR_THREAD GIT_ERROR_THREAD
85+
#define GITERR_STASH GIT_ERROR_STASH
86+
#define GITERR_CHECKOUT GIT_ERROR_CHECKOUT
87+
#define GITERR_FETCHHEAD GIT_ERROR_FETCHHEAD
88+
#define GITERR_MERGE GIT_ERROR_MERGE
89+
#define GITERR_SSH GIT_ERROR_SSH
90+
#define GITERR_FILTER GIT_ERROR_FILTER
91+
#define GITERR_REVERT GIT_ERROR_REVERT
92+
#define GITERR_CALLBACK GIT_ERROR_CALLBACK
93+
#define GITERR_CHERRYPICK GIT_ERROR_CHERRYPICK
94+
#define GITERR_DESCRIBE GIT_ERROR_DESCRIBE
95+
#define GITERR_REBASE GIT_ERROR_REBASE
96+
#define GITERR_FILESYSTEM GIT_ERROR_FILESYSTEM
97+
#define GITERR_PATCH GIT_ERROR_PATCH
98+
#define GITERR_WORKTREE GIT_ERROR_WORKTREE
99+
#define GITERR_SHA1 GIT_ERROR_SHA1
100+
101+
/**
102+
* Return the last `git_error` object that was generated for the
103+
* current thread. This is an alias of `git_error_last` and is
104+
* preserved for backward compatibility.
105+
*
106+
* This function is deprecated, but there is no plan to remove this
107+
* function at this time.
108+
*
109+
* @deprecated Use git_error_last
110+
* @see git_error_last
111+
*/
112+
GIT_EXTERN(const git_error *) giterr_last(void);
113+
114+
/**
115+
* Clear the last error. This is an alias of `git_error_last` and is
116+
* preserved for backward compatibility.
117+
*
118+
* This function is deprecated, but there is no plan to remove this
119+
* function at this time.
120+
*
121+
* @deprecated Use git_error_clear
122+
* @see git_error_clear
123+
*/
124+
GIT_EXTERN(void) giterr_clear(void);
125+
126+
/**
127+
* Sets the error message to the given string. This is an alias of
128+
* `git_error_set_str` and is preserved for backward compatibility.
129+
*
130+
* This function is deprecated, but there is no plan to remove this
131+
* function at this time.
132+
*
133+
* @deprecated Use git_error_set_str
134+
* @see git_error_set_str
135+
*/
136+
GIT_EXTERN(void) giterr_set_str(int error_class, const char *string);
137+
138+
/**
139+
* Indicates that an out-of-memory situation occured. This is an alias
140+
* of `git_error_set_oom` and is preserved for backward compatibility.
141+
*
142+
* This function is deprecated, but there is no plan to remove this
143+
* function at this time.
144+
*
145+
* @deprecated Use git_error_set_oom
146+
* @see git_error_set_oom
147+
*/
148+
GIT_EXTERN(void) giterr_set_oom(void);
149+
150+
/**@}*/
151+
152+
/** @name Deprecated Index Constants
153+
*
154+
* These enumeration values are retained for backward compatibility.
155+
* The newer versions of these values should be preferred in all new code.
156+
*
157+
* There is no plan to remove these backward compatibility values at
158+
* this time.
159+
*/
160+
/**@{*/
161+
162+
#define GIT_IDXENTRY_NAMEMASK GIT_INDEX_ENTRY_NAMEMASK
163+
#define GIT_IDXENTRY_STAGEMASK GIT_INDEX_ENTRY_STAGEMASK
164+
#define GIT_IDXENTRY_STAGESHIFT GIT_INDEX_ENTRY_STAGESHIFT
165+
166+
/* The git_indxentry_flag_t enum */
167+
#define GIT_IDXENTRY_EXTENDED GIT_INDEX_ENTRY_EXTENDED
168+
#define GIT_IDXENTRY_VALID GIT_INDEX_ENTRY_VALID
169+
170+
#define GIT_IDXENTRY_STAGE(E) GIT_INDEX_ENTRY_STAGE(E)
171+
#define GIT_IDXENTRY_STAGE_SET(E,S) GIT_INDEX_ENTRY_STAGE_SET(E,S)
172+
173+
/* The git_idxentry_extended_flag_t enum */
174+
#define GIT_IDXENTRY_INTENT_TO_ADD GIT_INDEX_ENTRY_INTENT_TO_ADD
175+
#define GIT_IDXENTRY_SKIP_WORKTREE GIT_INDEX_ENTRY_SKIP_WORKTREE
176+
#define GIT_IDXENTRY_EXTENDED_FLAGS (GIT_INDEX_ENTRY_INTENT_TO_ADD | GIT_INDEX_ENTRY_SKIP_WORKTREE)
177+
#define GIT_IDXENTRY_EXTENDED2 (1 << 15)
178+
#define GIT_IDXENTRY_UPDATE (1 << 0)
179+
#define GIT_IDXENTRY_REMOVE (1 << 1)
180+
#define GIT_IDXENTRY_UPTODATE (1 << 2)
181+
#define GIT_IDXENTRY_ADDED (1 << 3)
182+
#define GIT_IDXENTRY_HASHED (1 << 4)
183+
#define GIT_IDXENTRY_UNHASHED (1 << 5)
184+
#define GIT_IDXENTRY_WT_REMOVE (1 << 6)
185+
#define GIT_IDXENTRY_CONFLICTED (1 << 7)
186+
#define GIT_IDXENTRY_UNPACKED (1 << 8)
187+
#define GIT_IDXENTRY_NEW_SKIP_WORKTREE (1 << 9)
188+
189+
/* The git_index_capability_t enum */
190+
#define GIT_INDEXCAP_IGNORE_CASE GIT_INDEX_CAPABILITY_IGNORE_CASE
191+
#define GIT_INDEXCAP_NO_FILEMODE GIT_INDEX_CAPABILITY_NO_FILEMODE
192+
#define GIT_INDEXCAP_NO_SYMLINKS GIT_INDEX_CAPABILITY_NO_SYMLINKS
193+
#define GIT_INDEXCAP_FROM_OWNER GIT_INDEX_CAPABILITY_FROM_OWNER
194+
195+
/**@}*/
196+
197+
/** @name Deprecated Object Constants
198+
*
199+
* These enumeration values are retained for backward compatibility. The
200+
* newer versions of these values should be preferred in all new code.
201+
*
202+
* There is no plan to remove these backward compatibility values at
203+
* this time.
204+
*/
205+
/**@{*/
206+
207+
#define git_otype git_object_t
208+
209+
#define GIT_OBJ_ANY GIT_OBJECT_ANY
210+
#define GIT_OBJ_BAD GIT_OBJECT_INVALID
211+
#define GIT_OBJ__EXT1 0
212+
#define GIT_OBJ_COMMIT GIT_OBJECT_COMMIT
213+
#define GIT_OBJ_TREE GIT_OBJECT_TREE
214+
#define GIT_OBJ_BLOB GIT_OBJECT_BLOB
215+
#define GIT_OBJ_TAG GIT_OBJECT_TAG
216+
#define GIT_OBJ__EXT2 5
217+
#define GIT_OBJ_OFS_DELTA GIT_OBJECT_OFS_DELTA
218+
#define GIT_OBJ_REF_DELTA GIT_OBJECT_REF_DELTA
219+
220+
/**@}*/
221+
222+
/** @name Deprecated Reference Constants
223+
*
224+
* These enumeration values are retained for backward compatibility. The
225+
* newer versions of these values should be preferred in all new code.
226+
*
227+
* There is no plan to remove these backward compatibility values at
228+
* this time.
229+
*/
230+
/**@{*/
231+
232+
/** Basic type of any Git reference. */
233+
#define git_ref_t git_reference_t
234+
#define git_reference_normalize_t git_reference_format_t
235+
236+
#define GIT_REF_INVALID GIT_REFERENCE_INVALID
237+
#define GIT_REF_OID GIT_REFERENCE_DIRECT
238+
#define GIT_REF_SYMBOLIC GIT_REFERENCE_SYMBOLIC
239+
#define GIT_REF_LISTALL GIT_REFERENCE_ALL
240+
241+
#define GIT_REF_FORMAT_NORMAL GIT_REFERENCE_FORMAT_NORMAL
242+
#define GIT_REF_FORMAT_ALLOW_ONELEVEL GIT_REFERENCE_FORMAT_ALLOW_ONELEVEL
243+
#define GIT_REF_FORMAT_REFSPEC_PATTERN GIT_REFERENCE_FORMAT_REFSPEC_PATTERN
244+
#define GIT_REF_FORMAT_REFSPEC_SHORTHAND GIT_REFERENCE_FORMAT_REFSPEC_SHORTHAND
245+
246+
/**@}*/
247+
248+
/** @} */
249+
GIT_END_DECL
250+
251+
#endif
252+
253+
#endif

0 commit comments

Comments
 (0)