Commit bde336ea by Ben Straub

Add version fields and init macros for public input structs.

parent da820437
......@@ -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
......
......@@ -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,
......
......@@ -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
*
......
......@@ -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),
......
......@@ -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
*
......
......@@ -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.
*
......
......@@ -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.
*
......
......@@ -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;
......
......@@ -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;
......
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment