Commit 25345c0c by Carlos Martín Nieto

describe: rename git_describe_opts to git_describe_options

And implement the option init functions for this and the format options.
parent 5431c46a
...@@ -32,9 +32,9 @@ typedef enum { ...@@ -32,9 +32,9 @@ typedef enum {
* Zero out for defaults. Initialize with `GIT_DESCRIBE_OPTIONS_INIT` macro to * Zero out for defaults. Initialize with `GIT_DESCRIBE_OPTIONS_INIT` macro to
* correctly set the `version` field. E.g. * correctly set the `version` field. E.g.
* *
* git_describe_opts opts = GIT_DESCRIBE_OPTIONS_INIT; * git_describe_options opts = GIT_DESCRIBE_OPTIONS_INIT;
*/ */
typedef struct git_describe_opts { typedef struct git_describe_options {
unsigned int version; unsigned int version;
unsigned int max_candidates_tags; /** default: 10 */ unsigned int max_candidates_tags; /** default: 10 */
...@@ -42,7 +42,7 @@ typedef struct git_describe_opts { ...@@ -42,7 +42,7 @@ typedef struct git_describe_opts {
const char *pattern; const char *pattern;
int only_follow_first_parent; int only_follow_first_parent;
int show_commit_oid_as_fallback; int show_commit_oid_as_fallback;
} git_describe_opts; } git_describe_options;
#define GIT_DESCRIBE_DEFAULT_MAX_CANDIDATES_TAGS 10 #define GIT_DESCRIBE_DEFAULT_MAX_CANDIDATES_TAGS 10
#define GIT_DESCRIBE_DEFAULT_ABBREVIATED_SIZE 7 #define GIT_DESCRIBE_DEFAULT_ABBREVIATED_SIZE 7
...@@ -53,6 +53,8 @@ typedef struct git_describe_opts { ...@@ -53,6 +53,8 @@ typedef struct git_describe_opts {
GIT_DESCRIBE_DEFAULT_MAX_CANDIDATES_TAGS, \ GIT_DESCRIBE_DEFAULT_MAX_CANDIDATES_TAGS, \
} }
GIT_EXTERN(int) git_describe_init_options(git_describe_options *opts, unsigned int version);
typedef struct { typedef struct {
unsigned int version; unsigned int version;
...@@ -68,17 +70,19 @@ typedef struct { ...@@ -68,17 +70,19 @@ typedef struct {
GIT_DESCRIBE_DEFAULT_ABBREVIATED_SIZE, \ GIT_DESCRIBE_DEFAULT_ABBREVIATED_SIZE, \
} }
GIT_EXTERN(int) git_describe_init_format_options(git_describe_format_options *opts, unsigned int version);
typedef struct git_describe_result git_describe_result; typedef struct git_describe_result git_describe_result;
GIT_EXTERN(int) git_describe_commit( GIT_EXTERN(int) git_describe_commit(
git_describe_result **result, git_describe_result **result,
git_object *committish, git_object *committish,
git_describe_opts *opts); git_describe_options *opts);
GIT_EXTERN(int) git_describe_workdir( GIT_EXTERN(int) git_describe_workdir(
git_describe_result **out, git_describe_result **out,
git_repository *repo, git_repository *repo,
git_describe_opts *opts); git_describe_options *opts);
GIT_EXTERN(int) git_describe_format(git_buf *out, const git_describe_result *result, const git_describe_format_options *opts); GIT_EXTERN(int) git_describe_format(git_buf *out, const git_describe_result *result, const git_describe_format_options *opts);
......
...@@ -178,7 +178,7 @@ typedef struct git_describe_result { ...@@ -178,7 +178,7 @@ typedef struct git_describe_result {
struct get_name_data struct get_name_data
{ {
git_describe_opts *opts; git_describe_options *opts;
git_repository *repo; git_repository *repo;
git_oidmap *names; git_oidmap *names;
git_describe_result *result; git_describe_result *result;
...@@ -634,10 +634,10 @@ cleanup: ...@@ -634,10 +634,10 @@ cleanup:
} }
static int normalize_options( static int normalize_options(
git_describe_opts *dst, git_describe_options *dst,
const git_describe_opts *src) const git_describe_options *src)
{ {
git_describe_opts default_options = GIT_DESCRIBE_OPTIONS_INIT; git_describe_options default_options = GIT_DESCRIBE_OPTIONS_INIT;
if (!src) src = &default_options; if (!src) src = &default_options;
*dst = *src; *dst = *src;
...@@ -648,18 +648,16 @@ static int normalize_options( ...@@ -648,18 +648,16 @@ static int normalize_options(
return 0; return 0;
} }
/** TODO: Add git_object_describe_workdir(git_buf *, const char *dirty_suffix, git_describe_opts *); */
int git_describe_commit( int git_describe_commit(
git_describe_result **result, git_describe_result **result,
git_object *committish, git_object *committish,
git_describe_opts *opts) git_describe_options *opts)
{ {
struct get_name_data data; struct get_name_data data;
struct commit_name *name; struct commit_name *name;
git_commit *commit; git_commit *commit;
int error = -1; int error = -1;
git_describe_opts normOptions; git_describe_options normalized;
assert(committish); assert(committish);
...@@ -670,21 +668,19 @@ int git_describe_commit( ...@@ -670,21 +668,19 @@ int git_describe_commit(
data.opts = opts; data.opts = opts;
data.repo = git_object_owner(committish); data.repo = git_object_owner(committish);
if ((error = normalize_options(&normOptions, opts)) < 0) if ((error = normalize_options(&normalized, opts)) < 0)
return error; return error;
GITERR_CHECK_VERSION( GITERR_CHECK_VERSION(
&normOptions, &normalized,
GIT_DESCRIBE_OPTIONS_VERSION, GIT_DESCRIBE_OPTIONS_VERSION,
"git_describe_opts"); "git_describe_options");
data.names = git_oidmap_alloc(); data.names = git_oidmap_alloc();
GITERR_CHECK_ALLOC(data.names); GITERR_CHECK_ALLOC(data.names);
/** TODO: contains to be implemented */ /** TODO: contains to be implemented */
/** TODO: deal with max_abbrev_size (either document or fix) */
if ((error = git_object_peel((git_object **)(&commit), committish, GIT_OBJ_COMMIT)) < 0) if ((error = git_object_peel((git_object **)(&commit), committish, GIT_OBJ_COMMIT)) < 0)
goto cleanup; goto cleanup;
...@@ -725,7 +721,7 @@ cleanup: ...@@ -725,7 +721,7 @@ cleanup:
int git_describe_workdir( int git_describe_workdir(
git_describe_result **out, git_describe_result **out,
git_repository *repo, git_repository *repo,
git_describe_opts *opts) git_describe_options *opts)
{ {
int error; int error;
git_oid current_id; git_oid current_id;
...@@ -859,3 +855,17 @@ void git_describe_result_free(git_describe_result *result) ...@@ -859,3 +855,17 @@ void git_describe_result_free(git_describe_result *result)
git__free(result); git__free(result);
} }
int git_describe_init_options(git_describe_options *opts, unsigned int version)
{
GIT_INIT_STRUCTURE_FROM_TEMPLATE(
opts, version, git_describe_options, GIT_DESCRIBE_OPTIONS_INIT);
return 0;
}
int git_describe_init_format_options(git_describe_format_options *opts, unsigned int version)
{
GIT_INIT_STRUCTURE_FROM_TEMPLATE(
opts, version, git_describe_format_options, GIT_DESCRIBE_FORMAT_OPTIONS_INIT);
return 0;
}
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
void test_describe_describe__can_describe_against_a_bare_repo(void) void test_describe_describe__can_describe_against_a_bare_repo(void)
{ {
git_repository *repo; git_repository *repo;
git_describe_opts opts = GIT_DESCRIBE_OPTIONS_INIT; git_describe_options opts = GIT_DESCRIBE_OPTIONS_INIT;
git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT; git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT;
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git"))); cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
...@@ -31,7 +31,7 @@ static int delete_cb(git_reference *ref, void *payload) ...@@ -31,7 +31,7 @@ static int delete_cb(git_reference *ref, void *payload)
void test_describe_describe__cannot_describe_against_a_repo_with_no_ref(void) void test_describe_describe__cannot_describe_against_a_repo_with_no_ref(void)
{ {
git_repository *repo; git_repository *repo;
git_describe_opts opts = GIT_DESCRIBE_OPTIONS_INIT; git_describe_options opts = GIT_DESCRIBE_OPTIONS_INIT;
git_buf buf = GIT_BUF_INIT; git_buf buf = GIT_BUF_INIT;
git_object *object; git_object *object;
git_describe_result *result = NULL; git_describe_result *result = NULL;
......
...@@ -4,7 +4,7 @@ void assert_describe( ...@@ -4,7 +4,7 @@ void assert_describe(
const char *expected_output, const char *expected_output,
const char *revparse_spec, const char *revparse_spec,
git_repository *repo, git_repository *repo,
git_describe_opts *opts, git_describe_options *opts,
git_describe_format_options *fmt_opts) git_describe_format_options *fmt_opts)
{ {
git_object *object; git_object *object;
...@@ -26,7 +26,7 @@ void assert_describe( ...@@ -26,7 +26,7 @@ void assert_describe(
void assert_describe_workdir( void assert_describe_workdir(
const char *expected_output, const char *expected_output,
git_repository *repo, git_repository *repo,
git_describe_opts *opts, git_describe_options *opts,
git_describe_format_options *fmt_opts) git_describe_format_options *fmt_opts)
{ {
git_buf label = GIT_BUF_INIT; git_buf label = GIT_BUF_INIT;
......
...@@ -5,11 +5,11 @@ extern void assert_describe( ...@@ -5,11 +5,11 @@ extern void assert_describe(
const char *expected_output, const char *expected_output,
const char *revparse_spec, const char *revparse_spec,
git_repository *repo, git_repository *repo,
git_describe_opts *opts, git_describe_options *opts,
git_describe_format_options *fmt_opts); git_describe_format_options *fmt_opts);
extern void assert_describe_workdir( extern void assert_describe_workdir(
const char *expected_output, const char *expected_output,
git_repository *repo, git_repository *repo,
git_describe_opts *opts, git_describe_options *opts,
git_describe_format_options *fmt_opts); git_describe_format_options *fmt_opts);
...@@ -18,7 +18,7 @@ void test_describe_t6120__cleanup(void) ...@@ -18,7 +18,7 @@ void test_describe_t6120__cleanup(void)
void test_describe_t6120__default(void) void test_describe_t6120__default(void)
{ {
git_describe_opts opts = GIT_DESCRIBE_OPTIONS_INIT; git_describe_options opts = GIT_DESCRIBE_OPTIONS_INIT;
git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT; git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT;
assert_describe("A-*", "HEAD", repo, &opts, &fmt_opts); assert_describe("A-*", "HEAD", repo, &opts, &fmt_opts);
...@@ -31,7 +31,7 @@ void test_describe_t6120__default(void) ...@@ -31,7 +31,7 @@ void test_describe_t6120__default(void)
void test_describe_t6120__tags(void) void test_describe_t6120__tags(void)
{ {
git_describe_opts opts = GIT_DESCRIBE_OPTIONS_INIT; git_describe_options opts = GIT_DESCRIBE_OPTIONS_INIT;
git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT; git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT;
opts.describe_strategy = GIT_DESCRIBE_TAGS; opts.describe_strategy = GIT_DESCRIBE_TAGS;
...@@ -45,7 +45,7 @@ void test_describe_t6120__tags(void) ...@@ -45,7 +45,7 @@ void test_describe_t6120__tags(void)
void test_describe_t6120__all(void) void test_describe_t6120__all(void)
{ {
git_describe_opts opts = GIT_DESCRIBE_OPTIONS_INIT; git_describe_options opts = GIT_DESCRIBE_OPTIONS_INIT;
git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT; git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT;
opts.describe_strategy = GIT_DESCRIBE_ALL; opts.describe_strategy = GIT_DESCRIBE_ALL;
...@@ -56,7 +56,7 @@ void test_describe_t6120__all(void) ...@@ -56,7 +56,7 @@ void test_describe_t6120__all(void)
void test_describe_t6120__longformat(void) void test_describe_t6120__longformat(void)
{ {
git_describe_opts opts = GIT_DESCRIBE_OPTIONS_INIT; git_describe_options opts = GIT_DESCRIBE_OPTIONS_INIT;
git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT; git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT;
fmt_opts.always_use_long_format = 1; fmt_opts.always_use_long_format = 1;
...@@ -67,7 +67,7 @@ void test_describe_t6120__longformat(void) ...@@ -67,7 +67,7 @@ void test_describe_t6120__longformat(void)
void test_describe_t6120__firstparent(void) void test_describe_t6120__firstparent(void)
{ {
git_describe_opts opts = GIT_DESCRIBE_OPTIONS_INIT; git_describe_options opts = GIT_DESCRIBE_OPTIONS_INIT;
git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT; git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT;
opts.describe_strategy = GIT_DESCRIBE_TAGS; opts.describe_strategy = GIT_DESCRIBE_TAGS;
...@@ -79,7 +79,7 @@ void test_describe_t6120__firstparent(void) ...@@ -79,7 +79,7 @@ void test_describe_t6120__firstparent(void)
void test_describe_t6120__workdir(void) void test_describe_t6120__workdir(void)
{ {
git_describe_opts opts = GIT_DESCRIBE_OPTIONS_INIT; git_describe_options opts = GIT_DESCRIBE_OPTIONS_INIT;
git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT; git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT;
assert_describe_workdir("A-*[0-9a-f]", repo, &opts, &fmt_opts); assert_describe_workdir("A-*[0-9a-f]", repo, &opts, &fmt_opts);
...@@ -119,7 +119,7 @@ static void commit_and_tag( ...@@ -119,7 +119,7 @@ static void commit_and_tag(
void test_describe_t6120__pattern(void) void test_describe_t6120__pattern(void)
{ {
git_describe_opts opts = GIT_DESCRIBE_OPTIONS_INIT; git_describe_options opts = GIT_DESCRIBE_OPTIONS_INIT;
git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT; git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT;
git_oid tag_id; git_oid tag_id;
git_object *head; git_object *head;
......
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