Add version fields and init macros for public input structs.
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
diff --git a/include/git2/checkout.h b/include/git2/checkout.h
index bd988db..ea6e219 100644
--- a/include/git2/checkout.h
+++ b/include/git2/checkout.h
@@ -186,7 +186,8 @@ typedef struct git_checkout_opts {
git_strarray paths;
} git_checkout_opts;
-#define GIT_CHECKOUT_OPTS_INIT {1, 0}
+#define GIT_CHECKOUT_OPTS_VERSION 1
+#define GIT_CHECKOUT_OPTS_INIT {GIT_CHECKOUT_OPTS_VERSION, 0}
/**
* Updates files in the index and the working tree to match the content of the
diff --git a/include/git2/config.h b/include/git2/config.h
index af4d540..4855bab 100644
--- a/include/git2/config.h
+++ b/include/git2/config.h
@@ -49,6 +49,7 @@ typedef int (*git_config_foreach_cb)(const git_config_entry *, void *);
* access a configuration file
*/
struct git_config_backend {
+ unsigned int version;
struct git_config *cfg;
/* Open means open the file/database and parse if necessary */
@@ -62,6 +63,8 @@ struct git_config_backend {
int (*refresh)(struct git_config_backend *);
void (*free)(struct git_config_backend *);
};
+#define GIT_CONFIG_BACKEND_VERSION 1
+#define GIT_CONFIG_BACKEND_INIT {GIT_CONFIG_BACKEND_VERSION, 0}
typedef enum {
GIT_CVAR_FALSE = 0,
diff --git a/include/git2/diff.h b/include/git2/diff.h
index fd00378..855e4be 100644
--- a/include/git2/diff.h
+++ b/include/git2/diff.h
@@ -106,16 +106,19 @@ typedef enum {
* - max_size: maximum blob size to diff, above this treated as binary
*/
typedef struct {
- unsigned int version; /**< version for the struct */
- uint32_t flags; /**< defaults to GIT_DIFF_NORMAL */
- uint16_t context_lines; /**< defaults to 3 */
- uint16_t interhunk_lines; /**< defaults to 0 */
- char *old_prefix; /**< defaults to "a" */
- char *new_prefix; /**< defaults to "b" */
- git_strarray pathspec; /**< defaults to show all paths */
- git_off_t max_size; /**< defaults to 512Mb */
+ unsigned int version; /**< version for the struct */
+ uint32_t flags; /**< defaults to git_diff_normal */
+ uint16_t context_lines; /**< defaults to 3 */
+ uint16_t interhunk_lines; /**< defaults to 0 */
+ char *old_prefix; /**< defaults to "a" */
+ char *new_prefix; /**< defaults to "b" */
+ git_strarray pathspec; /**< defaults to show all paths */
+ git_off_t max_size; /**< defaults to 512mb */
} git_diff_options;
+#define GIT_DIFF_OPTIONS_VERSION 1
+#define GIT_DIFF_OPTIONS_INIT = {GIT_DIFF_OPTIONS_VERSION, 0}
+
/**
* The diff list object that contains all individual file deltas.
*/
@@ -304,6 +307,8 @@ typedef struct {
unsigned int target_limit;
} git_diff_find_options;
+#define GIT_DIFF_FIND_OPTIONS_VERSION 1
+#define GIT_DIFF_FIND_OPTIONS_INIT {GIT_DIFF_FIND_OPTIONS_VERSION, 0}
/** @name Diff List Generator Functions
*
diff --git a/include/git2/odb_backend.h b/include/git2/odb_backend.h
index 04658f9..3963ae5 100644
--- a/include/git2/odb_backend.h
+++ b/include/git2/odb_backend.h
@@ -33,6 +33,7 @@ typedef int (*git_odb_foreach_cb)(const git_oid *id, void *payload);
* An instance for a custom backend
*/
struct git_odb_backend {
+ unsigned int version;
git_odb *odb;
/* read and read_prefix each return to libgit2 a buffer which
@@ -98,6 +99,9 @@ struct git_odb_backend {
void (* free)(struct git_odb_backend *);
};
+#define GIT_ODB_BACKEND_VERSION 1
+#define GIT_ODB_BACKEND_INIT {GIT_ODB_BACKEND_VERSION, 0}
+
/** Streaming mode */
enum {
GIT_STREAM_RDONLY = (1 << 1),
diff --git a/include/git2/remote.h b/include/git2/remote.h
index 6c70d7f..e5b60b9 100644
--- a/include/git2/remote.h
+++ b/include/git2/remote.h
@@ -338,12 +338,16 @@ typedef enum git_remote_completion_type {
* Set the calbacks to be called by the remote.
*/
struct git_remote_callbacks {
+ unsigned int version;
void (*progress)(const char *str, int len, void *data);
int (*completion)(git_remote_completion_type type, void *data);
int (*update_tips)(const char *refname, const git_oid *a, const git_oid *b, void *data);
void *payload;
};
+#define GIT_REMOTE_CALLBACKS_VERSION 1
+#define GIT_REMOTE_CALLBACKS_INIT {GIT_REMOTE_CALLBACKS_VERSION, 0}
+
/**
* Set the callbacks for a remote
*
diff --git a/include/git2/repository.h b/include/git2/repository.h
index e91108a..0d82b98 100644
--- a/include/git2/repository.h
+++ b/include/git2/repository.h
@@ -239,6 +239,7 @@ typedef enum {
* will be added pointing to this URL.
*/
typedef struct {
+ unsigned int version;
uint32_t flags;
uint32_t mode;
const char *workdir_path;
@@ -248,6 +249,9 @@ typedef struct {
const char *origin_url;
} git_repository_init_options;
+#define GIT_REPOSITORY_INIT_OPTIONS_VERSION 1
+#define GIT_REPOSITORY_INIT_OPTIONS_INIT {GIT_REPOSITORY_INIT_OPTIONS_VERSION, 0}
+
/**
* Create a new Git repository in the given folder with extended controls.
*
diff --git a/include/git2/status.h b/include/git2/status.h
index c6926f3..1211f1d 100644
--- a/include/git2/status.h
+++ b/include/git2/status.h
@@ -164,6 +164,9 @@ typedef struct {
git_strarray pathspec;
} git_status_options;
+#define GIT_STATUS_OPTIONS_VERSION 1
+#define GIT_STATUS_OPTIONS_INIT {GIT_STATUS_OPTIONS_VERSION, 0}
+
/**
* Gather file status information and run callbacks as requested.
*
diff --git a/include/git2/transport.h b/include/git2/transport.h
index 6172692..84d71c6 100644
--- a/include/git2/transport.h
+++ b/include/git2/transport.h
@@ -31,11 +31,15 @@ typedef enum {
/* The base structure for all credential types */
typedef struct git_cred {
+ unsigned int version; /* This should update if subtypes are extended */
git_credtype_t credtype;
void (*free)(
struct git_cred *cred);
} git_cred;
+#define GIT_CRED_VERSION 1
+#define GIT_CRED_INIT {GIT_CRED_VERSION, 0}
+
/* A plaintext username and password */
typedef struct git_cred_userpass_plaintext {
git_cred parent;
@@ -82,6 +86,7 @@ typedef enum {
typedef void (*git_transport_message_cb)(const char *str, int len, void *data);
typedef struct git_transport {
+ unsigned int version;
/* Set progress and error callbacks */
int (*set_callbacks)(struct git_transport *transport,
git_transport_message_cb progress_cb,
@@ -140,6 +145,9 @@ typedef struct git_transport {
void (*free)(struct git_transport *transport);
} git_transport;
+#define GIT_TRANSPORT_VERSION 1
+#define GIT_TRANSPORT_INIT {GIT_TRANSPORT_VERSION, 0}
+
/**
* Function to use to create a transport from a URL. The transport database
* is scanned to find a transport that implements the scheme of the URI (i.e.
@@ -284,6 +292,7 @@ typedef int (*git_smart_subtransport_cb)(
typedef struct git_smart_subtransport_definition {
/* The function to use to create the git_smart_subtransport */
git_smart_subtransport_cb callback;
+
/* True if the protocol is stateless; false otherwise. For example,
* http:// is stateless, but git:// is not. */
unsigned rpc : 1;
diff --git a/include/git2/types.h b/include/git2/types.h
index 06fcf36..d83b1d1 100644
--- a/include/git2/types.h
+++ b/include/git2/types.h
@@ -151,11 +151,15 @@ typedef struct git_time {
/** An action signature (e.g. for committers, taggers, etc) */
typedef struct git_signature {
+ unsigned int version;
char *name; /** full name of the author */
char *email; /** email of the author */
git_time when; /** time when the action happened */
} git_signature;
+#define GIT_SIGNATURE_VERSION 1
+#define GIT_SIGNATURE_INIT {GIT_SIGNATURE_VERSION, 0}
+
/** In-memory representation of a reference. */
typedef struct git_reference git_reference;
diff --git a/tests-clar/commit/parse.c b/tests-clar/commit/parse.c
index bbb502c..37e38db 100644
--- a/tests-clar/commit/parse.c
+++ b/tests-clar/commit/parse.c
@@ -149,7 +149,7 @@ void test_commit_parse__signature(void)
{
const char *str = passcase->string;
size_t len = strlen(passcase->string);
- struct git_signature person = {NULL, NULL, {0, 0}};
+ struct git_signature person = GIT_SIGNATURE_INIT;
cl_git_pass(git_signature__parse(&person, &str, str + len, passcase->header, '\n'));
cl_assert(strcmp(passcase->name, person.name) == 0);
cl_assert(strcmp(passcase->email, person.email) == 0);
@@ -162,7 +162,7 @@ void test_commit_parse__signature(void)
{
const char *str = failcase->string;
size_t len = strlen(failcase->string);
- git_signature person = {NULL, NULL, {0, 0}};
+ git_signature person = GIT_SIGNATURE_INIT;
cl_git_fail(git_signature__parse(&person, &str, str + len, failcase->header, '\n'));
git__free(person.name); git__free(person.email);
}