diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2020-05-27 22:08:24 +0100 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2020-05-29 11:33:58 +0100 |
commit | ca92646688fae0e44bb82a8a27c804aa6c328c2a (patch) | |
tree | dd3cdf2ddc0c59886529252a506adef6dc8c4924 | |
parent | 79dea820ac4087aac414e31ac45366f219da3365 (diff) | |
download | libgit2-ca92646688fae0e44bb82a8a27c804aa6c328c2a.tar.gz |
describe: user-facing functions write to a userbuf
-rw-r--r-- | include/git2/describe.h | 2 | ||||
-rw-r--r-- | src/describe.c | 12 | ||||
-rw-r--r-- | tests/describe/describe_helpers.c | 12 |
3 files changed, 15 insertions, 11 deletions
diff --git a/include/git2/describe.h b/include/git2/describe.h index 1d2ca1496..d53d9e81f 100644 --- a/include/git2/describe.h +++ b/include/git2/describe.h @@ -174,7 +174,7 @@ GIT_EXTERN(int) git_describe_workdir( * @param opts the formatting options (or NULL for defaults) */ GIT_EXTERN(int) git_describe_format( - git_buf *out, + git_userbuf *out, const git_describe_result *result, const git_describe_format_options *opts); diff --git a/src/describe.c b/src/describe.c index 42e5848c2..d31dff782 100644 --- a/src/describe.c +++ b/src/describe.c @@ -21,6 +21,7 @@ #include "tag.h" #include "vector.h" #include "wildmatch.h" +#include "userbuf.h" /* Ported from https://github.com/git/git/blob/89dde7882f71f846ccd0359756d27bebc31108de/builtin/describe.c */ @@ -768,7 +769,7 @@ static int normalize_format_options( return 0; } -int git_describe_format(git_buf *out, const git_describe_result *result, const git_describe_format_options *given) +static int git_describe__format(git_buf *out, const git_describe_result *result, const git_describe_format_options *given) { int error; git_repository *repo; @@ -780,9 +781,6 @@ int git_describe_format(git_buf *out, const git_describe_result *result, const g GIT_ERROR_CHECK_VERSION(given, GIT_DESCRIBE_FORMAT_OPTIONS_VERSION, "git_describe_format_options"); normalize_format_options(&opts, given); - git_buf_sanitize(out); - - if (opts.always_use_long_format && opts.abbreviated_size == 0) { git_error_set(GIT_ERROR_DESCRIBE, "cannot describe - " "'always_use_long_format' is incompatible with a zero" @@ -848,6 +846,12 @@ int git_describe_format(git_buf *out, const git_describe_result *result, const g return git_buf_oom(out) ? -1 : 0; } +int git_describe_format(git_userbuf *out, const git_describe_result *result, const git_describe_format_options *given) +{ + git_userbuf_sanitize(out); + return git_describe__format((git_buf *)out, result, given); +} + void git_describe_result_free(git_describe_result *result) { if (result == NULL) diff --git a/tests/describe/describe_helpers.c b/tests/describe/describe_helpers.c index 80217dcf0..57e0d27d9 100644 --- a/tests/describe/describe_helpers.c +++ b/tests/describe/describe_helpers.c @@ -10,7 +10,7 @@ void assert_describe( git_describe_format_options *fmt_opts) { git_object *object; - git_buf label = GIT_BUF_INIT; + git_userbuf label = GIT_USERBUF_INIT; git_describe_result *result; cl_git_pass(git_revparse_single(&object, repo, revparse_spec)); @@ -18,11 +18,11 @@ void assert_describe( cl_git_pass(git_describe_commit(&result, object, opts)); cl_git_pass(git_describe_format(&label, result, fmt_opts)); - cl_must_pass(wildmatch(expected_output, git_buf_cstr(&label), 0)); + cl_must_pass(wildmatch(expected_output, label.ptr, 0)); git_describe_result_free(result); git_object_free(object); - git_buf_dispose(&label); + git_userbuf_dispose(&label); } void assert_describe_workdir( @@ -31,14 +31,14 @@ void assert_describe_workdir( git_describe_options *opts, git_describe_format_options *fmt_opts) { - git_buf label = GIT_BUF_INIT; + git_userbuf label = GIT_USERBUF_INIT; git_describe_result *result; cl_git_pass(git_describe_workdir(&result, repo, opts)); cl_git_pass(git_describe_format(&label, result, fmt_opts)); - cl_must_pass(wildmatch(expected_output, git_buf_cstr(&label), 0)); + cl_must_pass(wildmatch(expected_output, label.ptr, 0)); git_describe_result_free(result); - git_buf_dispose(&label); + git_userbuf_dispose(&label); } |