Commit bde336ea51df071de922827ae322df7b01b059ce

Ben Straub 2012-11-29T12:26:09

Add version fields and init macros for public input structs.

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);
    }